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

Sleep peer if can't get account range #5323

Merged
merged 1 commit into from
Feb 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Test01()
ISyncModeSelector selector = Substitute.For<ISyncModeSelector>();
ISnapProvider snapProvider = Substitute.For<ISnapProvider>();

Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, null!, LimboLogs.Instance);
Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, LimboLogs.Instance);

feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer1);
feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer1);
Expand Down Expand Up @@ -57,7 +57,7 @@ public void Test02()
ISyncModeSelector selector = Substitute.For<ISyncModeSelector>();
ISnapProvider snapProvider = Substitute.For<ISnapProvider>();

Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, null!, LimboLogs.Instance);
Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, LimboLogs.Instance);

feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer1);
feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer1);
Expand Down Expand Up @@ -92,7 +92,7 @@ public void Test03()
ISyncModeSelector selector = Substitute.For<ISyncModeSelector>();
ISnapProvider snapProvider = Substitute.For<ISnapProvider>();

Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, null!, LimboLogs.Instance);
Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, LimboLogs.Instance);

feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer2);
feed.AnalyzeResponsePerPeer(AddRangeResult.OK, peer1);
Expand All @@ -117,7 +117,7 @@ public void Test04()
ISyncModeSelector selector = Substitute.For<ISyncModeSelector>();
ISnapProvider snapProvider = Substitute.For<ISnapProvider>();

Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, null!, LimboLogs.Instance);
Synchronization.SnapSync.SnapSyncFeed feed = new(selector, snapProvider, LimboLogs.Instance);

for (int i = 0; i < 200; i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using FluentAssertions;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core.Crypto;
using Nethermind.Logging;
using Nethermind.State.Snap;
using Nethermind.Synchronization.ParallelSync;
using Nethermind.Synchronization.Peers;
using Nethermind.Synchronization.SnapSync;
using NSubstitute;
using NUnit.Framework;

namespace Nethermind.Synchronization.Test.SnapSync.SnapSyncFeed;

public class SnapSyncFeedTests
{
[Test]
public void WhenAccountRequestEmpty_ReturnNoProgress()
{
ISnapProvider snapProvider = Substitute.For<ISnapProvider>();
Synchronization.SnapSync.SnapSyncFeed feed = new(
Substitute.For<ISyncModeSelector>(), snapProvider, LimboLogs.Instance);

snapProvider.AddAccountRange(Arg.Any<AccountRange>(), Arg.Any<AccountsAndProofs>())
.Returns(AddRangeResult.ExpiredRootHash);

SnapSyncBatch response = new SnapSyncBatch();
response.AccountRangeRequest = new AccountRange(Keccak.Zero, Keccak.Zero);
response.AccountRangeResponse = new AccountsAndProofs();

PeerInfo peer = new PeerInfo(Substitute.For<ISyncPeer>());

feed.HandleResponse(response, peer).Should().Be(SyncResponseHandlingResult.NoProgress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SnapSyncFeed : SyncFeed<SnapSyncBatch?>, IDisposable
public override bool IsMultiFeed => true;
public override AllocationContexts Contexts => AllocationContexts.Snap;

public SnapSyncFeed(ISyncModeSelector syncModeSelector, ISnapProvider snapProvider, IBlockTree blockTree, ILogManager logManager)
public SnapSyncFeed(ISyncModeSelector syncModeSelector, ISnapProvider snapProvider, ILogManager logManager)
{
_syncModeSelector = syncModeSelector;
_snapProvider = snapProvider;
Expand Down Expand Up @@ -188,6 +188,11 @@ public SyncResponseHandlingResult AnalyzeResponsePerPeer(AddRangeResult result,
}
}

if (result == AddRangeResult.ExpiredRootHash)
{
return SyncResponseHandlingResult.NoProgress;
}

return SyncResponseHandlingResult.OK;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Synchronization/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void StartStateSyncComponents()

private void StartSnapSyncComponents()
{
_snapSyncFeed = new SnapSyncFeed(_syncMode, _snapProvider, _blockTree, _logManager);
_snapSyncFeed = new SnapSyncFeed(_syncMode, _snapProvider, _logManager);
SnapSyncDispatcher dispatcher = new(_snapSyncFeed!, _syncPeerPool, new SnapSyncAllocationStrategyFactory(), _logManager);

Task _ = dispatcher.Start(_syncCancellation!.Token).ContinueWith(t =>
Expand Down