-
Notifications
You must be signed in to change notification settings - Fork 179
/
config.go
76 lines (64 loc) · 2.81 KB
/
config.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
package consensus
import (
"time"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/notifications/pubsub"
)
// HotstuffModules is a helper structure to encapsulate dependencies to create
// a hotStuff participant.
type HotstuffModules struct {
Notifier hotstuff.Consumer // observer for hotstuff events
Committee hotstuff.Committee // consensus committee
Signer hotstuff.Signer // signer of proposal & votes
Persist hotstuff.Persister // last state of consensus participant
FinalizationDistributor *pubsub.FinalizationDistributor // observer for finalization events, used by compliance engine
QCCreatedDistributor *pubsub.QCCreatedDistributor // observer for qc created event, used by leader
Forks hotstuff.Forks // information about multiple forks
Validator hotstuff.Validator // validator of proposals & votes
Aggregator hotstuff.VoteAggregator // aggregator of votes, used by leader
}
type ParticipantConfig struct {
StartupTime time.Time // the time when consensus participant enters first view
TimeoutInitial time.Duration // the initial timeout for the pacemaker
TimeoutMinimum time.Duration // the minimum timeout for the pacemaker
TimeoutAggregationFraction float64 // the percentage part of the timeout period reserved for vote aggregation
TimeoutIncreaseFactor float64 // the factor at which the timeout grows when timeouts occur
TimeoutDecreaseFactor float64 // the factor at which the timeout grows when timeouts occur
BlockRateDelay time.Duration // a delay to broadcast block proposal in order to control the block production rate
}
type Option func(*ParticipantConfig)
func WithStartupTime(time time.Time) Option {
return func(cfg *ParticipantConfig) {
cfg.StartupTime = time
}
}
func WithInitialTimeout(timeout time.Duration) Option {
return func(cfg *ParticipantConfig) {
cfg.TimeoutInitial = timeout
}
}
func WithMinTimeout(timeout time.Duration) Option {
return func(cfg *ParticipantConfig) {
cfg.TimeoutMinimum = timeout
}
}
func WithTimeoutIncreaseFactor(factor float64) Option {
return func(cfg *ParticipantConfig) {
cfg.TimeoutIncreaseFactor = factor
}
}
func WithTimeoutDecreaseFactor(factor float64) Option {
return func(cfg *ParticipantConfig) {
cfg.TimeoutDecreaseFactor = factor
}
}
func WithVoteAggregationTimeoutFraction(fraction float64) Option {
return func(cfg *ParticipantConfig) {
cfg.TimeoutAggregationFraction = fraction
}
}
func WithBlockRateDelay(delay time.Duration) Option {
return func(cfg *ParticipantConfig) {
cfg.BlockRateDelay = delay
}
}