Search in sources :

Example 1 with RoundSpecificPeers

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);
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) RoundSpecificPeers(org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers) Block(org.hyperledger.besu.ethereum.core.Block) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) Test(org.junit.jupiter.api.Test)

Example 2 with RoundSpecificPeers

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);
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ValidatorPeer(org.hyperledger.besu.consensus.ibft.support.ValidatorPeer) Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) RoundSpecificPeers(org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers) Block(org.hyperledger.besu.ethereum.core.Block) PreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts) IntegrationTestHelpers.createValidPreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts) Test(org.junit.jupiter.api.Test)

Aggregations

ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)2 Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)2 RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)2 RoundSpecificPeers (org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers)2 Block (org.hyperledger.besu.ethereum.core.Block)2 Test (org.junit.jupiter.api.Test)2 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)1 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)1 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)1 IntegrationTestHelpers.createValidPreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts)1 ValidatorPeer (org.hyperledger.besu.consensus.ibft.support.ValidatorPeer)1