Search in sources :

Example 1 with MessageFactory

use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.

the class RoundChangeArtifactsTest method setup.

@Before
public void setup() {
    for (int i = 0; i < 4; i++) {
        final NodeKey nodeKey = NodeKeyUtils.generate();
        final MessageFactory messageFactory = new MessageFactory(nodeKey);
        messageFactories.add(messageFactory);
    }
}
Also used : MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) NodeKey(org.hyperledger.besu.crypto.NodeKey) Before(org.junit.Before)

Example 2 with MessageFactory

use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.

the class RoundStateTest method setup.

@Before
public void setup() {
    for (int i = 0; i < 3; i++) {
        final NodeKey newNodeKey = NodeKeyUtils.generate();
        validatorKeys.add(newNodeKey);
        validators.add(Util.publicKeyToAddress(newNodeKey.getPublicKey()));
        validatorMessageFactories.add(new MessageFactory(newNodeKey));
    }
    when(block.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
}
Also used : MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) NodeKey(org.hyperledger.besu.crypto.NodeKey) Before(org.junit.Before)

Example 3 with MessageFactory

use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.

the class RoundChangeCertificateValidatorTest method latestPreparedCertificateIsExtractedFromRoundChangeCertificate.

@Test
public void latestPreparedCertificateIsExtractedFromRoundChangeCertificate() {
    // NOTE: This function does not validate that all RoundCHanges/Prepares etc. come from valid
    // sources, it is only responsible for determine which of the list or RoundChange messages
    // contains the newest
    // NOTE: This capability is tested as part of the NewRoundMessageValidationTests.
    final NodeKey proposerKey = NodeKeyUtils.generate();
    final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
    final Block proposedBlock = mock(Block.class);
    when(proposedBlock.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
    final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);
    final ConsensusRoundIdentifier preparedRound = ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -1);
    final Proposal differentProposal = proposerMessageFactory.createProposal(preparedRound, proposedBlock, Optional.empty());
    final Optional<PreparedRoundArtifacts> latterPreparedRoundArtifacts = Optional.of(new PreparedRoundArtifacts(differentProposal, Lists.newArrayList(proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()), proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()))));
    // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
    // is correctly followed.
    final ConsensusRoundIdentifier earlierPreparedRound = ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -2);
    final Proposal earlierProposal = proposerMessageFactory.createProposal(earlierPreparedRound, proposedBlock, Optional.empty());
    final Optional<PreparedRoundArtifacts> earlierPreparedRoundArtifacts = Optional.of(new PreparedRoundArtifacts(earlierProposal, Lists.newArrayList(proposerMessageFactory.createPrepare(earlierPreparedRound, proposedBlock.getHash()), proposerMessageFactory.createPrepare(earlierPreparedRound, proposedBlock.getHash()))));
    final Optional<PreparedCertificate> newestCert = RoundChangeCertificateValidator.findLatestPreparedCertificate(Lists.newArrayList(proposerMessageFactory.createRoundChange(roundIdentifier, earlierPreparedRoundArtifacts).getSignedPayload(), proposerMessageFactory.createRoundChange(roundIdentifier, latterPreparedRoundArtifacts).getSignedPayload()));
    assertThat(newestCert.get()).isEqualTo(latterPreparedRoundArtifacts.get().getPreparedCertificate());
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) Block(org.hyperledger.besu.ethereum.core.Block) PreparedRoundArtifacts(org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts) PreparedCertificate(org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate) NodeKey(org.hyperledger.besu.crypto.NodeKey) Proposal(org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal) Test(org.junit.Test)

Example 4 with MessageFactory

use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.

the class RoundChangeCertificateValidatorTest method allRoundChangeHaveNoPreparedReturnsEmptyOptional.

@Test
public void allRoundChangeHaveNoPreparedReturnsEmptyOptional() {
    final NodeKey proposerKey = NodeKeyUtils.generate();
    final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
    final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);
    final Optional<PreparedCertificate> newestCert = RoundChangeCertificateValidator.findLatestPreparedCertificate(Lists.newArrayList(proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()).getSignedPayload(), proposerMessageFactory.createRoundChange(roundIdentifier, Optional.empty()).getSignedPayload()));
    assertThat(newestCert).isEmpty();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) PreparedCertificate(org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate) NodeKey(org.hyperledger.besu.crypto.NodeKey) Test(org.junit.Test)

Example 5 with MessageFactory

use of org.hyperledger.besu.consensus.ibft.payload.MessageFactory in project besu by hyperledger.

the class TestHelpers method createSignedProposalPayloadWithRound.

public static Proposal createSignedProposalPayloadWithRound(final NodeKey signerNodeKey, final int round) {
    final MessageFactory messageFactory = new MessageFactory(signerNodeKey);
    final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round);
    final Block block = ProposedBlockHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), roundIdentifier);
    return messageFactory.createProposal(roundIdentifier, block, Optional.empty());
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) Block(org.hyperledger.besu.ethereum.core.Block)

Aggregations

MessageFactory (org.hyperledger.besu.consensus.ibft.payload.MessageFactory)17 NodeKey (org.hyperledger.besu.crypto.NodeKey)9 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)7 Block (org.hyperledger.besu.ethereum.core.Block)5 Before (org.junit.Before)4 Test (org.junit.Test)4 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)3 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)3 BftExecutors (org.hyperledger.besu.consensus.common.bft.BftExecutors)3 BlockTimer (org.hyperledger.besu.consensus.common.bft.BlockTimer)3 EventMultiplexer (org.hyperledger.besu.consensus.common.bft.EventMultiplexer)3 MessageTracker (org.hyperledger.besu.consensus.common.bft.MessageTracker)3 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)3 Address (org.hyperledger.besu.datatypes.Address)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)3 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)2