Search in sources :

Example 1 with RoundChangeCertificate

use of org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate in project besu by hyperledger.

the class IbftBlockHeightManagerTest method whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted.

@Test
public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted() {
    final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
    final RoundChange roundChange = messageFactory.createRoundChange(futureRoundIdentifier, Optional.empty());
    final RoundChangeCertificate roundChangCert = new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()));
    when(roundChangeManager.appendRoundChangeMessage(any())).thenReturn(Optional.of(singletonList(roundChange)));
    when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true);
    final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
    reset(messageTransmitter);
    manager.handleRoundChangePayload(roundChange);
    verify(messageTransmitter, times(1)).multicastProposal(eq(futureRoundIdentifier), any(), eq(Optional.of(roundChangCert)));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Test(org.junit.Test)

Example 2 with RoundChangeCertificate

use of org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate in project besu by hyperledger.

the class IbftBlockHeightManagerTest method illegalFutureRoundProposalDoesNotTriggerNewRound.

@Test
public void illegalFutureRoundProposalDoesNotTriggerNewRound() {
    when(futureRoundProposalMessageValidator.validateProposalMessage(any())).thenReturn(false);
    final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
    final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
    // Force a new round to be started at new round number.
    final Proposal futureRoundProposal = messageFactory.createProposal(futureRoundIdentifier, createdBlock, Optional.of(new RoundChangeCertificate(Collections.emptyList())));
    // Discard the existing createNewRound invocation.
    reset(roundFactory);
    manager.handleProposalPayload(futureRoundProposal);
    verify(roundFactory, never()).createNewRound(any(), anyInt());
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 3 with RoundChangeCertificate

use of org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate in project besu by hyperledger.

the class IbftRoundTest method aProposalWithAnewBlockIsSentUponReceptionOfARoundChangeWithNoCertificate.

@Test
public void aProposalWithAnewBlockIsSentUponReceptionOfARoundChangeWithNoCertificate() {
    final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
    final IbftRound round = new IbftRound(roundState, blockCreator, protocolContext, blockImporter, subscribers, nodeKey, messageFactory, transmitter, roundTimer, bftExtraDataCodec);
    final RoundChangeCertificate roundChangeCertificate = new RoundChangeCertificate(emptyList());
    round.startRoundWith(new RoundChangeArtifacts(empty(), emptyList()), 15);
    verify(transmitter, times(1)).multicastProposal(eq(roundIdentifier), any(), eq(Optional.of(roundChangeCertificate)));
}
Also used : RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Test(org.junit.Test)

Example 4 with RoundChangeCertificate

use of org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate in project besu by hyperledger.

the class MessageValidatorTest method proposalFailsValidationIfRoundChangeCertificateDoeNotMatchBlock.

@Test
public void proposalFailsValidationIfRoundChangeCertificateDoeNotMatchBlock() {
    final ConsensusRoundIdentifier nonZeroRound = new ConsensusRoundIdentifier(1, 1);
    when(roundChangeCertificateValidator.validateProposalMessageMatchesLatestPrepareCertificate(any(), any())).thenReturn(false);
    final Proposal proposal = messageFactory.createProposal(nonZeroRound, block, Optional.of(new RoundChangeCertificate(emptyList())));
    assertThat(messageValidator.validateProposal(proposal)).isFalse();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 5 with RoundChangeCertificate

use of org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate in project besu by hyperledger.

the class RoundChangeCertificateValidatorTest method correctlyMatchesBlockAgainstLatestInRoundChangeCertificate.

@Test
public void correctlyMatchesBlockAgainstLatestInRoundChangeCertificate() {
    final ConsensusRoundIdentifier latterPrepareRound = ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -1);
    final Block latterBlock = ProposedBlockHelpers.createProposalBlock(validators, latterPrepareRound, bftExtraDataEncoder);
    final Proposal latterProposal = proposerMessageFactory.createProposal(latterPrepareRound, latterBlock, empty());
    final Optional<PreparedRoundArtifacts> latterTerminatedRoundArtefacts = Optional.of(new PreparedRoundArtifacts(latterProposal, org.assertj.core.util.Lists.newArrayList(validatorMessageFactory.createPrepare(latterPrepareRound, proposedBlock.getHash()))));
    // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
    // is correctly followed.
    final ConsensusRoundIdentifier earlierPreparedRound = new ConsensusRoundIdentifier(roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2);
    final Block earlierBlock = ProposedBlockHelpers.createProposalBlock(validators.subList(0, 1), earlierPreparedRound, bftExtraDataEncoder);
    final Proposal earlierProposal = proposerMessageFactory.createProposal(earlierPreparedRound, earlierBlock, empty());
    final Optional<PreparedRoundArtifacts> earlierTerminatedRoundArtefacts = Optional.of(new PreparedRoundArtifacts(earlierProposal, org.assertj.core.util.Lists.newArrayList(validatorMessageFactory.createPrepare(earlierPreparedRound, earlierBlock.getHash()))));
    final RoundChangeCertificate roundChangeCert = new RoundChangeCertificate(org.assertj.core.util.Lists.newArrayList(proposerMessageFactory.createRoundChange(roundIdentifier, earlierTerminatedRoundArtefacts).getSignedPayload(), validatorMessageFactory.createRoundChange(roundIdentifier, latterTerminatedRoundArtefacts).getSignedPayload()));
    assertThat(validator.validateProposalMessageMatchesLatestPrepareCertificate(roundChangeCert, earlierBlock)).isFalse();
    assertThat(validator.validateProposalMessageMatchesLatestPrepareCertificate(roundChangeCert, latterBlock)).isTrue();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Block(org.hyperledger.besu.ethereum.core.Block) PreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Aggregations

RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)26 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)17 Block (org.hyperledger.besu.ethereum.core.Block)14 Test (org.junit.jupiter.api.Test)12 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)11 Test (org.junit.Test)11 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)7 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)6 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)5 ValidatorPeer (org.hyperledger.besu.consensus.ibft.support.ValidatorPeer)5 Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)4 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)4 IntegrationTestHelpers.createValidPreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts)4 RoundSpecificPeers (org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers)2 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)1 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)1 ProposalPayload (org.hyperledger.besu.consensus.ibft.payload.ProposalPayload)1 RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)1