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)
| 54 | // sets c's state. Unlike CommitBlock, it accepts an already applied |
| 55 | // snapshot. CommitAppliedBlock is idempotent. |
| 56 | func (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 |