MCPcopy Index your code
hub / github.com/chain/txvm / finalizeCommitState

Method finalizeCommitState

protocol/block.go:105–122  ·  view source on GitHub ↗
(ctx context.Context, snapshot *state.Snapshot)

Source from the content-addressed store, hash-verified

103}
104
105func (c *Chain) finalizeCommitState(ctx context.Context, snapshot *state.Snapshot) error {
106 // Save the blockchain state tree snapshot to persistent storage
107 // if we haven't done it recently.
108 lastQueuedHeight := atomic.LoadUint64(&c.lastQueuedSnapshotHeight)
109 if lastQueuedHeight+c.blocksPerSnapshot <= snapshot.Height() {
110 c.queueSnapshot(ctx, snapshot)
111 }
112 // setState will update c's current block and snapshot, or no-op
113 // if another goroutine has already updated the state.
114 c.setState(snapshot)
115
116 // The below FinalizeHeight will notify other cored processes that
117 // the a new block has been committed. It may result in a duplicate
118 // attempt to update c's height but setState and setHeight safely
119 // ignore duplicate heights.
120 err := c.store.FinalizeHeight(ctx, snapshot.Height())
121 return errors.Wrap(err, "finalizing block")
122}
123
124func (c *Chain) queueSnapshot(ctx context.Context, s *state.Snapshot) {
125 // Non-blockingly queue the snapshot for storage.

Callers 2

CommitAppliedBlockMethod · 0.95
CommitBlockMethod · 0.95

Calls 5

queueSnapshotMethod · 0.95
setStateMethod · 0.95
WrapFunction · 0.92
HeightMethod · 0.65
FinalizeHeightMethod · 0.65

Tested by

no test coverage detected