/
state_enter_commit.go
70 lines (58 loc) · 1.95 KB
/
state_enter_commit.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package consensus
import (
"context"
cstypes "github.com/dashpay/tenderdash/internal/consensus/types"
"github.com/dashpay/tenderdash/libs/log"
tmtime "github.com/dashpay/tenderdash/libs/time"
)
type EnterCommitEvent struct {
Height int64
CommitRound int32
}
// GetType returns EnterCommitType event-type
func (e *EnterCommitEvent) GetType() EventType {
return EnterCommitType
}
// EnterCommitAction ...
// Enter: +2/3 precommits for block
type EnterCommitAction struct {
logger log.Logger
eventPublisher *EventPublisher
proposalUpdater *proposalUpdater
metrics *Metrics
}
// Execute ...
func (c *EnterCommitAction) Execute(ctx context.Context, stateEvent StateEvent) error {
event := stateEvent.Data.(*EnterCommitEvent)
stateData := stateEvent.StateData
height := event.Height
commitRound := event.CommitRound
logger := c.logger.With("new_height", height, "commit_round", commitRound)
if stateData.Height != height || cstypes.RoundStepApplyCommit <= stateData.Step {
// this is quite common event
logger.Trace("entering commit step with invalid args",
"height", stateData.Height,
"round", stateData.Round,
"step", stateData.Step)
return nil
}
logger.Debug("entering commit step",
"height", stateData.Height,
"round", stateData.Round,
"step", stateData.Step)
defer func() {
// Done enterCommit:
// keep c.Round the same, commitRound points to the right Precommits set.
stateData.updateRoundStep(stateData.Round, cstypes.RoundStepApplyCommit)
stateData.CommitRound = commitRound
stateData.CommitTime = tmtime.Now()
c.eventPublisher.PublishNewRoundStepEvent(stateData.RoundState)
// Maybe finalize immediately.
_ = stateEvent.Ctrl.Dispatch(ctx, &TryFinalizeCommitEvent{Height: height}, stateData)
}()
blockID, ok := stateData.Votes.Precommits(commitRound).TwoThirdsMajority()
if !ok {
panic("RunActionCommit() expects +2/3 precommits")
}
return c.proposalUpdater.updateStateData(stateData, blockID)
}