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

Set minimum state pivot to be at least the block after #7949

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,7 +3,6 @@

using FluentAssertions;
using Nethermind.Blockchain;
using Nethermind.Blockchain.Synchronization;
using Nethermind.Core.Test.Builders;
using Nethermind.Logging;
using NSubstitute;
Expand All @@ -13,16 +12,18 @@ namespace Nethermind.Synchronization.Test.SnapSync;

public class StateSyncPivotTest
{
[TestCase(1000, 1000, 10, 100, 1022)]
[TestCase(900, 1000, 10, 50, 1022)]
[TestCase(900, 1000, 10, 100, 1022)]
[TestCase(900, 900, 32, 100, 900)]
[TestCase(1000, 1000, 10, 100, 1022, 0)]
[TestCase(900, 1000, 10, 50, 1022, 0)]
[TestCase(900, 1000, 10, 100, 1022, 0)]
[TestCase(900, 900, 32, 100, 900, 0)]
[TestCase(0, 300, 32, 100, 301, 300)]
public void Will_set_new_best_header_some_distance_from_best_suggested(
int originalBestSuggested,
int newBestSuggested,
int minDistance,
int maxDistance,
int newBestHeader
int newPivotHeader,
int syncPivot
)
{
IBlockTree blockTree = Substitute.For<IBlockTree>();
Expand All @@ -32,6 +33,8 @@ int newBestHeader
Synchronization.FastSync.StateSyncPivot stateSyncPivot = new Synchronization.FastSync.StateSyncPivot(blockTree,
new TestSyncConfig()
{
PivotNumber = syncPivot.ToString(),
FastSync = true,
StateMinDistanceFromHead = minDistance,
StateMaxDistanceFromHead = maxDistance,
}, LimboLogs.Instance);
Expand All @@ -40,6 +43,6 @@ int newBestHeader
stateSyncPivot.GetPivotHeader().Should().NotBeNull();

blockTree.BestSuggestedHeader.Returns(Build.A.BlockHeader.WithNumber(newBestSuggested).TestObject);
stateSyncPivot.GetPivotHeader().Number.Should().Be(newBestHeader);
stateSyncPivot.GetPivotHeader().Number.Should().Be(newPivotHeader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ public void UpdateHeaderForcefully()
private void TrySetNewBestHeader(string msg)
{
BlockHeader bestSuggestedHeader = _blockTree.BestSuggestedHeader;
long targetBlockNumber = Math.Max(bestSuggestedHeader.Number + MultiSyncModeSelector.FastSyncLag - _syncConfig.StateMinDistanceFromHead, 0);
long targetBlockNumber = bestSuggestedHeader.Number + MultiSyncModeSelector.FastSyncLag - _syncConfig.StateMinDistanceFromHead;
targetBlockNumber = Math.Max(targetBlockNumber, 0);
// The new pivot must be at least one block after the sync pivot as the forward downloader does not
// download the block at the sync pivot which may cause state not found error if state was downloaded
// at exactly sync pivot.
targetBlockNumber = Math.Max(targetBlockNumber, _syncConfig.PivotNumberParsed + 1);

BlockHeader bestHeader = _blockTree.FindHeader(targetBlockNumber);
if (bestHeader is not null)
{
Expand Down
Loading