use of org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec in project besu by hyperledger.
the class QbftRoundTest method localNodeProposesToNetworkOfTwoValidatorsImportsOnReceptionOfCommitFromPeer.
@Test
public void localNodeProposesToNetworkOfTwoValidatorsImportsOnReceptionOfCommitFromPeer() {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final QbftRound round = new QbftRound(roundState, blockCreator, protocolContext, blockImporter, subscribers, nodeKey, messageFactory, transmitter, roundTimer, bftExtraDataCodec);
final Hash commitSealHash = new BftBlockHashing(new QbftExtraDataCodec()).calculateDataHashForCommittedSeal(proposedBlock.getHeader(), proposedExtraData);
final SECPSignature localCommitSeal = nodeKey.sign(commitSealHash);
round.createAndSendProposalMessage(15);
verify(transmitter, never()).multicastCommit(any(), any(), any());
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handlePrepareMessage(messageFactory2.createPrepare(roundIdentifier, proposedBlock.getHash()));
verify(transmitter, times(1)).multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handleCommitMessage(messageFactory.createCommit(roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}
use of org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec in project besu by hyperledger.
the class IntegrationTestHelpers method createSignedCommitPayload.
public static SignedData<CommitPayload> createSignedCommitPayload(final ConsensusRoundIdentifier roundId, final Block block, final NodeKey nodeKey) {
final QbftExtraDataCodec qbftExtraDataEncoder = new QbftExtraDataCodec();
final Block commitBlock = createCommitBlockFromProposalBlock(block, roundId.getRoundNumber());
final SECPSignature commitSeal = nodeKey.sign(new BftBlockHashing(qbftExtraDataEncoder).calculateDataHashForCommittedSeal(commitBlock.getHeader()));
final MessageFactory messageFactory = new MessageFactory(nodeKey);
return messageFactory.createCommit(roundId, block.getHash(), commitSeal).getSignedPayload();
}
use of org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec in project besu by hyperledger.
the class IntegrationTestHelpers method createCommitBlockFromProposalBlock.
public static Block createCommitBlockFromProposalBlock(final Block proposalBlock, final int round) {
final QbftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();
final BftBlockInterface bftBlockInterface = new BftBlockInterface(bftExtraDataCodec);
return bftBlockInterface.replaceRoundInBlock(proposalBlock, round, BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec));
}
use of org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec in project besu by hyperledger.
the class GossipTest method futureMessageGetGossipedLater.
@Test
public void futureMessageGetGossipedLater() {
final Block signedCurrentHeightBlock = BftHelpers.createSealedBlock(new QbftExtraDataCodec(), block, 0, peers.sign(block.getHash()));
final ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0);
final Prepare futurePrepare = sender.injectPrepare(futureRoundId, block.getHash());
peers.verifyNoMessagesReceivedNonProposing();
// add block to chain so we can move to next block height
context.getBlockchain().appendBlock(signedCurrentHeightBlock, emptyList());
context.getController().handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader()));
peers.verifyMessagesReceivedNonProposing(futurePrepare);
}
use of org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec in project besu by hyperledger.
the class QbftRoundIntegrationTest method setup.
@BeforeEach
public void setup() {
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);
when(messageValidator.validateCommit(any())).thenReturn(true);
when(nodeKey.sign(any())).thenThrow(new SecurityModuleException("Hsm Is Down"));
final QbftExtraDataCodec qbftExtraDataEncoder = new QbftExtraDataCodec();
throwingMessageFactory = new MessageFactory(nodeKey);
transmitter = new QbftMessageTransmitter(throwingMessageFactory, multicaster);
final BftExtraData proposedExtraData = new BftExtraData(Bytes.wrap(new byte[32]), emptyList(), empty(), 0, emptyList());
final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture();
headerTestFixture.extraData(qbftExtraDataEncoder.encode(proposedExtraData));
headerTestFixture.number(1);
final BlockHeader header = headerTestFixture.buildHeader();
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
when(blockImporter.importBlock(any(), any(), any())).thenReturn(true);
protocolContext = new ProtocolContext(blockChain, worldStateArchive, setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), qbftExtraDataEncoder));
}
Aggregations