From 7588e22ac0c4e03e7cef77deedb714a51ff5323c Mon Sep 17 00:00:00 2001 From: Marcin Sobczak <77129288+marcindsobczak@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:25:54 +0200 Subject: [PATCH 1/2] Block beacon header sync until global pivot is updated (#7614) --- .../EngineModuleTests.Setup.cs | 1 + .../Handlers/ForkchoiceUpdatedHandler.cs | 4 ++-- .../Synchronization/BeaconSync.cs | 16 ++++++++++++++-- .../Synchronization/PivotUpdator.cs | 2 ++ .../IBeaconSyncStrategy.cs | 3 +++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index cffbfafb516..a76bdf5eff8 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -90,6 +90,7 @@ protected IEngineRpcModule CreateEngineModule(MergeTestBlockchain chain, ISyncCo chain.LogManager); invalidChainTracker.SetupBlockchainProcessorInterceptor(chain.BlockchainProcessor); chain.BeaconSync = new BeaconSync(chain.BeaconPivot, chain.BlockTree, synchronizationConfig, blockCacheService, chain.PoSSwitcher, chain.LogManager); + chain.BeaconSync.AllowBeaconHeaderSync(); EngineRpcCapabilitiesProvider capabilitiesProvider = new(chain.SpecProvider); return new EngineRpcModule( new GetPayloadV1Handler( diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/ForkchoiceUpdatedHandler.cs b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/ForkchoiceUpdatedHandler.cs index f5d95a00ac4..7d3507e8ed6 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/ForkchoiceUpdatedHandler.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/ForkchoiceUpdatedHandler.cs @@ -322,12 +322,12 @@ private ResultWrapper StartBuildingPayload(Block newH private void StartNewBeaconHeaderSync(ForkchoiceStateV1 forkchoiceState, BlockHeader blockHeader, string requestStr) { - _mergeSyncController.InitBeaconHeaderSync(blockHeader); + bool isSyncInitialized = _mergeSyncController.TryInitBeaconHeaderSync(blockHeader); _beaconPivot.ProcessDestination = blockHeader; _peerRefresher.RefreshPeers(blockHeader.Hash!, blockHeader.ParentHash!, forkchoiceState.FinalizedBlockHash); _blockCacheService.FinalizedHash = forkchoiceState.FinalizedBlockHash; - if (_logger.IsInfo) _logger.Info($"Start a new sync process, Request: {requestStr}."); + if (isSyncInitialized && _logger.IsInfo) _logger.Info($"Start a new sync process, Request: {requestStr}."); } private bool IsInconsistent(Hash256 blockHash) => blockHash != Keccak.Zero && !_blockTree.IsMainChain(blockHash); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconSync.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconSync.cs index 368c5d11516..73e8811ea54 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconSync.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconSync.cs @@ -23,6 +23,10 @@ public class BeaconSync : IMergeSyncController, IBeaconSyncStrategy private bool _isInBeaconModeControl = false; private readonly ILogger _logger; + // beacon header sync can be initialized only when global pivot is already set, + // otherwise it might result in conflicting pivots and a deadlock + private bool _canInitBeaconHeaderSync = false; + public BeaconSync( IBeaconPivot beaconPivot, IBlockTree blockTree, @@ -50,10 +54,13 @@ public void StopSyncing() _isInBeaconModeControl = true; } - public void InitBeaconHeaderSync(BlockHeader blockHeader) + public bool TryInitBeaconHeaderSync(BlockHeader blockHeader) { + if (!_canInitBeaconHeaderSync) return false; + StopBeaconModeControl(); _beaconPivot.EnsurePivot(blockHeader); + return true; } public void StopBeaconModeControl() @@ -61,6 +68,11 @@ public void StopBeaconModeControl() _isInBeaconModeControl = false; } + public void AllowBeaconHeaderSync() + { + _canInitBeaconHeaderSync = true; + } + public bool ShouldBeInBeaconHeaders() { bool beaconPivotExists = _beaconPivot.BeaconPivotExists(); @@ -130,7 +142,7 @@ public interface IMergeSyncController { void StopSyncing(); - void InitBeaconHeaderSync(BlockHeader blockHeader); + bool TryInitBeaconHeaderSync(BlockHeader blockHeader); void StopBeaconModeControl(); } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs index d4f874d75fb..141af1b44de 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/PivotUpdator.cs @@ -110,6 +110,7 @@ private async void OnSyncModeChanged(object? sender, SyncModeChangedEventArgs sy { _syncModeSelector.Changed -= OnSyncModeChanged; _syncConfig.MaxAttemptsToUpdatePivot = 0; + _beaconSyncStrategy.AllowBeaconHeaderSync(); if (_logger.IsInfo) _logger.Info("Failed to update pivot block, skipping it and using pivot from config file."); } } @@ -254,6 +255,7 @@ private void UpdateConfigValues(Hash256 finalizedBlockHash, long finalizedBlockN _syncConfig.PivotHash = finalizedBlockHash.ToString(); _syncConfig.PivotNumber = finalizedBlockNumber.ToString(); _syncConfig.MaxAttemptsToUpdatePivot = 0; + _beaconSyncStrategy.AllowBeaconHeaderSync(); } } diff --git a/src/Nethermind/Nethermind.Synchronization/IBeaconSyncStrategy.cs b/src/Nethermind/Nethermind.Synchronization/IBeaconSyncStrategy.cs index 9043437fe28..ab92cf45e4a 100644 --- a/src/Nethermind/Nethermind.Synchronization/IBeaconSyncStrategy.cs +++ b/src/Nethermind/Nethermind.Synchronization/IBeaconSyncStrategy.cs @@ -12,6 +12,8 @@ private No() { } public static No BeaconSync { get; } = new(); + public void AllowBeaconHeaderSync() { } + public bool ShouldBeInBeaconHeaders() => false; public bool ShouldBeInBeaconModeControl() => false; @@ -24,6 +26,7 @@ private No() { } public interface IBeaconSyncStrategy { + void AllowBeaconHeaderSync(); bool ShouldBeInBeaconHeaders(); bool ShouldBeInBeaconModeControl(); bool IsBeaconSyncFinished(BlockHeader? blockHeader); From 25f681b2b90fe4ff1ac39eb47df09da6eaf63b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Chodo=C5=82a?= <43241881+kamilchodola@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:48:04 +0200 Subject: [PATCH 2/2] Faster and not locked VM creation (#7639) --- .github/workflows/sync-supported-chains.yml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.github/workflows/sync-supported-chains.yml b/.github/workflows/sync-supported-chains.yml index aac65b6aaa3..0b3a5e7cf5c 100644 --- a/.github/workflows/sync-supported-chains.yml +++ b/.github/workflows/sync-supported-chains.yml @@ -46,7 +46,6 @@ jobs: needs: [setup-matrix] strategy: fail-fast: false - max-parallel: 5 matrix: config: ${{fromJson(needs.setup-matrix.outputs.matrix)}} runs-on: ubuntu-latest @@ -276,7 +275,6 @@ jobs: - name: Destroy VM if: always() - continue-on-error: true id: run-linode-action uses: kamilchodola/linode-github-runner/.github/actions/linode-machine-manager@main with: @@ -297,20 +295,7 @@ jobs: matrix: config: ${{fromJson(needs.setup-matrix.outputs.matrix)}} runs-on: ubuntu-latest - steps: - - name: Destroy VM (make sure is removed if by any unexpected reason it did not removed it on ) - continue-on-error: true - uses: kamilchodola/linode-github-runner/.github/actions/linode-machine-manager@main - with: - linode_token: ${{ secrets.LINODE_TOKEN }} - github_token: "${{ secrets.REPOSITORY_DISPATCH_TOKEN }}" - action: "destroy-machine" - runner_label: t-${{ github.run_id }}-${{ matrix.config.network }} - search_phrase: t-${{ github.run_id }}-${{ matrix.config.network }} - root_password: ${{ secrets.LINODE_ROOT_PASSWORD }} - organization: "NethermindEth" - repo_name: "nethermind" - + steps: - name: Destroy Runner uses: kamilchodola/linode-github-runner/.github/actions/linode-machine-manager@main with: