Search in sources :

Example 1 with Proposal

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.

the class RoundStateTest method invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal.

@Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
    final Prepare firstPrepare = validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
    final Prepare secondPrepare = validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
    // RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be
    // 'prepared'.
    final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
    when(messageValidator.validateProposal(any())).thenReturn(true);
    when(messageValidator.validatePrepare(firstPrepare)).thenReturn(true);
    when(messageValidator.validatePrepare(secondPrepare)).thenReturn(false);
    roundState.addPrepareMessage(firstPrepare);
    roundState.addPrepareMessage(secondPrepare);
    verify(messageValidator, never()).validatePrepare(any());
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
    assertThat(roundState.setProposedBlock(proposal)).isTrue();
    assertThat(roundState.isPrepared()).isFalse();
    assertThat(roundState.isCommitted()).isFalse();
    assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
Also used : Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 2 with Proposal

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.

the class RoundStateTest method ifProposalMessageFailsValidationMethodReturnsFalse.

@Test
public void ifProposalMessageFailsValidationMethodReturnsFalse() {
    when(messageValidator.validateProposal(any())).thenReturn(false);
    final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
    final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
    assertThat(roundState.setProposedBlock(proposal)).isFalse();
    assertThat(roundState.isPrepared()).isFalse();
    assertThat(roundState.isCommitted()).isFalse();
    assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
Also used : Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 3 with Proposal

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.

the class ProposalPayloadValidatorTest method validationFailsWhenExpectedProposerDoesNotMatchPayloadsAuthor.

@Test
public void validationFailsWhenExpectedProposerDoesNotMatchPayloadsAuthor() {
    final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(Address.fromHexString("0x1"), roundIdentifier, blockValidator, protocolContext, bftExtraDataCodec);
    final Block block = ProposedBlockHelpers.createProposalBlock(emptyList(), roundIdentifier);
    final Proposal proposal = messageFactory.createProposal(roundIdentifier, block, emptyList(), emptyList());
    assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse();
    verifyNoMoreInteractions(blockValidator);
}
Also used : Block(org.hyperledger.besu.ethereum.core.Block) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 4 with Proposal

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.

the class ProposalPayloadValidatorTest method validationFailsWhenMessageMismatchesExpectedHeight.

@Test
public void validationFailsWhenMessageMismatchesExpectedHeight() {
    final ProposalPayloadValidator payloadValidator = new ProposalPayloadValidator(expectedProposer, roundIdentifier, blockValidator, protocolContext, bftExtraDataCodec);
    final Block block = ProposedBlockHelpers.createProposalBlock(emptyList(), roundIdentifier);
    final Proposal proposal = messageFactory.createProposal(ConsensusRoundHelpers.createFrom(roundIdentifier, +1, 0), block, emptyList(), emptyList());
    assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse();
    verifyNoMoreInteractions(blockValidator);
}
Also used : Block(org.hyperledger.besu.ethereum.core.Block) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 5 with Proposal

use of org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal in project besu by hyperledger.

the class ProposalValidatorTest method validationFailsIfPiggybackedRoundChangePayloadHasDuplicatedAuthors.

@Test
public void validationFailsIfPiggybackedRoundChangePayloadHasDuplicatedAuthors() {
    final RoundSpecificItems roundItem = roundItems.get(ROUND_ID.ONE);
    final List<SignedData<RoundChangePayload>> roundChanges = createEmptyRoundChangePayloads(roundItem.roundIdentifier, validators.getNode(0), validators.getNode(1), validators.getNode(1));
    final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItem.roundIdentifier, roundItem.block, roundChanges, emptyList());
    assertThat(roundItem.messageValidator.validate(proposal)).isFalse();
}
Also used : SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Aggregations

Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)48 Test (org.junit.Test)37 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)18 Block (org.hyperledger.besu.ethereum.core.Block)14 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)11 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)9 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)7 Test (org.junit.jupiter.api.Test)7 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)5 Commit (org.hyperledger.besu.consensus.qbft.messagewrappers.Commit)4 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)4 Bytes (org.apache.tuweni.bytes.Bytes)2 QbftContext (org.hyperledger.besu.consensus.qbft.QbftContext)2 MessageFactory (org.hyperledger.besu.consensus.qbft.payload.MessageFactory)2 PreparedRoundMetadata (org.hyperledger.besu.consensus.qbft.payload.PreparedRoundMetadata)2 RoundChangePayload (org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)2 PkiQbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)2 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)2 IntegrationTestHelpers.createValidPreparedCertificate (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate)2 Hash (org.hyperledger.besu.datatypes.Hash)2