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

Cleanup/Remove fast sync with header only #7779

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 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
10 changes: 10 additions & 0 deletions src/Nethermind/Nethermind.Core/ContainerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public static ContainerBuilder AddSingleton<T>(this ContainerBuilder builder, T
return builder;
}


public static ContainerBuilder AddSingleton<T>(this ContainerBuilder builder, Func<IComponentContext, T> factory) where T : class
{
builder.Register(factory)
.As<T>()
.SingleInstance();

return builder;
}

public static ContainerBuilder AddSingleton<T, TImpl>(this ContainerBuilder builder) where TImpl : notnull where T : notnull
{
builder.RegisterType<TImpl>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Autofac;
using Nethermind.Blockchain;
using Nethermind.Core;
using Nethermind.Db;

namespace Nethermind.Merge.Plugin.Test;

public static class MergeSyncTestContainerBuilderExtensions
{
public static ContainerBuilder AddBlockTreeScenario(this ContainerBuilder builder, BlockTreeTests.BlockTreeTestScenario.ScenarioBuilder scenarioBuilder)
{
return builder
.AddSingleton<IBlockTree>(scenarioBuilder.NotSyncedTree)
.AddKeyedSingleton(DbNames.Metadata, scenarioBuilder.NotSyncedTreeBuilder.MetadataDb);
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Merge.Plugin/PoSSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Autofac.Features.AttributeFilters;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class PoSSwitcher : IPoSSwitcher
public PoSSwitcher(
IMergeConfig mergeConfig,
ISyncConfig syncConfig,
IDb metadataDb,
[KeyFilter(DbNames.Metadata)] IDb metadataDb,
IBlockTree blockTree,
ISpecProvider specProvider,
ChainSpec chainSpec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Autofac.Features.AttributeFilters;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Consensus;
Expand Down Expand Up @@ -45,7 +46,7 @@ private BlockHeader? CurrentBeaconPivot

public BeaconPivot(
ISyncConfig syncConfig,
IDb metadataDb,
[KeyFilter(DbNames.Metadata)] IDb metadataDb,
IBlockTree blockTree,
IPoSSwitcher poSSwitcher,
ILogManager logManager)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

459 changes: 210 additions & 249 deletions src/Nethermind/Nethermind.Synchronization.Test/BlockDownloaderTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Nethermind.Core.Timers;
using Nethermind.Db;
using Nethermind.Logging;
using Nethermind.State;
using Nethermind.Stats;
using Nethermind.Trie;
using NSubstitute;
Expand All @@ -28,6 +29,7 @@ protected override void Load(ContainerBuilder builder)
.AddSingleton<IBlockTree>(Substitute.For<IBlockTree>())
.AddSingleton<ITimerFactory>(Substitute.For<ITimerFactory>())
.AddSingleton<ISyncConfig>(syncConfig)
.AddSingleton<IStateReader>(Substitute.For<IStateReader>())
.AddSingleton<IBetterPeerStrategy>(new TotalDifficultyBetterPeerStrategy(LimboLogs.Instance))
.AddSingleton<INodeStatsManager, NodeStatsManager>()
.AddSingleton<CancelOnDisposeToken>()
Expand Down
473 changes: 236 additions & 237 deletions src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ namespace Nethermind.Synchronization.Blocks
[Flags]
public enum DownloaderOptions
{
None = 0,
Process = 1,
WithReceipts = 2,
MoveToMain = 4,
WithBodies = 8,
// ReSharper disable once UnusedMember.Global
All = 15
Fast,
Full,
}
}
13 changes: 1 addition & 12 deletions src/Nethermind/Nethermind.Synchronization/Blocks/FastSyncFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ public FastSyncFeed(ISyncConfig syncConfig)

private DownloaderOptions BuildOptions()
{
DownloaderOptions options = DownloaderOptions.MoveToMain;
if (_syncConfig.DownloadReceiptsInFastSync)
{
options |= DownloaderOptions.WithReceipts;
}

if (_syncConfig.DownloadBodiesInFastSync)
{
options |= DownloaderOptions.WithBodies;
}

return options;
return DownloaderOptions.Fast;
}

public override Task<BlocksRequest> PrepareRequest(CancellationToken token = default) => Task.FromResult(_blocksRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FullSyncFeed : ActivatedSyncFeed<BlocksRequest?>

protected override SyncMode ActivationSyncModes { get; } = SyncMode.Full;

private static DownloaderOptions BuildOptions() => DownloaderOptions.WithBodies | DownloaderOptions.Process;
private static DownloaderOptions BuildOptions() => DownloaderOptions.Full;

// ReSharper disable once RedundantTypeArgumentsOfMethod
public override Task<BlocksRequest?> PrepareRequest(CancellationToken token = default) => Task.FromResult<BlocksRequest?>(_blocksRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Nethermind.Synchronization.Blocks
{
[DebuggerDisplay("{Current}")]
public struct SyncBatchSize
public class SyncBatchSize
{
private readonly ILogger _logger;

Expand All @@ -22,9 +22,9 @@ public struct SyncBatchSize

public int Current { get; private set; }

public readonly bool IsMin => Current == Min;
public bool IsMin => Current == Min;

public readonly bool IsMax => Current == Max;
public bool IsMax => Current == Max;

public SyncBatchSize(ILogManager logManager)
{
Expand Down
Loading