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 all 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
9 changes: 5 additions & 4 deletions src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public NethermindApi(IConfigProvider configProvider, IJsonSerializer jsonSeriali
public IBlockchainBridge CreateBlockchainBridge()
{
ReadOnlyBlockTree readOnlyTree = BlockTree!.AsReadOnly();
OverridableWorldStateManager overridableWorldStateManager = new(DbProvider!, WorldStateManager!.TrieStore, LogManager);

// TODO: reuse the same trie cache here
ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new(
WorldStateManager!,
OverridableTxProcessingEnv txProcessingEnv = new(
overridableWorldStateManager,
readOnlyTree,
SpecProvider,
SpecProvider!,
LogManager);

SimulateReadOnlyBlocksProcessingEnvFactory simulateReadOnlyBlocksProcessingEnvFactory =
Expand All @@ -97,7 +98,7 @@ public IBlockchainBridge CreateBlockchainBridge()
IBlocksConfig blocksConfig = ConfigProvider.GetConfig<IBlocksConfig>();

return new BlockchainBridge(
readOnlyTxProcessingEnv,
txProcessingEnv,
simulateReadOnlyBlocksProcessingEnvFactory,
TxPool,
ReceiptFinder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,10 @@ private ProcessingBranch PrepareProcessingBranch(Block suggestedBlock, Processin
break;
}

branchingPoint = _blockTree.FindParentHeader(toBeProcessed.Header,
BlockTreeLookupOptions.TotalDifficultyNotNeeded);
branchingPoint = options.ContainsFlag(ProcessingOptions.ForceSameBlock)
? toBeProcessed.Header
: _blockTree.FindParentHeader(toBeProcessed.Header, BlockTreeLookupOptions.TotalDifficultyNotNeeded);

if (branchingPoint is null)
{
// genesis block
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using Nethermind.Blockchain;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Evm;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Logging;
using Nethermind.State;

namespace Nethermind.Consensus.Processing;

public class OverridableTxProcessingEnv : ReadOnlyTxProcessingEnvBase, IOverridableTxProcessorSource
{
private readonly Lazy<ITransactionProcessor> _transactionProcessorLazy;

protected new OverridableWorldState StateProvider { get; }
protected OverridableWorldStateManager WorldStateManager { get; }
protected OverridableCodeInfoRepository CodeInfoRepository { get; }
protected IVirtualMachine Machine { get; }
protected ITransactionProcessor TransactionProcessor => _transactionProcessorLazy.Value;

public OverridableTxProcessingEnv(
OverridableWorldStateManager worldStateManager,
IReadOnlyBlockTree readOnlyBlockTree,
ISpecProvider specProvider,
ILogManager? logManager,
IWorldState? worldStateToWarmUp = null
) : base(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp)
{
WorldStateManager = worldStateManager;
StateProvider = (OverridableWorldState)base.StateProvider;
CodeInfoRepository = new(new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache));
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager);
_transactionProcessorLazy = new(CreateTransactionProcessor);
}

protected virtual ITransactionProcessor CreateTransactionProcessor() =>
new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, LogManager);

IOverridableTxProcessingScope IOverridableTxProcessorSource.Build(Hash256 stateRoot) => Build(stateRoot);

public OverridableTxProcessingScope Build(Hash256 stateRoot)
{
Hash256 originalStateRoot = StateProvider.StateRoot;
StateProvider.StateRoot = stateRoot;
return new(CodeInfoRepository, TransactionProcessor, StateProvider, originalStateRoot);
}

IOverridableTxProcessingScope IOverridableTxProcessorSource.BuildAndOverride(BlockHeader header, Dictionary<Address, AccountOverride>? stateOverride)
{
OverridableTxProcessingScope scope = Build(header.StateRoot ?? throw new ArgumentException($"Block {header.Hash} state root is null", nameof(header)));
if (stateOverride != null)
{
scope.WorldState.ApplyStateOverrides(scope.CodeInfoRepository, stateOverride, SpecProvider.GetSpec(header), header.Number);
header.StateRoot = scope.WorldState.StateRoot;
}
return scope;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core.Crypto;
using Nethermind.Evm;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.State;

namespace Nethermind.Consensus.Processing;

public class OverridableTxProcessingScope(
IOverridableCodeInfoRepository codeInfoRepository,
ITransactionProcessor transactionProcessor,
OverridableWorldState worldState,
Hash256 originalStateRoot
) : IOverridableTxProcessingScope
{
public IOverridableCodeInfoRepository CodeInfoRepository => codeInfoRepository;
public ITransactionProcessor TransactionProcessor => transactionProcessor;
public IWorldState WorldState => worldState;

public void Dispose()
{
worldState.StateRoot = originalStateRoot;
worldState.Reset();
worldState.ResetOverrides();
codeInfoRepository.ResetOverrides();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public enum ProcessingOptions
/// </summary>
MarkAsProcessed = 128,

All = 255,
/// <summary>
/// Forces to run on top of the specified block state, instead of reverting to the previous one.
/// </summary>
ForceSameBlock = 1 << 8,

/// <summary>
/// Combination of switches for block producers when they preprocess block for state root calculation.
Expand All @@ -63,6 +66,12 @@ public enum ProcessingOptions
/// </summary>
Trace = ForceProcessing | ReadOnlyChain | DoNotVerifyNonce | NoValidation,

/// <summary>
/// EVM tracing needs to process one or more transactions on top of the specified block (instead of the previous one)
/// without storing the data on chain.
/// </summary>
TraceTransactions = Trace | ForceSameBlock,

/// <summary>
/// Processing options for engine_NewPayload
/// </summary>
Expand Down
16 changes: 12 additions & 4 deletions src/Nethermind/Nethermind.Consensus/Tracing/GethStyleTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
using Nethermind.Evm.Tracing.GethStyle;
using Nethermind.Evm.Tracing.GethStyle.Custom.JavaScript;
Expand All @@ -36,6 +37,7 @@ public class GethStyleTracer : IGethStyleTracer
private readonly IWorldState _worldState;
private readonly IReceiptStorage _receiptStorage;
private readonly IFileSystem _fileSystem;
private readonly IOverridableTxProcessorSource _env;

public GethStyleTracer(IBlockchainProcessor processor,
IWorldState worldState,
Expand All @@ -44,7 +46,8 @@ public GethStyleTracer(IBlockchainProcessor processor,
IBadBlockStore badBlockStore,
ISpecProvider specProvider,
ChangeableTransactionProcessorAdapter transactionProcessorAdapter,
IFileSystem fileSystem)
IFileSystem fileSystem,
IOverridableTxProcessorSource env)
{
_processor = processor ?? throw new ArgumentNullException(nameof(processor));
_worldState = worldState;
Expand All @@ -54,6 +57,7 @@ public GethStyleTracer(IBlockchainProcessor processor,
_specProvider = specProvider;
_transactionProcessorAdapter = transactionProcessorAdapter;
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
_env = env ?? throw new ArgumentNullException(nameof(env));
}

public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions options, CancellationToken cancellationToken)
Expand Down Expand Up @@ -82,7 +86,10 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op

try
{
return Trace(block, tx.Hash, cancellationToken, options);
Dictionary<Address, AccountOverride>? stateOverride = options.StateOverrides;
using IOverridableTxProcessingScope? scope = stateOverride != null ? _env.BuildAndOverride(block.Header, stateOverride) : null;

return Trace(block, tx.Hash, cancellationToken, options, ProcessingOptions.TraceTransactions);
}
finally
{
Expand Down Expand Up @@ -189,15 +196,16 @@ public IEnumerable<string> TraceBadBlockToFile(Hash256 blockHash, GethTraceOptio
return tracer.FileNames;
}

private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options)
private GethLikeTxTrace? Trace(Block block, Hash256? txHash, CancellationToken cancellationToken, GethTraceOptions options,
ProcessingOptions processingOptions = ProcessingOptions.Trace)
{
ArgumentNullException.ThrowIfNull(txHash);

IBlockTracer<GethLikeTxTrace> tracer = CreateOptionsTracer(block.Header, options with { TxHash = txHash });

try
{
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken));
_processor.Process(block, processingOptions, tracer.WithCancellation(cancellationToken));
return tracer.BuildResult().SingleOrDefault();
}
catch
Expand Down
16 changes: 9 additions & 7 deletions src/Nethermind/Nethermind.Consensus/Tracing/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ public class Tracer : ITracer
private readonly IWorldState _stateProvider;
private readonly IBlockchainProcessor _traceProcessor;
private readonly IBlockchainProcessor _executeProcessor;
private readonly ProcessingOptions _processingOptions;
private readonly ProcessingOptions _executeOptions;
private readonly ProcessingOptions _traceOptions;

public Tracer(IWorldState stateProvider, IBlockchainProcessor traceProcessor, IBlockchainProcessor executeProcessor,
ProcessingOptions processingOptions = ProcessingOptions.Trace)
ProcessingOptions executeOptions = ProcessingOptions.Trace, ProcessingOptions traceOptions = ProcessingOptions.Trace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't Execute be always Trace
And Trace be always TraceTransaction
And we don't need the parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When created in TraceModuleFactory, traceOptions should be ProcessingOptions.TraceTransactions, so we don't rollback to previous block on some methods. For ProofRpcModule/ProofModuleFactory I decided to leave it as is for now - default ProcessingOptions.Trace.

executeOptions parameter was added just for the symmetry.

{
_traceProcessor = traceProcessor;
_executeProcessor = executeProcessor;
_stateProvider = stateProvider;
_processingOptions = processingOptions;
_executeOptions = executeOptions;
_traceOptions = traceOptions;
}

private void Process(Block block, IBlockTracer blockTracer, IBlockchainProcessor processor)
private void Process(Block block, IBlockTracer blockTracer, IBlockchainProcessor processor, ProcessingOptions options)
{
/* We force process since we want to process a block that has already been processed in the past and normally it would be ignored.
We also want to make it read only so the state is not modified persistently in any way. */
Expand All @@ -36,7 +38,7 @@ We also want to make it read only so the state is not modified persistently in a

try
{
processor.Process(block, _processingOptions, blockTracer);
processor.Process(block, options, blockTracer);
}
catch (Exception)
{
Expand All @@ -47,9 +49,9 @@ We also want to make it read only so the state is not modified persistently in a
blockTracer.EndBlockTrace();
}

public void Trace(Block block, IBlockTracer tracer) => Process(block, tracer, _traceProcessor);
public void Trace(Block block, IBlockTracer tracer) => Process(block, tracer, _traceProcessor, _traceOptions);

public void Execute(Block block, IBlockTracer tracer) => Process(block, tracer, _executeProcessor);
public void Execute(Block block, IBlockTracer tracer) => Process(block, tracer, _executeProcessor, _executeOptions);

public void Accept(ITreeVisitor visitor, Hash256 stateRoot)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public IBlockFinder BlockFinder
public IWorldState State { get; set; } = null!;
public IReadOnlyStateProvider ReadOnlyState { get; private set; } = null!;
public IDb StateDb => DbProvider.StateDb;
public IDb BlocksDb => DbProvider.BlocksDb;
public TrieStore TrieStore { get; set; } = null!;
public IBlockProducer BlockProducer { get; private set; } = null!;
public IBlockProducerRunner BlockProducerRunner { get; protected set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Nethermind.Core.Crypto;
using Nethermind.Int256;

namespace Nethermind.Facade.Proxy.Models;
namespace Nethermind.Evm;

public class AccountOverride
{
Expand Down
15 changes: 15 additions & 0 deletions src/Nethermind/Nethermind.Evm/IOverridableCodeInfoRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Evm.CodeAnalysis;
using Nethermind.State;

namespace Nethermind.Evm;

public interface IOverridableCodeInfoRepository : ICodeInfoRepository
{
void SetCodeOverwrite(IWorldState worldState, IReleaseSpec vmSpec, Address key, CodeInfo value, Address? redirectAddress = null);
public void ResetOverrides();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Evm;
using Nethermind.Evm.CodeAnalysis;
using Nethermind.State;

namespace Nethermind.Facade;
namespace Nethermind.Evm;

public class OverridableCodeInfoRepository(ICodeInfoRepository codeInfoRepository) : ICodeInfoRepository
public class OverridableCodeInfoRepository(ICodeInfoRepository codeInfoRepository) : IOverridableCodeInfoRepository
{
private readonly Dictionary<Address, CodeInfo> _codeOverwrites = new();

Expand Down Expand Up @@ -51,4 +50,6 @@ public bool TryGetDelegation(IReadOnlyStateProvider worldState, Address address,

public ValueHash256 GetExecutableCodeHash(IWorldState worldState, Address address) =>
codeInfoRepository.GetExecutableCodeHash(worldState, address);

public void ResetOverrides() => _codeOverwrites.Clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using Nethermind.Evm.CodeAnalysis;
using Nethermind.Facade.Proxy.Models;
using Nethermind.Int256;
using Nethermind.State;

namespace Nethermind.Facade;
namespace Nethermind.Evm;

public static class StateOverridesExtensions
{
public static void ApplyStateOverrides(
this IWorldState state,
OverridableCodeInfoRepository overridableCodeInfoRepository,
IOverridableCodeInfoRepository overridableCodeInfoRepository,
Dictionary<Address, AccountOverride>? overrides,
IReleaseSpec spec,
long blockNumber)
Expand Down Expand Up @@ -69,13 +68,15 @@ void ApplyState(Dictionary<UInt256, Hash256> diff)

private static void UpdateCode(
this IWorldState stateProvider,
OverridableCodeInfoRepository overridableCodeInfoRepository,
IOverridableCodeInfoRepository overridableCodeInfoRepository,
IReleaseSpec currentSpec,
AccountOverride accountOverride,
Address address)
{
if (accountOverride.Code is not null)
{
stateProvider.InsertCode(address, accountOverride.Code, currentSpec);
Copy link
Contributor Author

@alexb5dh alexb5dh Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to prevent an "Account {address} is null when updating storage hash" error in StateProvider when overridden code writes to address storage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OlegJakushkin maybe this solves some issues on StateRoot in eth_simulate?


overridableCodeInfoRepository.SetCodeOverwrite(
stateProvider,
currentSpec,
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.Text.Json;
using System.Text.Json.Serialization;

using Nethermind.Core;
using Nethermind.Core.Crypto;

namespace Nethermind.Evm.Tracing.GethStyle;
Expand Down Expand Up @@ -36,5 +37,8 @@ public record GethTraceOptions
[JsonPropertyName("tracerConfig")]
public JsonElement? TracerConfig { get; init; }

[JsonPropertyName("stateOverrides")]
public Dictionary<Address, AccountOverride>? StateOverrides { get; init; }

public static GethTraceOptions Default { get; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Evm.TransactionProcessing;

public interface IOverridableTxProcessingScope : IReadOnlyTxProcessingScope
{
IOverridableCodeInfoRepository CodeInfoRepository { get; }
}
Loading