Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions execution_chain/core/chain/forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions execution_chain/core/chain/forked_chain/chain_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions execution_chain/core/chain/forked_chain/chain_private.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions execution_chain/core/chain/forked_chain/chain_serialize.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down