Search in sources :

Example 1 with Commit

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

the class CommitValidatorTest method commitForWrongSequenceFails.

@Test
public void commitForWrongSequenceFails() {
    final SECPSignature commitSeal = validators.getNode(0).getNodeKey().sign(expectedHash);
    final Commit msg = validators.getMessageFactory(0).createCommit(ConsensusRoundHelpers.createFrom(round, +1, 0), expectedHash, commitSeal);
    assertThat(validator.validate(msg)).isFalse();
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Commit(org.hyperledger.besu.consensus.qbft.messagewrappers.Commit) Test(org.junit.Test)

Example 2 with Commit

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

the class CommitValidatorTest method commitSignedByANonValidatorFails.

@Test
public void commitSignedByANonValidatorFails() {
    final QbftNode nonValidator = QbftNode.create();
    final SECPSignature commitSeal = nonValidator.getNodeKey().sign(expectedHash);
    final Commit msg = nonValidator.getMessageFactory().createCommit(round, expectedHash, commitSeal);
    assertThat(validator.validate(msg)).isFalse();
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Commit(org.hyperledger.besu.consensus.qbft.messagewrappers.Commit) Test(org.junit.Test)

Example 3 with Commit

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

the class CommitValidatorTest method commitWithWrongDigestFails.

@Test
public void commitWithWrongDigestFails() {
    final SECPSignature commitSeal = validators.getNode(0).getNodeKey().sign(expectedHash);
    final Commit msg = validators.getMessageFactory(0).createCommit(round, Hash.fromHexStringLenient("0x2"), commitSeal);
    assertThat(validator.validate(msg)).isFalse();
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Commit(org.hyperledger.besu.consensus.qbft.messagewrappers.Commit) Test(org.junit.Test)

Example 4 with Commit

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

the class QbftRound method updateStateWithProposedBlock.

private boolean updateStateWithProposedBlock(final Proposal msg) {
    final boolean wasPrepared = roundState.isPrepared();
    final boolean wasCommitted = roundState.isCommitted();
    final boolean blockAccepted = roundState.setProposedBlock(msg);
    if (blockAccepted) {
        final Block block = roundState.getProposedBlock().get();
        final SECPSignature commitSeal;
        try {
            commitSeal = createCommitSeal(block);
        } catch (final SecurityModuleException e) {
            LOG.warn("Failed to construct commit seal; {}", e.getMessage());
            return true;
        }
        // There are times handling a proposed block is enough to enter prepared.
        if (wasPrepared != roundState.isPrepared()) {
            LOG.debug("Sending commit message. round={}", roundState.getRoundIdentifier());
            transmitter.multicastCommit(getRoundIdentifier(), block.getHash(), commitSeal);
        }
        // prepare
        try {
            final Commit localCommitMessage = messageFactory.createCommit(roundState.getRoundIdentifier(), msg.getBlock().getHash(), commitSeal);
            roundState.addCommitMessage(localCommitMessage);
        } catch (final SecurityModuleException e) {
            LOG.warn("Failed to create signed Commit message; {}", e.getMessage());
            return true;
        }
        // It is possible sufficient commit seals are now available and the block should be imported
        if (wasCommitted != roundState.isCommitted()) {
            importBlockToChain();
        }
    }
    return blockAccepted;
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) Commit(org.hyperledger.besu.consensus.qbft.messagewrappers.Commit) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Block(org.hyperledger.besu.ethereum.core.Block)

Example 5 with Commit

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

the class QbftMessageTransmitter method multicastCommit.

public void multicastCommit(final ConsensusRoundIdentifier roundIdentifier, final Hash digest, final SECPSignature commitSeal) {
    try {
        final Commit data = messageFactory.createCommit(roundIdentifier, digest, commitSeal);
        final CommitMessageData message = CommitMessageData.create(data);
        multicaster.send(message);
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to generate signature for Commit (not sent): {} ", e.getMessage());
    }
}
Also used : Commit(org.hyperledger.besu.consensus.qbft.messagewrappers.Commit) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) CommitMessageData(org.hyperledger.besu.consensus.qbft.messagedata.CommitMessageData)

Aggregations

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