github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/compliance/config.go (about)

     1  package compliance
     2  
     3  const MinSkipNewProposalsThreshold = 1000
     4  
     5  // Config is shared config for consensus and collection compliance engines, and
     6  // the consensus follower engine.
     7  type Config struct {
     8  	// SkipNewProposalsThreshold defines the threshold for dropping blocks that are too far in
     9  	// the future. Formally, let `H` be the view of the latest finalized block known to this
    10  	// node. A new block `B` is dropped without further processing, if
    11  	//   B.View > H + SkipNewProposalsThreshold
    12  	SkipNewProposalsThreshold uint64
    13  }
    14  
    15  func DefaultConfig() Config {
    16  	return Config{
    17  		SkipNewProposalsThreshold: 100_000,
    18  	}
    19  }
    20  
    21  // GetSkipNewProposalsThreshold returns stored value in config possibly applying a lower bound.
    22  func (c *Config) GetSkipNewProposalsThreshold() uint64 {
    23  	if c.SkipNewProposalsThreshold < MinSkipNewProposalsThreshold {
    24  		return MinSkipNewProposalsThreshold
    25  	}
    26  
    27  	return c.SkipNewProposalsThreshold
    28  }
    29  
    30  type Opt func(*Config)
    31  
    32  // WithSkipNewProposalsThreshold returns an option to set the skip new proposals
    33  // threshold. For inputs less than the minimum threshold, the minimum threshold
    34  // will be set instead.
    35  func WithSkipNewProposalsThreshold(threshold uint64) Opt {
    36  	return func(config *Config) {
    37  		// sanity check: small values are dangerous and can cause finalization halt
    38  		if threshold < MinSkipNewProposalsThreshold {
    39  			threshold = MinSkipNewProposalsThreshold
    40  		}
    41  		config.SkipNewProposalsThreshold = threshold
    42  	}
    43  }