Search in sources :

Example 1 with RoundSpecificPeers

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()));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) BlockTimerExpiry(org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry) RoundSpecificPeers(org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers) Block(org.hyperledger.besu.ethereum.core.Block) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead)

Example 2 with RoundSpecificPeers

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()));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ValidatorPeer(org.hyperledger.besu.consensus.qbft.support.ValidatorPeer) RoundSpecificPeers(org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers) Block(org.hyperledger.besu.ethereum.core.Block) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead)

Example 3 with RoundSpecificPeers

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

Example 4 with RoundSpecificPeers

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

Aggregations

ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)4 RoundSpecificPeers (org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers)4 Block (org.hyperledger.besu.ethereum.core.Block)4 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)2 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)2 Commit (org.hyperledger.besu.consensus.qbft.messagewrappers.Commit)2 ValidatorPeer (org.hyperledger.besu.consensus.qbft.support.ValidatorPeer)2 Test (org.junit.jupiter.api.Test)2 BlockTimerExpiry (org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry)1 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)1 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)1 IntegrationTestHelpers.createCommitBlockFromProposalBlock (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createCommitBlockFromProposalBlock)1 IntegrationTestHelpers.createValidPreparedCertificate (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate)1 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)1