MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / tryFinalizeCommit

Method tryFinalizeCommit

consensus/state.go:1539–1564  ·  view source on GitHub ↗

If we have the block AND +2/3 commits for it, finalize.

(height int64)

Source from the content-addressed store, hash-verified

1537
1538// If we have the block AND +2/3 commits for it, finalize.
1539func (cs *State) tryFinalizeCommit(height int64) {
1540 logger := cs.Logger.With("height", height)
1541
1542 if cs.Height != height {
1543 panic(fmt.Sprintf("tryFinalizeCommit() cs.Height: %v vs height: %v", cs.Height, height))
1544 }
1545
1546 blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
1547 if !ok || len(blockID.Hash) == 0 {
1548 logger.Error("failed attempt to finalize commit; there was no +2/3 majority or +2/3 was for nil")
1549 return
1550 }
1551
1552 if !cs.ProposalBlock.HashesTo(blockID.Hash) {
1553 // TODO: this happens every time if we're not a validator (ugly logs)
1554 // TODO: ^^ wait, why does it matter that we're a validator?
1555 logger.Debug(
1556 "failed attempt to finalize commit; we do not have the commit block",
1557 "proposal_block", log.NewLazyBlockHash(cs.ProposalBlock),
1558 "commit_block", blockID.Hash,
1559 )
1560 return
1561 }
1562
1563 cs.finalizeCommit(height)
1564}
1565
1566// Increment height and goto cstypes.RoundStepNewHeight
1567func (cs *State) finalizeCommit(height int64) {

Callers 2

enterCommitMethod · 0.95

Calls 8

finalizeCommitMethod · 0.95
NewLazyBlockHashFunction · 0.92
TwoThirdsMajorityMethod · 0.80
PrecommitsMethod · 0.80
WithMethod · 0.65
ErrorMethod · 0.65
DebugMethod · 0.65
HashesToMethod · 0.45

Tested by

no test coverage detected