-
Notifications
You must be signed in to change notification settings - Fork 175
/
participant.go
39 lines (33 loc) · 1.02 KB
/
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
37
38
39
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
err = voteAggregator.AddBlock(proposal)
if err != nil {
return fmt.Errorf("could not process proposal %v: %w", proposal.Block.BlockID, err)
}
return nil
})
}