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