github.com/koko1123/flow-go-1@v0.29.6/consensus/config.go (about) 1 package consensus 2 3 import ( 4 "time" 5 6 "github.com/koko1123/flow-go-1/consensus/hotstuff" 7 "github.com/koko1123/flow-go-1/consensus/hotstuff/notifications/pubsub" 8 "github.com/koko1123/flow-go-1/consensus/hotstuff/pacemaker/timeout" 9 "github.com/koko1123/flow-go-1/module/updatable_configs" 10 ) 11 12 // HotstuffModules is a helper structure to encapsulate dependencies to create 13 // a hotStuff participant. 14 type HotstuffModules struct { 15 Notifier hotstuff.Consumer // observer for hotstuff events 16 Committee hotstuff.Committee // consensus committee 17 Signer hotstuff.Signer // signer of proposal & votes 18 Persist hotstuff.Persister // last state of consensus participant 19 FinalizationDistributor *pubsub.FinalizationDistributor // observer for finalization events, used by compliance engine 20 QCCreatedDistributor *pubsub.QCCreatedDistributor // observer for qc created event, used by leader 21 Forks hotstuff.Forks // information about multiple forks 22 Validator hotstuff.Validator // validator of proposals & votes 23 Aggregator hotstuff.VoteAggregator // aggregator of votes, used by leader 24 } 25 26 type ParticipantConfig struct { 27 StartupTime time.Time // the time when consensus participant enters first view 28 TimeoutInitial time.Duration // the initial timeout for the pacemaker 29 TimeoutMinimum time.Duration // the minimum timeout for the pacemaker 30 TimeoutAggregationFraction float64 // the percentage part of the timeout period reserved for vote aggregation 31 TimeoutIncreaseFactor float64 // the factor at which the timeout grows when timeouts occur 32 TimeoutDecreaseFactor float64 // the factor at which the timeout grows when timeouts occur 33 BlockRateDelay time.Duration // a delay to broadcast block proposal in order to control the block production rate 34 Registrar updatable_configs.Registrar // optional: for registering HotStuff configs as dynamically configurable 35 } 36 37 func DefaultParticipantConfig() ParticipantConfig { 38 defTimeout := timeout.DefaultConfig 39 cfg := ParticipantConfig{ 40 TimeoutInitial: time.Duration(defTimeout.ReplicaTimeout) * time.Millisecond, 41 TimeoutMinimum: time.Duration(defTimeout.MinReplicaTimeout) * time.Millisecond, 42 TimeoutAggregationFraction: defTimeout.VoteAggregationTimeoutFraction, 43 TimeoutIncreaseFactor: defTimeout.TimeoutIncrease, 44 TimeoutDecreaseFactor: defTimeout.TimeoutDecrease, 45 BlockRateDelay: defTimeout.GetBlockRateDelay(), 46 Registrar: nil, 47 } 48 return cfg 49 } 50 51 type Option func(*ParticipantConfig) 52 53 func WithStartupTime(time time.Time) Option { 54 return func(cfg *ParticipantConfig) { 55 cfg.StartupTime = time 56 } 57 } 58 59 func WithInitialTimeout(timeout time.Duration) Option { 60 return func(cfg *ParticipantConfig) { 61 cfg.TimeoutInitial = timeout 62 } 63 } 64 65 func WithMinTimeout(timeout time.Duration) Option { 66 return func(cfg *ParticipantConfig) { 67 cfg.TimeoutMinimum = timeout 68 } 69 } 70 71 func WithTimeoutIncreaseFactor(factor float64) Option { 72 return func(cfg *ParticipantConfig) { 73 cfg.TimeoutIncreaseFactor = factor 74 } 75 } 76 77 func WithTimeoutDecreaseFactor(factor float64) Option { 78 return func(cfg *ParticipantConfig) { 79 cfg.TimeoutDecreaseFactor = factor 80 } 81 } 82 83 func WithVoteAggregationTimeoutFraction(fraction float64) Option { 84 return func(cfg *ParticipantConfig) { 85 cfg.TimeoutAggregationFraction = fraction 86 } 87 } 88 89 func WithBlockRateDelay(delay time.Duration) Option { 90 return func(cfg *ParticipantConfig) { 91 cfg.BlockRateDelay = delay 92 } 93 } 94 95 func WithConfigRegistrar(reg updatable_configs.Registrar) Option { 96 return func(cfg *ParticipantConfig) { 97 cfg.Registrar = reg 98 } 99 }