Skip to content

Commit

Permalink
Bugfix/snap and syncerver (#7305)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekM25 committed Aug 6, 2024
1 parent cc392eb commit 6beafee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/Nethermind/Nethermind.Synchronization.Test/SyncServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Synchronization/SyncServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6beafee

Please sign in to comment.