Skip to content

Commit

Permalink
Double checking
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap committed Oct 29, 2024
1 parent 5932250 commit a00e3f5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using Autofac;
using Autofac.Core;
using Autofac.Features.AttributeFilters;

namespace Nethermind.Core.Container;
Expand Down Expand Up @@ -135,6 +136,13 @@ public static ContainerBuilder Bind<TImpl, TAs>(this ContainerBuilder builder) w

return builder;
}

public static ContainerBuilder AddModule(this ContainerBuilder builder, IModule module)
{
builder.RegisterModule(module);

return builder;
}
}

/// <summary>
Expand Down
11 changes: 5 additions & 6 deletions src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,7 @@ public void ConfigureSynchronizationBuilder(ContainerBuilder builder)
if (!MergeEnabled) return;

builder
.AddInstance<IBlockCacheService>(_blockCacheService)
.AddInstance<IInvalidChainTracker>(_invalidChainTracker);

builder
.RegisterModule(new MergeNetworkModule());
.RegisterModule(new MergeNetworkModule(_blockCacheService, _invalidChainTracker));
}

public Task InitSynchronization(IContainer container)
Expand Down Expand Up @@ -455,12 +451,15 @@ public Task InitSynchronization(IContainer container)
public bool MustInitialize { get => true; }
}

public class MergeNetworkModule : Module
public class MergeNetworkModule(IBlockCacheService blockCacheService, IInvalidChainTracker invalidChainTracker) : Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);

builder
.AddInstance<IBlockCacheService>(blockCacheService)
.AddInstance<IInvalidChainTracker>(invalidChainTracker)
.AddSingleton<IPeerRefresher, PeerRefresher>()
.AddSingleton<PivotUpdator>()
.AddSingleton<IBeaconSyncStrategy, BeaconSync>();
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Network/Rlpx/RlpxHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Nethermind.Core.Extensions;
using Nethermind.Crypto;
using Nethermind.Logging;
using Nethermind.Network.Config;
using Nethermind.Network.P2P;
using Nethermind.Network.P2P.Analyzers;
using Nethermind.Network.P2P.EventArg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Autofac;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core;
using Nethermind.Core.Container;
using Nethermind.Core.Specs;
using Nethermind.Specs.ChainSpecStyle;
using Nethermind.Synchronization;
Expand All @@ -24,7 +25,7 @@ protected override void Load(ContainerBuilder builder)
{
if (provider.ChainId == OptimismMainnetChainId)
{
builder.AddSingleton<ITotalDifficultyStrategy>(
builder.AddInstance<ITotalDifficultyStrategy>(
new FixedTotalDifficultyStrategy(
new CumulativeTotalDifficultyStrategy(),
fixesBlockNumber: parameters.BedrockBlockNumber - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ ISyncConfig GetSyncConfig() =>

ContainerBuilder builder = new ContainerBuilder();
dbProvider.ConfigureServiceCollection(builder);

BlockCacheService blockCacheService = new BlockCacheService();
builder
.AddInstance(dbProvider)
.AddInstance(nodeStorage)
Expand All @@ -347,21 +347,19 @@ ISyncConfig GetSyncConfig() =>
.AddInstance(syncConfig)
.AddInstance<IPoSSwitcher>(poSSwitcher)
.AddInstance<IMergeConfig>(mergeConfig)
.AddInstance(invalidChainTracker)
.AddInstance(Substitute.For<IProcessExitSource>())
.AddInstance(new ChainSpec())
.AddInstance<IStateReader>(reader)
.AddInstance<ISealValidator>(Always.Valid)
.AddInstance<IBlockValidator>(Always.Valid)
.AddInstance<IGossipPolicy>(Policy.FullGossip)
.AddInstance<IBlockCacheService>(new BlockCacheService())
.AddInstance(_logManager);

builder.RegisterModule(new NetworkModule(new NetworkConfig(), syncConfig));

if (IsMerge(synchronizerType))
{
builder.RegisterModule(new MergeNetworkModule());
builder.RegisterModule(new MergeNetworkModule(blockCacheService, invalidChainTracker));
}

IContainer container = builder.Build();
Expand Down
46 changes: 12 additions & 34 deletions src/Nethermind/Nethermind.Taiko/TaikoPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using Autofac;
using Nethermind.Synchronization;
using System.Linq;
using Nethermind.Core.Container;

namespace Nethermind.Taiko;

Expand Down Expand Up @@ -278,7 +279,7 @@ public async Task InitRpcModules()
public bool MustInitialize => true;

// ISynchronizationPlugin
public Task InitSynchronization()
public Task InitSynchronization(IContainer container)
{
if (_api is null || !ShouldRunSteps(_api))
return Task.CompletedTask;
Expand All @@ -296,39 +297,10 @@ public Task InitSynchronization()

_api.InvalidChainTracker.SetupBlockchainProcessorInterceptor(_api.BlockchainProcessor);

_peerRefresher = new PeerRefresher(_api.PeerDifficultyRefreshPool, _api.TimerFactory, _api.LogManager);
_api.DisposeStack.Push((PeerRefresher)_peerRefresher);

_beaconPivot = new BeaconPivot(_syncConfig, _api.DbProvider.MetadataDb, _api.BlockTree, _api.PoSSwitcher, _api.LogManager);
_beaconSync = new BeaconSync(_beaconPivot, _api.BlockTree, _syncConfig, _blockCacheService, _api.PoSSwitcher, _api.LogManager);
_api.BetterPeerStrategy = new MergeBetterPeerStrategy(null!, _api.PoSSwitcher, _beaconPivot, _api.LogManager);
_api.Pivot = _beaconPivot;

ContainerBuilder builder = new ContainerBuilder();

((INethermindApi)_api).ConfigureContainerBuilderFromApiWithNetwork(builder)
.AddSingleton<IBeaconSyncStrategy>(_beaconSync)
.AddSingleton<IBeaconPivot>(_beaconPivot)
.AddSingleton(_mergeConfig)
.AddSingleton<IInvalidChainTracker>(_api.InvalidChainTracker);

builder.RegisterModule(new SynchronizerModule(_syncConfig));
builder.RegisterModule(new MergeSynchronizerModule());

IContainer container = builder.Build();

_api.ApiWithNetworkServiceContainer = container;
_api.DisposeStack.Append(container);

PivotUpdator pivotUpdator = new(
_api.BlockTree,
_api.SyncModeSelector,
_api.SyncPeerPool,
_syncConfig,
_blockCacheService,
_beaconSync,
_api.DbProvider.MetadataDb,
_api.LogManager);
_peerRefresher = container.Resolve<PeerRefresher>();
_beaconPivot = container.Resolve<IBeaconPivot>();
_beaconSync = container.Resolve<BeaconSync>();
_ = container.Resolve<PivotUpdator>();

return Task.CompletedTask;
}
Expand All @@ -338,6 +310,12 @@ public Task InitSynchronization()

// IConsensusPlugin

public void ConfigureSynchronizationBuilder(ContainerBuilder builder)
{
builder
.RegisterModule(new MergeNetworkModule(_blockCacheService!, _api!.InvalidChainTracker!));
}

public INethermindApi CreateApi(
IConfigProvider configProvider,
IJsonSerializer jsonSerializer,
Expand Down

0 comments on commit a00e3f5

Please sign in to comment.