Search in sources :

Example 1 with Prepare

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

the class IbftBlockHeightManagerTest method preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired.

@Test
public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired() {
    final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
    // Trigger a Proposal creation.
    manager.handleBlockTimerExpiry(roundIdentifier);
    final Prepare firstPrepare = validatorMessageFactory.get(0).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
    final Prepare secondPrepare = validatorMessageFactory.get(1).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
    manager.handlePreparePayload(firstPrepare);
    manager.handlePreparePayload(secondPrepare);
    manager.roundExpired(new RoundExpiry(roundIdentifier));
    verify(validatorMulticaster, times(1)).send(sentMessageArgCaptor.capture());
    final MessageData capturedMessageData = sentMessageArgCaptor.getValue();
    assertThat(capturedMessageData).isInstanceOf(RoundChangeMessageData.class);
    final RoundChangeMessageData roundChange = (RoundChangeMessageData) capturedMessageData;
    Optional<PreparedCertificate> preparedCert = roundChange.decode().getPreparedCertificate();
    Assertions.assertThat(preparedCert).isNotEmpty();
    assertThat(preparedCert.get().getPreparePayloads()).containsOnly(firstPrepare.getSignedPayload(), secondPrepare.getSignedPayload());
}
Also used : RoundChangeMessageData(org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) PreparedCertificate(org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate) RoundChangeMessageData(org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData) RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.Test)

Example 2 with Prepare

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

the class RoundChangeSignedDataValidatorTest method roundChangeInvalidPrepareMessageFromProposerFails.

@Test
public void roundChangeInvalidPrepareMessageFromProposerFails() {
    final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
    final PreparedRoundArtifacts preparedRoundArtifacts = new PreparedRoundArtifacts(proposerMessageFactory.createProposal(currentRound, block, Optional.empty()), Lists.newArrayList(prepareMsg));
    when(basicValidator.validateProposal(any())).thenReturn(true);
    when(basicValidator.validatePrepare(any())).thenReturn(false);
    final RoundChange msg = proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
    assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
    verify(basicValidator, times(1)).validatePrepare(prepareMsg.getSignedPayload());
    verify(basicValidator, never()).validateCommit(any());
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) PreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts) Test(org.junit.Test)

Example 3 with Prepare

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

the class RoundChangeSignedDataValidatorTest method roundChangeWithDuplicatedPreparesFails.

@Test
public void roundChangeWithDuplicatedPreparesFails() {
    final RoundChangePayloadValidator validatorRequiringTwoPrepares = new RoundChangePayloadValidator(validatorFactory, validators, 2, chainHeight);
    final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
    final PreparedRoundArtifacts preparedRoundArtifacts = new PreparedRoundArtifacts(proposerMessageFactory.createProposal(currentRound, block, Optional.empty()), Lists.newArrayList(prepareMsg, prepareMsg));
    final PreparedCertificate prepareCertificate = preparedRoundArtifacts.getPreparedCertificate();
    final RoundChange msg = proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
    when(basicValidator.validateProposal(prepareCertificate.getProposalPayload())).thenReturn(true);
    when(basicValidator.validatePrepare(prepareMsg.getSignedPayload())).thenReturn(true);
    assertThat(validatorRequiringTwoPrepares.validateRoundChange(msg.getSignedPayload())).isFalse();
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) PreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts) PreparedCertificate(org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate) Test(org.junit.Test)

Example 4 with Prepare

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

the class SignedDataValidatorTest method receivingPrepareFromProposerFails.

@Test
public void receivingPrepareFromProposerFails() {
    final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
    final Prepare prepareMsg = proposerMessageFactory.createPrepare(roundIdentifier, block.getHash());
    assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
    assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
}
Also used : Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 5 with Prepare

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

the class IbftRound method handleProposalMessage.

public void handleProposalMessage(final Proposal msg) {
    LOG.debug("Received a proposal message. round={}", roundState.getRoundIdentifier());
    final Block block = msg.getBlock();
    if (updateStateWithProposedBlock(msg)) {
        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) Block(org.hyperledger.besu.ethereum.core.Block) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)

Aggregations

Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)30 Test (org.junit.Test)17 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)13 Test (org.junit.jupiter.api.Test)10 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)9 Block (org.hyperledger.besu.ethereum.core.Block)9 Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)7 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)7 RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)5 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)5 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)4 PreparedCertificate (org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate)3 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)2 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)2 IbftExtraDataCodec (org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 List (java.util.List)1