Search in sources :

Example 1 with Proposal

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal 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());
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 2 with Proposal

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.

the class RoundStateTest method singleValidatorRequiresCommitMessageToBeCommitted.

@Test
public void singleValidatorRequiresCommitMessageToBeCommitted() {
    when(messageValidator.validateProposal(any())).thenReturn(true);
    when(messageValidator.validateCommit(any())).thenReturn(true);
    final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Optional.empty());
    assertThat(roundState.setProposedBlock(proposal)).isTrue();
    assertThat(roundState.isPrepared()).isTrue();
    assertThat(roundState.isCommitted()).isFalse();
    final Commit commit = validatorMessageFactories.get(0).createCommit(roundIdentifier, block.getHash(), SignatureAlgorithmFactory.getInstance().createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 1));
    roundState.addCommitMessage(commit);
    assertThat(roundState.isPrepared()).isTrue();
    assertThat(roundState.isCommitted()).isTrue();
    assertThat(roundState.constructPreparedRoundArtifacts()).isNotEmpty();
}
Also used : Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 3 with Proposal

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.

the class RoundStateTest method commitSealsAreExtractedFromReceivedMessages.

@Test
public void commitSealsAreExtractedFromReceivedMessages() {
    when(messageValidator.validateProposal(any())).thenReturn(true);
    when(messageValidator.validateCommit(any())).thenReturn(true);
    final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
    final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithmFactory.getInstance();
    final Commit firstCommit = validatorMessageFactories.get(1).createCommit(roundIdentifier, block.getHash(), signatureAlgorithm.createSignature(BigInteger.ONE, BigInteger.TEN, (byte) 1));
    final Commit secondCommit = validatorMessageFactories.get(2).createCommit(roundIdentifier, block.getHash(), signatureAlgorithm.createSignature(BigInteger.TEN, BigInteger.TEN, (byte) 1));
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Optional.empty());
    roundState.setProposedBlock(proposal);
    roundState.addCommitMessage(firstCommit);
    assertThat(roundState.isCommitted()).isFalse();
    roundState.addCommitMessage(secondCommit);
    assertThat(roundState.isCommitted()).isTrue();
    assertThat(roundState.getCommitSeals()).containsOnly(firstCommit.getCommitSeal(), secondCommit.getCommitSeal());
}
Also used : Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) SignatureAlgorithm(org.hyperledger.besu.crypto.SignatureAlgorithm) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 4 with Proposal

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.

the class RoundStateTest method singleValidatorIsPreparedWithJustProposal.

@Test
public void singleValidatorIsPreparedWithJustProposal() {
    when(messageValidator.validateProposal(any())).thenReturn(true);
    final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Optional.empty());
    assertThat(roundState.setProposedBlock(proposal)).isTrue();
    assertThat(roundState.isPrepared()).isTrue();
    assertThat(roundState.isCommitted()).isFalse();
    assertThat(roundState.constructPreparedRoundArtifacts()).isNotEmpty();
    assertThat(roundState.constructPreparedRoundArtifacts().get().getPreparedCertificate().getProposalPayload()).isEqualTo(proposal.getSignedPayload());
}
Also used : Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 5 with Proposal

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal in project besu by hyperledger.

the class FutureRoundProposalMessageValidatorTest method validProposalMatchingCurrentChainHeightPassesValidation.

@Test
public void validProposalMatchingCurrentChainHeightPassesValidation() {
    final Proposal proposal = messageFactoy.createProposal(roundIdentifier, proposedBlock, Optional.empty());
    assertThat(validator.validateProposalMessage(proposal)).isTrue();
}
Also used : Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Aggregations

Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)48 Test (org.junit.Test)36 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)18 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)13 RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)11 Block (org.hyperledger.besu.ethereum.core.Block)9 Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)8 Test (org.junit.jupiter.api.Test)8 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)5 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)5 MessageFactory (org.hyperledger.besu.consensus.ibft.payload.MessageFactory)4 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)3 IntegrationTestHelpers.createValidPreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts)3 IbftExtraDataCodec (org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec)2 NodeKey (org.hyperledger.besu.crypto.NodeKey)2 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1