Search in sources :

Example 1 with PreparedRoundMetadata

use of org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata in project besu by hyperledger.

the class ProposalValidatorTest method validationFailsIfBlockHashInLatestPreparedMetadataDoesNotMatchProposedBlock.

@Test
public void validationFailsIfBlockHashInLatestPreparedMetadataDoesNotMatchProposedBlock() {
    final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ONE);
    final List<SignedData<RoundChangePayload>> roundChanges = createEmptyRoundChangePayloads(roundItem.roundIdentifier, validators.getNode(0), validators.getNode(1));
    final RoundChangePayload illegalPayload = new RoundChangePayload(roundItem.roundIdentifier, Optional.of(new PreparedRoundMetadata(Hash.fromHexStringLenient("0x1"), roundItems.get(ROUND_ID.ZERO).roundIdentifier.getRoundNumber())));
    final SignedData<RoundChangePayload> preparedRoundChange = SignedData.create(illegalPayload, validators.getNode(2).getNodeKey().sign(illegalPayload.hashForSignature()));
    roundChanges.add(preparedRoundChange);
    final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItem.roundIdentifier, roundItem.block, roundChanges, createPreparePayloads(roundItems.get(ROUND_ID.ZERO).roundIdentifier, Hash.fromHexStringLenient("0x1"), validators.getNode(0), validators.getNode(1), validators.getNode(2)));
    assertThat(roundItem.messageValidator.validate(proposal)).isFalse();
}
Also used : SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) PreparedRoundMetadata(org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata) RoundChangePayload(org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 2 with PreparedRoundMetadata

use of org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata in project besu by hyperledger.

the class ProposalValidatorTest method validationFailsIfTwoRoundChangesArePreparedOnSameRoundDifferentBlock.

@Test
public void validationFailsIfTwoRoundChangesArePreparedOnSameRoundDifferentBlock() {
    final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ONE);
    final List<SignedData<RoundChangePayload>> roundChanges = createPreparedRoundZeroRoundChanges();
    final RoundChangePayload illegalPreparedRoundChangePayload = new RoundChangePayload(roundItem.roundIdentifier, Optional.of(new PreparedRoundMetadata(roundItems.get(ROUND_ID.ONE).block.getHash(), roundItems.get(ROUND_ID.ZERO).roundIdentifier.getRoundNumber())));
    final SignedData<RoundChangePayload> preparedRoundChange = SignedData.create(illegalPreparedRoundChangePayload, validators.getNode(3).getNodeKey().sign(illegalPreparedRoundChangePayload.hashForSignature()));
    roundChanges.add(preparedRoundChange);
    final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItem.roundIdentifier, roundItem.block, roundChanges, createPreparePayloads(roundItems.get(ROUND_ID.ZERO).roundIdentifier, Hash.fromHexStringLenient("0x1"), validators.getNode(0), validators.getNode(1), validators.getNode(2)));
    assertThat(roundItem.messageValidator.validate(proposal)).isFalse();
}
Also used : SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) PreparedRoundMetadata(org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata) RoundChangePayload(org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 3 with PreparedRoundMetadata

use of org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata in project besu by hyperledger.

the class ProposalValidatorTest method createPreparedRoundZeroRoundChanges.

private List<SignedData<RoundChangePayload>> createPreparedRoundZeroRoundChanges() {
    final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ONE);
    final List<SignedData<RoundChangePayload>> roundChanges = createEmptyRoundChangePayloads(roundItem.roundIdentifier, validators.getNode(0), validators.getNode(1));
    final RoundChangePayload preparedRoundChangePayload = new RoundChangePayload(roundItem.roundIdentifier, Optional.of(new PreparedRoundMetadata(roundItems.get(ROUND_ID.ZERO).block.getHash(), roundItems.get(ROUND_ID.ZERO).roundIdentifier.getRoundNumber())));
    final SignedData<RoundChangePayload> preparedRoundChange = SignedData.create(preparedRoundChangePayload, validators.getNode(2).getNodeKey().sign(preparedRoundChangePayload.hashForSignature()));
    roundChanges.add(preparedRoundChange);
    return roundChanges;
}
Also used : SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) PreparedRoundMetadata(org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata) RoundChangePayload(org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)

Example 4 with PreparedRoundMetadata

use of org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata in project besu by hyperledger.

the class RoundChangePayloadValidatorTest method roundChangeWithMatchingTargetAndPrepareFails.

@Test
public void roundChangeWithMatchingTargetAndPrepareFails() {
    final RoundChangePayload payload = new RoundChangePayload(new ConsensusRoundIdentifier(chainHeight, 1), Optional.of(new PreparedRoundMetadata(preparedBlockHash, 1)));
    final SignedData<RoundChangePayload> signedPayload = createSignedPayload(payload, validators.getNode(0).getNodeKey());
    assertThat(messageValidator.validate(signedPayload)).isFalse();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) PreparedRoundMetadata(org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata) RoundChangePayload(org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload) Test(org.junit.Test)

Example 5 with PreparedRoundMetadata

use of org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata in project besu by hyperledger.

the class RoundChangePayloadValidatorTest method roundChangeForFutureHeightFails.

@Test
public void roundChangeForFutureHeightFails() {
    final RoundChangePayload payload = new RoundChangePayload(new ConsensusRoundIdentifier(chainHeight + 1, 1), Optional.of(new PreparedRoundMetadata(preparedBlockHash, 0)));
    final SignedData<RoundChangePayload> signedPayload = createSignedPayload(payload, validators.getNode(0).getNodeKey());
    assertThat(messageValidator.validate(signedPayload)).isFalse();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) PreparedRoundMetadata(org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata) RoundChangePayload(org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload) Test(org.junit.Test)

Aggregations

PreparedRoundMetadata (org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata)16 RoundChangePayload (org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)14 Test (org.junit.Test)12 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)10 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)4 NodeKey (org.hyperledger.besu.crypto.NodeKey)3 Block (org.hyperledger.besu.ethereum.core.Block)3 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)2 PreparePayload (org.hyperledger.besu.consensus.qbft.payload.PreparePayload)2 Address (org.hyperledger.besu.datatypes.Address)2 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)1 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)1 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)1 ProposalPayload (org.hyperledger.besu.consensus.qbft.payload.ProposalPayload)1 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)1 Hash (org.hyperledger.besu.datatypes.Hash)1 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)1 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)1