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;
}
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());
}
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);
}
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;
}
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);
}
Aggregations