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);
}
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);
}
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);
}
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());
}
}
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());
}
}
}
Aggregations