Skip to content
Closed
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: 10 additions & 1 deletion execution_chain/core/chain/forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ proc updateBase(c: ForkedChainRef, base: BlockRef): uint =
return

let startTime = Moment.now()
block:
# Write block contents to txFrame at the last moment - otherwise, they would
# stay both in BlockRef and TxFrame memory
# TODO probably makes sense to do it the other way around, removing blk
# from BlockRef
var blk = base
while blk.isOk:
c.writeBaggage(blk.blk, blk.hash, blk.txFrame, blk.receipts)
blk = blk.parent

# State root sanity check is performed to verify, before writing to disk,
# that optimistically checked blocks indeed end up being stored with a
Expand Down Expand Up @@ -513,7 +522,7 @@ proc validateBlock(c: ForkedChainRef,
# Update 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)
c.updateSnapshot(parent.blk.header.number, parentFrame)

var receipts = c.processBlock(parent, txFrame, blk, blkHash, finalized).valueOr:
txFrame.dispose()
Expand Down
6 changes: 3 additions & 3 deletions execution_chain/core/chain/forked_chain/chain_private.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ proc writeBaggage*(c: ForkedChainRef,
header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"),
blk.withdrawals.get)

template updateSnapshot*(c: ForkedChainRef,
blk: Block,
proc updateSnapshot*(c: ForkedChainRef,
number: BlockNumber,
txFrame: CoreDbTxRef) =
let pos = c.lastSnapshotPos
c.lastSnapshotPos = (c.lastSnapshotPos + 1) mod c.lastSnapshots.len
Expand All @@ -51,7 +51,7 @@ template updateSnapshot*(c: ForkedChainRef,
# 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)
txFrame.checkpoint(number)

c.lastSnapshots[pos] = txFrame

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ proc replayBlock(fc: ForkedChainRef;
# Update 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)
fc.updateSnapshot(parent.blk.header.number, parentFrame)

# 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