github.com/koko1123/flow-go-1@v0.29.6/consensus/follower.go (about) 1 package consensus 2 3 import ( 4 "fmt" 5 6 "github.com/rs/zerolog" 7 8 "github.com/koko1123/flow-go-1/consensus/hotstuff" 9 "github.com/koko1123/flow-go-1/consensus/hotstuff/follower" 10 "github.com/koko1123/flow-go-1/consensus/hotstuff/validator" 11 "github.com/koko1123/flow-go-1/consensus/recovery" 12 "github.com/koko1123/flow-go-1/model/flow" 13 "github.com/koko1123/flow-go-1/module" 14 "github.com/koko1123/flow-go-1/storage" 15 ) 16 17 // TODO: this needs to be integrated with proper configuration and bootstrapping. 18 19 func NewFollower(log zerolog.Logger, committee hotstuff.Committee, headers storage.Headers, updater module.Finalizer, 20 verifier hotstuff.Verifier, notifier hotstuff.FinalizationConsumer, rootHeader *flow.Header, 21 rootQC *flow.QuorumCertificate, finalized *flow.Header, pending []*flow.Header) (*hotstuff.FollowerLoop, error) { 22 23 finalizer, err := newFinalizer(finalized, headers, updater, notifier, rootHeader, rootQC) 24 if err != nil { 25 return nil, fmt.Errorf("could not initialize finalizer: %w", err) 26 } 27 28 // initialize the Validator 29 validator := validator.New(committee, finalizer, verifier) 30 31 // recover the hotstuff state as a follower 32 err = recovery.Follower(log, finalizer, validator, finalized, pending) 33 if err != nil { 34 return nil, fmt.Errorf("could not recover hotstuff follower state: %w", err) 35 } 36 37 // initialize the follower logic 38 logic, err := follower.New(log, validator, finalizer) 39 if err != nil { 40 return nil, fmt.Errorf("could not create follower logic: %w", err) 41 } 42 43 // initialize the follower loop 44 loop, err := hotstuff.NewFollowerLoop(log, logic) 45 if err != nil { 46 return nil, fmt.Errorf("could not create follower loop: %w", err) 47 } 48 49 return loop, nil 50 }