(ctx context.Context, snapshot *state.Snapshot)
| 103 | } |
| 104 | |
| 105 | func (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 | |
| 124 | func (c *Chain) queueSnapshot(ctx context.Context, s *state.Snapshot) { |
| 125 | // Non-blockingly queue the snapshot for storage. |
no test coverage detected