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