-
Notifications
You must be signed in to change notification settings - Fork 175
/
sealing_configs.go
88 lines (74 loc) · 3.26 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
88
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 value and returns the old value
// if the new value is valid. otherwise returns an error,
// and the value is not updated (equivalent to no-op)
func (r *sealingConfigs) SetRequiredApprovalsForSealingConstruction(requiredApprovalsForSealConstruction uint) (uint, error) {
err := validation.ValidateRequireApprovals(
requiredApprovalsForSealConstruction,
r.requiredApprovalsForSealVerification,
r.chunkAlpha,
)
if err != nil {
return 0, err
}
from := uint(r.requiredApprovalsForSealConstruction.Load())
r.requiredApprovalsForSealConstruction.Store(uint32(requiredApprovalsForSealConstruction))
return from, 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
}