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

Use OP tx processor in trace RPC module #7118

Merged
merged 8 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using FluentAssertions;
using Nethermind.Abi;
using Nethermind.Blockchain;
using Nethermind.Consensus;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
Expand Down Expand Up @@ -85,7 +86,7 @@ protected override BlockProcessor CreateBlockProcessor()
BlockGasLimitContract gasLimitContract = new(AbiEncoder.Instance, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
new ReadOnlyTxProcessingEnv(
WorldStateManager,
BlockTree, SpecProvider, LimboLogs.Instance));
BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance));

GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
GasLimitCalculator = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, new FollowOtherMiners(SpecProvider), LimboLogs.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using FluentAssertions;
using Nethermind.Abi;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Data;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Contracts.DataStore;
Expand Down Expand Up @@ -254,7 +255,7 @@ protected override TxPoolTxSource CreateTxPoolTxSource()
TxPoolTxSource txPoolTxSource = base.CreateTxPoolTxSource();

TxPriorityContract = new TxPriorityContract(AbiEncoder.Instance, TestItem.AddressA,
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree, SpecProvider, LimboLogs.Instance));
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance));

Priorities = new DictionaryContractDataStore<TxPriorityContract.Destination>(
new TxPriorityContract.DestinationSortedListContractDataStoreCollection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FluentAssertions;
using Nethermind.Abi;
using Nethermind.AuRa.Test.Contract;
using Nethermind.Blockchain;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Transactions;
Expand Down Expand Up @@ -138,7 +139,7 @@ protected override BlockProcessor CreateBlockProcessor()
AbiEncoder abiEncoder = AbiEncoder.Instance;
ReadOnlyTransactionProcessorSource = new ReadOnlyTxProcessingEnv(
WorldStateManager,
BlockTree, SpecProvider,
BlockTree.AsReadOnly(), SpecProvider,
LimboLogs.Instance);
RegisterContract = new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, ReadOnlyTransactionProcessorSource);
CertifierContract = new CertifierContract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using FluentAssertions;
using Nethermind.Abi;
using Nethermind.AuRa.Test.Contract;
using Nethermind.Blockchain;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Transactions;
Expand Down Expand Up @@ -277,12 +278,12 @@ protected override BlockProcessor CreateBlockProcessor()
IReadOnlyTrieStore trieStore = new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly();
IReadOnlyTxProcessorSource txProcessorSource = new ReadOnlyTxProcessingEnv(
WorldStateManager,
BlockTree,
BlockTree.AsReadOnly(),
SpecProvider,
LimboLogs.Instance);

VersionedTransactionPermissionContract transactionPermissionContract = new(AbiEncoder.Instance, _contractAddress, 1,
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree, SpecProvider, LimboLogs.Instance), TransactionPermissionContractVersions, LimboLogs.Instance, SpecProvider);
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance), TransactionPermissionContractVersions, LimboLogs.Instance, SpecProvider);

TxPermissionFilterCache = new PermissionBasedTxFilter.Cache();
PermissionBasedTxFilter = new PermissionBasedTxFilter(transactionPermissionContract, TxPermissionFilterCache, LimboLogs.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Validators;
using Nethermind.Core.Specs;
using Nethermind.Db;
using Nethermind.Logging;
using Nethermind.State;

Expand Down Expand Up @@ -41,7 +40,16 @@ public ReadOnlyChainProcessingEnv(
IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor =
blockTransactionsExecutor ?? new BlockProcessor.BlockValidationTransactionsExecutor(_txEnv.TransactionProcessor, StateProvider);

BlockProcessor = new BlockProcessor(
BlockProcessor = CreateBlockProcessor(txEnv, blockValidator, rewardCalculator, receiptStorage, specProvider, logManager, transactionsExecutor);

_blockProcessingQueue = new BlockchainProcessor(_txEnv.BlockTree, BlockProcessor, recoveryStep, _txEnv.StateReader, logManager, BlockchainProcessor.Options.NoReceipts);
BlockProcessingQueue = _blockProcessingQueue;
ChainProcessor = new OneTimeChainProcessor(txEnv.StateProvider, _blockProcessingQueue);
}

protected virtual IBlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv txEnv, IBlockValidator blockValidator, IRewardCalculator rewardCalculator, IReceiptStorage receiptStorage, ISpecProvider specProvider, ILogManager logManager, IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor)
{
return new BlockProcessor(
specProvider,
blockValidator,
rewardCalculator,
Expand All @@ -50,10 +58,6 @@ public ReadOnlyChainProcessingEnv(
receiptStorage,
new BlockhashStore(txEnv.BlockTree, specProvider, StateProvider),
logManager);

_blockProcessingQueue = new BlockchainProcessor(_txEnv.BlockTree, BlockProcessor, recoveryStep, _txEnv.StateReader, logManager, BlockchainProcessor.Options.NoReceipts);
BlockProcessingQueue = _blockProcessingQueue;
ChainProcessor = new OneTimeChainProcessor(txEnv.StateProvider, _blockProcessingQueue);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,48 @@

// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace Nethermind.Consensus.Processing
namespace Nethermind.Consensus.Processing;

public class ReadOnlyTxProcessingEnv : IReadOnlyTxProcessorSource
{
public class ReadOnlyTxProcessingEnv : IReadOnlyTxProcessorSource
protected readonly ISpecProvider _specProvider;
protected readonly ILogManager? _logManager;

public IStateReader StateReader { get; }
public IWorldState StateProvider { get; }
public ITransactionProcessor TransactionProcessor { get; set; }
public IBlockTree BlockTree { get; }

public ReadOnlyTxProcessingEnv(
IWorldStateManager? worldStateManager,
IReadOnlyBlockTree? readOnlyBlockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
PreBlockCaches? preBlockCaches = null)
{
ArgumentNullException.ThrowIfNull(worldStateManager);
ArgumentNullException.ThrowIfNull(readOnlyBlockTree);
ArgumentNullException.ThrowIfNull(specProvider);

StateReader = worldStateManager.GlobalStateReader;
StateProvider = worldStateManager.CreateResettableWorldState(preBlockCaches);
BlockTree = readOnlyBlockTree;
_specProvider = specProvider;
_logManager = logManager;
TransactionProcessor = CreateTransactionProcessor();
}

protected virtual TransactionProcessor CreateTransactionProcessor()
{
BlockhashProvider blockhashProvider = new(BlockTree, _specProvider, StateProvider, _logManager);
VirtualMachine virtualMachine = new(blockhashProvider, _specProvider, _logManager);
return new TransactionProcessor(_specProvider, StateProvider, virtualMachine, _logManager);
}

public IReadOnlyTransactionProcessor Build(Hash256 stateRoot) => new ReadOnlyTransactionProcessor(TransactionProcessor, StateProvider, stateRoot);

public void Reset()
{
public IStateReader StateReader { get; }
public IWorldState StateProvider { get; }
public ITransactionProcessor TransactionProcessor { get; set; }
public IBlockTree BlockTree { get; }
public IBlockhashProvider BlockhashProvider { get; }
public IVirtualMachine Machine { get; }
public ISpecProvider SpecProvider { get; }

public ReadOnlyTxProcessingEnv(
IWorldStateManager worldStateManager,
IBlockTree? blockTree,
ISpecProvider? specProvider,
ILogManager? logManager)
: this(worldStateManager, blockTree?.AsReadOnly(), specProvider, logManager)
{
}

public ReadOnlyTxProcessingEnv(
IWorldStateManager worldStateManager,
IReadOnlyBlockTree? readOnlyBlockTree,
ISpecProvider? specProvider,
ILogManager? logManager,
PreBlockCaches? preBlockCaches = null)
{
ArgumentNullException.ThrowIfNull(specProvider);
ArgumentNullException.ThrowIfNull(worldStateManager);
SpecProvider = specProvider;
StateReader = worldStateManager.GlobalStateReader;
StateProvider = worldStateManager.CreateResettableWorldState(preBlockCaches);

BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree));
BlockhashProvider = new BlockhashProvider(BlockTree, specProvider, StateProvider, logManager);

Machine = new VirtualMachine(BlockhashProvider, specProvider, logManager);
TransactionProcessor = new TransactionProcessor(specProvider, StateProvider, Machine, logManager);
}

public IReadOnlyTransactionProcessor Build(Hash256 stateRoot) => new ReadOnlyTransactionProcessor(TransactionProcessor, StateProvider, stateRoot);

public void Reset()
{
StateProvider.Reset();
}
StateProvider.Reset();
}
}
40 changes: 28 additions & 12 deletions src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,7 @@ public virtual async Task Execute(CancellationToken cancellationToken)
_api.LogManager);
rpcModuleProvider.RegisterBoundedByCpuCount(debugModuleFactory, _jsonRpcConfig.Timeout);

TraceModuleFactory traceModuleFactory = new(
_api.WorldStateManager,
_api.BlockTree,
_jsonRpcConfig,
_api.BlockPreprocessor,
_api.RewardCalculatorSource,
_api.ReceiptStorage,
_api.SpecProvider,
_api.PoSSwitcher,
_api.LogManager);

rpcModuleProvider.RegisterBoundedByCpuCount(traceModuleFactory, _jsonRpcConfig.Timeout);
RegisterTraceRpcModule(rpcModuleProvider);

StepDependencyException.ThrowIfNull(_api.EthereumEcdsa);

Expand Down Expand Up @@ -249,4 +238,31 @@ protected virtual void RegisterEthRpcModule(IRpcModuleProvider rpcModuleProvider
rpcModuleProvider.RegisterBounded(ethModuleFactory,
_jsonRpcConfig.EthModuleConcurrentInstances ?? Environment.ProcessorCount, _jsonRpcConfig.Timeout);
}

protected ModuleFactoryBase<ITraceRpcModule> CreateTraceModuleFactory()
{
StepDependencyException.ThrowIfNull(_api.WorldStateManager);
StepDependencyException.ThrowIfNull(_api.BlockTree);
StepDependencyException.ThrowIfNull(_api.RewardCalculatorSource);
StepDependencyException.ThrowIfNull(_api.ReceiptStorage);
StepDependencyException.ThrowIfNull(_api.SpecProvider);

return new TraceModuleFactory(
_api.WorldStateManager,
_api.BlockTree,
_jsonRpcConfig,
_api.BlockPreprocessor,
_api.RewardCalculatorSource,
_api.ReceiptStorage,
_api.SpecProvider,
_api.PoSSwitcher,
_api.LogManager);
}

protected virtual void RegisterTraceRpcModule(IRpcModuleProvider rpcModuleProvider)
{
ModuleFactoryBase<ITraceRpcModule> traceModuleFactory = CreateTraceModuleFactory();

rpcModuleProvider.RegisterBoundedByCpuCount(traceModuleFactory, _jsonRpcConfig.Timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public StepDependencyException(string message)
{
}

public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression("argument")] string? paramName = null)
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is not null)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public void Setup()
[Test]
public void Can_trace_raw_parity_style()
{
TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, MainnetSpecProvider.Instance, LimboLogs.Instance, _stateReader);
TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, _stateReader);
ResultWrapper<ParityTxTraceFromReplay> result = traceRpcModule.trace_rawTransaction(Bytes.FromHexString("f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f"), new[] { "trace" });
Assert.NotNull(result.Data);
}

[Test]
public void Can_trace_raw_parity_style_berlin_tx()
{
TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, MainnetSpecProvider.Instance, LimboLogs.Instance, _stateReader);
TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, _stateReader);
ResultWrapper<ParityTxTraceFromReplay> result = traceRpcModule.trace_rawTransaction(Bytes.FromHexString("01f85b821e8e8204d7847735940083030d408080853a60005500c080a0f43e70c79190701347517e283ef63753f6143a5225cbb500b14d98eadfb7616ba070893923d8a1fc97499f426524f9e82f8e0322dfac7c3d7e8a9eee515f0bcdc4"), new[] { "trace" });
Assert.NotNull(result.Data);
}
Expand All @@ -114,7 +114,7 @@ public void Should_return_correct_block_reward(bool isPostMerge)
_blockTree!.SuggestBlock(block).Should().Be(AddBlockResult.Added);
_poSSwitcher!.IsPostMerge(Arg.Any<BlockHeader>()).Returns(isPostMerge);

TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, MainnetSpecProvider.Instance, LimboLogs.Instance, _stateReader);
TraceRpcModule traceRpcModule = new(NullReceiptStorage.Instance, _tracer, _blockTree, _jsonRpcConfig, _stateReader);
ParityTxTraceFromStore[] result = traceRpcModule.trace_block(new BlockParameter(block.Number)).Data.ToArray();
if (isPostMerge)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Build(ISpecProvider? specProvider = null, bool isAura = false)
ReadOnlyChainProcessingEnv executeProcessingEnv = CreateChainProcessingEnv(executeBlockTransactionsExecutor);

Tracer tracer = new(txProcessingEnv.StateProvider, traceProcessingEnv.ChainProcessor, executeProcessingEnv.ChainProcessor);
TraceRpcModule = new TraceRpcModule(receiptFinder, tracer, Blockchain.BlockFinder, JsonRpcConfig, MainnetSpecProvider.Instance, LimboLogs.Instance, txProcessingEnv.StateReader);
TraceRpcModule = new TraceRpcModule(receiptFinder, tracer, Blockchain.BlockFinder, JsonRpcConfig, txProcessingEnv.StateReader);

for (int i = 1; i < 10; i++)
{
Expand Down
Loading