Search in sources :

Example 1 with PostMergeContext

use of org.hyperledger.besu.consensus.merge.PostMergeContext in project besu by hyperledger.

the class TransitionBesuControllerBuilder method initTransitionWatcher.

private void initTransitionWatcher(final ProtocolContext protocolContext, final TransitionCoordinator composedCoordinator) {
    PostMergeContext postMergeContext = protocolContext.getConsensusContext(PostMergeContext.class);
    postMergeContext.observeNewIsPostMergeState((isPoS, difficultyStoppedAt) -> {
        if (isPoS) {
            // if we transitioned to post-merge, stop and disable any mining
            composedCoordinator.getPreMergeObject().disable();
            composedCoordinator.getPreMergeObject().stop();
            // set the blockchoiceRule to never reorg, rely on forkchoiceUpdated instead
            protocolContext.getBlockchain().setBlockChoiceRule((newBlockHeader, currentBlockHeader) -> -1);
        } else if (composedCoordinator.isMiningBeforeMerge()) {
            // if our merge state is set to mine pre-merge and we are mining, start mining
            composedCoordinator.getPreMergeObject().enable();
            composedCoordinator.getPreMergeObject().start();
        }
    });
    // initialize our merge context merge status before we would start either
    Blockchain blockchain = protocolContext.getBlockchain();
    blockchain.getTotalDifficultyByHash(blockchain.getChainHeadHash()).ifPresent(postMergeContext::setIsPostMerge);
}
Also used : PostMergeContext(org.hyperledger.besu.consensus.merge.PostMergeContext) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain)

Aggregations

PostMergeContext (org.hyperledger.besu.consensus.merge.PostMergeContext)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1