use of org.hyperledger.besu.consensus.qbft.payload.MessageFactory 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.qbft.payload.MessageFactory in project besu by hyperledger.
the class RoundStateTest method setup.
@Before
public void setup() {
for (int i = 0; i < 3; i++) {
final NodeKey newNodeKey = NodeKeyUtils.generate();
validatorKeys.add(newNodeKey);
validators.add(Util.publicKeyToAddress(newNodeKey.getPublicKey()));
validatorMessageFactories.add(new MessageFactory(newNodeKey));
}
when(block.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
}
use of org.hyperledger.besu.consensus.qbft.payload.MessageFactory in project besu by hyperledger.
the class QbftNode method create.
public static QbftNode create() {
final NodeKey nodeKey = NodeKeyUtils.generate();
final MessageFactory factory = new MessageFactory(nodeKey);
return new QbftNode(nodeKey, factory);
}
use of org.hyperledger.besu.consensus.qbft.payload.MessageFactory in project besu by hyperledger.
the class QbftRoundTest method exceptionDuringNodeKeySigningDoesNotEscape.
@Test
public void exceptionDuringNodeKeySigningDoesNotEscape() {
final int QUORUM_SIZE = 1;
final RoundState roundState = new RoundState(roundIdentifier, QUORUM_SIZE, messageValidator);
final NodeKey throwingNodeKey = mock(NodeKey.class);
final MessageFactory throwingMessageFactory = new MessageFactory(throwingNodeKey);
when(throwingNodeKey.sign(any())).thenThrow(new SecurityModuleException("Hsm is Offline"));
final QbftRound round = new QbftRound(roundState, blockCreator, protocolContext, blockImporter, subscribers, throwingNodeKey, throwingMessageFactory, transmitter, roundTimer, bftExtraDataCodec);
round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList()));
// Verify that no prepare message was constructed by the QbftRound
assertThat(roundState.constructPreparedCertificate()).isEmpty();
verifyNoInteractions(transmitter);
}
use of org.hyperledger.besu.consensus.qbft.payload.MessageFactory in project besu by hyperledger.
the class SpuriousBehaviourTest method nonValidatorsCannotTriggerResponses.
@Test
public void nonValidatorsCannotTriggerResponses() {
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final NodeParams nonValidatorParams = new NodeParams(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey()), nonValidatorNodeKey);
final ValidatorPeer nonvalidator = new ValidatorPeer(nonValidatorParams, new MessageFactory(nonValidatorParams.getNodeKey()), context.getEventMultiplexer());
nonvalidator.injectProposal(new ConsensusRoundIdentifier(1, 0), proposedBlock);
peers.verifyNoMessagesReceived();
}
Aggregations