Search in sources :

Example 6 with MergeContext

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

the class TransitionBesuControllerBuilder method createSynchronizer.

@Override
protected DefaultSynchronizer createSynchronizer(final ProtocolSchedule protocolSchedule, final WorldStateStorage worldStateStorage, final ProtocolContext protocolContext, final Optional<Pruner> maybePruner, final EthContext ethContext, final SyncState syncState, final EthProtocolManager ethProtocolManager, final PivotBlockSelector pivotBlockSelector) {
    DefaultSynchronizer sync = super.createSynchronizer(protocolSchedule, worldStateStorage, protocolContext, maybePruner, ethContext, syncState, ethProtocolManager, pivotBlockSelector);
    ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class);
    if (cc instanceof MergeContext) {
        protocolContext.getConsensusContext(MergeContext.class).addNewForkchoiceMessageListener(sync);
    }
    return sync;
}
Also used : ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) PostMergeContext(org.hyperledger.besu.consensus.merge.PostMergeContext) DefaultSynchronizer(org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer)

Example 7 with MergeContext

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

the class MergeBesuControllerBuilderTest method assertFinalizedBlockIsPresentWhenStored.

@Test
public void assertFinalizedBlockIsPresentWhenStored() {
    final BlockHeader finalizedHeader = finalizedBlockHeader();
    final Blockchain mockChain = mock(Blockchain.class);
    when(mockChain.getFinalized()).thenReturn(Optional.of(finalizedHeader.getHash()));
    when(mockChain.getBlockHeader(finalizedHeader.getHash())).thenReturn(Optional.of(finalizedHeader));
    MergeContext mergeContext = besuControllerBuilder.createConsensusContext(mockChain, mock(WorldStateArchive.class), this.besuControllerBuilder.createProtocolSchedule());
    assertThat(mergeContext).isNotNull();
    assertThat(mergeContext.getFinalized().get()).isEqualTo(finalizedHeader);
}
Also used : WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 8 with MergeContext

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

the class MergeBesuControllerBuilderTest method assertNoFinalizedBlockWhenNotStored.

@Test
public void assertNoFinalizedBlockWhenNotStored() {
    Blockchain mockChain = mock(Blockchain.class);
    when(mockChain.getFinalized()).thenReturn(Optional.empty());
    MergeContext mergeContext = besuControllerBuilder.createConsensusContext(mockChain, mock(WorldStateArchive.class), this.besuControllerBuilder.createProtocolSchedule());
    assertThat(mergeContext).isNotNull();
    assertThat(mergeContext.getFinalized()).isEmpty();
}
Also used : WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) Test(org.junit.Test)

Aggregations

MergeContext (org.hyperledger.besu.consensus.merge.MergeContext)8 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)4 Test (org.junit.Test)4 PostMergeContext (org.hyperledger.besu.consensus.merge.PostMergeContext)3 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 InMemoryKeyValueStorageProvider.createInMemoryBlockchain (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain)3 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)3 ConsensusContext (org.hyperledger.besu.ethereum.ConsensusContext)2 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)2 OptionalLong (java.util.OptionalLong)1 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)1 FinalizedBlockHashSupplier (org.hyperledger.besu.consensus.merge.FinalizedBlockHashSupplier)1 Hash (org.hyperledger.besu.datatypes.Hash)1 GenesisState (org.hyperledger.besu.ethereum.chain.GenesisState)1 Block (org.hyperledger.besu.ethereum.core.Block)1 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)1 DefaultSynchronizer (org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer)1 PivotSelectorFromFinalizedBlock (org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromFinalizedBlock)1 PivotSelectorFromPeers (org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotSelectorFromPeers)1