initial
}
/**
- * Defines the custom initialization function to be performed after common initialization of the caller and
- * listener nodes but before graph creation.
- *
- * For example, this could be used to turn on saving events for one or both of the node prior to any event creation.
+ * Defines the custom initialization function to be performed after common initialization of the caller and listener
+ * nodes but before graph creation.
+ *
+ * For example, this could be used to turn on saving events for one or both of the node prior to any event
+ * creation.
*
* @param customInitialization
*/
@@ -352,10 +366,10 @@ public void setCustomInitialization(final BiConsumer customI
}
/**
- * Defines a graph customization function to be performed after initial graph creation, but before {@link
- * SyncTestParams#getNumCallerEvents()} and {@link SyncTestParams#getNumListenerEvents()}
- * events are added to the caller and listener shadow graphs.
- *
+ * Defines a graph customization function to be performed after initial graph creation, but before
+ * {@link SyncTestParams#getNumCallerEvents()} and {@link SyncTestParams#getNumListenerEvents()} events are added to
+ * the caller and listener shadow graphs.
+ *
* For example, this method could be used to setup the sync nodes to partition for the remaining events.
*
* @param graphCustomization
@@ -384,9 +398,8 @@ public void setCallerAddToGraphTest(final Predicate callerAddToGra
}
/**
- * Defines a custom predicate that determines if listener events generated after the common events should be
- * added to
- * the caller's shadow graph.
+ * Defines a custom predicate that determines if listener events generated after the common events should be added
+ * to the caller's shadow graph.
*
* @param listenerAddToGraphTest
*/
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestParams.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestParams.java
index 3673002136b1..ddfb4a984f8b 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestParams.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestParams.java
@@ -17,6 +17,9 @@
package com.swirlds.platform.test.sync;
import com.swirlds.base.utility.ToStringBuilder;
+import com.swirlds.platform.event.AncientMode;
+import edu.umd.cs.findbugs.annotations.NonNull;
+import java.util.Objects;
/**
* Data holder for parameters needed for every sync unit test.
@@ -28,22 +31,30 @@ public class SyncTestParams {
private final int numCallerEvents;
private final int numListenerEvents;
private final Long customSeed;
+ private final AncientMode ancientMode;
public SyncTestParams(
- int numNetworkNodes, int numCommonEvents, int numCallerEvents, int numListenerEvents, Long customSeed) {
+ int numNetworkNodes,
+ int numCommonEvents,
+ int numCallerEvents,
+ int numListenerEvents,
+ Long customSeed,
+ @NonNull final AncientMode ancientMode) {
this.numNetworkNodes = numNetworkNodes;
this.numCommonEvents = numCommonEvents;
this.numCallerEvents = numCallerEvents;
this.numListenerEvents = numListenerEvents;
this.customSeed = customSeed;
+ this.ancientMode = Objects.requireNonNull(ancientMode);
}
public SyncTestParams(
final int numNetworkNodes,
final int numCommonEvents,
final int numCallerEvents,
- final int numListenerEvents) {
- this(numNetworkNodes, numCommonEvents, numCallerEvents, numListenerEvents, null);
+ final int numListenerEvents,
+ @NonNull final AncientMode ancientMode) {
+ this(numNetworkNodes, numCommonEvents, numCallerEvents, numListenerEvents, null, ancientMode);
}
/**
@@ -61,16 +72,16 @@ public int getNumCommonEvents() {
}
/**
- * The number of events to insert into the caller's shadow graph in addition to {@link
- * SyncTestParams#numCommonEvents}.
+ * The number of events to insert into the caller's shadow graph in addition to
+ * {@link SyncTestParams#numCommonEvents}.
*/
public int getNumCallerEvents() {
return numCallerEvents;
}
/**
- * The number of events to insert into the listener's shadow graph in addition to {@link
- * SyncTestParams#numCommonEvents}.
+ * The number of events to insert into the listener's shadow graph in addition to
+ * {@link SyncTestParams#numCommonEvents}.
*/
public int getNumListenerEvents() {
return numListenerEvents;
@@ -83,6 +94,13 @@ public Long getCustomSeed() {
return customSeed;
}
+ /**
+ * @return the ancient mode set for this test
+ */
+ public AncientMode getAncientMode() {
+ return ancientMode;
+ }
+
@Override
public String toString() {
return new ToStringBuilder(this)
@@ -91,6 +109,7 @@ public String toString() {
.append("numCallerEvents", numCallerEvents)
.append("numListenerEvents", numListenerEvents)
.append("customSeed", customSeed)
+ .append("ancientMode", ancientMode)
.toString();
}
}
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtils.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtils.java
index 3c6ec00d9a1c..fca5b6665055 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtils.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtils.java
@@ -17,9 +17,11 @@
package com.swirlds.platform.test.sync;
import com.swirlds.platform.EventStrings;
+import com.swirlds.platform.event.AncientMode;
import com.swirlds.platform.event.GossipEvent;
import com.swirlds.platform.gossip.shadowgraph.ShadowEvent;
import com.swirlds.platform.internal.EventImpl;
+import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -41,19 +43,19 @@ public static void printTipSet(final String nodeName, final SyncNode node) {
node.getShadowGraph().getTips().forEach(tip -> System.out.println(EventStrings.toMediumString(tip.getEvent())));
}
- public static long getMaxGen(final List tips) {
- long maxGen = 0;
- for (ShadowEvent tip : tips) {
- maxGen = Math.max(tip.getEvent().getGeneration(), maxGen);
+ public static long getMaxIndicator(final List tips, @NonNull final AncientMode ancientMode) {
+ long maxIndicator = ancientMode.getGenesisIndicator();
+ for (final ShadowEvent tip : tips) {
+ maxIndicator = Math.max(tip.getEvent().getBaseEvent().getAncientIndicator(ancientMode), maxIndicator);
}
- return maxGen;
+ return maxIndicator;
}
- public static long getMinGen(final Set events) {
- long minGen = Long.MAX_VALUE;
- for (ShadowEvent event : events) {
- minGen = Math.min(event.getEvent().getGeneration(), minGen);
+ public static long getMinIndicator(@NonNull final Set events, @NonNull final AncientMode ancientMode) {
+ long minIndicator = Long.MAX_VALUE;
+ for (final ShadowEvent event : events) {
+ minIndicator = Math.min(event.getEvent().getBaseEvent().getAncientIndicator(ancientMode), minIndicator);
}
- return minGen == Long.MAX_VALUE ? 0 : minGen;
+ return minIndicator == Long.MAX_VALUE ? ancientMode.getGenesisIndicator() : minIndicator;
}
}
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtilsTest.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtilsTest.java
index 92784df33303..81279b370971 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtilsTest.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTestUtilsTest.java
@@ -16,11 +16,11 @@
package com.swirlds.platform.test.sync;
+import static com.swirlds.platform.event.AncientMode.GENERATION_THRESHOLD;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.swirlds.platform.consensus.GraphGenerations;
-import com.swirlds.platform.gossip.shadowgraph.Generations;
+import com.swirlds.platform.consensus.NonAncientEventWindow;
import com.swirlds.platform.gossip.shadowgraph.ShadowEvent;
import com.swirlds.platform.gossip.shadowgraph.SyncUtils;
import java.util.HashSet;
@@ -55,10 +55,10 @@ void testUnknownNonAncient() {
knownSet.add(e3);
knownSet.add(e1);
- final GraphGenerations generations = new Generations(0, 1, 3);
+ final NonAncientEventWindow eventWindow = new NonAncientEventWindow(0, 1, 0, GENERATION_THRESHOLD);
final Predicate unknownNonAncient =
- SyncUtils.unknownNonAncient(knownSet, generations, generations);
+ SyncUtils.unknownNonAncient(knownSet, eventWindow, eventWindow, GENERATION_THRESHOLD);
assertFalse(unknownNonAncient.test(e1), "e1 is both ancient and known, should be false");
assertFalse(unknownNonAncient.test(e2), "e2 is ancient, should be false");
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTests.java
index 06de480d10c0..7e23542e0b2f 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTests.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncTests.java
@@ -19,6 +19,8 @@
import static com.swirlds.common.test.fixtures.io.ResourceLoader.loadLog4jContext;
import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager;
import static com.swirlds.common.utility.CompareTo.max;
+import static com.swirlds.platform.consensus.ConsensusConstants.ROUND_FIRST;
+import static com.swirlds.platform.event.AncientMode.BIRTH_ROUND_THRESHOLD;
import static com.swirlds.platform.event.AncientMode.GENERATION_THRESHOLD;
import static com.swirlds.platform.test.fixtures.event.EventUtils.integerPowerDistribution;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -26,7 +28,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.Mockito.when;
import com.swirlds.common.constructable.ConstructableRegistry;
import com.swirlds.common.constructable.ConstructableRegistryException;
@@ -37,10 +38,9 @@
import com.swirlds.common.threading.pool.ParallelExecutionException;
import com.swirlds.common.threading.pool.ParallelExecutor;
import com.swirlds.config.extensions.test.fixtures.TestConfigBuilder;
-import com.swirlds.platform.consensus.GraphGenerations;
import com.swirlds.platform.consensus.NonAncientEventWindow;
+import com.swirlds.platform.event.AncientMode;
import com.swirlds.platform.gossip.shadowgraph.ShadowEvent;
-import com.swirlds.platform.internal.EventImpl;
import com.swirlds.platform.system.events.EventConstants;
import com.swirlds.platform.test.event.emitter.EventEmitterFactory;
import com.swirlds.platform.test.event.emitter.StandardEventEmitter;
@@ -50,6 +50,7 @@
import com.swirlds.platform.test.graph.OtherParentMatrixFactory;
import com.swirlds.platform.test.graph.PartitionedGraphCreator;
import com.swirlds.platform.test.graph.SplitForkGraphCreator;
+import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.FileNotFoundException;
import java.net.SocketException;
import java.util.List;
@@ -60,9 +61,7 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -72,25 +71,38 @@ public class SyncTests {
private static final boolean platformLoggingEnabled = true;
+ private static Stream bothAncientModes() {
+ return Stream.of(Arguments.of(GENERATION_THRESHOLD), Arguments.of(BIRTH_ROUND_THRESHOLD));
+ }
+
private static Stream fourNodeGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(4, 100, 20, 0)),
- Arguments.of(new SyncTestParams(4, 100, 0, 20)),
- Arguments.of(new SyncTestParams(4, 100, 20, 20)));
+ Arguments.of(new SyncTestParams(4, 100, 20, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 0, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 0, 20, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, BIRTH_ROUND_THRESHOLD)));
}
private static Stream tenNodeGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 100, 50, 0)),
- Arguments.of(new SyncTestParams(10, 100, 0, 50)),
- Arguments.of(new SyncTestParams(10, 100, 50, 50)));
+ Arguments.of(new SyncTestParams(10, 100, 50, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD)));
}
private static Stream tenNodeBigGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 1000, 2000, 0)),
- Arguments.of(new SyncTestParams(10, 1000, 0, 2000)),
- Arguments.of(new SyncTestParams(10, 1000, 2000, 2000)));
+ Arguments.of(new SyncTestParams(10, 1000, 2000, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 0, 2000, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 2000, 2000, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 2000, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 0, 2000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 2000, 2000, BIRTH_ROUND_THRESHOLD)));
}
/**
@@ -98,11 +110,16 @@ private static Stream tenNodeBigGraphParams() {
*/
private static Stream simpleFourNodeGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(4, 10, 0, 0)),
- Arguments.of(new SyncTestParams(4, 10, 1, 0)),
- Arguments.of(new SyncTestParams(4, 10, 0, 1)),
- Arguments.of(new SyncTestParams(4, 10, 1, 1)),
- Arguments.of(new SyncTestParams(4, 10, 8, 1)));
+ Arguments.of(new SyncTestParams(4, 10, 0, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 0, 1, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 1, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 8, 1, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 0, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 0, 1, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 1, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 8, 1, BIRTH_ROUND_THRESHOLD)));
}
/**
@@ -110,10 +127,14 @@ private static Stream simpleFourNodeGraphParams() {
*/
private static Stream edgeCaseGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 0, 20, 0)),
- Arguments.of(new SyncTestParams(10, 0, 0, 20)),
- Arguments.of(new SyncTestParams(10, 0, 0, 0)),
- Arguments.of(new SyncTestParams(10, 20, 0, 0)));
+ Arguments.of(new SyncTestParams(10, 0, 20, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 20, 0, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 20, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 20, 0, 0, BIRTH_ROUND_THRESHOLD)));
}
/**
@@ -122,15 +143,25 @@ private static Stream edgeCaseGraphParams() {
private static Stream partitionedGraphParams() {
return Stream.of(
// Partitioned graphs with common events
- Arguments.of(new SyncTestParams(10, 30, 5, 5)),
- Arguments.of(new SyncTestParams(10, 30, 5, 5)),
- Arguments.of(new SyncTestParams(20, 200, 100, 0)),
- Arguments.of(new SyncTestParams(20, 200, 0, 100)),
- Arguments.of(new SyncTestParams(20, 200, 100, 100)),
+ Arguments.of(new SyncTestParams(10, 30, 5, 5, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 30, 5, 5, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 100, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 0, 100, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 100, 100, GENERATION_THRESHOLD)),
+ // Partitioned graphs with no common events
+ Arguments.of(new SyncTestParams(20, 0, 100, 0, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 0, 0, 100, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 0, 100, 100, GENERATION_THRESHOLD)),
+ // Partitioned graphs with common events
+ Arguments.of(new SyncTestParams(10, 30, 5, 5, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 30, 5, 5, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 100, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 0, 100, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 200, 100, 100, BIRTH_ROUND_THRESHOLD)),
// Partitioned graphs with no common events
- Arguments.of(new SyncTestParams(20, 0, 100, 0)),
- Arguments.of(new SyncTestParams(20, 0, 0, 100)),
- Arguments.of(new SyncTestParams(20, 0, 100, 100)));
+ Arguments.of(new SyncTestParams(20, 0, 100, 0, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 0, 0, 100, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(20, 0, 100, 100, BIRTH_ROUND_THRESHOLD)));
}
/**
@@ -139,25 +170,40 @@ private static Stream partitionedGraphParams() {
*/
private static Stream exceptionParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 1, 1),
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 1, 2),
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 2, 1),
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 2, 2),
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 3, 1),
- Arguments.of(new SyncTestParams(10, 100, 50, 50), 3, 2));
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 1, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 1, 2),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 2, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 2, 2),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 3, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD), 3, 2),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 1, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 1, 2),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 2, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 2, 2),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 3, 1),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD), 3, 2));
}
private static Stream splitForkParams() {
return Stream.of(
// This seed makes the caller send the whole graph, should not be the case once we change the tip
// definition
- Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L)),
- Arguments.of(new SyncTestParams(4, 100, 20, 1)),
- Arguments.of(new SyncTestParams(4, 100, 1, 20)),
- Arguments.of(new SyncTestParams(4, 100, 20, 20)),
- Arguments.of(new SyncTestParams(10, 100, 50, 50)),
- Arguments.of(new SyncTestParams(10, 100, 100, 50)),
- Arguments.of(new SyncTestParams(10, 100, 50, 100)));
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 1, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 100, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 100, GENERATION_THRESHOLD)),
+ // This seed makes the caller send the whole graph, should not be the case once we change the tip
+ // definition
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 1, 20, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 100, 50, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 100, BIRTH_ROUND_THRESHOLD)));
}
private static Stream splitForkParamsBreakingSeed() {
@@ -165,56 +211,82 @@ private static Stream splitForkParamsBreakingSeed() {
// This seed used to make the caller send the whole graph back when the definition of a tip was an
// event with no children (self or other). Now that the definition of a tip is an event with no
// self-child, this seed passes.
- Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L)));
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 1, 4956163591276672768L, BIRTH_ROUND_THRESHOLD)));
}
private static Stream largeGraphParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 1000, 500, 200)),
- Arguments.of(new SyncTestParams(10, 1000, 200, 500)),
- Arguments.of(new SyncTestParams(10, 1000, 500, 500)));
+ Arguments.of(new SyncTestParams(10, 1000, 500, 200, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 200, 500, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 500, 500, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 500, 200, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 200, 500, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 1000, 500, 500, BIRTH_ROUND_THRESHOLD)));
}
private static Stream noCommonEventsParams() {
return Stream.of(
- Arguments.of(new SyncTestParams(4, 0, 50, 20)),
- Arguments.of(new SyncTestParams(4, 0, 20, 50)),
- Arguments.of(new SyncTestParams(4, 0, 50, 50)),
- Arguments.of(new SyncTestParams(10, 0, 500, 200)),
- Arguments.of(new SyncTestParams(10, 0, 200, 500)),
- Arguments.of(new SyncTestParams(10, 0, 500, 500)));
+ Arguments.of(new SyncTestParams(4, 0, 50, 20, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 0, 20, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 0, 50, 50, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 500, 200, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 200, 500, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 500, 500, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 0, 50, 20, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 0, 20, 50, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 0, 50, 50, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 500, 200, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 200, 500, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 500, 500, BIRTH_ROUND_THRESHOLD)));
}
private static Stream tipsChangeBreakingSeed() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 0, 20, 0, 6238590233436833292L)),
- Arguments.of(new SyncTestParams(4, 10, 8, 1, 8824331216639179768L)),
- Arguments.of(new SyncTestParams(10, 0, 0, 20, -909134053413382981L)),
- Arguments.of(new SyncTestParams(10, 0, 0, 20, 5236225801504915258L)),
- Arguments.of(new SyncTestParams(4, 10, 1, 1, -3204404663467002969L)),
- Arguments.of(new SyncTestParams(10, 0, 0, 20, -4776092416980912346L)));
+ Arguments.of(new SyncTestParams(10, 0, 20, 0, 6238590233436833292L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 8, 1, 8824331216639179768L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, -909134053413382981L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, 5236225801504915258L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 1, -3204404663467002969L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, -4776092416980912346L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 20, 0, 6238590233436833292L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 8, 1, 8824331216639179768L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, -909134053413382981L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, 5236225801504915258L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 10, 1, 1, -3204404663467002969L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 0, 0, 20, -4776092416980912346L, BIRTH_ROUND_THRESHOLD)));
}
private static Stream simpleGraphBreakingSeed() {
return Stream.of(
- Arguments.of(new SyncTestParams(4, 100, 20, 20, -5979073137457357235L)),
- Arguments.of(new SyncTestParams(10, 100, 50, 50, 1861589538493329478L)));
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, -5979073137457357235L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, 1861589538493329478L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(4, 100, 20, 20, -5979073137457357235L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 50, 50, 1861589538493329478L, BIRTH_ROUND_THRESHOLD)));
}
private static Stream tipExpiresBreakingSeed() {
return Stream.of(
- Arguments.of(new SyncTestParams(10, 100, 0, 50, 1152284535185134815L)),
- Arguments.of(new SyncTestParams(10, 100, 0, 50, -8664085824668001150L)));
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, 1152284535185134815L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, -8664085824668001150L, GENERATION_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, 1152284535185134815L, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(new SyncTestParams(10, 100, 0, 50, -8664085824668001150L, BIRTH_ROUND_THRESHOLD)));
}
private static Stream requiredEventsExpire() {
return Stream.of(
- Arguments.of(1, new SyncTestParams(10, 100, 0, 1000)),
- Arguments.of(1, new SyncTestParams(10, 200, 100, 1000)),
- Arguments.of(1, new SyncTestParams(10, 200, 200, 1000)),
- Arguments.of(2, new SyncTestParams(10, 100, 0, 1000)),
- Arguments.of(2, new SyncTestParams(10, 200, 100, 1000)),
- Arguments.of(2, new SyncTestParams(10, 200, 200, 1000)));
+ Arguments.of(1, new SyncTestParams(10, 100, 0, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(1, new SyncTestParams(10, 200, 100, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(1, new SyncTestParams(10, 200, 200, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 100, 0, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 200, 100, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 200, 200, 1000, GENERATION_THRESHOLD)),
+ Arguments.of(1, new SyncTestParams(10, 100, 0, 1000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(1, new SyncTestParams(10, 200, 100, 1000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(1, new SyncTestParams(10, 200, 200, 1000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 100, 0, 1000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 200, 100, 1000, BIRTH_ROUND_THRESHOLD)),
+ Arguments.of(2, new SyncTestParams(10, 200, 200, 1000, BIRTH_ROUND_THRESHOLD)));
}
@BeforeAll
@@ -249,7 +321,8 @@ void simpleGraph(final SyncTestParams params) throws Exception {
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -264,13 +337,12 @@ void skipInit(final SyncTestParams params) throws Exception {
executor.setGraphCustomization((caller, listener) -> {
caller.setSaveGeneratedEvents(true);
listener.setSaveGeneratedEvents(true);
- caller.setSendRecInitBytes(false);
- listener.setSendRecInitBytes(false);
});
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -282,16 +354,20 @@ void skipInit(final SyncTestParams params) throws Exception {
void forkingGraph(final SyncTestParams params) throws Exception {
final SyncTestExecutor executor = new SyncTestExecutor(params);
- executor.setCallerSupplier(
- (factory) -> new SyncNode(params.getNumNetworkNodes(), 0, factory.newForkingShuffledGenerator()));
+ executor.setCallerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(), 0, factory.newForkingShuffledGenerator(), params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
- params.getNumNetworkNodes(), params.getNumNetworkNodes() - 1, factory.newForkingShuffledGenerator()));
+ params.getNumNetworkNodes(),
+ params.getNumNetworkNodes() - 1,
+ factory.newForkingShuffledGenerator(),
+ params.getAncientMode()));
executor.execute();
// Some extra events could be transferred in the case of a split fork graph. This is explicitly tested in
// splitForkGraph()
- SyncValidator.assertRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -307,10 +383,13 @@ void splitForkGraph(final SyncTestParams params) throws Exception {
final int callerOtherParent = 1;
final int listenerOtherParent = 2;
- executor.setCallerSupplier(
- (factory) -> new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter()));
+ executor.setCallerSupplier((factory) ->
+ new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter(), params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
- params.getNumNetworkNodes(), params.getNumNetworkNodes() - 1, factory.newStandardEmitter()));
+ params.getNumNetworkNodes(),
+ params.getNumNetworkNodes() - 1,
+ factory.newStandardEmitter(),
+ params.getAncientMode()));
executor.setInitialGraphCreation((caller, listener) -> {
caller.generateAndAdd(params.getNumCommonEvents());
@@ -332,7 +411,8 @@ void splitForkGraph(final SyncTestParams params) throws Exception {
// In split fork graphs, some extra events will be sent because each node has a different tip for the same
// creator, causing each to think the other does not have any ancestors of that creator's event when they in
// fact do.
- SyncValidator.assertRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -352,10 +432,13 @@ void partitionedGraph(final SyncTestParams params) throws Exception {
.boxed()
.collect(Collectors.toList());
- executor.setCallerSupplier(
- (factory) -> new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter()));
+ executor.setCallerSupplier((factory) ->
+ new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter(), params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
- params.getNumNetworkNodes(), params.getNumNetworkNodes() - 1, factory.newStandardEmitter()));
+ params.getNumNetworkNodes(),
+ params.getNumNetworkNodes() - 1,
+ factory.newStandardEmitter(),
+ params.getAncientMode()));
executor.setInitialGraphCreation((caller, listener) -> {
caller.generateAndAdd(params.getNumCommonEvents());
@@ -372,23 +455,8 @@ void partitionedGraph(final SyncTestParams params) throws Exception {
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
- SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
- }
-
- /**
- * Test a sync where the listener rejects the sync.
- */
- @ParameterizedTest
- @MethodSource({"simpleFourNodeGraphParams", "fourNodeGraphParams", "tenNodeGraphParams", "edgeCaseGraphParams"})
- void testSyncRejected(final SyncTestParams params) throws Exception {
- final SyncTestExecutor executor = new SyncTestExecutor(params);
-
- executor.setCustomInitialization((caller, listener) -> listener.setCanAcceptSync(false));
-
- executor.execute();
-
- SyncValidator.assertNoEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -406,13 +474,14 @@ void testNoBooleansReceived(final SyncTestParams params) {
listenerExecutor.start();
// Setup parallel executors
- executor.setCallerSupplier((factory) ->
- new SyncNode(params.getNumNetworkNodes(), 0, factory.newShuffledEmitter(), callerExecutor));
+ executor.setCallerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(), 0, factory.newShuffledEmitter(), callerExecutor, params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
params.getNumNetworkNodes(),
params.getNumNetworkNodes() - 1,
factory.newShuffledEmitter(),
- listenerExecutor));
+ listenerExecutor,
+ params.getAncientMode()));
assertThrows(ParallelExecutionException.class, executor::execute, "Unexpected exception during sync.");
@@ -437,8 +506,8 @@ void testCallerExceptionDuringSyncPhase(final SyncTestParams params, final int p
throw new SocketException();
});
- executor.setCallerSupplier((factory) ->
- new SyncNode(params.getNumNetworkNodes(), 0, factory.newShuffledEmitter(), callerExecutor));
+ executor.setCallerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(), 0, factory.newShuffledEmitter(), callerExecutor, params.getAncientMode()));
runExceptionDuringSyncPhase(phaseToThrowIn, taskNum, executor);
}
@@ -460,8 +529,12 @@ void testListenerExceptionDuringSyncPhase(final SyncTestParams params, final int
throw new SocketException();
});
- executor.setListenerSupplier((factory) ->
- new SyncNode(params.getNumNetworkNodes(), 0, factory.newShuffledEmitter(), listenerExecutor));
+ executor.setListenerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(),
+ 0,
+ factory.newShuffledEmitter(),
+ listenerExecutor,
+ params.getAncientMode()));
runExceptionDuringSyncPhase(phaseToThrowIn, taskNum, executor);
}
@@ -527,62 +600,80 @@ void testUnknownCreator(final SyncTestParams params) throws Exception {
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
}
/**
* Tests fallen behind detection works
*/
- @Test
- void fallenBehind() throws Exception {
- final SyncTestParams params = new SyncTestParams(4, 100, 20, 20);
+ @ParameterizedTest
+ @MethodSource("bothAncientModes")
+ void fallenBehind(@NonNull final AncientMode ancientMode) throws Exception {
+ final SyncTestParams params = new SyncTestParams(4, 100, 20, 20, ancientMode);
- final long callerMinGen = 100;
- final long callerMaxGen = 200;
- final long listenerMinGen = 300;
- final long listenerMaxGen = 400;
+ final long callerExpiredThreshold = 100;
+ final long callerMaximumIndicator = 200;
+ final long listenerExpiredThreshold = 300;
+ final long listenerMaximumIndicator = 400;
- runFallenBehindTest(params, callerMinGen, callerMaxGen, listenerMinGen, listenerMaxGen);
+ runFallenBehindTest(
+ params,
+ callerExpiredThreshold,
+ callerMaximumIndicator,
+ listenerExpiredThreshold,
+ listenerMaximumIndicator);
}
/**
* Tests fallen behind detection works with one node at genesis
*/
- @Test
- void fallenBehindAtGenesis() throws Exception {
- final SyncTestParams params = new SyncTestParams(4, 0, 1, 100);
+ @ParameterizedTest
+ @MethodSource("bothAncientModes")
+ void fallenBehindAtGenesis(@NonNull final AncientMode ancientMode) throws Exception {
+ final SyncTestParams params = new SyncTestParams(4, 0, 1, 100, ancientMode);
- final long callerMinGen = GraphGenerations.FIRST_GENERATION;
- final long callerMaxGen = GraphGenerations.FIRST_GENERATION;
- final long listenerMinGen = 200;
- final long listenerMaxGen = 300;
+ final long callerExpiredThreshold = ancientMode.getGenesisIndicator();
+ final long callerMaximumIndicator = ancientMode.getGenesisIndicator();
+ final long listenerAncientThreshold = 200;
+ final long listenerMaximumIndicator = 300;
- runFallenBehindTest(params, callerMinGen, callerMaxGen, listenerMinGen, listenerMaxGen);
+ runFallenBehindTest(
+ params,
+ callerExpiredThreshold,
+ callerMaximumIndicator,
+ listenerAncientThreshold,
+ listenerMaximumIndicator);
}
private void runFallenBehindTest(
final SyncTestParams params,
- final long callerMinGen,
- final long callerMaxGen,
- final long listenerMinGen,
- final long listenerMaxGen)
+ final long callerExpiredThreshold,
+ final long callerMaximumIndicator,
+ final long listenerExpiredThreshold,
+ final long listenerMaximumIndicator)
throws Exception {
- assertTrue(callerMinGen <= callerMaxGen, "Caller generations provided do not represent a fallen behind node.");
assertTrue(
- listenerMinGen <= listenerMaxGen,
- "Listener generations provided do not represent a fallen behind node.");
+ callerExpiredThreshold <= callerMaximumIndicator,
+ "Caller event window provided does not represent a fallen behind node.");
+ assertTrue(
+ listenerExpiredThreshold <= listenerMaximumIndicator,
+ "Listener event window provided does not represent a fallen behind node.");
assertTrue(
- callerMaxGen < listenerMinGen || listenerMaxGen < callerMinGen,
- "Generations provided do not represent a fallen behind node.");
+ callerMaximumIndicator < listenerExpiredThreshold || listenerMaximumIndicator < callerExpiredThreshold,
+ "Event window provided does not represent a fallen behind node.");
- final boolean callerFallenBehind = callerMaxGen < listenerMinGen;
+ final boolean callerFallenBehind = callerMaximumIndicator < listenerExpiredThreshold;
final SyncTestExecutor executor = new SyncTestExecutor(params);
- executor.setCallerSupplier(
- (factory) -> new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter()));
+ executor.setCallerSupplier((factory) ->
+ new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardEmitter(), params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
- params.getNumNetworkNodes(), params.getNumNetworkNodes() - 1, factory.newStandardEmitter()));
+ params.getNumNetworkNodes(),
+ params.getNumNetworkNodes() - 1,
+ factory.newStandardEmitter(),
+ params.getAncientMode()));
executor.setInitialGraphCreation((caller, listener) -> {
caller.setSaveGeneratedEvents(true);
@@ -590,21 +681,17 @@ private void runFallenBehindTest(
});
executor.setCustomPreSyncConfiguration((c, l) -> {
- when(c.getConsensus().getMinGenerationNonAncient()).thenReturn(callerMinGen);
- when(c.getConsensus().getMaxRoundGeneration()).thenReturn(callerMaxGen);
c.getShadowGraph()
- .updateNonExpiredEventWindow(new NonAncientEventWindow(
+ .updateEventWindow(new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- 0 /* ignored by shadowgraph */,
- callerMinGen,
+ callerMaximumIndicator,
+ callerExpiredThreshold,
GENERATION_THRESHOLD));
- when(l.getConsensus().getMinGenerationNonAncient()).thenReturn(listenerMinGen);
- when(l.getConsensus().getMaxRoundGeneration()).thenReturn(listenerMaxGen);
l.getShadowGraph()
- .updateNonExpiredEventWindow(new NonAncientEventWindow(
- 0 /* ignored by shadowgraph */,
+ .updateEventWindow(new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- listenerMinGen,
+ listenerMaximumIndicator,
+ listenerExpiredThreshold,
GENERATION_THRESHOLD));
});
@@ -618,53 +705,70 @@ private void runFallenBehindTest(
SyncValidator.assertNoEventsReceived("caller", executor.getCaller());
}
- @Test
- void testBarelyNotFallenBehind() throws Exception {
- final SyncTestParams params = new SyncTestParams(4, 200, 200, 0);
+ @ParameterizedTest
+ @MethodSource("bothAncientModes")
+ void testBarelyNotFallenBehind(@NonNull final AncientMode ancientMode) throws Exception {
+ final SyncTestParams params = new SyncTestParams(4, 200, 200, 0, ancientMode);
final SyncTestExecutor executor = new SyncTestExecutor(params);
- executor.setGenerationDefinitions((caller, listener) -> {
- long listenerMaxGen =
- SyncTestUtils.getMaxGen(listener.getShadowGraph().getTips());
- // make the min non-ancient gen slightly below the max gen
- long listenerMinNonAncient = listenerMaxGen - (listenerMaxGen / 10);
- long listenerMinGen = SyncTestUtils.getMinGen(listener.getShadowGraph()
- .findAncestors(listener.getShadowGraph().getTips(), (e) -> true));
-
- // Expire everything below the listener's min non-ancient gen on the caller
- // so that the listener's maxGen == caller's min non-ancient gen
- caller.expireBelow(listenerMinNonAncient);
-
- long callerMaxGen = SyncTestUtils.getMaxGen(caller.getShadowGraph().getTips());
- // make the min non-ancient gen slightly below the max gen
- long callerMinNonAncient = callerMaxGen - (callerMaxGen / 10);
- long callerMinGen = SyncTestUtils.getMinGen(caller.getShadowGraph()
- .findAncestors(caller.getShadowGraph().getTips(), (e) -> true));
-
- assertEquals(listenerMinNonAncient, callerMinGen, "listener max gen and caller min gen should be equal.");
-
- when(listener.getConsensus().getMaxRoundGeneration()).thenReturn(listenerMaxGen);
- when(listener.getConsensus().getMinGenerationNonAncient()).thenReturn(listenerMinNonAncient);
- when(listener.getConsensus().getMinRoundGeneration()).thenReturn(listenerMinGen);
- when(caller.getConsensus().getMaxRoundGeneration()).thenReturn(callerMaxGen);
- when(caller.getConsensus().getMinGenerationNonAncient()).thenReturn(callerMinNonAncient);
- when(caller.getConsensus().getMinRoundGeneration()).thenReturn(callerMinGen);
+ executor.setEventWindowDefinitions((caller, listener) -> {
+ long listenerMaxIndicator =
+ SyncTestUtils.getMaxIndicator(listener.getShadowGraph().getTips(), ancientMode);
+ // make the min non-ancient indicator slightly below the max indicator
+ long listenerNonAncientThreshold = listenerMaxIndicator - (listenerMaxIndicator / 10);
+ long listenerMinIndicator = SyncTestUtils.getMinIndicator(
+ listener.getShadowGraph()
+ .findAncestors(listener.getShadowGraph().getTips(), (e) -> true),
+ ancientMode);
+
+ // Expire everything below the listener's min non-ancient indicator on the caller
+ // so that the listener's maxIndicator == caller's min non-ancient indicator
+ caller.expireBelow(listenerNonAncientThreshold);
+
+ long callerMaxIndicator =
+ SyncTestUtils.getMaxIndicator(caller.getShadowGraph().getTips(), ancientMode);
+ // make the min non-ancient indicator slightly below the max indicator
+ long callerNonAncientThreshold = callerMaxIndicator - (callerMaxIndicator / 10);
+ long callerMinIndicator = SyncTestUtils.getMinIndicator(
+ caller.getShadowGraph()
+ .findAncestors(caller.getShadowGraph().getTips(), (e) -> true),
+ ancientMode);
+
+ assertEquals(
+ listenerNonAncientThreshold,
+ callerMinIndicator,
+ "listener max indicator and caller min indicator should be equal.");
+
+ listener.getShadowGraph()
+ .updateEventWindow(new NonAncientEventWindow(
+ ROUND_FIRST /* ignored */,
+ Math.max(ancientMode.getGenesisIndicator(), listenerNonAncientThreshold),
+ Math.max(ancientMode.getGenesisIndicator(), listenerMinIndicator),
+ ancientMode));
+
+ caller.getShadowGraph()
+ .updateEventWindow(new NonAncientEventWindow(
+ ROUND_FIRST /* ignored */,
+ Math.max(ancientMode.getGenesisIndicator(), callerNonAncientThreshold),
+ Math.max(ancientMode.getGenesisIndicator(), callerMinIndicator),
+ ancientMode));
});
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener(), ancientMode);
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
/**
* Verifies that even if events are expired right before sending, they are still sent.
*/
- @Test
- void testSendExpiredEvents() throws Exception {
- final SyncTestParams params = new SyncTestParams(4, 20, 10, 0);
+ @ParameterizedTest
+ @MethodSource("bothAncientModes")
+ void testSendExpiredEvents(@NonNull final AncientMode ancientMode) throws Exception {
+ final SyncTestParams params = new SyncTestParams(4, 20, 10, 0, ancientMode);
final SyncTestExecutor executor = new SyncTestExecutor(params);
- final AtomicLong genToExpire = new AtomicLong(EventConstants.GENERATION_UNDEFINED);
+ final AtomicLong indicatorToExpire = new AtomicLong(ancientMode.getGenesisIndicator() - 1);
// before phase 3, expire all events so that expired events are sent
executor.setCallerExecutorSupplier(() -> new SyncPhaseParallelExecutor(
@@ -681,20 +785,20 @@ void testSendExpiredEvents() throws Exception {
// Expire the events from the shadow graph
final NonAncientEventWindow eventWindow = new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- 0 /* ignored by shadowgraph */,
- genToExpire.get() + 1,
- GENERATION_THRESHOLD);
- executor.getCaller().getShadowGraph().updateNonExpiredEventWindow(eventWindow);
+ ancientMode.getGenesisIndicator(),
+ indicatorToExpire.get() + 1,
+ ancientMode);
+ executor.getCaller().getShadowGraph().updateEventWindow(eventWindow);
},
false));
- // we save the max generation of node 0, so we know what we need to expire to remove a tip
- executor.setCustomPreSyncConfiguration((caller, listener) ->
- genToExpire.set(SyncTestUtils.getMaxGen(caller.getShadowGraph().getTips())));
+ // we save the max indicator of node 0, so we know what we need to expire to remove a tip
+ executor.setCustomPreSyncConfiguration((caller, listener) -> indicatorToExpire.set(
+ SyncTestUtils.getMaxIndicator(caller.getShadowGraph().getTips(), ancientMode)));
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener(), ancientMode);
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -705,7 +809,7 @@ void testSendExpiredEvents() throws Exception {
@MethodSource({"tenNodeGraphParams", "tenNodeBigGraphParams", "tipExpiresBreakingSeed"})
void tipExpiresAfterPhase1(final SyncTestParams params) throws Exception {
final SyncTestExecutor executor = new SyncTestExecutor(params);
- final AtomicLong maxGen = new AtomicLong(EventConstants.GENERATION_UNDEFINED);
+ final AtomicLong maximumIndicator = new AtomicLong(EventConstants.GENERATION_UNDEFINED);
final int creatorIndexToExpire = 0;
final NodeId creatorIdToExpire = executor.getAddressBook().getNodeId(creatorIndexToExpire);
@@ -724,52 +828,49 @@ void tipExpiresAfterPhase1(final SyncTestParams params) throws Exception {
return source0;
}));
- // we save the max generation of node 0, so we know what we need to expire to remove a tip
+ // we save the max indicator of node 0, so we know what we need to expire to remove a tip
executor.setGraphCustomization((caller, listener) -> {
caller.setSaveGeneratedEvents(true);
listener.setSaveGeneratedEvents(true);
- maxGen.set(caller.getEmitter().getGraphGenerator().getMaxGeneration(creatorIdToExpire));
+ // As a hack, birth round is equal to generation + 1
+ maximumIndicator.set(caller.getEmitter().getGraphGenerator().getMaxGeneration(creatorIdToExpire)
+ + (params.getAncientMode() == BIRTH_ROUND_THRESHOLD ? 1 : 0));
});
// before the sync, expire the tip on the listener
executor.setCustomPreSyncConfiguration((c, l) -> {
l.getShadowGraph()
- .updateNonExpiredEventWindow(new NonAncientEventWindow(
- 0 /* ignored by shadowgraph */,
- 0 /* ignored by shadowgraph */,
- maxGen.get() + 1,
- GENERATION_THRESHOLD));
- when(l.getConsensus().getMinGenerationNonAncient()).thenReturn(maxGen.get() + 2);
- when(l.getConsensus().getMaxRoundGeneration()).thenReturn(maxGen.get() + 3);
-
- c.getShadowGraph()
- .updateNonExpiredEventWindow(new NonAncientEventWindow(
- 0 /* ignored by shadowgraph */,
+ .updateEventWindow(new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- max(EventConstants.FIRST_GENERATION, maxGen.get() - 1),
- GENERATION_THRESHOLD));
- when(c.getConsensus().getMinGenerationNonAncient()).thenReturn(maxGen.get() + 2);
- when(c.getConsensus().getMaxRoundGeneration()).thenReturn(maxGen.get() + 3);
+ maximumIndicator.get() + 2,
+ maximumIndicator.get() + 1,
+ params.getAncientMode()));
+
+ c.updateEventWindow(new NonAncientEventWindow(
+ 0 /* ignored by shadowgraph */,
+ maximumIndicator.get() + 2,
+ max(params.getAncientMode().getGenesisIndicator(), maximumIndicator.get() - 1),
+ params.getAncientMode()));
});
// after phase 1, expire the tip on the caller
final SyncPhaseParallelExecutor parallelExecutor = new SyncPhaseParallelExecutor(
getStaticThreadManager(),
() -> executor.getCaller()
- .getShadowGraph()
- .updateNonExpiredEventWindow(new NonAncientEventWindow(
- 0 /* ignored by shadowgraph */,
+ .updateEventWindow(new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- maxGen.get() + 1,
- GENERATION_THRESHOLD)),
+ params.getAncientMode().getGenesisIndicator(),
+ maximumIndicator.get() + 1,
+ params.getAncientMode())),
null,
true);
executor.setExecutorSupplier(() -> parallelExecutor);
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -806,7 +907,8 @@ void tipsChangeAfterPhase1(final SyncTestParams params) throws Exception {
// since we get a new set of tips before phase 3, it is possible to transfer some duplicate events that were
// added after the initial tips were exchanged
- SyncValidator.assertRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -843,13 +945,15 @@ void tipsChangeAfterPhase2(final SyncTestParams params) throws Exception {
// since we get a new set of tips before phase 3, it is possible to transfer some duplicate events that were
// added after the initial tips were exchanged
- SyncValidator.assertRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
/**
* Tests scenarios in which events that need to be sent to the peer are requested to be expired before they are
- * sent. Because generations are reserved in a sync, the events should not be expired while a sync is in progress.
+ * sent. Because ancient indicators are reserved in a sync, the events should not be expired while a sync is in
+ * progress.
*
* @param expireAfterPhase the phase after which events that need to be sent should be requested to be expired
* @param params Sync parameters
@@ -858,24 +962,25 @@ void tipsChangeAfterPhase2(final SyncTestParams params) throws Exception {
@MethodSource("requiredEventsExpire")
void requiredEventsExpire(final int expireAfterPhase, final SyncTestParams params) throws Exception {
final SyncTestExecutor executor = new SyncTestExecutor(params);
- final AtomicLong genToExpire = new AtomicLong(0);
+ final AtomicLong indicatorToExpire = new AtomicLong(0);
final NodeId creatorId = executor.getAddressBook().getNodeId(0);
- // Set the generation to expire such that half the listener's graph, and therefore some events that need
- // to be sent to the caller, will be expired
- executor.setCustomPreSyncConfiguration(
- (c, l) -> genToExpire.set(l.getEmitter().getGraphGenerator().getMaxGeneration(creatorId) / 2));
+ // Set the indicator to expire such that half the listener's graph, and therefore some events that need
+ // to be sent to the caller, will be expired. Since we are hacking birth rounds to be the same as generations,
+ // we can use the same indicator for both.
+ executor.setCustomPreSyncConfiguration((c, l) ->
+ indicatorToExpire.set(l.getEmitter().getGraphGenerator().getMaxGeneration(creatorId) / 2));
final NonAncientEventWindow eventWindow = new NonAncientEventWindow(
0 /* ignored by shadowgraph */,
- 0 /* ignored by shadowgraph */,
- genToExpire.get(),
- GENERATION_THRESHOLD);
+ params.getAncientMode().getGenesisIndicator(),
+ Math.max(params.getAncientMode().getGenesisIndicator(), indicatorToExpire.get()),
+ params.getAncientMode());
// Expire events from the listener's graph after the supplied phase
final Runnable expireEvents =
- () -> executor.getListener().getShadowGraph().updateNonExpiredEventWindow(eventWindow);
+ () -> executor.getListener().getShadowGraph().updateEventWindow(eventWindow);
final SyncPhaseParallelExecutor parallelExecutor = new SyncPhaseParallelExecutor(
getStaticThreadManager(),
expireAfterPhase == 1 ? expireEvents : null,
@@ -885,7 +990,8 @@ void requiredEventsExpire(final int expireAfterPhase, final SyncTestParams param
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(
+ executor.getCaller(), executor.getListener(), params.getAncientMode());
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
@@ -931,10 +1037,13 @@ private void runOldParentGraphTest(final SyncTestParams params, final Consumer new SyncNode(params.getNumNetworkNodes(), 0, factory.newStandardFromSourceFactory()));
+ executor.setCallerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(), 0, factory.newStandardFromSourceFactory(), params.getAncientMode()));
executor.setListenerSupplier((factory) -> new SyncNode(
- params.getNumNetworkNodes(), params.getNumNetworkNodes() - 1, factory.newStandardFromSourceFactory()));
+ params.getNumNetworkNodes(),
+ params.getNumNetworkNodes() - 1,
+ factory.newStandardFromSourceFactory(),
+ params.getAncientMode()));
executor.setInitialGraphCreation((caller, listener) -> {
for (final SyncNode node : List.of(caller, listener)) {
@@ -945,7 +1054,8 @@ private void runOldParentGraphTest(final SyncTestParams params, final Consumer executor.getCaller().getConnection().disconnect(),
false);
- executor.setCallerSupplier((factory) ->
- new SyncNode(params.getNumNetworkNodes(), 0, factory.newShuffledFromSourceFactory(), parallelExecutor));
+ executor.setCallerSupplier((factory) -> new SyncNode(
+ params.getNumNetworkNodes(),
+ 0,
+ factory.newShuffledFromSourceFactory(),
+ parallelExecutor,
+ params.getAncientMode()));
try {
executor.execute();
@@ -980,119 +1094,42 @@ void testConnectionClosedBehavior(final SyncTestParams params) {
}
/**
- * Tests if a sync is interrupted because it takes too long. The caller has 300 events to send, but the listener
- * sleeps after reading every event. Eventually, the sync will time out and will be aborted.
- */
- @Test
- @Disabled("Test takes a minute to finish, so disabled by default")
- void testSyncTimeExceeded() {
- final SyncTestParams params = new SyncTestParams(10, 1000, 500, 200);
- final SyncTestExecutor executor = new SyncTestExecutor(params);
- final int sleep = 1000;
-
- executor.setGraphCustomization((caller, listener) -> {
- caller.setSaveGeneratedEvents(true);
- listener.setSaveGeneratedEvents(true);
- });
-
- executor.setCustomInitialization((c, l) -> l.setSleepAfterEventReadMillis(sleep));
-
- assertThrows(Exception.class, executor::execute, "the sync should time out and an exception should be thrown");
- }
-
- /**
- * Tests if a sync is aborted when there is any issue on the readers side (in this case a socket timeout), while the
- * listener is blocked while writing to the socket, because the buffer is full. The only was to unlock the writer is
- * to close the connection, which is what the synchronizer does.
- */
- @Test
- @Disabled("Not reliable enough for CCI")
- void testTimoutWriterStuck() {
- final SyncTestParams params = new SyncTestParams(10, 1000, 5000, 200);
- final SyncTestExecutor executor = new SyncTestExecutor(params);
- final int sleep = 5000;
-
- executor.setConnectionFactory(ConnectionFactory::createSocketConnections);
-
- executor.setGraphCustomization((caller, listener) -> {
- caller.setSaveGeneratedEvents(true);
- listener.setSaveGeneratedEvents(true);
- });
-
- executor.setCustomInitialization((c, l) -> l.setSleepAfterEventReadMillis(sleep));
-
- assertThrows(
- Exception.class,
- executor::execute,
- "the socket read should time out and an exception should be thrown");
- }
-
- /**
- * Tests that events from a signed state are not gossiped and that such a sync is properly aborted
+ * Tests that a sync works if one node has no events at all in the graph and also has a non-ancient indicator that
+ * is not 0
*/
- @Test
- void signedStateEvents() throws Exception {
- final SyncTestParams params = new SyncTestParams(10, 50, 2, 1);
+ @ParameterizedTest
+ @MethodSource("bothAncientModes")
+ void noEventsStartIndicator(@NonNull final AncientMode ancientMode) throws Exception {
+ final SyncTestParams params = new SyncTestParams(4, 0, 100, 0, ancientMode);
final SyncTestExecutor executor = new SyncTestExecutor(params);
-
executor.setGraphCustomization((caller, listener) -> {
caller.setSaveGeneratedEvents(true);
listener.setSaveGeneratedEvents(true);
});
- // the caller will have only signed state events
- executor.setCustomPreSyncConfiguration((caller, listener) -> {
- caller.getGeneratedEvents().forEach(EventImpl::markAsSignedStateEvent);
-
- // a signed sent event needs to be identified as needed by the peer
- // if it is ancient, it will not be marked as needed, so need to make sure no events are ancient
- when(caller.getConsensus().getMinRoundGeneration()).thenReturn(GraphGenerations.FIRST_GENERATION);
- when(caller.getConsensus().getMinGenerationNonAncient()).thenReturn(GraphGenerations.FIRST_GENERATION);
- when(listener.getConsensus().getMinRoundGeneration()).thenReturn(GraphGenerations.FIRST_GENERATION);
- when(listener.getConsensus().getMinGenerationNonAncient()).thenReturn(GraphGenerations.FIRST_GENERATION);
- });
+ executor.setEventWindowDefinitions((caller, listener) -> {
+ final long callerMaximumIndicator =
+ SyncTestUtils.getMaxIndicator(caller.getShadowGraph().getTips(), ancientMode);
+ final long callerAncientIndicator = SyncTestUtils.getMinIndicator(
+ caller.getShadowGraph()
+ .findAncestors(caller.getShadowGraph().getTips(), (e) -> true),
+ ancientMode);
- executor.execute();
-
- // the caller should not have sent any events to the listener
- SyncValidator.assertNoEventsReceived(executor.getListener());
- SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
-
- // both should be aware that the sync was aborted
- assertFalse(executor.getCaller().getSynchronizerReturn());
- assertFalse(executor.getListener().getSynchronizerReturn());
- }
+ listener.getShadowGraph()
+ .updateEventWindow(new NonAncientEventWindow(
+ ROUND_FIRST /* ignored */,
+ callerMaximumIndicator / 2,
+ callerAncientIndicator,
+ ancientMode));
- /**
- * Tests that a sync works if one node has no events at all in the graph and also has a non-ancient generation that
- * is not 0
- */
- @Test
- void noEventsStartGeneration() throws Exception {
- final SyncTestParams params = new SyncTestParams(4, 0, 100, 0);
- final SyncTestExecutor executor = new SyncTestExecutor(params);
- executor.setGraphCustomization((caller, listener) -> {
- caller.setSaveGeneratedEvents(true);
- listener.setSaveGeneratedEvents(true);
- });
- executor.setGenerationDefinitions((caller, listener) -> {
- long callerMaxGen = SyncTestUtils.getMaxGen(caller.getShadowGraph().getTips());
- long callerMinGen = SyncTestUtils.getMinGen(caller.getShadowGraph()
- .findAncestors(caller.getShadowGraph().getTips(), (e) -> true));
-
- when(listener.getConsensus().getMaxRoundGeneration()).thenReturn(callerMaxGen);
- when(listener.getConsensus().getMinGenerationNonAncient()).thenReturn(callerMaxGen / 2);
- when(listener.getConsensus().getMinRoundGeneration()).thenReturn(callerMinGen);
-
- when(caller.getConsensus().getMaxRoundGeneration()).thenReturn(callerMaxGen);
- when(caller.getConsensus().getMinGenerationNonAncient()).thenReturn(callerMaxGen / 2);
- when(caller.getConsensus().getMinRoundGeneration()).thenReturn(callerMinGen);
- });
- executor.setCustomPreSyncConfiguration((caller, listener) -> {
listener.getShadowGraph()
- .startWithExpiredThreshold(caller.getConsensus().getMinGenerationNonAncient());
+ .updateEventWindow(new NonAncientEventWindow(
+ ROUND_FIRST /* ignored */,
+ callerMaximumIndicator / 2,
+ callerAncientIndicator,
+ ancientMode));
});
executor.execute();
- SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener());
+ SyncValidator.assertOnlyRequiredEventsTransferred(executor.getCaller(), executor.getListener(), ancientMode);
SyncValidator.assertStreamsEmpty(executor.getCaller(), executor.getListener());
}
}
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncValidator.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncValidator.java
index 4b0ff1ccb0d5..8bfb1c42cc95 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncValidator.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/SyncValidator.java
@@ -26,12 +26,14 @@
import static org.junit.jupiter.api.Assertions.fail;
import com.swirlds.common.utility.CommonUtils;
+import com.swirlds.platform.event.AncientMode;
import com.swirlds.platform.event.GossipEvent;
import com.swirlds.platform.internal.EventImpl;
import com.swirlds.platform.network.Connection;
import com.swirlds.platform.system.events.BaseEventHashedData;
import com.swirlds.platform.system.events.BaseEventUnhashedData;
import com.swirlds.platform.test.fixtures.event.IndexedEvent;
+import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -67,20 +69,22 @@ public static void assertNoEventsTransferred(final SyncNode caller, final SyncNo
assertNoEventsReceived("listener", listener);
}
- public static void assertRequiredEventsTransferred(final SyncNode caller, final SyncNode listener) {
+ public static void assertRequiredEventsTransferred(
+ final SyncNode caller, final SyncNode listener, @NonNull final AncientMode ancientMode) {
if (enableLogging) {
printTipSet("Caller's Tip Set", caller);
printTipSet("Listener's Tip Set", listener);
System.out.println("*** Asserting that required events were transferred ***");
}
- compareEventLists(caller, listener, false);
+ compareEventLists(caller, listener, false, ancientMode);
}
- public static void assertOnlyRequiredEventsTransferred(final SyncNode caller, final SyncNode listener) {
+ public static void assertOnlyRequiredEventsTransferred(
+ final SyncNode caller, final SyncNode listener, @NonNull final AncientMode ancientMode) {
if (enableLogging) {
System.out.println("*** Asserting that only required events were transferred ***");
}
- compareEventLists(caller, listener, true);
+ compareEventLists(caller, listener, true, ancientMode);
}
public static void assertFallenBehindDetection(final boolean fellBehind, final SyncNode... nodes) {
@@ -121,7 +125,11 @@ public static void assertExceptionThrown(final SyncNode caller, final SyncNode l
assertNotNull(listener.getSyncException(), "Expected the listener to have thrown an exception.");
}
- private static void compareEventLists(final SyncNode caller, final SyncNode listener, final boolean strictCompare) {
+ private static void compareEventLists(
+ final SyncNode caller,
+ final SyncNode listener,
+ final boolean strictCompare,
+ @NonNull final AncientMode ancientMode) {
// Determine the unique events for the caller and listener, since they could have added some of the
// same events from step 2.
final Collection expectedCallerSendList = new ArrayList<>(caller.getGeneratedEvents());
@@ -131,14 +139,16 @@ private static void compareEventLists(final SyncNode caller, final SyncNode list
expectedListenerSendList.removeAll(caller.getGeneratedEvents());
// Remove expired events
- expectedCallerSendList.removeIf(e -> e.getGeneration() < caller.getOldestGeneration());
- expectedListenerSendList.removeIf(e -> e.getGeneration() < listener.getOldestGeneration());
+ expectedCallerSendList.removeIf(
+ e -> e.getBaseEvent().getAncientIndicator(ancientMode) < caller.getExpirationThreshold());
+ expectedListenerSendList.removeIf(
+ e -> e.getBaseEvent().getAncientIndicator(ancientMode) < listener.getExpirationThreshold());
// Remove events that are ancient for the peer
expectedCallerSendList.removeIf(
- e -> e.getGeneration() < listener.getConsensus().getMinGenerationNonAncient());
+ e -> e.getBaseEvent().getAncientIndicator(ancientMode) < listener.getCurrentAncientThreshold());
expectedListenerSendList.removeIf(
- e -> e.getGeneration() < caller.getConsensus().getMinGenerationNonAncient());
+ e -> e.getBaseEvent().getAncientIndicator(ancientMode) < caller.getCurrentAncientThreshold());
// Get the events each received from the other in the sync
final List callerReceivedEvents = caller.getReceivedEvents();
@@ -157,15 +167,16 @@ private static void compareEventLists(final SyncNode caller, final SyncNode list
}
// Assert that the event each received are the unique events in the other's shadow graph
- compareEventLists("listener", expectedCallerSendList, listener, strictCompare);
- compareEventLists("caller", expectedListenerSendList, caller, strictCompare);
+ compareEventLists("listener", expectedCallerSendList, listener, strictCompare, ancientMode);
+ compareEventLists("caller", expectedListenerSendList, caller, strictCompare, ancientMode);
}
private static void compareEventLists(
final String node,
final Collection expectedList,
final SyncNode receiver,
- final boolean strictCompare) {
+ final boolean strictCompare,
+ @NonNull final AncientMode ancientMode) {
Collection actualList = receiver.getReceivedEvents();
diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/Synchronizer.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/Synchronizer.java
index 406c7b540be1..ef0ad74f6d14 100644
--- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/Synchronizer.java
+++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/sync/Synchronizer.java
@@ -67,18 +67,11 @@ public void synchronize(final SyncNode caller, final SyncNode listener) throws E
return null;
},
() -> {
- if (listener.isSendRecInitBytes()) {
- // Read the COMM_SYNC_REQUEST byte on the listener prior to calling synchronize to match the
- // production code and align the streams
- listener.getConnection().getDis().readByte();
- }
try {
if (listener.isCanAcceptSync()) {
final boolean synchronize =
listener.getSynchronizer().synchronize(platformContext, listener.getConnection());
listener.setSynchronizerReturn(synchronize);
- } else {
- listener.getSynchronizer().rejectSync(listener.getConnection());
}
} catch (final Exception e) {
listener.setSynchronizerReturn(null);