Skip to content

Commit

Permalink
Fix: Deprecate FastBlocks - Remove all references outside SyncConfig …
Browse files Browse the repository at this point in the history
…and mark obsolete.
  • Loading branch information
obasekiosa committed Mar 1, 2024
1 parent 8c7336b commit da7812e
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Init/MemoryHintMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? ""
Expand All @@ -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() ?? ""
Expand All @@ -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() ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void Setup()
_syncConfig = new SyncConfig
{
FastSync = true,
FastBlocks = true,
PivotNumber = "1000",
PivotHash = Keccak.Zero.ToString(),
PivotTotalDifficulty = "1000"
Expand Down
14 changes: 7 additions & 7 deletions src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISyncConfig, bool>(configWildcard, c => c.FastSync, fastSyncEnabled);
Test<ISyncConfig, bool>(configWildcard, c => c.FastBlocks, fastBlocksEnabled);
}

[TestCase("archive")]
Expand Down
5 changes: 1 addition & 4 deletions src/Nethermind/Nethermind.Runner.Test/MemoryHintManTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -95,7 +93,6 @@ public void Db_size_are_computed_correctly(

SyncConfig syncConfig = new SyncConfig();
syncConfig.FastSync = fastSync;
syncConfig.FastBlocks = fastBlocks;

IDbConfig dbConfig = _dbConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void Setup()
PivotHash = _pivotBlock.Hash!.ToString(),
PivotNumber = _pivotBlock.Number.ToString(),
AncientBodiesBarrier = 0,
FastBlocks = true,
DownloadBodiesInFastSync = true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()!
Expand Down Expand Up @@ -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()!
Expand Down Expand Up @@ -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()!,
Expand Down Expand Up @@ -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()!
Expand Down Expand Up @@ -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"
Expand All @@ -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<ISyncPeerPool>(), new SyncConfig { FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance);
HeadersSyncFeed feed = new(blockTree, Substitute.For<ISyncPeerPool>(), 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();
Expand All @@ -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<ISyncPeerPool>(), new SyncConfig { FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance);
HeadersSyncFeed feed = new(blockTree, Substitute.For<ISyncPeerPool>(), new SyncConfig { FastSync = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000" }, report, LimboLogs.Instance);
feed.InitializeFeed();
HeadersSyncBatch? result = await feed.PrepareRequest();

Expand All @@ -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"
Expand Down Expand Up @@ -466,7 +459,6 @@ public void IsFinished_returns_false_when_headers_not_downloaded()
IBlockTree blockTree = Substitute.For<IBlockTree>();
SyncConfig syncConfig = new()
{
FastBlocks = true,
FastSync = true,
DownloadBodiesInFastSync = true,
DownloadReceiptsInFastSync = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void Setup()
_blockTree = Substitute.For<IBlockTree>();
_metadataDb = new TestMemDb();

_syncConfig = new SyncConfig { FastBlocks = true, FastSync = true };
_syncConfig = new SyncConfig { FastSync = true };
_syncConfig.PivotNumber = _pivotNumber.ToString();
_syncConfig.PivotHash = Keccak.Zero.ToString();

Expand Down Expand Up @@ -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<InvalidOperationException>(
() => _feed = new ReceiptsSyncFeed(
_specProvider,
Expand Down Expand Up @@ -407,7 +409,6 @@ public void Is_fast_block_receipts_finished_returns_false_when_receipts_not_down
_blockTree = Substitute.For<IBlockTree>();
_syncConfig = new SyncConfig()
{
FastBlocks = true,
FastSync = true,
DownloadBodiesInFastSync = true,
DownloadReceiptsInFastSync = true,
Expand All @@ -430,7 +431,7 @@ public void Is_fast_block_bodies_finished_returns_true_when_bodies_not_downloade
_blockTree = Substitute.For<IBlockTree>();
_syncConfig = new SyncConfig()
{
FastBlocks = true,
FastSync = true,
DownloadBodiesInFastSync = false,
DownloadReceiptsInFastSync = true,
PivotNumber = "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
});
Expand All @@ -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";
});
Expand All @@ -760,7 +757,6 @@ public ScenarioBuilder WhenSnapSyncWithFastBlocksIsConfigured()
{
SyncConfig.FastSync = true;
SyncConfig.SnapSync = true;
SyncConfig.FastBlocks = true;
return "snap sync with fast blocks";
});

Expand All @@ -772,7 +768,6 @@ public ScenarioBuilder WhenFastSyncWithFastBlocksIsConfigured()
_configActions.Add(() =>
{
SyncConfig.FastSync = true;
SyncConfig.FastBlocks = true;
return "fast sync with fast blocks";
});

Expand All @@ -785,7 +780,6 @@ public ScenarioBuilder WhenSnapSyncWithoutFastBlocksIsConfigured()
{
SyncConfig.FastSync = true;
SyncConfig.SnapSync = true;
SyncConfig.FastBlocks = false;
return "snap sync without fast blocks";
});

Expand All @@ -797,7 +791,6 @@ public ScenarioBuilder WhenFullArchiveSyncIsConfigured()
_configActions.Add(() =>
{
SyncConfig.FastSync = false;
SyncConfig.FastBlocks = false;
return "full archive";
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public async Task ShouldRecoverOnInsertFailure()
PivotHash = pivot.Hash!.ToString(),
PivotNumber = pivot.Number.ToString(),
AncientBodiesBarrier = 0,
FastBlocks = true,
DownloadBodiesInFastSync = true,
};

Expand Down
Loading

0 comments on commit da7812e

Please sign in to comment.