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

Bugfix/snap and syncerver #7305

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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