-
Notifications
You must be signed in to change notification settings - Fork 175
/
follower.go
52 lines (44 loc) · 1.74 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
51
52
package consensus
import (
"fmt"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"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.
// NewFollower instantiates the consensus follower and recovers its in-memory state of pending blocks.
// It receives the list `pending` containing _all_ blocks that
// - have passed the compliance layer and stored in the protocol state
// - descend from the latest finalized block
// - are listed in ancestor-first order (i.e. for any block B ∈ pending, B's parent must
// be listed before B, unless B's parent is the latest finalized block)
//
// CAUTION: all pending blocks are required to be valid (guaranteed if the block passed the compliance layer)
func NewFollower(log zerolog.Logger,
headers storage.Headers,
updater module.Finalizer,
notifier hotstuff.FollowerConsumer,
rootHeader *flow.Header,
rootQC *flow.QuorumCertificate,
finalized *flow.Header,
pending []*flow.Header,
) (*hotstuff.FollowerLoop, error) {
forks, err := NewForks(finalized, headers, updater, notifier, rootHeader, rootQC)
if err != nil {
return nil, fmt.Errorf("could not initialize forks: %w", err)
}
// recover forks internal state (inserts all pending blocks)
err = recovery.Recover(log, pending, recovery.ForksState(forks))
if err != nil {
return nil, fmt.Errorf("could not recover hotstuff follower state: %w", err)
}
// initialize the follower loop
loop, err := hotstuff.NewFollowerLoop(log, forks)
if err != nil {
return nil, fmt.Errorf("could not create follower loop: %w", err)
}
return loop, nil
}