use of org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector in project besu by hyperledger.
the class QbftBesuControllerBuilder method createMiningCoordinator.
@Override
protected MiningCoordinator createMiningCoordinator(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) {
final MutableBlockchain blockchain = protocolContext.getBlockchain();
final BftExecutors bftExecutors = BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.QBFT);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory<?> blockCreatorFactory = new QbftBlockCreatorFactory(transactionPool.getPendingTransactions(), protocolContext, protocolSchedule, qbftForksSchedule, miningParameters, localAddress, bftExtraDataCodec().get());
final ValidatorProvider validatorProvider = protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
final ProposerSelector proposerSelector = new ProposerSelector(blockchain, bftBlockInterface().get(), true, validatorProvider);
// NOTE: peers should not be used for accessing the network as it does not enforce the
// "only send once" filter applied by the UniqueMessageMulticaster.
peers = new ValidatorPeers(validatorProvider, Istanbul100SubProtocol.NAME);
final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, qbftConfig.getGossipedHistoryLimit());
final QbftGossip gossiper = new QbftGossip(uniqueMessageMulticaster, bftExtraDataCodec().get());
final BftFinalState finalState = new BftFinalState(validatorProvider, nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, uniqueMessageMulticaster, new RoundTimer(bftEventQueue, qbftConfig.getRequestTimeoutSeconds(), bftExecutors), new BlockTimer(bftEventQueue, qbftForksSchedule, bftExecutors, clock), blockCreatorFactory, clock);
final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
minedBlockObservers.subscribe(ethProtocolManager);
minedBlockObservers.subscribe(blockLogger(transactionPool, localAddress));
final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(qbftConfig.getFutureMessagesMaxDistance(), qbftConfig.getFutureMessagesLimit(), blockchain.getChainHeadBlockNumber());
final MessageTracker duplicateMessageTracker = new MessageTracker(qbftConfig.getDuplicateMessageLimit());
final MessageFactory messageFactory = new MessageFactory(nodeKey);
final BftEventHandler qbftController = new QbftController(blockchain, finalState, new QbftBlockHeightManagerFactory(finalState, new QbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, bftExtraDataCodec().get()), messageValidatorFactory, messageFactory, new ValidatorModeTransitionLogger(qbftForksSchedule)), gossiper, duplicateMessageTracker, futureMessageBuffer, new EthSynchronizerUpdater(ethProtocolManager.ethContext().getEthPeers()), bftExtraDataCodec().get());
final EventMultiplexer eventMultiplexer = new EventMultiplexer(qbftController);
final BftProcessor bftProcessor = new BftProcessor(bftEventQueue, eventMultiplexer);
final MiningCoordinator miningCoordinator = new BftMiningCoordinator(bftExecutors, qbftController, bftProcessor, blockCreatorFactory, blockchain, bftEventQueue);
miningCoordinator.enable();
return miningCoordinator;
}
use of org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector in project besu by hyperledger.
the class TestContextBuilder method createControllerAndFinalState.
private static ControllerAndState createControllerAndFinalState(final MutableBlockchain blockChain, final WorldStateArchive worldStateArchive, final StubValidatorMulticaster multicaster, final NodeKey nodeKey, final Clock clock, final BftEventQueue bftEventQueue, final Gossiper gossiper, final SynchronizerUpdater synchronizerUpdater, final boolean useValidatorContract, final List<QbftFork> qbftForks) {
final MiningParameters miningParams = new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(Bytes.wrap("Qbft Int tests".getBytes(UTF_8))).miningEnabled(true).build();
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
final Map<String, Object> qbftConfigValues = useValidatorContract ? Map.of(JsonQbftConfigOptions.VALIDATOR_CONTRACT_ADDRESS, VALIDATOR_CONTRACT_ADDRESS.toHexString()) : Collections.emptyMap();
final QbftConfigOptions qbftConfigOptions = createGenesisConfig(useValidatorContract);
genesisConfigOptions.byzantiumBlock(0);
genesisConfigOptions.qbftConfigOptions(new JsonQbftConfigOptions(JsonUtil.objectNodeFromMap(qbftConfigValues)));
genesisConfigOptions.transitions(TestTransitions.createQbftTestTransitions(qbftForks));
genesisConfigOptions.qbftConfigOptions(qbftConfigOptions);
final EpochManager epochManager = new EpochManager(EPOCH_LENGTH);
final BftBlockInterface blockInterface = new BftBlockInterface(BFT_EXTRA_DATA_ENCODER);
final ForksSchedule<QbftConfigOptions> forksSchedule = QbftForksSchedulesFactory.create(genesisConfigOptions);
final ProtocolSchedule protocolSchedule = QbftProtocolSchedule.create(genesisConfigOptions, forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks);
final TransactionSimulator transactionSimulator = new TransactionSimulator(blockChain, worldStateArchive, protocolSchedule);
final BlockValidatorProvider blockValidatorProvider = BlockValidatorProvider.forkingValidatorProvider(blockChain, epochManager, blockInterface, validatorOverrides);
final TransactionValidatorProvider transactionValidatorProvider = new TransactionValidatorProvider(blockChain, new ValidatorContractController(transactionSimulator), forksSchedule);
final ValidatorProvider validatorProvider = new ForkingValidatorProvider(blockChain, forksSchedule, blockValidatorProvider, transactionValidatorProvider);
final ProtocolContext protocolContext = new ProtocolContext(blockChain, worldStateArchive, new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()));
final GasPricePendingTransactionsSorter pendingTransactions = new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, clock, metricsSystem, blockChain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory<?> blockCreatorFactory = new QbftBlockCreatorFactory(// changed from QbftBesuController
pendingTransactions, protocolContext, protocolSchedule, forksSchedule, miningParams, localAddress, BFT_EXTRA_DATA_ENCODER);
final ProposerSelector proposerSelector = new ProposerSelector(blockChain, blockInterface, true, validatorProvider);
final BftExecutors bftExecutors = BftExecutors.create(new NoOpMetricsSystem(), BftExecutors.ConsensusType.QBFT);
final BftFinalState finalState = new BftFinalState(protocolContext.getConsensusContext(BftContext.class).getValidatorProvider(), nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, multicaster, new RoundTimer(bftEventQueue, ROUND_TIMER_SEC, bftExecutors), new BlockTimer(bftEventQueue, forksSchedule, bftExecutors, TestClock.fixed()), blockCreatorFactory, clock);
final MessageFactory messageFactory = new MessageFactory(nodeKey);
final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, BFT_EXTRA_DATA_ENCODER);
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
final MessageTracker duplicateMessageTracker = new MessageTracker(DUPLICATE_MESSAGE_LIMIT);
final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(FUTURE_MESSAGES_MAX_DISTANCE, FUTURE_MESSAGES_LIMIT, blockChain.getChainHeadBlockNumber());
final BftEventHandler qbftController = new QbftController(blockChain, finalState, new QbftBlockHeightManagerFactory(finalState, new QbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, BFT_EXTRA_DATA_ENCODER), messageValidatorFactory, messageFactory, new ValidatorModeTransitionLogger(forksSchedule)), gossiper, duplicateMessageTracker, futureMessageBuffer, synchronizerUpdater, BFT_EXTRA_DATA_ENCODER);
final EventMultiplexer eventMultiplexer = new EventMultiplexer(qbftController);
return new ControllerAndState(bftExecutors, qbftController, finalState, eventMultiplexer, messageFactory, validatorProvider);
}
use of org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector in project besu by hyperledger.
the class IbftBesuControllerBuilder method createMiningCoordinator.
@Override
protected MiningCoordinator createMiningCoordinator(final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final TransactionPool transactionPool, final MiningParameters miningParameters, final SyncState syncState, final EthProtocolManager ethProtocolManager) {
final MutableBlockchain blockchain = protocolContext.getBlockchain();
final BftExecutors bftExecutors = BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.IBFT);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory<?> blockCreatorFactory = new BftBlockCreatorFactory<>(transactionPool.getPendingTransactions(), protocolContext, protocolSchedule, forksSchedule, miningParameters, localAddress, bftExtraDataCodec().get());
final ValidatorProvider validatorProvider = protocolContext.getConsensusContext(BftContext.class).getValidatorProvider();
final ProposerSelector proposerSelector = new ProposerSelector(blockchain, bftBlockInterface().get(), true, validatorProvider);
// NOTE: peers should not be used for accessing the network as it does not enforce the
// "only send once" filter applied by the UniqueMessageMulticaster.
peers = new ValidatorPeers(validatorProvider, IbftSubProtocol.NAME);
final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit());
final IbftGossip gossiper = new IbftGossip(uniqueMessageMulticaster);
final BftFinalState finalState = new BftFinalState(validatorProvider, nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, uniqueMessageMulticaster, new RoundTimer(bftEventQueue, bftConfig.getRequestTimeoutSeconds(), bftExecutors), new BlockTimer(bftEventQueue, forksSchedule, bftExecutors, clock), blockCreatorFactory, clock);
final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
minedBlockObservers.subscribe(ethProtocolManager);
minedBlockObservers.subscribe(blockLogger(transactionPool, localAddress));
final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(bftConfig.getFutureMessagesMaxDistance(), bftConfig.getFutureMessagesLimit(), blockchain.getChainHeadBlockNumber());
final MessageTracker duplicateMessageTracker = new MessageTracker(bftConfig.getDuplicateMessageLimit());
final MessageFactory messageFactory = new MessageFactory(nodeKey);
final BftEventHandler ibftController = new IbftController(blockchain, finalState, new IbftBlockHeightManagerFactory(finalState, new IbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, bftExtraDataCodec().get()), messageValidatorFactory, messageFactory), gossiper, duplicateMessageTracker, futureMessageBuffer, new EthSynchronizerUpdater(ethProtocolManager.ethContext().getEthPeers()));
final EventMultiplexer eventMultiplexer = new EventMultiplexer(ibftController);
final BftProcessor bftProcessor = new BftProcessor(bftEventQueue, eventMultiplexer);
final MiningCoordinator ibftMiningCoordinator = new BftMiningCoordinator(bftExecutors, ibftController, bftProcessor, blockCreatorFactory, blockchain, bftEventQueue);
ibftMiningCoordinator.enable();
return ibftMiningCoordinator;
}
use of org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector in project besu by hyperledger.
the class TestContextBuilder method createControllerAndFinalState.
private static ControllerAndState createControllerAndFinalState(final MutableBlockchain blockChain, final StubValidatorMulticaster multicaster, final NodeKey nodeKey, final Clock clock, final BftEventQueue bftEventQueue, final Gossiper gossiper, final SynchronizerUpdater synchronizerUpdater, final List<BftFork> bftForks) {
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
final MiningParameters miningParams = new MiningParameters.Builder().coinbase(AddressHelpers.ofValue(1)).minTransactionGasPrice(Wei.ZERO).extraData(Bytes.wrap("Ibft Int tests".getBytes(UTF_8))).miningEnabled(true).build();
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
genesisConfigOptions.byzantiumBlock(0);
genesisConfigOptions.transitions(TestTransitions.createIbftTestTransitions(bftForks));
final ForksSchedule<BftConfigOptions> forksSchedule = IbftForksSchedulesFactory.create(genesisConfigOptions);
final ProtocolSchedule protocolSchedule = IbftProtocolSchedule.create(genesisConfigOptions, forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
// ///////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftBesuController
final EpochManager epochManager = new EpochManager(EPOCH_LENGTH);
final BftBlockInterface blockInterface = new BftBlockInterface(IBFT_EXTRA_DATA_ENCODER);
final ValidatorProvider validatorProvider = BlockValidatorProvider.nonForkingValidatorProvider(blockChain, epochManager, blockInterface);
final ProtocolContext protocolContext = new ProtocolContext(blockChain, worldStateArchive, new BftContext(validatorProvider, epochManager, blockInterface));
final GasPricePendingTransactionsSorter pendingTransactions = new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, clock, metricsSystem, blockChain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftBlockCreatorFactory<?> blockCreatorFactory = new BftBlockCreatorFactory<>(// changed from IbftBesuController
pendingTransactions, protocolContext, protocolSchedule, forksSchedule, miningParams, localAddress, IBFT_EXTRA_DATA_ENCODER);
final ProposerSelector proposerSelector = new ProposerSelector(blockChain, blockInterface, true, validatorProvider);
final BftExecutors bftExecutors = BftExecutors.create(new NoOpMetricsSystem(), BftExecutors.ConsensusType.IBFT);
final BftFinalState finalState = new BftFinalState(protocolContext.getConsensusContext(BftContext.class).getValidatorProvider(), nodeKey, Util.publicKeyToAddress(nodeKey.getPublicKey()), proposerSelector, multicaster, new RoundTimer(bftEventQueue, ROUND_TIMER_SEC, bftExecutors), new BlockTimer(bftEventQueue, forksSchedule, bftExecutors, TestClock.fixed()), blockCreatorFactory, clock);
final MessageFactory messageFactory = new MessageFactory(nodeKey);
final MessageValidatorFactory messageValidatorFactory = new MessageValidatorFactory(proposerSelector, protocolSchedule, protocolContext, IBFT_EXTRA_DATA_ENCODER);
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
final MessageTracker duplicateMessageTracker = new MessageTracker(DUPLICATE_MESSAGE_LIMIT);
final FutureMessageBuffer futureMessageBuffer = new FutureMessageBuffer(FUTURE_MESSAGES_MAX_DISTANCE, FUTURE_MESSAGES_LIMIT, blockChain.getChainHeadBlockNumber());
final BftEventHandler ibftController = new IbftController(blockChain, finalState, new IbftBlockHeightManagerFactory(finalState, new IbftRoundFactory(finalState, protocolContext, protocolSchedule, minedBlockObservers, messageValidatorFactory, messageFactory, IBFT_EXTRA_DATA_ENCODER), messageValidatorFactory, messageFactory), gossiper, duplicateMessageTracker, futureMessageBuffer, synchronizerUpdater);
final EventMultiplexer eventMultiplexer = new EventMultiplexer(ibftController);
return new ControllerAndState(bftExecutors, ibftController, finalState, eventMultiplexer, messageFactory);
}
Aggregations