From b95f4c210dfb9e8842b8d7e3d4db7b7907695a8c Mon Sep 17 00:00:00 2001 From: Nikita Mescheryakov Date: Mon, 1 May 2023 11:51:07 +0900 Subject: [PATCH] Enable nullability --- .../AccountAbstractionPlugin.cs | 11 ++++--- .../Extensions/IConsensusPlugin.cs | 7 ++++- .../Nethermind.Api/IApiWithBlockchain.cs | 6 ++-- .../Nethermind.Api/IApiWithNetwork.cs | 4 +-- src/Nethermind/Nethermind.Api/IBasicApi.cs | 4 +-- .../Nethermind.Api/Nethermind.Api.csproj | 2 +- .../Nethermind.Api/NethermindApi.cs | 29 ++++++++++--------- .../Nethermind.AuRa.Test/AuRaPluginTests.cs | 6 +++- .../Nethermind.Consensus.AuRa/AuRaPlugin.cs | 7 ++++- .../InitializationSteps/AuRaNethermindApi.cs | 6 ++++ .../Steps/InitializeBlockProducer.cs | 2 +- .../Steps/InitializeBlockchain.cs | 2 +- .../Steps/StartBlockProducer.cs | 2 +- .../AuRaMergeEngineModuleTests.cs | 13 ++++----- .../MergePlugin.BlockProducer.cs | 5 +--- .../Nethermind.Merge.Plugin/MergePlugin.cs | 1 + src/Nethermind/Nethermind.Mev/MevPlugin.cs | 4 +-- .../Ethereum/ContextWithMocks.cs | 6 +--- .../Steps/EthereumStepsManagerTests.cs | 20 ++++++------- .../Steps/Migrations/ReceiptMigrationTests.cs | 6 ++-- .../Ethereum/Api/ApiBuilder.cs | 8 ++--- 21 files changed, 79 insertions(+), 72 deletions(-) diff --git a/src/Nethermind/Nethermind.AccountAbstraction/AccountAbstractionPlugin.cs b/src/Nethermind/Nethermind.AccountAbstraction/AccountAbstractionPlugin.cs index cb545205169..1e8c3ef1418 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction/AccountAbstractionPlugin.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction/AccountAbstractionPlugin.cs @@ -22,7 +22,6 @@ using Nethermind.JsonRpc.Modules; using Nethermind.Logging; using Nethermind.Network; -using Nethermind.Network.P2P; using Nethermind.Stats; using Nethermind.Stats.Model; using Nethermind.Mev; @@ -286,7 +285,7 @@ public Task InitRpcModules() { if (_accountAbstractionConfig.Enabled) { - (IApiWithNetwork getFromApi, _) = _nethermindApi!.ForRpc; + (IApiWithNetwork getFromApi, _) = _nethermindApi.ForRpc; // init all relevant objects if not already initialized foreach (Address entryPoint in _entryPointContractAddresses) @@ -304,9 +303,9 @@ public Task InitRpcModules() throw new ArgumentNullException(nameof(_nethermindApi.LogManager)); getFromApi.RpcModuleProvider!.RegisterBoundedByCpuCount(accountAbstractionModuleFactory, rpcConfig.Timeout); - ISubscriptionFactory subscriptionFactory = _nethermindApi.SubscriptionFactory; + ISubscriptionFactory? subscriptionFactory = _nethermindApi.SubscriptionFactory; //Register custom UserOperation websocket subscription types in the SubscriptionFactory. - subscriptionFactory.RegisterSubscriptionType( + subscriptionFactory?.RegisterSubscriptionType( "newPendingUserOperations", (jsonRpcDuplexClient, param) => new NewPendingUserOpsSubscription( jsonRpcDuplexClient, @@ -314,7 +313,7 @@ public Task InitRpcModules() logManager, param) ); - subscriptionFactory.RegisterSubscriptionType( + subscriptionFactory?.RegisterSubscriptionType( "newReceivedUserOperations", (jsonRpcDuplexClient, param) => new NewReceivedUserOpsSubscription( jsonRpcDuplexClient, @@ -361,7 +360,7 @@ public Task InitBlockProducer(IConsensusPlugin consensusPlugin) UserOperationTxBuilder(entryPoint); } - _nethermindApi.BlockProducerEnvFactory.TransactionsExecutorFactory = + _nethermindApi.BlockProducerEnvFactory!.TransactionsExecutorFactory = new AABlockProducerTransactionsExecutorFactory( _nethermindApi.SpecProvider!, _nethermindApi.LogManager!, diff --git a/src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs b/src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs index 5c1fc48ee3e..abb29c5981d 100644 --- a/src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs +++ b/src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs @@ -2,9 +2,13 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Threading.Tasks; +using Nethermind.Config; using Nethermind.Consensus; using Nethermind.Consensus.Producers; using Nethermind.Consensus.Transactions; +using Nethermind.Logging; +using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; namespace Nethermind.Api.Extensions { @@ -32,6 +36,7 @@ Task InitBlockProducer( /// IBlockProductionTrigger DefaultBlockProductionTrigger { get; } - INethermindApi CreateApi() => new NethermindApi(); + INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer, + ILogManager logManager, ChainSpec chainSpec) => new NethermindApi(configProvider, jsonSerializer, logManager, chainSpec); } } diff --git a/src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs b/src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs index d5ca4004a0e..ce5fef1528e 100644 --- a/src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs +++ b/src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs @@ -84,9 +84,9 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory /// IBlockFinalizationManager? FinalizationManager { get; set; } - IGasLimitCalculator GasLimitCalculator { get; set; } + IGasLimitCalculator? GasLimitCalculator { get; set; } - IBlockProducerEnvFactory BlockProducerEnvFactory { get; set; } + IBlockProducerEnvFactory? BlockProducerEnvFactory { get; set; } IGasPriceOracle? GasPriceOracle { get; set; } @@ -94,6 +94,6 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory CompositePruningTrigger PruningTrigger { get; } - IBlockProductionPolicy BlockProductionPolicy { get; set; } + IBlockProductionPolicy? BlockProductionPolicy { get; set; } } } diff --git a/src/Nethermind/Nethermind.Api/IApiWithNetwork.cs b/src/Nethermind/Nethermind.Api/IApiWithNetwork.cs index 6ff1b46658b..9854452bfac 100644 --- a/src/Nethermind/Nethermind.Api/IApiWithNetwork.cs +++ b/src/Nethermind/Nethermind.Api/IApiWithNetwork.cs @@ -50,7 +50,7 @@ public interface IApiWithNetwork : IApiWithBlockchain IPeerDifficultyRefreshPool? PeerDifficultyRefreshPool { get; set; } ISyncServer? SyncServer { get; set; } IWebSocketsManager WebSocketsManager { get; set; } - ISubscriptionFactory SubscriptionFactory { get; set; } - ISnapProvider SnapProvider { get; set; } + ISubscriptionFactory? SubscriptionFactory { get; set; } + ISnapProvider? SnapProvider { get; set; } } } diff --git a/src/Nethermind/Nethermind.Api/IBasicApi.cs b/src/Nethermind/Nethermind.Api/IBasicApi.cs index 06af2d7f00f..cb6131a87e1 100644 --- a/src/Nethermind/Nethermind.Api/IBasicApi.cs +++ b/src/Nethermind/Nethermind.Api/IBasicApi.cs @@ -27,7 +27,7 @@ public interface IBasicApi DisposableStack DisposeStack { get; } IAbiEncoder AbiEncoder { get; } - ChainSpec? ChainSpec { get; set; } + ChainSpec ChainSpec { get; set; } IConfigProvider ConfigProvider { get; set; } ICryptoRandom CryptoRandom { get; } IDbProvider? DbProvider { get; set; } @@ -47,7 +47,7 @@ public interface IBasicApi IBetterPeerStrategy? BetterPeerStrategy { get; set; } ITimestamper Timestamper { get; } ITimerFactory TimerFactory { get; } - IProcessExitSource ProcessExit { get; set; } + IProcessExitSource? ProcessExit { get; set; } public IConsensusPlugin? GetConsensusPlugin() => Plugins diff --git a/src/Nethermind/Nethermind.Api/Nethermind.Api.csproj b/src/Nethermind/Nethermind.Api/Nethermind.Api.csproj index 217ed1d7b0f..11ffd627cf8 100644 --- a/src/Nethermind/Nethermind.Api/Nethermind.Api.csproj +++ b/src/Nethermind/Nethermind.Api/Nethermind.Api.csproj @@ -3,7 +3,7 @@ net7.0 strong.snk - annotations + enable true diff --git a/src/Nethermind/Nethermind.Api/NethermindApi.cs b/src/Nethermind/Nethermind.Api/NethermindApi.cs index e78ceaaa9e0..938b1ff96cd 100644 --- a/src/Nethermind/Nethermind.Api/NethermindApi.cs +++ b/src/Nethermind/Nethermind.Api/NethermindApi.cs @@ -53,7 +53,6 @@ using Nethermind.TxPool; using Nethermind.Wallet; using Nethermind.Sockets; -using Nethermind.State.Snap; using Nethermind.Synchronization.SnapSync; using Nethermind.Synchronization.Blocks; @@ -61,8 +60,12 @@ namespace Nethermind.Api { public class NethermindApi : INethermindApi { - public NethermindApi() + public NethermindApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer, ILogManager logManager, ChainSpec chainSpec) { + ConfigProvider = configProvider; + EthereumJsonSerializer = jsonSerializer; + LogManager = logManager; + ChainSpec = chainSpec; CryptoRandom = new CryptoRandom(); DisposeStack.Push(CryptoRandom); } @@ -71,7 +74,7 @@ public NethermindApi() public IBlockchainBridge CreateBlockchainBridge() { - ReadOnlyBlockTree readOnlyTree = BlockTree.AsReadOnly(); + ReadOnlyBlockTree readOnlyTree = BlockTree!.AsReadOnly(); LazyInitializer.EnsureInitialized(ref _readOnlyDbProvider, () => new ReadOnlyDbProvider(DbProvider, false)); // TODO: reuse the same trie cache here @@ -153,7 +156,7 @@ public IBlockchainBridge CreateBlockchainBridge() public IReceiptMonitor? ReceiptMonitor { get; set; } public IRewardCalculatorSource? RewardCalculatorSource { get; set; } = NoBlockRewards.Instance; public IRlpxHost? RlpxPeer { get; set; } - public IRpcModuleProvider RpcModuleProvider { get; set; } = NullModuleProvider.Instance; + public IRpcModuleProvider? RpcModuleProvider { get; set; } = NullModuleProvider.Instance; public IRpcAuthentication? RpcAuthentication { get; set; } public IJsonRpcLocalStats? JsonRpcLocalStats { get; set; } public ISealer? Sealer { get; set; } = NullSealEngine.Instance; @@ -204,18 +207,18 @@ public ISealEngine SealEngine public IRpcCapabilitiesProvider? RpcCapabilitiesProvider { get; set; } public TxValidator? TxValidator { get; set; } public IBlockFinalizationManager? FinalizationManager { get; set; } - public IGasLimitCalculator GasLimitCalculator { get; set; } + public IGasLimitCalculator? GasLimitCalculator { get; set; } - public IBlockProducerEnvFactory BlockProducerEnvFactory { get; set; } + public IBlockProducerEnvFactory? BlockProducerEnvFactory { get; set; } public IGasPriceOracle? GasPriceOracle { get; set; } - public IEthSyncingInfo EthSyncingInfo { get; set; } - public IBlockProductionPolicy BlockProductionPolicy { get; set; } + public IEthSyncingInfo? EthSyncingInfo { get; set; } + public IBlockProductionPolicy? BlockProductionPolicy { get; set; } public IWallet? Wallet { get; set; } - public ITransactionComparerProvider TransactionComparerProvider { get; set; } + public ITransactionComparerProvider? TransactionComparerProvider { get; set; } public IWebSocketsManager WebSocketsManager { get; set; } = new WebSocketsManager(); - public ISubscriptionFactory SubscriptionFactory { get; set; } + public ISubscriptionFactory? SubscriptionFactory { get; set; } public ProtectedPrivateKey? NodeKey { get; set; } /// @@ -223,12 +226,12 @@ public ISealEngine SealEngine /// public ProtectedPrivateKey? OriginalSignerKey { get; set; } - public ChainSpec? ChainSpec { get; set; } + public ChainSpec ChainSpec { get; set; } public DisposableStack DisposeStack { get; } = new(); public IReadOnlyList Plugins { get; } = new List(); public IList Publishers { get; } = new List(); // this should be called publishers public CompositePruningTrigger PruningTrigger { get; } = new(); - public ISnapProvider SnapProvider { get; set; } - public IProcessExitSource ProcessExit { get; set; } + public ISnapProvider? SnapProvider { get; set; } + public IProcessExitSource? ProcessExit { get; set; } } } diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs index 22ca4434fa4..009035305dd 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs @@ -4,7 +4,11 @@ using System; using FluentAssertions; using Nethermind.Api; +using Nethermind.Config; using Nethermind.Consensus.AuRa; +using Nethermind.Logging; +using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; using NUnit.Framework; namespace Nethermind.AuRa.Test @@ -15,7 +19,7 @@ public class AuRaPluginTests public void Init_when_not_AuRa_doesnt_trow() { AuRaPlugin auRaPlugin = new(); - Action init = () => auRaPlugin.Init(new NethermindApi()); + Action init = () => auRaPlugin.Init(new NethermindApi(new ConfigProvider(), new EthereumJsonSerializer(), new TestLogManager(), new ChainSpec())); init.Should().NotThrow(); } diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs index b0cbe623ffd..558433e9e78 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs @@ -5,9 +5,13 @@ using System.Threading.Tasks; using Nethermind.Api; using Nethermind.Api.Extensions; +using Nethermind.Config; using Nethermind.Consensus.AuRa.InitializationSteps; using Nethermind.Consensus.Producers; using Nethermind.Consensus.Transactions; +using Nethermind.Logging; +using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; [assembly: InternalsVisibleTo("Nethermind.Merge.AuRa")] @@ -73,7 +77,8 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd public IBlockProductionTrigger? DefaultBlockProductionTrigger { get; private set; } - public INethermindApi CreateApi() => new AuRaNethermindApi(); + public INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer, + ILogManager logManager, ChainSpec chainSpec) => new AuRaNethermindApi(configProvider, jsonSerializer, logManager, chainSpec); public bool ShouldRunSteps(INethermindApi api) => true; } diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/AuRaNethermindApi.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/AuRaNethermindApi.cs index f6bd4af1f15..b478f58b8e2 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/AuRaNethermindApi.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/AuRaNethermindApi.cs @@ -11,11 +11,17 @@ using Nethermind.Int256; using Nethermind.Logging; using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; namespace Nethermind.Consensus.AuRa.InitializationSteps { public class AuRaNethermindApi : NethermindApi { + public AuRaNethermindApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer, ILogManager logManager, ChainSpec chainSpec) + : base(configProvider, jsonSerializer, logManager, chainSpec) + { + } + public new IAuRaBlockFinalizationManager? FinalizationManager { get => base.FinalizationManager as IAuRaBlockFinalizationManager; diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs index 9373eb5a3bf..b5b41c08b59 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockProducer.cs @@ -25,7 +25,7 @@ public InitializeBlockProducer(INethermindApi api) public async Task Execute(CancellationToken _) { - if (_api.BlockProductionPolicy.ShouldStartBlockProduction()) + if (_api.BlockProductionPolicy!.ShouldStartBlockProduction()) { _api.BlockProducer = await BuildProducer(); } diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs index 7fbcbf2b17e..6ec42bee114 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs @@ -314,7 +314,7 @@ private static void InitializeFullPruning( api.PruningTrigger.Add(pruningTrigger); } - FullPruner pruner = new(fullPruningDb, api.PruningTrigger, pruningConfig, api.BlockTree!, stateReader, api.ProcessExit, api.LogManager); + FullPruner pruner = new(fullPruningDb, api.PruningTrigger, pruningConfig, api.BlockTree!, stateReader, api.ProcessExit!, api.LogManager); api.DisposeStack.Push(pruner); } } diff --git a/src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs b/src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs index 4c351138ace..e5c475e9657 100644 --- a/src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs +++ b/src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs @@ -26,7 +26,7 @@ public StartBlockProducer(INethermindApi api) public async Task Execute(CancellationToken _) { - if (_api.BlockProductionPolicy.ShouldStartBlockProduction() && _api.BlockProducer is not null) + if (_api.BlockProductionPolicy!.ShouldStartBlockProduction() && _api.BlockProducer is not null) { if (_api.BlockTree is null) throw new StepDependencyException(nameof(_api.BlockTree)); diff --git a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs index 21731b8d164..bdb6222938a 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa.Test/AuRaMergeEngineModuleTests.cs @@ -135,21 +135,18 @@ protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolT targetAdjustedGasLimitCalculator); AuRaMergeBlockProducerEnvFactory blockProducerEnvFactory = new( - new() - { - BlockTree = BlockTree, - ChainSpec = new ChainSpec + new(new ConfigProvider(), new EthereumJsonSerializer(), LogManager, + new ChainSpec { AuRa = new() { WithdrawalContractAddress = new("0xbabe2bed00000000000000000000000000000003") }, Parameters = new() - }, + }) + { + BlockTree = BlockTree, DbProvider = DbProvider, - ConfigProvider = new ConfigProvider(), - EthereumJsonSerializer = new EthereumJsonSerializer(), - LogManager = LogManager, ReadOnlyTrieStore = ReadOnlyTrieStore, SpecProvider = SpecProvider, TransactionComparerProvider = TransactionComparerProvider, diff --git a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs index f66300af163..a8436b8813f 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs @@ -6,13 +6,9 @@ using Nethermind.Api.Extensions; using Nethermind.Consensus; using Nethermind.Consensus.Producers; -using Nethermind.Consensus.Transactions; using Nethermind.Core; -using Nethermind.Logging; using Nethermind.Merge.Plugin.BlockProduction; -using Nethermind.Merge.Plugin.Data; using Nethermind.Merge.Plugin.Handlers; -using Nethermind.State; namespace Nethermind.Merge.Plugin { @@ -44,6 +40,7 @@ public virtual async Task InitBlockProducer(IConsensusPlugin con if (_api.HeaderValidator is null) throw new ArgumentNullException(nameof(_api.HeaderValidator)); if (_mergeBlockProductionPolicy is null) throw new ArgumentNullException(nameof(_mergeBlockProductionPolicy)); if (_api.SealValidator is null) throw new ArgumentNullException(nameof(_api.SealValidator)); + if (_api.BlockProducerEnvFactory is null) throw new ArgumentNullException(nameof(_api.BlockProducerEnvFactory)); if (_logger.IsInfo) _logger.Info("Starting Merge block producer & sealer"); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs index df64702c315..74abfcf4664 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs @@ -367,6 +367,7 @@ public Task InitSynchronization() if (_api.NodeStatsManager is null) throw new ArgumentNullException(nameof(_api.NodeStatsManager)); if (_api.HeaderValidator is null) throw new ArgumentNullException(nameof(_api.HeaderValidator)); if (_api.PeerDifficultyRefreshPool is null) throw new ArgumentNullException(nameof(_api.PeerDifficultyRefreshPool)); + if (_api.SnapProvider is null) throw new ArgumentNullException(nameof(_api.SnapProvider)); // ToDo strange place for validators initialization PeerRefresher peerRefresher = new(_api.PeerDifficultyRefreshPool, _api.TimerFactory, _api.LogManager); diff --git a/src/Nethermind/Nethermind.Mev/MevPlugin.cs b/src/Nethermind/Nethermind.Mev/MevPlugin.cs index f5a7976a6d0..9996b4a252a 100644 --- a/src/Nethermind/Nethermind.Mev/MevPlugin.cs +++ b/src/Nethermind/Nethermind.Mev/MevPlugin.cs @@ -59,7 +59,7 @@ public BundlePool BundlePool TxBundleSimulator txBundleSimulator = new( TracerFactory, - getFromApi.GasLimitCalculator, + getFromApi.GasLimitCalculator!, getFromApi.Timestamper, getFromApi.TxPool!, getFromApi.SpecProvider!, @@ -139,7 +139,7 @@ public async Task InitBlockProducer(IConsensusPlugin consensusPl throw new InvalidOperationException("Plugin is disabled"); } - _nethermindApi.BlockProducerEnvFactory.TransactionsExecutorFactory = new MevBlockProducerTransactionsExecutorFactory(_nethermindApi.SpecProvider!, _nethermindApi.LogManager); + _nethermindApi.BlockProducerEnvFactory!.TransactionsExecutorFactory = new MevBlockProducerTransactionsExecutorFactory(_nethermindApi.SpecProvider!, _nethermindApi.LogManager); int megabundleProducerCount = _mevConfig.GetTrustedRelayAddresses().Any() ? 1 : 0; List blockProducers = diff --git a/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs b/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs index 56d4206e3e0..65721ff5bcb 100644 --- a/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs +++ b/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs @@ -52,9 +52,8 @@ namespace Nethermind.Runner.Test.Ethereum public static class Build { public static NethermindApi ContextWithMocks() => - new NethermindApi() + new(Substitute.For(), Substitute.For(), LimboLogs.Instance, new ChainSpec()) { - LogManager = LimboLogs.Instance, Enode = Substitute.For(), TxPool = Substitute.For(), Wallet = Substitute.For(), @@ -77,7 +76,6 @@ public static NethermindApi ContextWithMocks() => Synchronizer = Substitute.For(), BlockchainProcessor = Substitute.For(), BlockProducer = Substitute.For(), - ConfigProvider = Substitute.For(), DiscoveryApp = Substitute.For(), EngineSigner = Substitute.For(), FileSystem = Substitute.For(), @@ -102,7 +100,6 @@ public static NethermindApi ContextWithMocks() => TxSender = Substitute.For(), BlockProcessingQueue = Substitute.For(), EngineSignerStore = Substitute.For(), - EthereumJsonSerializer = Substitute.For(), NodeStatsManager = Substitute.For(), RpcModuleProvider = Substitute.For(), SyncModeSelector = Substitute.For(), @@ -112,7 +109,6 @@ public static NethermindApi ContextWithMocks() => ChainLevelInfoRepository = Substitute.For(), TrieStore = Substitute.For(), ReadOnlyTrieStore = Substitute.For(), - ChainSpec = new ChainSpec(), BlockProducerEnvFactory = Substitute.For(), TransactionComparerProvider = Substitute.For(), GasPriceOracle = Substitute.For(), diff --git a/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/EthereumStepsManagerTests.cs b/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/EthereumStepsManagerTests.cs index 32831499e41..3ab5bc7dadf 100644 --- a/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/EthereumStepsManagerTests.cs +++ b/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/EthereumStepsManagerTests.cs @@ -14,6 +14,7 @@ using Nethermind.Runner.Ethereum.Api; using Nethermind.Runner.Ethereum.Steps; using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; using NSubstitute.ExceptionExtensions; using NUnit.Framework; @@ -25,7 +26,7 @@ public class EthereumStepsManagerTests [Test] public async Task When_no_assemblies_defined() { - NethermindApi runnerContext = CreateApi(); + NethermindApi runnerContext = CreateNethermindApi(); IEthereumStepsLoader stepsLoader = new EthereumStepsLoader(); EthereumStepsManager stepsManager = new EthereumStepsManager( @@ -40,7 +41,7 @@ public async Task When_no_assemblies_defined() [Test] public async Task With_steps_from_here() { - NethermindApi runnerContext = CreateApi(); + NethermindApi runnerContext = CreateNethermindApi(); IEthereumStepsLoader stepsLoader = new EthereumStepsLoader(GetType().Assembly); EthereumStepsManager stepsManager = new EthereumStepsManager( @@ -66,7 +67,7 @@ public async Task With_steps_from_here() [Test] public async Task With_steps_from_here_AuRa() { - AuRaNethermindApi runnerContext = CreateApi(); + AuRaNethermindApi runnerContext = CreateAuraApi(); IEthereumStepsLoader stepsLoader = new EthereumStepsLoader(GetType().Assembly); EthereumStepsManager stepsManager = new EthereumStepsManager( @@ -89,7 +90,7 @@ public async Task With_steps_from_here_AuRa() [Test] public async Task With_failing_steps() { - NethermindApi runnerContext = CreateApi(); + NethermindApi runnerContext = CreateNethermindApi(); IEthereumStepsLoader stepsLoader = new EthereumStepsLoader(GetType().Assembly); EthereumStepsManager stepsManager = new EthereumStepsManager( @@ -112,13 +113,10 @@ public async Task With_failing_steps() } } - private static T CreateApi() where T : INethermindApi, new() => - new T() - { - ConfigProvider = new ConfigProvider(), - EthereumJsonSerializer = new EthereumJsonSerializer(), - LogManager = LimboLogs.Instance - }; + private static NethermindApi CreateNethermindApi() => + new(new ConfigProvider(), new EthereumJsonSerializer(), LimboLogs.Instance, new ChainSpec()); + private static AuRaNethermindApi CreateAuraApi() => + new(new ConfigProvider(), new EthereumJsonSerializer(), LimboLogs.Instance, new ChainSpec()); } public class StepLong : IStep diff --git a/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/Migrations/ReceiptMigrationTests.cs b/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/Migrations/ReceiptMigrationTests.cs index 1adbbf60a79..bba61f8110b 100644 --- a/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/Migrations/ReceiptMigrationTests.cs +++ b/src/Nethermind/Nethermind.Runner.Test/Ethereum/Steps/Migrations/ReceiptMigrationTests.cs @@ -16,6 +16,7 @@ using Nethermind.Init.Steps.Migrations; using Nethermind.Logging; using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; using Nethermind.Synchronization; using Nethermind.Synchronization.ParallelSync; using NSubstitute; @@ -35,11 +36,8 @@ public void RunMigration(int? migratedBlockNumber) BlockTreeBuilder blockTreeBuilder = Core.Test.Builders.Build.A.BlockTree().OfChainLength(chainLength); InMemoryReceiptStorage inMemoryReceiptStorage = new() { MigratedBlockNumber = migratedBlockNumber is not null ? 0 : long.MaxValue }; InMemoryReceiptStorage outMemoryReceiptStorage = new() { MigratedBlockNumber = migratedBlockNumber is not null ? 0 : long.MaxValue }; - NethermindApi context = new() + NethermindApi context = new(configProvider, new EthereumJsonSerializer(), LimboLogs.Instance, new ChainSpec()) { - ConfigProvider = configProvider, - EthereumJsonSerializer = new EthereumJsonSerializer(), - LogManager = LimboLogs.Instance, ReceiptStorage = new TestReceiptStorage(inMemoryReceiptStorage, outMemoryReceiptStorage), DbProvider = Substitute.For(), BlockTree = blockTreeBuilder.TestObject, diff --git a/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs b/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs index 5622140830a..e81b7dc8983 100644 --- a/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs +++ b/src/Nethermind/Nethermind.Runner/Ethereum/Api/ApiBuilder.cs @@ -50,14 +50,12 @@ public INethermindApi Create(IEnumerable consensusPlugins) string engine = chainSpec.SealEngineType; IConsensusPlugin? enginePlugin = consensusPlugins.FirstOrDefault(p => p.SealEngineType == engine); - INethermindApi nethermindApi = enginePlugin?.CreateApi() ?? new NethermindApi(); - nethermindApi.ConfigProvider = _configProvider; - nethermindApi.EthereumJsonSerializer = _jsonSerializer; - nethermindApi.LogManager = _logManager; + INethermindApi nethermindApi = + enginePlugin?.CreateApi(_configProvider, _jsonSerializer, _logManager, chainSpec) ?? + new NethermindApi(_configProvider, _jsonSerializer, _logManager, chainSpec); nethermindApi.SealEngineType = engine; nethermindApi.SpecProvider = new ChainSpecBasedSpecProvider(chainSpec, _logManager); nethermindApi.GasLimitCalculator = new FollowOtherMiners(nethermindApi.SpecProvider); - nethermindApi.ChainSpec = chainSpec; SetLoggerVariables(chainSpec);