Search in sources :

Example 1 with QbftExtraDataCodec

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());
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) BftBlockHashing(org.hyperledger.besu.consensus.common.bft.BftBlockHashing) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) Hash(org.hyperledger.besu.datatypes.Hash) Test(org.junit.Test)

Example 2 with QbftExtraDataCodec

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();
}
Also used : SECPSignature(org.hyperledger.besu.crypto.SECPSignature) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) BftBlockHashing(org.hyperledger.besu.consensus.common.bft.BftBlockHashing) Block(org.hyperledger.besu.ethereum.core.Block)

Example 3 with QbftExtraDataCodec

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));
}
Also used : BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)

Example 4 with QbftExtraDataCodec

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);
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) Block(org.hyperledger.besu.ethereum.core.Block) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) Test(org.junit.jupiter.api.Test)

Example 5 with QbftExtraDataCodec

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));
}
Also used : QbftMessageTransmitter(org.hyperledger.besu.consensus.qbft.network.QbftMessageTransmitter) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) Block(org.hyperledger.besu.ethereum.core.Block) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

QbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)10 Block (org.hyperledger.besu.ethereum.core.Block)6 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)4 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)3 MessageFactory (org.hyperledger.besu.consensus.qbft.payload.MessageFactory)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)3 BftBlockHashing (org.hyperledger.besu.consensus.common.bft.BftBlockHashing)2 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)2 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)2 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)2 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)2 Before (org.junit.Before)2 Test (org.junit.Test)2 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)1 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)1 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)1 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)1 QbftMessageTransmitter (org.hyperledger.besu.consensus.qbft.network.QbftMessageTransmitter)1