Search in sources :

Example 1 with Prepare

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.

the class RoundStateTest method invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal.

@Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
    final Prepare firstPrepare = validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
    final Prepare secondPrepare = validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
    // RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be
    // 'prepared'.
    final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
    when(messageValidator.validateProposal(any())).thenReturn(true);
    when(messageValidator.validatePrepare(firstPrepare)).thenReturn(true);
    when(messageValidator.validatePrepare(secondPrepare)).thenReturn(false);
    roundState.addPrepareMessage(firstPrepare);
    roundState.addPrepareMessage(secondPrepare);
    verify(messageValidator, never()).validatePrepare(any());
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
    assertThat(roundState.setProposedBlock(proposal)).isTrue();
    assertThat(roundState.isPrepared()).isFalse();
    assertThat(roundState.isCommitted()).isFalse();
    assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
Also used : Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 2 with Prepare

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.

the class PrepareValidatorTest method prepareSignedByANonValidatorFails.

@Test
public void prepareSignedByANonValidatorFails() {
    final QbftNode nonValidator = QbftNode.create();
    final Prepare msg = nonValidator.getMessageFactory().createPrepare(round, expectedHash);
    assertThat(validator.validate(msg)).isFalse();
}
Also used : Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) Test(org.junit.Test)

Example 3 with Prepare

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.

the class ProposalValidatorTest method validationFailsIfRoundZeroHasNonEmptyPrepares.

@Test
public void validationFailsIfRoundZeroHasNonEmptyPrepares() {
    final Prepare prepareMsg = validators.getMessageFactory(1).createPrepare(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block.getHash());
    final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block, emptyList(), List.of(prepareMsg.getSignedPayload()));
    assertThat(roundItems.get(ROUND_ID.ZERO).messageValidator.validate(proposal)).isFalse();
}
Also used : Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 4 with Prepare

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.

the class QbftRound method sendPrepare.

private void sendPrepare(final Block block) {
    LOG.debug("Sending prepare message. round={}", roundState.getRoundIdentifier());
    try {
        final Prepare localPrepareMessage = messageFactory.createPrepare(getRoundIdentifier(), block.getHash());
        peerIsPrepared(localPrepareMessage);
        transmitter.multicastPrepare(localPrepareMessage.getRoundIdentifier(), localPrepareMessage.getDigest());
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to create a signed Prepare; {}", e.getMessage());
    }
}
Also used : SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)

Example 5 with Prepare

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.

the class QbftMessageTransmitter method multicastPrepare.

public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
    try {
        final Prepare data = messageFactory.createPrepare(roundIdentifier, digest);
        final PrepareMessageData message = PrepareMessageData.create(data);
        multicaster.send(message);
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to generate signature for Prepare (not sent): {} ", e.getMessage());
    }
}
Also used : SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) PrepareMessageData(org.hyperledger.besu.consensus.qbft.messagedata.PrepareMessageData)

Aggregations

Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)30 Test (org.junit.jupiter.api.Test)14 Test (org.junit.Test)13 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)11 Block (org.hyperledger.besu.ethereum.core.Block)11 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)10 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)6 Commit (org.hyperledger.besu.consensus.qbft.messagewrappers.Commit)6 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)5 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)4 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)3 IntegrationTestHelpers.createValidPreparedCertificate (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate)3 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)2 IntegrationTestHelpers.createCommitBlockFromProposalBlock (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createCommitBlockFromProposalBlock)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 QbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)1 PrepareMessageData (org.hyperledger.besu.consensus.qbft.messagedata.PrepareMessageData)1 RoundChangeMessageData (org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData)1 RoundSpecificPeers (org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers)1 ValidatorPeer (org.hyperledger.besu.consensus.qbft.support.ValidatorPeer)1