diff --git a/execution_chain/core/chain/forked_chain.nim b/execution_chain/core/chain/forked_chain.nim index 38e546d656..9fdb7676a3 100644 --- a/execution_chain/core/chain/forked_chain.nim +++ b/execution_chain/core/chain/forked_chain.nim @@ -200,10 +200,6 @@ proc removeBlockFromCache(c: ForkedChainRef, b: BlockRef) = for tx in b.blk.transactions: c.txRecords.del(computeRlpHash(tx)) - for v in c.lastSnapshots.mitems(): - if v == b.txFrame: - v = nil - b.blk.reset b.receipts.reset b.txFrame.dispose() @@ -482,10 +478,13 @@ proc validateBlock(c: ForkedChainRef, parentTxFrame=cast[uint](parentFrame), txFrame=cast[uint](txFrame) - # Update the snapshot before processing the block so that any vertexes in snapshots + # Checkpoint creates a snapshot of ancestor changes in txFrame - it is an + # expensive operation, specially when creating a new branch (ie when blk + # is being applied to a block that is currently not a head). + # Create the snapshot before processing the block so that any vertexes in snapshots # from lower levels than the baseTxFrame are removed from the snapshot before running # the stateroot computation. - c.updateSnapshot(parent.blk, parentFrame) + parentFrame.checkpoint(parent.blk.header.number, skipSnapshot = false) var receipts = c.processBlock(parent, txFrame, blk, blkHash, finalized).valueOr: txFrame.dispose() diff --git a/execution_chain/core/chain/forked_chain/chain_desc.nim b/execution_chain/core/chain/forked_chain/chain_desc.nim index 2e831fb2ce..76f017f07f 100644 --- a/execution_chain/core/chain/forked_chain/chain_desc.nim +++ b/execution_chain/core/chain/forked_chain/chain_desc.nim @@ -67,11 +67,6 @@ type # User can query for block state while it is still in memory. # Any state older than base block are purged. - lastSnapshots*: array[10, CoreDbTxRef] - lastSnapshotPos*: int - # The snapshot contains the cumulative changes of all ancestors and - # txFrame allowing the lookup recursion to stop whenever it is encountered. - eagerStateRoot*: bool pendingFCU* : Hash32 diff --git a/execution_chain/core/chain/forked_chain/chain_private.nim b/execution_chain/core/chain/forked_chain/chain_private.nim index 4407dff9a4..7360f2bb66 100644 --- a/execution_chain/core/chain/forked_chain/chain_private.nim +++ b/execution_chain/core/chain/forked_chain/chain_private.nim @@ -35,26 +35,6 @@ proc writeBaggage*(c: ForkedChainRef, header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"), blk.withdrawals.get) -template updateSnapshot*(c: ForkedChainRef, - blk: Block, - txFrame: CoreDbTxRef) = - let pos = c.lastSnapshotPos - c.lastSnapshotPos = (c.lastSnapshotPos + 1) mod c.lastSnapshots.len - if not isNil(c.lastSnapshots[pos]): - # Put a cap on frame memory usage by clearing out the oldest snapshots - - # this works at the expense of making building on said branches slower. - # 10 is quite arbitrary. - c.lastSnapshots[pos].clearSnapshot() - c.lastSnapshots[pos] = nil - - # Block fully written to txFrame, mark it as such - # Checkpoint creates a snapshot of ancestor changes in txFrame - it is an - # expensive operation, specially when creating a new branch (ie when blk - # is being applied to a block that is currently not a head) - txFrame.checkpoint(blk.header.number) - - c.lastSnapshots[pos] = txFrame - proc processBlock*(c: ForkedChainRef, parentBlk: BlockRef, txFrame: CoreDbTxRef, diff --git a/execution_chain/core/chain/forked_chain/chain_serialize.nim b/execution_chain/core/chain/forked_chain/chain_serialize.nim index a18e72532a..e9f7fc9c76 100644 --- a/execution_chain/core/chain/forked_chain/chain_serialize.nim +++ b/execution_chain/core/chain/forked_chain/chain_serialize.nim @@ -126,10 +126,13 @@ proc replayBlock(fc: ForkedChainRef; parentFrame = parent.txFrame txFrame = parentFrame.txFrameBegin() - # Update the snapshot before processing the block so that any vertexes in snapshots + # Checkpoint creates a snapshot of ancestor changes in txFrame - it is an + # expensive operation, specially when creating a new branch (ie when blk + # is being applied to a block that is currently not a head). + # Create the snapshot before processing the block so that any vertexes in snapshots # from lower levels than the baseTxFrame are removed from the snapshot before running # the stateroot computation. - fc.updateSnapshot(parent.blk, parentFrame) + parentFrame.checkpoint(parent.blk.header.number, skipSnapshot = false) # Set finalized to true in order to skip the stateroot check when replaying the # block because the blocks should have already been checked previously during