github.com/celestiaorg/celestia-node@v0.15.0-beta.1/share/availability/light/options.go (about)

     1  package light
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // SampleAmount specifies the minimum required amount of samples a light node must perform
     8  // before declaring that a block is available
     9  var (
    10  	DefaultSampleAmount uint = 16
    11  )
    12  
    13  // Parameters is the set of Parameters that must be configured for the light
    14  // availability implementation
    15  type Parameters struct {
    16  	SampleAmount uint // The minimum required amount of samples to perform
    17  }
    18  
    19  // Option is a function that configures light availability Parameters
    20  type Option func(*Parameters)
    21  
    22  // DefaultParameters returns the default Parameters' configuration values
    23  // for the light availability implementation
    24  func DefaultParameters() Parameters {
    25  	return Parameters{
    26  		SampleAmount: DefaultSampleAmount,
    27  	}
    28  }
    29  
    30  // Validate validates the values in Parameters
    31  func (p *Parameters) Validate() error {
    32  	if p.SampleAmount <= 0 {
    33  		return fmt.Errorf(
    34  			"light availability: invalid option: value %s was %s, where it should be %s",
    35  			"SampleAmount",
    36  			"<= 0", // current value
    37  			">= 0", // what the value should be
    38  		)
    39  	}
    40  
    41  	return nil
    42  }
    43  
    44  // WithSampleAmount is a functional option that the Availability interface
    45  // implementers use to set the SampleAmount configuration param
    46  func WithSampleAmount(sampleAmount uint) Option {
    47  	return func(p *Parameters) {
    48  		p.SampleAmount = sampleAmount
    49  	}
    50  }