Skip to content

Commit

Permalink
Override empty state scope with the state of the current block (#8067)
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 authored Jan 16, 2025
1 parent 7db8192 commit 1ab5908
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op
try
{
Dictionary<Address, AccountOverride>? stateOverride = options.StateOverrides;
using IOverridableTxProcessingScope? scope = stateOverride != null ? _env.BuildAndOverride(block.Header, stateOverride) : null;
using IOverridableTxProcessingScope? scope = _env.BuildAndOverride(block.Header, stateOverride);

return Trace(block, tx.Hash, cancellationToken, options, ProcessingOptions.TraceTransactions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private ResultWrapper<ParityTxTraceFromReplay> TraceTx(Transaction tx, string[]
BlockHeader header = headerSearch.Object!.Clone();
Block block = new(header, [tx], []);

using IOverridableTxProcessingScope? scope = stateOverride != null ? _env.BuildAndOverride(header, stateOverride) : null;
using IOverridableTxProcessingScope? scope = _env.BuildAndOverride(header, stateOverride);

ParityTraceTypes traceTypes1 = GetParityTypes(traceTypes);
IReadOnlyCollection<ParityLikeTxTrace> result = TraceBlock(block, new(traceTypes1));
Expand Down
38 changes: 19 additions & 19 deletions src/Nethermind/Nethermind.State/StateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ internal class StateProvider

private readonly bool _populatePreBlockCache;

public StateProvider(IScopedTrieStore? trieStore,
IKeyValueStore codeDb,
ILogManager logManager,
StateTree? stateTree = null,
ConcurrentDictionary<AddressAsKey, Account>? preBlockCache = null,
bool populatePreBlockCache = true)
{
_preBlockCache = preBlockCache;
_populatePreBlockCache = populatePreBlockCache;
_logger = logManager?.GetClassLogger<StateProvider>() ?? throw new ArgumentNullException(nameof(logManager));
_codeDb = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
_tree = stateTree ?? new StateTree(trieStore, logManager);
_getStateFromTrie = address =>
{
Metrics.IncrementStateTreeReads();
return _tree.Get(address);
};
}

public void Accept(ITreeVisitor? visitor, Hash256? stateRoot, VisitingOptions? visitingOptions = null)
{
ArgumentNullException.ThrowIfNull(visitor);
Expand Down Expand Up @@ -628,25 +647,6 @@ private void ReportChanges(IStateTracer stateTracer, Dictionary<AddressAsKey, Ch
}
}

public StateProvider(IScopedTrieStore? trieStore,
IKeyValueStore codeDb,
ILogManager logManager,
StateTree? stateTree = null,
ConcurrentDictionary<AddressAsKey, Account>? preBlockCache = null,
bool populatePreBlockCache = true)
{
_preBlockCache = preBlockCache;
_populatePreBlockCache = populatePreBlockCache;
_logger = logManager?.GetClassLogger<StateProvider>() ?? throw new ArgumentNullException(nameof(logManager));
_codeDb = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
_tree = stateTree ?? new StateTree(trieStore, logManager);
_getStateFromTrie = address =>
{
Metrics.IncrementStateTreeReads();
return _tree.Get(address);
};
}

public bool WarmUp(Address address)
{
return GetState(address) is not null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
using Nethermind.Blockchain.Synchronization;
using Nethermind.Config;
using Nethermind.Init.Steps;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Modules;
using Nethermind.JsonRpc.Modules.Eth.FeeHistory;
using Nethermind.Logging;
using System;

namespace Nethermind.Taiko.Rpc;

public class RegisterTaikoRpcModules : RegisterRpcModules
{
private readonly TaikoNethermindApi _api;
private readonly ILogger _logger;

public RegisterTaikoRpcModules(INethermindApi api) : base(api)
{
_api = (TaikoNethermindApi)api;
_logger = api.LogManager.GetClassLogger();
}

protected override void RegisterEthRpcModule(IRpcModuleProvider rpcModuleProvider)
Expand Down Expand Up @@ -82,7 +78,7 @@ protected override void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvi

TaikoTraceModuleFactory traceModuleFactory = new(
_api.WorldStateManager,
_api.BlockTree,
_api.BlockTree.AsReadOnly(),
_jsonRpcConfig,
_api.BlockPreprocessor,
_api.RewardCalculatorSource,
Expand Down

0 comments on commit 1ab5908

Please sign in to comment.