Skip to content

Commit

Permalink
Merge branch 'master' into block-production-improve
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Oct 22, 2024
2 parents 2a6bf9c + 25f681b commit 8e159b8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/sync-supported-chains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ private ResultWrapper<ForkchoiceUpdatedV1Result> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -50,17 +54,25 @@ 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()
{
_isInBeaconModeControl = false;
}

public void AllowBeaconHeaderSync()
{
_canInitBeaconHeaderSync = true;
}

public bool ShouldBeInBeaconHeaders()
{
bool beaconPivotExists = _beaconPivot.BeaconPivotExists();
Expand Down Expand Up @@ -130,7 +142,7 @@ public interface IMergeSyncController
{
void StopSyncing();

void InitBeaconHeaderSync(BlockHeader blockHeader);
bool TryInitBeaconHeaderSync(BlockHeader blockHeader);

void StopBeaconModeControl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down Expand Up @@ -254,6 +255,7 @@ private void UpdateConfigValues(Hash256 finalizedBlockHash, long finalizedBlockN
_syncConfig.PivotHash = finalizedBlockHash.ToString();
_syncConfig.PivotNumber = finalizedBlockNumber.ToString();
_syncConfig.MaxAttemptsToUpdatePivot = 0;
_beaconSyncStrategy.AllowBeaconHeaderSync();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ private No() { }

public static No BeaconSync { get; } = new();

public void AllowBeaconHeaderSync() { }

public bool ShouldBeInBeaconHeaders() => false;

public bool ShouldBeInBeaconModeControl() => false;
Expand All @@ -24,6 +26,7 @@ private No() { }

public interface IBeaconSyncStrategy
{
void AllowBeaconHeaderSync();
bool ShouldBeInBeaconHeaders();
bool ShouldBeInBeaconModeControl();
bool IsBeaconSyncFinished(BlockHeader? blockHeader);
Expand Down

0 comments on commit 8e159b8

Please sign in to comment.