github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/config.go (about) 1 package consensus 2 3 import ( 4 "time" 5 6 "github.com/onflow/flow-go/consensus/hotstuff" 7 "github.com/onflow/flow-go/consensus/hotstuff/notifications/pubsub" 8 "github.com/onflow/flow-go/consensus/hotstuff/pacemaker" 9 "github.com/onflow/flow-go/consensus/hotstuff/pacemaker/timeout" 10 ) 11 12 // HotstuffModules is a helper structure to encapsulate dependencies to create 13 // a hotStuff participant. 14 type HotstuffModules struct { 15 Committee hotstuff.DynamicCommittee // consensus committee 16 Signer hotstuff.Signer // signer of proposal & votes 17 Persist hotstuff.Persister // last state of consensus participant 18 Notifier *pubsub.Distributor // observer for hotstuff events 19 VoteCollectorDistributor *pubsub.VoteCollectorDistributor // observer for vote aggregation events, used by leader 20 TimeoutCollectorDistributor *pubsub.TimeoutCollectorDistributor // observer for timeout aggregation events 21 Forks hotstuff.Forks // information about multiple forks 22 Validator hotstuff.Validator // validator of proposals & votes 23 VoteAggregator hotstuff.VoteAggregator // aggregator of votes, used by leader 24 TimeoutAggregator hotstuff.TimeoutAggregator // aggregator of `TimeoutObject`s, used by every replica 25 } 26 27 type ParticipantConfig struct { 28 StartupTime time.Time // the time when consensus participant enters first view 29 TimeoutMinimum time.Duration // the minimum timeout for the pacemaker 30 TimeoutMaximum time.Duration // the maximum timeout for the pacemaker 31 TimeoutAdjustmentFactor float64 // the factor at which the timeout duration is adjusted 32 HappyPathMaxRoundFailures uint64 // number of failed rounds before first timeout increase 33 MaxTimeoutObjectRebroadcastInterval time.Duration // maximum interval for timeout object rebroadcast 34 ProposalDurationProvider hotstuff.ProposalDurationProvider // a delay to broadcast block proposal in order to control the block production rate 35 } 36 37 func DefaultParticipantConfig() ParticipantConfig { 38 defTimeout := timeout.DefaultConfig 39 cfg := ParticipantConfig{ 40 TimeoutMinimum: time.Duration(defTimeout.MinReplicaTimeout) * time.Millisecond, 41 TimeoutMaximum: time.Duration(defTimeout.MaxReplicaTimeout) * time.Millisecond, 42 TimeoutAdjustmentFactor: defTimeout.TimeoutAdjustmentFactor, 43 HappyPathMaxRoundFailures: defTimeout.HappyPathMaxRoundFailures, 44 MaxTimeoutObjectRebroadcastInterval: time.Duration(defTimeout.MaxTimeoutObjectRebroadcastInterval) * time.Millisecond, 45 ProposalDurationProvider: pacemaker.NoProposalDelay(), 46 } 47 return cfg 48 } 49 50 type Option func(*ParticipantConfig) 51 52 func WithStartupTime(time time.Time) Option { 53 return func(cfg *ParticipantConfig) { 54 cfg.StartupTime = time 55 } 56 } 57 58 func WithMinTimeout(timeout time.Duration) Option { 59 return func(cfg *ParticipantConfig) { 60 cfg.TimeoutMinimum = timeout 61 } 62 } 63 64 func WithTimeoutAdjustmentFactor(factor float64) Option { 65 return func(cfg *ParticipantConfig) { 66 cfg.TimeoutAdjustmentFactor = factor 67 } 68 } 69 70 func WithHappyPathMaxRoundFailures(happyPathMaxRoundFailures uint64) Option { 71 return func(cfg *ParticipantConfig) { 72 cfg.HappyPathMaxRoundFailures = happyPathMaxRoundFailures 73 } 74 } 75 76 func WithProposalDurationProvider(provider hotstuff.ProposalDurationProvider) Option { 77 return func(cfg *ParticipantConfig) { 78 cfg.ProposalDurationProvider = provider 79 } 80 } 81 82 func WithStaticProposalDuration(dur time.Duration) Option { 83 return func(cfg *ParticipantConfig) { 84 cfg.ProposalDurationProvider = pacemaker.NewStaticProposalDurationProvider(dur) 85 } 86 }