From 243063a281274f4c7ebff8e05188341593afcb95 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 5 Aug 2024 09:59:52 +0200 Subject: [PATCH 1/2] Fix in SyncServer (cherry picked from commit 3a5ebd463b27c3e974a24bfc996295994fa73792) --- .../SyncServerTests.cs | 48 +++++++++++++++++++ .../ParallelSync/StaticSelector.cs | 2 + .../Nethermind.Synchronization/SyncServer.cs | 4 +- src/tests | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncServerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncServerTests.cs index 28a8b87709e..46cadf01253 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncServerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncServerTests.cs @@ -155,6 +155,54 @@ public void Can_accept_blocks_that_are_fine() Assert.That(block.Header, Is.EqualTo(localBlockTree.BestSuggestedHeader)); } + [TestCase(SyncMode.SnapSync, false)] + [TestCase(SyncMode.FastSync, false)] + [TestCase(SyncMode.StateNodes, false)] + [TestCase(SyncMode.Full, true)] + public void Should_accept_or_not_blocks_depends_on_sync_mode(SyncMode syncMode, bool expectBlockAccepted) + { + Context ctx = new(); + BlockTree remoteBlockTree = Build.A.BlockTree().OfChainLength(10).TestObject; + BlockTree localBlockTree = Build.A.BlockTree().OfChainLength(9).TestObject; + + StaticSelector staticSelector; + switch (syncMode) + { + case SyncMode.SnapSync: + staticSelector = StaticSelector.SnapSync; + break; + case SyncMode.FastSync: + staticSelector = StaticSelector.FastSync; + break; + case SyncMode.StateNodes: + staticSelector = StaticSelector.StateNodesWithFastBlocks; + break; + default: + staticSelector = StaticSelector.Full; + break; + } + + ctx.SyncServer = new SyncServer( + new MemDb(), + new MemDb(), + localBlockTree, + NullReceiptStorage.Instance, + Always.Valid, + Always.Valid, + ctx.PeerPool, + staticSelector, + new SyncConfig(), + Policy.FullGossip, + MainnetSpecProvider.Instance, + LimboLogs.Instance); + + Block block = remoteBlockTree.FindBlock(9, BlockTreeLookupOptions.None)!; + + ctx.SyncServer.AddNewBlock(block, ctx.NodeWhoSentTheBlock); + + block.Header.Equals(localBlockTree.BestSuggestedHeader).Should().Be(expectBlockAccepted); + } + [Test] public void Terminal_block_with_lower_td_should_not_change_best_suggested_but_should_be_added_to_block_tree() { diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/StaticSelector.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/StaticSelector.cs index e4304064a82..2bec837c611 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/StaticSelector.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/StaticSelector.cs @@ -14,6 +14,8 @@ public StaticSelector(SyncMode syncMode) public static StaticSelector Full { get; } = new(SyncMode.Full); + public static StaticSelector SnapSync { get; } = new(SyncMode.SnapSync); + public static StaticSelector FastSync { get; } = new(SyncMode.FastSync); public static StaticSelector FastBlocks { get; } = new(SyncMode.FastBlocks); diff --git a/src/Nethermind/Nethermind.Synchronization/SyncServer.cs b/src/Nethermind/Nethermind.Synchronization/SyncServer.cs index 30ed536806e..429f27af1be 100644 --- a/src/Nethermind/Nethermind.Synchronization/SyncServer.cs +++ b/src/Nethermind/Nethermind.Synchronization/SyncServer.cs @@ -198,9 +198,9 @@ public void AddNewBlock(Block block, ISyncPeer nodeWhoSentTheBlock) BroadcastBlock(blockToBroadCast, false, nodeWhoSentTheBlock); SyncMode syncMode = _syncModeSelector.Current; - bool notInFastSyncNorStateSync = (syncMode & (SyncMode.FastSync | SyncMode.StateNodes)) == SyncMode.None; + bool notInFastSyncNorStateSyncNorSnap = (syncMode & (SyncMode.FastSync | SyncMode.StateNodes | SyncMode.SnapSync)) == SyncMode.None; bool inFullSyncOrWaitingForBlocks = (syncMode & (SyncMode.Full | SyncMode.WaitingForBlock)) != SyncMode.None; - if (notInFastSyncNorStateSync || inFullSyncOrWaitingForBlocks) + if (notInFastSyncNorStateSyncNorSnap || inFullSyncOrWaitingForBlocks) { LogBlockAuthorNicely(block, nodeWhoSentTheBlock); SyncBlock(block, nodeWhoSentTheBlock); diff --git a/src/tests b/src/tests index 8c215d6b56f..661356317ac 160000 --- a/src/tests +++ b/src/tests @@ -1 +1 @@ -Subproject commit 8c215d6b56fed36501d04c165093357f102de2ac +Subproject commit 661356317ac6df52208d54187e692472a25a01f8 From ee6bcd59c7462cc1b7680d395c671f29ab262ae4 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 5 Aug 2024 10:17:39 +0200 Subject: [PATCH 2/2] revert tests --- src/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests b/src/tests index 661356317ac..8c215d6b56f 160000 --- a/src/tests +++ b/src/tests @@ -1 +1 @@ -Subproject commit 661356317ac6df52208d54187e692472a25a01f8 +Subproject commit 8c215d6b56fed36501d04c165093357f102de2ac