-
Notifications
You must be signed in to change notification settings - Fork 175
/
follower.go
50 lines (39 loc) · 1.62 KB
/
follower.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
package consensus
import (
"fmt"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/follower"
"github.com/onflow/flow-go/consensus/hotstuff/validator"
"github.com/onflow/flow-go/consensus/recovery"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/storage"
)
// TODO: this needs to be integrated with proper configuration and bootstrapping.
func NewFollower(log zerolog.Logger, committee hotstuff.Committee, headers storage.Headers, updater module.Finalizer,
verifier hotstuff.Verifier, notifier hotstuff.FinalizationConsumer, rootHeader *flow.Header,
rootQC *flow.QuorumCertificate, finalized *flow.Header, pending []*flow.Header) (*hotstuff.FollowerLoop, error) {
finalizer, err := newFinalizer(finalized, headers, updater, notifier, rootHeader, rootQC)
if err != nil {
return nil, fmt.Errorf("could not initialize finalizer: %w", err)
}
// initialize the Validator
validator := validator.New(committee, finalizer, verifier)
// recover the hotstuff state as a follower
err = recovery.Follower(log, finalizer, validator, finalized, pending)
if err != nil {
return nil, fmt.Errorf("could not recover hotstuff follower state: %w", err)
}
// initialize the follower logic
logic, err := follower.New(log, validator, finalizer)
if err != nil {
return nil, fmt.Errorf("could not create follower logic: %w", err)
}
// initialize the follower loop
loop, err := hotstuff.NewFollowerLoop(log, logic)
if err != nil {
return nil, fmt.Errorf("could not create follower loop: %w", err)
}
return loop, nil
}