Skip to content

Commit

Permalink
No need to check Enabled manually anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap committed Jan 20, 2025
1 parent e493043 commit fe11752
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 152 deletions.
4 changes: 0 additions & 4 deletions src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public class CliquePlugin(ChainSpec chainSpec) : IConsensusPlugin
public Task Init(INethermindApi nethermindApi)
{
_nethermindApi = nethermindApi;
if (!Enabled)
{
return Task.CompletedTask;
}

(IApiWithStores getFromApi, IApiWithBlockchain setInApi) = _nethermindApi.ForInit;

Expand Down
4 changes: 0 additions & 4 deletions src/Nethermind/Nethermind.Consensus.Ethash/EthashPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public class EthashPlugin(ChainSpec chainSpec) : IConsensusPlugin
public Task Init(INethermindApi nethermindApi)
{
_nethermindApi = nethermindApi;
if (!Enabled)
{
return Task.CompletedTask;
}

var (getFromApi, setInApi) = _nethermindApi.ForInit;
setInApi.RewardCalculatorSource = new RewardCalculator(getFromApi.SpecProvider);
Expand Down
5 changes: 0 additions & 5 deletions src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public Task Init(INethermindApi nethermindApi)

public IBlockProducer InitBlockProducer(ITxSource? additionalTxSource = null)
{
if (!Enabled)
{
return null;
}

var (getFromApi, _) = _nethermindApi!.ForProducer;

ReadOnlyBlockTree readOnlyBlockTree = getFromApi.BlockTree.AsReadOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@ public class ClefSignerPlugin(IMiningConfig miningConfig) : INethermindPlugin
public async Task Init(INethermindApi nethermindApi)
{
_nethermindApi = nethermindApi ?? throw new ArgumentNullException(nameof(nethermindApi));
if (Enabled)
if (!string.IsNullOrEmpty(miningConfig.Signer))
{
if (!string.IsNullOrEmpty(miningConfig.Signer))
if (!Uri.TryCreate(miningConfig.Signer, UriKind.Absolute, out Uri? uri))
{
if (!Uri.TryCreate(miningConfig.Signer, UriKind.Absolute, out Uri? uri))
{
throw new ConfigurationErrorsException($"{miningConfig.Signer} must have be a valid uri.");
}

string blockAuthorAccount = _nethermindApi.Config<IKeyStoreConfig>().BlockAuthorAccount;
_nethermindApi.EngineSigner = await SetupExternalSigner(uri, blockAuthorAccount);
throw new ConfigurationErrorsException($"{miningConfig.Signer} must have be a valid uri.");
}

string blockAuthorAccount = _nethermindApi.Config<IKeyStoreConfig>().BlockAuthorAccount;
_nethermindApi.EngineSigner = await SetupExternalSigner(uri, blockAuthorAccount);
}
}

Expand Down
49 changes: 23 additions & 26 deletions src/Nethermind/Nethermind.Hive/HivePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,29 @@ public Task Init(INethermindApi api)

public async Task InitNetworkProtocol()
{
if (Enabled)
{
if (_api.BlockTree is null) throw new ArgumentNullException(nameof(_api.BlockTree));
if (_api.BlockProcessingQueue is null) throw new ArgumentNullException(nameof(_api.BlockProcessingQueue));
if (_api.ConfigProvider is null) throw new ArgumentNullException(nameof(_api.ConfigProvider));
if (_api.LogManager is null) throw new ArgumentNullException(nameof(_api.LogManager));
if (_api.FileSystem is null) throw new ArgumentNullException(nameof(_api.FileSystem));
if (_api.BlockValidator is null) throw new ArgumentNullException(nameof(_api.BlockValidator));

_api.TxPool!.AcceptTxWhenNotSynced = true;

_api.TxGossipPolicy.Policies.Clear();

HiveRunner hiveRunner = new(
_api.BlockTree,
_api.BlockProcessingQueue,
_api.ConfigProvider,
_api.LogManager.GetClassLogger(),
_api.FileSystem,
_api.BlockValidator
);

if (_logger.IsInfo) _logger.Info("Hive is starting");

await hiveRunner.Start(_disposeCancellationToken.Token);
}
if (_api.BlockTree is null) throw new ArgumentNullException(nameof(_api.BlockTree));
if (_api.BlockProcessingQueue is null) throw new ArgumentNullException(nameof(_api.BlockProcessingQueue));
if (_api.ConfigProvider is null) throw new ArgumentNullException(nameof(_api.ConfigProvider));
if (_api.LogManager is null) throw new ArgumentNullException(nameof(_api.LogManager));
if (_api.FileSystem is null) throw new ArgumentNullException(nameof(_api.FileSystem));
if (_api.BlockValidator is null) throw new ArgumentNullException(nameof(_api.BlockValidator));

_api.TxPool!.AcceptTxWhenNotSynced = true;

_api.TxGossipPolicy.Policies.Clear();

HiveRunner hiveRunner = new(
_api.BlockTree,
_api.BlockProcessingQueue,
_api.ConfigProvider,
_api.LogManager.GetClassLogger(),
_api.FileSystem,
_api.BlockValidator
);

if (_logger.IsInfo) _logger.Info("Hive is starting");

await hiveRunner.Start(_disposeCancellationToken.Token);
}

public Task InitRpcModules()
Expand Down
46 changes: 18 additions & 28 deletions src/Nethermind/Nethermind.JsonRpc.TraceStore/TraceStorePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,39 @@ public Task Init(INethermindApi nethermindApi)
_jsonRpcConfig = _api.Config<IJsonRpcConfig>();
_logger = _logManager.GetClassLogger<TraceStorePlugin>();

if (Enabled)
{
// Setup serialization
_traceSerializer = new ParityLikeTraceSerializer(_logManager, traceStoreConfig.MaxDepth, traceStoreConfig.VerifySerialized);
// Setup serialization
_traceSerializer = new ParityLikeTraceSerializer(_logManager, traceStoreConfig.MaxDepth, traceStoreConfig.VerifySerialized);

// Setup DB
_db = _api.DbFactory!.CreateDb(new DbSettings(DbName, DbName.ToLower()));
_api.DbProvider!.RegisterDb(DbName, _db);
// Setup DB
_db = _api.DbFactory!.CreateDb(new DbSettings(DbName, DbName.ToLower()));
_api.DbProvider!.RegisterDb(DbName, _db);

//Setup pruning if configured
if (traceStoreConfig.BlocksToKeep != 0)
{
_pruner = new TraceStorePruner(_api.BlockTree!, _db, traceStoreConfig.BlocksToKeep, _logManager);
}
//Setup pruning if configured
if (traceStoreConfig.BlocksToKeep != 0)
{
_pruner = new TraceStorePruner(_api.BlockTree!, _db, traceStoreConfig.BlocksToKeep, _logManager);
}

return Task.CompletedTask;
}

public Task InitNetworkProtocol()
{
if (Enabled)
{
if (_logger.IsInfo) _logger.Info($"Starting TraceStore with {traceStoreConfig.TraceTypes} traces.");
if (_logger.IsInfo) _logger.Info($"Starting TraceStore with {traceStoreConfig.TraceTypes} traces.");

// Setup tracing
ParityLikeBlockTracer parityTracer = new(traceStoreConfig.TraceTypes);
DbPersistingBlockTracer<ParityLikeTxTrace, ParityLikeTxTracer> dbPersistingTracer =
new(parityTracer, _db!, _traceSerializer!, _logManager);
_api.BlockchainProcessor!.Tracers.Add(dbPersistingTracer);
}
// Setup tracing
ParityLikeBlockTracer parityTracer = new(traceStoreConfig.TraceTypes);
DbPersistingBlockTracer<ParityLikeTxTrace, ParityLikeTxTracer> dbPersistingTracer =
new(parityTracer, _db!, _traceSerializer!, _logManager);
_api.BlockchainProcessor!.Tracers.Add(dbPersistingTracer);

// Potentially we could add protocol for syncing traces.
return Task.CompletedTask;
}

public Task InitRpcModules()
{
if (Enabled && _jsonRpcConfig.Enabled)
if (_jsonRpcConfig.Enabled)
{
IRpcModuleProvider apiRpcModuleProvider = _api.RpcModuleProvider!;
if (apiRpcModuleProvider.GetPool(ModuleType.Trace) is IRpcModulePool<ITraceRpcModule> traceModulePool)
Expand All @@ -86,12 +80,8 @@ public Task InitRpcModules()

public ValueTask DisposeAsync()
{
if (Enabled)
{
_pruner?.Dispose();
_db?.Dispose();
}

_pruner?.Dispose();
_db?.Dispose();
return default;
}
}
16 changes: 5 additions & 11 deletions src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,13 @@ public INethermindApi CreateApi(IConfigProvider configProvider, IJsonSerializer

public void InitTxTypesAndRlpDecoders(INethermindApi api)
{
if (Enabled)
{
api.RegisterTxType<OptimismTransactionForRpc>(new OptimismTxDecoder<Transaction>(), Always.Valid);
api.RegisterTxType<LegacyTransactionForRpc>(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator(api.SpecProvider!.ChainId));
Rlp.RegisterDecoders(typeof(OptimismReceiptMessageDecoder).Assembly, true);
}
api.RegisterTxType<OptimismTransactionForRpc>(new OptimismTxDecoder<Transaction>(), Always.Valid);
api.RegisterTxType<LegacyTransactionForRpc>(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator(api.SpecProvider!.ChainId));
Rlp.RegisterDecoders(typeof(OptimismReceiptMessageDecoder).Assembly, true);
}

public Task Init(INethermindApi api)
{
if (!Enabled)
return Task.CompletedTask;

_api = (OptimismNethermindApi)api;
_mergeConfig = _api.Config<IMergeConfig>();
_syncConfig = _api.Config<ISyncConfig>();
Expand Down Expand Up @@ -137,7 +131,7 @@ public Task Init(INethermindApi api)

public Task InitSynchronization()
{
if (_api is null || !Enabled)
if (_api is null)
return Task.CompletedTask;

ArgumentNullException.ThrowIfNull(_api.SpecProvider);
Expand Down Expand Up @@ -192,7 +186,7 @@ public Task InitSynchronization()

public async Task InitRpcModules()
{
if (_api is null || !Enabled)
if (_api is null)
return;

ArgumentNullException.ThrowIfNull(_api.SpecProvider);
Expand Down
100 changes: 47 additions & 53 deletions src/Nethermind/Nethermind.Shutter/ShutterPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,74 +46,68 @@ public Task Init(INethermindApi nethermindApi)

public Task InitRpcModules()
{
if (Enabled)
{
if (_api!.BlockProducer is null) throw new ArgumentNullException(nameof(_api.BlockProducer));
if (_api!.BlockProducer is null) throw new ArgumentNullException(nameof(_api.BlockProducer));

if (_logger.IsInfo) _logger.Info("Initializing Shutter block improvement.");
_api.BlockImprovementContextFactory = _shutterApi!.GetBlockImprovementContextFactory(_api.BlockProducer);
}
if (_logger.IsInfo) _logger.Info("Initializing Shutter block improvement.");
_api.BlockImprovementContextFactory = _shutterApi!.GetBlockImprovementContextFactory(_api.BlockProducer);
return Task.CompletedTask;
}

public IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, ITxSource? txSource)
{
if (Enabled)
if (_api!.BlockTree is null) throw new ArgumentNullException(nameof(_api.BlockTree));
if (_api.EthereumEcdsa is null) throw new ArgumentNullException(nameof(_api.SpecProvider));
if (_api.LogFinder is null) throw new ArgumentNullException(nameof(_api.LogFinder));
if (_api.SpecProvider is null) throw new ArgumentNullException(nameof(_api.SpecProvider));
if (_api.ReceiptFinder is null) throw new ArgumentNullException(nameof(_api.ReceiptFinder));
if (_api.WorldStateManager is null) throw new ArgumentNullException(nameof(_api.WorldStateManager));
if (_api.IpResolver is null) throw new ArgumentNullException(nameof(_api.IpResolver));

if (_logger.IsInfo) _logger.Info("Initializing Shutter block producer.");

Multiaddress[] bootnodeP2PAddresses;
try
{
if (_api!.BlockTree is null) throw new ArgumentNullException(nameof(_api.BlockTree));
if (_api.EthereumEcdsa is null) throw new ArgumentNullException(nameof(_api.SpecProvider));
if (_api.LogFinder is null) throw new ArgumentNullException(nameof(_api.LogFinder));
if (_api.SpecProvider is null) throw new ArgumentNullException(nameof(_api.SpecProvider));
if (_api.ReceiptFinder is null) throw new ArgumentNullException(nameof(_api.ReceiptFinder));
if (_api.WorldStateManager is null) throw new ArgumentNullException(nameof(_api.WorldStateManager));
if (_api.IpResolver is null) throw new ArgumentNullException(nameof(_api.IpResolver));

if (_logger.IsInfo) _logger.Info("Initializing Shutter block producer.");
shutterConfig!.Validate(out bootnodeP2PAddresses);
}
catch (ArgumentException e)
{
throw new ShutterLoadingException("Invalid Shutter config", e);
}

Multiaddress[] bootnodeP2PAddresses;
ShutterValidatorsInfo validatorsInfo = new();
if (shutterConfig!.ValidatorInfoFile is not null)
{
try
{
shutterConfig!.Validate(out bootnodeP2PAddresses);
}
catch (ArgumentException e)
{
throw new ShutterLoadingException("Invalid Shutter config", e);
validatorsInfo.Load(shutterConfig!.ValidatorInfoFile);
}

ShutterValidatorsInfo validatorsInfo = new();
if (shutterConfig!.ValidatorInfoFile is not null)
catch (Exception e)
{
try
{
validatorsInfo.Load(shutterConfig!.ValidatorInfoFile);
}
catch (Exception e)
{
throw new ShutterLoadingException("Could not load Shutter validator info file", e);
}
throw new ShutterLoadingException("Could not load Shutter validator info file", e);
}

_shutterApi = new ShutterApi(
_api.AbiEncoder,
_api.BlockTree,
_api.EthereumEcdsa,
_api.LogFinder,
_api.ReceiptFinder,
_api.LogManager,
_api.SpecProvider,
_api.Timestamper,
_api.WorldStateManager,
_api.FileSystem,
_api.Config<IKeyStoreConfig>(),
shutterConfig,
validatorsInfo,
TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot),
_api.IpResolver.ExternalIp
);

_ = _shutterApi.StartP2P(bootnodeP2PAddresses, _cts);
}

_shutterApi = new ShutterApi(
_api.AbiEncoder,
_api.BlockTree,
_api.EthereumEcdsa,
_api.LogFinder,
_api.ReceiptFinder,
_api.LogManager,
_api.SpecProvider,
_api.Timestamper,
_api.WorldStateManager,
_api.FileSystem,
_api.Config<IKeyStoreConfig>(),
shutterConfig,
validatorsInfo,
TimeSpan.FromSeconds(_blocksConfig!.SecondsPerSlot),
_api.IpResolver.ExternalIp
);

_ = _shutterApi.StartP2P(bootnodeP2PAddresses, _cts);

return consensusPlugin.InitBlockProducer(_shutterApi is null ? txSource : _shutterApi.TxSource.Then(txSource));
}

Expand Down
10 changes: 2 additions & 8 deletions src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public class TaikoPlugin(ChainSpec chainSpec) : IConsensusPlugin, ISynchronizati

public Task Init(INethermindApi api)
{
if (!Enabled)
return Task.CompletedTask;

_api = (TaikoNethermindApi)api;
_mergeConfig = _api.Config<IMergeConfig>();
_syncConfig = _api.Config<ISyncConfig>();
Expand Down Expand Up @@ -94,9 +91,6 @@ public Task Init(INethermindApi api)

public void InitTxTypesAndRlpDecoders(INethermindApi api)
{
if (!Enabled)
return;

_api = (TaikoNethermindApi)api;

ArgumentNullException.ThrowIfNull(_api.DbProvider);
Expand All @@ -113,7 +107,7 @@ public void InitTxTypesAndRlpDecoders(INethermindApi api)

public async Task InitRpcModules()
{
if (_api is null || !Enabled)
if (_api is null)
return;

ArgumentNullException.ThrowIfNull(_api.SpecProvider);
Expand Down Expand Up @@ -262,7 +256,7 @@ public async Task InitRpcModules()
// ISynchronizationPlugin
public Task InitSynchronization()
{
if (_api is null || !Enabled)
if (_api is null)
return Task.CompletedTask;

ArgumentNullException.ThrowIfNull(_api.SpecProvider);
Expand Down
Loading

0 comments on commit fe11752

Please sign in to comment.