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

Enable nullability in Api #5631

Merged
merged 1 commit into from
May 1, 2023
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 @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -304,17 +303,17 @@ 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<UserOperationSubscriptionParam?>(
subscriptionFactory?.RegisterSubscriptionType<UserOperationSubscriptionParam?>(
"newPendingUserOperations",
(jsonRpcDuplexClient, param) => new NewPendingUserOpsSubscription(
jsonRpcDuplexClient,
_userOperationPools,
logManager,
param)
);
subscriptionFactory.RegisterSubscriptionType<UserOperationSubscriptionParam?>(
subscriptionFactory?.RegisterSubscriptionType<UserOperationSubscriptionParam?>(
"newReceivedUserOperations",
(jsonRpcDuplexClient, param) => new NewReceivedUserOpsSubscription(
jsonRpcDuplexClient,
Expand Down Expand Up @@ -361,7 +360,7 @@ public Task<IBlockProducer> InitBlockProducer(IConsensusPlugin consensusPlugin)
UserOperationTxBuilder(entryPoint);
}

_nethermindApi.BlockProducerEnvFactory.TransactionsExecutorFactory =
_nethermindApi.BlockProducerEnvFactory!.TransactionsExecutorFactory =
new AABlockProducerTransactionsExecutorFactory(
_nethermindApi.SpecProvider!,
_nethermindApi.LogManager!,
Expand Down
7 changes: 6 additions & 1 deletion src/Nethermind/Nethermind.Api/Extensions/IConsensusPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -32,6 +36,7 @@ Task<IBlockProducer> InitBlockProducer(
/// </remarks>
IBlockProductionTrigger DefaultBlockProductionTrigger { get; }

INethermindApi CreateApi() => new NethermindApi();
INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer jsonSerializer,
ILogManager logManager, ChainSpec chainSpec) => new NethermindApi(configProvider, jsonSerializer, logManager, chainSpec);
}
}
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory
/// </remarks>
IBlockFinalizationManager? FinalizationManager { get; set; }

IGasLimitCalculator GasLimitCalculator { get; set; }
IGasLimitCalculator? GasLimitCalculator { get; set; }

IBlockProducerEnvFactory BlockProducerEnvFactory { get; set; }
IBlockProducerEnvFactory? BlockProducerEnvFactory { get; set; }

IGasPriceOracle? GasPriceOracle { get; set; }

IEthSyncingInfo? EthSyncingInfo { get; set; }

CompositePruningTrigger PruningTrigger { get; }

IBlockProductionPolicy BlockProductionPolicy { get; set; }
IBlockProductionPolicy? BlockProductionPolicy { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Api/IApiWithNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Api/IBasicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Api/Nethermind.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyOriginatorKeyFile>strong.snk</AssemblyOriginatorKeyFile>
<Nullable>annotations</Nullable>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
29 changes: 16 additions & 13 deletions src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@
using Nethermind.TxPool;
using Nethermind.Wallet;
using Nethermind.Sockets;
using Nethermind.State.Snap;
using Nethermind.Synchronization.SnapSync;
using Nethermind.Synchronization.Blocks;

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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -204,31 +207,31 @@ 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; }

/// <summary>
/// Key used for signing blocks. Original as its loaded on startup. This can later be changed via RPC in <see cref="Signer"/>.
/// </summary>
public ProtectedPrivateKey? OriginalSignerKey { get; set; }

public ChainSpec? ChainSpec { get; set; }
public ChainSpec ChainSpec { get; set; }
public DisposableStack DisposeStack { get; } = new();
public IReadOnlyList<INethermindPlugin> Plugins { get; } = new List<INethermindPlugin>();
public IList<IPublisher> Publishers { get; } = new List<IPublisher>(); // 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; }
}
}
6 changes: 5 additions & 1 deletion src/Nethermind/Nethermind.AuRa.Test/AuRaPluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Nethermind/Nethermind.Consensus.AuRa/AuRaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down Expand Up @@ -73,7 +77,8 @@ public Task<IBlockProducer> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Init/Steps/StartBlockProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -44,6 +40,7 @@ public virtual async Task<IBlockProducer> 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");

Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Mev/MevPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public BundlePool BundlePool

TxBundleSimulator txBundleSimulator = new(
TracerFactory,
getFromApi.GasLimitCalculator,
getFromApi.GasLimitCalculator!,
getFromApi.Timestamper,
getFromApi.TxPool!,
getFromApi.SpecProvider!,
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<IBlockProducer> 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<MevBlockProducer.MevBlockProducerInfo> blockProducers =
Expand Down
Loading