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)));
}
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());
}
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)));
}
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();
}
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();
}
Aggregations