use of org.hyperledger.besu.ethereum.chain.BlockAddedObserver in project besu by hyperledger.
the class MigratingMiningCoordinator method onBlockAdded.
@Override
public void onBlockAdded(final BlockAddedEvent event) {
final long currentBlock = event.getBlock().getHeader().getNumber();
final MiningCoordinator nextMiningCoordinator = miningCoordinatorSchedule.getFork(currentBlock + 1).getValue();
if (activeMiningCoordinator != nextMiningCoordinator) {
LOG.trace("Migrating mining coordinator at block {} from {} to {}", currentBlock, activeMiningCoordinator.getClass().getSimpleName(), nextMiningCoordinator.getClass().getSimpleName());
final Runnable stopActiveCoordinatorTask = () -> activeMiningCoordinator.stop();
final Runnable startNextCoordinatorTask = () -> {
activeMiningCoordinator = nextMiningCoordinator;
startActiveMiningCoordinator();
if (activeMiningCoordinator instanceof BlockAddedObserver) {
((BlockAddedObserver) activeMiningCoordinator).onBlockAdded(event);
}
};
CompletableFuture.runAsync(stopActiveCoordinatorTask).thenRun(startNextCoordinatorTask);
} else if (activeMiningCoordinator instanceof BlockAddedObserver) {
((BlockAddedObserver) activeMiningCoordinator).onBlockAdded(event);
}
}
Aggregations