@@ -329,6 +329,7 @@ Either the consensus client gave invalid information about finalized blocks or
329329something else needs attention! Shutting down to preserve the database - restart
330330with --debug-eager-state-root. """
331331
332+ base.txFrame.checkpoint (base.number, skipSnapshot = true )
332333 c.com.db.persist (base.txFrame)
333334
334335 # Update baseTxFrame when we about to yield to the event loop
@@ -484,7 +485,7 @@ proc validateBlock(c: ForkedChainRef,
484485 # Update the snapshot before processing the block so that any vertexes in snapshots
485486 # from lower levels than the baseTxFrame are removed from the snapshot before running
486487 # the stateroot computation.
487- c.updateSnapshot (blk, txFrame )
488+ c.updateSnapshot (parent. blk, parentFrame )
488489
489490 var receipts = c.processBlock (parent, txFrame, blk, blkHash, finalized).valueOr:
490491 txFrame.dispose ()
@@ -634,7 +635,7 @@ proc init*(
634635
635636 fc
636637
637- proc importBlock * (c: ForkedChainRef , blk: Block , finalized = false ):
638+ proc importBlock * (c: ForkedChainRef , blk: Block ):
638639 Future [Result [void , string ]] {.async : (raises: [CancelledError ]).} =
639640 # # Try to import block to canonical or side chain.
640641 # # return error if the block is invalid
@@ -655,9 +656,13 @@ proc importBlock*(c: ForkedChainRef, blk: Block, finalized = false):
655656 # to a "staging area" or disk-backed memory but it must not afect `base`.
656657 # `base` is the point of no return, we only update it on finality.
657658
658- let parent = ? (await c.validateBlock (parent, blk, finalized))
659+ # Setting the finalized flag to true here has the effect of skipping the
660+ # stateroot check for performance reasons.
661+ let
662+ isFinalized = blk.header.number <= c.latestFinalizedBlockNumber
663+ parent = ? (await c.validateBlock (parent, blk, isFinalized))
659664 if c.quarantine.hasOrphans ():
660- c.queueOrphan (parent, finalized )
665+ c.queueOrphan (parent, isFinalized )
661666
662667 else :
663668 # If its parent is an invalid block
@@ -730,9 +735,9 @@ proc stopProcessingQueue*(c: ForkedChainRef) {.async: (raises: []).} =
730735 # at the same time FC.serialize modify the state, crash can happen.
731736 await noCancel c.processingQueueLoop.cancelAndWait ()
732737
733- template queueImportBlock * (c: ForkedChainRef , blk: Block , finalized = false ): auto =
738+ template queueImportBlock * (c: ForkedChainRef , blk: Block ): auto =
734739 proc asyncHandler (): Future [Result [void , string ]] {.async : (raises: [CancelledError ], raw: true ).} =
735- c.importBlock (blk, finalized )
740+ c.importBlock (blk)
736741
737742 let item = QueueItem (
738743 responseFut: Future [Result [void , string ]].Raising ([CancelledError ]).init (),
0 commit comments