Search in sources :

Example 1 with MessageFactory

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;
}
Also used : ValidatorPeers(org.hyperledger.besu.consensus.common.bft.network.ValidatorPeers) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) EthSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater) Address(org.hyperledger.besu.datatypes.Address) ValidatorModeTransitionLogger(org.hyperledger.besu.consensus.qbft.validator.ValidatorModeTransitionLogger) BftProcessor(org.hyperledger.besu.consensus.common.bft.BftProcessor) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) QbftBlockCreatorFactory(org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) MiningCoordinator(org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) MessageValidatorFactory(org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) QbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory) QbftController(org.hyperledger.besu.consensus.qbft.statemachine.QbftController) BftMiningCoordinator(org.hyperledger.besu.consensus.common.bft.blockcreation.BftMiningCoordinator) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip) QbftRoundFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory)

Example 2 with MessageFactory

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"));
}
Also used : MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) NodeKey(org.hyperledger.besu.crypto.NodeKey) Before(org.junit.Before)

Example 3 with MessageFactory

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);
}
Also used : MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) NodeKey(org.hyperledger.besu.crypto.NodeKey)

Example 4 with MessageFactory

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);
}
Also used : MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Example 5 with MessageFactory

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();
}
Also used : ValidatorPeer(org.hyperledger.besu.consensus.qbft.support.ValidatorPeer) ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) NodeKey(org.hyperledger.besu.crypto.NodeKey) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

MessageFactory (org.hyperledger.besu.consensus.qbft.payload.MessageFactory)12 NodeKey (org.hyperledger.besu.crypto.NodeKey)6 QbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)4 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 BftExecutors (org.hyperledger.besu.consensus.common.bft.BftExecutors)3 BlockTimer (org.hyperledger.besu.consensus.common.bft.BlockTimer)3 EventMultiplexer (org.hyperledger.besu.consensus.common.bft.EventMultiplexer)3 MessageTracker (org.hyperledger.besu.consensus.common.bft.MessageTracker)3 RoundTimer (org.hyperledger.besu.consensus.common.bft.RoundTimer)3 ProposerSelector (org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector)3 BftEventHandler (org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler)3 BftFinalState (org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState)3 FutureMessageBuffer (org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer)3 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)3 BlockValidatorProvider (org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider)3 QbftBlockCreatorFactory (org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory)3 QbftBlockHeightManagerFactory (org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory)3 QbftController (org.hyperledger.besu.consensus.qbft.statemachine.QbftController)3 QbftRoundFactory (org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory)3 MessageValidatorFactory (org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory)3