Search in sources :

Example 1 with SecurityModuleException

use of org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException in project besu by hyperledger.

the class QbftRoundTest method exceptionDuringNodeKeySigningDoesNotEscape.

@Test
public void exceptionDuringNodeKeySigningDoesNotEscape() {
    final int QUORUM_SIZE = 1;
    final RoundState roundState = new RoundState(roundIdentifier, QUORUM_SIZE, messageValidator);
    final NodeKey throwingNodeKey = mock(NodeKey.class);
    final MessageFactory throwingMessageFactory = new MessageFactory(throwingNodeKey);
    when(throwingNodeKey.sign(any())).thenThrow(new SecurityModuleException("Hsm is Offline"));
    final QbftRound round = new QbftRound(roundState, blockCreator, protocolContext, blockImporter, subscribers, throwingNodeKey, throwingMessageFactory, transmitter, roundTimer, bftExtraDataCodec);
    round.handleProposalMessage(messageFactory.createProposal(roundIdentifier, proposedBlock, Collections.emptyList(), Collections.emptyList()));
    // Verify that no prepare message was constructed by the QbftRound
    assertThat(roundState.constructPreparedCertificate()).isEmpty();
    verifyNoInteractions(transmitter);
}
Also used : MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Example 2 with SecurityModuleException

use of org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException in project besu by hyperledger.

the class QbftBlockHeightManager method roundExpired.

@Override
public void roundExpired(final RoundExpiry expire) {
    if (currentRound.isEmpty()) {
        LOG.error("Received Round timer expiry before round is created timerRound={}", expire.getView());
        return;
    }
    QbftRound qbftRound = currentRound.get();
    if (!expire.getView().equals(qbftRound.getRoundIdentifier())) {
        LOG.trace("Ignoring Round timer expired which does not match current round. round={}, timerRound={}", qbftRound.getRoundIdentifier(), expire.getView());
        return;
    }
    LOG.debug("Round has expired, creating PreparedCertificate and notifying peers. round={}", qbftRound.getRoundIdentifier());
    final Optional<PreparedCertificate> preparedCertificate = qbftRound.constructPreparedCertificate();
    if (preparedCertificate.isPresent()) {
        latestPreparedCertificate = preparedCertificate;
    }
    startNewRound(qbftRound.getRoundIdentifier().getRoundNumber() + 1);
    qbftRound = currentRound.get();
    try {
        final RoundChange localRoundChange = messageFactory.createRoundChange(qbftRound.getRoundIdentifier(), latestPreparedCertificate);
        // Its possible the locally created RoundChange triggers the transmission of a NewRound
        // message - so it must be handled accordingly.
        handleRoundChangePayload(localRoundChange);
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to create signed RoundChange message.", e);
    }
    transmitter.multicastRoundChange(qbftRound.getRoundIdentifier(), latestPreparedCertificate);
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)

Example 3 with SecurityModuleException

use of org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException in project besu by hyperledger.

the class QbftRound method updateStateWithProposalAndTransmit.

protected void updateStateWithProposalAndTransmit(final Block block, final List<SignedData<RoundChangePayload>> roundChanges, final List<SignedData<PreparePayload>> prepares) {
    final Proposal proposal;
    try {
        proposal = messageFactory.createProposal(getRoundIdentifier(), block, roundChanges, prepares);
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to create a signed Proposal, waiting for next round.", e);
        return;
    }
    transmitter.multicastProposal(proposal.getRoundIdentifier(), proposal.getSignedPayload().getPayload().getProposedBlock(), roundChanges, prepares);
    updateStateWithProposedBlock(proposal);
    sendPrepare(block);
}
Also used : SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)

Example 4 with SecurityModuleException

use of org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException in project besu by hyperledger.

the class QbftRound method sendPrepare.

private void sendPrepare(final Block block) {
    LOG.debug("Sending prepare message. round={}", roundState.getRoundIdentifier());
    try {
        final Prepare localPrepareMessage = messageFactory.createPrepare(getRoundIdentifier(), block.getHash());
        peerIsPrepared(localPrepareMessage);
        transmitter.multicastPrepare(localPrepareMessage.getRoundIdentifier(), localPrepareMessage.getDigest());
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to create a signed Prepare; {}", e.getMessage());
    }
}
Also used : SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)

Example 5 with SecurityModuleException

use of org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException in project besu by hyperledger.

the class QbftRound method peerIsPrepared.

private void peerIsPrepared(final Prepare msg) {
    final boolean wasPrepared = roundState.isPrepared();
    roundState.addPrepareMessage(msg);
    if (wasPrepared != roundState.isPrepared()) {
        LOG.debug("Sending commit message. round={}", roundState.getRoundIdentifier());
        final Block block = roundState.getProposedBlock().get();
        try {
            transmitter.multicastCommit(getRoundIdentifier(), block.getHash(), createCommitSeal(block));
        // Note: the local-node's commit message was added to RoundState on block acceptance
        // and thus does not need to be done again here.
        } catch (final SecurityModuleException e) {
            LOG.warn("Failed to construct a commit seal: {}", e.getMessage());
        }
    }
}
Also used : SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) Block(org.hyperledger.besu.ethereum.core.Block)

Aggregations

SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)25 Block (org.hyperledger.besu.ethereum.core.Block)8 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 Bytes (org.apache.tuweni.bytes.Bytes)2 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)2 Commit (org.hyperledger.besu.consensus.ibft.messagewrappers.Commit)2 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)2 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)2 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)2 MessageFactory (org.hyperledger.besu.consensus.ibft.payload.MessageFactory)2 Commit (org.hyperledger.besu.consensus.qbft.messagewrappers.Commit)2 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)2 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)2 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)2 MessageFactory (org.hyperledger.besu.consensus.qbft.payload.MessageFactory)2 NodeKey (org.hyperledger.besu.crypto.NodeKey)2 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)2 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)2