Skip to content

Commit

Permalink
Fix sync pivot not set when dbload (#6080)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Sep 7, 2023
1 parent f0c7ea7 commit 4cdd176
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public void Load_from_db()
.TheSyncModeShouldBe(SyncMode.DbLoad);
}

[Test]
public void Load_from_without_merge_sync_pivot_resolved()
{
Scenario.GoesLikeThis(_needToWaitForHeaders)
.WhenMergeSyncPivotNotResolvedYet()
.WhateverThePeerPoolLooks()
.WhenThisNodeIsLoadingBlocksFromDb()
.ThenInAnyFastSyncConfiguration()
.TheSyncModeShouldBe(SyncMode.DbLoad | SyncMode.UpdatingPivot);
}

[Test]
public void Simple_archive()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,21 @@ public ScenarioBuilder WhenConsensusRequiresToWaitForHeaders(bool needToWaitForH
_needToWaitForHeaders = needToWaitForHeaders;
return this;
}

public ScenarioBuilder WhenMergeSyncPivotNotResolvedYet()
{
_syncProgressSetups.Add(
() =>
{
SyncConfig.MaxAttemptsToUpdatePivot = 3;
BeaconSyncStrategy = Substitute.For<IBeaconSyncStrategy>();
BeaconSyncStrategy.GetFinalizedHash().Returns(TestItem.KeccakA);
return "merge sync pivot not resolved yet";
}
);

return this;
}
}

public static ScenarioBuilder GoesLikeThis(bool needToWaitForHeaders) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ public void Stop()
public void Update()
{
_pivotNumber = _syncConfig.PivotNumberParsed;
bool shouldBeInUpdatingPivot = ShouldBeInUpdatingPivot();

SyncMode newModes;
string reason = string.Empty;
if (_syncProgressResolver.IsLoadingBlocksFromDb())
{
newModes = SyncMode.DbLoad;
if (shouldBeInUpdatingPivot)
{
newModes |= SyncMode.UpdatingPivot;
}
}
else if (!_syncConfig.SynchronizationEnabled)
{
Expand All @@ -149,7 +154,6 @@ public void Update()
else
{
bool inBeaconControl = _beaconSyncStrategy.ShouldBeInBeaconModeControl();
bool shouldBeInUpdatingPivot = ShouldBeInUpdatingPivot();
(UInt256? peerDifficulty, long? peerBlock) = ReloadDataFromPeers();
// if there are no peers that we could use then we cannot sync
if (peerDifficulty is null || peerBlock is null || peerBlock == 0)
Expand Down

0 comments on commit 4cdd176

Please sign in to comment.