diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index d3ea3d0fea5..434e213ddd1 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -122,8 +122,8 @@ the previous head state.*/ ? null : _preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token); (Block processedBlock, TxReceipt[] receipts) = ProcessOne(suggestedBlock, options, blockTracer); + // Block is processed, we can cancel the prewarm task cancellationTokenSource.Cancel(); - preWarmTask?.GetAwaiter().GetResult(); processedBlocks[i] = processedBlock; // be cautious here as AuRa depends on processing @@ -147,6 +147,8 @@ the previous head state.*/ } preBlockStateRoot = processedBlock.StateRoot; + // Make sure the prewarm task is finished before we reset the state + preWarmTask?.GetAwaiter().GetResult(); _stateProvider.Reset(resizeCollections: true); }