Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for state override parameter in some RPC methods #7362

Merged
merged 86 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
8c5f8ee
Moved `OverridableCodeInfoRepository` to Nethermind.Evm
alexb5dh Aug 20, 2024
5343927
Made state commit optional during overrides
alexb5dh Aug 20, 2024
d97caa4
Allow state overrides for `eth_call`, `eth_estimategas`
alexb5dh Aug 20, 2024
264056f
Allow state overrides for `trace_call`, `trace_callMany`
alexb5dh Aug 22, 2024
3c19b09
Simplify `eth_*` overriding code
alexb5dh Aug 22, 2024
aeaf7f0
Fix double serialization in RPC tests
alexb5dh Aug 23, 2024
c8fa006
Code cleanup
alexb5dh Aug 23, 2024
37eb5e3
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Aug 26, 2024
9a7094d
Allow state overrides for `debug_traceCall`
alexb5dh Aug 26, 2024
94c2618
Update supported methods to match Reth version
alexb5dh Sep 1, 2024
eb3700a
Added missing tests
alexb5dh Sep 1, 2024
58886b6
Normalize block error
alexb5dh Sep 2, 2024
76eea55
Tests fixes
alexb5dh Sep 3, 2024
1dee3c0
Adjust insufficient-balance handling when simulating transaction
alexb5dh Sep 3, 2024
363fdc9
Fix chain-id missing in one of the RPC transaction conversions
alexb5dh Sep 3, 2024
51d6aa6
Fix for `Eth_call_with_accessList` test
alexb5dh Sep 4, 2024
3e5f964
State overrides for `eth_call` using `SimulateTxExecutor`
alexb5dh Sep 4, 2024
4de78ab
State overrides for `eth_estimateGas` using `OverridableWorldState`
alexb5dh Sep 30, 2024
3e1d83a
Adjusted eth_estimateGas test values
alexb5dh Oct 2, 2024
18825c8
Simplify changes
alexb5dh Oct 2, 2024
d900a5a
Use custom `OverridableWorldStateManager`
alexb5dh Oct 2, 2024
95fb2ed
Simplify changes
alexb5dh Oct 2, 2024
b4df9a7
`eth_estimateGas` test improvements
alexb5dh Oct 2, 2024
8cbbe33
State overrides for `eth_call` using `OverridableWorldState`
alexb5dh Oct 2, 2024
e078fcf
`eth_call` test improvements
alexb5dh Oct 2, 2024
8930eba
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 3, 2024
4f9383d
Remove old implementation `stateOverride` parameters
alexb5dh Oct 3, 2024
5bf6c58
Code cleanup
alexb5dh Oct 3, 2024
bd28e70
Revert unneeded changes
alexb5dh Oct 3, 2024
a1bd302
Use `IOverridableCodeInfoRepository` interface instead of the impleme…
alexb5dh Oct 3, 2024
f8d8137
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 3, 2024
15f0e39
Get rid of `NotSupportedException`
alexb5dh Oct 3, 2024
f05b7d2
Revert "Get rid of `NotSupportedException`"
alexb5dh Oct 3, 2024
cc3cb4c
Simplify tests
alexb5dh Oct 3, 2024
82d7345
Update `trace_call` overrides tests
alexb5dh Oct 5, 2024
df1e146
Fix for "Account is null when updating storage hash" on code override
alexb5dh Oct 5, 2024
e35f7e4
[WIP] State overrides for `trace_call` using `OverridableWorldState`
alexb5dh Oct 5, 2024
c902a07
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 5, 2024
d4f75c5
Code cleanup
alexb5dh Oct 5, 2024
8b2bb68
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 8, 2024
606b569
Change `trace_call` and `trace_rawTransaction` to use specified block…
alexb5dh Oct 9, 2024
3c3f6b0
Test fix
alexb5dh Oct 11, 2024
dc9de8e
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 11, 2024
eba8bf0
Code cleanup
alexb5dh Oct 11, 2024
4ee4658
Fix unit tests
alexb5dh Oct 11, 2024
9c0244b
Switch to `ProcessingOptions.ForceState` instead of generating fake h…
alexb5dh Oct 11, 2024
023ab9c
Rename `ForceState` to `ForceSameBlock`
alexb5dh Oct 11, 2024
d01cf9c
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 11, 2024
e15e625
Change `debug_traceCall` to run on top of specified block instead of …
alexb5dh Oct 13, 2024
4596308
State overrides for `debug_traceCall` using `OverridableWorldState`
alexb5dh Oct 13, 2024
acefb56
Move `ReadOnlyTxProcessing*` changes to new `OverridableTxProcessing*…
alexb5dh Oct 14, 2024
b0ce7d4
Helper method `BuildAndOverride`
alexb5dh Oct 14, 2024
531cbe8
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 14, 2024
5758a4f
Code cleanup
alexb5dh Oct 14, 2024
34b27a3
Revert "Normalize block error"
alexb5dh Oct 14, 2024
fe60977
Simple build fix
alexb5dh Oct 14, 2024
c82c8f3
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 14, 2024
3e683cf
Fix tests
alexb5dh Oct 14, 2024
1651413
Code cleanup
alexb5dh Oct 15, 2024
e935178
Allow null `stateOverride` in `BuildAndOverride`
alexb5dh Oct 15, 2024
a54ac71
Rename `DebugModuleMockedTests` -> `DebugModuleTests`
alexb5dh Oct 15, 2024
78c379f
Tests for `debug_traceCall` state override
alexb5dh Oct 15, 2024
e0563c3
Few more `debug_*` tests
alexb5dh Oct 15, 2024
4c39610
Code cleanup
alexb5dh Oct 15, 2024
b70931b
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 16, 2024
fd5efaa
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 16, 2024
d7a8e8c
Add `OptimismOverridableTxProcessingEnv`
alexb5dh Oct 21, 2024
0650883
Remove `IReadOnlyTxProcessorSource` implementation from `OverridableT…
alexb5dh Oct 21, 2024
2754255
Code cleanup
alexb5dh Oct 21, 2024
63f0c9f
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 22, 2024
4e307c7
Code formatting
alexb5dh Oct 22, 2024
2a2e66d
Skip commit set validation in `OverlayTrieStore`
alexb5dh Oct 22, 2024
a5385c6
Clear in-memory database on `ResetOverrides`
alexb5dh Oct 22, 2024
5072a6f
Code cleanup
alexb5dh Oct 22, 2024
086e5b5
Use `TraceModuleFactory` to create module for `TraceRpcModuleTests`
alexb5dh Oct 22, 2024
54b3e89
Add state override storage test for trace_call
alexb5dh Oct 22, 2024
bdf2c84
Naming cleanup
alexb5dh Oct 22, 2024
aba3e6b
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 22, 2024
b6b656a
Fix DB cleanup
alexb5dh Oct 23, 2024
e872c4e
Create separate `OverridableWorldStateManager` per module
alexb5dh Oct 24, 2024
5d37f8b
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 24, 2024
4d82942
Code cleanup
alexb5dh Oct 24, 2024
92644b5
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Oct 30, 2024
2fa1c8e
Build fix
alexb5dh Oct 30, 2024
92809ff
PR fixes
alexb5dh Oct 30, 2024
8c8a6a2
Merge remote-tracking branch 'origin/master' into feature/rpc-state-o…
alexb5dh Nov 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
using Nethermind.Core.Attributes;
using Nethermind.Core.Crypto;
using Nethermind.Core.Test.Blockchain;
using Nethermind.Specs;
using Nethermind.Core.Test.Builders;
using Nethermind.Db;
using Nethermind.Evm.Tracing;
using Nethermind.Logging;
using Nethermind.State.Repositories;
using Nethermind.Db.Blooms;
using Nethermind.Evm;
using Nethermind.State;
using Nethermind.Trie;
using NSubstitute;
Expand Down Expand Up @@ -73,7 +70,8 @@ public void AllowToFail(Hash256 hash)
_allowedToFail.Add(hash);
}

public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions processingOptions, IBlockTracer blockTracer)
public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions processingOptions,
IBlockTracer blockTracer, Dictionary<Address, AccountOverride>? stateOverride)
{
if (blockTracer != NullBlockTracer.Instance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Blocks;
using Nethermind.Blockchain.Find;
Expand Down Expand Up @@ -74,12 +75,13 @@ public AuRaBlockProcessor(

public IAuRaValidator AuRaValidator { get; }

protected override TxReceipt[] ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options)
protected override TxReceipt[] ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options,
Dictionary<Address, AccountOverride>? stateOverride = null)
{
ValidateAuRa(block);
_contractRewriter?.RewriteContracts(block.Number, _stateProvider, _specProvider.GetSpec(block.Header));
AuRaValidator.OnBlockProcessingStart(block, options);
TxReceipt[] receipts = base.ProcessBlock(block, blockTracer, options);
TxReceipt[] receipts = base.ProcessBlock(block, blockTracer, options, stateOverride);
AuRaValidator.OnBlockProcessingEnd(block, receipts, options);
Metrics.AuRaStep = block.Header?.AuRaStep ?? 0;
return receipts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ event EventHandler<AddingTxEventArgs>? IBlockProductionTransactionsExecutor.Addi
}

public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions,
BlockReceiptsTracer receiptsTracer, IReleaseSpec spec)
BlockReceiptsTracer receiptsTracer, IReleaseSpec spec, Dictionary<Address, AccountOverride>? stateOverride = null)
{
IEnumerable<Transaction> transactions = GetTransactions(block);

Expand All @@ -79,8 +79,9 @@ public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions pr
BlockExecutionContext blkCtx = new(block.Header);
foreach (Transaction currentTx in transactions)
{
TxAction action = ProcessTransaction(block, in blkCtx, currentTx, i++, receiptsTracer, processingOptions, transactionsInBlock);
TxAction action = ProcessTransaction(block, in blkCtx, currentTx, i++, receiptsTracer, processingOptions, transactionsInBlock, stateOverride);
if (action == TxAction.Stop) break;
stateOverride = null; // Apply override only before the first transaction
}

_stateProvider.Commit(spec, receiptsTracer);
Expand All @@ -97,6 +98,7 @@ protected TxAction ProcessTransaction(
BlockReceiptsTracer receiptsTracer,
ProcessingOptions processingOptions,
LinkedHashSet<Transaction> transactionsInBlock,
Dictionary<Address, AccountOverride>? stateOverride = null,
bool addToBlock = true)
{
AddingTxEventArgs args =
Expand All @@ -109,7 +111,7 @@ protected TxAction ProcessTransaction(
}
else
{
TransactionResult result = _transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, _stateProvider);
TransactionResult result = _transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, _stateProvider, stateOverride);

if (result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand Down Expand Up @@ -30,24 +31,27 @@ public BlockValidationTransactionsExecutor(ITransactionProcessor transactionProc

public event EventHandler<TxProcessedEventArgs>? TransactionProcessed;

public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec)
public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer,
IReleaseSpec spec, Dictionary<Address, AccountOverride>? stateOverride = null)
{
Metrics.ResetBlockStats();
BlockExecutionContext blkCtx = CreateBlockExecutionContext(block);
for (int i = 0; i < block.Transactions.Length; i++)
{
block.TransactionProcessed = i;
Transaction currentTx = block.Transactions[i];
ProcessTransaction(in blkCtx, currentTx, i, receiptsTracer, processingOptions);
ProcessTransaction(in blkCtx, currentTx, i, receiptsTracer, processingOptions, stateOverride);
stateOverride = null; // Apply override only before the first transaction
}
return receiptsTracer.TxReceipts.ToArray();
}

protected virtual BlockExecutionContext CreateBlockExecutionContext(Block block) => new(block.Header);

protected virtual void ProcessTransaction(in BlockExecutionContext blkCtx, Transaction currentTx, int index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions)
protected virtual void ProcessTransaction(in BlockExecutionContext blkCtx, Transaction currentTx, int index, BlockReceiptsTracer receiptsTracer,
ProcessingOptions processingOptions, Dictionary<Address, AccountOverride>? stateOverride = null)
{
TransactionResult result = transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, stateProvider);
TransactionResult result = transactionProcessor.ProcessTransaction(in blkCtx, currentTx, receiptsTracer, processingOptions, stateProvider, stateOverride);
if (!result) ThrowInvalidBlockException(result, blkCtx.Header, currentTx, index);
TransactionProcessed?.Invoke(this, new TxProcessedEventArgs(index, currentTx, receiptsTracer.TxReceipts[index]));
}
Expand Down
16 changes: 10 additions & 6 deletions src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public event EventHandler<TxProcessedEventArgs> TransactionProcessed
}

// TODO: move to branch processor
public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions options, IBlockTracer blockTracer)
public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions options, IBlockTracer blockTracer,
Dictionary<Address, AccountOverride>? stateOverride = null)
{
if (suggestedBlocks.Count == 0) return Array.Empty<Block>();

Expand Down Expand Up @@ -121,7 +122,7 @@ the previous head state.*/
Task? preWarmTask = suggestedBlock.Transactions.Length < 3
? null
: _preWarmer?.PreWarmCaches(suggestedBlock, preBlockStateRoot!, cancellationTokenSource.Token);
(Block processedBlock, TxReceipt[] receipts) = ProcessOne(suggestedBlock, options, blockTracer);
(Block processedBlock, TxReceipt[] receipts) = ProcessOne(suggestedBlock, options, blockTracer, stateOverride);
// Block is processed, we can cancel the prewarm task
cancellationTokenSource.Cancel();
processedBlocks[i] = processedBlock;
Expand Down Expand Up @@ -214,13 +215,14 @@ private void RestoreBranch(Hash256 branchingPointStateRoot)
}

// TODO: block processor pipeline
private (Block Block, TxReceipt[] Receipts) ProcessOne(Block suggestedBlock, ProcessingOptions options, IBlockTracer blockTracer)
private (Block Block, TxReceipt[] Receipts) ProcessOne(Block suggestedBlock, ProcessingOptions options, IBlockTracer blockTracer,
Dictionary<Address, AccountOverride>? stateOverride)
{
if (_logger.IsTrace) _logger.Trace($"Processing block {suggestedBlock.ToString(Block.Format.Short)} ({options})");

ApplyDaoTransition(suggestedBlock);
Block block = PrepareBlockForProcessing(suggestedBlock);
TxReceipt[] receipts = ProcessBlock(block, blockTracer, options);
TxReceipt[] receipts = ProcessBlock(block, blockTracer, options, stateOverride);
ValidateProcessedBlock(suggestedBlock, options, block, receipts);
if (options.ContainsFlag(ProcessingOptions.StoreReceipts))
{
Expand Down Expand Up @@ -251,7 +253,9 @@ private bool ShouldComputeStateRoot(BlockHeader header) =>
protected virtual TxReceipt[] ProcessBlock(
Block block,
IBlockTracer blockTracer,
ProcessingOptions options)
ProcessingOptions options,
Dictionary<Address, AccountOverride>? stateOverride = null
)
{
IReleaseSpec spec = _specProvider.GetSpec(block.Header);

Expand All @@ -263,7 +267,7 @@ protected virtual TxReceipt[] ProcessBlock(

_stateProvider.Commit(spec, commitStorageRoots: false);

TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, ReceiptsTracer, spec);
TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, ReceiptsTracer, spec, stateOverride);

if (spec.IsEip4844Enabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
using System.Threading.Tasks;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Find;
using Nethermind.Config;
using Nethermind.Core;
using Nethermind.Core.Attributes;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
using Nethermind.Evm.Tracing.GethStyle;
using Nethermind.Evm.Tracing.ParityStyle;
Expand Down Expand Up @@ -313,7 +313,7 @@ private void RunProcessingLoop()

if (_logger.IsTrace) _logger.Trace($"Processing block {block.ToString(Block.Format.Short)}).");
_stats.Start();
Block processedBlock = Process(block, blockRef.ProcessingOptions, _compositeBlockTracer.GetTracer(), out string? error);
Block processedBlock = Process(block, blockRef.ProcessingOptions, _compositeBlockTracer.GetTracer(), null, out string? error);

if (processedBlock is null)
{
Expand Down Expand Up @@ -356,11 +356,12 @@ private void FireProcessingQueueEmpty()

int IBlockProcessingQueue.Count => _queueCount;

public Block? Process(Block suggestedBlock, ProcessingOptions options, IBlockTracer tracer)
public Block? Process(Block suggestedBlock, ProcessingOptions options, IBlockTracer tracer, Dictionary<Address, AccountOverride>? stateOverride = null)
{
return Process(suggestedBlock, options, tracer, out _);
return Process(suggestedBlock, options, tracer, stateOverride, out _);
}
public Block? Process(Block suggestedBlock, ProcessingOptions options, IBlockTracer tracer, out string? error)

public Block? Process(Block suggestedBlock, ProcessingOptions options, IBlockTracer tracer, Dictionary<Address, AccountOverride>? stateOverride, out string? error)
{
error = null;
if (!RunSimpleChecksAheadOfProcessing(suggestedBlock, options))
Expand Down Expand Up @@ -388,7 +389,7 @@ private void FireProcessingQueueEmpty()
PrepareBlocksToProcess(suggestedBlock, options, processingBranch);

_stopwatch.Restart();
Block[]? processedBlocks = ProcessBranch(processingBranch, options, tracer, out error);
Block[]? processedBlocks = ProcessBranch(processingBranch, options, tracer, stateOverride, out error);
if (processedBlocks is null)
{
return null;
Expand Down Expand Up @@ -475,7 +476,7 @@ private void TraceFailingBranch(in ProcessingBranch processingBranch, Processing
}
}

private Block[]? ProcessBranch(in ProcessingBranch processingBranch, ProcessingOptions options, IBlockTracer tracer, out string? error)
private Block[]? ProcessBranch(in ProcessingBranch processingBranch, ProcessingOptions options, IBlockTracer tracer, Dictionary<Address, AccountOverride>? stateOverride, out string? error)
{
void DeleteInvalidBlocks(in ProcessingBranch processingBranch, Hash256 invalidBlockHash)
{
Expand All @@ -499,7 +500,8 @@ void DeleteInvalidBlocks(in ProcessingBranch processingBranch, Hash256 invalidBl
processingBranch.Root,
processingBranch.BlocksToProcess,
options,
tracer);
tracer,
stateOverride);
error = null;
}
catch (InvalidBlockException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;

namespace Nethermind.Consensus.Processing
Expand All @@ -19,12 +20,13 @@ public interface IBlockProcessor
/// <param name="suggestedBlocks">List of blocks to be processed.</param>
/// <param name="processingOptions">Options to use for processor and transaction processor.</param>
/// <param name="blockTracer">Block tracer to use. By default either <see cref="NullBlockTracer"/> or <see cref="BlockReceiptsTracer"/></param>
/// <param name="stateOverride">Optional state overrides by address.</param>
/// <returns>List of processed blocks.</returns>
Block[] Process(
Hash256 newBranchStateRoot,
Block[] Process(Hash256 newBranchStateRoot,
List<Block> suggestedBlocks,
ProcessingOptions processingOptions,
IBlockTracer blockTracer);
IBlockTracer blockTracer,
Dictionary<Address, AccountOverride>? stateOverride = null);

/// <summary>
/// Fired when a branch is being processed.
Expand All @@ -43,7 +45,9 @@ Block[] Process(

public interface IBlockTransactionsExecutor
{
TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec);
TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec,
Dictionary<Address, AccountOverride>? stateOverride = null);

event EventHandler<TxProcessedEventArgs> TransactionProcessed;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Core;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;

namespace Nethermind.Consensus.Processing
Expand All @@ -16,7 +18,7 @@ public interface IBlockchainProcessor : IDisposable

Task StopAsync(bool processRemainingBlocks = false);

Block? Process(Block block, ProcessingOptions options, IBlockTracer tracer);
Block? Process(Block block, ProcessingOptions options, IBlockTracer tracer, Dictionary<Address, AccountOverride>? stateOverride = null);

bool IsProcessingBlocks(ulong? maxProcessingInterval);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;

namespace Nethermind.Consensus.Processing
Expand All @@ -15,7 +16,8 @@ private NullBlockProcessor() { }

public static IBlockProcessor Instance { get; } = new NullBlockProcessor();

public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions processingOptions, IBlockTracer blockTracer)
public Block[] Process(Hash256 newBranchStateRoot, List<Block> suggestedBlocks, ProcessingOptions processingOptions, IBlockTracer blockTracer,
Dictionary<Address, AccountOverride>? stateOverride)
{
return suggestedBlocks.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Core;
using Nethermind.Db;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
using Nethermind.State;

Expand Down Expand Up @@ -35,11 +36,11 @@ public Task StopAsync(bool processRemainingBlocks = false)
return _processor.StopAsync(processRemainingBlocks);
}

public Block? Process(Block block, ProcessingOptions options, IBlockTracer tracer)
public Block? Process(Block block, ProcessingOptions options, IBlockTracer tracer, Dictionary<Address, AccountOverride> stateOverride)
{
lock (_lock)
{
return _processor.Process(block, options, tracer);
return _processor.Process(block, options, tracer, stateOverride);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected ITransactionProcessor TransactionProcessor

public IVirtualMachine Machine { get; }

public ICodeInfoRepository CodeInfoRepository { get; }
public OverridableCodeInfoRepository CodeInfoRepository { get; }
public ReadOnlyTxProcessingEnv(
IWorldStateManager worldStateManager,
IBlockTree blockTree,
Expand All @@ -48,7 +48,7 @@ public ReadOnlyTxProcessingEnv(
IWorldState? worldStateToWarmUp = null
) : base(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp)
{
CodeInfoRepository = new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache);
CodeInfoRepository = new(new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache));
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree));
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using Nethermind.Core;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
Expand All @@ -16,15 +17,16 @@ public static TransactionResult ProcessTransaction(this ITransactionProcessorAda
Transaction currentTx,
BlockReceiptsTracer receiptsTracer,
ProcessingOptions processingOptions,
IWorldState stateProvider)
IWorldState stateProvider,
Dictionary<Address, AccountOverride>? stateOverride)
{
if (processingOptions.ContainsFlag(ProcessingOptions.DoNotVerifyNonce))
{
currentTx.Nonce = stateProvider.GetNonce(currentTx.SenderAddress!);
}

using ITxTracer tracer = receiptsTracer.StartNewTxTrace(currentTx);
TransactionResult result = transactionProcessor.Execute(currentTx, in blkCtx, receiptsTracer);
TransactionResult result = transactionProcessor.Execute(currentTx, in blkCtx, receiptsTracer, stateOverride);
receiptsTracer.EndTxTrace();
return result;
}
Expand Down
Loading