use of org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers in project besu by hyperledger.
the class FutureRoundTest method messagesForFutureRoundAreNotActionedUntilRoundIsActive.
@Test
public void messagesForFutureRoundAreNotActionedUntilRoundIsActive() {
final Block futureBlock = context.createBlockForProposalFromChainHead(futureRoundId.getRoundNumber(), 60);
final int quorum = BftHelpers.calculateRequiredValidatorQuorum(NETWORK_SIZE);
final ConsensusRoundIdentifier subsequentRoundId = new ConsensusRoundIdentifier(1, 6);
final RoundSpecificPeers subsequentRoles = context.roundSpecificPeers(subsequentRoundId);
// Inject 1 too few Commit messages (but sufficient Prepare)
for (int i = 0; i < quorum - 3; i++) {
futurePeers.getNonProposing(i).injectPrepare(futureRoundId, futureBlock.getHash());
}
for (int i = 0; i < quorum - 2; i++) {
futurePeers.getNonProposing(i).injectCommit(futureRoundId, futureBlock.getHash());
}
// inject a prepare and a commit from a subsequent round, and ensure no transmissions are
// created
subsequentRoles.getNonProposing(1).injectPrepare(subsequentRoundId, futureBlock.getHash());
subsequentRoles.getNonProposing(1).injectCommit(subsequentRoundId, futureBlock.getHash());
peers.verifyNoMessagesReceived();
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(0);
// inject a newRound to move to 'futureRoundId', and ensure localnode sends prepare, commit
// and updates blockchain
futurePeers.getProposer().injectProposalForFutureRound(futureRoundId, new RoundChangeCertificate(futurePeers.createSignedRoundChangePayload(futureRoundId)), futureBlock);
final Prepare expectedPrepare = localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedPrepare);
// following 1 more prepare, a commit msg will be sent
futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash());
final Commit expectedCommit = localNodeMessageFactory.createCommit(futureRoundId, futureBlock.getHash(), context.getLocalNodeParams().getNodeKey().sign(futureBlock.getHash()));
peers.verifyMessagesReceived(expectedCommit);
// requires 1 more commit and the blockchain will progress
futurePeers.getNonProposing(quorum - 2).injectCommit(futureRoundId, futureBlock.getHash());
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(1);
}
use of org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers in project besu by hyperledger.
the class ReceivedFutureProposalTest method receiveRoundStateIsNotLostIfASecondProposalMessageIsReceivedForCurrentRound.
@Test
public void receiveRoundStateIsNotLostIfASecondProposalMessageIsReceivedForCurrentRound() {
final Block initialBlock = context.createBlockForProposalFromChainHead(0, 15);
final Block reproposedBlock = context.createBlockForProposalFromChainHead(1, 15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final PreparedRoundArtifacts preparedRoundArtifacts = createValidPreparedRoundArtifacts(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges = peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtifacts);
final RoundSpecificPeers nextRoles = context.roundSpecificPeers(nextRoundId);
final ValidatorPeer nextProposer = nextRoles.getProposer();
nextProposer.injectProposalForFutureRound(nextRoundId, new RoundChangeCertificate(roundChanges), reproposedBlock);
peers.verifyMessagesReceived(localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
// Inject a prepare, then re-inject the proposal - then ensure only a single prepare is enough
// to trigger a Commit transmission from the local node
nextRoles.getNonProposing(0).injectPrepare(nextRoundId, reproposedBlock.getHash());
nextProposer.injectProposalForFutureRound(nextRoundId, new RoundChangeCertificate(roundChanges), reproposedBlock);
peers.verifyNoMessagesReceived();
nextRoles.getNonProposing(1).injectPrepare(nextRoundId, reproposedBlock.getHash());
final Commit expectedCommit = new Commit(IntegrationTestHelpers.createSignedCommitPayload(nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKey()));
peers.verifyMessagesReceived(expectedCommit);
}
Aggregations