use of org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers in project besu by hyperledger.
the class ValidatorContractTest method createNewBlockAsProposer.
private void createNewBlockAsProposer(final TestContext context, final long blockNumber) {
ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(blockNumber, 0);
// trigger proposal
context.getController().handleBlockTimerExpiry(new BlockTimerExpiry(roundId));
// peers commit proposed block
Block proposedBlock = context.createBlockForProposalFromChainHead(clock.instant().getEpochSecond());
RoundSpecificPeers peers = context.roundSpecificPeers(roundId);
peers.commitForNonProposing(roundId, proposedBlock);
assertThat(context.getCurrentChainHeight()).isEqualTo(blockNumber);
context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
}
use of org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers in project besu by hyperledger.
the class ValidatorContractTest method remotePeerProposesNewBlock.
private void remotePeerProposesNewBlock(final TestContext context, final long blockNumber) {
ConsensusRoundIdentifier roundId = new ConsensusRoundIdentifier(blockNumber, 0);
RoundSpecificPeers peers = context.roundSpecificPeers(roundId);
ValidatorPeer remoteProposer = peers.getProposer();
final Block blockToPropose = context.createBlockForProposalFromChainHead(clock.instant().getEpochSecond(), remoteProposer.getNodeAddress());
remoteProposer.injectProposal(roundId, blockToPropose);
remoteProposer.injectCommit(roundId, blockToPropose);
assertThat(context.getCurrentChainHeight()).isEqualTo(blockNumber);
context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
}
use of org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers in project besu by hyperledger.
the class FutureRoundTest method messagesForFutureRoundAreNotActionedUntilRoundIsActive.
@Test
public void messagesForFutureRoundAreNotActionedUntilRoundIsActive() {
final Block futureBlock = context.createBlockForProposalFromChainHead(60, peers.getProposer().getNodeAddress());
final int quorum = BftHelpers.calculateRequiredValidatorQuorum(NETWORK_SIZE);
final ConsensusRoundIdentifier subsequentRoundId = new ConsensusRoundIdentifier(1, 6);
final RoundSpecificPeers subsequentRoles = context.roundSpecificPeers(subsequentRoundId);
for (int i = 0; i < quorum - 2; i++) {
futurePeers.getNonProposing(i).injectPrepare(futureRoundId, futureBlock.getHash());
}
for (int i = 0; i < quorum - 2; i++) {
futurePeers.getNonProposing(i).injectCommit(futureRoundId, futureBlock);
}
// 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);
peers.verifyNoMessagesReceived();
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(0);
// inject a newRound to move to 'futureRoundId', and ensure localnode sends prepare, commit
// and updates blockchain
final List<SignedData<RoundChangePayload>> signedRoundChangePayload = futurePeers.createSignedRoundChangePayload(futureRoundId);
futurePeers.getProposer().injectProposalForFutureRound(futureRoundId, signedRoundChangePayload, emptyList(), 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 - 2).injectPrepare(futureRoundId, futureBlock.getHash());
final Block commitBlock = createCommitBlockFromProposalBlock(futureBlock, futureRoundId.getRoundNumber());
final SECPSignature commitSeal = context.getLocalNodeParams().getNodeKey().sign(commitBlock.getHash());
final Commit expectedCommit = localNodeMessageFactory.createCommit(futureRoundId, futureBlock.getHash(), commitSeal);
peers.verifyMessagesReceived(expectedCommit);
// requires 1 more commit and the blockchain will progress
futurePeers.getNonProposing(quorum - 2).injectCommit(futureRoundId, futureBlock);
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(1);
}
use of org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers in project besu by hyperledger.
the class ReceivedFutureProposalTest method receiveRoundStateIsNotLostIfASecondProposalMessageIsReceivedForCurrentRound.
@Test
public void receiveRoundStateIsNotLostIfASecondProposalMessageIsReceivedForCurrentRound() {
final Block block = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final PreparedCertificate preparedRoundArtifacts = createValidPreparedCertificate(context, roundId, block);
final List<SignedData<RoundChangePayload>> roundChanges = peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtifacts);
final RoundSpecificPeers nextRoles = context.roundSpecificPeers(nextRoundId);
final ValidatorPeer nextProposer = nextRoles.getProposer();
nextProposer.injectProposalForFutureRound(nextRoundId, roundChanges, preparedRoundArtifacts.getPrepares(), block);
peers.verifyMessagesReceived(localNodeMessageFactory.createPrepare(nextRoundId, block.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, block.getHash());
nextProposer.injectProposalForFutureRound(nextRoundId, roundChanges, preparedRoundArtifacts.getPrepares(), block);
nextProposer.injectPrepare(nextRoundId, block.getHash());
peers.verifyNoMessagesReceived();
nextRoles.getNonProposing(1).injectPrepare(nextRoundId, block.getHash());
final Commit expectedCommit = new Commit(IntegrationTestHelpers.createSignedCommitPayload(nextRoundId, block, context.getLocalNodeParams().getNodeKey()));
peers.verifyMessagesReceived(expectedCommit);
}
Aggregations