Search in sources :

Example 1 with MessageMutator

use of com.radixdlt.environment.deterministic.network.MessageMutator in project radixdlt by radixdlt.

the class RandomChannelOrderResponsiveTest method run.

private void run(int numNodes, long viewsToRun) {
    assertEquals(0, viewsToRun % numNodes);
    final Random random = new Random(12345);
    DeterministicTest test = DeterministicTest.builder().numNodes(numNodes).messageSelector(MessageSelector.randomSelector(random)).messageMutator(MessageMutator.dropTimeouts()).buildWithoutEpochs().runUntil(DeterministicTest.hasReachedView(View.of(viewsToRun)));
    List<Long> proposalsMade = IntStream.range(0, numNodes).mapToObj(test::getSystemCounters).map(counters -> counters.get(CounterType.BFT_PACEMAKER_PROPOSALS_SENT)).collect(ImmutableList.toImmutableList());
    final long numViews = viewsToRun / numNodes;
    assertThat(proposalsMade).hasSize(numNodes).areAtLeast(numNodes - 1, new Condition<>(l -> l == numViews, "has as many proposals as views")).areAtMost(1, new Condition<>(l -> l == numViews - 1, "has one less proposal"));
}
Also used : IntStream(java.util.stream.IntStream) Random(java.util.Random) Test(org.junit.Test) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) CounterType(com.radixdlt.counters.SystemCounters.CounterType) Assert.assertEquals(org.junit.Assert.assertEquals) View(com.radixdlt.consensus.bft.View) Condition(org.assertj.core.api.Condition) Random(java.util.Random) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest)

Example 2 with MessageMutator

use of com.radixdlt.environment.deterministic.network.MessageMutator in project radixdlt by radixdlt.

the class DifferentTimestampsCauseTimeoutTest method when_four_nodes_receive_qcs_with_different_timestamps__quorum_is_not_achieved.

@Test
public void when_four_nodes_receive_qcs_with_different_timestamps__quorum_is_not_achieved() {
    final int numNodes = 4;
    // TODO: this test isn't exactly right and should be updated so that
    // TODO: byzantine node sends different sets of valid QCs to each node
    DeterministicManualExecutor executor = DeterministicTest.builder().overrideWithIncorrectModule(new AbstractModule() {

        @Override
        protected void configure() {
            bind(HashVerifier.class).toInstance((pubKey, hash, sig) -> true);
            bind(HashSigner.class).toInstance(h -> ECDSASignature.zeroSignature());
        }
    }).numNodes(numNodes).messageMutator(mutateProposalsBy(1)).buildWithoutEpochs().createExecutor();
    executor.start();
    executeTwoViews(executor);
    // Timeouts from nodes
    executor.processNext(0, 0, ScheduledLocalTimeout.class);
    executor.processNext(1, 1, ScheduledLocalTimeout.class);
    executor.processNext(2, 2, ScheduledLocalTimeout.class);
    executor.processNext(3, 3, ScheduledLocalTimeout.class);
}
Also used : ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) ImmutableMap(com.google.common.collect.ImmutableMap) HashVerifier(com.radixdlt.consensus.HashVerifier) ECDSASignature(com.radixdlt.crypto.ECDSASignature) Proposal(com.radixdlt.consensus.Proposal) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) HashSigner(com.radixdlt.consensus.HashSigner) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) VoteData(com.radixdlt.consensus.VoteData) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) Vote(com.radixdlt.consensus.Vote) TimestampedECDSASignature(com.radixdlt.consensus.TimestampedECDSASignature) DeterministicManualExecutor(com.radixdlt.harness.deterministic.DeterministicTest.DeterministicManualExecutor) Map(java.util.Map) BFTNode(com.radixdlt.consensus.bft.BFTNode) Pair(com.radixdlt.utils.Pair) Optional(java.util.Optional) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) AbstractModule(com.google.inject.AbstractModule) DeterministicManualExecutor(com.radixdlt.harness.deterministic.DeterministicTest.DeterministicManualExecutor) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest)

Example 3 with MessageMutator

use of com.radixdlt.environment.deterministic.network.MessageMutator in project radixdlt by radixdlt.

the class MovingWindowValidatorsTest method run.

private void run(int numNodes, int windowSize, long maxEpoch, View highView) {
    DeterministicTest bftTest = DeterministicTest.builder().numNodes(numNodes).messageMutator(mutator()).messageSelector(firstSelector()).epochNodeIndexesMapping(windowedEpochToNodesMapper(windowSize, numNodes)).buildWithEpochs(highView).runUntil(DeterministicTest.hasReachedEpochView(EpochView.of(maxEpoch, highView)));
    LinkedList<SystemCounters> testCounters = systemCounters(bftTest);
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_VERTEX_STORE_INDIRECT_PARENTS)).containsOnly(0L);
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_PACEMAKER_TIMEOUTS_SENT)).containsOnly(0L);
    long maxCount = maxProcessedFor(numNodes, windowSize, maxEpoch, highView.number());
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_COMMITTED_VERTICES)).allMatch(between(maxCount - maxEpoch, maxCount));
}
Also used : IntStream(java.util.stream.IntStream) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) SystemCounters(com.radixdlt.counters.SystemCounters) Epoched(com.radixdlt.consensus.epoch.Epoched) LongFunction(java.util.function.LongFunction) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) EpochView(com.radixdlt.consensus.epoch.EpochView) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) ChannelId(com.radixdlt.environment.deterministic.network.ChannelId) LinkedList(java.util.LinkedList) CounterType(com.radixdlt.counters.SystemCounters.CounterType) View(com.radixdlt.consensus.bft.View) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) SystemCounters(com.radixdlt.counters.SystemCounters)

Aggregations

MessageMutator (com.radixdlt.environment.deterministic.network.MessageMutator)3 DeterministicTest (com.radixdlt.harness.deterministic.DeterministicTest)3 Test (org.junit.Test)3 View (com.radixdlt.consensus.bft.View)2 ScheduledLocalTimeout (com.radixdlt.consensus.liveness.ScheduledLocalTimeout)2 CounterType (com.radixdlt.counters.SystemCounters.CounterType)2 ControlledMessage (com.radixdlt.environment.deterministic.network.ControlledMessage)2 MessageSelector (com.radixdlt.environment.deterministic.network.MessageSelector)2 IntStream (java.util.stream.IntStream)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 AbstractModule (com.google.inject.AbstractModule)1 HashSigner (com.radixdlt.consensus.HashSigner)1 HashVerifier (com.radixdlt.consensus.HashVerifier)1 Proposal (com.radixdlt.consensus.Proposal)1 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)1 TimestampedECDSASignature (com.radixdlt.consensus.TimestampedECDSASignature)1 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)1 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)1 Vote (com.radixdlt.consensus.Vote)1