Search in sources :

Example 1 with ConsensusContext

use of org.hyperledger.besu.ethereum.ConsensusContext in project besu by hyperledger.

the class TransitionBesuControllerBuilder method createEthProtocolManager.

@Override
protected EthProtocolManager createEthProtocolManager(final ProtocolContext protocolContext, final boolean fastSyncEnabled, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration, final EthPeers ethPeers, final EthContext ethContext, final EthMessages ethMessages, final EthScheduler scheduler, final List<PeerValidator> peerValidators) {
    EthProtocolManager ethProtocolManager = super.createEthProtocolManager(protocolContext, fastSyncEnabled, transactionPool, ethereumWireProtocolConfiguration, ethPeers, ethContext, ethMessages, scheduler, peerValidators);
    ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class);
    if (cc instanceof MergeContext) {
        protocolContext.getConsensusContext(MergeContext.class).observeNewIsPostMergeState(ethProtocolManager);
        protocolContext.getConsensusContext(MergeContext.class).addNewForkchoiceMessageListener(ethProtocolManager);
    }
    return ethProtocolManager;
}
Also used : EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) MergeContext(org.hyperledger.besu.consensus.merge.MergeContext) PostMergeContext(org.hyperledger.besu.consensus.merge.PostMergeContext)

Example 2 with ConsensusContext

use of org.hyperledger.besu.ethereum.ConsensusContext in project besu by hyperledger.

the class MigratingProtocolContext method init.

public static ProtocolContext init(final MutableBlockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule, final ConsensusContextFactory consensusContextFactory) {
    final ConsensusContext consensusContext = consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule);
    final MigratingContext migratingContext = consensusContext.as(MigratingContext.class);
    return new MigratingProtocolContext(blockchain, worldStateArchive, migratingContext.getConsensusContextSchedule());
}
Also used : ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext)

Example 3 with ConsensusContext

use of org.hyperledger.besu.ethereum.ConsensusContext in project besu by hyperledger.

the class ConsensusScheduleBesuControllerBuilderTest method createsMigratingContext.

@Test
public void createsMigratingContext() {
    final ConsensusContext context1 = Mockito.mock(ConsensusContext.class);
    final ConsensusContext context2 = Mockito.mock(ConsensusContext.class);
    final Map<Long, BesuControllerBuilder> besuControllerBuilderSchedule = new TreeMap<>();
    besuControllerBuilderSchedule.put(0L, besuControllerBuilder1);
    besuControllerBuilderSchedule.put(10L, besuControllerBuilder2);
    when(besuControllerBuilder1.createConsensusContext(any(), any(), any())).thenReturn(context1);
    when(besuControllerBuilder2.createConsensusContext(any(), any(), any())).thenReturn(context2);
    final ConsensusScheduleBesuControllerBuilder controllerBuilder = new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule);
    final ConsensusContext consensusContext = controllerBuilder.createConsensusContext(Mockito.mock(Blockchain.class), Mockito.mock(WorldStateArchive.class), Mockito.mock(ProtocolSchedule.class));
    assertThat(consensusContext).isInstanceOf(MigratingContext.class);
    final MigratingContext migratingContext = (MigratingContext) consensusContext;
    final ForksSchedule<ConsensusContext> contextSchedule = migratingContext.getConsensusContextSchedule();
    final NavigableSet<ForkSpec<ConsensusContext>> expectedConsensusContextSpecs = new TreeSet<>(ForkSpec.COMPARATOR);
    expectedConsensusContextSpecs.add(new ForkSpec<>(0L, context1));
    expectedConsensusContextSpecs.add(new ForkSpec<>(10L, context2));
    assertThat(contextSchedule.getForks()).isEqualTo(expectedConsensusContextSpecs);
    assertThat(contextSchedule.getFork(0).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(1).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(9).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(10).getValue()).isSameAs(context2);
    assertThat(contextSchedule.getFork(11).getValue()).isSameAs(context2);
}
Also used : ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) TreeMap(java.util.TreeMap) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) MigratingContext(org.hyperledger.besu.consensus.common.MigratingContext) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) TreeSet(java.util.TreeSet) ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) Test(org.junit.Test)

Example 4 with ConsensusContext

use of org.hyperledger.besu.ethereum.ConsensusContext 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 5 with ConsensusContext

use of org.hyperledger.besu.ethereum.ConsensusContext in project besu by hyperledger.

the class MigratingProtocolContextTest method returnsContextForSpecificChainHeight.

@Test
public void returnsContextForSpecificChainHeight() {
    final MutableBlockchain blockchain = Mockito.mock(MutableBlockchain.class);
    final WorldStateArchive worldStateArchive = Mockito.mock(WorldStateArchive.class);
    final ConsensusContext context1 = Mockito.mock(ConsensusContext.class);
    when(context1.as(any())).thenReturn(context1);
    final ConsensusContext context2 = Mockito.mock(ConsensusContext.class);
    when(context2.as(any())).thenReturn(context2);
    final ForksSchedule<ConsensusContext> contextSchedule = new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2)));
    final MigratingProtocolContext migratingProtocolContext = new MigratingProtocolContext(blockchain, worldStateArchive, contextSchedule);
    assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)).isSameAs(context1);
    when(blockchain.getChainHeadBlockNumber()).thenReturn(2L);
    assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)).isSameAs(context1);
    when(blockchain.getChainHeadBlockNumber()).thenReturn(10L);
    assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class)).isSameAs(context2);
}
Also used : WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Test(org.junit.Test)

Aggregations

ConsensusContext (org.hyperledger.besu.ethereum.ConsensusContext)5 MergeContext (org.hyperledger.besu.consensus.merge.MergeContext)2 PostMergeContext (org.hyperledger.besu.consensus.merge.PostMergeContext)2 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)2 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)2 Test (org.junit.Test)2 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)1 MigratingContext (org.hyperledger.besu.consensus.common.MigratingContext)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 EthProtocolManager (org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager)1 DefaultSynchronizer (org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1