Search in sources :

Example 1 with RoundChange

use of org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange in project besu by hyperledger.

the class IbftBlockHeightManagerTest method whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted.

@Test
public void whenSufficientRoundChangesAreReceivedAProposalMessageIsTransmitted() {
    final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
    final RoundChange roundChange = messageFactory.createRoundChange(futureRoundIdentifier, Optional.empty());
    final RoundChangeCertificate roundChangCert = new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()));
    when(roundChangeManager.appendRoundChangeMessage(any())).thenReturn(Optional.of(singletonList(roundChange)));
    when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true);
    final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
    reset(messageTransmitter);
    manager.handleRoundChangePayload(roundChange);
    verify(messageTransmitter, times(1)).multicastProposal(eq(futureRoundIdentifier), any(), eq(Optional.of(roundChangCert)));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) RoundChangeCertificate(org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate) Test(org.junit.Test)

Example 2 with RoundChange

use of org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeManagerTest method rejectsInvalidRoundChangeMessage.

@Test
public void rejectsInvalidRoundChangeMessage() {
    final RoundChange roundChangeData = makeRoundChangeMessage(nonValidatorKey, ri1);
    assertThat(manager.appendRoundChangeMessage(roundChangeData)).isEmpty();
    assertThat(manager.roundChangeCache.get(ri1)).isNull();
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Test(org.junit.Test)

Example 3 with RoundChange

use of org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeManagerTest method doesntReachReadyWhenSuppliedWithDifferentRounds.

@Test
public void doesntReachReadyWhenSuppliedWithDifferentRounds() {
    final RoundChange roundChangeDataProposer = makeRoundChangeMessage(proposerKey, ri2);
    final RoundChange roundChangeDataValidator1 = makeRoundChangeMessage(validator1Key, ri3);
    assertThat(manager.appendRoundChangeMessage(roundChangeDataProposer)).isEqualTo(Optional.empty());
    assertThat(manager.appendRoundChangeMessage(roundChangeDataValidator1)).isEqualTo(Optional.empty());
    assertThat(manager.roundChangeCache.get(ri2).receivedMessages.size()).isEqualTo(1);
    assertThat(manager.roundChangeCache.get(ri3).receivedMessages.size()).isEqualTo(1);
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Test(org.junit.Test)

Example 4 with RoundChange

use of org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeManagerTest method becomesReadyAtThreshold.

@Test
public void becomesReadyAtThreshold() {
    final RoundChange roundChangeDataProposer = makeRoundChangeMessage(proposerKey, ri2);
    final RoundChange roundChangeDataValidator1 = makeRoundChangeMessage(validator1Key, ri2);
    assertThat(manager.appendRoundChangeMessage(roundChangeDataProposer)).isEqualTo(Optional.empty());
    assertThat(manager.appendRoundChangeMessage(roundChangeDataValidator1).isPresent()).isTrue();
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Test(org.junit.Test)

Example 5 with RoundChange

use of org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeManagerTest method discardsRoundPreviousToThatRequested.

@Test
public void discardsRoundPreviousToThatRequested() {
    final RoundChange roundChangeDataProposer = makeRoundChangeMessage(proposerKey, ri1);
    final RoundChange roundChangeDataValidator1 = makeRoundChangeMessage(validator1Key, ri2);
    final RoundChange roundChangeDataValidator2 = makeRoundChangeMessage(validator2Key, ri3);
    assertThat(manager.appendRoundChangeMessage(roundChangeDataProposer)).isEqualTo(Optional.empty());
    assertThat(manager.appendRoundChangeMessage(roundChangeDataValidator1)).isEqualTo(Optional.empty());
    assertThat(manager.appendRoundChangeMessage(roundChangeDataValidator2)).isEqualTo(Optional.empty());
    manager.discardRoundsPriorTo(ri2);
    assertThat(manager.roundChangeCache.get(ri1)).isNull();
    assertThat(manager.roundChangeCache.get(ri2).receivedMessages.size()).isEqualTo(1);
    assertThat(manager.roundChangeCache.get(ri3).receivedMessages.size()).isEqualTo(1);
}
Also used : RoundChange(org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange) Test(org.junit.Test)

Aggregations

RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)31 Test (org.junit.Test)21 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)11 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)8 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)7 Test (org.junit.jupiter.api.Test)7 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)5 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)4 RoundChangeCertificate (org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate)4 PreparedCertificate (org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate)3 Block (org.hyperledger.besu.ethereum.core.Block)3 IntegrationTestHelpers.createValidPreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1