Skip to content

Commit

Permalink
Cleanup DI
Browse files Browse the repository at this point in the history
  • Loading branch information
emlautarom1 committed Oct 24, 2024
1 parent 2f1e822 commit a30e516
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public Task InitSynchronization()
.AddSingleton(_mergeConfig)
.AddSingleton<IInvalidChainTracker>(_invalidChainTracker);

builder.RegisterModule(new OptimismSynchronizerModule(parameters: _api.ChainSpec.Optimism, _api.SpecProvider, _syncConfig));
builder.RegisterModule(new SynchronizerModule(_syncConfig));
builder.RegisterModule(new MergeSynchronizerModule());
builder.RegisterModule(new OptimismSynchronizerModule(_api.ChainSpec.Optimism, _api.SpecProvider));

IContainer container = builder.Build();

Expand Down
12 changes: 1 addition & 11 deletions src/Nethermind/Nethermind.Optimism/OptimismSynchronizerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ namespace Nethermind.Optimism;
/// Calculation is still the same: the current block's <see cref="BlockHeader.TotalDifficulty"/> is the parent's <see cref="BlockHeader.TotalDifficulty"/> plus the current block's <see cref="BlockHeader.Difficulty"/>.
/// <seealso href="https://github.com/NethermindEth/nethermind/issues/7626"/>
/// </remarks>
public class OptimismSynchronizerModule(
OptimismParameters parameters,
ISpecProvider provider,
ISyncConfig syncConfig
) : SynchronizerModule(syncConfig)
public sealed class OptimismSynchronizerModule(OptimismParameters parameters, ISpecProvider provider) : Module
{
private const ulong OptimismMainnetChainId = 0xA;

protected override void Load(ContainerBuilder builder)
{
base.Load(builder);

if (provider.ChainId == OptimismMainnetChainId)
{
builder.AddSingleton<ITotalDifficultyStrategy>(
Expand All @@ -38,9 +32,5 @@ protected override void Load(ContainerBuilder builder)
)
);
}
else
{
builder.AddSingleton<ITotalDifficultyStrategy>(new CumulativeTotalDifficultyStrategy());
}
}
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Synchronization/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ protected override void Load(ContainerBuilder builder)
.AddScoped<IPeerAllocationStrategyFactory<HeadersSyncBatch>, FastBlocksPeerAllocationStrategyFactory>()
.AddScoped<SyncDispatcher<HeadersSyncBatch>>()

// Default TotalDifficulty calculation strategy used when processing headers
.AddScoped<ITotalDifficultyStrategy, CumulativeTotalDifficultyStrategy>()

// SyncProgress resolver need one header sync batch feed, which is the fast header one.
.Register(ctx => ctx
.ResolveNamed<SyncFeedComponent<HeadersSyncBatch>>(nameof(HeadersSyncFeed))
Expand Down

0 comments on commit a30e516

Please sign in to comment.