-
Notifications
You must be signed in to change notification settings - Fork 178
/
participant.go
36 lines (30 loc) · 962 Bytes
/
participant.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/model"
"github.com/onflow/flow-go/model/flow"
)
// Participant recovers the HotStuff state for a consensus participant.
// It reads the pending blocks from storage and pass them to the input Forks
// instance to recover its state from before the restart.
func Participant(
log zerolog.Logger,
forks hotstuff.Forks,
voteAggregator hotstuff.VoteAggregator,
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.AddBlock(proposal.Block)
if err != nil {
return fmt.Errorf("could not add block to forks: %w", err)
}
// recovery the proposer's vote
_ = voteAggregator.StoreProposerVote(proposal.ProposerVote())
return nil
})
}