From d4f8abc93a33ac53ef21580160da272f5601af4c Mon Sep 17 00:00:00 2001 From: Deeptanshu Sankhwar Date: Sat, 25 Jan 2025 15:12:36 -0700 Subject: [PATCH 1/2] Set MaxAttemptsToUpdatePivot to -1 for infinite pivot update trials --- .../Nethermind.Blockchain/Synchronization/ISyncConfig.cs | 2 +- .../Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs | 2 +- .../ParallelSync/MultiSyncModeSelectorTests.Scenario.cs | 2 +- .../ParallelSync/MultiSyncModeSelector.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs index 0be221fe56b..7c8d2a7c1e6 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs @@ -62,7 +62,7 @@ public interface ISyncConfig : IConfig [ConfigItem(DisabledForCli = true, HiddenFromDocs = true)] Hash256? PivotHashParsed => PivotHash is null ? null : new Hash256(Bytes.FromHexString(PivotHash)); - [ConfigItem(Description = "The max number of attempts to update the pivot block based on the FCU message from the consensus client.", DefaultValue = "2147483647")] + [ConfigItem(Description = "The max number of attempts to update the pivot block based on the FCU message from the consensus client.", DefaultValue = "-1")] int MaxAttemptsToUpdatePivot { get; set; } [ConfigItem(Description = $$""" diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs index e047ec7ae01..67f34062951 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs @@ -104,7 +104,7 @@ private async void OnSyncModeChanged(object? sender, SyncModeChangedEventArgs sy { _syncModeSelector.Changed -= OnSyncModeChanged; } - else if (_attemptsLeft-- > 0) + else if (_attemptsLeft-- < 0) { Interlocked.CompareExchange(ref _updateInProgress, 0, 1); } diff --git a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs index 61704129f4d..34f838d1647 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs @@ -873,7 +873,7 @@ public ScenarioBuilder WhenMergeSyncPivotNotResolvedYet() _syncProgressSetups.Add( () => { - SyncConfig.MaxAttemptsToUpdatePivot = 3; + SyncConfig.MaxAttemptsToUpdatePivot = -1; BeaconSyncStrategy = Substitute.For(); BeaconSyncStrategy.MergeTransitionFinished.Returns(true); return "merge sync pivot not resolved yet"; diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs index 129c6d98134..dd37c973bfa 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs @@ -355,7 +355,7 @@ private bool ShouldBeInBeaconHeaders(bool shouldBeInUpdatingPivot) private bool ShouldBeInUpdatingPivot() { - bool updateRequestedAndNotFinished = _syncConfig.MaxAttemptsToUpdatePivot > 0; + bool updateRequestedAndNotFinished = _syncConfig.MaxAttemptsToUpdatePivot == -1; bool isPostMerge = _beaconSyncStrategy.MergeTransitionFinished; bool stateSyncNotFinished = _syncProgressResolver.FindBestFullState() == 0; From 83610881a726f52fde97ed13e74b9cd313abe444 Mon Sep 17 00:00:00 2001 From: Deeptanshu Sankhwar Date: Tue, 28 Jan 2025 04:35:44 -0700 Subject: [PATCH 2/2] allow any positive value to come from config as well, only handle the infinite case for -1 --- .../Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs | 2 +- .../ParallelSync/MultiSyncModeSelectorTests.Scenario.cs | 4 ++-- .../ParallelSync/MultiSyncModeSelector.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs index 67f34062951..b784db2aca5 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs @@ -104,7 +104,7 @@ private async void OnSyncModeChanged(object? sender, SyncModeChangedEventArgs sy { _syncModeSelector.Changed -= OnSyncModeChanged; } - else if (_attemptsLeft-- < 0) + else if (_syncConfig.MaxAttemptsToUpdatePivot == -1 || _attemptsLeft-- > 0) { Interlocked.CompareExchange(ref _updateInProgress, 0, 1); } diff --git a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs index 34f838d1647..87e6c9e0689 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.Scenario.cs @@ -476,7 +476,7 @@ public ScenarioBuilder IfThisNodeJustFinishedStateSyncButBehindHeader(FastBlocks { SyncProgressResolver.FindBestHeader().Returns(currentBlock); SyncProgressResolver.FindBestFullBlock().Returns(0); //no full blocks available - SyncProgressResolver.FindBestFullState().Returns(currentBlock - 4); //pivot is set to header, but then header follows the head of the chain + SyncProgressResolver.FindBestFullState().Returns(currentBlock - 4); //pivot is set to header, but then header follows the head of the chain SyncProgressResolver.FindBestProcessedBlock().Returns(0); SyncProgressResolver.IsFastBlocksFinished().Returns(fastBlocksState); SyncProgressResolver.ChainDifficulty.Returns((UInt256)currentBlock); @@ -873,7 +873,7 @@ public ScenarioBuilder WhenMergeSyncPivotNotResolvedYet() _syncProgressSetups.Add( () => { - SyncConfig.MaxAttemptsToUpdatePivot = -1; + SyncConfig.MaxAttemptsToUpdatePivot = 3; BeaconSyncStrategy = Substitute.For(); BeaconSyncStrategy.MergeTransitionFinished.Returns(true); return "merge sync pivot not resolved yet"; diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs index dd37c973bfa..2b4a6318f18 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs @@ -355,7 +355,7 @@ private bool ShouldBeInBeaconHeaders(bool shouldBeInUpdatingPivot) private bool ShouldBeInUpdatingPivot() { - bool updateRequestedAndNotFinished = _syncConfig.MaxAttemptsToUpdatePivot == -1; + bool updateRequestedAndNotFinished = _syncConfig.MaxAttemptsToUpdatePivot != 0; bool isPostMerge = _beaconSyncStrategy.MergeTransitionFinished; bool stateSyncNotFinished = _syncProgressResolver.FindBestFullState() == 0;