Search in sources :

Example 1 with Commit

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit 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 2 with Commit

use of org.hyperledger.besu.consensus.ibft.messagewrappers.Commit 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 3 with Commit

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

the class SignedDataValidatorTest method receivingACommitMessageBeforeProposalFails.

@Test
public void receivingACommitMessageBeforeProposalFails() {
    final Commit commitMsg = proposerMessageFactory.createCommit(roundIdentifier, Hash.ZERO, proposerKey.sign(block.getHash()));
    assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
Also used : Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) Test(org.junit.Test)

Example 4 with Commit

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

the class SignedDataValidatorTest method commitMessageContainingValidSealFromValidatorIsSuccessful.

@Test
public void commitMessageContainingValidSealFromValidatorIsSuccessful() {
    final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
    final Commit proposerCommitMsg = proposerMessageFactory.createCommit(roundIdentifier, block.getHash(), proposerKey.sign(block.getHash()));
    final Commit validatorCommitMsg = validatorMessageFactory.createCommit(roundIdentifier, block.getHash(), validatorKey.sign(block.getHash()));
    assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
    assertThat(validator.validateCommit(proposerCommitMsg.getSignedPayload())).isTrue();
    assertThat(validator.validateCommit(validatorCommitMsg.getSignedPayload())).isTrue();
}
Also used : Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 5 with Commit

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

the class SignedDataValidatorTest method receivingACommitMessageWithAnInvalidCommitSealFails.

@Test
public void receivingACommitMessageWithAnInvalidCommitSealFails() {
    final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
    final Commit commitMsg = proposerMessageFactory.createCommit(roundIdentifier, block.getHash(), nonValidatorKey.sign(block.getHash()));
    assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
    assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
}
Also used : Commit(org.hyperledger.besu.consensus.ibft.messagewrappers.Commit) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Aggregations

Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)20 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)8 Test (org.junit.Test)8 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)7 Block (org.hyperledger.besu.ethereum.core.Block)6 Test (org.junit.jupiter.api.Test)6 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)5 RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)4 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RoundSpecificPeers (org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 BlockTimerExpiry (org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry)1 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)1 CommitMessageData (org.hyperledger.besu.consensus.ibft.messagedata.CommitMessageData)1 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)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 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)1