From da7812ea499377951ec00d4407aeb7da7dfa34a7 Mon Sep 17 00:00:00 2001 From: Osakpolor Obaseki Date: Fri, 1 Mar 2024 13:27:23 +0100 Subject: [PATCH] Fix: Deprecate FastBlocks - Remove all references outside SyncConfig and mark obsolete. --- .../Synchronization/SyncConfig.cs | 8 ++++++-- .../Eth/EthSyncingInfoTests.cs | 1 - src/Nethermind/Nethermind.Init/MemoryHintMan.cs | 2 +- .../EngineModuleTests.Synchronization.cs | 3 --- .../Synchronization/BeaconHeadersSyncTests.cs | 4 ---- .../Synchronization/BeaconPivotTests.cs | 1 - .../Nethermind.Runner.Test/ConfigFilesTests.cs | 14 +++++++------- .../MemoryHintManTests.cs | 5 +---- .../FastBlocks/BodiesSyncFeedTests.cs | 1 - .../FastBlocks/FastBlocksFeedTests.cs | 6 +++--- .../FastBlocks/FastHeadersSyncTests.cs | 12 ++---------- .../FastBlocks/ReceiptsSyncFeedTests.cs | 11 ++++++----- .../MultiSyncModeSelectorTests.Scenario.cs | 7 ------- .../ReceiptSyncFeedTests.cs | 1 - .../SyncProgressResolverTests.cs | 6 +++--- .../SyncReportTest.cs | 17 ++++++++--------- .../FastBlocks/BodiesSyncFeed.cs | 5 +++-- .../FastBlocks/FastHeadersSyncFeed.cs | 5 +++-- .../FastBlocks/ReceiptsSyncFeed.cs | 3 ++- .../ParallelSync/MultiSyncModeSelector.cs | 6 +++--- .../ParallelSync/SyncProgressResolver.cs | 4 +++- .../Reporting/SyncReport.cs | 7 +------ .../Nethermind.Synchronization/Synchronizer.cs | 11 ++++------- 23 files changed, 56 insertions(+), 84 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs index 382de0d089a..b59a1e6fa92 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only - +using System; using Nethermind.Config; using Nethermind.Db; @@ -27,9 +27,13 @@ public bool SynchronizationEnabled } public long? FastSyncCatchUpHeightDelta { get; set; } = 8192; + + // maybe log warnign on set? Remove all references within this file. + // using a class method marked obsolete in reflections might not be possible. + // [ObsoleteAttribute("Fast blocks mode is dependent on and auto enabled in fast sync mode, please use FastSync instead.", false)] public bool FastBlocks { get; set; } public bool UseGethLimitsInFastBlocks { get; set; } = true; - public bool FastSync { get => _fastSync || SnapSync; set => _fastSync = value; } + public bool FastSync { get => _fastSync || SnapSync; set => _fastSync = value; } public bool DownloadHeadersInFastSync { get; set; } = true; public bool DownloadBodiesInFastSync { get; set; } = true; public bool DownloadReceiptsInFastSync { get; set; } = true; diff --git a/src/Nethermind/Nethermind.Facade.Test/Eth/EthSyncingInfoTests.cs b/src/Nethermind/Nethermind.Facade.Test/Eth/EthSyncingInfoTests.cs index b004c2dd59e..cdeb7f58bf4 100644 --- a/src/Nethermind/Nethermind.Facade.Test/Eth/EthSyncingInfoTests.cs +++ b/src/Nethermind/Nethermind.Facade.Test/Eth/EthSyncingInfoTests.cs @@ -169,7 +169,6 @@ public void IsSyncing_ReturnsFalseOnFastSyncWithoutPivot(long bestHeader, long c { FastSync = true, SnapSync = true, - FastBlocks = true, PivotNumber = "0", // Equivalent to not having a pivot }; EthSyncingInfo ethSyncingInfo = new(blockTree, receiptStorage, syncConfig, diff --git a/src/Nethermind/Nethermind.Init/MemoryHintMan.cs b/src/Nethermind/Nethermind.Init/MemoryHintMan.cs index 5fa5c3da2a0..c6362098624 100644 --- a/src/Nethermind/Nethermind.Init/MemoryHintMan.cs +++ b/src/Nethermind/Nethermind.Init/MemoryHintMan.cs @@ -144,7 +144,7 @@ private void AssignTxPoolMemory(ITxPoolConfig txPoolConfig) private void AssignFastBlocksMemory(ISyncConfig syncConfig) { - if (syncConfig.FastBlocks) + if (syncConfig.FastSync) { if (!syncConfig.DownloadBodiesInFastSync && !syncConfig.DownloadReceiptsInFastSync) { diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs index 69046fa9df2..46084601b64 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs @@ -843,7 +843,6 @@ public async Task Blocks_before_pivots_should_not_be_added_if_node_has_never_bee ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = syncedBlockTree.Head?.Number.ToString() ?? "", PivotHash = syncedBlockTree.HeadHash?.ToString() ?? "", PivotTotalDifficulty = syncedBlockTree.Head?.TotalDifficulty?.ToString() ?? "" @@ -865,7 +864,6 @@ public async Task Blocks_before_pivots_should_not_be_added_if_node_has_been_sync ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = syncedBlockTree.Head?.Number.ToString() ?? "", PivotHash = syncedBlockTree.HeadHash?.ToString() ?? "", PivotTotalDifficulty = syncedBlockTree.Head?.TotalDifficulty?.ToString() ?? "" @@ -891,7 +889,6 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_fast_sync() ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = syncedBlockTree.Head?.Number.ToString() ?? "", PivotHash = syncedBlockTree.HeadHash?.ToString() ?? "", PivotTotalDifficulty = syncedBlockTree.Head?.TotalDifficulty?.ToString() ?? "" diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconHeadersSyncTests.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconHeadersSyncTests.cs index 3e7d4dadbee..849ce15648d 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconHeadersSyncTests.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconHeadersSyncTests.cs @@ -153,7 +153,6 @@ public async Task Can_keep_returning_nulls_after_all_batches_were_prepared() SyncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" @@ -184,7 +183,6 @@ public async Task Finishes_when_all_downloaded() ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" @@ -221,7 +219,6 @@ public void Feed_able_to_sync_when_new_pivot_is_set() ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "500", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000000" // default difficulty in block tree builder @@ -308,7 +305,6 @@ public async Task When_pivot_changed_during_header_sync_after_chain_merged__do_n ISyncConfig syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "0", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "0" diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconPivotTests.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconPivotTests.cs index 2dbe02bd60a..83908a33710 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconPivotTests.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/Synchronization/BeaconPivotTests.cs @@ -27,7 +27,6 @@ public void Setup() _syncConfig = new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" diff --git a/src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs b/src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs index a2ae556a89a..e23105f0ee9 100644 --- a/src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs +++ b/src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs @@ -41,15 +41,15 @@ public void Required_config_files_exist(string configWildcard) } } - [TestCase("validators", true, true)] - [TestCase("poacore_validator.cfg", true, true)] - [TestCase("spaceneth", false, false)] - [TestCase("archive", false, false)] - [TestCase("fast", true, true)] - public void Sync_defaults_are_correct(string configWildcard, bool fastSyncEnabled, bool fastBlocksEnabled) + // maybe leave in test since deprecation has not fully happened? + [TestCase("validators", true)] + [TestCase("poacore_validator.cfg", true)] + [TestCase("spaceneth", false)] + [TestCase("archive", false)] + [TestCase("fast", true)] + public void Sync_defaults_are_correct(string configWildcard, bool fastSyncEnabled) { Test(configWildcard, c => c.FastSync, fastSyncEnabled); - Test(configWildcard, c => c.FastBlocks, fastBlocksEnabled); } [TestCase("archive")] diff --git a/src/Nethermind/Nethermind.Runner.Test/MemoryHintManTests.cs b/src/Nethermind/Nethermind.Runner.Test/MemoryHintManTests.cs index f1b069ee8dd..612c699de18 100755 --- a/src/Nethermind/Nethermind.Runner.Test/MemoryHintManTests.cs +++ b/src/Nethermind/Nethermind.Runner.Test/MemoryHintManTests.cs @@ -79,14 +79,12 @@ public void Db_size_are_computed_correctly( [Values(256 * MB, 512 * MB, 1 * GB, 4 * GB, 6 * GB, 16 * GB, 32 * GB, 64 * GB, 128 * GB)] long memoryHint, [Values(1u, 2u, 3u, 4u, 8u, 32u)] uint cpuCount, - [Values(true, false)] bool fastSync, - [Values(true, false)] bool fastBlocks) + [Values(true, false)] bool fastSync) { // OK to throw here if (memoryHint == 256.MB()) { _txPoolConfig.Size = 128; - _syncConfig.FastBlocks = false; _initConfig.DiagnosticMode = DiagnosticMode.MemDb; } @@ -95,7 +93,6 @@ public void Db_size_are_computed_correctly( SyncConfig syncConfig = new SyncConfig(); syncConfig.FastSync = fastSync; - syncConfig.FastBlocks = fastBlocks; IDbConfig dbConfig = _dbConfig; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/BodiesSyncFeedTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/BodiesSyncFeedTests.cs index b0c4eed5118..16b59593ec6 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/BodiesSyncFeedTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/BodiesSyncFeedTests.cs @@ -60,7 +60,6 @@ public void Setup() PivotHash = _pivotBlock.Hash!.ToString(), PivotNumber = _pivotBlock.Number.ToString(), AncientBodiesBarrier = 0, - FastBlocks = true, DownloadBodiesInFastSync = true, }; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastBlocksFeedTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastBlocksFeedTests.cs index fe96acd16f2..d4d94a3855f 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastBlocksFeedTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastBlocksFeedTests.cs @@ -125,7 +125,7 @@ // _syncConfig.PivotNumber = _validTree2048.Head.Number.ToString(); // _syncConfig.PivotTotalDifficulty = _validTree2048.Head.TotalDifficulty.ToString(); // _syncConfig.UseGethLimitsInFastBlocks = false; -// _syncConfig.FastBlocks = true; +// _syncConfig.FastSync = true; // // SetupLocalTree(); // SetupFeed(); @@ -549,7 +549,7 @@ // [Test] // public void Throws_when_launched_and_disabled_in_config() // { -// _syncConfig.FastBlocks = false; +// _syncConfig.FastSync = false; // SetupFeed(); // // LatencySyncPeerMock syncPeer1 = new LatencySyncPeerMock(_validTree2048); @@ -568,7 +568,7 @@ // _syncConfig.UseGethLimitsInFastBlocks = false; // _syncConfig.DownloadBodiesInFastSync = true; // _syncConfig.DownloadReceiptsInFastSync = true; -// _syncConfig.FastBlocks = true; +// _syncConfig.FastSync = true; // // _feed = new FastBlocksFeed(_specProvider, _localBlockTree, _localReceiptStorage, _syncPeerPool, _syncConfig, NullSyncReport.Instance, LimboLogs.Instance); // diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastHeadersSyncTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastHeadersSyncTests.cs index dc3fce6c84f..c83f567e832 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastHeadersSyncTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/FastHeadersSyncTests.cs @@ -59,7 +59,6 @@ public async Task Can_prepare_3_requests_in_a_row() syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" @@ -93,7 +92,6 @@ public async Task When_next_header_hash_update_is_delayed_do_not_drop_peer() syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = pivot.Hash!.Bytes.ToHexString(), PivotTotalDifficulty = pivot.TotalDifficulty.ToString()! @@ -154,7 +152,6 @@ public async Task Can_prepare_several_request_and_ignore_request_from_previous_s syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "500", PivotHash = pivot.Hash!.Bytes.ToHexString(), PivotTotalDifficulty = pivot.TotalDifficulty!.ToString()! @@ -202,7 +199,6 @@ public async Task Will_dispatch_when_only_partially_processed_dependency() syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = pivot.Number.ToString(), PivotHash = pivot.Hash!.ToString(), PivotTotalDifficulty = pivot.TotalDifficulty.ToString()!, @@ -273,7 +269,6 @@ public async Task Can_reset_and_not_hang_when_a_batch_is_processing() syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "500", PivotHash = pivot.Hash!.Bytes.ToHexString(), PivotTotalDifficulty = pivot.TotalDifficulty!.ToString()! @@ -328,7 +323,6 @@ public async Task Can_keep_returning_nulls_after_all_batches_were_prepared() syncConfig: new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" @@ -354,7 +348,7 @@ public async Task Finishes_when_all_downloaded() report.HeadersInQueue.Returns(new MeasuredProgress()); MeasuredProgress measuredProgress = new(); report.FastBlocksHeaders.Returns(measuredProgress); - HeadersSyncFeed feed = new(blockTree, Substitute.For(), new SyncConfig { FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance); + HeadersSyncFeed feed = new(blockTree, Substitute.For(), new SyncConfig { FastSync = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance); await feed.PrepareRequest(); blockTree.LowestInsertedHeader.Returns(Build.A.BlockHeader.WithNumber(1).TestObject); HeadersSyncBatch? result = await feed.PrepareRequest(); @@ -377,7 +371,7 @@ public async Task Can_resume_downloading_from_parent_of_lowest_inserted_header() report.HeadersInQueue.Returns(new MeasuredProgress()); report.FastBlocksHeaders.Returns(new MeasuredProgress()); - HeadersSyncFeed feed = new(blockTree, Substitute.For(), new SyncConfig { FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance); + HeadersSyncFeed feed = new(blockTree, Substitute.For(), new SyncConfig { FastSync = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance); feed.InitializeFeed(); HeadersSyncBatch? result = await feed.PrepareRequest(); @@ -400,7 +394,6 @@ public async Task Will_never_lose_batch_on_invalid_batch() new SyncConfig { FastSync = true, - FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" @@ -466,7 +459,6 @@ public void IsFinished_returns_false_when_headers_not_downloaded() IBlockTree blockTree = Substitute.For(); SyncConfig syncConfig = new() { - FastBlocks = true, FastSync = true, DownloadBodiesInFastSync = true, DownloadReceiptsInFastSync = true, diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/ReceiptsSyncFeedTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/ReceiptsSyncFeedTests.cs index 38b207348d0..b4f4df32f15 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/ReceiptsSyncFeedTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/ReceiptsSyncFeedTests.cs @@ -101,7 +101,7 @@ public void Setup() _blockTree = Substitute.For(); _metadataDb = new TestMemDb(); - _syncConfig = new SyncConfig { FastBlocks = true, FastSync = true }; + _syncConfig = new SyncConfig { FastSync = true }; _syncConfig.PivotNumber = _pivotNumber.ToString(); _syncConfig.PivotHash = Keccak.Zero.ToString(); @@ -138,10 +138,12 @@ private ReceiptsSyncFeed CreateFeed() LimboLogs.Instance); } + // maybe remove test completely(obsolete) (previous throws when fast block not enabled? [Test] - public void Should_throw_when_fast_blocks_not_enabled() + [Obsolete("Fast Blocks mode is active when fast sync mode is active")] + public void Should_throw_when_fast_block_not_enabled() { - _syncConfig = new SyncConfig { FastBlocks = false }; + _syncConfig = new SyncConfig { FastSync = false }; Assert.Throws( () => _feed = new ReceiptsSyncFeed( _specProvider, @@ -407,7 +409,6 @@ public void Is_fast_block_receipts_finished_returns_false_when_receipts_not_down _blockTree = Substitute.For(); _syncConfig = new SyncConfig() { - FastBlocks = true, FastSync = true, DownloadBodiesInFastSync = true, DownloadReceiptsInFastSync = true, @@ -430,7 +431,7 @@ public void Is_fast_block_bodies_finished_returns_true_when_bodies_not_downloade _blockTree = Substitute.For(); _syncConfig = new SyncConfig() { - FastBlocks = true, + FastSync = true, DownloadBodiesInFastSync = false, DownloadReceiptsInFastSync = true, PivotNumber = "1", diff --git a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs index 6e4e327bbe6..43375a68a4e 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs @@ -170,7 +170,6 @@ private void SetDefaults() SyncProgressResolver.IsFastBlocksFinished().Returns(FastBlocksState.None); SyncConfig.FastSync = false; - SyncConfig.FastBlocks = false; SyncConfig.PivotNumber = Pivot.Number.ToString(); SyncConfig.PivotHash = Keccak.Zero.ToString(); SyncConfig.SynchronizationEnabled = true; @@ -733,7 +732,6 @@ public ScenarioBuilder When_FastSync_NoSnapSync_FastBlocks_Configured() _configActions.Add(() => { SyncConfig.FastSync = true; - SyncConfig.FastBlocks = true; SyncConfig.SnapSync = false; return "fast sync with fast blocks"; }); @@ -746,7 +744,6 @@ public ScenarioBuilder When_FastSync_NoSnapSync_WithoutFastBlocks_Configured() _configActions.Add(() => { SyncConfig.FastSync = true; - SyncConfig.FastBlocks = false; SyncConfig.SnapSync = false; return "fast sync without fast blocks"; }); @@ -760,7 +757,6 @@ public ScenarioBuilder WhenSnapSyncWithFastBlocksIsConfigured() { SyncConfig.FastSync = true; SyncConfig.SnapSync = true; - SyncConfig.FastBlocks = true; return "snap sync with fast blocks"; }); @@ -772,7 +768,6 @@ public ScenarioBuilder WhenFastSyncWithFastBlocksIsConfigured() _configActions.Add(() => { SyncConfig.FastSync = true; - SyncConfig.FastBlocks = true; return "fast sync with fast blocks"; }); @@ -785,7 +780,6 @@ public ScenarioBuilder WhenSnapSyncWithoutFastBlocksIsConfigured() { SyncConfig.FastSync = true; SyncConfig.SnapSync = true; - SyncConfig.FastBlocks = false; return "snap sync without fast blocks"; }); @@ -797,7 +791,6 @@ public ScenarioBuilder WhenFullArchiveSyncIsConfigured() _configActions.Add(() => { SyncConfig.FastSync = false; - SyncConfig.FastBlocks = false; return "full archive"; }); diff --git a/src/Nethermind/Nethermind.Synchronization.Test/ReceiptSyncFeedTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/ReceiptSyncFeedTests.cs index b3a178bf287..59ce827e2b0 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/ReceiptSyncFeedTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/ReceiptSyncFeedTests.cs @@ -52,7 +52,6 @@ public async Task ShouldRecoverOnInsertFailure() PivotHash = pivot.Hash!.ToString(), PivotNumber = pivot.Number.ToString(), AncientBodiesBarrier = 0, - FastBlocks = true, DownloadBodiesInFastSync = true, }; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncProgressResolverTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncProgressResolverTests.cs index 2a82088423e..970cd08e722 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncProgressResolverTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncProgressResolverTests.cs @@ -114,6 +114,7 @@ public void Best_state_is_head_if_there_is_suggested_block_without_state() Assert.That(syncProgressResolver.FindBestFullState(), Is.EqualTo(head.Number)); } + // maybe delete(mark obsolete) this test, since fastblock is always used? [Test] public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used() { @@ -121,7 +122,7 @@ public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used( IStateReader stateReader = Substitute.For(); SyncConfig syncConfig = new() { - FastBlocks = false, + FastSync = false, PivotNumber = "1", }; @@ -138,7 +139,6 @@ public void Is_fast_block_bodies_finished_returns_false_when_blocks_not_download IStateReader stateReader = Substitute.For(); SyncConfig syncConfig = new() { - FastBlocks = true, FastSync = true, DownloadBodiesInFastSync = true, DownloadReceiptsInFastSync = true, @@ -159,7 +159,7 @@ public void Is_fast_block_receipts_finished_returns_true_when_receipts_not_downl IStateReader stateReader = Substitute.For(); SyncConfig syncConfig = new() { - FastBlocks = true, + FastSync = true, DownloadBodiesInFastSync = true, DownloadReceiptsInFastSync = false, PivotNumber = "1", diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncReportTest.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncReportTest.cs index ee4c6b8c8cf..074cb71ee56 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncReportTest.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncReportTest.cs @@ -20,10 +20,10 @@ namespace Nethermind.Synchronization.Test [TestFixture, Parallelizable(ParallelScope.All)] public class SyncReportTest { - [TestCase(true, false)] - [TestCase(true, true)] - [TestCase(false, false)] - public void Smoke(bool fastSync, bool fastBlocks) + [Test] + public void Smoke( + [Values(true, false)] + bool fastSync) { ISyncPeerPool pool = Substitute.For(); pool.InitializedPeersCount.Returns(1); @@ -41,7 +41,6 @@ public void Smoke(bool fastSync, bool fastBlocks) SyncConfig syncConfig = new() { - FastBlocks = fastBlocks, FastSync = fastSync, }; @@ -62,9 +61,10 @@ void UpdateMode() timer.Elapsed += Raise.Event(); } - [TestCase(false)] - [TestCase(true)] - public void Ancient_bodies_and_receipts_are_reported_correctly(bool setBarriers) + [Test] + public void Ancient_bodies_and_receipts_are_reported_correctly( + [Values(false, true)] + bool setBarriers) { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; ISyncPeerPool pool = Substitute.For(); @@ -86,7 +86,6 @@ public void Ancient_bodies_and_receipts_are_reported_correctly(bool setBarriers) SyncConfig syncConfig = new() { - FastBlocks = true, FastSync = true, PivotNumber = "100", }; diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs index d2809c473e0..10c91677bbb 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs @@ -66,10 +66,11 @@ public BodiesSyncFeed( _blocksDb = blocksDb ?? throw new ArgumentNullException(nameof(blocksDb)); _flushDbInterval = flushDbInterval; - if (!_syncConfig.FastBlocks) + // maybe remove fastblock(now replaced with fastsync) condition completely? + if (!_syncConfig.FastSync) { throw new InvalidOperationException( - "Entered fast blocks mode without fast blocks enabled in configuration."); + "Entered fast sync with fast blocks mode without fast sync enabled in configuration."); } _pivotNumber = -1; // First reset in `InitializeFeed`. diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs index e6a0ffefbc0..2dcd845d6ec 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs @@ -179,9 +179,10 @@ public HeadersSyncFeed( _headersRequestSize = NethermindSyncLimits.MaxHeaderFetch; } - if (!_syncConfig.FastBlocks && !alwaysStartHeaderSync) + // maybe remove fastblock(now replaced with fastsync) condition completely? + if (!_syncConfig.FastSync && !alwaysStartHeaderSync) { - throw new InvalidOperationException("Entered fast blocks mode without fast blocks enabled in configuration."); + throw new InvalidOperationException("Entered fast sync with fast blocks mode without fast sync enabled in configuration."); } _historicalOverrides.TryGetValue(_blockTree.NetworkId, out _expectedDifficultyOverride); diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs index 847c4b69184..69cccc2dddc 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs @@ -67,7 +67,8 @@ public ReceiptsSyncFeed( _syncReport = syncReport ?? throw new ArgumentNullException(nameof(syncReport)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); - if (!_syncConfig.FastBlocks) + // maybe remove fastblock(now replaced with fastsync) condition completely? + if (!_syncConfig.FastSync) { throw new InvalidOperationException("Entered fast blocks mode without fast blocks enabled in configuration."); } diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs index ab8ef0ef71c..41bc3c25c73 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs @@ -28,7 +28,7 @@ namespace Nethermind.Synchronization.ParallelSync /// - Their are enabled based on and . /// * When is enabled: /// - Beacon modes are exclusive with , , and . - /// - Beacon modes can run parallel with syncing old state (, and ). + /// - Beacon modes can run parallel with syncing old state (, (the default and always on) and ). /// * When is disabled: /// - Beacon modes are allied directly. /// - If no Beacon mode is applied and we have good peers on the network we apply ,. @@ -57,7 +57,7 @@ public class MultiSyncModeSelector : ISyncModeSelector private long _pivotNumber; private bool FastSyncEnabled => _syncConfig.FastSync; private bool SnapSyncEnabled => _syncConfig.SnapSync && !_isSnapSyncDisabledAfterAnyStateSync; - private bool FastBlocksEnabled => _syncConfig.FastSync && _syncConfig.FastBlocks; + private bool FastBlocksEnabled => _syncConfig.FastSync; // maybe replace all reference with FastSyycEnabled? private bool FastBodiesEnabled => FastBlocksEnabled && _syncConfig.DownloadBodiesInFastSync; private bool FastReceiptsEnabled => FastBlocksEnabled && _syncConfig.DownloadReceiptsInFastSync; private bool FastBlocksHeadersFinished => !FastBlocksEnabled || _syncProgressResolver.IsFastBlocksHeadersFinished(); @@ -383,7 +383,7 @@ private bool ShouldBeInFastSyncMode(Snapshot best) return false; } - if (_syncConfig.FastBlocks && _pivotNumber != 0 && best.Header == 0) + if (_pivotNumber != 0 && best.Header == 0) { // do not start fast sync until at least one header is downloaded or we would start from zero // we are fine to start from zero if we do not use fast blocks diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/SyncProgressResolver.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/SyncProgressResolver.cs index 9c70049fecc..672879dc5d6 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/SyncProgressResolver.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/SyncProgressResolver.cs @@ -98,7 +98,9 @@ public bool IsFastBlocksReceiptsFinished() => !IsFastBlocks() || (!_syncConfig.D private bool IsFastBlocks() { - bool isFastBlocks = _syncConfig.FastBlocks; + // maybe eliminate the entire code refeferencing this function why? fast block depends on fastsync so this code might just be check that is now unnecessay! + // name isFastBlocks left in place for correlation with protocol specification. + bool isFastBlocks = _syncConfig.FastSync; // if pivot number is 0 then it is equivalent to fast blocks disabled if (!isFastBlocks || _syncConfig.PivotNumberParsed == 0L) diff --git a/src/Nethermind/Nethermind.Synchronization/Reporting/SyncReport.cs b/src/Nethermind/Nethermind.Synchronization/Reporting/SyncReport.cs index 7c08123056a..cc1ee42de31 100644 --- a/src/Nethermind/Nethermind.Synchronization/Reporting/SyncReport.cs +++ b/src/Nethermind/Nethermind.Synchronization/Reporting/SyncReport.cs @@ -230,12 +230,11 @@ private void WriteSyncConfigReport() if (!_logger.IsTrace) return; bool isFastSync = _syncConfig.FastSync; - bool isFastBlocks = _syncConfig.FastBlocks; bool bodiesInFastBlocks = _syncConfig.DownloadBodiesInFastSync; bool receiptsInFastBlocks = _syncConfig.DownloadReceiptsInFastSync; StringBuilder builder = new(); - if (isFastSync && isFastBlocks) + if (isFastSync) { builder.Append($"Sync config - fast sync with fast blocks from block {_syncConfig.PivotNumber}"); if (bodiesInFastBlocks) @@ -248,10 +247,6 @@ private void WriteSyncConfigReport() builder.Append(" + receipts"); } } - else if (isFastSync) - { - builder.Append("Sync config - fast sync without fast blocks"); - } else { builder.Append("Sync config - full archive sync"); diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index 9cde79a661c..782dd9ceded 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -153,10 +153,7 @@ public virtual void Start() if (_syncConfig.FastSync) { - if (_syncConfig.FastBlocks) - { - StartFastBlocksComponents(); - } + StartFastBlocksComponents(); StartFastSyncComponents(); @@ -186,19 +183,19 @@ public virtual void Start() private HeadersSyncFeed? CreateHeadersSyncFeed() { - if (!_syncConfig.FastSync || !_syncConfig.FastBlocks || !_syncConfig.DownloadHeadersInFastSync) return null; + if (!_syncConfig.FastSync || !_syncConfig.DownloadHeadersInFastSync) return null; return new HeadersSyncFeed(_blockTree, _syncPeerPool, _syncConfig, _syncReport, _logManager); } private BodiesSyncFeed? CreateBodiesSyncFeed() { - if (!_syncConfig.FastSync || !_syncConfig.FastBlocks || !_syncConfig.DownloadHeadersInFastSync || !_syncConfig.DownloadBodiesInFastSync) return null; + if (!_syncConfig.FastSync || !_syncConfig.DownloadHeadersInFastSync || !_syncConfig.DownloadBodiesInFastSync) return null; return new BodiesSyncFeed(_specProvider, _blockTree, _syncPeerPool, _syncConfig, _syncReport, _dbProvider.BlocksDb, _dbProvider.MetadataDb, _logManager); } private ReceiptsSyncFeed? CreateReceiptsSyncFeed() { - if (!_syncConfig.FastSync || !_syncConfig.FastBlocks || !_syncConfig.DownloadHeadersInFastSync || !_syncConfig.DownloadBodiesInFastSync || !_syncConfig.DownloadReceiptsInFastSync) return null; + if (!_syncConfig.FastSync || !_syncConfig.DownloadHeadersInFastSync || !_syncConfig.DownloadBodiesInFastSync || !_syncConfig.DownloadReceiptsInFastSync) return null; return new ReceiptsSyncFeed(_specProvider, _blockTree, _receiptStorage, _syncPeerPool, _syncConfig, _syncReport, _dbProvider.MetadataDb, _logManager); }