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

Forward eth_sendTransaction to the sequencer #7017

Merged
merged 7 commits into from
May 21, 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
144 changes: 75 additions & 69 deletions src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,98 +33,75 @@ namespace Nethermind.Init.Steps;
public class RegisterRpcModules : IStep
{
private readonly INethermindApi _api;
private readonly IJsonRpcConfig _jsonRpcConfig;

public RegisterRpcModules(INethermindApi api)
{
_api = api;
_jsonRpcConfig = _api.Config<IJsonRpcConfig>();
}

public virtual async Task Execute(CancellationToken cancellationToken)
{
if (_api.BlockTree is null) throw new StepDependencyException(nameof(_api.BlockTree));
if (_api.ReceiptFinder is null) throw new StepDependencyException(nameof(_api.ReceiptFinder));
if (_api.BloomStorage is null) throw new StepDependencyException(nameof(_api.BloomStorage));
if (_api.LogManager is null) throw new StepDependencyException(nameof(_api.LogManager));
StepDependencyException.ThrowIfNull(_api.BlockTree);
StepDependencyException.ThrowIfNull(_api.ReceiptFinder);
StepDependencyException.ThrowIfNull(_api.BloomStorage);
StepDependencyException.ThrowIfNull(_api.LogManager);

IJsonRpcConfig jsonRpcConfig = _api.Config<IJsonRpcConfig>();
if (!jsonRpcConfig.Enabled)
if (!_jsonRpcConfig.Enabled)
{
return;
}

if (_api.FileSystem is null) throw new StepDependencyException(nameof(_api.FileSystem));
if (_api.TxPool is null) throw new StepDependencyException(nameof(_api.TxPool));
if (_api.Wallet is null) throw new StepDependencyException(nameof(_api.Wallet));
if (_api.SpecProvider is null) throw new StepDependencyException(nameof(_api.SpecProvider));
if (_api.SyncModeSelector is null) throw new StepDependencyException(nameof(_api.SyncModeSelector));
if (_api.TxSender is null) throw new StepDependencyException(nameof(_api.TxSender));
if (_api.StateReader is null) throw new StepDependencyException(nameof(_api.StateReader));
if (_api.WorldStateManager is null) throw new StepDependencyException(nameof(_api.WorldStateManager));
if (_api.PeerManager is null) throw new StepDependencyException(nameof(_api.PeerManager));

if (jsonRpcConfig.Enabled)
{
_api.RpcModuleProvider = new RpcModuleProvider(_api.FileSystem, jsonRpcConfig, _api.LogManager);
}
else
{
_api.RpcModuleProvider ??= NullModuleProvider.Instance;
}
StepDependencyException.ThrowIfNull(_api.FileSystem);
StepDependencyException.ThrowIfNull(_api.TxPool);
StepDependencyException.ThrowIfNull(_api.Wallet);
StepDependencyException.ThrowIfNull(_api.SpecProvider);
StepDependencyException.ThrowIfNull(_api.SyncModeSelector);
StepDependencyException.ThrowIfNull(_api.TxSender);
StepDependencyException.ThrowIfNull(_api.StateReader);
StepDependencyException.ThrowIfNull(_api.WorldStateManager);
StepDependencyException.ThrowIfNull(_api.PeerManager);

_api.RpcModuleProvider = new RpcModuleProvider(_api.FileSystem, _jsonRpcConfig, _api.LogManager);

IRpcModuleProvider rpcModuleProvider = _api.RpcModuleProvider;

// the following line needs to be called in order to make sure that the CLI library is referenced from runner and built alongside
ILogger logger = _api.LogManager.GetClassLogger();

IInitConfig initConfig = _api.Config<IInitConfig>();
IJsonRpcConfig rpcConfig = _api.Config<IJsonRpcConfig>();
INetworkConfig networkConfig = _api.Config<INetworkConfig>();

// lets add threads to support parallel eth_getLogs
ThreadPool.GetMinThreads(out int workerThreads, out int completionPortThreads);
ThreadPool.SetMinThreads(workerThreads + Environment.ProcessorCount, completionPortThreads + Environment.ProcessorCount);

if (_api.ReceiptStorage is null) throw new StepDependencyException(nameof(_api.ReceiptStorage));
if (_api.GasPriceOracle is null) throw new StepDependencyException(nameof(_api.GasPriceOracle));
if (_api.EthSyncingInfo is null) throw new StepDependencyException(nameof(_api.EthSyncingInfo));
StepDependencyException.ThrowIfNull(_api.ReceiptStorage);
StepDependencyException.ThrowIfNull(_api.GasPriceOracle);
StepDependencyException.ThrowIfNull(_api.EthSyncingInfo);

ModuleFactoryBase<IEthRpcModule> ethModuleFactory = CreateEthModuleFactory();

var feeHistoryOracle = new FeeHistoryOracle(_api.BlockTree, _api.ReceiptStorage, _api.SpecProvider);
_api.DisposeStack.Push(feeHistoryOracle);
EthModuleFactory ethModuleFactory = new(
_api.TxPool,
_api.TxSender,
_api.Wallet,
_api.BlockTree,
rpcConfig,
_api.LogManager,
_api.StateReader,
_api,
_api.SpecProvider,
_api.ReceiptStorage,
_api.GasPriceOracle,
_api.EthSyncingInfo,
feeHistoryOracle);

RpcLimits.Init(rpcConfig.RequestQueueLimit);
rpcModuleProvider.RegisterBounded(ethModuleFactory, rpcConfig.EthModuleConcurrentInstances ?? Environment.ProcessorCount, rpcConfig.Timeout);
RpcLimits.Init(_jsonRpcConfig.RequestQueueLimit);
rpcModuleProvider.RegisterBounded(ethModuleFactory, _jsonRpcConfig.EthModuleConcurrentInstances ?? Environment.ProcessorCount, _jsonRpcConfig.Timeout);

if (_api.DbProvider is null) throw new StepDependencyException(nameof(_api.DbProvider));
if (_api.BlockPreprocessor is null) throw new StepDependencyException(nameof(_api.BlockPreprocessor));
if (_api.BlockValidator is null) throw new StepDependencyException(nameof(_api.BlockValidator));
if (_api.RewardCalculatorSource is null) throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
if (_api.KeyStore is null) throw new StepDependencyException(nameof(_api.KeyStore));
if (_api.PeerPool is null) throw new StepDependencyException(nameof(_api.PeerPool));
if (_api.BadBlocksStore is null) throw new StepDependencyException(nameof(_api.BadBlocksStore));
StepDependencyException.ThrowIfNull(_api.DbProvider);
StepDependencyException.ThrowIfNull(_api.BlockPreprocessor);
StepDependencyException.ThrowIfNull(_api.BlockValidator);
StepDependencyException.ThrowIfNull(_api.RewardCalculatorSource);
StepDependencyException.ThrowIfNull(_api.KeyStore);
StepDependencyException.ThrowIfNull(_api.PeerPool);
StepDependencyException.ThrowIfNull(_api.BadBlocksStore);

ProofModuleFactory proofModuleFactory = new(_api.WorldStateManager, _api.BlockTree, _api.BlockPreprocessor, _api.ReceiptFinder, _api.SpecProvider, _api.LogManager);
rpcModuleProvider.RegisterBounded(proofModuleFactory, 2, rpcConfig.Timeout);
rpcModuleProvider.RegisterBounded(proofModuleFactory, 2, _jsonRpcConfig.Timeout);

DebugModuleFactory debugModuleFactory = new(
_api.WorldStateManager,
_api.DbProvider,
_api.BlockTree,
rpcConfig,
_jsonRpcConfig,
_api.BlockValidator,
_api.BlockPreprocessor,
_api.RewardCalculatorSource,
Expand All @@ -136,33 +113,32 @@ public virtual async Task Execute(CancellationToken cancellationToken)
_api.BadBlocksStore,
_api.FileSystem,
_api.LogManager);
rpcModuleProvider.RegisterBoundedByCpuCount(debugModuleFactory, rpcConfig.Timeout);
rpcModuleProvider.RegisterBoundedByCpuCount(debugModuleFactory, _jsonRpcConfig.Timeout);

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

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

if (_api.EthereumEcdsa is null) throw new StepDependencyException(nameof(_api.EthereumEcdsa));
if (_api.Wallet is null) throw new StepDependencyException(nameof(_api.Wallet));
StepDependencyException.ThrowIfNull(_api.EthereumEcdsa);

PersonalRpcModule personalRpcModule = new(
_api.EthereumEcdsa,
_api.Wallet,
_api.KeyStore);
rpcModuleProvider.RegisterSingle<IPersonalRpcModule>(personalRpcModule);

if (_api.PeerManager is null) throw new StepDependencyException(nameof(_api.PeerManager));
if (_api.StaticNodesManager is null) throw new StepDependencyException(nameof(_api.StaticNodesManager));
if (_api.Enode is null) throw new StepDependencyException(nameof(_api.Enode));
StepDependencyException.ThrowIfNull(_api.PeerManager);
StepDependencyException.ThrowIfNull(_api.StaticNodesManager);
StepDependencyException.ThrowIfNull(_api.Enode);

ManualPruningTrigger pruningTrigger = new();
_api.PruningTrigger.Add(pruningTrigger);
Expand All @@ -176,13 +152,13 @@ public virtual async Task Execute(CancellationToken cancellationToken)
pruningTrigger);
rpcModuleProvider.RegisterSingle<IAdminRpcModule>(adminRpcModule);

if (_api.TxPoolInfoProvider is null) throw new StepDependencyException(nameof(_api.TxPoolInfoProvider));
StepDependencyException.ThrowIfNull(_api.TxPoolInfoProvider);

TxPoolRpcModule txPoolRpcModule = new(_api.TxPoolInfoProvider, _api.LogManager);
rpcModuleProvider.RegisterSingle<ITxPoolRpcModule>(txPoolRpcModule);

if (_api.SyncServer is null) throw new StepDependencyException(nameof(_api.SyncServer));
if (_api.EngineSignerStore is null) throw new StepDependencyException(nameof(_api.EngineSignerStore));
StepDependencyException.ThrowIfNull(_api.SyncServer);
StepDependencyException.ThrowIfNull(_api.EngineSignerStore);

NetRpcModule netRpcModule = new(_api.LogManager, new NetBridge(_api.Enode, _api.SyncServer));
rpcModuleProvider.RegisterSingle<INetRpcModule>(netRpcModule);
Expand All @@ -199,11 +175,11 @@ public virtual async Task Execute(CancellationToken cancellationToken)
_api.PeerManager);
rpcModuleProvider.RegisterSingle<IParityRpcModule>(parityRpcModule);

if (_api.ReceiptMonitor is null) throw new StepDependencyException(nameof(_api.ReceiptMonitor));
StepDependencyException.ThrowIfNull(_api.ReceiptMonitor);

JsonRpcLocalStats jsonRpcLocalStats = new(
_api.Timestamper,
jsonRpcConfig,
_jsonRpcConfig,
_api.LogManager);

_api.JsonRpcLocalStats = jsonRpcLocalStats;
Expand Down Expand Up @@ -236,4 +212,34 @@ public virtual async Task Execute(CancellationToken cancellationToken)

await Task.CompletedTask;
}

protected virtual ModuleFactoryBase<IEthRpcModule> CreateEthModuleFactory()
{
StepDependencyException.ThrowIfNull(_api.BlockTree);
StepDependencyException.ThrowIfNull(_api.ReceiptStorage);
StepDependencyException.ThrowIfNull(_api.SpecProvider);
StepDependencyException.ThrowIfNull(_api.TxPool);
StepDependencyException.ThrowIfNull(_api.TxSender);
StepDependencyException.ThrowIfNull(_api.Wallet);
StepDependencyException.ThrowIfNull(_api.StateReader);
StepDependencyException.ThrowIfNull(_api.GasPriceOracle);
StepDependencyException.ThrowIfNull(_api.EthSyncingInfo);

var feeHistoryOracle = new FeeHistoryOracle(_api.BlockTree, _api.ReceiptStorage, _api.SpecProvider);
_api.DisposeStack.Push(feeHistoryOracle);
return new EthModuleFactory(
_api.TxPool,
_api.TxSender,
_api.Wallet,
_api.BlockTree,
_jsonRpcConfig,
_api.LogManager,
_api.StateReader,
_api,
_api.SpecProvider,
_api.ReceiptStorage,
_api.GasPriceOracle,
_api.EthSyncingInfo,
feeHistoryOracle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Nethermind.Init.Steps
{
Expand All @@ -15,5 +17,12 @@ public StepDependencyException(string message)
: base(message)
{
}

public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression("argument")] string? paramName = null)
{
if (argument is not null)
return;
throw new StepDependencyException(paramName ?? "");
}
}
}
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.JsonRpc/Modules/Eth/IEthRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ public interface IEthRpcModule : IRpcModule
Description = "Returns account balance",
IsSharable = true,
ExampleResponse = "0x6c8ae945bfe6e")]
Task<ResultWrapper<UInt256?>> eth_getBalance([JsonRpcParameter(ExampleValue = "[\"0x78467cada5f1883e79fcf0f3ebfa50abeec8c820\"]")] Address address, BlockParameter blockParameter = null);
Task<ResultWrapper<UInt256?>> eth_getBalance([JsonRpcParameter(ExampleValue = "[\"0x78467cada5f1883e79fcf0f3ebfa50abeec8c820\"]")] Address address, BlockParameter? blockParameter = null);

[JsonRpcMethod(IsImplemented = true,
Description = "Returns storage data at address. storage_index",
IsSharable = true,
ExampleResponse = "0x")]
ResultWrapper<byte[]> eth_getStorageAt([JsonRpcParameter(ExampleValue = "[\"0x000000000000000000000000c666d239cbda32aa7ebca894b6dc598ddb881285\",\"0x2\"]")] Address address, UInt256 positionIndex, BlockParameter blockParameter = null);
ResultWrapper<byte[]> eth_getStorageAt([JsonRpcParameter(ExampleValue = "[\"0x000000000000000000000000c666d239cbda32aa7ebca894b6dc598ddb881285\",\"0x2\"]")] Address address, UInt256 positionIndex, BlockParameter? blockParameter = null);

[JsonRpcMethod(IsImplemented = true,
Description = "Returns account nonce (number of trnsactions from the account since genesis) at the given block number",
IsSharable = true,
ExampleResponse = "0x3e")]
Task<ResultWrapper<UInt256>> eth_getTransactionCount([JsonRpcParameter(ExampleValue = "[\"0xae3ed7a6ccdddf2914133d0669b5f02ff6fa8ad2\"]")] Address address, BlockParameter blockParameter = null);
Task<ResultWrapper<UInt256>> eth_getTransactionCount([JsonRpcParameter(ExampleValue = "[\"0xae3ed7a6ccdddf2914133d0669b5f02ff6fa8ad2\"]")] Address address, BlockParameter? blockParameter = null);

[JsonRpcMethod(IsImplemented = true,
Description = "Returns number of transactions in the block block hash",
Expand Down Expand Up @@ -126,7 +126,7 @@ public interface IEthRpcModule : IRpcModule
ResultWrapper<UInt256?> eth_getUncleCountByBlockNumber([JsonRpcParameter(ExampleValue = "[\"5127400\"]")] BlockParameter blockParameter);

[JsonRpcMethod(IsImplemented = true, Description = "Returns account code at given address and block", IsSharable = true)]
ResultWrapper<byte[]> eth_getCode(Address address, BlockParameter blockParameter = null);
ResultWrapper<byte[]> eth_getCode(Address address, BlockParameter? blockParameter = null);

[JsonRpcMethod(IsImplemented = false, Description = "Signs a transaction", IsSharable = true)]
ResultWrapper<byte[]> eth_sign(Address addressData, byte[] message);
Expand Down Expand Up @@ -267,6 +267,6 @@ ResultWrapper<TransactionForRpc> eth_getTransactionByBlockNumberAndIndex(
ResultWrapper<AccountProof> eth_getProof([JsonRpcParameter(ExampleValue = "[\"0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842\",[ \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\" ],\"latest\"]")] Address accountAddress, UInt256[] hashRate, BlockParameter blockParameter);

[JsonRpcMethod(IsImplemented = true, Description = "Retrieves Accounts via Address and Blocknumber", IsSharable = true)]
ResultWrapper<AccountForRpc?> eth_getAccount([JsonRpcParameter(ExampleValue = "[\"0xaa00000000000000000000000000000000000000\", \"latest\"]")] Address accountAddress, BlockParameter blockParameter = null);
ResultWrapper<AccountForRpc?> eth_getAccount([JsonRpcParameter(ExampleValue = "[\"0xaa00000000000000000000000000000000000000\", \"latest\"]")] Address accountAddress, BlockParameter? blockParameter = null);
}
}
12 changes: 12 additions & 0 deletions src/Nethermind/Nethermind.Optimism/IOptimismConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Config;

namespace Nethermind.Optimism;

public interface IOptimismConfig : IConfig
{
[ConfigItem(Description = "Sequencer address", DefaultValue = "null")]
string? SequencerUrl { get; set; }
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Optimism/OPConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public OPSpecHelper(OptimismParameters parameters)
_regolithTimestamp = parameters.RegolithTimestamp;
_bedrockBlockNumber = parameters.BedrockBlockNumber;
_canyonTimestamp = parameters.CanyonTimestamp;

L1FeeReceiver = parameters.L1FeeRecipient;
Create2DeployerCode = parameters.Create2DeployerCode;
Create2DeployerAddress = parameters.Create2DeployerAddress;
Expand Down
9 changes: 9 additions & 0 deletions src/Nethermind/Nethermind.Optimism/OptimismConfig.cs
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.Optimism;

public class OptimismConfig : IOptimismConfig
{
public string? SequencerUrl { get; set; } = null;
}
40 changes: 40 additions & 0 deletions src/Nethermind/Nethermind.Optimism/Rpc/OptimismEthModuleFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Crypto;
using Nethermind.Facade;
using Nethermind.JsonRpc.Client;
using Nethermind.JsonRpc.Modules;
using Nethermind.JsonRpc.Modules.Eth;
using Nethermind.TxPool;

namespace Nethermind.Optimism;

public class OptimismEthModuleFactory : ModuleFactoryBase<IEthRpcModule>
{
private readonly ModuleFactoryBase<IEthRpcModule> _ethModuleFactory;
private readonly BasicJsonRpcClient? _sequencerRpcClient;
private readonly IBlockchainBridge _blockchainBridge;
private readonly IAccountStateProvider _accountStateProvider;
private readonly IEthereumEcdsa _ecdsa;
private readonly ITxSealer _sealer;

public OptimismEthModuleFactory(ModuleFactoryBase<IEthRpcModule> ethModuleFactory,
BasicJsonRpcClient? sequencerRpcClient, IBlockchainBridge blockchainBridge,
IAccountStateProvider accountStateProvider, IEthereumEcdsa ecdsa, ITxSealer sealer)
{
_ethModuleFactory = ethModuleFactory;
_sequencerRpcClient = sequencerRpcClient;
_blockchainBridge = blockchainBridge;
_accountStateProvider = accountStateProvider;
_ecdsa = ecdsa;
_sealer = sealer;
}

public override IEthRpcModule Create()
{
return new OptimismEthRpcModule(_ethModuleFactory.Create(), _sequencerRpcClient, _blockchainBridge,
_accountStateProvider, _ecdsa, _sealer);
}
}
Loading