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

Method CommitAppliedBlock

protocol/block.go:56–71  ·  view source on GitHub ↗

CommitAppliedBlock takes a block, commits it to persistent storage and sets c's state. Unlike CommitBlock, it accepts an already applied snapshot. CommitAppliedBlock is idempotent.

(ctx context.Context, block *bc.Block, snapshot *state.Snapshot)

Source from the content-addressed store, hash-verified

54// sets c's state. Unlike CommitBlock, it accepts an already applied
55// snapshot. CommitAppliedBlock is idempotent.
56func (c *Chain) CommitAppliedBlock(ctx context.Context, block *bc.Block, snapshot *state.Snapshot) error {
57 err := c.store.SaveBlock(ctx, block)
58 if err != nil {
59 return errors.Wrap(err, "storing block")
60 }
61 curState := c.State()
62
63 // CommitAppliedBlock needs to be idempotent. If block's height is less than or
64 // equal to c's current block, then it was already applied. Because
65 // SaveBlock didn't error with a conflict, we know it's not a different
66 // block at the same height.
67 if block.Height <= curState.Height() {
68 return nil
69 }
70 return c.finalizeCommitState(ctx, snapshot)
71}
72
73// CommitBlock takes a block, commits it to persistent storage and applies
74// it to c. CommitBlock is idempotent. A duplicate call with a previously

Callers 7

RecoverMethod · 0.95
NewChainFunction · 0.95
newTestChainFunction · 0.80
MakeBlockFunction · 0.80

Calls 5

StateMethod · 0.95
finalizeCommitStateMethod · 0.95
WrapFunction · 0.92
SaveBlockMethod · 0.65
HeightMethod · 0.65

Tested by 4

newTestChainFunction · 0.64