-
Notifications
You must be signed in to change notification settings - Fork 176
/
follower.go
35 lines (31 loc) · 942 Bytes
/
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
package recovery
import (
"fmt"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
)
// Follower recovers the HotStuff state for a follower instance.
// It reads the pending blocks from storage and pass them to the input Forks
// instance to recover its state from before the restart.
func Follower(
log zerolog.Logger,
forks hotstuff.Forks,
validator hotstuff.Validator,
finalized *flow.Header,
pending []*flow.Header,
) error {
return Recover(log, finalized, pending, validator, func(proposal *model.Proposal) error {
// add it to forks
err := forks.AddProposal(proposal)
if err != nil {
return fmt.Errorf("could not add block to forks: %w", err)
}
log.Debug().
Uint64("block_view", proposal.Block.View).
Hex("block_id", proposal.Block.BlockID[:]).
Msg("block recovered")
return nil
})
}