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

Method finalizeCommit

consensus/state.go:1567–1700  ·  view source on GitHub ↗

Increment height and goto cstypes.RoundStepNewHeight

(height int64)

Source from the content-addressed store, hash-verified

1565
1566// Increment height and goto cstypes.RoundStepNewHeight
1567func (cs *State) finalizeCommit(height int64) {
1568 logger := cs.Logger.With("height", height)
1569
1570 if cs.Height != height || cs.Step != cstypes.RoundStepCommit {
1571 logger.Debug(
1572 "entering finalize commit step",
1573 "current", log.NewLazySprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step),
1574 )
1575 return
1576 }
1577
1578 cs.calculatePrevoteMessageDelayMetrics()
1579
1580 blockID, ok := cs.Votes.Precommits(cs.CommitRound).TwoThirdsMajority()
1581 block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts
1582
1583 if !ok {
1584 panic("cannot finalize commit; commit does not have 2/3 majority")
1585 }
1586 if !blockParts.HasHeader(blockID.PartSetHeader) {
1587 panic("expected ProposalBlockParts header to be commit header")
1588 }
1589 if !block.HashesTo(blockID.Hash) {
1590 panic("cannot finalize commit; proposal block does not hash to commit hash")
1591 }
1592
1593 if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil {
1594 panic(fmt.Errorf("+2/3 committed an invalid block: %w", err))
1595 }
1596
1597 logger.Info(
1598 "finalizing commit of block",
1599 "hash", log.NewLazyBlockHash(block),
1600 "root", block.AppHash,
1601 "num_txs", len(block.Txs),
1602 )
1603 logger.Debug("committed block", "block", log.NewLazySprintf("%v", block))
1604
1605 fail.Fail() // XXX
1606
1607 // Save to blockStore.
1608 if cs.blockStore.Height() < block.Height {
1609 // NOTE: the seenCommit is local justification to commit this block,
1610 // but may differ from the LastCommit included in the next block
1611 precommits := cs.Votes.Precommits(cs.CommitRound)
1612 seenCommit := precommits.MakeCommit()
1613 cs.blockStore.SaveBlock(block, blockParts, seenCommit)
1614 } else {
1615 // Happens during replay if we already saved the block but didn't commit
1616 logger.Debug("calling finalizeCommit on already stored block", "height", block.Height)
1617 }
1618
1619 fail.Fail() // XXX
1620
1621 // Write EndHeightMessage{} for this height, implying that the blockstore
1622 // has saved the block.
1623 //
1624 // If we crash before writing this EndHeightMessage{}, we will recover by

Callers 1

tryFinalizeCommitMethod · 0.95

Calls 15

pruneBlocksMethod · 0.95
recordMetricsMethod · 0.95
updateToStateMethod · 0.95
scheduleRound0Method · 0.95
NewLazySprintfFunction · 0.92
NewLazyBlockHashFunction · 0.92
FailFunction · 0.92
TwoThirdsMajorityMethod · 0.80
PrecommitsMethod · 0.80
HasHeaderMethod · 0.80

Tested by

no test coverage detected