-
Notifications
You must be signed in to change notification settings - Fork 175
/
follower.go
36 lines (32 loc) · 1020 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
36
package recovery
import (
"fmt"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/forks"
"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 Finalizer
// instance to recover its state from before the restart.
func Follower(
log zerolog.Logger,
finalizer forks.Finalizer,
validator hotstuff.Validator,
finalized *flow.Header,
pending []*flow.Header,
) error {
return Recover(log, finalized, pending, validator, func(proposal *model.Proposal) error {
// add it to finalizer
err := finalizer.AddBlock(proposal.Block)
if err != nil {
return fmt.Errorf("could not add block to finalizer: %w", err)
}
log.Debug().
Uint64("block_view", proposal.Block.View).
Hex("block_id", proposal.Block.BlockID[:]).
Msg("block recovered")
return nil
})
}