Search in sources :

Example 1 with TransitionPivotSelector

use of org.hyperledger.besu.ethereum.eth.sync.fastsync.TransitionPivotSelector in project besu by hyperledger.

the class BesuControllerBuilder method createPivotSelector.

private PivotBlockSelector createPivotSelector(final ProtocolContext protocolContext) {
    final PivotSelectorFromPeers pivotSelectorFromPeers = new PivotSelectorFromPeers(syncConfig);
    final GenesisConfigOptions genesisConfigOptions = configOptionsSupplier.get();
    if (genesisConfigOptions.getTerminalTotalDifficulty().isPresent()) {
        LOG.info("TTD difficulty is present, creating initial sync phase with transition to PoS support");
        final MergeContext mergeContext = protocolContext.getConsensusContext(MergeContext.class);
        final FinalizedBlockHashSupplier finalizedBlockHashSupplier = new FinalizedBlockHashSupplier();
        final long subscriptionId = mergeContext.addNewForkchoiceMessageListener(finalizedBlockHashSupplier);
        final Runnable unsubscribeFinalizedBlockHashListener = () -> {
            mergeContext.removeNewForkchoiceMessageListener(subscriptionId);
            LOG.info("Initial sync done, unsubscribe finalized block hash supplier");
        };
        return new TransitionPivotSelector(genesisConfigOptions, finalizedBlockHashSupplier, pivotSelectorFromPeers, new PivotSelectorFromFinalizedBlock(genesisConfigOptions, finalizedBlockHashSupplier, unsubscribeFinalizedBlockHashListener));
    } else {
        LOG.info("TTD difficulty is not present, creating initial sync phase for PoW");
        return pivotSelectorFromPeers;
    }
}
Also used : PivotSelectorFromFinalizedBlock(org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromFinalizedBlock) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) PivotSelectorFromPeers(org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromPeers) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) FinalizedBlockHashSupplier(org.hyperledger.besu.consensus.merge.FinalizedBlockHashSupplier) TransitionPivotSelector(org.hyperledger.besu.ethereum.eth.sync.fastsync.TransitionPivotSelector)

Aggregations

GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)1 FinalizedBlockHashSupplier (org.hyperledger.besu.consensus.merge.FinalizedBlockHashSupplier)1 MergeContext (org.hyperledger.besu.consensus.merge.MergeContext)1 PivotSelectorFromFinalizedBlock (org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromFinalizedBlock)1 PivotSelectorFromPeers (org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromPeers)1 TransitionPivotSelector (org.hyperledger.besu.ethereum.eth.sync.fastsync.TransitionPivotSelector)1