github.com/koko1123/flow-go-1@v0.29.6/module/updatable_configs/sealing_configs.go (about) 1 package updatable_configs 2 3 import ( 4 "fmt" 5 6 "go.uber.org/atomic" 7 8 "github.com/koko1123/flow-go-1/model/flow" 9 "github.com/koko1123/flow-go-1/module" 10 "github.com/koko1123/flow-go-1/module/updatable_configs/validation" 11 ) 12 13 // min number of approvals required for constructing a candidate seal 14 type sealingConfigs struct { 15 requiredApprovalsForSealConstruction *atomic.Uint32 16 requiredApprovalsForSealVerification uint 17 chunkAlpha uint 18 emergencySealingActive bool // flag which indicates if emergency sealing is active or not. NOTE: this is temporary while sealing & verification is under development 19 approvalRequestsThreshold uint64 // threshold for re-requesting approvals: min height difference between the latest finalized block and the block incorporating a result 20 } 21 22 var _ module.SealingConfigsSetter = (*sealingConfigs)(nil) 23 24 func NewSealingConfigs( 25 requiredApprovalsForSealConstruction uint, 26 requiredApprovalsForSealVerification uint, 27 chunkAlpha uint, 28 emergencySealingActive bool, 29 ) (module.SealingConfigsSetter, error) { 30 err := validation.ValidateRequireApprovals( 31 requiredApprovalsForSealConstruction, 32 requiredApprovalsForSealVerification, 33 chunkAlpha, 34 ) 35 if err != nil { 36 return nil, fmt.Errorf("can not create RequiredApprovalsForSealConstructionInstance: %w", err) 37 } 38 return &sealingConfigs{ 39 requiredApprovalsForSealConstruction: atomic.NewUint32(uint32(requiredApprovalsForSealConstruction)), 40 requiredApprovalsForSealVerification: requiredApprovalsForSealVerification, 41 chunkAlpha: chunkAlpha, 42 emergencySealingActive: emergencySealingActive, 43 approvalRequestsThreshold: flow.DefaultApprovalRequestsThreshold, 44 }, nil 45 } 46 47 // SetRequiredApprovalsForSealingConstruction takes a new config value and updates the config 48 // if the new value is valid. 49 // Returns ValidationError if the new value results in an invalid sealing config. 50 func (r *sealingConfigs) SetRequiredApprovalsForSealingConstruction(requiredApprovalsForSealConstruction uint) error { 51 err := validation.ValidateRequireApprovals( 52 requiredApprovalsForSealConstruction, 53 r.requiredApprovalsForSealVerification, 54 r.chunkAlpha, 55 ) 56 if err != nil { 57 return NewValidationErrorf("invalid: %w", err) 58 } 59 60 r.requiredApprovalsForSealConstruction.Store(uint32(requiredApprovalsForSealConstruction)) 61 62 return nil 63 } 64 65 // RequireApprovalsForSealConstructionDynamicValue gets the latest value of requiredApprovalsForSealConstruction 66 func (r *sealingConfigs) RequireApprovalsForSealConstructionDynamicValue() uint { 67 return uint(r.requiredApprovalsForSealConstruction.Load()) 68 } 69 70 // ChunkAlphaConst returns the constant chunk alpha value 71 func (r *sealingConfigs) ChunkAlphaConst() uint { 72 return r.chunkAlpha 73 } 74 75 // RequireApprovalsForSealVerificationConst returns the constant RequireApprovalsForSealVerification value 76 func (r *sealingConfigs) RequireApprovalsForSealVerificationConst() uint { 77 return r.requiredApprovalsForSealVerification 78 } 79 80 // EmergencySealingActiveConst returns the constant EmergencySealingActive value 81 func (r *sealingConfigs) EmergencySealingActiveConst() bool { 82 return r.emergencySealingActive 83 } 84 85 func (r *sealingConfigs) ApprovalRequestsThresholdConst() uint64 { 86 return r.approvalRequestsThreshold 87 }