diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/test/java/com/swirlds/demo/consistency/ConsistencyTestingToolRoundTests.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/test/java/com/swirlds/demo/consistency/ConsistencyTestingToolRoundTests.java index e1d925ebb68d..632857d957dd 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/test/java/com/swirlds/demo/consistency/ConsistencyTestingToolRoundTests.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/test/java/com/swirlds/demo/consistency/ConsistencyTestingToolRoundTests.java @@ -24,6 +24,7 @@ import com.swirlds.platform.consensus.ConsensusSnapshot; import com.swirlds.platform.consensus.GraphGenerations; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; @@ -82,7 +83,12 @@ private static Round buildMockRound(final List> eventContents, final Mockito.when(mockSnapshot.round()).thenReturn(roundReceived); return new ConsensusRound( - mock(AddressBook.class), mockEvents, mock(EventImpl.class), mock(GraphGenerations.class), mockSnapshot); + mock(AddressBook.class), + mockEvents, + mock(EventImpl.class), + mock(GraphGenerations.class), + mock(NonAncientEventWindow.class), + mockSnapshot); } @Test diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/ConsensusImpl.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/ConsensusImpl.java index cead95025e11..b8a00deaa817 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/ConsensusImpl.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/ConsensusImpl.java @@ -32,6 +32,7 @@ import com.swirlds.platform.consensus.ConsensusUtils; import com.swirlds.platform.consensus.CountingVote; import com.swirlds.platform.consensus.InitJudges; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.consensus.RoundElections; import com.swirlds.platform.consensus.SequentialRingBuffer; import com.swirlds.platform.consensus.ThreadSafeConsensusInfo; @@ -655,6 +656,8 @@ private List getStronglySeenInPreviousRound(final EventImpl event) { consensusEvents, recentEvents.get(recentEvents.size() - 1), new Generations(this), + NonAncientEventWindow.createUsingRoundsNonAncient( + decidedRoundNumber, getMinGenerationNonAncient(), config.roundsNonAncient()), new ConsensusSnapshot( decidedRoundNumber, ConsensusUtils.getHashes(judges), diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/SwirldsPlatform.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/SwirldsPlatform.java index 4f37234401b8..31534c6facb3 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/SwirldsPlatform.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/SwirldsPlatform.java @@ -74,6 +74,7 @@ import com.swirlds.platform.components.transaction.system.PreconsensusSystemTransactionManager; import com.swirlds.platform.config.ThreadConfig; import com.swirlds.platform.consensus.ConsensusConfig; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.crypto.CryptoStatic; import com.swirlds.platform.crypto.KeysAndCerts; import com.swirlds.platform.crypto.PlatformSigner; @@ -904,7 +905,13 @@ public class SwirldsPlatform implements Platform { if (eventConfig.useLegacyIntake()) { eventLinker.loadFromSignedState(initialState); } else { - platformWiring.updateMinimumGenerationNonAncient(initialMinimumGenerationNonAncient); + platformWiring.updateNonAncientEventWindow(NonAncientEventWindow.createUsingRoundsNonAncient( + initialState.getRound(), + initialMinimumGenerationNonAncient, + platformContext + .getConfiguration() + .getConfigData(ConsensusConfig.class) + .roundsNonAncient())); } // We don't want to invoke these callbacks until after we are starting up. @@ -1054,8 +1061,13 @@ private void loadStateIntoEventCreator(@NonNull final SignedState signedState) { } try { - eventCreator.setMinimumGenerationNonAncient( - signedState.getState().getPlatformState().getMinimumGenerationNonAncient()); + eventCreator.setNonAncientEventWindow(NonAncientEventWindow.createUsingRoundsNonAncient( + signedState.getRound(), + signedState.getState().getPlatformState().getMinimumGenerationNonAncient(), + platformContext + .getConfiguration() + .getConfigData(ConsensusConfig.class) + .roundsNonAncient())); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted while loading state into event creator", e); @@ -1152,7 +1164,13 @@ private void loadReconnectState(final SignedState signedState) { .inject(new AddressBookUpdate( signedState.getState().getPlatformState().getPreviousAddressBook(), signedState.getState().getPlatformState().getAddressBook())); - platformWiring.updateMinimumGenerationNonAncient(signedState.getMinRoundGeneration()); + platformWiring.updateNonAncientEventWindow(NonAncientEventWindow.createUsingRoundsNonAncient( + signedState.getRound(), + signedState.getMinRoundGeneration(), + platformContext + .getConfiguration() + .getConfigData(ConsensusConfig.class) + .roundsNonAncient())); } } finally { intakeQueue.resume(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/EventIntake.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/EventIntake.java index 69e9b633362d..42197fc3674d 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/EventIntake.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/EventIntake.java @@ -25,6 +25,8 @@ import com.swirlds.common.platform.NodeId; import com.swirlds.common.threading.manager.ThreadManager; import com.swirlds.platform.Consensus; +import com.swirlds.platform.consensus.ConsensusConfig; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.linking.EventLinker; import com.swirlds.platform.event.validation.StaticValidators; @@ -79,6 +81,7 @@ public class EventIntake { private final EventIntakeMetrics metrics; private final Time time; + private final Long roundsNonAncient; /** * Measures the time spent in each phase of event intake @@ -137,6 +140,10 @@ public EventIntake( this.intakeEventCounter = Objects.requireNonNull(intakeEventCounter); final EventConfig eventConfig = platformContext.getConfiguration().getConfigData(EventConfig.class); + this.roundsNonAncient = (long) platformContext + .getConfiguration() + .getConfigData(ConsensusConfig.class) + .roundsNonAncient(); final BlockingQueue prehandlePoolQueue = new LinkedBlockingQueue<>(); prehandlePool = new ThreadPoolExecutor( @@ -214,7 +221,10 @@ public void addEvent(final EventImpl event) { phaseTimer.activatePhase(EventIntakePhase.HANDLING_STALE_EVENTS); handleStale(minGenNonAncientBeforeAdding); if (latestEventTipsetTracker != null) { - latestEventTipsetTracker.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + // FUTURE WORK: When this class is refactored, it should not be constructing the + // NonAncientEventWindow, but receiving it through the PlatformWiring instead. + latestEventTipsetTracker.setNonAncientEventWindow(NonAncientEventWindow.createUsingRoundsNonAncient( + consensus().getLastRoundDecided(), minimumGenerationNonAncient, roundsNonAncient)); } } } finally { diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/LinkedEventIntake.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/LinkedEventIntake.java index 8a5e75832c95..adbca1264bf7 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/LinkedEventIntake.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/components/LinkedEventIntake.java @@ -19,6 +19,8 @@ import com.swirlds.base.time.Time; import com.swirlds.common.context.PlatformContext; import com.swirlds.platform.Consensus; +import com.swirlds.platform.consensus.ConsensusConfig; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.eventhandling.ConsensusRoundHandler; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.gossip.shadowgraph.LatestEventTipsetTracker; @@ -61,6 +63,7 @@ public class LinkedEventIntake { private final EventIntakeMetrics metrics; private final Time time; + private final Long roundsNonAncient; /** * Tracks the number of events from each peer have been received, but aren't yet through the intake pipeline @@ -104,6 +107,10 @@ public LinkedEventIntake( this.paused = false; metrics = new EventIntakeMetrics(platformContext, () -> -1); + this.roundsNonAncient = (long) platformContext + .getConfiguration() + .getConfigData(ConsensusConfig.class) + .roundsNonAncient(); } /** @@ -150,7 +157,12 @@ public List addEvent(@NonNull final EventImpl event) { // with no consensus events, so we check the diff in generations to look for stale events handleStale(minimumGenerationNonAncientBeforeAdding); if (latestEventTipsetTracker != null) { - latestEventTipsetTracker.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + // FUTURE WORK: When this class is refactored, it should not be constructing the + // NonAncientEventWindow, but receiving it through the PlatformWiring instead. + latestEventTipsetTracker.setNonAncientEventWindow(NonAncientEventWindow.createUsingRoundsNonAncient( + consensusSupplier.get().getLastRoundDecided(), + minimumGenerationNonAncient, + roundsNonAncient)); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/consensus/NonAncientEventWindow.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/consensus/NonAncientEventWindow.java new file mode 100644 index 000000000000..9481cf6d5c5f --- /dev/null +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/consensus/NonAncientEventWindow.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.swirlds.platform.consensus; + +import com.swirlds.base.utility.ToStringBuilder; +import com.swirlds.platform.event.GossipEvent; +import com.swirlds.platform.system.events.EventConstants; +import com.swirlds.platform.system.events.EventDescriptor; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * Determines the non-ancient lower bound (inclusive) on events and communicates the window of rounds between the + * pendingConsensusRound and the minimumRoundNonAncient (inclusive). + */ +public class NonAncientEventWindow { + + /** + * The initial NonAncientEventWindow. This constant is used to initialize NonAncientEventWindow variables before + * receiving an updated value. + */ + public static NonAncientEventWindow INITIAL_EVENT_WINDOW = new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_FIRST, EventConstants.FIRST_GENERATION); + + private final long latestConsensusRound; + private final long minRoundNonAncient; + private final long minGenNonAncient; + + /** + * Create a new NonAncientEventWindow with the given bounds. The latestConsensusRound must be greater than or equal + * to the first round of consensus. If the minimum round non-ancient is set to a number lower than the first round + * of consensus, the first round of consensus is used instead. The minGenNonAncient value must be greater than or + * equal to the first generation for events. + * + * @param latestConsensusRound the latest round that has come to consensus + * @param minRoundNonAncient the minimum round that is non-ancient + * @param minGenNonAncient the minimum generation that is non-ancient + * @throws IllegalArgumentException if the latestConsensusRound is less than the first round of consensus or if the + * minGenNonAncient value is less than the first generation for events. + */ + public NonAncientEventWindow( + final long latestConsensusRound, final long minRoundNonAncient, final long minGenNonAncient) { + if (latestConsensusRound < ConsensusConstants.ROUND_FIRST) { + throw new IllegalArgumentException( + "The latest consensus round cannot be less than the first round of consensus."); + } + if (minGenNonAncient < EventConstants.FIRST_GENERATION) { + throw new IllegalArgumentException( + "the minimum generation non-ancient cannot be lower than the first generation for events."); + } + this.latestConsensusRound = latestConsensusRound; + this.minRoundNonAncient = Math.max(minRoundNonAncient, ConsensusConstants.ROUND_FIRST); + this.minGenNonAncient = minGenNonAncient; + } + + /** + * @return the pending round coming to consensus, i.e. 1 + the latestConsensusRound + */ + public long pendingConsensusRound() { + return latestConsensusRound + 1; + } + + /** + * @return the lower bound of the non-ancient event window + */ + public long getLowerBound() { + // FUTURE WORK: return minRoundNonAncient once we switch from minGenNonAncient. + return minGenNonAncient; + } + + /** + * Determines if the given event is ancient. + * + * @param event the event to check for being ancient. + * @return true if the event is ancient, false otherwise. + */ + public boolean isAncient(@NonNull final GossipEvent event) { + // FUTURE WORK: use generation until we throw the switch to using round + return event.getGeneration() < minGenNonAncient; + } + + /** + * Determines if the given event is ancient. + * + * @param event the event to check for being ancient. + * @return true if the event is ancient, false otherwise. + */ + public boolean isAncient(@NonNull final EventDescriptor event) { + // FUTURE WORK: use generation until we throw the switch to using round + return event.getGeneration() < minGenNonAncient; + } + + /** + * Determines if the given long value is ancient. + * + * @param testValue the value to check for being ancient. + * @return true if the value is ancient, false otherwise. + */ + public boolean isAncient(final long testValue) { + // FUTURE WORK: use generation until we throw the switch to using round + return testValue < minGenNonAncient; + } + + /** + * Create a NonAncientEventWindow by calculating the minRoundNonAncient value from the latestConsensusRound and + * roundsNonAncient. + * + * @param latestConsensusRound the latest round that has come to consensus + * @param minGenNonAncient the minimum generation that is non-ancient + * @param roundsNonAncient the number of rounds that are non-ancient + * @return the new NonAncientEventWindow + */ + @NonNull + public static NonAncientEventWindow createUsingRoundsNonAncient( + final long latestConsensusRound, final long minGenNonAncient, final long roundsNonAncient) { + return new NonAncientEventWindow( + latestConsensusRound, latestConsensusRound - roundsNonAncient + 1, minGenNonAncient); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("latestConsensusRound", latestConsensusRound) + .append("minRoundNonAncient", minRoundNonAncient) + .append("minGenNonAncient", minGenNonAncient) + .toString(); + } +} diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/AsyncEventCreationManager.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/AsyncEventCreationManager.java index c91179edb852..adb50a136a5c 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/AsyncEventCreationManager.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/AsyncEventCreationManager.java @@ -29,6 +29,7 @@ import com.swirlds.common.threading.framework.config.QueueThreadMetricsConfiguration; import com.swirlds.common.threading.futures.StandardFuture; import com.swirlds.common.threading.manager.ThreadManager; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.internal.EventImpl; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Objects; @@ -60,9 +61,9 @@ public class AsyncEventCreationManager implements Lifecycle { private final BlockingQueueInserter eventInserter; /** - * The object used to enqueue updates to the minimum generation non-ancient onto the work queue. + * The object used to enqueue updates to the non-ancient event window onto the work queue. */ - private final BlockingQueueInserter minimumGenerationNonAncientInserter; + private final BlockingQueueInserter nonAncientEventWindowInserter; /** * Used to signal a desired pause. @@ -102,7 +103,7 @@ public AsyncEventCreationManager( .setCapacity(eventCreationConfig.creationQueueSize()) .setMaxBufferSize(eventCreationConfig.creationQueueBufferSize()) .addHandler(EventImpl.class, this::handleEvent) - .addHandler(Long.class, this::handleMinimumGenerationNonAncient) + .addHandler(NonAncientEventWindow.class, this::handleNonAncientEventWindow) .addHandler(PauseRequest.class, this::handlePauseStatusChange) .setIdleCallback(eventCreator::maybeCreateEvent) .setBatchHandledCallback(eventCreator::maybeCreateEvent) @@ -113,7 +114,7 @@ public AsyncEventCreationManager( .build(); eventInserter = workQueue.getInserter(EventImpl.class); - minimumGenerationNonAncientInserter = workQueue.getInserter(Long.class); + nonAncientEventWindowInserter = workQueue.getInserter(NonAncientEventWindow.class); setPauseStatusInserter = workQueue.getInserter(PauseRequest.class); } @@ -128,12 +129,13 @@ public void registerEvent(@NonNull final EventImpl event) throws InterruptedExce } /** - * Update the minimum generation non-ancient + * Update the non-ancient event window * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the new minimum generation non-ancient */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) throws InterruptedException { - minimumGenerationNonAncientInserter.put(minimumGenerationNonAncient); + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) + throws InterruptedException { + nonAncientEventWindowInserter.put(nonAncientEventWindow); } /** @@ -146,12 +148,12 @@ private void handleEvent(@NonNull final EventImpl event) { } /** - * Pass a new minimum generation non-ancient into the event creator. + * Pass a new non-ancient event window into the event creator. * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the new non-ancient event window */ - private void handleMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - eventCreator.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + private void handleNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + eventCreator.setNonAncientEventWindow(nonAncientEventWindow); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManager.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManager.java index 6e4f23b954a1..bd0ad11dfb66 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManager.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManager.java @@ -25,6 +25,7 @@ import com.swirlds.common.context.PlatformContext; import com.swirlds.common.metrics.extensions.PhaseTimer; import com.swirlds.common.metrics.extensions.PhaseTimerBuilder; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.rules.EventCreationRule; import edu.umd.cs.findbugs.annotations.NonNull; @@ -134,11 +135,11 @@ public void registerEvent(@NonNull final GossipEvent event) { } /** - * Update the minimum generation non-ancient. + * Update the non-ancient event window, defining the minimum threshold for an event to be non-ancient. * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the non-ancient event window */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - creator.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + creator.setNonAncientEventWindow(nonAncientEventWindow); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManagerFactory.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManagerFactory.java index 29300f7a40b4..2241ed7ec30f 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManagerFactory.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreationManagerFactory.java @@ -123,8 +123,8 @@ public static AsyncEventCreationManager buildLegacyEventCreationManager( "Interrupted while attempting to register event with tipset event creator")); eventObserverDispatcher.addObserver((ConsensusRoundObserver) round -> abortAndThrowIfInterrupted( - manager::setMinimumGenerationNonAncient, - round.getGenerations().getMinGenerationNonAncient(), + manager::setNonAncientEventWindow, + round.getNonAncientEventWindow(), "Interrupted while attempting to register minimum generation " + "non-ancient with tipset event creator")); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreator.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreator.java index 37f839c33ec3..11fa530790bd 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreator.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/EventCreator.java @@ -16,6 +16,7 @@ package com.swirlds.platform.event.creation; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -33,11 +34,11 @@ public interface EventCreator { void registerEvent(@NonNull GossipEvent event); /** - * Update the minimum generation non-ancient. + * Update the non-ancient event window. * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the new non-ancient event window */ - void setMinimumGenerationNonAncient(long minimumGenerationNonAncient); + void setNonAncientEventWindow(@NonNull NonAncientEventWindow nonAncientEventWindow); /** * Create a new event if it is legal to do so. The only time this should not create an event is if there are no diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/SyncEventCreationManager.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/SyncEventCreationManager.java index b12bf008fec5..a66d082c796a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/SyncEventCreationManager.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/SyncEventCreationManager.java @@ -26,6 +26,7 @@ import com.swirlds.common.context.PlatformContext; import com.swirlds.common.metrics.extensions.PhaseTimer; import com.swirlds.common.metrics.extensions.PhaseTimerBuilder; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.rules.EventCreationRule; import edu.umd.cs.findbugs.annotations.NonNull; @@ -179,11 +180,11 @@ public void registerEvent(@NonNull final GossipEvent event) { } /** - * Update the minimum generation non-ancient. + * Update the non-ancient event window * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the new non-ancient event window */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - creator.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + creator.setNonAncientEventWindow(nonAncientEventWindow); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/ChildlessEventTracker.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/ChildlessEventTracker.java index be71ac170dca..1831b3f18780 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/ChildlessEventTracker.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/ChildlessEventTracker.java @@ -17,6 +17,7 @@ package com.swirlds.platform.event.creation.tipset; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.system.events.EventDescriptor; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.ArrayList; @@ -80,11 +81,11 @@ public void registerSelfEventParents(@NonNull final List parent /** * Remove ancient events. * - * @param minimumGenerationNonAncient the minimum generation of non-ancient events + * @param nonAncientEventWindow the non-ancient event window */ - public void pruneOldEvents(final long minimumGenerationNonAncient) { + public void pruneOldEvents(@NonNull final NonAncientEventWindow nonAncientEventWindow) { for (final EventDescriptor event : getChildlessEvents()) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { removeEvent(event); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetEventCreator.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetEventCreator.java index 6847c3180cd9..20f9b668d9a5 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetEventCreator.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetEventCreator.java @@ -17,7 +17,6 @@ package com.swirlds.platform.event.creation.tipset; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; -import static com.swirlds.platform.consensus.GraphGenerations.FIRST_GENERATION; import static com.swirlds.platform.event.creation.tipset.TipsetAdvancementWeight.ZERO_ADVANCEMENT_WEIGHT; import static com.swirlds.platform.event.creation.tipset.TipsetUtils.getParentDescriptors; import static com.swirlds.platform.system.events.EventConstants.CREATOR_ID_UNDEFINED; @@ -31,6 +30,7 @@ import com.swirlds.common.stream.Signer; import com.swirlds.common.utility.throttle.RateLimitedLogger; import com.swirlds.platform.components.transaction.TransactionSupplier; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.EventUtils; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.EventCreationConfig; @@ -69,7 +69,7 @@ public class TipsetEventCreator implements EventCreator { private final ChildlessEventTracker childlessOtherEventTracker; private final TransactionSupplier transactionSupplier; private final SoftwareVersion softwareVersion; - private long minimumGenerationNonAncient = FIRST_GENERATION; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; /** * The address book for the current network. @@ -156,7 +156,7 @@ public TipsetEventCreator( */ @Override public void registerEvent(@NonNull final GossipEvent event) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { return; } @@ -197,10 +197,10 @@ public void registerEvent(@NonNull final GossipEvent event) { * {@inheritDoc} */ @Override - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - this.minimumGenerationNonAncient = minimumGenerationNonAncient; - tipsetTracker.setMinimumGenerationNonAncient(minimumGenerationNonAncient); - childlessOtherEventTracker.pruneOldEvents(minimumGenerationNonAncient); + public void setNonAncientEventWindow(@NonNull NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); + tipsetTracker.setNonAncientEventWindow(nonAncientEventWindow); + childlessOtherEventTracker.pruneOldEvents(nonAncientEventWindow); } /** @@ -274,8 +274,8 @@ private GossipEvent createEventByOptimizingAdvancementWeight() { if (bestOtherParent == null) { // If there are no available other parents, it is only legal to create a new event if we are // creating a genesis event. In order to create a genesis event, we must have never created - // an event before and the current minimum generation non ancient must have never been advanced. - if (minimumGenerationNonAncient > GENERATION_UNDEFINED + 1 || lastSelfEvent != null) { + // an event before and the current non-ancient event window must have never been advanced. + if (nonAncientEventWindow != NonAncientEventWindow.INITIAL_EVENT_WINDOW || lastSelfEvent != null) { // event creation isn't legal return null; } @@ -474,7 +474,7 @@ private static NodeId getCreator(@Nullable final EventDescriptor descriptor) { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("Minimum generation non-ancient: ") - .append(tipsetTracker.getMinimumGenerationNonAncient()) + .append(tipsetTracker.getNonAncientEventWindow()) .append("\n"); sb.append("Latest self event: ").append(lastSelfEvent).append("\n"); sb.append(tipsetWeightCalculator); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetTracker.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetTracker.java index ff4251beebb2..98a4ec76376f 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetTracker.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetTracker.java @@ -24,6 +24,7 @@ import com.swirlds.common.sequence.map.SequenceMap; import com.swirlds.common.sequence.map.StandardSequenceMap; import com.swirlds.common.utility.throttle.RateLimitedLogger; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.EventDescriptor; import edu.umd.cs.findbugs.annotations.NonNull; @@ -58,7 +59,7 @@ public class TipsetTracker { private final AddressBook addressBook; - private long minimumGenerationNonAncient; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; private final RateLimitedLogger ancientEventLogger; @@ -80,22 +81,23 @@ public TipsetTracker(@NonNull final Time time, @NonNull final AddressBook addres } /** - * Set the minimum generation that is not considered ancient. + * Set the non-ancient event window. * - * @param minimumGenerationNonAncient the minimum non-ancient generation, all lower generations are ancient + * @param nonAncientEventWindow the minimum non-ancient generation, all lower generations are ancient */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - tipsets.shiftWindow(minimumGenerationNonAncient); - this.minimumGenerationNonAncient = minimumGenerationNonAncient; + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); + tipsets.shiftWindow(nonAncientEventWindow.getLowerBound()); } /** - * Get the minimum generation that is not considered ancient (from this class's perspective). + * Get the current non-ancient event window (from this class's perspective). * - * @return the minimum non-ancient generation, all lower generations are ancient + * @return the non-ancient event window */ - public long getMinimumGenerationNonAncient() { - return minimumGenerationNonAncient; + @NonNull + public NonAncientEventWindow getNonAncientEventWindow() { + return nonAncientEventWindow; } /** @@ -109,17 +111,16 @@ public long getMinimumGenerationNonAncient() { public Tipset addEvent( @NonNull final EventDescriptor eventDescriptor, @NonNull final List parents) { - if (eventDescriptor.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(eventDescriptor)) { // Note: although we don't immediately return from this method, the tipsets.put() // will not update the data structure for an ancient event. We should never // enter this bock of code. This log is here as a canary to alert us if we somehow do. ancientEventLogger.error( EXCEPTION.getMarker(), - "Rejecting ancient event from {} with generation {}. " - + "Current minimum generation non-ancient is {}", + "Rejecting ancient event from {} with generation {}. Current non-ancient event window is {}", eventDescriptor.getCreator(), eventDescriptor.getGeneration(), - minimumGenerationNonAncient); + nonAncientEventWindow); } final List parentTipsets = new ArrayList<>(parents.size()); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetWeightCalculator.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetWeightCalculator.java index ab0e7011d929..e5f914b269dd 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetWeightCalculator.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/creation/tipset/TipsetWeightCalculator.java @@ -236,7 +236,7 @@ public TipsetAdvancementWeight getTheoreticalAdvancementWeight(@NonNull final Li + "Parent ID = {}, parent generation = {}, minimum generation non-ancient = {}", parent.getCreator(), parent.getGeneration(), - tipsetTracker.getMinimumGenerationNonAncient()); + tipsetTracker.getNonAncientEventWindow()); } continue; } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/deduplication/EventDeduplicator.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/deduplication/EventDeduplicator.java index 94f7c062128e..6f7f73eb2c91 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/deduplication/EventDeduplicator.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/deduplication/EventDeduplicator.java @@ -22,6 +22,7 @@ import com.swirlds.common.metrics.LongAccumulator; import com.swirlds.common.sequence.map.SequenceMap; import com.swirlds.common.sequence.map.StandardSequenceMap; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.metrics.EventIntakeMetrics; @@ -53,9 +54,9 @@ public class EventDeduplicator { private static final int INITIAL_CAPACITY = 1024; /** - * The current minimum generation required for an event to be non-ancient. + * The current non-ancient event window. */ - private long minimumGenerationNonAncient = 0; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; /** * Keeps track of the number of events in the intake pipeline from each peer @@ -111,7 +112,7 @@ public EventDeduplicator( */ @Nullable public GossipEvent handleEvent(@NonNull final GossipEvent event) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { // Ancient events can be safely ignored. intakeEventCounter.eventExitedIntakePipeline(event.getSenderId()); return null; @@ -137,14 +138,14 @@ public GossipEvent handleEvent(@NonNull final GossipEvent event) { } /** - * Set the minimum generation required for an event to be non-ancient. + * Set the NonAncientEventWindow, defines the minimum threshold for an event to be non-ancient. * - * @param minimumGenerationNonAncient the minimum generation required for an event to be non-ancient + * @param nonAncientEventWindow the non-ancient event window */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - this.minimumGenerationNonAncient = minimumGenerationNonAncient; + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); - observedEvents.shiftWindow(minimumGenerationNonAncient); + observedEvents.shiftWindow(nonAncientEventWindow.getLowerBound()); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/linking/InOrderLinker.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/linking/InOrderLinker.java index 4457f843655b..9806b572f8d0 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/linking/InOrderLinker.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/linking/InOrderLinker.java @@ -27,6 +27,7 @@ import com.swirlds.common.sequence.map.StandardSequenceMap; import com.swirlds.common.utility.throttle.RateLimitedLogger; import com.swirlds.platform.EventStrings; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.internal.EventImpl; @@ -94,9 +95,9 @@ public class InOrderLinker { private final Map parentHashMap = new HashMap<>(INITIAL_CAPACITY); /** - * The current minimum generation required for an event to be non-ancient. + * The current non-ancient event window. */ - private long minimumGenerationNonAncient = 0; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; /** * Keeps track of the number of events in the intake pipeline from each peer @@ -158,7 +159,7 @@ public InOrderLinker( private EventImpl getParentToLink( @NonNull final GossipEvent child, @NonNull final Hash parentHash, final long claimedParentGeneration) { - if (claimedParentGeneration < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(claimedParentGeneration)) { // ancient parents don't need to be linked return null; } @@ -220,7 +221,7 @@ private EventImpl getParentToLink( */ @Nullable public EventImpl linkEvent(@NonNull final GossipEvent event) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { // This event is ancient, so we don't need to link it. this.intakeEventCounter.eventExitedIntakePipeline(event.getSenderId()); return null; @@ -242,15 +243,16 @@ public EventImpl linkEvent(@NonNull final GossipEvent event) { } /** - * Set the minimum generation required for an event to be non-ancient. + * Set the non-ancient event window, defining the minimum non-ancient threshold. * - * @param minimumGenerationNonAncient the minimum generation required for an event to be non-ancient + * @param nonAncientEventWindow the non-ancient event window */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - this.minimumGenerationNonAncient = minimumGenerationNonAncient; + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); parentDescriptorMap.shiftWindow( - minimumGenerationNonAncient, (descriptor, event) -> parentHashMap.remove(descriptor.getHash())); + nonAncientEventWindow.getLowerBound(), + (descriptor, event) -> parentHashMap.remove(descriptor.getHash())); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/orphan/OrphanBuffer.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/orphan/OrphanBuffer.java index faca16a18a6e..607c53d67261 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/orphan/OrphanBuffer.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/orphan/OrphanBuffer.java @@ -24,6 +24,7 @@ import com.swirlds.common.sequence.map.StandardSequenceMap; import com.swirlds.common.sequence.set.SequenceSet; import com.swirlds.common.sequence.set.StandardSequenceSet; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.system.events.EventDescriptor; @@ -53,9 +54,9 @@ public class OrphanBuffer { private static final Function> EMPTY_LIST = ignored -> new ArrayList<>(); /** - * The current minimum generation required for an event to be non-ancient. + * The current non-ancient event window. */ - private long minimumGenerationNonAncient = 0; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; /** * The number of orphans currently in the buffer. @@ -112,7 +113,7 @@ public OrphanBuffer( */ @NonNull public List handleEvent(@NonNull final GossipEvent event) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { // Ancient events can be safely ignored. intakeEventCounter.eventExitedIntakePipeline(event.getSenderId()); return List.of(); @@ -134,23 +135,23 @@ public List handleEvent(@NonNull final GossipEvent event) { } /** - * Set the minimum generation of non-ancient events to keep in the buffer. + * Sets the non-ancient event window that defines when an event is considered ancient. * - * @param minimumGenerationNonAncient the minimum generation of non-ancient events to keep in the buffer + * @param nonAncientEventWindow the non-ancient event window * @return the list of events that are no longer orphans as a result of this change */ @NonNull - public List setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - this.minimumGenerationNonAncient = minimumGenerationNonAncient; + public List setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); - eventsWithParents.shiftWindow(minimumGenerationNonAncient); + eventsWithParents.shiftWindow(nonAncientEventWindow.getLowerBound()); // As the map is cleared out, we need to gather the ancient parents and their orphans. We can't // modify the data structure as the window is being shifted, so we collect that data and act on // it once the window has finished shifting. final List ancientParents = new ArrayList<>(); missingParentMap.shiftWindow( - minimumGenerationNonAncient, + nonAncientEventWindow.getLowerBound(), (parent, orphans) -> ancientParents.add(new ParentAndOrphans(parent, orphans))); final List unorphanedEvents = new ArrayList<>(); @@ -198,7 +199,7 @@ private List getMissingParents(@NonNull final GossipEvent event final Iterator parentIterator = new ParentIterator(event); while (parentIterator.hasNext()) { final EventDescriptor parent = parentIterator.next(); - if (!eventsWithParents.contains(parent) && parent.getGeneration() >= minimumGenerationNonAncient) { + if (!eventsWithParents.contains(parent) && !nonAncientEventWindow.isAncient(parent)) { missingParents.add(parent); } } @@ -230,7 +231,7 @@ private List eventIsNotAnOrphan(@NonNull final GossipEvent event) { final GossipEvent nonOrphan = nonOrphanStack.pop(); final EventDescriptor nonOrphanDescriptor = nonOrphan.getDescriptor(); - if (nonOrphan.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(nonOrphan)) { // Although it doesn't cause harm to pass along ancient events, it is unnecessary to do so. intakeEventCounter.eventExitedIntakePipeline(event.getSenderId()); continue; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/validation/EventSignatureValidator.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/validation/EventSignatureValidator.java index 8de1f411512f..adf2e0ea1801 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/validation/EventSignatureValidator.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/validation/EventSignatureValidator.java @@ -25,6 +25,7 @@ import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.CommonUtils; import com.swirlds.common.utility.throttle.RateLimitedLogger; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.crypto.SignatureVerifier; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; @@ -73,9 +74,9 @@ public class EventSignatureValidator { private final SoftwareVersion currentSoftwareVersion; /** - * The current minimum generation required for an event to be non-ancient. + * The current non-ancient event window. */ - private long minimumGenerationNonAncient = 0; + private NonAncientEventWindow nonAncientEventWindow = NonAncientEventWindow.INITIAL_EVENT_WINDOW; /** * Keeps track of the number of events in the intake pipeline from each peer @@ -221,7 +222,7 @@ private boolean isSignatureValid(@NonNull final GossipEvent event) { */ @Nullable public GossipEvent validateSignature(@NonNull final GossipEvent event) { - if (event.getGeneration() < minimumGenerationNonAncient) { + if (nonAncientEventWindow.isAncient(event)) { // ancient events can be safely ignored intakeEventCounter.eventExitedIntakePipeline(event.getSenderId()); return null; @@ -238,12 +239,12 @@ public GossipEvent validateSignature(@NonNull final GossipEvent event) { } /** - * Set the minimum generation required for an event to be non-ancient. + * Set the non-ancient event window that defines the minimum threshold required for an event to be non-ancient * - * @param minimumGenerationNonAncient the minimum generation required for an event to be non-ancient + * @param nonAncientEventWindow the non-ancient event window */ - public void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - this.minimumGenerationNonAncient = minimumGenerationNonAncient; + public void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/gossip/shadowgraph/LatestEventTipsetTracker.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/gossip/shadowgraph/LatestEventTipsetTracker.java index 4e3d8876e9ed..16279ecb8b57 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/gossip/shadowgraph/LatestEventTipsetTracker.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/gossip/shadowgraph/LatestEventTipsetTracker.java @@ -18,6 +18,7 @@ import com.swirlds.base.time.Time; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.creation.tipset.Tipset; import com.swirlds.platform.event.creation.tipset.TipsetTracker; import com.swirlds.platform.internal.EventImpl; @@ -58,12 +59,12 @@ public LatestEventTipsetTracker( } /** - * Update the minimum generation non-ancient. + * Update the non-ancient event window * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the non-ancient event window */ - public synchronized void setMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - tipsetTracker.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + public synchronized void setNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + tipsetTracker.setNonAncientEventWindow(nonAncientEventWindow); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/internal/ConsensusRound.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/internal/ConsensusRound.java index 353ead7271b6..dc67f10b1d18 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/internal/ConsensusRound.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/internal/ConsensusRound.java @@ -19,6 +19,7 @@ import com.swirlds.base.utility.ToStringBuilder; import com.swirlds.platform.consensus.ConsensusSnapshot; import com.swirlds.platform.consensus.GraphGenerations; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.EventUtils; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.address.AddressBook; @@ -37,6 +38,8 @@ public class ConsensusRound implements Round { private final List consensusEvents; /** the consensus generations when this round reached consensus */ private final GraphGenerations generations; + /** the non-ancient event window for this round */ + private final NonAncientEventWindow nonAncientEventWindow; /** The number of application transactions in this round */ private int numAppTransactions = 0; /** A snapshot of consensus at this consensus round */ @@ -52,23 +55,26 @@ public class ConsensusRound implements Round { /** * Create a new instance with the provided consensus events. * - * @param consensusRoster the consensus roster for this round - * @param consensusEvents the events in the round, in consensus order - * @param keystoneEvent the event that, when added to the hashgraph, caused this round to reach consensus - * @param generations the consensus generations for this round - * @param snapshot snapshot of consensus at this round + * @param consensusRoster the consensus roster for this round + * @param consensusEvents the events in the round, in consensus order + * @param keystoneEvent the event that, when added to the hashgraph, caused this round to reach consensus + * @param generations the consensus generations for this round + * @param nonAncientEventWindow the non-ancient event window for this round + * @param snapshot snapshot of consensus at this round */ public ConsensusRound( @NonNull final AddressBook consensusRoster, @NonNull final List consensusEvents, @NonNull final EventImpl keystoneEvent, @NonNull final GraphGenerations generations, + @NonNull final NonAncientEventWindow nonAncientEventWindow, @NonNull final ConsensusSnapshot snapshot) { this.consensusRoster = Objects.requireNonNull(consensusRoster); this.consensusEvents = Collections.unmodifiableList(Objects.requireNonNull(consensusEvents)); this.keystoneEvent = Objects.requireNonNull(keystoneEvent); this.generations = Objects.requireNonNull(generations); + this.nonAncientEventWindow = Objects.requireNonNull(nonAncientEventWindow); this.snapshot = Objects.requireNonNull(snapshot); for (final EventImpl e : consensusEvents) { @@ -101,6 +107,13 @@ public int getNumAppTransactions() { return generations; } + /** + * @return the non-ancient event window for this round + */ + public @NonNull NonAncientEventWindow getNonAncientEventWindow() { + return nonAncientEventWindow; + } + /** * @return a snapshot of consensus at this consensus round */ diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventConstants.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventConstants.java index c5bd3aab9593..c97fa992f911 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventConstants.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventConstants.java @@ -37,4 +37,6 @@ private EventConstants() {} public static final long MINIMUM_ROUND_CREATED = 1; /** the round number to represent that the birth round is undefined */ public static final long BIRTH_ROUND_UNDEFINED = -1; + /** the minimum generation value an event can have. */ + public static final long FIRST_GENERATION = 0; } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventDeduplicatorWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventDeduplicatorWiring.java index 816cb8f0191d..9b2214e8fe09 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventDeduplicatorWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventDeduplicatorWiring.java @@ -20,6 +20,7 @@ import com.swirlds.common.wiring.wires.input.BindableInputWire; import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.deduplication.EventDeduplicator; import edu.umd.cs.findbugs.annotations.NonNull; @@ -27,15 +28,15 @@ /** * Wiring for the {@link EventDeduplicator}. * - * @param eventInput the input wire for events to be deduplicated - * @param minimumGenerationNonAncientInput the input wire for the minimum generation non-ancient - * @param clearInput the input wire to clear the internal state of the deduplicator - * @param eventOutput the output wire for deduplicated events - * @param flushRunnable the runnable to flush the deduplicator + * @param eventInput the input wire for events to be deduplicated + * @param nonAncientEventWindowInput the input wire for the minimum non-ancient threshold + * @param clearInput the input wire to clear the internal state of the deduplicator + * @param eventOutput the output wire for deduplicated events + * @param flushRunnable the runnable to flush the deduplicator */ public record EventDeduplicatorWiring( @NonNull InputWire eventInput, - @NonNull InputWire minimumGenerationNonAncientInput, + @NonNull InputWire nonAncientEventWindowInput, @NonNull InputWire clearInput, @NonNull OutputWire eventOutput, @NonNull Runnable flushRunnable) { @@ -49,7 +50,7 @@ public record EventDeduplicatorWiring( public static EventDeduplicatorWiring create(@NonNull final TaskScheduler taskScheduler) { return new EventDeduplicatorWiring( taskScheduler.buildInputWire("non-deduplicated events"), - taskScheduler.buildInputWire("minimum generation non ancient"), + taskScheduler.buildInputWire("non-ancient event window"), taskScheduler.buildInputWire("clear"), taskScheduler.getOutputWire(), taskScheduler::flush); @@ -62,8 +63,8 @@ public static EventDeduplicatorWiring create(@NonNull final TaskScheduler) eventInput).bind(deduplicator::handleEvent); - ((BindableInputWire) minimumGenerationNonAncientInput) - .bind(deduplicator::setMinimumGenerationNonAncient); + ((BindableInputWire) nonAncientEventWindowInput) + .bind(deduplicator::setNonAncientEventWindow); ((BindableInputWire) clearInput).bind(deduplicator::clear); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventSignatureValidatorWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventSignatureValidatorWiring.java index fe5af6282fc5..2edb50c4f63a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventSignatureValidatorWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/EventSignatureValidatorWiring.java @@ -20,6 +20,7 @@ import com.swirlds.common.wiring.wires.input.BindableInputWire; import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.validation.AddressBookUpdate; import com.swirlds.platform.event.validation.EventSignatureValidator; @@ -28,15 +29,15 @@ /** * Wiring for the {@link EventSignatureValidator}. * - * @param eventInput the input wire for events with unvalidated signatures - * @param minimumGenerationNonAncientInput the input wire for the minimum generation non-ancient - * @param addressBookUpdateInput the input wire for address book updates - * @param eventOutput the output wire for events with validated signatures - * @param flushRunnable the runnable to flush the validator + * @param eventInput the input wire for events with unvalidated signatures + * @param nonAncientEventWindowInput the input wire for the minimum non-ancient threshold + * @param addressBookUpdateInput the input wire for address book updates + * @param eventOutput the output wire for events with validated signatures + * @param flushRunnable the runnable to flush the validator */ public record EventSignatureValidatorWiring( @NonNull InputWire eventInput, - @NonNull InputWire minimumGenerationNonAncientInput, + @NonNull InputWire nonAncientEventWindowInput, @NonNull InputWire addressBookUpdateInput, @NonNull OutputWire eventOutput, @NonNull Runnable flushRunnable) { @@ -50,7 +51,7 @@ public record EventSignatureValidatorWiring( public static EventSignatureValidatorWiring create(@NonNull final TaskScheduler taskScheduler) { return new EventSignatureValidatorWiring( taskScheduler.buildInputWire("events with unvalidated signatures"), - taskScheduler.buildInputWire("minimum generation non ancient"), + taskScheduler.buildInputWire("non-ancient event window"), taskScheduler.buildInputWire("address book update"), taskScheduler.getOutputWire(), taskScheduler::flush); @@ -63,8 +64,8 @@ public static EventSignatureValidatorWiring create(@NonNull final TaskScheduler< */ public void bind(@NonNull final EventSignatureValidator eventSignatureValidator) { ((BindableInputWire) eventInput).bind(eventSignatureValidator::validateSignature); - ((BindableInputWire) minimumGenerationNonAncientInput) - .bind(eventSignatureValidator::setMinimumGenerationNonAncient); + ((BindableInputWire) nonAncientEventWindowInput) + .bind(eventSignatureValidator::setNonAncientEventWindow); ((BindableInputWire) addressBookUpdateInput) .bind(eventSignatureValidator::updateAddressBooks); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/InOrderLinkerWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/InOrderLinkerWiring.java index cd565d08e176..a6bbe8f99fba 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/InOrderLinkerWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/InOrderLinkerWiring.java @@ -20,6 +20,7 @@ import com.swirlds.common.wiring.wires.input.BindableInputWire; import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.linking.InOrderLinker; import com.swirlds.platform.internal.EventImpl; @@ -28,15 +29,15 @@ /** * Wiring for the {@link InOrderLinker}. * - * @param eventInput the input wire for events to be linked - * @param minimumGenerationNonAncientInput the input wire for the minimum generation non-ancient - * @param clearInput the input wire to clear the internal state of the linker - * @param eventOutput the output wire for linked events - * @param flushRunnable the runnable to flush the linker + * @param eventInput the input wire for events to be linked + * @param nonAncientEventWindowInput the input wire for the minimum generation non-ancient + * @param clearInput the input wire to clear the internal state of the linker + * @param eventOutput the output wire for linked events + * @param flushRunnable the runnable to flush the linker */ public record InOrderLinkerWiring( @NonNull InputWire eventInput, - @NonNull InputWire minimumGenerationNonAncientInput, + @NonNull InputWire nonAncientEventWindowInput, @NonNull InputWire clearInput, @NonNull OutputWire eventOutput, @NonNull Runnable flushRunnable) { @@ -50,7 +51,7 @@ public record InOrderLinkerWiring( public static InOrderLinkerWiring create(@NonNull final TaskScheduler taskScheduler) { return new InOrderLinkerWiring( taskScheduler.buildInputWire("unlinked events"), - taskScheduler.buildInputWire("minimum generation non ancient"), + taskScheduler.buildInputWire("non-ancient event window"), taskScheduler.buildInputWire("clear"), taskScheduler.getOutputWire(), taskScheduler::flush); @@ -63,8 +64,8 @@ public static InOrderLinkerWiring create(@NonNull final TaskScheduler */ public void bind(@NonNull final InOrderLinker inOrderLinker) { ((BindableInputWire) eventInput).bind(inOrderLinker::linkEvent); - ((BindableInputWire) minimumGenerationNonAncientInput) - .bind(inOrderLinker::setMinimumGenerationNonAncient); + ((BindableInputWire) nonAncientEventWindowInput) + .bind(inOrderLinker::setNonAncientEventWindow); ((BindableInputWire) clearInput).bind(inOrderLinker::clear); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/LinkedEventIntakeWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/LinkedEventIntakeWiring.java index 7623a57f42a3..0258ffccfbf0 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/LinkedEventIntakeWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/LinkedEventIntakeWiring.java @@ -21,6 +21,7 @@ import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; import com.swirlds.platform.components.LinkedEventIntake; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; @@ -30,18 +31,18 @@ /** * Wiring for the {@link LinkedEventIntake}. * - * @param eventInput the input wire for events to be added to the hashgraph - * @param pauseInput the input wire for pausing the linked event intake - * @param consensusRoundOutput the output wire for consensus rounds - * @param minimumGenerationNonAncientOutput the output wire for the minimum generation non-ancient. This output is - * transformed from the consensus round output - * @param flushRunnable the runnable to flush the intake + * @param eventInput the input wire for events to be added to the hashgraph + * @param pauseInput the input wire for pausing the linked event intake + * @param consensusRoundOutput the output wire for consensus rounds + * @param nonAncientEventWindowOutput the output wire for the {@link NonAncientEventWindow}. This output is transformed + * from the consensus round output + * @param flushRunnable the runnable to flush the intake */ public record LinkedEventIntakeWiring( @NonNull InputWire eventInput, @NonNull InputWire pauseInput, @NonNull OutputWire consensusRoundOutput, - @NonNull OutputWire minimumGenerationNonAncientOutput, + @NonNull OutputWire nonAncientEventWindowOutput, @NonNull Runnable flushRunnable) { /** @@ -59,9 +60,9 @@ public static LinkedEventIntakeWiring create(@NonNull final TaskScheduler consensusRound.getGenerations().getMinGenerationNonAncient()), + consensusRound -> consensusRound.getNonAncientEventWindow()), taskScheduler::flush); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/OrphanBufferWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/OrphanBufferWiring.java index 1551ee212284..91de7b212c6b 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/OrphanBufferWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/OrphanBufferWiring.java @@ -20,6 +20,7 @@ import com.swirlds.common.wiring.wires.input.BindableInputWire; import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.orphan.OrphanBuffer; import edu.umd.cs.findbugs.annotations.NonNull; @@ -29,14 +30,14 @@ * Wiring for the {@link OrphanBuffer}. * * @param eventInput the input wire for unordered events - * @param minimumGenerationNonAncientInput the input wire for the minimum generation non-ancient + * @param nonAncientEventWindowInput the input wire for the non-ancient event window * @param clearInput the input wire to clear the internal state of the orphan buffer * @param eventOutput the output wire for topologically ordered events * @param flushRunnable the runnable to flush the buffer */ public record OrphanBufferWiring( @NonNull InputWire eventInput, - @NonNull InputWire minimumGenerationNonAncientInput, + @NonNull InputWire nonAncientEventWindowInput, @NonNull InputWire clearInput, @NonNull OutputWire eventOutput, @NonNull Runnable flushRunnable) { @@ -50,7 +51,7 @@ public record OrphanBufferWiring( public static OrphanBufferWiring create(@NonNull final TaskScheduler> taskScheduler) { return new OrphanBufferWiring( taskScheduler.buildInputWire("unordered events"), - taskScheduler.buildInputWire("minimum generation non ancient"), + taskScheduler.buildInputWire("non-ancient event window"), taskScheduler.buildInputWire("clear"), taskScheduler.getOutputWire().buildSplitter("orphanBufferSplitter", "event lists"), taskScheduler::flush); @@ -63,8 +64,8 @@ public static OrphanBufferWiring create(@NonNull final TaskScheduler>) eventInput).bind(orphanBuffer::handleEvent); - ((BindableInputWire>) minimumGenerationNonAncientInput) - .bind(orphanBuffer::setMinimumGenerationNonAncient); + ((BindableInputWire>) nonAncientEventWindowInput) + .bind(orphanBuffer::setNonAncientEventWindow); ((BindableInputWire>) clearInput).bind(orphanBuffer::clear); } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/PlatformWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/PlatformWiring.java index e560340e85c2..6e97f307f513 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/PlatformWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/PlatformWiring.java @@ -29,6 +29,7 @@ import com.swirlds.platform.StateSigner; import com.swirlds.platform.components.LinkedEventIntake; import com.swirlds.platform.components.appcomm.AppCommunicationComponent; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.EventCreationManager; import com.swirlds.platform.event.deduplication.EventDeduplicator; @@ -145,19 +146,17 @@ public WiringModel getModel() { } /** - * Solder the minimum generation non-ancient output to all components that need it. + * Solder the NonAncientEventWindow output to all components that need it. */ - private void solderMinimumGenerationNonAncient() { - final OutputWire minimumGenerationNonAncientOutput = - linkedEventIntakeWiring.minimumGenerationNonAncientOutput(); - - minimumGenerationNonAncientOutput.solderTo(eventDeduplicatorWiring.minimumGenerationNonAncientInput(), INJECT); - minimumGenerationNonAncientOutput.solderTo( - eventSignatureValidatorWiring.minimumGenerationNonAncientInput(), INJECT); - minimumGenerationNonAncientOutput.solderTo(orphanBufferWiring.minimumGenerationNonAncientInput(), INJECT); - minimumGenerationNonAncientOutput.solderTo(inOrderLinkerWiring.minimumGenerationNonAncientInput(), INJECT); - minimumGenerationNonAncientOutput.solderTo( - eventCreationManagerWiring.minimumGenerationNonAncientInput(), INJECT); + private void solderNonAncientEventWindow() { + final OutputWire nonAncientEventWindowOutputWire = + linkedEventIntakeWiring.nonAncientEventWindowOutput(); + + nonAncientEventWindowOutputWire.solderTo(eventDeduplicatorWiring.nonAncientEventWindowInput(), INJECT); + nonAncientEventWindowOutputWire.solderTo(eventSignatureValidatorWiring.nonAncientEventWindowInput(), INJECT); + nonAncientEventWindowOutputWire.solderTo(orphanBufferWiring.nonAncientEventWindowInput(), INJECT); + nonAncientEventWindowOutputWire.solderTo(inOrderLinkerWiring.nonAncientEventWindowInput(), INJECT); + nonAncientEventWindowOutputWire.solderTo(eventCreationManagerWiring.nonAncientEventWindowInput(), INJECT); } /** @@ -177,7 +176,7 @@ private void wire() { .solderTo(applicationTransactionPrehandlerWiring.appTransactionsToPrehandleInput()); orphanBufferWiring.eventOutput().solderTo(stateSignatureCollectorWiring.preconsensusEventInput()); - solderMinimumGenerationNonAncient(); + solderNonAncientEventWindow(); } } @@ -329,19 +328,19 @@ public InputWire getSignStateInput() { } /** - * Inject a new minimum generation non-ancient on all components that need it. + * Inject a new non-ancient event window into all components that need it. *

- * Future work: this is a temporary hook to allow the components to get the minimum generation non-ancient during - * startup. This method will be removed once the components are wired together. + * Future work: this is a temporary hook to allow the components to get the non-ancient event window during startup. + * This method will be removed once the components are wired together. * - * @param minimumGenerationNonAncient the new minimum generation non-ancient + * @param nonAncientEventWindow the new non-ancient event window */ - public void updateMinimumGenerationNonAncient(final long minimumGenerationNonAncient) { - eventDeduplicatorWiring.minimumGenerationNonAncientInput().inject(minimumGenerationNonAncient); - eventSignatureValidatorWiring.minimumGenerationNonAncientInput().inject(minimumGenerationNonAncient); - orphanBufferWiring.minimumGenerationNonAncientInput().inject(minimumGenerationNonAncient); - inOrderLinkerWiring.minimumGenerationNonAncientInput().inject(minimumGenerationNonAncient); - eventCreationManagerWiring.minimumGenerationNonAncientInput().inject(minimumGenerationNonAncient); + public void updateNonAncientEventWindow(@NonNull final NonAncientEventWindow nonAncientEventWindow) { + eventDeduplicatorWiring.nonAncientEventWindowInput().inject(nonAncientEventWindow); + eventSignatureValidatorWiring.nonAncientEventWindowInput().inject(nonAncientEventWindow); + orphanBufferWiring.nonAncientEventWindowInput().inject(nonAncientEventWindow); + inOrderLinkerWiring.nonAncientEventWindowInput().inject(nonAncientEventWindow); + eventCreationManagerWiring.nonAncientEventWindowInput().inject(nonAncientEventWindow); } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/components/EventCreationManagerWiring.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/components/EventCreationManagerWiring.java index 28d8b2b3e41f..0eddeda0d8f0 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/components/EventCreationManagerWiring.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/wiring/components/EventCreationManagerWiring.java @@ -22,6 +22,7 @@ import com.swirlds.common.wiring.wires.input.BindableInputWire; import com.swirlds.common.wiring.wires.input.InputWire; import com.swirlds.common.wiring.wires.output.OutputWire; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.EventCreationConfig; import com.swirlds.platform.event.creation.EventCreationManager; @@ -36,7 +37,7 @@ public class EventCreationManagerWiring { private final TaskScheduler taskScheduler; private final BindableInputWire eventInput; - private final BindableInputWire minimumGenerationNonAncientInput; + private final BindableInputWire nonAncientEventWindowInput; private final BindableInputWire pauseInput; private final Bindable heartbeatBindable; private final OutputWire newEventOutput; @@ -66,7 +67,7 @@ private EventCreationManagerWiring( this.taskScheduler = taskScheduler; eventInput = taskScheduler.buildInputWire("possible parents"); - minimumGenerationNonAncientInput = taskScheduler.buildInputWire("minimum generation non ancient"); + nonAncientEventWindowInput = taskScheduler.buildInputWire("non-ancient event window"); pauseInput = taskScheduler.buildInputWire("pause"); newEventOutput = taskScheduler.getOutputWire(); @@ -84,7 +85,7 @@ private EventCreationManagerWiring( */ public void bind(@NonNull final EventCreationManager eventCreationManager) { eventInput.bind(eventCreationManager::registerEvent); - minimumGenerationNonAncientInput.bind(eventCreationManager::setMinimumGenerationNonAncient); + nonAncientEventWindowInput.bind(eventCreationManager::setNonAncientEventWindow); pauseInput.bind(eventCreationManager::setPauseStatus); heartbeatBindable.bind(now -> { return eventCreationManager.maybeCreateEvent(); @@ -102,13 +103,13 @@ public InputWire eventInput() { } /** - * Get the input wire for the minimum generation non-ancient. + * Get the input wire for the non-ancient event window. * - * @return the input wire for the minimum generation non-ancient + * @return the input wire for the non-ancient event window */ @NonNull - public InputWire minimumGenerationNonAncientInput() { - return minimumGenerationNonAncientInput; + public InputWire nonAncientEventWindowInput() { + return nonAncientEventWindowInput; } /** diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/ConsensusRoundTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/ConsensusRoundTests.java index 086586dc41d7..a10e8f691612 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/ConsensusRoundTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/ConsensusRoundTests.java @@ -24,6 +24,7 @@ import com.swirlds.common.test.fixtures.RandomUtils; import com.swirlds.platform.consensus.ConsensusSnapshot; import com.swirlds.platform.consensus.GraphGenerations; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; import com.swirlds.platform.system.address.AddressBook; @@ -48,8 +49,8 @@ void testConstructor() { final List events = List.of(e1, e2, e3); - final ConsensusRound round = - new ConsensusRound(mock(AddressBook.class), events, mock(EventImpl.class), g, snapshot); + final ConsensusRound round = new ConsensusRound( + mock(AddressBook.class), events, mock(EventImpl.class), g, mock(NonAncientEventWindow.class), snapshot); assertEquals(events, round.getConsensusEvents(), "consensus event list does not match the provided list."); assertEquals(events.size(), round.getNumEvents(), "numEvents does not match the events provided."); @@ -76,6 +77,7 @@ void testNumApplicationTransactions() { events, mock(EventImpl.class), mock(GraphGenerations.class), + mock(NonAncientEventWindow.class), mock(ConsensusSnapshot.class)); assertEquals( diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/EventDeduplicatorTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/EventDeduplicatorTests.java index b8311e0421e5..ee3f3a729809 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/EventDeduplicatorTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/EventDeduplicatorTests.java @@ -29,6 +29,8 @@ import com.swirlds.common.crypto.Hash; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.ConsensusConstants; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.deduplication.EventDeduplicator; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.metrics.EventIntakeMetrics; @@ -181,7 +183,11 @@ void standardOperation() { if (random.nextBoolean()) { minimumGenerationNonAncient++; - deduplicator.setMinimumGenerationNonAncient(minimumGenerationNonAncient); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + deduplicator.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, + ConsensusConstants.ROUND_NEGATIVE_INFINITY, + minimumGenerationNonAncient)); } } diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/linking/InOrderLinkerTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/linking/InOrderLinkerTests.java index 27e17969506e..f151e189023c 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/linking/InOrderLinkerTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/linking/InOrderLinkerTests.java @@ -29,6 +29,8 @@ import com.swirlds.base.test.fixtures.time.FakeTime; import com.swirlds.common.crypto.Hash; +import com.swirlds.platform.consensus.ConsensusConstants; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.internal.EventImpl; @@ -161,7 +163,9 @@ void standardOperation() { assertEquals(0, exitedIntakePipelineCount.get()); time.tick(Duration.ofSeconds(1)); - inOrderLinker.setMinimumGenerationNonAncient(1); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + inOrderLinker.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_NEGATIVE_INFINITY, 1)); final Hash child2Hash = randomHash(random); final long child2Generation = 2; @@ -181,7 +185,9 @@ void standardOperation() { assertEquals(0, exitedIntakePipelineCount.get()); time.tick(Duration.ofSeconds(1)); - inOrderLinker.setMinimumGenerationNonAncient(2); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + inOrderLinker.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_NEGATIVE_INFINITY, 2)); final Hash child3Hash = randomHash(random); final long child3Generation = 3; @@ -195,7 +201,9 @@ void standardOperation() { assertEquals(0, exitedIntakePipelineCount.get()); time.tick(Duration.ofSeconds(1)); - inOrderLinker.setMinimumGenerationNonAncient(4); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + inOrderLinker.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_NEGATIVE_INFINITY, 4)); final Hash child4Hash = randomHash(random); final long child4Generation = 4; @@ -252,7 +260,9 @@ void missingOtherParent() { @Test @DisplayName("Ancient events should immediately exit the intake pipeline") void ancientEvent() { - inOrderLinker.setMinimumGenerationNonAncient(3); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + inOrderLinker.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_NEGATIVE_INFINITY, 3)); final GossipEvent child1 = generateMockEvent( randomHash(random), diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/orphan/OrphanBufferTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/orphan/OrphanBufferTests.java index 8c580371a83b..acfc17331cb9 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/orphan/OrphanBufferTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/orphan/OrphanBufferTests.java @@ -27,6 +27,8 @@ import com.swirlds.common.crypto.Hash; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.ConsensusConstants; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; import com.swirlds.platform.system.events.BaseEventHashedData; @@ -281,7 +283,12 @@ void standardOperation() { final int stepRandomness = Math.round(random.nextFloat() * MAX_GENERATION_STEP); if (random.nextFloat() < averageGenerationAdvancement / stepRandomness) { minimumGenerationNonAncient += stepRandomness; - unorphanedEvents.addAll(orphanBuffer.setMinimumGenerationNonAncient(minimumGenerationNonAncient)); + // FUTURE WORK: change from minGenNonAncient to minRoundNonAncient + final NonAncientEventWindow nonAncientEventWindow = new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, + ConsensusConstants.ROUND_NEGATIVE_INFINITY, + minimumGenerationNonAncient); + unorphanedEvents.addAll(orphanBuffer.setNonAncientEventWindow(nonAncientEventWindow)); } for (final GossipEvent unorphanedEvent : unorphanedEvents) { diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/validation/EventSignatureValidatorTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/validation/EventSignatureValidatorTests.java index 611b0f598735..644e36e36281 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/validation/EventSignatureValidatorTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/event/validation/EventSignatureValidatorTests.java @@ -31,6 +31,8 @@ import com.swirlds.common.crypto.Hash; import com.swirlds.common.crypto.SerializablePublicKey; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.ConsensusConstants; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.crypto.SignatureVerifier; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.IntakeEventCounter; @@ -252,7 +254,8 @@ void ancientEvent() { assertNotEquals(null, validatorWithTrueVerifier.validateSignature(event)); assertEquals(0, exitedIntakePipelineCount.get()); - validatorWithTrueVerifier.setMinimumGenerationNonAncient(100L); + validatorWithTrueVerifier.setNonAncientEventWindow(new NonAncientEventWindow( + ConsensusConstants.ROUND_FIRST, ConsensusConstants.ROUND_NEGATIVE_INFINITY, 100L)); assertNull(validatorWithTrueVerifier.validateSignature(event)); assertEquals(1, exitedIntakePipelineCount.get()); diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/uptime/UptimeTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/uptime/UptimeTests.java index 3955a5d51d4f..273c8291e289 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/uptime/UptimeTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/uptime/UptimeTests.java @@ -33,6 +33,7 @@ import com.swirlds.common.test.fixtures.RandomAddressBookGenerator; import com.swirlds.platform.consensus.ConsensusSnapshot; import com.swirlds.platform.consensus.GraphGenerations; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; import com.swirlds.platform.system.address.Address; @@ -103,7 +104,12 @@ private static List generateEvents( private static ConsensusRound mockRound(@NonNull final List events) { final ConsensusSnapshot snapshot = mock(ConsensusSnapshot.class); final ConsensusRound round = new ConsensusRound( - mock(AddressBook.class), events, mock(EventImpl.class), mock(GraphGenerations.class), snapshot); + mock(AddressBook.class), + events, + mock(EventImpl.class), + mock(GraphGenerations.class), + mock(NonAncientEventWindow.class), + snapshot); final Instant consensusTimestamp = events.get(events.size() - 1).getConsensusTimestamp(); when(snapshot.consensusTimestamp()).thenReturn(consensusTimestamp); return round; diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/chatter/ChatterNotifierTest.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/chatter/ChatterNotifierTest.java index 5123d04e606b..0e2559e1e01a 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/chatter/ChatterNotifierTest.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/chatter/ChatterNotifierTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verify; import com.swirlds.platform.consensus.ConsensusSnapshot; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.gossip.chatter.ChatterNotifier; import com.swirlds.platform.gossip.chatter.protocol.ChatterCore; @@ -73,6 +74,7 @@ void testPurge() { List.of(event), mock(EventImpl.class), new Generations(1, 2, 3), + mock(NonAncientEventWindow.class), mock(ConsensusSnapshot.class))); verify(chatterCore).shiftWindow(1); } diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventIntakeTest.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventIntakeTest.java index 9f571f3f5366..2afec83d0442 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventIntakeTest.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventIntakeTest.java @@ -33,6 +33,7 @@ import com.swirlds.platform.Consensus; import com.swirlds.platform.components.EventIntake; import com.swirlds.platform.consensus.ConsensusSnapshot; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.linking.EventLinker; import com.swirlds.platform.gossip.IntakeEventCounter; @@ -110,6 +111,7 @@ void test() { List.of(consEvent1, consEvent2), added, generations, + mock(NonAncientEventWindow.class), mock(ConsensusSnapshot.class))); }); diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventObserverDispatcherTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventObserverDispatcherTests.java index 427eea17d859..70e6e3f1f410 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventObserverDispatcherTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/EventObserverDispatcherTests.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock; import com.swirlds.platform.consensus.ConsensusSnapshot; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.gossip.shadowgraph.Generations; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; @@ -81,6 +82,7 @@ void test() { List.of(e1, e2), mock(EventImpl.class), Generations.GENESIS_GENERATIONS, + mock(NonAncientEventWindow.class), mock(ConsensusSnapshot.class))); } diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/TransactionHandlingTestUtils.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/TransactionHandlingTestUtils.java index d6763fe37133..30c4f5f8da6a 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/TransactionHandlingTestUtils.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/components/TransactionHandlingTestUtils.java @@ -23,6 +23,7 @@ import com.swirlds.common.test.fixtures.DummySystemTransaction; import com.swirlds.platform.consensus.ConsensusSnapshot; import com.swirlds.platform.consensus.GraphGenerations; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.internal.ConsensusRound; import com.swirlds.platform.internal.EventImpl; import com.swirlds.platform.system.BasicSoftwareVersion; @@ -89,6 +90,7 @@ public static ConsensusRound newDummyRound(final List roundContents) { events, mock(EventImpl.class), mock(GraphGenerations.class), + mock(NonAncientEventWindow.class), mock(ConsensusSnapshot.class)); } } diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/ChildlessEventTrackerTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/ChildlessEventTrackerTests.java index 256393d844b6..9e029ef0e2ec 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/ChildlessEventTrackerTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/ChildlessEventTrackerTests.java @@ -22,6 +22,7 @@ import com.swirlds.common.crypto.Hash; import com.swirlds.common.platform.NodeId; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.creation.tipset.ChildlessEventTracker; import com.swirlds.platform.system.events.EventDescriptor; import edu.umd.cs.findbugs.annotations.NonNull; @@ -100,7 +101,8 @@ void basicBehaviorTest() { assertEquals(removeBranches(expectedEvents), new HashSet<>(tracker.getChildlessEvents())); // Increase the minimum generation non-ancient to 1, all events from batch1 should be removed - tracker.pruneOldEvents(1); + // FUTURE WORK: Change the test to use round instead of generation for ancient. + tracker.pruneOldEvents(new NonAncientEventWindow(1, 0, 1)); assertEquals(removeBranches(batch2), new HashSet<>(tracker.getChildlessEvents())); } diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetEventCreatorTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetEventCreatorTests.java index 982f81c8369e..f56d65c6b382 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetEventCreatorTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetEventCreatorTests.java @@ -38,6 +38,7 @@ import com.swirlds.common.stream.Signer; import com.swirlds.common.test.fixtures.RandomAddressBookGenerator; import com.swirlds.platform.components.transaction.TransactionSupplier; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.GossipEvent; import com.swirlds.platform.event.creation.EventCreator; import com.swirlds.platform.event.creation.tipset.ChildlessEventTracker; @@ -889,7 +890,7 @@ void noStaleEventsAtCreationTimeTest() { final EventCreator eventCreator = buildEventCreator(random, time, addressBook, nodeA, () -> new ConsensusTransactionImpl[0]); - eventCreator.setMinimumGenerationNonAncient(100); + eventCreator.setNonAncientEventWindow(new NonAncientEventWindow(1, 0, 100)); // Since there are no other parents available, the next event created would have a generation of 0 // (if event creation were permitted). Since the current minimum generation non ancient is 100, diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetTrackerTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetTrackerTests.java index d7ad97240157..e8a487cc57b7 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetTrackerTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetTrackerTests.java @@ -26,6 +26,7 @@ import com.swirlds.base.time.Time; import com.swirlds.common.platform.NodeId; import com.swirlds.common.test.fixtures.RandomAddressBookGenerator; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.creation.tipset.Tipset; import com.swirlds.platform.event.creation.tipset.TipsetTracker; import com.swirlds.platform.system.address.Address; @@ -141,8 +142,11 @@ void basicBehaviorTest() { long minimumGenerationNonAncient = 0; while (tracker.size() > 0) { minimumGenerationNonAncient += random.nextInt(1, 5); - tracker.setMinimumGenerationNonAncient(minimumGenerationNonAncient); - assertEquals(minimumGenerationNonAncient, tracker.getMinimumGenerationNonAncient()); + // FUTURE WORK: change test to use round number instead of minimum generation non-ancient. + final NonAncientEventWindow nonAncientEventWindow = + new NonAncientEventWindow(1, 0, minimumGenerationNonAncient); + tracker.setNonAncientEventWindow(nonAncientEventWindow); + assertEquals(nonAncientEventWindow, tracker.getNonAncientEventWindow()); for (final EventDescriptor fingerprint : expectedTipsets.keySet()) { if (fingerprint.getGeneration() < minimumGenerationNonAncient) { assertNull(tracker.getTipset(fingerprint)); diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetWeightCalculatorTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetWeightCalculatorTests.java index 985cb4b7dcd2..503b78a85aa2 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetWeightCalculatorTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/event/tipset/TipsetWeightCalculatorTests.java @@ -34,6 +34,7 @@ import com.swirlds.common.platform.NodeId; import com.swirlds.common.test.fixtures.RandomAddressBookGenerator; import com.swirlds.common.test.fixtures.RandomAddressBookGenerator.WeightDistributionStrategy; +import com.swirlds.platform.consensus.NonAncientEventWindow; import com.swirlds.platform.event.creation.tipset.ChildlessEventTracker; import com.swirlds.platform.event.creation.tipset.Tipset; import com.swirlds.platform.event.creation.tipset.TipsetAdvancementWeight; @@ -533,9 +534,11 @@ void ancientParentTest() { final EventDescriptor eventD2 = newEventDescriptor(randomHash(random), nodeD, 2); builder.addEvent(eventD2, List.of(eventA1, eventB1, eventC1, eventD1)); + // FUTURE WORK: Change the test to use round instead of generation for ancient. // Mark generation 1 as ancient. - builder.setMinimumGenerationNonAncient(2); - childlessEventTracker.pruneOldEvents(2); + final NonAncientEventWindow nonAncientEventWindow = new NonAncientEventWindow(1, 0, 2); + builder.setNonAncientEventWindow(nonAncientEventWindow); + childlessEventTracker.pruneOldEvents(nonAncientEventWindow); // We shouldn't be able to find tipsets for ancient events. assertNull(builder.getTipset(eventA1));