From 1971adda410b764b756e476bbd7278055273dc72 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 31 Oct 2024 10:06:21 +0200 Subject: [PATCH 01/59] refactor: remove State class Signed-off-by: Nikita Lebedev --- .../demo/crypto/CryptocurrencyDemoMain.java | 12 +- .../demo/crypto/CryptocurrencyDemoState.java | 85 +----- .../src/main/java/module-info.java | 2 + .../demo/hello/HelloSwirldDemoMain.java | 12 +- .../demo/hello/HelloSwirldDemoState.java | 31 +- .../src/main/java/module-info.java | 2 + .../com/swirlds/demo/stats/StatsDemoMain.java | 12 +- .../swirlds/demo/stats/StatsDemoState.java | 32 +- .../StatsDemo/src/main/java/module-info.java | 2 + .../AddressBookTestingToolMain.java | 12 +- .../AddressBookTestingToolState.java | 42 +-- .../src/main/java/module-info.java | 2 + .../ConsistencyTestingTool/build.gradle.kts | 1 - .../ConsistencyTestingToolMain.java | 12 +- .../ConsistencyTestingToolState.java | 41 +-- .../src/main/java/module-info.java | 2 + .../swirlds/demo/iss/ISSTestingToolMain.java | 12 +- .../swirlds/demo/iss/ISSTestingToolState.java | 42 +-- .../src/main/java/module-info.java | 2 + .../migration/MigrationTestingToolMain.java | 12 +- .../migration/MigrationTestingToolState.java | 18 +- .../src/main/java/module-info.java | 2 + .../PlatformTestingTool/build.gradle.kts | 1 + .../platform/PlatformTestingToolMain.java | 12 +- .../platform/PlatformTestingToolState.java | 17 +- .../src/main/java/module-info.java | 2 + .../demo/platform/PttTransactionPoolTest.java | 8 +- .../signing/StatsSigningTestingToolMain.java | 13 +- .../signing/StatsSigningTestingToolState.java | 49 +--- .../src/main/java/module-info.java | 2 + .../demo/stress/StressTestingToolMain.java | 12 +- .../demo/stress/StressTestingToolState.java | 38 +-- .../src/main/java/module-info.java | 2 + .../com/swirlds/platform/state/State.java | 274 ------------------ .../util/NoOpMerkleStateLifecycles.java | 197 +++++++++++++ .../platform/state/StateRegistryTests.java | 5 +- .../platform/turtle/runner/Turtle.java | 11 +- .../turtle/runner/TurtleTestingToolState.java | 52 +--- .../com/swirlds/platform/test/StateTest.java | 8 +- .../com/swirlds/platform/test/StateTests.java | 23 +- 40 files changed, 451 insertions(+), 665 deletions(-) delete mode 100644 platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/State.java create mode 100644 platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java diff --git a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java index 28e21828fb5b..34656f5d268c 100644 --- a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java +++ b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java @@ -36,11 +36,11 @@ import com.swirlds.common.utility.AutoCloseableWrapper; import com.swirlds.metrics.api.Metrics; import com.swirlds.platform.Browser; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; @@ -182,10 +182,10 @@ public void run() { @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new CryptocurrencyDemoState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new CryptocurrencyDemoState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java index d08785a13640..ec6d22e39cb3 100644 --- a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java +++ b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java @@ -26,25 +26,22 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ +import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.pbj.runtime.io.buffer.Bytes; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; import com.swirlds.common.platform.NodeId; import com.swirlds.platform.SwirldsPlatform; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.address.Address; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.transaction.Transaction; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,6 +49,7 @@ import java.util.Objects; import java.util.Random; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; /** * This holds the current state of a swirld representing both a cryptocurrency and a stock market. @@ -62,7 +60,7 @@ * entirely new cryptocurrency is created every time all the computers start the program over again, so * these cryptocurrencies won't have any actual value. */ -public class CryptocurrencyDemoState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class CryptocurrencyDemoState extends MerkleStateRoot { /** * The version history of this class. @@ -134,7 +132,11 @@ public static enum TransType { //////////////////////////////////////////////////// - public CryptocurrencyDemoState() {} + public CryptocurrencyDemoState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); + } private CryptocurrencyDemoState(final CryptocurrencyDemoState sourceState) { super(sourceState); @@ -196,6 +198,7 @@ public synchronized long getNumTrades() { @Override public synchronized CryptocurrencyDemoState copy() { throwIfImmutable(); + setImmutable(true); return new CryptocurrencyDemoState(this); } @@ -380,76 +383,14 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { - this.platform = (SwirldsPlatform) platform; + super.init(platform, trigger, previousSoftwareVersion); + this.platform = (SwirldsPlatform) platform; if (trigger == InitTrigger.GENESIS) { genesisInit(); } } - @Override - public void serialize(final SerializableDataOutputStream out) throws IOException { - out.writeStringArray(tickerSymbol); - - out.writeInt(wallet.size()); - for (Map.Entry entry : wallet.entrySet()) { - out.writeSerializable(entry.getKey(), false); - out.writeLong(entry.getValue().get()); - } - - out.writeInt(shares.size()); - for (Map.Entry> entry : shares.entrySet()) { - out.writeSerializable(entry.getKey(), false); - out.writeInt(entry.getValue().size()); - for (int i = 0; i < entry.getValue().size(); i++) { - out.writeLong(entry.getValue().get(i).get()); - } - } - - out.writeStringArray(trades); - out.writeInt(numTradesStored); - out.writeInt(lastTradeIndex); - out.writeLong(numTrades); - out.writeByteArray(ask); - out.writeByteArray(bid); - out.writeSerializableArray(askId, false, true); - out.writeSerializableArray(bidId, false, true); - out.writeByteArray(price); - } - - @Override - public void deserialize(final SerializableDataInputStream in, final int version) throws IOException { - tickerSymbol = in.readStringArray(DEFAULT_MAX_ARRAY_SIZE, DEFAULT_MAX_STRING_SIZE); - - int walletSize = in.readInt(); - for (int i = 0; i < walletSize; i++) { - final NodeId id = in.readSerializable(false, NodeId::new); - final AtomicLong amount = new AtomicLong(in.readLong()); - wallet.put(id, amount); - } - - final int sharesSize = in.readInt(); - for (int i = 0; i < sharesSize; i++) { - final NodeId id = in.readSerializable(false, NodeId::new); - final int numShares = in.readInt(); - final List sharesForID = new ArrayList<>(numShares); - for (int j = 0; j < numShares; j++) { - sharesForID.add(new AtomicLong(in.readLong())); - } - shares.put(id, sharesForID); - } - - trades = in.readStringArray(DEFAULT_MAX_ARRAY_SIZE, DEFAULT_MAX_STRING_SIZE); - numTradesStored = in.readInt(); - lastTradeIndex = in.readInt(); - numTrades = in.readLong(); - ask = in.readByteArray(DEFAULT_MAX_ARRAY_SIZE); - bid = in.readByteArray(DEFAULT_MAX_ARRAY_SIZE); - askId = in.readSerializableArray(NodeId[]::new, DEFAULT_MAX_ARRAY_SIZE, false, NodeId::new); - bidId = in.readSerializableArray(NodeId[]::new, DEFAULT_MAX_ARRAY_SIZE, false, NodeId::new); - price = in.readByteArray(DEFAULT_MAX_ARRAY_SIZE); - } - @Override public long getClassId() { return CLASS_ID; diff --git a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/module-info.java b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/module-info.java index b42efa99b26b..769d0e16696f 100644 --- a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/module-info.java @@ -1,7 +1,9 @@ module com.swirlds.demo.crypto { + requires com.hedera.node.hapi; requires com.swirlds.common; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires java.desktop; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java index 04dfe21cdf2a..b3872ec8ae57 100644 --- a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java +++ b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java @@ -35,12 +35,12 @@ import com.swirlds.platform.SwirldsPlatform; import com.swirlds.platform.listeners.PlatformStatusChangeListener; import com.swirlds.platform.listeners.PlatformStatusChangeNotification; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; import com.swirlds.platform.system.status.PlatformStatus; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import java.nio.charset.StandardCharsets; @@ -109,10 +109,10 @@ public void run() { @NonNull @Override - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new HelloSwirldDemoState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new HelloSwirldDemoState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } private void platformStatusChange(final PlatformStatusChangeNotification notification) { diff --git a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java index 7d36ec7950cd..bca84ac24137 100644 --- a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java +++ b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java @@ -26,25 +26,25 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.Round; -import com.swirlds.platform.system.SwirldState; +import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.transaction.Transaction; -import java.io.IOException; +import edu.umd.cs.findbugs.annotations.NonNull; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; /** * This holds the current state of the swirld. For this simple "hello swirld" code, each transaction is just * a string, and the state is just a list of the strings in all the transactions handled so far, in the * order that they were handled. */ -public class HelloSwirldDemoState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class HelloSwirldDemoState extends MerkleStateRoot { /** * The version history of this class. @@ -91,7 +91,11 @@ public synchronized String toString() { // /////////////////////////////////////////////////////////////////// - public HelloSwirldDemoState() {} + public HelloSwirldDemoState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); + } private HelloSwirldDemoState(final HelloSwirldDemoState sourceState) { super(sourceState); @@ -107,6 +111,7 @@ public synchronized void handleConsensusRound(final Round round, final PlatformS @Override public synchronized HelloSwirldDemoState copy() { throwIfImmutable(); + setImmutable(true); return new HelloSwirldDemoState(this); } @@ -117,16 +122,6 @@ private void handleTransaction(final Transaction transaction) { strings.add(new String(transaction.getApplicationTransaction().toByteArray(), StandardCharsets.UTF_8)); } - @Override - public void serialize(final SerializableDataOutputStream out) throws IOException { - out.writeStringList(strings); - } - - @Override - public void deserialize(final SerializableDataInputStream in, final int version) throws IOException { - strings = in.readStringList(DEFAULT_MAX_ARRAY_SIZE, DEFAULT_MAX_STRING_SIZE); - } - @Override public long getClassId() { return CLASS_ID; diff --git a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/module-info.java b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/module-info.java index cfd02e9373bc..76f2cb141a2c 100644 --- a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/module-info.java @@ -1,6 +1,8 @@ module com.swirlds.demo.hello { + requires com.hedera.node.hapi; requires com.swirlds.common; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires java.desktop; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java index 794f67e901c1..5a6f1ad7bf1a 100644 --- a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java +++ b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java @@ -39,11 +39,11 @@ import com.swirlds.metrics.api.Metrics; import com.swirlds.platform.Browser; import com.swirlds.platform.ParameterProvider; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.BufferedWriter; import java.io.File; @@ -297,10 +297,10 @@ private String valueAsString(final Metric metric) { @NonNull @Override - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new StatsDemoState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new StatsDemoState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java index 68d018b2c2a3..ed560940bd06 100644 --- a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java +++ b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java @@ -26,13 +26,14 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.Round; -import com.swirlds.platform.system.SwirldState; +import com.swirlds.platform.system.SoftwareVersion; +import edu.umd.cs.findbugs.annotations.NonNull; +import java.util.function.Function; /** * This demo collects statistics on the running of the network and consensus systems. It writes them to the @@ -41,7 +42,7 @@ * is 100 random bytes. So StatsDemoState.handleTransaction doesn't actually do anything, other than the * optional sequence number check. */ -public class StatsDemoState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class StatsDemoState extends MerkleStateRoot { /** * The version history of this class. @@ -62,7 +63,11 @@ private static class ClassVersion { private static final long CLASS_ID = 0xc550a1cd94e91ca3L; - public StatsDemoState() {} + public StatsDemoState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); + } private StatsDemoState(final StatsDemoState sourceState) { super(sourceState); @@ -77,21 +82,10 @@ public void handleConsensusRound(final Round round, final PlatformStateModifier @Override public synchronized StatsDemoState copy() { throwIfImmutable(); + setImmutable(true); return new StatsDemoState(this); } - /** - * {@inheritDoc} - */ - @Override - public void serialize(final SerializableDataOutputStream out) {} - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(final SerializableDataInputStream in, final int version) {} - /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/module-info.java b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/module-info.java index e0830b328858..5387a8dc5903 100644 --- a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/module-info.java @@ -1,8 +1,10 @@ module com.swirlds.demo.stats { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires java.desktop; requires static com.github.spotbugs.annotations; } diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java index 8fef0db4e50a..af19fb09a94b 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java @@ -23,11 +23,11 @@ import com.swirlds.config.api.Configuration; import com.swirlds.config.api.ConfigurationBuilder; import com.swirlds.platform.config.DefaultConfiguration; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.IOException; @@ -105,10 +105,10 @@ public void run() { */ @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new AddressBookTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new AddressBookTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java index fb6e10ea4c5e..b8c9d29ba674 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java @@ -35,22 +35,19 @@ import static com.swirlds.platform.state.address.AddressBookInitializer.STATE_ADDRESS_BOOK_USED; import static com.swirlds.platform.state.address.AddressBookInitializer.USED_ADDRESS_BOOK_HEADER; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.context.PlatformContext; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ByteUtils; import com.swirlds.common.utility.StackTrace; import com.swirlds.platform.config.AddressBookConfig; -import com.swirlds.platform.state.PlatformStateAccessor; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.address.Address; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.address.AddressBookUtils; @@ -68,13 +65,14 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * State for the AddressBookTestingTool. */ -public class AddressBookTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class AddressBookTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(AddressBookTestingToolState.class); @@ -110,8 +108,8 @@ private static class ClassVersion { /** * The number of rounds handled by this app. Is incremented each time - * {@link #handleConsensusRound(Round, PlatformStateAccessor)} is called. Note that this may not actually equal the round - * number, since we don't call {@link #handleConsensusRound(Round, PlatformStateAccessor)} for rounds with no events. + * {@link #handleConsensusRound(Round, PlatformStateModifier)} is called. Note that this may not actually equal the round + * number, since we don't call {@link #handleConsensusRound(Round, PlatformStateModifier)} for rounds with no events. * *

* Affects the hash of this node. @@ -126,7 +124,10 @@ private static class ClassVersion { */ private Duration freezeAfterGenesis = null; - public AddressBookTestingToolState() { + public AddressBookTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); logger.info(STARTUP.getMarker(), "New State Constructed."); } @@ -153,6 +154,7 @@ private AddressBookTestingToolState(@NonNull final AddressBookTestingToolState t @Override public synchronized AddressBookTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new AddressBookTestingToolState(this); } @@ -230,26 +232,6 @@ private void handleTransaction(@NonNull final ConsensusTransaction transaction) runningSum += delta; } - /** - * {@inheritDoc} - */ - @Override - public void serialize(@NonNull final SerializableDataOutputStream out) throws IOException { - Objects.requireNonNull(out, "the serializable data output stream cannot be null"); - out.writeLong(runningSum); - out.writeLong(roundsHandled); - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(@NonNull final SerializableDataInputStream in, final int version) throws IOException { - Objects.requireNonNull(in, "the serializable data input stream cannot be null"); - runningSum = in.readLong(); - roundsHandled = in.readLong(); - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/module-info.java index 9cf7d36b3ea9..dc767113b793 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/module-info.java @@ -1,9 +1,11 @@ module com.swirlds.demo.addressbook { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.config.api; requires com.swirlds.logging; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/build.gradle.kts index 75324db7df15..0cb0449462f1 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/build.gradle.kts @@ -21,7 +21,6 @@ application.mainClass.set("com.swirlds.demo.consistency.ConsistencyTestingToolMa mainModuleInfo { annotationProcessor("com.swirlds.config.processor") } testModuleInfo { - requires("com.hedera.node.hapi") requires("com.swirlds.common.test.fixtures") requires("com.swirlds.platform.core.test.fixtures") requires("org.junit.jupiter.api") diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index 1f197fc14865..85d52ec7ae7e 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -19,12 +19,12 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.swirlds.common.platform.NodeId; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.security.SecureRandom; @@ -88,10 +88,10 @@ public void run() { */ @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new ConsistencyTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new ConsistencyTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getVersion())); } /** diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 4cbd7b6c7b7b..75a00c91033c 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -20,19 +20,16 @@ import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.config.StateCommonConfig; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; import com.swirlds.common.utility.NonCryptographicHashing; -import com.swirlds.platform.state.PlatformStateAccessor; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; @@ -45,13 +42,14 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * State for the Consistency Testing Tool */ -public class ConsistencyTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class ConsistencyTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(ConsistencyTestingToolState.class); private static final long CLASS_ID = 0xda03bb07eb897d82L; @@ -76,8 +74,8 @@ private static class ClassVersion { /** * The number of rounds handled by this app. Is incremented each time - * {@link #handleConsensusRound(Round, PlatformStateAccessor)} is called. Note that this may not actually equal the round - * number, since we don't call {@link #handleConsensusRound(Round, PlatformStateAccessor)} for rounds with no events. + * {@link #handleConsensusRound(Round, PlatformStateModifier)} is called. Note that this may not actually equal the round + * number, since we don't call {@link #handleConsensusRound(Round, PlatformStateModifier)} for rounds with no events. * *

* Affects the hash of this node. @@ -104,7 +102,10 @@ private static class ClassVersion { /** * Constructor */ - public ConsistencyTestingToolState() { + public ConsistencyTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); logger.info(STARTUP.getMarker(), "New State Constructed."); this.transactionHandlingHistory = new TransactionHandlingHistory(); @@ -166,25 +167,6 @@ public long getClassId() { return CLASS_ID; } - /** - * {@inheritDoc} - */ - @Override - public void serialize(final @NonNull SerializableDataOutputStream out) throws IOException { - Objects.requireNonNull(out); - out.writeLong(stateLong); - out.writeLong(roundsHandled); - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(final @NonNull SerializableDataInputStream in, final int version) throws IOException { - stateLong = Objects.requireNonNull(in).readLong(); - roundsHandled = in.readLong(); - } - /** * {@inheritDoc} */ @@ -200,6 +182,7 @@ public int getVersion() { @NonNull public synchronized ConsistencyTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new ConsistencyTestingToolState(this); } diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java index be312e2cff34..180572b8b186 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java @@ -1,9 +1,11 @@ module com.swirlds.demo.consistency { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.config.api; requires com.swirlds.logging; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java index 1bd1ca3e790e..3ecf0ed47acd 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java @@ -19,13 +19,13 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.swirlds.common.platform.NodeId; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; import com.swirlds.platform.system.state.notifications.IssListener; import com.swirlds.platform.system.state.notifications.IssNotification; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.util.List; @@ -89,10 +89,10 @@ public void run() { */ @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new ISSTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new ISSTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java index b14e90ca0d2b..d9cd03d6a99a 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java @@ -32,27 +32,24 @@ import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.merkle.utility.SerializableLong; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ByteUtils; import com.swirlds.platform.scratchpad.Scratchpad; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.address.Address; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.io.IOException; import java.time.Duration; import java.time.Instant; import java.util.HashMap; @@ -62,13 +59,14 @@ import java.util.Map; import java.util.Objects; import java.util.Random; +import java.util.function.Function; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * State for the ISSTestingTool. */ -public class ISSTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class ISSTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(ISSTestingToolState.class); @@ -110,7 +108,11 @@ private static class ClassVersion { private Scratchpad scratchPad; - public ISSTestingToolState() {} + public ISSTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); + } /** * Copy constructor. @@ -140,6 +142,7 @@ public boolean isImmutable() { @Override public synchronized ISSTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new ISSTestingToolState(this); } @@ -151,6 +154,7 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { + super.init(platform, trigger, previousSoftwareVersion); throwIfImmutable(); @@ -391,28 +395,6 @@ private void triggerLogError( elapsedSinceGenesis); } - /** - * {@inheritDoc} - */ - @Override - public void serialize(final SerializableDataOutputStream out) throws IOException { - out.writeLong(runningSum); - out.writeInstant(genesisTimestamp); - out.writeSerializableList(plannedIssList, false, true); - out.writeSerializableList(plannedLogErrorList, false, true); - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(final SerializableDataInputStream in, final int version) throws IOException { - runningSum = in.readLong(); - genesisTimestamp = in.readInstant(); - plannedIssList = in.readSerializableList(1024, false, PlannedIss::new); - plannedLogErrorList = in.readSerializableList(1024, false, PlannedLogError::new); - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/module-info.java index 6b1ce2c53dbf..b621bdaab105 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/module-info.java @@ -1,9 +1,11 @@ module com.swirlds.demo.iss { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.config.api; requires com.swirlds.logging; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java index 8ac8ecb4e3d5..2ad1b650960a 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java @@ -24,11 +24,11 @@ import com.swirlds.logging.legacy.payload.ApplicationFinishedPayload; import com.swirlds.merkle.map.MerkleMapMetrics; import com.swirlds.platform.ParameterProvider; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import java.security.SignatureException; import org.apache.logging.log4j.LogManager; @@ -166,10 +166,10 @@ private void throttleTransactionCreation() throws InterruptedException { */ @NonNull @Override - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new MigrationTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new MigrationTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java index dea54d5ab330..833032225a13 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java @@ -19,10 +19,9 @@ import static com.swirlds.demo.migration.MigrationTestingToolMain.PREVIOUS_SOFTWARE_VERSION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.crypto.DigestType; -import com.swirlds.common.merkle.MerkleInternal; import com.swirlds.common.merkle.MerkleNode; -import com.swirlds.common.merkle.impl.PartialNaryMerkleInternal; import com.swirlds.common.platform.NodeId; import com.swirlds.demo.migration.virtual.AccountVirtualMapKey; import com.swirlds.demo.migration.virtual.AccountVirtualMapKeySerializer; @@ -32,12 +31,13 @@ import com.swirlds.merkledb.MerkleDb; import com.swirlds.merkledb.MerkleDbDataSourceBuilder; import com.swirlds.merkledb.MerkleDbTableConfig; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; @@ -47,10 +47,11 @@ import edu.umd.cs.findbugs.annotations.Nullable; import java.util.Iterator; import java.util.List; +import java.util.function.Function; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class MigrationTestingToolState extends PartialNaryMerkleInternal implements MerkleInternal, SwirldState { +public class MigrationTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(MigrationTestingToolState.class); /** @@ -92,8 +93,10 @@ private static class ChildIndices { public NodeId selfId; - public MigrationTestingToolState() { - super(ChildIndices.CHILD_COUNT); + public MigrationTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); } private MigrationTestingToolState(final MigrationTestingToolState that) { @@ -217,6 +220,8 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { + super.init(platform, trigger, previousSoftwareVersion); + final MerkleMap merkleMap = getMerkleMap(); if (merkleMap != null) { logger.info(STARTUP.getMarker(), "MerkleMap initialized with {} values", merkleMap.size()); @@ -272,6 +277,7 @@ public void handleConsensusRound(final Round round, final PlatformStateModifier @Override public MigrationTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new MigrationTestingToolState(this); } diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/module-info.java index e7e8a7f850d1..4e1dd468994d 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/module-info.java @@ -1,4 +1,5 @@ module com.swirlds.demo.migration { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.fcqueue; @@ -7,6 +8,7 @@ requires com.swirlds.merkledb; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.swirlds.virtualmap; requires com.hedera.pbj.runtime; requires java.logging; diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts index 5eddb4203445..e84c41fe4b1d 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/build.gradle.kts @@ -44,6 +44,7 @@ timingSensitiveModuleInfo { requires("com.swirlds.merkle") requires("com.swirlds.merkle.test.fixtures") requires("com.swirlds.platform.core") + requires("com.hedera.node.hapi") requires("org.junit.jupiter.api") requires("org.junit.jupiter.params") requires("org.mockito") diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index e1847a320e8a..a1896d20457e 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -79,8 +79,7 @@ import com.swirlds.platform.listeners.PlatformStatusChangeNotification; import com.swirlds.platform.listeners.ReconnectCompleteListener; import com.swirlds.platform.listeners.StateWriteToDiskCompleteListener; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; @@ -88,6 +87,7 @@ import com.swirlds.platform.system.SystemExitUtils; import com.swirlds.platform.system.state.notifications.NewSignedStateListener; import com.swirlds.platform.system.status.PlatformStatus; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import com.swirlds.virtualmap.internal.merkle.VirtualLeafNode; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.File; @@ -836,10 +836,10 @@ public void run() { @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new PlatformTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new PlatformTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); } private void platformStatusChange(final PlatformStatusChangeNotification notification) { diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 0681177a515e..20b2250969be 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -31,13 +31,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.protobuf.InvalidProtocolBufferException; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.SignatureType; import com.swirlds.common.crypto.TransactionSignature; import com.swirlds.common.crypto.VerificationStatus; -import com.swirlds.common.merkle.MerkleInternal; import com.swirlds.common.merkle.MerkleNode; -import com.swirlds.common.merkle.impl.PartialNaryMerkleInternal; import com.swirlds.common.metrics.RunningAverageMetric; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ThresholdLimitingHandler; @@ -83,12 +82,13 @@ import com.swirlds.merkle.test.fixtures.map.pta.MapKey; import com.swirlds.platform.ParameterProvider; import com.swirlds.platform.Utilities; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.events.Event; @@ -116,6 +116,7 @@ import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; @@ -126,7 +127,7 @@ * writes them to the screen, and also saves them to disk in a comma separated value (.csv) file. Each transaction * consists of an optional sequence number and random bytes. */ -public class PlatformTestingToolState extends PartialNaryMerkleInternal implements MerkleInternal, SwirldState { +public class PlatformTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0xc0900cfa7a24db76L; private static final Logger logger = LogManager.getLogger(PlatformTestingToolState.class); @@ -243,8 +244,10 @@ public class PlatformTestingToolState extends PartialNaryMerkleInternal implemen private long transactionsIgnoredByExpectedMap = 0; - public PlatformTestingToolState() { - super(ChildIndices.CHILD_COUNT); + public PlatformTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); expectedFCMFamily = new ExpectedFCMFamilyImpl(); @@ -651,6 +654,7 @@ public synchronized ExpectedFCMFamily getStateExpectedMap() { @Override public synchronized PlatformTestingToolState copy() { throwIfImmutable(); + setImmutable(true); roundCounter++; if (transactionsIgnoredByExpectedMap > 0) { @@ -1305,6 +1309,7 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { + super.init(platform, trigger, previousSoftwareVersion); if (trigger == InitTrigger.RESTART) { rebuildExpectedMapFromState(Instant.EPOCH, true); diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java index cfa03039efdb..4fa02df0f59a 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java @@ -23,6 +23,7 @@ exports com.swirlds.demo.virtualmerkle.config to com.fasterxml.jackson.databind; + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common.test.fixtures; requires com.swirlds.common; @@ -34,6 +35,7 @@ requires com.swirlds.merkledb; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.swirlds.virtualmap; requires com.fasterxml.jackson.annotation; requires com.fasterxml.jackson.core; diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/timingSensitive/java/com/swirlds/demo/platform/PttTransactionPoolTest.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/timingSensitive/java/com/swirlds/demo/platform/PttTransactionPoolTest.java index 1ff76d7aeb62..5f0fc9b30014 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/timingSensitive/java/com/swirlds/demo/platform/PttTransactionPoolTest.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/timingSensitive/java/com/swirlds/demo/platform/PttTransactionPoolTest.java @@ -43,7 +43,9 @@ import com.swirlds.merkle.test.fixtures.map.lifecycle.LifecycleStatus; import com.swirlds.merkle.test.fixtures.map.lifecycle.TransactionState; import com.swirlds.merkle.test.fixtures.map.pta.MapKey; +import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import java.io.IOException; import java.time.Instant; import java.util.Random; @@ -180,7 +182,8 @@ public void fcqDeleteTest() { .setOriginNode(otherID) .build(); try { - final PlatformTestingToolState state = new PlatformTestingToolState(); + final PlatformTestingToolState state = new PlatformTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(1)); state.setFcmFamily(fCMFamily); handler.performOperation( trans, @@ -237,7 +240,8 @@ public void fcqDeleteNodeTest() { .setOriginNode(otherID) .build(); try { - final PlatformTestingToolState state = new PlatformTestingToolState(); + final PlatformTestingToolState state = new PlatformTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(1)); state.setFcmFamily(fCMFamily); handler.performOperation( trans, diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java index a6db42b89082..7a037e25f601 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java @@ -42,11 +42,11 @@ import com.swirlds.metrics.api.Metrics; import com.swirlds.platform.Browser; import com.swirlds.platform.ParameterProvider; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -272,10 +272,11 @@ private synchronized void generateTransactions() { @Override @NonNull - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new StatsSigningTestingToolState(() -> sttTransactionPool)); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new StatsSigningTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion()), + () -> sttTransactionPool); } /** diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java index 22c71f3f071d..f8a614e9dad7 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java @@ -30,26 +30,25 @@ import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.TESTING_EXCEPTIONS_ACCEPTABLE_RECONNECT; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.TransactionSignature; import com.swirlds.common.crypto.VerificationStatus; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.Round; -import com.swirlds.platform.system.SwirldState; +import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import com.swirlds.platform.system.transaction.Transaction; import edu.umd.cs.findbugs.annotations.NonNull; -import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.function.Function; import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -61,7 +60,7 @@ * is 100 random bytes. So StatsSigningDemoState.handleTransaction doesn't actually do anything, other than the * optional sequence number check. */ -public class StatsSigningTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class StatsSigningTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0x79900efa3127b6eL; /** @@ -80,11 +79,11 @@ public class StatsSigningTestingToolState extends PartialMerkleLeaf implements S /** the number of microseconds to wait before returning from the handle method */ private static final int HANDLE_MICROS = 100; - public StatsSigningTestingToolState() { - this(() -> null); - } - - public StatsSigningTestingToolState(@NonNull final Supplier transactionPoolSupplier) { + public StatsSigningTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory, + @NonNull final Supplier transactionPoolSupplier) { + super(lifecycles, versionFactory); this.transactionPoolSupplier = Objects.requireNonNull(transactionPoolSupplier); } @@ -101,6 +100,7 @@ private StatsSigningTestingToolState(@NonNull final StatsSigningTestingToolState @Override public synchronized StatsSigningTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new StatsSigningTestingToolState(this); } @@ -195,31 +195,6 @@ private boolean validateSignature(final TransactionSignature signature, final Tr return false; } - /** - * {@inheritDoc} - */ - @Override - public void serialize(final SerializableDataOutputStream out) throws IOException { - if (getVersion() >= ClassVersion.KEEP_STATE) { - out.writeLong(runningSum); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(final SerializableDataInputStream in, final int version) throws IOException { - if (version < ClassVersion.KEEP_STATE) { - // In this version we serialized an address book - in.readSerializable(); - } - - if (getVersion() >= ClassVersion.KEEP_STATE) { - runningSum = in.readLong(); - } - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/module-info.java index 509f9f29ca18..0cd6b866b724 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/module-info.java @@ -1,9 +1,11 @@ module com.swirlds.demo.stats.signing { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.logging; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires lazysodium.java; requires org.apache.logging.log4j; diff --git a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java index 817aa74f438e..98229740df6d 100644 --- a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java @@ -39,11 +39,11 @@ import com.swirlds.common.threading.framework.config.ThreadConfiguration; import com.swirlds.metrics.api.Metrics; import com.swirlds.platform.Browser; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.util.List; @@ -231,10 +231,10 @@ private synchronized void generateTransactions() { } @Override - public MerkleRoot newMerkleStateRoot() { - final State state = new State(); - state.setSwirldState(new StressTestingToolState()); - return state; + public MerkleStateRoot newMerkleStateRoot() { + return new StressTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(SOFTWARE_VERSION.getSoftwareVersion())); } /** diff --git a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java index c4885e40e090..d49cb3253adb 100644 --- a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java +++ b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java @@ -26,29 +26,27 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.utility.ByteUtils; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.io.IOException; import java.time.Duration; +import java.util.function.Function; /** * This testing tool simulates configurable processing times for both preHandling and handling for stress testing * purposes. */ -public class StressTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class StressTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0x79900efa3127b6eL; /** A running sum of transaction contents */ @@ -57,8 +55,11 @@ public class StressTestingToolState extends PartialMerkleLeaf implements SwirldS /** supplies the app config */ public StressTestingToolConfig config; - @SuppressWarnings("unused") - public StressTestingToolState() {} + public StressTestingToolState( + @NonNull final MerkleStateLifecycles lifecycles, + @NonNull final Function versionFactory) { + super(lifecycles, versionFactory); + } private StressTestingToolState(@NonNull final StressTestingToolState sourceState) { super(sourceState); @@ -74,6 +75,7 @@ private StressTestingToolState(@NonNull final StressTestingToolState sourceState @Override public synchronized StressTestingToolState copy() { throwIfImmutable(); + setImmutable(true); return new StressTestingToolState(this); } @@ -84,6 +86,8 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { + super.init(platform, trigger, previousSoftwareVersion); + this.config = platform.getContext().getConfiguration().getConfigData(StressTestingToolConfig.class); } @@ -124,22 +128,6 @@ private void busyWait(@NonNull final Duration duration) { } } - /** - * {@inheritDoc} - */ - @Override - public void serialize(@NonNull final SerializableDataOutputStream out) throws IOException { - out.writeLong(runningSum); - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(@NonNull final SerializableDataInputStream in, final int version) throws IOException { - runningSum = in.readLong(); - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/module-info.java index 056479da84b5..237005494096 100644 --- a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/module-info.java @@ -1,10 +1,12 @@ module com.swirlds.demo.stress { + requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common; requires com.swirlds.config.api; requires com.swirlds.logging; requires com.swirlds.metrics.api; requires com.swirlds.platform.core; + requires com.swirlds.state.api; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/State.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/State.java deleted file mode 100644 index 373cd7db8101..000000000000 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/State.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2016-2024 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.state; - -import static com.swirlds.platform.state.MerkleStateUtils.createInfoString; - -import com.swirlds.base.utility.ToStringBuilder; -import com.swirlds.common.merkle.MerkleNode; -import com.swirlds.common.merkle.impl.PartialNaryMerkleInternal; -import com.swirlds.common.merkle.route.MerkleRouteFactory; -import com.swirlds.common.utility.RuntimeObjectRecord; -import com.swirlds.common.utility.RuntimeObjectRegistry; -import com.swirlds.platform.system.SwirldState; -import edu.umd.cs.findbugs.annotations.NonNull; -import java.nio.file.Path; -import java.util.Objects; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * The root of the merkle tree holding the state of the Swirlds ledger. Contains two children: the state used by the - * application and the state used by the platform. - * - * @deprecated This class is deprecated for usage as production code. - * It should be only used for testing purposes and will be moved to testFixtures in 0.54. - */ -@Deprecated(forRemoval = true, since = "0.53.0") -public class State extends PartialNaryMerkleInternal implements MerkleRoot { - - private static final Logger logger = LogManager.getLogger(State.class); - - private static final long CLASS_ID = 0x2971b4ba7dd84402L; - - public static class ClassVersion { - public static final int ORIGINAL = 1; - public static final int ADD_MIN_GEN = 2; - public static final int EVENT_REFACTOR = 3; - public static final int MIGRATE_TO_SERIALIZABLE = 4; - public static final int ADD_DUAL_STATE = 5; - public static final int REMOVE_DUAL_STATE = 6; - public static final int MIGRATE_PLATFORM_STATE = 7; - } - - private static class ChildIndices { - /** - * The state written and used by the application. It is the state resulting from all transactions in consensus - * order from all events with received rounds up through the round this State represents. - */ - public static final int SWIRLD_STATE = 0; - /** - * The state written and used by the platform. - */ - public static final int PLATFORM_STATE = 1; - } - - /** - * Used to track the lifespan of this state. - */ - private final RuntimeObjectRecord registryRecord; - - public State() { - registryRecord = RuntimeObjectRegistry.createRecord(getClass()); - updatePlatformState(new PlatformState()); - } - - private State(final State that) { - super(that); - - registryRecord = RuntimeObjectRegistry.createRecord(getClass()); - - if (that.getSwirldState() != null) { - this.setSwirldState(that.getSwirldState().copy()); - } - if (that.getWritablePlatformState() != null) { - this.updatePlatformState(that.getWritablePlatformState().copy()); - } - } - - /** - * {@inheritDoc} - */ - @Override - public MerkleNode migrate(final int version) { - if (version < ClassVersion.REMOVE_DUAL_STATE) { - throw new UnsupportedOperationException("State migration from version " + version + " is not supported." - + " The minimum supported version is " + getMinimumSupportedVersion()); - } - - if (version < ClassVersion.MIGRATE_PLATFORM_STATE - && getSwirldState() instanceof MerkleStateRoot merkleStateRoot) { - PlatformState platformState = getWritablePlatformState().copy(); - setChild(ChildIndices.PLATFORM_STATE, null); - merkleStateRoot.updatePlatformState(platformState); - merkleStateRoot.setRoute(MerkleRouteFactory.getEmptyRoute()); - return merkleStateRoot.copy(); - } - - return this; - } - - @Override - public void initPlatformState() { - // no initialization required - } - - /** - * {@inheritDoc} - */ - @Override - public int getMinimumSupportedVersion() { - return ClassVersion.REMOVE_DUAL_STATE; - } - - /** - * Get the application state. - * - * @return the application state - */ - @Override - @NonNull - public SwirldState getSwirldState() { - return getChild(ChildIndices.SWIRLD_STATE); - } - - /** - * Set the application state. - * - * @param state the application state - */ - public void setSwirldState(final SwirldState state) { - setChild(ChildIndices.SWIRLD_STATE, state); - } - - /** - * Immutable platform state is not supported by this class. - */ - @NonNull - @Override - public PlatformStateAccessor getReadablePlatformState() { - return getChild(ChildIndices.PLATFORM_STATE); - } - - /** - * Get the platform state. - * @return the platform state - */ - @NonNull - @Override - public PlatformState getWritablePlatformState() { - return getChild(ChildIndices.PLATFORM_STATE); - } - - /** - * Updates the platform state. - * - * @param modifier the platform state - */ - @Override - public void updatePlatformState(@NonNull final PlatformStateModifier modifier) { - if (modifier instanceof PlatformState platformState) { - setChild(ChildIndices.PLATFORM_STATE, platformState); - } else { - throw new UnsupportedOperationException("%s implementation of %s is not supported" - .formatted(modifier.getClass().getSimpleName(), PlatformStateModifier.class.getSimpleName())); - } - } - - /** - * {@inheritDoc} - */ - @Override - public long getClassId() { - return CLASS_ID; - } - - /** - * {@inheritDoc} - */ - @Override - public int getVersion() { - return ClassVersion.MIGRATE_PLATFORM_STATE; - } - - /** - * {@inheritDoc} - */ - @NonNull - @Override - public MerkleRoot copy() { - throwIfImmutable(); - throwIfDestroyed(); - setImmutable(true); - return new State(this); - } - - /** - * {@inheritDoc} - */ - @Override - protected void destroyNode() { - registryRecord.release(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (other == null || getClass() != other.getClass()) { - return false; - } - final MerkleRoot state = (MerkleRoot) other; - return Objects.equals(getReadablePlatformState(), state.getReadablePlatformState()) - && Objects.equals(getSwirldState(), state.getSwirldState()); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hash(getReadablePlatformState(), getSwirldState()); - } - - /** - * Generate a string that describes this state. - * - * @param hashDepth the depth of the tree to visit and print - */ - @NonNull - @Override - public String getInfoString(final int hashDepth) { - final PlatformStateAccessor platformState = getReadablePlatformState(); - return createInfoString(hashDepth, platformState, getHash(), this); - } - - /** - * {@inheritDoc} - */ - @Override - public void createSnapshot(@NonNull final Path targetPath) { - throwIfMutable(); - throwIfDestroyed(); - MerkleTreeSnapshotWriter.createSnapshot(this, targetPath); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return new ToStringBuilder(this) - .append("platformState", getReadablePlatformState()) - .append("swirldState", getSwirldState()) - .toString(); - } -} diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java new file mode 100644 index 000000000000..e5dc0f3479ac --- /dev/null +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2024 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.util; + +import com.hedera.hapi.block.stream.output.StateChanges; +import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ClassConstructorPair; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; +import com.swirlds.common.context.PlatformContext; +import com.swirlds.config.api.Configuration; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.MerkleStateRoot; +import com.swirlds.platform.state.service.PlatformStateService; +import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema; +import com.swirlds.platform.system.*; +import com.swirlds.platform.system.address.AddressBook; +import com.swirlds.platform.system.events.Event; +import com.swirlds.state.State; +import com.swirlds.state.merkle.StateMetadata; +import com.swirlds.state.merkle.singleton.SingletonNode; +import com.swirlds.state.merkle.singleton.StringLeaf; +import com.swirlds.state.merkle.singleton.ValueLeaf; +import com.swirlds.state.spi.*; +import com.swirlds.state.spi.info.NetworkInfo; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { + NO_OP_MERKLE_STATE_LIFECYCLES; + /** + * Register the class IDs for the {@link MerkleStateRoot} and its required children, specifically those + * used by the {@link PlatformStateService}. + */ + public static void registerMerkleStateRootClassIds() { + try { + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + MerkleStateRoot.class, + () -> new MerkleStateRoot( + NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(version.major())))); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(SingletonNode.class, SingletonNode::new)); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); + final var schema = new V0540PlatformStateSchema(); + schema.statesToCreate().stream() + .sorted(Comparator.comparing(StateDefinition::stateKey)) + .forEach(def -> { + final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); + try { + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + ValueLeaf.class, + () -> new ValueLeaf<>( + md.singletonClassId(), + md.stateDefinition().valueCodec()))); + } catch (ConstructableRegistryException e) { + throw new IllegalStateException(e); + } + }); + } catch (ConstructableRegistryException e) { + throw new IllegalStateException(e); + } + } + + @Override + public List initPlatformState(@NonNull final State state) { + if (!(state instanceof MerkleStateRoot merkleStateRoot)) { + throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); + } + final var schema = new V0540PlatformStateSchema(); + schema.statesToCreate().stream() + .sorted(Comparator.comparing(StateDefinition::stateKey)) + .forEach(def -> { + final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); + if (def.singleton()) { + merkleStateRoot.putServiceStateIfAbsent( + md, + () -> new SingletonNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.singletonClassId(), + md.stateDefinition().valueCodec(), + null)); + } else { + throw new IllegalStateException("PlatformStateService only expected to use singleton states"); + } + }); + final var writableStates = state.getWritableStates(PlatformStateService.NAME); + final var migrationContext = new MigrationContext() { + @NonNull + @Override + public ReadableStates previousStates() { + return null; + } + + @NonNull + @Override + public WritableStates newStates() { + return writableStates; + } + + @NonNull + @Override + public Configuration configuration() { + return null; + } + + @Nullable + @Override + public NetworkInfo genesisNetworkInfo() { + return null; + } + + @Override + public long newEntityNum() { + return 0; + } + + @Override + public void copyAndReleaseOnDiskState(String stateKey) { + // no-op + } + + @Nullable + @Override + public SemanticVersion previousVersion() { + return null; + } + + @Override + public Map sharedValues() { + return Map.of(); + } + }; + + schema.migrate(migrationContext); + ((CommittableWritableStates) writableStates).commit(); + return Collections.emptyList(); + } + + @Override + public void onPreHandle(@NonNull Event event, @NonNull State state) { + // no-op + } + + @Override + public void onHandleConsensusRound(@NonNull Round round, @NonNull State state) { + // no-op + } + + @Override + public void onSealConsensusRound(@NonNull Round round, @NonNull State state) { + // Touch this round + round.getRoundNum(); + } + + @Override + public void onStateInitialized( + @NonNull State state, + @NonNull Platform platform, + @NonNull InitTrigger trigger, + @Nullable SoftwareVersion previousVersion) { + // no-op + } + + @Override + public void onUpdateWeight( + @NonNull MerkleStateRoot state, @NonNull AddressBook configAddressBook, @NonNull PlatformContext context) { + // no-op + } + + @Override + public void onNewRecoveredState(@NonNull MerkleStateRoot recoveredState) { + // no-op + } +} diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/state/StateRegistryTests.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/state/StateRegistryTests.java index 666e81660311..9b380f87b0d2 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/state/StateRegistryTests.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/state/StateRegistryTests.java @@ -81,7 +81,10 @@ void activeStateCountTest() throws IOException { // Restore the registry to its original condition at boot time RuntimeObjectRegistry.reset(); - assertEquals(0, RuntimeObjectRegistry.getActiveObjectsCount(State.class), "no states have been created yet"); + assertEquals( + 0, + RuntimeObjectRegistry.getActiveObjectsCount(MerkleStateRoot.class), + "no states have been created yet"); final List states = new LinkedList<>(); // Create a bunch of states diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/Turtle.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/Turtle.java index fd00324d1209..04fdf341fdbc 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/Turtle.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/Turtle.java @@ -16,11 +16,16 @@ package com.swirlds.platform.turtle.runner; +import static com.swirlds.platform.test.fixtures.state.FakeMerkleStateLifecycles.FAKE_MERKLE_STATE_LIFECYCLES; + import com.swirlds.base.test.fixtures.time.FakeTime; +import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.platform.NodeId; import com.swirlds.common.test.fixtures.Randotron; +import com.swirlds.platform.state.MerkleStateRoot; +import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.test.fixtures.addressbook.RandomAddressBookBuilder; import com.swirlds.platform.test.fixtures.turtle.gossip.SimulatedNetwork; @@ -96,7 +101,11 @@ public class Turtle { timeReportingEnabled = builder.isTimeReportingEnabled(); try { - ConstructableRegistry.getInstance().registerConstructables(""); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + MerkleStateRoot.class, + () -> new MerkleStateRoot( + FAKE_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(1)))); } catch (final ConstructableRegistryException e) { throw new RuntimeException(e); } diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java index 6ab2196681e3..4d308da41d42 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java @@ -16,18 +16,13 @@ package com.swirlds.platform.turtle.runner; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import static com.swirlds.platform.test.fixtures.state.FakeMerkleStateLifecycles.FAKE_MERKLE_STATE_LIFECYCLES; + import com.swirlds.common.utility.NonCryptographicHashing; -import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.PlatformStateModifier; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.*; +import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Round; -import com.swirlds.platform.system.SwirldState; import edu.umd.cs.findbugs.annotations.NonNull; -import java.io.IOException; /** * A simple testing application intended for use with TURTLE. @@ -37,7 +32,7 @@ * ﹉∏﹉∏﹉ ﹉∏﹉∏﹉ * */ -public class TurtleTestingToolState extends PartialMerkleLeaf implements SwirldState, MerkleLeaf { +public class TurtleTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0xa49b3822a4136ac6L; @@ -48,18 +43,18 @@ private static final class ClassVersion { private long state; - /** - * Zero arg constructor needed for constructable registry. - */ - public TurtleTestingToolState() {} + public TurtleTestingToolState() { + super(FAKE_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(1)); + } /** * Copy constructor. * - * @param that the object to copy + * @param from the object to copy */ - private TurtleTestingToolState(@NonNull final TurtleTestingToolState that) { - this.state = that.state; + private TurtleTestingToolState(@NonNull final TurtleTestingToolState from) { + super(from); + this.state = from.state; } /** @@ -95,25 +90,11 @@ public void handleConsensusRound(@NonNull final Round round, @NonNull final Plat */ @Override public TurtleTestingToolState copy() { + throwIfImmutable(); + setImmutable(true); return new TurtleTestingToolState(this); } - /** - * {@inheritDoc} - */ - @Override - public void serialize(@NonNull final SerializableDataOutputStream out) throws IOException { - out.writeLong(state); - } - - /** - * {@inheritDoc} - */ - @Override - public void deserialize(@NonNull final SerializableDataInputStream in, final int version) throws IOException { - state = in.readLong(); - } - /** * Creates a merkle node to act as a state tree root. * @@ -121,9 +102,6 @@ public void deserialize(@NonNull final SerializableDataInputStream in, final int */ @NonNull public static MerkleRoot getStateRootNode() { - final TurtleTestingToolState turtleState = new TurtleTestingToolState(); - final State root = new State(); - root.setSwirldState(turtleState); - return root; + return new TurtleTestingToolState(); } } diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTest.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTest.java index b10df3e51d89..a78a789bface 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTest.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTest.java @@ -30,7 +30,6 @@ import com.swirlds.platform.crypto.CryptoStatic; import com.swirlds.platform.state.MerkleRoot; import com.swirlds.platform.state.MerkleStateRoot; -import com.swirlds.platform.state.State; import com.swirlds.platform.state.signed.SignedState; import com.swirlds.platform.system.BasicSoftwareVersion; import java.util.Random; @@ -86,14 +85,13 @@ void tryReserveTest() { private static SignedState randomSignedState() { Random random = new Random(0); - State root = new State(); - root.setSwirldState(new MerkleStateRoot( - FAKE_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major()))); + MerkleStateRoot merkleStateRoot = + new MerkleStateRoot(FAKE_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())); boolean shouldSaveToDisk = random.nextBoolean(); SignedState signedState = new SignedState( TestPlatformContextBuilder.create().build(), CryptoStatic::verifySignature, - root, + merkleStateRoot, "test", shouldSaveToDisk, false, diff --git a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTests.java b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTests.java index d8569b653915..780c02336dd7 100644 --- a/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTests.java +++ b/platform-sdk/swirlds-unit-tests/core/swirlds-platform-test/src/test/java/com/swirlds/platform/test/StateTests.java @@ -27,7 +27,7 @@ import com.swirlds.common.test.fixtures.junit.tags.TestComponentTags; import com.swirlds.config.extensions.test.fixtures.TestConfigBuilder; import com.swirlds.platform.state.MerkleRoot; -import com.swirlds.platform.state.State; +import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.test.fixtures.state.BlockingSwirldState; import java.io.IOException; import java.nio.file.Path; @@ -40,7 +40,7 @@ @DisplayName("State Tests") class StateTests { - private static State state; + private static MerkleStateRoot merkleStateRoot; /** * Temporary directory provided by JUnit */ @@ -53,11 +53,10 @@ static void setUp() throws ConstructableRegistryException { ConstructableRegistry.getInstance().registerConstructables("com.swirlds"); - state = new State(); - state.setSwirldState(new BlockingSwirldState()); + merkleStateRoot = new BlockingSwirldState(); - state.invalidateHash(); - MerkleCryptoFactory.getInstance().digestTreeSync(state); + merkleStateRoot.invalidateHash(); + MerkleCryptoFactory.getInstance().digestTreeSync(merkleStateRoot); } @Test @@ -67,25 +66,25 @@ static void setUp() throws ConstructableRegistryException { void stateSerializationTest() throws IOException { InputOutputStream io = new InputOutputStream(); - io.getOutput().writeMerkleTree(testDirectory, state); + io.getOutput().writeMerkleTree(testDirectory, merkleStateRoot); io.startReading(); final MerkleRoot decodedState = io.getInput().readMerkleTree(testDirectory, Integer.MAX_VALUE); MerkleCryptoFactory.getInstance().digestTreeSync(decodedState); - assertEquals(state.getHash(), decodedState.getHash(), "expected trees to be equal"); - assertTrue(areTreesEqual(state, decodedState), "expected trees to be equal"); + assertEquals(merkleStateRoot.getHash(), decodedState.getHash(), "expected trees to be equal"); + assertTrue(areTreesEqual(merkleStateRoot, decodedState), "expected trees to be equal"); } @Test @Tag(TestComponentTags.PLATFORM) @DisplayName("State Copy Test") void stateCopyTest() { - final MerkleRoot copiedState = state.copy(); + final MerkleRoot copiedState = merkleStateRoot.copy(); MerkleCryptoFactory.getInstance().digestTreeSync(copiedState); - assertEquals(state.getHash(), copiedState.getHash(), "expected trees to be equal"); - assertTrue(areTreesEqual(state, copiedState), "expected trees to be equal"); + assertEquals(merkleStateRoot.getHash(), copiedState.getHash(), "expected trees to be equal"); + assertTrue(areTreesEqual(merkleStateRoot, copiedState), "expected trees to be equal"); } } From 91f73b7915cd37ed3368d32619e7fe4a57693ac3 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 31 Oct 2024 19:09:52 +0200 Subject: [PATCH 02/59] fix: PTT unit tests Signed-off-by: Nikita Lebedev --- .../java/com/swirlds/demo/platform/ControlActionTest.java | 6 +++++- .../swirlds/demo/platform/MapValueSerializableTest.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java index bf95cdeef257..1cf8476d39a7 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.test.fixtures.io.InputOutputStream; @@ -32,7 +33,10 @@ public class ControlActionTest { @BeforeAll public static void setUp() throws ConstructableRegistryException { - ConstructableRegistry.getInstance().registerConstructables("com.swirlds"); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(QuorumResult.class, QuorumResult::new)); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(ControlAction.class, ControlAction::new)); } @Test diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java index 083c0b70884b..9990fe5c54fe 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.crypto.Hash; @@ -36,6 +37,7 @@ import com.swirlds.demo.merkle.map.MapValueFCQ; import com.swirlds.demo.merkle.map.internal.DummyExpectedFCMFamily; import com.swirlds.demo.merkle.map.internal.ExpectedFCMFamily; +import com.swirlds.demo.platform.actions.QuorumResult; import com.swirlds.demo.platform.expiration.ExpirationRecordEntry; import com.swirlds.merkle.map.MerkleMap; import com.swirlds.merkle.test.fixtures.map.lifecycle.ExpectedValue; @@ -78,7 +80,10 @@ class MapValueSerializableTest { @BeforeAll public static void setUp() throws ConstructableRegistryException { - ConstructableRegistry.getInstance().registerConstructables("com.swirlds"); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(QuorumResult.class, QuorumResult::new)); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair(ControlAction.class, ControlAction::new)); cryptography = MerkleCryptoFactory.getInstance(); } From c33c409b08ad874dc018c053159cf10a9da0e26d Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 31 Oct 2024 19:26:17 +0200 Subject: [PATCH 03/59] fix: add ConstructableIgnored annotations Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/crypto/CryptocurrencyDemoState.java | 2 ++ .../java/com/swirlds/demo/hello/HelloSwirldDemoState.java | 2 ++ .../main/java/com/swirlds/demo/stats/StatsDemoState.java | 2 ++ .../demo/addressbook/AddressBookTestingToolState.java | 2 ++ .../demo/consistency/ConsistencyTestingToolState.java | 2 ++ .../java/com/swirlds/demo/iss/ISSTestingToolState.java | 2 ++ .../swirlds/demo/migration/MigrationTestingToolState.java | 2 ++ .../swirlds/demo/platform/PlatformTestingToolState.java | 2 ++ .../java/com/swirlds/demo/platform/ControlActionTest.java | 6 +----- .../swirlds/demo/platform/MapValueSerializableTest.java | 7 +------ .../demo/stats/signing/StatsSigningTestingToolState.java | 2 ++ .../com/swirlds/demo/stress/StressTestingToolState.java | 2 ++ 12 files changed, 22 insertions(+), 11 deletions(-) diff --git a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java index ec6d22e39cb3..8225e5ba318f 100644 --- a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java +++ b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoState.java @@ -28,6 +28,7 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.pbj.runtime.io.buffer.Bytes; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.platform.NodeId; import com.swirlds.platform.SwirldsPlatform; import com.swirlds.platform.state.MerkleStateLifecycles; @@ -60,6 +61,7 @@ * entirely new cryptocurrency is created every time all the computers start the program over again, so * these cryptocurrencies won't have any actual value. */ +@ConstructableIgnored public class CryptocurrencyDemoState extends MerkleStateRoot { /** diff --git a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java index bca84ac24137..9ac33b259c35 100644 --- a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java +++ b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoState.java @@ -27,6 +27,7 @@ */ import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; @@ -44,6 +45,7 @@ * a string, and the state is just a list of the strings in all the transactions handled so far, in the * order that they were handled. */ +@ConstructableIgnored public class HelloSwirldDemoState extends MerkleStateRoot { /** diff --git a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java index ed560940bd06..dc4662f77807 100644 --- a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java +++ b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoState.java @@ -27,6 +27,7 @@ */ import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; @@ -42,6 +43,7 @@ * is 100 random bytes. So StatsDemoState.handleTransaction doesn't actually do anything, other than the * optional sequence number check. */ +@ConstructableIgnored public class StatsDemoState extends MerkleStateRoot { /** diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java index b8c9d29ba674..a645256569f5 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java @@ -36,6 +36,7 @@ import static com.swirlds.platform.state.address.AddressBookInitializer.USED_ADDRESS_BOOK_HEADER; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.context.PlatformContext; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ByteUtils; @@ -72,6 +73,7 @@ /** * State for the AddressBookTestingTool. */ +@ConstructableIgnored public class AddressBookTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(AddressBookTestingToolState.class); diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 75a00c91033c..b9690237c8ed 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -22,6 +22,7 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.config.StateCommonConfig; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.utility.NonCryptographicHashing; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; @@ -49,6 +50,7 @@ /** * State for the Consistency Testing Tool */ +@ConstructableIgnored public class ConsistencyTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(ConsistencyTestingToolState.class); private static final long CLASS_ID = 0xda03bb07eb897d82L; diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java index d9cd03d6a99a..8e1426261e81 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java @@ -33,6 +33,7 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.merkle.utility.SerializableLong; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ByteUtils; @@ -66,6 +67,7 @@ /** * State for the ISSTestingTool. */ +@ConstructableIgnored public class ISSTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(ISSTestingToolState.class); diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java index 833032225a13..bdc180e2c40b 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java @@ -20,6 +20,7 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.crypto.DigestType; import com.swirlds.common.merkle.MerkleNode; import com.swirlds.common.platform.NodeId; @@ -51,6 +52,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +@ConstructableIgnored public class MigrationTestingToolState extends MerkleStateRoot { private static final Logger logger = LogManager.getLogger(MigrationTestingToolState.class); diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 20b2250969be..b140e97361f2 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.SignatureType; import com.swirlds.common.crypto.TransactionSignature; @@ -127,6 +128,7 @@ * writes them to the screen, and also saves them to disk in a comma separated value (.csv) file. Each transaction * consists of an optional sequence number and random bytes. */ +@ConstructableIgnored public class PlatformTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0xc0900cfa7a24db76L; diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java index 1cf8476d39a7..bf95cdeef257 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/ControlActionTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.test.fixtures.io.InputOutputStream; @@ -33,10 +32,7 @@ public class ControlActionTest { @BeforeAll public static void setUp() throws ConstructableRegistryException { - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(QuorumResult.class, QuorumResult::new)); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(ControlAction.class, ControlAction::new)); + ConstructableRegistry.getInstance().registerConstructables("com.swirlds"); } @Test diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java index 9990fe5c54fe..083c0b70884b 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/test/java/com/swirlds/demo/platform/MapValueSerializableTest.java @@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.crypto.Hash; @@ -37,7 +36,6 @@ import com.swirlds.demo.merkle.map.MapValueFCQ; import com.swirlds.demo.merkle.map.internal.DummyExpectedFCMFamily; import com.swirlds.demo.merkle.map.internal.ExpectedFCMFamily; -import com.swirlds.demo.platform.actions.QuorumResult; import com.swirlds.demo.platform.expiration.ExpirationRecordEntry; import com.swirlds.merkle.map.MerkleMap; import com.swirlds.merkle.test.fixtures.map.lifecycle.ExpectedValue; @@ -80,10 +78,7 @@ class MapValueSerializableTest { @BeforeAll public static void setUp() throws ConstructableRegistryException { - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(QuorumResult.class, QuorumResult::new)); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(ControlAction.class, ControlAction::new)); + ConstructableRegistry.getInstance().registerConstructables("com.swirlds"); cryptography = MerkleCryptoFactory.getInstance(); } diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java index f8a614e9dad7..cd78c30a16cf 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolState.java @@ -31,6 +31,7 @@ import static com.swirlds.logging.legacy.LogMarker.TESTING_EXCEPTIONS_ACCEPTABLE_RECONNECT; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.TransactionSignature; import com.swirlds.common.crypto.VerificationStatus; @@ -60,6 +61,7 @@ * is 100 random bytes. So StatsSigningDemoState.handleTransaction doesn't actually do anything, other than the * optional sequence number check. */ +@ConstructableIgnored public class StatsSigningTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0x79900efa3127b6eL; diff --git a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java index d49cb3253adb..92bda480b8ed 100644 --- a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java +++ b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolState.java @@ -27,6 +27,7 @@ */ import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.utility.ByteUtils; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; @@ -46,6 +47,7 @@ * This testing tool simulates configurable processing times for both preHandling and handling for stress testing * purposes. */ +@ConstructableIgnored public class StressTestingToolState extends MerkleStateRoot { private static final long CLASS_ID = 0x79900efa3127b6eL; From 84e2bbdeb383e4518e52e51686d81485ebd28c66 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 31 Oct 2024 21:07:17 +0200 Subject: [PATCH 04/59] chore: update MTT and PTT Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/migration/MigrationTestingToolState.java | 1 + .../java/com/swirlds/demo/platform/PlatformTestingToolState.java | 1 + 2 files changed, 2 insertions(+) diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java index bdc180e2c40b..2787c23fed39 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java @@ -99,6 +99,7 @@ public MigrationTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { super(lifecycles, versionFactory); + allocateSpaceForChild(ChildIndices.CHILD_COUNT); } private MigrationTestingToolState(final MigrationTestingToolState that) { diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index b140e97361f2..bf24213c028d 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -250,6 +250,7 @@ public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { super(lifecycles, versionFactory); + allocateSpaceForChild(ChildIndices.CHILD_COUNT); expectedFCMFamily = new ExpectedFCMFamilyImpl(); From cfbfa2d92b185128f0266c07aa434407ef4dadc6 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 12:39:36 +0200 Subject: [PATCH 05/59] update after merging develop Signed-off-by: Nikita Lebedev --- .../com/swirlds/platform/util/NoOpMerkleStateLifecycles.java | 1 - 1 file changed, 1 deletion(-) diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index e5dc0f3479ac..0622055d40ca 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -83,7 +83,6 @@ public static void registerMerkleStateRootClassIds() { } } - @Override public List initPlatformState(@NonNull final State state) { if (!(state instanceof MerkleStateRoot merkleStateRoot)) { throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); From aaaea3a9b81d95876f9a233d3303ed10f546de52 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 12:54:23 +0200 Subject: [PATCH 06/59] fix jrs Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index bf24213c028d..e63f5d7ec47d 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -1684,7 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 11; + public static final int CHILD_COUNT = 12; } @Override From 6df5bc8a100f89be87eb0c95bfd902ba38a8ccd2 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 13:05:38 +0200 Subject: [PATCH 07/59] spotless Signed-off-by: Nikita Lebedev --- .../java/com/swirlds/demo/iss/ISSTestingToolState.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java index 42ae384a83ec..1e4e19e87a8f 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java @@ -33,13 +33,9 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; -import com.swirlds.common.constructable.ConstructableIgnored; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; -import com.swirlds.common.io.streams.SerializableDataInputStream; -import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.merkle.MerkleLeaf; -import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.merkle.utility.SerializableLong; import com.swirlds.common.platform.NodeId; import com.swirlds.common.utility.ByteUtils; @@ -51,9 +47,6 @@ import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; -import com.swirlds.platform.system.address.Address; -import com.swirlds.platform.system.address.AddressBook; -import com.swirlds.platform.system.SwirldState; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; From c55bd10cda080f1ca30a37420e41760472070399 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 18:34:04 +0200 Subject: [PATCH 08/59] fix turtle tests Signed-off-by: Nikita Lebedev --- .../com/swirlds/platform/turtle/runner/TurtleNode.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleNode.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleNode.java index eb5463b7318c..0ef3e72fe510 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleNode.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleNode.java @@ -18,6 +18,7 @@ import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager; import static com.swirlds.platform.builder.internal.StaticPlatformBuilder.getMetricsProvider; +import static com.swirlds.platform.builder.internal.StaticPlatformBuilder.setupGlobalMetrics; import static com.swirlds.platform.state.signed.StartupStateUtils.getInitialState; import static com.swirlds.platform.system.address.AddressBookUtils.createRoster; @@ -90,6 +91,8 @@ public class TurtleNode { .withValue(BasicConfig_.JVM_PAUSE_DETECTOR_SLEEP_MS, "0") .getOrCreateConfig(); + setupGlobalMetrics(configuration); + final PlatformContext platformContext = TestPlatformContextBuilder.create() .withTime(time) .withConfiguration(configuration) @@ -101,11 +104,10 @@ public class TurtleNode { final Supplier genesisStateSupplier = TurtleTestingToolState::getStateRootNode; final var version = new BasicSoftwareVersion(1); - final NodeId selfId = null; - final var metrics = getMetricsProvider().createPlatformMetrics(selfId); + final var metrics = getMetricsProvider().createPlatformMetrics(nodeId); final var fileSystemManager = FileSystemManager.create(configuration); final var recycleBin = - RecycleBin.create(metrics, configuration, getStaticThreadManager(), time, fileSystemManager, selfId); + RecycleBin.create(metrics, configuration, getStaticThreadManager(), time, fileSystemManager, nodeId); final var reservedState = getInitialState( configuration, recycleBin, version, genesisStateSupplier, "foo", "bar", nodeId, addressBook); From 282808e6e6d18e4b4ba45f3d854d188eb43953e7 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 18:56:06 +0200 Subject: [PATCH 09/59] fix init platform state Signed-off-by: Nikita Lebedev --- .../java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java | 4 +++- .../main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java | 4 +++- .../src/main/java/com/swirlds/demo/stats/StatsDemoMain.java | 4 +++- .../swirlds/demo/addressbook/AddressBookTestingToolMain.java | 4 +++- .../swirlds/demo/consistency/ConsistencyTestingToolMain.java | 4 +++- .../main/java/com/swirlds/demo/iss/ISSTestingToolMain.java | 4 +++- .../com/swirlds/demo/migration/MigrationTestingToolMain.java | 4 +++- .../com/swirlds/demo/platform/PlatformTestingToolMain.java | 4 +++- .../demo/stats/signing/StatsSigningTestingToolMain.java | 4 +++- .../java/com/swirlds/demo/stress/StressTestingToolMain.java | 4 +++- .../platform/turtle/runner/TurtleTestingToolState.java | 4 +++- 11 files changed, 33 insertions(+), 11 deletions(-) diff --git a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java index 34656f5d268c..d6de55759f65 100644 --- a/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java +++ b/platform-sdk/platform-apps/demos/CryptocurrencyDemo/src/main/java/com/swirlds/demo/crypto/CryptocurrencyDemoMain.java @@ -183,9 +183,11 @@ public void run() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new CryptocurrencyDemoState( + final MerkleStateRoot state = new CryptocurrencyDemoState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java index b3872ec8ae57..236de5ca7703 100644 --- a/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java +++ b/platform-sdk/platform-apps/demos/HelloSwirldDemo/src/main/java/com/swirlds/demo/hello/HelloSwirldDemoMain.java @@ -110,9 +110,11 @@ public void run() { @NonNull @Override public MerkleStateRoot newMerkleStateRoot() { - return new HelloSwirldDemoState( + final MerkleStateRoot state = new HelloSwirldDemoState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } private void platformStatusChange(final PlatformStatusChangeNotification notification) { diff --git a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java index 5a6f1ad7bf1a..27a7cb63063b 100644 --- a/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java +++ b/platform-sdk/platform-apps/demos/StatsDemo/src/main/java/com/swirlds/demo/stats/StatsDemoMain.java @@ -298,9 +298,11 @@ private String valueAsString(final Metric metric) { @NonNull @Override public MerkleStateRoot newMerkleStateRoot() { - return new StatsDemoState( + final MerkleStateRoot state = new StatsDemoState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java index af19fb09a94b..eff2c97441d2 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolMain.java @@ -106,9 +106,11 @@ public void run() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new AddressBookTestingToolState( + final MerkleStateRoot state = new AddressBookTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index 85d52ec7ae7e..9707c58457e9 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -89,9 +89,11 @@ public void run() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new ConsistencyTestingToolState( + final MerkleStateRoot state = new ConsistencyTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java index 3ecf0ed47acd..dcbe18542c62 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java @@ -90,9 +90,11 @@ public void run() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new ISSTestingToolState( + final MerkleStateRoot state = new ISSTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java index 2ad1b650960a..78959e527143 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolMain.java @@ -167,9 +167,11 @@ private void throttleTransactionCreation() throws InterruptedException { @NonNull @Override public MerkleStateRoot newMerkleStateRoot() { - return new MigrationTestingToolState( + final MerkleStateRoot state = new MigrationTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index a1896d20457e..acab88f3a605 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -837,9 +837,11 @@ public void run() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new PlatformTestingToolState( + final MerkleStateRoot state = new PlatformTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } private void platformStatusChange(final PlatformStatusChangeNotification notification) { diff --git a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java index 7a037e25f601..325a995ee4f8 100644 --- a/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/StatsSigningTestingTool/src/main/java/com/swirlds/demo/stats/signing/StatsSigningTestingToolMain.java @@ -273,10 +273,12 @@ private synchronized void generateTransactions() { @Override @NonNull public MerkleStateRoot newMerkleStateRoot() { - return new StatsSigningTestingToolState( + final MerkleStateRoot state = new StatsSigningTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion()), () -> sttTransactionPool); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java index 98229740df6d..dd91221963c4 100644 --- a/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/StressTestingTool/src/main/java/com/swirlds/demo/stress/StressTestingToolMain.java @@ -232,9 +232,11 @@ private synchronized void generateTransactions() { @Override public MerkleStateRoot newMerkleStateRoot() { - return new StressTestingToolState( + final MerkleStateRoot state = new StressTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(SOFTWARE_VERSION.getSoftwareVersion())); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } /** diff --git a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java index 4d308da41d42..e954300d27a6 100644 --- a/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java +++ b/platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/turtle/runner/TurtleTestingToolState.java @@ -102,6 +102,8 @@ public TurtleTestingToolState copy() { */ @NonNull public static MerkleRoot getStateRootNode() { - return new TurtleTestingToolState(); + final MerkleStateRoot state = new TurtleTestingToolState(); + FAKE_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } } From 67e63df807cb00869489a593533d820fae14196c Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 20:01:34 +0200 Subject: [PATCH 10/59] fix jrs Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index e63f5d7ec47d..d349af5c947f 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -1684,7 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 12; + public static final int CHILD_COUNT = 13; } @Override From 21a9891b7810ee5b80792731c755f0bf8e3ec16b Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 4 Nov 2024 21:24:36 +0200 Subject: [PATCH 11/59] add logging to NoOpMerkleStateLifecycles Signed-off-by: Nikita Lebedev --- .../util/NoOpMerkleStateLifecycles.java | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index 0622055d40ca..1f6d532b318a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -18,9 +18,6 @@ import com.hedera.hapi.block.stream.output.StateChanges; import com.hedera.hapi.node.base.SemanticVersion; -import com.swirlds.common.constructable.ClassConstructorPair; -import com.swirlds.common.constructable.ConstructableRegistry; -import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.context.PlatformContext; import com.swirlds.config.api.Configuration; import com.swirlds.platform.state.MerkleStateLifecycles; @@ -33,8 +30,6 @@ import com.swirlds.state.State; import com.swirlds.state.merkle.StateMetadata; import com.swirlds.state.merkle.singleton.SingletonNode; -import com.swirlds.state.merkle.singleton.StringLeaf; -import com.swirlds.state.merkle.singleton.ValueLeaf; import com.swirlds.state.spi.*; import com.swirlds.state.spi.info.NetworkInfo; import edu.umd.cs.findbugs.annotations.NonNull; @@ -43,51 +38,20 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { NO_OP_MERKLE_STATE_LIFECYCLES; - /** - * Register the class IDs for the {@link MerkleStateRoot} and its required children, specifically those - * used by the {@link PlatformStateService}. - */ - public static void registerMerkleStateRootClassIds() { - try { - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair( - MerkleStateRoot.class, - () -> new MerkleStateRoot( - NO_OP_MERKLE_STATE_LIFECYCLES, - version -> new BasicSoftwareVersion(version.major())))); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(SingletonNode.class, SingletonNode::new)); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); - final var schema = new V0540PlatformStateSchema(); - schema.statesToCreate().stream() - .sorted(Comparator.comparing(StateDefinition::stateKey)) - .forEach(def -> { - final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); - try { - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair( - ValueLeaf.class, - () -> new ValueLeaf<>( - md.singletonClassId(), - md.stateDefinition().valueCodec()))); - } catch (ConstructableRegistryException e) { - throw new IllegalStateException(e); - } - }); - } catch (ConstructableRegistryException e) { - throw new IllegalStateException(e); - } - } + + private static final Logger logger = LogManager.getLogger(NoOpMerkleStateLifecycles.class); public List initPlatformState(@NonNull final State state) { if (!(state instanceof MerkleStateRoot merkleStateRoot)) { throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); } final var schema = new V0540PlatformStateSchema(); + logger.info("schema.statesToCreate() size: {}", schema.statesToCreate().size()); schema.statesToCreate().stream() .sorted(Comparator.comparing(StateDefinition::stateKey)) .forEach(def -> { From 4d2f136bf74b97950db4baaf8346334325da684d Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 09:26:35 +0200 Subject: [PATCH 12/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolMain.java | 1 + .../demo/platform/PlatformTestingToolState.java | 14 ++++++-------- .../platform/util/NoOpMerkleStateLifecycles.java | 6 +++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index acab88f3a605..c00ede4c135e 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -840,6 +840,7 @@ public MerkleStateRoot newMerkleStateRoot() { final MerkleStateRoot state = new PlatformTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); + logger.info(LOGM_STARTUP, "Initializing platform state..."); NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); return state; } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index d349af5c947f..8ac9e7098dcd 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -255,6 +255,12 @@ public PlatformTestingToolState( expectedFCMFamily = new ExpectedFCMFamilyImpl(); referenceNftLedger = new ReferenceNftLedger(NFT_TRACKING_FRACTION); + + logger.info( + LOGM_STARTUP, + "PlatformTestingToolState constructor... Current child count: {} | Max child count: {} ", + getNumberOfChildren(), + getMaximumChildCount()); } protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { @@ -415,14 +421,6 @@ private static void getCurrentTransactionStat() { static AtomicLong totalTransactionSignatureCount = new AtomicLong(0); static AtomicLong expectedInvalidSignatureCount = new AtomicLong(0); - /** - * {@inheritDoc} - */ - @Override - public int getNumberOfChildren() { - return ChildIndices.CHILD_COUNT; - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index 1f6d532b318a..dec2f5714ea2 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -40,6 +40,7 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.MarkerManager; public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { NO_OP_MERKLE_STATE_LIFECYCLES; @@ -51,7 +52,10 @@ public List initPlatformState(@NonNull final State state) throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); } final var schema = new V0540PlatformStateSchema(); - logger.info("schema.statesToCreate() size: {}", schema.statesToCreate().size()); + logger.info( + MarkerManager.getMarker("DEMO_INFO"), + "schema.statesToCreate() size: {}", + schema.statesToCreate().size()); schema.statesToCreate().stream() .sorted(Comparator.comparing(StateDefinition::stateKey)) .forEach(def -> { From 1f091466b8e1f26dcbee202063a0b82e11bf00fb Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 11:35:34 +0200 Subject: [PATCH 13/59] ptt increase CHILD_COUNT Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 8ac9e7098dcd..5dff26ed5e84 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -1682,7 +1682,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 13; + public static final int CHILD_COUNT = 15; } @Override From a00208522a33fa87ee804e6c78c18c5fde146f1e Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 12:42:56 +0200 Subject: [PATCH 14/59] ptt increase CHILD_COUNT Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolState.java | 16 +++++++++------- .../platform/util/NoOpMerkleStateLifecycles.java | 4 ---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 5dff26ed5e84..eae2cf7ee250 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -255,12 +255,6 @@ public PlatformTestingToolState( expectedFCMFamily = new ExpectedFCMFamilyImpl(); referenceNftLedger = new ReferenceNftLedger(NFT_TRACKING_FRACTION); - - logger.info( - LOGM_STARTUP, - "PlatformTestingToolState constructor... Current child count: {} | Max child count: {} ", - getNumberOfChildren(), - getMaximumChildCount()); } protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { @@ -421,6 +415,14 @@ private static void getCurrentTransactionStat() { static AtomicLong totalTransactionSignatureCount = new AtomicLong(0); static AtomicLong expectedInvalidSignatureCount = new AtomicLong(0); + /** + * {@inheritDoc} + */ + @Override + public int getNumberOfChildren() { + return ChildIndices.CHILD_COUNT; + } + /** * {@inheritDoc} */ @@ -1682,7 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 15; + public static final int CHILD_COUNT = 40; } @Override diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index dec2f5714ea2..6577b0e15b31 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -52,10 +52,6 @@ public List initPlatformState(@NonNull final State state) throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); } final var schema = new V0540PlatformStateSchema(); - logger.info( - MarkerManager.getMarker("DEMO_INFO"), - "schema.statesToCreate() size: {}", - schema.statesToCreate().size()); schema.statesToCreate().stream() .sorted(Comparator.comparing(StateDefinition::stateKey)) .forEach(def -> { From 26692ab5ef25c8139a4acc5ca94d03959aac0a29 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 12:43:27 +0200 Subject: [PATCH 15/59] spotless Signed-off-by: Nikita Lebedev --- .../com/swirlds/platform/util/NoOpMerkleStateLifecycles.java | 1 - 1 file changed, 1 deletion(-) diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index 6577b0e15b31..2e929fb8c712 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -40,7 +40,6 @@ import java.util.Map; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.MarkerManager; public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { NO_OP_MERKLE_STATE_LIFECYCLES; From c706c40591168a639830471e5d1f8b4e0897b5b5 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 13:51:19 +0200 Subject: [PATCH 16/59] PTT CHILD_COUNT experiment Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index eae2cf7ee250..6db263a08adc 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -1684,7 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 40; + public static final int CHILD_COUNT = 64; } @Override From 5a59b7212a06fd0ea7c1cfb78abf7f133ab8dd58 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 17:34:54 +0200 Subject: [PATCH 17/59] PTT debugging Signed-off-by: Nikita Lebedev --- .../swirlds/demo/platform/PlatformTestingToolState.java | 8 -------- .../java/com/swirlds/platform/state/MerkleStateRoot.java | 6 ++++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 6db263a08adc..066444a7e4b7 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -415,14 +415,6 @@ private static void getCurrentTransactionStat() { static AtomicLong totalTransactionSignatureCount = new AtomicLong(0); static AtomicLong expectedInvalidSignatureCount = new AtomicLong(0); - /** - * {@inheritDoc} - */ - @Override - public int getNumberOfChildren() { - return ChildIndices.CHILD_COUNT; - } - /** * {@inheritDoc} */ diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java index 3fc3e4fdd178..5d801a3c3915 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java @@ -525,6 +525,12 @@ public void putServiceStateIfAbsent( "A label must be computed based on the same " + "service name and state key in the metadata!"); } + logger.info( + STARTUP.getMarker(), + "Setting child.. Service name: {} / Number of children: {} / node: {}", + md.serviceName(), + getNumberOfChildren(), + nodeIndex); setChild(getNumberOfChildren(), node); } else { node = getChild(nodeIndex); From b27ad3b595a95c4b9b5be1dd6c45c7faabc08873 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 18:50:11 +0200 Subject: [PATCH 18/59] PTT fixing Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolState.java | 12 ++++++++++-- .../com/swirlds/platform/state/MerkleStateRoot.java | 2 +- .../platform/util/NoOpMerkleStateLifecycles.java | 4 ---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 066444a7e4b7..7dae46a4234f 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -415,6 +415,14 @@ private static void getCurrentTransactionStat() { static AtomicLong totalTransactionSignatureCount = new AtomicLong(0); static AtomicLong expectedInvalidSignatureCount = new AtomicLong(0); + /** + * {@inheritDoc} + */ + @Override + public int getNumberOfChildren() { + return ChildIndices.CHILD_COUNT; + } + /** * {@inheritDoc} */ @@ -428,7 +436,7 @@ public int getMinimumChildCount() { */ @Override public int getMaximumChildCount() { - return ChildIndices.CHILD_COUNT; + return ChildIndices.CHILD_COUNT + 1; } /** @@ -1676,7 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 64; + public static final int CHILD_COUNT = 11; } @Override diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java index 5d801a3c3915..43efcbe11522 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java @@ -530,7 +530,7 @@ public void putServiceStateIfAbsent( "Setting child.. Service name: {} / Number of children: {} / node: {}", md.serviceName(), getNumberOfChildren(), - nodeIndex); + node); setChild(getNumberOfChildren(), node); } else { node = getChild(nodeIndex); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index 2e929fb8c712..a0bf1e290a2e 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -38,14 +38,10 @@ import java.util.Comparator; import java.util.List; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { NO_OP_MERKLE_STATE_LIFECYCLES; - private static final Logger logger = LogManager.getLogger(NoOpMerkleStateLifecycles.class); - public List initPlatformState(@NonNull final State state) { if (!(state instanceof MerkleStateRoot merkleStateRoot)) { throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); From 579517a4402eea74dbf8422f63eb4816c1dc0aed Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 19:52:57 +0200 Subject: [PATCH 19/59] PTT fixing Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolMain.java | 2 +- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index c00ede4c135e..deacc635a0d9 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -841,7 +841,7 @@ public MerkleStateRoot newMerkleStateRoot() { NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); logger.info(LOGM_STARTUP, "Initializing platform state..."); - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + // NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); return state; } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 7dae46a4234f..2e4f6762c40a 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -436,7 +436,7 @@ public int getMinimumChildCount() { */ @Override public int getMaximumChildCount() { - return ChildIndices.CHILD_COUNT + 1; + return ChildIndices.CHILD_COUNT; } /** @@ -1312,7 +1312,7 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { - super.init(platform, trigger, previousSoftwareVersion); + // super.init(platform, trigger, previousSoftwareVersion); if (trigger == InitTrigger.RESTART) { rebuildExpectedMapFromState(Instant.EPOCH, true); From 22c790996ba4c942ce6ed426b9eaa815184b3576 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 5 Nov 2024 21:06:53 +0200 Subject: [PATCH 20/59] PTT fixing Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolMain.java | 2 +- .../demo/platform/PlatformTestingToolState.java | 11 ++++++++--- .../com/swirlds/platform/state/MerkleStateRoot.java | 6 ------ .../swirlds/state/merkle/singleton/SingletonNode.java | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index deacc635a0d9..c00ede4c135e 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -841,7 +841,7 @@ public MerkleStateRoot newMerkleStateRoot() { NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); logger.info(LOGM_STARTUP, "Initializing platform state..."); - // NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); return state; } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 2e4f6762c40a..46684a5f6ee8 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -95,6 +95,7 @@ import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import com.swirlds.platform.system.transaction.Transaction; +import com.swirlds.state.merkle.singleton.SingletonNode; import com.swirlds.virtualmap.VirtualMap; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -436,7 +437,7 @@ public int getMinimumChildCount() { */ @Override public int getMaximumChildCount() { - return ChildIndices.CHILD_COUNT; + return ChildIndices.CHILD_COUNT + 1; } /** @@ -469,6 +470,8 @@ public boolean childHasExpectedType(final int index, final long childClassId) { return childClassId == VirtualMap.CLASS_ID || childClassId == NULL_CLASS_ID; case ChildIndices.QUORUM_RESULT: return childClassId == QuorumResult.CLASS_ID; + case ChildIndices.SINGLETON_NODE: + return childClassId == SingletonNode.CLASS_ID; default: return false; } @@ -1312,7 +1315,7 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { - // super.init(platform, trigger, previousSoftwareVersion); + super.init(platform, trigger, previousSoftwareVersion); if (trigger == InitTrigger.RESTART) { rebuildExpectedMapFromState(Instant.EPOCH, true); @@ -1684,7 +1687,9 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int CHILD_COUNT = 11; + public static final int SINGLETON_NODE = 11; + + public static final int CHILD_COUNT = 12; } @Override diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java index 43efcbe11522..3fc3e4fdd178 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java @@ -525,12 +525,6 @@ public void putServiceStateIfAbsent( "A label must be computed based on the same " + "service name and state key in the metadata!"); } - logger.info( - STARTUP.getMarker(), - "Setting child.. Service name: {} / Number of children: {} / node: {}", - md.serviceName(), - getNumberOfChildren(), - node); setChild(getNumberOfChildren(), node); } else { node = getChild(nodeIndex); diff --git a/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/merkle/singleton/SingletonNode.java b/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/merkle/singleton/SingletonNode.java index 76f8ec9816bb..10cb1298f358 100644 --- a/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/merkle/singleton/SingletonNode.java +++ b/platform-sdk/swirlds-state-api/src/main/java/com/swirlds/state/merkle/singleton/SingletonNode.java @@ -37,7 +37,7 @@ */ @DebugIterationEndpoint public class SingletonNode extends PartialBinaryMerkleInternal implements Labeled, MerkleInternal { - static final long CLASS_ID = 0x3832CC837AB77BFL; + public static final long CLASS_ID = 0x3832CC837AB77BFL; public static final int CLASS_VERSION = 1; /** From 15b0c329801f986dc4fa6a994f932275cceccdaf Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 14:11:03 +0200 Subject: [PATCH 21/59] fix: PTT Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 46684a5f6ee8..bb8ce5c311a4 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -470,7 +470,7 @@ public boolean childHasExpectedType(final int index, final long childClassId) { return childClassId == VirtualMap.CLASS_ID || childClassId == NULL_CLASS_ID; case ChildIndices.QUORUM_RESULT: return childClassId == QuorumResult.CLASS_ID; - case ChildIndices.SINGLETON_NODE: + case 11, 12: // temp return childClassId == SingletonNode.CLASS_ID; default: return false; @@ -1689,7 +1689,7 @@ private static class ChildIndices { public static final int SINGLETON_NODE = 11; - public static final int CHILD_COUNT = 12; + public static final int CHILD_COUNT = 13; } @Override From 6db8463ccfb8c316b2c02b8896ed9c2c1a6f56dc Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 14:31:48 +0200 Subject: [PATCH 22/59] fix: compilation error Signed-off-by: Nikita Lebedev --- .../tests/PlatformTestingTool/src/main/java/module-info.java | 1 + .../com/swirlds/platform/util/NoOpMerkleStateLifecycles.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java index 4fa02df0f59a..c614af2f8e6a 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java @@ -36,6 +36,7 @@ requires com.swirlds.metrics.api; requires com.swirlds.platform.core; requires com.swirlds.state.api; + requires com.swirlds.state.impl; requires com.swirlds.virtualmap; requires com.fasterxml.jackson.annotation; requires com.fasterxml.jackson.core; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index a0bf1e290a2e..d8d380584c96 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -28,10 +28,12 @@ import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.Event; import com.swirlds.state.State; +import com.swirlds.state.lifecycle.MigrationContext; +import com.swirlds.state.lifecycle.StateDefinition; +import com.swirlds.state.lifecycle.info.NetworkInfo; import com.swirlds.state.merkle.StateMetadata; import com.swirlds.state.merkle.singleton.SingletonNode; import com.swirlds.state.spi.*; -import com.swirlds.state.spi.info.NetworkInfo; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.util.Collections; From 9dcbc1471af2acd02b578ce61afce9ee9586a977 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 16:17:07 +0200 Subject: [PATCH 23/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolState.java | 11 +++++++---- .../src/main/java/module-info.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index bb8ce5c311a4..400b71af1e7e 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -95,7 +95,6 @@ import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import com.swirlds.platform.system.transaction.Transaction; -import com.swirlds.state.merkle.singleton.SingletonNode; import com.swirlds.virtualmap.VirtualMap; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -445,6 +444,12 @@ public int getMaximumChildCount() { */ @Override public boolean childHasExpectedType(final int index, final long childClassId) { + logger.info( + DEMO_INFO.getMarker(), + "Checking if childHasExpectedType for index: {} and childClassId: {} ", + index, + childClassId); + switch (index) { case ChildIndices.UNUSED: // We used to use this for an address book, but now we don't use this index. @@ -470,10 +475,8 @@ public boolean childHasExpectedType(final int index, final long childClassId) { return childClassId == VirtualMap.CLASS_ID || childClassId == NULL_CLASS_ID; case ChildIndices.QUORUM_RESULT: return childClassId == QuorumResult.CLASS_ID; - case 11, 12: // temp - return childClassId == SingletonNode.CLASS_ID; default: - return false; + return true; // temp } } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java index c614af2f8e6a..c9e756da8c87 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java @@ -23,6 +23,7 @@ exports com.swirlds.demo.virtualmerkle.config to com.fasterxml.jackson.databind; + // requires com.swirlds.state.impl; requires com.hedera.node.hapi; requires com.swirlds.base; requires com.swirlds.common.test.fixtures; @@ -36,7 +37,6 @@ requires com.swirlds.metrics.api; requires com.swirlds.platform.core; requires com.swirlds.state.api; - requires com.swirlds.state.impl; requires com.swirlds.virtualmap; requires com.fasterxml.jackson.annotation; requires com.fasterxml.jackson.core; From 2caa5a3a9b51c23f1c9d140599dfb5d1f1c2e9e8 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 19:37:35 +0200 Subject: [PATCH 24/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../platform/PlatformTestingToolState.java | 2 +- .../platform/state/MerkleStateRoot.java | 19 ++++++++++++++++++- .../util/NoOpMerkleStateLifecycles.java | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 400b71af1e7e..ef58c509624b 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -250,7 +250,7 @@ public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { super(lifecycles, versionFactory); - allocateSpaceForChild(ChildIndices.CHILD_COUNT); + // allocateSpaceForChild(ChildIndices.CHILD_COUNT); expectedFCMFamily = new ExpectedFCMFamilyImpl(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java index a4ffddbad224..b87d76992926 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java @@ -16,7 +16,7 @@ package com.swirlds.platform.state; -import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; +import static com.swirlds.logging.legacy.LogMarker.*; import static com.swirlds.platform.state.MerkleStateUtils.createInfoString; import static com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema.PLATFORM_STATE_KEY; import static com.swirlds.platform.system.InitTrigger.EVENT_STREAM_RECOVERY; @@ -432,6 +432,8 @@ public void putServiceStateIfAbsent( @NonNull final Supplier nodeSupplier, @NonNull final Consumer nodeInitializer) { + logger.info(STARTUP.getMarker(), "Putting states... ", md.serviceName()); + // Validate the inputs throwIfImmutable(); requireNonNull(md); @@ -449,6 +451,8 @@ public void putServiceStateIfAbsent( readableStatesMap.put(serviceName, new MerkleReadableStates(stateMetadata)); writableStatesMap.put(serviceName, new MerkleWritableStates(serviceName, stateMetadata)); + logger.info(STARTUP.getMarker(), "Put states! Service name: {} ", md.serviceName()); + // Look for a node, and if we don't find it, then insert the one we were given // If there is not a node there, then set it. I don't want to overwrite the existing node, // because it may have been loaded from state on disk, and the node provided here in this @@ -478,8 +482,21 @@ public void putServiceStateIfAbsent( "A label must be computed based on the same " + "service name and state key in the metadata!"); } + logger.info( + STARTUP.getMarker(), + "Setting child.. Service name: {} / Number of children: {} / node: {}", + md.serviceName(), + getNumberOfChildren(), + nodeIndex); setChild(getNumberOfChildren(), node); } else { + logger.info( + STARTUP.getMarker(), + "Getting child.. Service name: {} / Number of children: {} / node: {}", + md.serviceName(), + getNumberOfChildren(), + nodeIndex); + node = getChild(nodeIndex); } nodeInitializer.accept(node); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java index d8d380584c96..5de7b6e9373f 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/util/NoOpMerkleStateLifecycles.java @@ -40,11 +40,18 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.MarkerManager; public enum NoOpMerkleStateLifecycles implements MerkleStateLifecycles { NO_OP_MERKLE_STATE_LIFECYCLES; + private static final Logger logger = LogManager.getLogger(NoOpMerkleStateLifecycles.class); + public List initPlatformState(@NonNull final State state) { + logger.info(MarkerManager.getMarker("DEMO_INFO"), "Init Platform State..."); + if (!(state instanceof MerkleStateRoot merkleStateRoot)) { throw new IllegalArgumentException("Can only be used with MerkleStateRoot instances"); } @@ -66,7 +73,11 @@ public List initPlatformState(@NonNull final State state) throw new IllegalStateException("PlatformStateService only expected to use singleton states"); } }); + final var writableStates = state.getWritableStates(PlatformStateService.NAME); + + logger.info(MarkerManager.getMarker("DEMO_INFO"), "Writable states: {}", writableStates.stateKeys()); + final var migrationContext = new MigrationContext() { @NonNull @Override @@ -114,6 +125,11 @@ public Map sharedValues() { } }; + logger.info( + MarkerManager.getMarker("DEMO_INFO"), + "(MigrationContext) Writable states: {}", + migrationContext.newStates().stateKeys()); + schema.migrate(migrationContext); ((CommittableWritableStates) writableStates).commit(); return Collections.emptyList(); From a8f26b5ff23ff37e01ceb1d7245c6d749885d2ee Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 20:39:12 +0200 Subject: [PATCH 25/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../platform/PlatformTestingToolState.java | 20 ++++++------------- .../platform/state/MerkleStateRoot.java | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index ef58c509624b..795df568530f 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -250,6 +250,7 @@ public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { super(lifecycles, versionFactory); + // don't need it but keep for a while // allocateSpaceForChild(ChildIndices.CHILD_COUNT); expectedFCMFamily = new ExpectedFCMFamilyImpl(); @@ -415,14 +416,6 @@ private static void getCurrentTransactionStat() { static AtomicLong totalTransactionSignatureCount = new AtomicLong(0); static AtomicLong expectedInvalidSignatureCount = new AtomicLong(0); - /** - * {@inheritDoc} - */ - @Override - public int getNumberOfChildren() { - return ChildIndices.CHILD_COUNT; - } - /** * {@inheritDoc} */ @@ -436,7 +429,7 @@ public int getMinimumChildCount() { */ @Override public int getMaximumChildCount() { - return ChildIndices.CHILD_COUNT + 1; + return ChildIndices.CHILD_COUNT; } /** @@ -454,6 +447,7 @@ public boolean childHasExpectedType(final int index, final long childClassId) { case ChildIndices.UNUSED: // We used to use this for an address book, but now we don't use this index. // Ignore whatever is found at this index. + // platform should be here, so check for singleton if all will be ok return true; case ChildIndices.CONFIG: return childClassId == PayloadCfgSimple.CLASS_ID; @@ -476,7 +470,7 @@ public boolean childHasExpectedType(final int index, final long childClassId) { case ChildIndices.QUORUM_RESULT: return childClassId == QuorumResult.CLASS_ID; default: - return true; // temp + return false; } } @@ -1660,7 +1654,7 @@ private static class ClassVersion { } private static class ChildIndices { - public static final int UNUSED = 0; + public static final int UNUSED = 0; // should be platform and singleton public static final int CONFIG = 1; /** * last sequence by each member for consensus events @@ -1690,9 +1684,7 @@ private static class ChildIndices { public static final int QUORUM_RESULT = 10; - public static final int SINGLETON_NODE = 11; - - public static final int CHILD_COUNT = 13; + public static final int CHILD_COUNT = 11; } @Override diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java index b87d76992926..b1f63a2d318a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/MerkleStateRoot.java @@ -487,7 +487,7 @@ public void putServiceStateIfAbsent( "Setting child.. Service name: {} / Number of children: {} / node: {}", md.serviceName(), getNumberOfChildren(), - nodeIndex); + node); setChild(getNumberOfChildren(), node); } else { logger.info( From 6d6216a744470a8736148c3d197f2bfde6b8fb81 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Thu, 7 Nov 2024 21:52:46 +0200 Subject: [PATCH 26/59] ptt fixing Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 795df568530f..b5693ffef108 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -657,7 +657,7 @@ public synchronized ExpectedFCMFamily getStateExpectedMap() { @Override public synchronized PlatformTestingToolState copy() { throwIfImmutable(); - setImmutable(true); + // setImmutable(true); roundCounter++; if (transactionsIgnoredByExpectedMap > 0) { @@ -1312,7 +1312,7 @@ public void init( @NonNull final Platform platform, @NonNull final InitTrigger trigger, @Nullable final SoftwareVersion previousSoftwareVersion) { - super.init(platform, trigger, previousSoftwareVersion); + // super.init(platform, trigger, previousSoftwareVersion); if (trigger == InitTrigger.RESTART) { rebuildExpectedMapFromState(Instant.EPOCH, true); From 739900d6404adc8d0173b24401dc3c94abdffb60 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 10:50:22 +0200 Subject: [PATCH 27/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PayloadCfgSimple.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 759054d4549f..15262e2c8404 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -23,9 +23,16 @@ import com.swirlds.common.merkle.MerkleLeaf; import com.swirlds.common.merkle.impl.PartialMerkleLeaf; import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; public class PayloadCfgSimple extends PartialMerkleLeaf implements MerkleLeaf { + private static final Logger logger = LogManager.getLogger(PlatformTestingToolState.class); + private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); + /** * The version history of this class. * Versions that have been released must NEVER be given a different value. @@ -160,10 +167,13 @@ private static class ClassVersion { */ private float ratioOfFCMTransaction; - public PayloadCfgSimple() {} + public PayloadCfgSimple() { + logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple constructor, immutable: {}", isImmutable()); + } private PayloadCfgSimple(final PayloadCfgSimple sourcePayload) { super(sourcePayload); + logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple constructor COPY, immutable: {}", isImmutable()); setAppendSig(sourcePayload.appendSig); setInvalidSigRatio(sourcePayload.invalidSigRatio); setInsertSeq(sourcePayload.insertSeq); @@ -381,6 +391,7 @@ public void setRatioOfFCMTransaction(final float ratioOfFCMTransaction) { */ @Override public PayloadCfgSimple copy() { + logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple copy method, immutable: {}", isImmutable()); throwIfImmutable(); return new PayloadCfgSimple(this); } From 313a04b00d148500f435ae903e86c9ef63496786 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 12:30:20 +0200 Subject: [PATCH 28/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/platform/PayloadCfgSimple.java | 7 ++++++- .../demo/platform/PlatformTestingToolState.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 15262e2c8404..660c89510e19 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -22,6 +22,7 @@ import com.swirlds.common.io.streams.SerializableDataOutputStream; import com.swirlds.common.merkle.MerkleLeaf; import com.swirlds.common.merkle.impl.PartialMerkleLeaf; +import com.swirlds.common.utility.StackTrace; import java.io.IOException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -391,7 +392,11 @@ public void setRatioOfFCMTransaction(final float ratioOfFCMTransaction) { */ @Override public PayloadCfgSimple copy() { - logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple copy method, immutable: {}", isImmutable()); + logger.info( + LOGM_DEMO_INFO, + "PayloadCfgSimple copy method, immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); throwIfImmutable(); return new PayloadCfgSimple(this); } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index b5693ffef108..eca6f6dada56 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -40,6 +40,7 @@ import com.swirlds.common.merkle.MerkleNode; import com.swirlds.common.metrics.RunningAverageMetric; import com.swirlds.common.platform.NodeId; +import com.swirlds.common.utility.StackTrace; import com.swirlds.common.utility.ThresholdLimitingHandler; import com.swirlds.demo.merkle.map.FCMConfig; import com.swirlds.demo.merkle.map.FCMFamily; @@ -250,6 +251,9 @@ public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { super(lifecycles, versionFactory); + + logger.info(LOGM_DEMO_INFO, "PlatformTestingToolState constructor, immutable: {}", isImmutable()); + // don't need it but keep for a while // allocateSpaceForChild(ChildIndices.CHILD_COUNT); @@ -261,6 +265,8 @@ public PlatformTestingToolState( protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { super(sourceState); + logger.info(LOGM_DEMO_INFO, "PlatformTestingToolState constructor COPY, immutable: {}", isImmutable()); + this.initialized.set(sourceState.initialized.get()); this.platform = sourceState.platform; @@ -656,6 +662,12 @@ public synchronized ExpectedFCMFamily getStateExpectedMap() { */ @Override public synchronized PlatformTestingToolState copy() { + logger.info( + LOGM_DEMO_INFO, + "PlatformTestingToolState copy method, immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); + throwIfImmutable(); // setImmutable(true); roundCounter++; From 1f0e4722b304d04c7d00bb14e2c477a7ae879f58 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 14:26:34 +0200 Subject: [PATCH 29/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../swirlds/demo/merkle/map/FCMFamily.java | 2 +- .../demo/platform/PayloadCfgSimple.java | 16 ++++++++++---- .../platform/PlatformTestingToolState.java | 22 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java index 1a4287c70785..9e233e6a3b99 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java @@ -133,7 +133,7 @@ private FCMFamily(final FCMFamily other) { */ @Override public FCMFamily copy() { - throwIfImmutable(); + throwIfImmutable(); // double check if this line needs to be removed throwIfDestroyed(); return new FCMFamily(this); diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 660c89510e19..7589d84c7281 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -169,12 +169,20 @@ private static class ClassVersion { private float ratioOfFCMTransaction; public PayloadCfgSimple() { - logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple constructor, immutable: {}", isImmutable()); + logger.info( + LOGM_DEMO_INFO, + "PayloadCfgSimple., immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); } private PayloadCfgSimple(final PayloadCfgSimple sourcePayload) { super(sourcePayload); - logger.info(LOGM_DEMO_INFO, "PayloadCfgSimple constructor COPY, immutable: {}", isImmutable()); + logger.info( + LOGM_DEMO_INFO, + "PayloadCfgSimple.(COPY), immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); setAppendSig(sourcePayload.appendSig); setInvalidSigRatio(sourcePayload.invalidSigRatio); setInsertSeq(sourcePayload.insertSeq); @@ -394,10 +402,10 @@ public void setRatioOfFCMTransaction(final float ratioOfFCMTransaction) { public PayloadCfgSimple copy() { logger.info( LOGM_DEMO_INFO, - "PayloadCfgSimple copy method, immutable: {}, StackTrace: {}", + "PayloadCfgSimple.copy(), immutable: {}, StackTrace: {}", isImmutable(), StackTrace.getStackTrace()); - throwIfImmutable(); + // throwIfImmutable(); return new PayloadCfgSimple(this); } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index eca6f6dada56..a915041d497b 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -252,10 +252,11 @@ public PlatformTestingToolState( @NonNull final Function versionFactory) { super(lifecycles, versionFactory); - logger.info(LOGM_DEMO_INFO, "PlatformTestingToolState constructor, immutable: {}", isImmutable()); - - // don't need it but keep for a while - // allocateSpaceForChild(ChildIndices.CHILD_COUNT); + logger.info( + LOGM_DEMO_INFO, + "PlatformTestingToolState., immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); expectedFCMFamily = new ExpectedFCMFamilyImpl(); @@ -265,7 +266,11 @@ public PlatformTestingToolState( protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { super(sourceState); - logger.info(LOGM_DEMO_INFO, "PlatformTestingToolState constructor COPY, immutable: {}", isImmutable()); + logger.info( + LOGM_DEMO_INFO, + "PlatformTestingToolState.(COPY), immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); this.initialized.set(sourceState.initialized.get()); this.platform = sourceState.platform; @@ -445,9 +450,10 @@ public int getMaximumChildCount() { public boolean childHasExpectedType(final int index, final long childClassId) { logger.info( DEMO_INFO.getMarker(), - "Checking if childHasExpectedType for index: {} and childClassId: {} ", + "Checking if childHasExpectedType for index: {}, childClassId: {}, StackTrace: {}", index, - childClassId); + childClassId, + StackTrace.getStackTrace()); switch (index) { case ChildIndices.UNUSED: @@ -664,7 +670,7 @@ public synchronized ExpectedFCMFamily getStateExpectedMap() { public synchronized PlatformTestingToolState copy() { logger.info( LOGM_DEMO_INFO, - "PlatformTestingToolState copy method, immutable: {}, StackTrace: {}", + "PlatformTestingToolState.copy() immutable: {}, StackTrace: {}", isImmutable(), StackTrace.getStackTrace()); From 14677260b464816a4d89d0e57d7382a62a0c4880 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 15:35:59 +0200 Subject: [PATCH 30/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java index 9e233e6a3b99..07fffb6fddb4 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java @@ -133,7 +133,7 @@ private FCMFamily(final FCMFamily other) { */ @Override public FCMFamily copy() { - throwIfImmutable(); // double check if this line needs to be removed + // throwIfImmutable(); // double check if this line needs to be removed throwIfDestroyed(); return new FCMFamily(this); From 13f1b547bcdd92d35e842b40fd5213c402178c25 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 18:05:37 +0200 Subject: [PATCH 31/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../swirlds/demo/merkle/map/FCMFamily.java | 2 +- .../demo/platform/PayloadCfgSimple.java | 2 +- .../platform/PlatformTestingToolState.java | 79 ++++++++++--------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java index 07fffb6fddb4..1a4287c70785 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/merkle/map/FCMFamily.java @@ -133,7 +133,7 @@ private FCMFamily(final FCMFamily other) { */ @Override public FCMFamily copy() { - // throwIfImmutable(); // double check if this line needs to be removed + throwIfImmutable(); throwIfDestroyed(); return new FCMFamily(this); diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 7589d84c7281..216ab2c5be17 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -405,7 +405,7 @@ public PayloadCfgSimple copy() { "PayloadCfgSimple.copy(), immutable: {}, StackTrace: {}", isImmutable(), StackTrace.getStackTrace()); - // throwIfImmutable(); + throwIfImmutable(); return new PayloadCfgSimple(this); } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index a915041d497b..29b32ed08ddd 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -275,33 +275,34 @@ protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { this.initialized.set(sourceState.initialized.get()); this.platform = sourceState.platform; - if (sourceState.getConfig() != null) { - setConfig(sourceState.getConfig().copy()); - } - - if (sourceState.getNextSeqCons() != null) { - setNextSeqCons(new NextSeqConsList(sourceState.getNextSeqCons())); - } - - if (sourceState.getFcmFamily() != null) { - setFcmFamily(sourceState.getFcmFamily().copy()); - } else { - setFcmFamily(new FCMFamily(true)); - } - - if (sourceState.getVirtualMap() != null) { - setVirtualMap(sourceState.getVirtualMap().copy()); - } - - if (sourceState.getVirtualMapForSmartContracts() != null) { - setVirtualMapForSmartContracts( - sourceState.getVirtualMapForSmartContracts().copy()); - } - - if (sourceState.getVirtualMapForSmartContractsByteCode() != null) { - setVirtualMapForSmartContractsByteCode( - sourceState.getVirtualMapForSmartContractsByteCode().copy()); - } + // commented because copying happens in super + // if (sourceState.getConfig() != null) { + // setConfig(sourceState.getConfig().copy()); + // } + // + // if (sourceState.getNextSeqCons() != null) { + // setNextSeqCons(new NextSeqConsList(sourceState.getNextSeqCons())); + // } + // + // if (sourceState.getFcmFamily() != null) { + // setFcmFamily(sourceState.getFcmFamily().copy()); + // } else { + // setFcmFamily(new FCMFamily(true)); + // } + // + // if (sourceState.getVirtualMap() != null) { + // setVirtualMap(sourceState.getVirtualMap().copy()); + // } + // + // if (sourceState.getVirtualMapForSmartContracts() != null) { + // setVirtualMapForSmartContracts( + // sourceState.getVirtualMapForSmartContracts().copy()); + // } + // + // if (sourceState.getVirtualMapForSmartContractsByteCode() != null) { + // setVirtualMapForSmartContractsByteCode( + // sourceState.getVirtualMapForSmartContractsByteCode().copy()); + // } this.lastFileTranFinishTimeStamp = sourceState.lastFileTranFinishTimeStamp; this.lastTranTimeStamp = sourceState.lastTranTimeStamp; @@ -333,21 +334,21 @@ protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { } } - if (sourceState.getIssLeaf() != null) { - setIssLeaf(sourceState.getIssLeaf().copy()); - } + // if (sourceState.getIssLeaf() != null) { + // setIssLeaf(sourceState.getIssLeaf().copy()); + // } - if (sourceState.getNftLedger() != null) { - setNftLedger(sourceState.getNftLedger().copy()); - } + // if (sourceState.getNftLedger() != null) { + // setNftLedger(sourceState.getNftLedger().copy()); + // } // set the current value of QuorumResult from source state - if (sourceState.getQuorumResult() != null) { - setQuorumResult(sourceState.getQuorumResult().copy()); - } - if (controlQuorum != null) { - controlQuorum.setQuorumResult(getQuorumResult().copy()); - } + // if (sourceState.getQuorumResult() != null) { + // setQuorumResult(sourceState.getQuorumResult().copy()); + // } + // if (controlQuorum != null) { + // controlQuorum.setQuorumResult(getQuorumResult().copy()); + // } setImmutable(false); sourceState.setImmutable(true); From e1baae0ba54f8cd353d0db9405301296d50c015a Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 8 Nov 2024 19:39:56 +0200 Subject: [PATCH 32/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../swirlds/demo/platform/PayloadCfgSimple.java | 2 +- .../demo/platform/TransactionCounter.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 216ab2c5be17..872862129d5a 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -31,7 +31,7 @@ public class PayloadCfgSimple extends PartialMerkleLeaf implements MerkleLeaf { - private static final Logger logger = LogManager.getLogger(PlatformTestingToolState.class); + private static final Logger logger = LogManager.getLogger(PayloadCfgSimple.class); private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); /** diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java index caa21f720524..cfac9990ebb5 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java @@ -20,6 +20,7 @@ import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; import com.swirlds.common.io.streams.SerializableDataOutputStream; +import com.swirlds.common.utility.StackTrace; import java.io.IOException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,6 +32,8 @@ */ public class TransactionCounter implements Cloneable, FastCopyable, SelfSerializable { + private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); + /** * The version history of this class. * Versions that have been released must NEVER be given a different value. @@ -102,6 +105,12 @@ public TransactionCounter(int nodeId) { public TransactionCounter() {} private TransactionCounter(final TransactionCounter sourceTransactionCounter) { + logger.info( + LOGM_DEMO_INFO, + "TransactionCounter.(COPY), immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); + this.fcmCreateAmount = sourceTransactionCounter.fcmCreateAmount; this.fcmUpdateAmount = sourceTransactionCounter.fcmUpdateAmount; this.fcmDeleteAmount = sourceTransactionCounter.fcmDeleteAmount; @@ -129,7 +138,12 @@ private TransactionCounter(final TransactionCounter sourceTransactionCounter) { @Override public TransactionCounter copy() { - throwIfImmutable(); + logger.info( + LOGM_DEMO_INFO, + "TransactionCounter.copy(), immutable: {}, StackTrace: {}", + isImmutable(), + StackTrace.getStackTrace()); + // throwIfImmutable(); return new TransactionCounter(this); } From 700548c4865f7f6469dca8a635cf7cb14cfe7a6b Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 11 Nov 2024 09:35:48 +0200 Subject: [PATCH 33/59] commented logging Signed-off-by: Nikita Lebedev --- .../demo/platform/PayloadCfgSimple.java | 31 +++++++------ .../platform/PlatformTestingToolState.java | 43 +++++++++---------- .../demo/platform/TransactionCounter.java | 23 +++++----- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java index 872862129d5a..4a45c94775a2 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PayloadCfgSimple.java @@ -22,7 +22,6 @@ import com.swirlds.common.io.streams.SerializableDataOutputStream; import com.swirlds.common.merkle.MerkleLeaf; import com.swirlds.common.merkle.impl.PartialMerkleLeaf; -import com.swirlds.common.utility.StackTrace; import java.io.IOException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -169,20 +168,20 @@ private static class ClassVersion { private float ratioOfFCMTransaction; public PayloadCfgSimple() { - logger.info( - LOGM_DEMO_INFO, - "PayloadCfgSimple., immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PayloadCfgSimple., immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); } private PayloadCfgSimple(final PayloadCfgSimple sourcePayload) { super(sourcePayload); - logger.info( - LOGM_DEMO_INFO, - "PayloadCfgSimple.(COPY), immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PayloadCfgSimple.(COPY), immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); setAppendSig(sourcePayload.appendSig); setInvalidSigRatio(sourcePayload.invalidSigRatio); setInsertSeq(sourcePayload.insertSeq); @@ -400,11 +399,11 @@ public void setRatioOfFCMTransaction(final float ratioOfFCMTransaction) { */ @Override public PayloadCfgSimple copy() { - logger.info( - LOGM_DEMO_INFO, - "PayloadCfgSimple.copy(), immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PayloadCfgSimple.copy(), immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); throwIfImmutable(); return new PayloadCfgSimple(this); } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 29b32ed08ddd..4766d45fb332 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -40,7 +40,6 @@ import com.swirlds.common.merkle.MerkleNode; import com.swirlds.common.metrics.RunningAverageMetric; import com.swirlds.common.platform.NodeId; -import com.swirlds.common.utility.StackTrace; import com.swirlds.common.utility.ThresholdLimitingHandler; import com.swirlds.demo.merkle.map.FCMConfig; import com.swirlds.demo.merkle.map.FCMFamily; @@ -252,11 +251,11 @@ public PlatformTestingToolState( @NonNull final Function versionFactory) { super(lifecycles, versionFactory); - logger.info( - LOGM_DEMO_INFO, - "PlatformTestingToolState., immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PlatformTestingToolState., immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); expectedFCMFamily = new ExpectedFCMFamilyImpl(); @@ -266,11 +265,11 @@ public PlatformTestingToolState( protected PlatformTestingToolState(final PlatformTestingToolState sourceState) { super(sourceState); - logger.info( - LOGM_DEMO_INFO, - "PlatformTestingToolState.(COPY), immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PlatformTestingToolState.(COPY), immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); this.initialized.set(sourceState.initialized.get()); this.platform = sourceState.platform; @@ -449,12 +448,12 @@ public int getMaximumChildCount() { */ @Override public boolean childHasExpectedType(final int index, final long childClassId) { - logger.info( - DEMO_INFO.getMarker(), - "Checking if childHasExpectedType for index: {}, childClassId: {}, StackTrace: {}", - index, - childClassId, - StackTrace.getStackTrace()); + // logger.info( + // DEMO_INFO.getMarker(), + // "Checking if childHasExpectedType for index: {}, childClassId: {}, StackTrace: {}", + // index, + // childClassId, + // StackTrace.getStackTrace()); switch (index) { case ChildIndices.UNUSED: @@ -669,11 +668,11 @@ public synchronized ExpectedFCMFamily getStateExpectedMap() { */ @Override public synchronized PlatformTestingToolState copy() { - logger.info( - LOGM_DEMO_INFO, - "PlatformTestingToolState.copy() immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "PlatformTestingToolState.copy() immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); throwIfImmutable(); // setImmutable(true); diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java index cfac9990ebb5..6e6cc87b9e37 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/TransactionCounter.java @@ -20,7 +20,6 @@ import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; import com.swirlds.common.io.streams.SerializableDataOutputStream; -import com.swirlds.common.utility.StackTrace; import java.io.IOException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -32,7 +31,7 @@ */ public class TransactionCounter implements Cloneable, FastCopyable, SelfSerializable { - private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); + // private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); /** * The version history of this class. @@ -105,11 +104,11 @@ public TransactionCounter(int nodeId) { public TransactionCounter() {} private TransactionCounter(final TransactionCounter sourceTransactionCounter) { - logger.info( - LOGM_DEMO_INFO, - "TransactionCounter.(COPY), immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "TransactionCounter.(COPY), immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); this.fcmCreateAmount = sourceTransactionCounter.fcmCreateAmount; this.fcmUpdateAmount = sourceTransactionCounter.fcmUpdateAmount; @@ -138,11 +137,11 @@ private TransactionCounter(final TransactionCounter sourceTransactionCounter) { @Override public TransactionCounter copy() { - logger.info( - LOGM_DEMO_INFO, - "TransactionCounter.copy(), immutable: {}, StackTrace: {}", - isImmutable(), - StackTrace.getStackTrace()); + // logger.info( + // LOGM_DEMO_INFO, + // "TransactionCounter.copy(), immutable: {}, StackTrace: {}", + // isImmutable(), + // StackTrace.getStackTrace()); // throwIfImmutable(); return new TransactionCounter(this); } From 3a4e6271e448664d1b0d4cb4655b0acfc251af4a Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 11 Nov 2024 18:18:14 +0200 Subject: [PATCH 34/59] spotless Signed-off-by: Nikita Lebedev --- .../com/swirlds/demo/migration/MigrationTestingToolState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java index 12a0b65902bd..af4b8cb98093 100644 --- a/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java +++ b/platform-sdk/platform-apps/tests/MigrationTestingTool/src/main/java/com/swirlds/demo/migration/MigrationTestingToolState.java @@ -34,9 +34,9 @@ import com.swirlds.merkledb.MerkleDb; import com.swirlds.merkledb.MerkleDbDataSourceBuilder; import com.swirlds.merkledb.MerkleDbTableConfig; +import com.swirlds.merkledb.config.MerkleDbConfig; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; -import com.swirlds.merkledb.config.MerkleDbConfig; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; From 9dfba2dbe8ee328633af57d157f1da5627b04e3c Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Mon, 11 Nov 2024 18:48:27 +0200 Subject: [PATCH 35/59] ptt fix Signed-off-by: Nikita Lebedev --- .../platform/PlatformTestingToolMain.java | 2 +- .../platform/PlatformTestingToolState.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index c00ede4c135e..80bd29885ae7 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -840,7 +840,7 @@ public MerkleStateRoot newMerkleStateRoot() { final MerkleStateRoot state = new PlatformTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getSoftwareVersion())); - logger.info(LOGM_STARTUP, "Initializing platform state..."); + // logger.info(LOGM_STARTUP, "Initializing platform state..."); NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); return state; } diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 4766d45fb332..199b26f9c7d6 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -32,7 +32,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hapi.node.base.SemanticVersion; +import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableIgnored; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.SignatureType; import com.swirlds.common.crypto.TransactionSignature; @@ -86,15 +89,13 @@ import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; -import com.swirlds.platform.system.InitTrigger; -import com.swirlds.platform.system.Platform; -import com.swirlds.platform.system.Round; -import com.swirlds.platform.system.SoftwareVersion; +import com.swirlds.platform.system.*; import com.swirlds.platform.system.address.AddressBook; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import com.swirlds.platform.system.transaction.Transaction; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import com.swirlds.virtualmap.VirtualMap; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; @@ -246,6 +247,19 @@ public class PlatformTestingToolState extends MerkleStateRoot { private long transactionsIgnoredByExpectedMap = 0; + static { + try { + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + PlatformTestingToolState.class, + () -> new PlatformTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(version.major())))); + } catch (ConstructableRegistryException e) { + throw new RuntimeException(e); + } + } + public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { From bdad0c278253107c3e123adb3144f7a2eb0d0cd9 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Mon, 11 Nov 2024 16:54:16 -0500 Subject: [PATCH 36/59] Added more logging Signed-off-by: Ivan Malygin --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 199b26f9c7d6..ba3fc0196feb 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -23,6 +23,7 @@ import static com.swirlds.demo.platform.fs.stresstest.proto.TestTransaction.BodyCase.FCMTRANSACTION; import static com.swirlds.logging.legacy.LogMarker.DEMO_INFO; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; +import static com.swirlds.logging.legacy.LogMarker.STARTUP; import static com.swirlds.logging.legacy.LogMarker.TESTING_EXCEPTIONS_ACCEPTABLE_RECONNECT; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.STORAGE_DIRECTORY; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.createExpectedMapName; @@ -249,13 +250,16 @@ public class PlatformTestingToolState extends MerkleStateRoot { static { try { + logger.info(STARTUP.getMarker(), "Registering PlatformTestingToolState with ConstructableRegistry"); ConstructableRegistry.getInstance() .registerConstructable(new ClassConstructorPair( PlatformTestingToolState.class, () -> new PlatformTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())))); + logger.info(STARTUP.getMarker(), "PlatformTestingToolState is registered with ConstructableRegistry"); } catch (ConstructableRegistryException e) { + logger.error(STARTUP.getMarker(), "Failed to register PlatformTestingToolState", e); throw new RuntimeException(e); } } From d548537a48b30ff05a5a094b03092eeb9d4a9229 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Mon, 11 Nov 2024 20:30:31 -0500 Subject: [PATCH 37/59] Added registration for ConsistencyTestingToolState Signed-off-by: Ivan Malygin --- .../ConsistencyTestingToolState.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index b9690237c8ed..35ef45037f43 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -22,17 +22,22 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.config.StateCommonConfig; +import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableIgnored; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.utility.NonCryptographicHashing; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; +import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; +import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.IOException; @@ -59,6 +64,22 @@ private static class ClassVersion { public static final int ORIGINAL = 1; } + static { + try { + logger.info(STARTUP.getMarker(), "Registering ConsistencyTestingToolState with ConstructableRegistry"); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + ConsistencyTestingToolState.class, + () -> new ConsistencyTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(version.major())))); + logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); + } catch (ConstructableRegistryException e) { + logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); + throw new RuntimeException(e); + } + } + /** * The history of transactions that have been handled by this app. *

From bf9582ce6c38db6c2945a280eb9295733f63b68c Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Tue, 12 Nov 2024 10:48:26 +0200 Subject: [PATCH 38/59] ptt debugging Signed-off-by: Nikita Lebedev --- .../demo/platform/PlatformTestingToolState.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index ba3fc0196feb..9372ce79ff1a 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -33,10 +33,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hapi.node.base.SemanticVersion; -import com.swirlds.common.constructable.ClassConstructorPair; -import com.swirlds.common.constructable.ConstructableIgnored; -import com.swirlds.common.constructable.ConstructableRegistry; -import com.swirlds.common.constructable.ConstructableRegistryException; +import com.swirlds.common.constructable.*; import com.swirlds.common.crypto.CryptographyHolder; import com.swirlds.common.crypto.SignatureType; import com.swirlds.common.crypto.TransactionSignature; @@ -257,7 +254,14 @@ public class PlatformTestingToolState extends MerkleStateRoot { () -> new PlatformTestingToolState( NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())))); - logger.info(STARTUP.getMarker(), "PlatformTestingToolState is registered with ConstructableRegistry"); + logger.info( + STARTUP.getMarker(), + "PlatformTestingToolState is registered with ConstructableRegistry: {}", + ConstructableRegistry.getInstance() + .getRegistry(NoArgsConstructor.class) + .getConstructor(CLASS_ID) + .get() + .getClassId()); } catch (ConstructableRegistryException e) { logger.error(STARTUP.getMarker(), "Failed to register PlatformTestingToolState", e); throw new RuntimeException(e); From d1aa4cb5029ccbebb22874890a56389ba8ff8174 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 11:12:07 -0500 Subject: [PATCH 39/59] Moved PlatformTestingToolState registration to PlatformTestingToolMain to guarantee that it's always registered. Signed-off-by: Ivan Malygin --- .../platform/PlatformTestingToolMain.java | 29 +++++++++++++++++++ .../platform/PlatformTestingToolState.java | 25 +--------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index 80bd29885ae7..7da132d8057b 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -30,6 +30,7 @@ import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager; import static com.swirlds.logging.legacy.LogMarker.DEMO_INFO; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; +import static com.swirlds.logging.legacy.LogMarker.STARTUP; import static com.swirlds.merkle.test.fixtures.map.lifecycle.EntityType.Crypto; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.STORAGE_DIRECTORY; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.createExpectedMapName; @@ -43,6 +44,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.swirlds.base.units.UnitConstants; import com.swirlds.base.utility.Pair; +import com.swirlds.common.constructable.ClassConstructorPair; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; +import com.swirlds.common.constructable.NoArgsConstructor; import com.swirlds.common.merkle.iterators.MerkleIterator; import com.swirlds.common.metrics.RunningAverageMetric; import com.swirlds.common.metrics.SpeedometerMetric; @@ -136,6 +141,30 @@ public class PlatformTestingToolMain implements SwirldMain { private static final String FCM_CATEGORY = "FCM"; private static final String VM_CATEGORY = "VM"; + + static { + try { + logger.info(STARTUP.getMarker(), "Registering PlatformTestingToolState with ConstructableRegistry"); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + PlatformTestingToolState.class, + () -> new PlatformTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(version.major())))); + logger.info( + STARTUP.getMarker(), + "PlatformTestingToolState is registered with ConstructableRegistry: {}", + ConstructableRegistry.getInstance() + .getRegistry(NoArgsConstructor.class) + .getConstructor(PlatformTestingToolState.CLASS_ID) + .get() + .getClassId()); + } catch (ConstructableRegistryException e) { + logger.error(STARTUP.getMarker(), "Failed to register PlatformTestingToolState", e); + throw new RuntimeException(e); + } + } + /** * save internal file logs and expected map to file while freezing; * for restart test we should set `saveExpectedMapAtFreeze` to be true, so that diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 9372ce79ff1a..0ba855649b76 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -130,7 +130,7 @@ @ConstructableIgnored public class PlatformTestingToolState extends MerkleStateRoot { - private static final long CLASS_ID = 0xc0900cfa7a24db76L; + static final long CLASS_ID = 0xc0900cfa7a24db76L; private static final Logger logger = LogManager.getLogger(PlatformTestingToolState.class); private static final Marker LOGM_DEMO_INFO = MarkerManager.getMarker("DEMO_INFO"); private static final Marker LOGM_EXCEPTION = MarkerManager.getMarker("EXCEPTION"); @@ -245,29 +245,6 @@ public class PlatformTestingToolState extends MerkleStateRoot { private long transactionsIgnoredByExpectedMap = 0; - static { - try { - logger.info(STARTUP.getMarker(), "Registering PlatformTestingToolState with ConstructableRegistry"); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair( - PlatformTestingToolState.class, - () -> new PlatformTestingToolState( - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, - version -> new BasicSoftwareVersion(version.major())))); - logger.info( - STARTUP.getMarker(), - "PlatformTestingToolState is registered with ConstructableRegistry: {}", - ConstructableRegistry.getInstance() - .getRegistry(NoArgsConstructor.class) - .getConstructor(CLASS_ID) - .get() - .getClassId()); - } catch (ConstructableRegistryException e) { - logger.error(STARTUP.getMarker(), "Failed to register PlatformTestingToolState", e); - throw new RuntimeException(e); - } - } - public PlatformTestingToolState( @NonNull final MerkleStateLifecycles lifecycles, @NonNull final Function versionFactory) { From 829a91f6d4c45660575b37e968faf53f27427767 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 11:22:35 -0500 Subject: [PATCH 40/59] Spotless Signed-off-by: Ivan Malygin --- .../com/swirlds/demo/platform/PlatformTestingToolState.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java index 0ba855649b76..3741efab2648 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolState.java @@ -23,7 +23,6 @@ import static com.swirlds.demo.platform.fs.stresstest.proto.TestTransaction.BodyCase.FCMTRANSACTION; import static com.swirlds.logging.legacy.LogMarker.DEMO_INFO; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; -import static com.swirlds.logging.legacy.LogMarker.STARTUP; import static com.swirlds.logging.legacy.LogMarker.TESTING_EXCEPTIONS_ACCEPTABLE_RECONNECT; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.STORAGE_DIRECTORY; import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.createExpectedMapName; @@ -93,7 +92,6 @@ import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; import com.swirlds.platform.system.transaction.Transaction; -import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import com.swirlds.virtualmap.VirtualMap; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; From 04819dbd327cce8af839c3c1048593b4085b1b72 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 12:26:43 -0500 Subject: [PATCH 41/59] Moved ConsistencyTestingToolState registration to ConsistencyTestingToolMain. Signed-off-by: Ivan Malygin --- .../ConsistencyTestingToolMain.java | 20 +++++++++++++++++++ .../ConsistencyTestingToolState.java | 16 +-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index 9707c58457e9..6a870e4a4192 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -18,6 +18,9 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import com.swirlds.common.constructable.ClassConstructorPair; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.platform.NodeId; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.system.BasicSoftwareVersion; @@ -40,6 +43,23 @@ public class ConsistencyTestingToolMain implements SwirldMain { private static final Logger logger = LogManager.getLogger(ConsistencyTestingToolMain.class); + static { + try { + logger.info(STARTUP.getMarker(), "Registering ConsistencyTestingToolState with ConstructableRegistry"); + ConstructableRegistry.getInstance() + .registerConstructable(new ClassConstructorPair( + ConsistencyTestingToolState.class, + () -> new ConsistencyTestingToolState( + NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + version -> new BasicSoftwareVersion(version.major())))); + logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); + } catch (ConstructableRegistryException e) { + logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); + throw new RuntimeException(e); + } + } + + /** * The default software version of this application */ diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 35ef45037f43..20d0143d95b5 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -64,21 +64,7 @@ private static class ClassVersion { public static final int ORIGINAL = 1; } - static { - try { - logger.info(STARTUP.getMarker(), "Registering ConsistencyTestingToolState with ConstructableRegistry"); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair( - ConsistencyTestingToolState.class, - () -> new ConsistencyTestingToolState( - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, - version -> new BasicSoftwareVersion(version.major())))); - logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); - } catch (ConstructableRegistryException e) { - logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); - throw new RuntimeException(e); - } - } + /** * The history of transactions that have been handled by this app. From 42fc9cc79fabfeb5db278681dd4e73fa732746e4 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 12:39:07 -0500 Subject: [PATCH 42/59] Spotless Signed-off-by: Ivan Malygin --- .../demo/consistency/ConsistencyTestingToolMain.java | 1 - .../demo/consistency/ConsistencyTestingToolState.java | 7 ------- 2 files changed, 8 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index 6a870e4a4192..d1e55ea512b4 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -59,7 +59,6 @@ public class ConsistencyTestingToolMain implements SwirldMain { } } - /** * The default software version of this application */ diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 20d0143d95b5..b9690237c8ed 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -22,22 +22,17 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.config.StateCommonConfig; -import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableIgnored; -import com.swirlds.common.constructable.ConstructableRegistry; -import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.utility.NonCryptographicHashing; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.MerkleStateRoot; import com.swirlds.platform.state.PlatformStateModifier; -import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.InitTrigger; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; -import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.IOException; @@ -64,8 +59,6 @@ private static class ClassVersion { public static final int ORIGINAL = 1; } - - /** * The history of transactions that have been handled by this app. *

From 8855f579d4a92fde185a0742447d74cd1615b242 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 14:36:00 -0500 Subject: [PATCH 43/59] Fixed minimum supported version. Signed-off-by: Ivan Malygin --- .../demo/consistency/ConsistencyTestingToolState.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index b9690237c8ed..826e131e4c25 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -177,6 +177,14 @@ public int getVersion() { return ClassVersion.ORIGINAL; } + /** + * {@inheritDoc} + */ + @Override + public int getMinimumSupportedVersion() { + return ClassVersion.ORIGINAL; + } + /** * {@inheritDoc} */ From 164682b93fbb333459805d5478c40cb935b77ccd Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 15:39:32 -0500 Subject: [PATCH 44/59] Added logging of registered classId-s Signed-off-by: Ivan Malygin --- .../main/java/com/swirlds/state/merkle/StateUtils.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java index c27999baa925..fe78e4e4dba5 100644 --- a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java +++ b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java @@ -24,7 +24,11 @@ import com.hedera.pbj.runtime.io.stream.ReadableStreamingData; import com.hedera.pbj.runtime.io.stream.WritableStreamingData; import com.swirlds.common.utility.NonCryptographicHashing; +import com.swirlds.logging.legacy.LogMarker; import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -34,6 +38,8 @@ /** Utility class for working with states. */ public final class StateUtils { + private static final Logger logger = LogManager.getLogger(StateUtils.class); + /** Prevent instantiation */ private StateUtils() {} @@ -176,7 +182,9 @@ static long hashString(@NonNull final String s) { // Normalize the string so things are deterministic (different JVMs might be using different // default internal representation for strings, and we need to normalize that) final var data = getNormalisedStringBytes(s); - return hashBytes(data); + long l = hashBytes(data); + logger.info(LogMarker.STARTUP.getMarker(), "Hashed string {} to {}", s, l); + return l; } // Will be moved to `NonCryptographicHashing` with From 26282e8e9e08ced6a16594ea4994b653f47b07dc Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 16:24:28 -0500 Subject: [PATCH 45/59] Spotless Signed-off-by: Ivan Malygin --- .../demo/addressbook/AddressBookTestingToolState.java | 2 +- .../src/main/java/com/swirlds/state/merkle/StateUtils.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java index 5e9bd07dd55c..f10d931a37ea 100644 --- a/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java +++ b/platform-sdk/platform-apps/tests/AddressBookTestingTool/src/main/java/com/swirlds/demo/addressbook/AddressBookTestingToolState.java @@ -35,9 +35,9 @@ import static com.swirlds.platform.state.address.AddressBookInitializer.STATE_ADDRESS_BOOK_USED; import static com.swirlds.platform.state.address.AddressBookInitializer.USED_ADDRESS_BOOK_HEADER; +import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.pbj.runtime.io.buffer.Bytes; -import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.context.PlatformContext; import com.swirlds.common.platform.NodeId; diff --git a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java index fe78e4e4dba5..80110104e715 100644 --- a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java +++ b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java @@ -26,14 +26,13 @@ import com.swirlds.common.utility.NonCryptographicHashing; import com.swirlds.logging.legacy.LogMarker; import edu.umd.cs.findbugs.annotations.NonNull; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** Utility class for working with states. */ public final class StateUtils { From 90165617ad63ce1e530804a6855ebd877fcee6a1 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 17:00:35 -0500 Subject: [PATCH 46/59] Added missing dependency Signed-off-by: Ivan Malygin --- platform-sdk/swirlds-state-impl/src/main/java/module-info.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-sdk/swirlds-state-impl/src/main/java/module-info.java b/platform-sdk/swirlds-state-impl/src/main/java/module-info.java index a899fb136f79..eb3c88b67d11 100644 --- a/platform-sdk/swirlds-state-impl/src/main/java/module-info.java +++ b/platform-sdk/swirlds-state-impl/src/main/java/module-info.java @@ -12,6 +12,7 @@ requires transitive com.swirlds.virtualmap; requires transitive com.hedera.pbj.runtime; requires com.swirlds.fcqueue; + requires com.swirlds.logging; requires org.apache.logging.log4j; requires static transitive com.github.spotbugs.annotations; } From e70985b4c9106152cf3ae2411fb452f4d9ebc205 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Tue, 12 Nov 2024 18:53:11 -0500 Subject: [PATCH 47/59] Added registration of the PlatformState classes Signed-off-by: Ivan Malygin --- .../ConsistencyTestingToolMain.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index d1e55ea512b4..2523e39f0903 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -17,6 +17,7 @@ package com.swirlds.demo.consistency; import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import static com.swirlds.platform.util.NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES; import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; @@ -27,7 +28,6 @@ import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.SwirldMain; -import com.swirlds.platform.util.NoOpMerkleStateLifecycles; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.security.SecureRandom; @@ -43,6 +43,11 @@ public class ConsistencyTestingToolMain implements SwirldMain { private static final Logger logger = LogManager.getLogger(ConsistencyTestingToolMain.class); + /** + * The default software version of this application + */ + private static final SoftwareVersion softwareVersion = new BasicSoftwareVersion(1); + static { try { logger.info(STARTUP.getMarker(), "Registering ConsistencyTestingToolState with ConstructableRegistry"); @@ -50,20 +55,19 @@ public class ConsistencyTestingToolMain implements SwirldMain { .registerConstructable(new ClassConstructorPair( ConsistencyTestingToolState.class, () -> new ConsistencyTestingToolState( - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, + NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())))); logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); + + // to register platform state classes with the ConstructableRegistry + NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(new MerkleStateRoot( + NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion()))); } catch (ConstructableRegistryException e) { logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); throw new RuntimeException(e); } } - /** - * The default software version of this application - */ - private static final SoftwareVersion softwareVersion = new BasicSoftwareVersion(1); - /** * The platform instance */ @@ -109,9 +113,8 @@ public void run() { @NonNull public MerkleStateRoot newMerkleStateRoot() { final MerkleStateRoot state = new ConsistencyTestingToolState( - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES, - version -> new BasicSoftwareVersion(softwareVersion.getVersion())); - NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion())); + NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); return state; } From 7f3b4ad827260bd8cf127668dcc2dde02fd81222 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Wed, 13 Nov 2024 10:04:56 -0500 Subject: [PATCH 48/59] Added registration of the PlatformState classes Signed-off-by: Ivan Malygin --- .../ConsistencyTestingToolMain.java | 89 +++++++++++++++++-- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index 2523e39f0903..c851b76433d6 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -24,10 +24,23 @@ import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.platform.NodeId; import com.swirlds.platform.state.MerkleStateRoot; +import com.swirlds.platform.state.service.PlatformStateService; +import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.SwirldMain; +import com.swirlds.state.lifecycle.StateDefinition; +import com.swirlds.state.merkle.StateMetadata; +import com.swirlds.state.merkle.disk.OnDiskKey; +import com.swirlds.state.merkle.disk.OnDiskKeySerializer; +import com.swirlds.state.merkle.disk.OnDiskValue; +import com.swirlds.state.merkle.disk.OnDiskValueSerializer; +import com.swirlds.state.merkle.memory.InMemoryValue; +import com.swirlds.state.merkle.queue.QueueNode; +import com.swirlds.state.merkle.singleton.SingletonNode; +import com.swirlds.state.merkle.singleton.StringLeaf; +import com.swirlds.state.merkle.singleton.ValueLeaf; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.security.SecureRandom; @@ -51,17 +64,74 @@ public class ConsistencyTestingToolMain implements SwirldMain { static { try { logger.info(STARTUP.getMarker(), "Registering ConsistencyTestingToolState with ConstructableRegistry"); - ConstructableRegistry.getInstance() - .registerConstructable(new ClassConstructorPair( - ConsistencyTestingToolState.class, - () -> new ConsistencyTestingToolState( - NO_OP_MERKLE_STATE_LIFECYCLES, - version -> new BasicSoftwareVersion(version.major())))); + ConstructableRegistry constructableRegistry = ConstructableRegistry.getInstance(); + constructableRegistry.registerConstructable(new ClassConstructorPair( + ConsistencyTestingToolState.class, + () -> new ConsistencyTestingToolState( + NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())))); logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); + final var schema = new V0540PlatformStateSchema(); + final StateDefinition def = schema.statesToCreate().iterator().next(); + final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); + try { + constructableRegistry.registerConstructable(new ClassConstructorPair( + InMemoryValue.class, + () -> new InMemoryValue( + md.inMemoryValueClassId(), + md.stateDefinition().keyCodec(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKey.class, + () -> new OnDiskKey<>( + md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKeySerializer.class, + () -> new OnDiskKeySerializer<>( + md.onDiskKeySerializerClassId(), + md.onDiskKeyClassId(), + md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValue.class, + () -> new OnDiskValue<>( + md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValueSerializer.class, + () -> new OnDiskValueSerializer<>( + md.onDiskValueSerializerClassId(), + md.onDiskValueClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + SingletonNode.class, + () -> new SingletonNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.singletonClassId(), + md.stateDefinition().valueCodec(), + null))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + QueueNode.class, + () -> new QueueNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.queueNodeClassId(), + md.singletonClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable( + new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); + constructableRegistry.registerConstructable(new ClassConstructorPair( + ValueLeaf.class, + () -> new ValueLeaf<>( + md.singletonClassId(), md.stateDefinition().valueCodec()))); + } catch (ConstructableRegistryException e) { + // This is a fatal error. + throw new IllegalStateException( + "Failed to register with the system 'PlatformService'" + + ":" + + md.stateDefinition().stateKey() + + "'", + e); + } - // to register platform state classes with the ConstructableRegistry - NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(new MerkleStateRoot( - NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion()))); } catch (ConstructableRegistryException e) { logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); throw new RuntimeException(e); @@ -115,6 +185,7 @@ public MerkleStateRoot newMerkleStateRoot() { final MerkleStateRoot state = new ConsistencyTestingToolState( NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion())); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + return state; } From 751c5bbf4ee79e495f4494aa7adfc8837d84570c Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Wed, 13 Nov 2024 10:43:09 -0500 Subject: [PATCH 49/59] Added missing dependency Signed-off-by: Ivan Malygin --- .../tests/ConsistencyTestingTool/src/main/java/module-info.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java index 180572b8b186..c525c555dc08 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/module-info.java @@ -6,6 +6,7 @@ requires com.swirlds.logging; requires com.swirlds.platform.core; requires com.swirlds.state.api; + requires com.swirlds.state.impl; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; From fa15fb601b0218070a812b3df7e457f589cc2786 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Wed, 13 Nov 2024 12:12:38 -0500 Subject: [PATCH 50/59] Another attempt to register platform classes. Signed-off-by: Ivan Malygin --- .../ConsistencyTestingToolMain.java | 130 ++++++++++-------- .../ConsistencyTestingToolState.java | 2 + 2 files changed, 71 insertions(+), 61 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index c851b76433d6..a52c7b9c9e69 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -70,67 +70,7 @@ public class ConsistencyTestingToolMain implements SwirldMain { () -> new ConsistencyTestingToolState( NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(version.major())))); logger.info(STARTUP.getMarker(), "ConsistencyTestingToolState is registered with ConstructableRegistry"); - final var schema = new V0540PlatformStateSchema(); - final StateDefinition def = schema.statesToCreate().iterator().next(); - final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); - try { - constructableRegistry.registerConstructable(new ClassConstructorPair( - InMemoryValue.class, - () -> new InMemoryValue( - md.inMemoryValueClassId(), - md.stateDefinition().keyCodec(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKey.class, - () -> new OnDiskKey<>( - md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKeySerializer.class, - () -> new OnDiskKeySerializer<>( - md.onDiskKeySerializerClassId(), - md.onDiskKeyClassId(), - md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValue.class, - () -> new OnDiskValue<>( - md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValueSerializer.class, - () -> new OnDiskValueSerializer<>( - md.onDiskValueSerializerClassId(), - md.onDiskValueClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - SingletonNode.class, - () -> new SingletonNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.singletonClassId(), - md.stateDefinition().valueCodec(), - null))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - QueueNode.class, - () -> new QueueNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.queueNodeClassId(), - md.singletonClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable( - new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); - constructableRegistry.registerConstructable(new ClassConstructorPair( - ValueLeaf.class, - () -> new ValueLeaf<>( - md.singletonClassId(), md.stateDefinition().valueCodec()))); - } catch (ConstructableRegistryException e) { - // This is a fatal error. - throw new IllegalStateException( - "Failed to register with the system 'PlatformService'" - + ":" - + md.stateDefinition().stateKey() - + "'", - e); - } + registerPlatformClasses(constructableRegistry); } catch (ConstructableRegistryException e) { logger.error(STARTUP.getMarker(), "Failed to register ConsistencyTestingToolState", e); @@ -138,6 +78,73 @@ public class ConsistencyTestingToolMain implements SwirldMain { } } + private static void registerPlatformClasses(ConstructableRegistry constructableRegistry) { + logger.info(STARTUP.getMarker(), "Registering PlatformState classes with ConstructableRegistry"); + final var schema = new V0540PlatformStateSchema(); + final StateDefinition def = schema.statesToCreate().iterator().next(); + final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); + try { + constructableRegistry.registerConstructable(new ClassConstructorPair( + InMemoryValue.class, + () -> new InMemoryValue( + md.inMemoryValueClassId(), + md.stateDefinition().keyCodec(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKey.class, + () -> new OnDiskKey<>( + md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKeySerializer.class, + () -> new OnDiskKeySerializer<>( + md.onDiskKeySerializerClassId(), + md.onDiskKeyClassId(), + md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValue.class, + () -> new OnDiskValue<>( + md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValueSerializer.class, + () -> new OnDiskValueSerializer<>( + md.onDiskValueSerializerClassId(), + md.onDiskValueClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + SingletonNode.class, + () -> new SingletonNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.singletonClassId(), + md.stateDefinition().valueCodec(), + null))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + QueueNode.class, + () -> new QueueNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.queueNodeClassId(), + md.singletonClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); + constructableRegistry.registerConstructable(new ClassConstructorPair( + ValueLeaf.class, + () -> new ValueLeaf<>( + md.singletonClassId(), md.stateDefinition().valueCodec()))); + logger.info( + STARTUP.getMarker(), + "PlatformState classes are successfully registered with ConstructableRegistry"); + } catch (ConstructableRegistryException e) { + // This is a fatal error. + throw new IllegalStateException( + "Failed to register with the system 'PlatformService'" + + ":" + + md.stateDefinition().stateKey() + + "'", + e); + } + } + /** * The platform instance */ @@ -185,6 +192,7 @@ public MerkleStateRoot newMerkleStateRoot() { final MerkleStateRoot state = new ConsistencyTestingToolState( NO_OP_MERKLE_STATE_LIFECYCLES, version -> new BasicSoftwareVersion(softwareVersion.getVersion())); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(state); + registerPlatformClasses(ConstructableRegistry.INSTANCE); return state; } diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 826e131e4c25..82bc38208257 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -19,6 +19,7 @@ import static com.swirlds.common.utility.ByteUtils.byteArrayToLong; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import static com.swirlds.platform.util.NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES; import com.hedera.hapi.node.base.SemanticVersion; import com.swirlds.common.config.StateCommonConfig; @@ -159,6 +160,7 @@ public void init( this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); transactionHandlingHistory.init(logFilePath); + NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); } /** From 91703de83c127fbcf597d999a65d9244f6a307d5 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Wed, 13 Nov 2024 16:54:39 -0500 Subject: [PATCH 51/59] Added more logging Signed-off-by: Ivan Malygin --- .../demo/consistency/ConsistencyTestingToolRound.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java index f1df5c5a342a..767700165ee7 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java @@ -17,6 +17,7 @@ package com.swirlds.demo.consistency; import static com.swirlds.common.utility.ByteUtils.byteArrayToLong; +import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import com.swirlds.platform.system.Round; import edu.umd.cs.findbugs.annotations.NonNull; @@ -25,6 +26,8 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Represents a round in the ConsistencyTestingTool @@ -36,6 +39,8 @@ public record ConsistencyTestingToolRound(long roundNumber, long currentState, @NonNull List transactionsContents) implements Comparable { + private static final Logger logger = LogManager.getLogger(ConsistencyTestingToolRound.class); + private static final String ROUND_NUMBER_STRING = "Round Number: "; private static final String CURRENT_STATE_STRING = "Current State: "; private static final String TRANSACTIONS_STRING = "Transactions: "; @@ -123,9 +128,12 @@ public boolean equals(final @Nullable Object other) { } if (other instanceof final ConsistencyTestingToolRound otherRound) { - return roundNumber == otherRound.roundNumber + var result = roundNumber == otherRound.roundNumber && currentState == otherRound.currentState && transactionsContents.equals(otherRound.transactionsContents); + if (!result) { + logger.error(EXCEPTION.getMarker(), "This round: {} \n Other round: {}", this, otherRound); + } } return false; From a53a4a064b2d487465415a132e46fbf985e268cc Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Thu, 14 Nov 2024 17:02:25 -0500 Subject: [PATCH 52/59] Added leafs for `stateLong` and `roundsHandled` and utilized them Signed-off-by: Ivan Malygin --- .../consistency/ConsistencyTestingToolRound.java | 5 +---- .../consistency/ConsistencyTestingToolState.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java index 767700165ee7..32e76108d281 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java @@ -128,12 +128,9 @@ public boolean equals(final @Nullable Object other) { } if (other instanceof final ConsistencyTestingToolRound otherRound) { - var result = roundNumber == otherRound.roundNumber + return roundNumber == otherRound.roundNumber && currentState == otherRound.currentState && transactionsContents.equals(otherRound.transactionsContents); - if (!result) { - logger.error(EXCEPTION.getMarker(), "This round: {} \n Other round: {}", this, otherRound); - } } return false; diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 82bc38208257..1f867909a8e2 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -34,6 +34,7 @@ import com.swirlds.platform.system.SoftwareVersion; import com.swirlds.platform.system.events.Event; import com.swirlds.platform.system.transaction.ConsensusTransaction; +import com.swirlds.state.merkle.singleton.StringLeaf; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.IOException; @@ -60,6 +61,9 @@ private static class ClassVersion { public static final int ORIGINAL = 1; } + private static final int STATE_LONG_INDEX = 0; + private static final int ROUND_HANDLED_INDEX = 1; + /** * The history of transactions that have been handled by this app. *

@@ -71,7 +75,7 @@ private static class ClassVersion { /** * The true "state" of this app. This long value is updated with every transaction, and with every round. *

- * Effects the hash of this node. + * Affects the hash of this node. */ private long stateLong = 0; @@ -158,6 +162,10 @@ public void init( final Path logFilePath = logFileDirectory.resolve("ConsistencyTestLog.csv"); this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); + this.roundsHandled = Long.getLong(((StringLeaf)getChild(ROUND_HANDLED_INDEX)).getLabel()); + this.stateLong = Long.getLong(((StringLeaf)getChild(STATE_LONG_INDEX)).getLabel()); + logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled and state long {}.", + roundsHandled, stateLong); transactionHandlingHistory.init(logFilePath); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); @@ -264,5 +272,8 @@ public void handleConsensusRound(final @NonNull Round round, final @NonNull Plat stateLong = NonCryptographicHashing.hash64(stateLong, round.getRoundNum()); transactionHandlingHistory.processRound(ConsistencyTestingToolRound.fromRound(round, stateLong)); + + setChild(ROUND_HANDLED_INDEX, new StringLeaf(Long.toString(roundsHandled))); + setChild(STATE_LONG_INDEX, new StringLeaf(Long.toString(stateLong))); } } From 94f60f1a7a41b03a28deb586ea7b7863e92d451c Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Thu, 14 Nov 2024 19:30:10 -0500 Subject: [PATCH 53/59] Spotless Signed-off-by: Ivan Malygin --- .../demo/consistency/ConsistencyTestingToolRound.java | 1 - .../demo/consistency/ConsistencyTestingToolState.java | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java index 32e76108d281..e3ff72b2257f 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolRound.java @@ -17,7 +17,6 @@ package com.swirlds.demo.consistency; import static com.swirlds.common.utility.ByteUtils.byteArrayToLong; -import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import com.swirlds.platform.system.Round; import edu.umd.cs.findbugs.annotations.NonNull; diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 1f867909a8e2..c12db5961599 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -162,10 +162,13 @@ public void init( final Path logFilePath = logFileDirectory.resolve("ConsistencyTestLog.csv"); this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); - this.roundsHandled = Long.getLong(((StringLeaf)getChild(ROUND_HANDLED_INDEX)).getLabel()); - this.stateLong = Long.getLong(((StringLeaf)getChild(STATE_LONG_INDEX)).getLabel()); - logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled and state long {}.", - roundsHandled, stateLong); + this.roundsHandled = Long.getLong(((StringLeaf) getChild(ROUND_HANDLED_INDEX)).getLabel()); + this.stateLong = Long.getLong(((StringLeaf) getChild(STATE_LONG_INDEX)).getLabel()); + logger.info( + STARTUP.getMarker(), + "State initialized with {} rounds handled and state long {}.", + roundsHandled, + stateLong); transactionHandlingHistory.init(logFilePath); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); From 2977d1951b5d3a1e0b3a2a30e359977a24cd6ed2 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 15 Nov 2024 11:44:07 +0200 Subject: [PATCH 54/59] fix initialization issue Signed-off-by: Nikita Lebedev --- .../ConsistencyTestingToolState.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index c12db5961599..bf5c605f5e93 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -162,16 +162,19 @@ public void init( final Path logFilePath = logFileDirectory.resolve("ConsistencyTestLog.csv"); this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); - this.roundsHandled = Long.getLong(((StringLeaf) getChild(ROUND_HANDLED_INDEX)).getLabel()); - this.stateLong = Long.getLong(((StringLeaf) getChild(STATE_LONG_INDEX)).getLabel()); - logger.info( - STARTUP.getMarker(), - "State initialized with {} rounds handled and state long {}.", - roundsHandled, - stateLong); transactionHandlingHistory.init(logFilePath); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); + + if (trigger != InitTrigger.GENESIS) { + this.roundsHandled = Long.getLong(((StringLeaf) getChild(ROUND_HANDLED_INDEX)).getLabel()); + this.stateLong = Long.getLong(((StringLeaf) getChild(STATE_LONG_INDEX)).getLabel()); + logger.info( + STARTUP.getMarker(), + "State initialized with {} rounds handled and state long {}.", + roundsHandled, + stateLong); + } } /** From 991dad42b418d17f68213bf4cb98ab9b2929605a Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 15 Nov 2024 14:26:01 +0200 Subject: [PATCH 55/59] fix initialization issue Signed-off-by: Nikita Lebedev --- .../ConsistencyTestingToolState.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index bf5c605f5e93..a18aebb2ff30 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -163,18 +163,19 @@ public void init( this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); + final StringLeaf roundsHandledLeaf = getChild(ROUND_HANDLED_INDEX); + if (roundsHandledLeaf != null) { + this.roundsHandled = Long.getLong(roundsHandledLeaf.getLabel()); + logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled.", roundsHandled); + } + final StringLeaf stateLongLeaf = getChild(STATE_LONG_INDEX); + if (stateLongLeaf != null) { + this.stateLong = Long.getLong(stateLongLeaf.getLabel()); + logger.info(STARTUP.getMarker(), "State initialized with state long {}.", stateLong); + } + transactionHandlingHistory.init(logFilePath); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); - - if (trigger != InitTrigger.GENESIS) { - this.roundsHandled = Long.getLong(((StringLeaf) getChild(ROUND_HANDLED_INDEX)).getLabel()); - this.stateLong = Long.getLong(((StringLeaf) getChild(STATE_LONG_INDEX)).getLabel()); - logger.info( - STARTUP.getMarker(), - "State initialized with {} rounds handled and state long {}.", - roundsHandled, - stateLong); - } } /** From 207d9643c28544e64e2a3183920e8523bf7e5de8 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 15 Nov 2024 15:37:41 +0200 Subject: [PATCH 56/59] fix initialization issue Signed-off-by: Nikita Lebedev --- .../consistency/ConsistencyTestingToolState.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index a18aebb2ff30..42b45b2eba51 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -61,8 +61,8 @@ private static class ClassVersion { public static final int ORIGINAL = 1; } - private static final int STATE_LONG_INDEX = 0; - private static final int ROUND_HANDLED_INDEX = 1; + private static final int STATE_LONG_INDEX = 1; + private static final int ROUND_HANDLED_INDEX = 2; /** * The history of transactions that have been handled by this app. @@ -163,16 +163,16 @@ public void init( this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); - final StringLeaf roundsHandledLeaf = getChild(ROUND_HANDLED_INDEX); - if (roundsHandledLeaf != null) { - this.roundsHandled = Long.getLong(roundsHandledLeaf.getLabel()); - logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled.", roundsHandled); - } final StringLeaf stateLongLeaf = getChild(STATE_LONG_INDEX); if (stateLongLeaf != null) { this.stateLong = Long.getLong(stateLongLeaf.getLabel()); logger.info(STARTUP.getMarker(), "State initialized with state long {}.", stateLong); } + final StringLeaf roundsHandledLeaf = getChild(ROUND_HANDLED_INDEX); + if (roundsHandledLeaf != null) { + this.roundsHandled = Long.getLong(roundsHandledLeaf.getLabel()); + logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled.", roundsHandled); + } transactionHandlingHistory.init(logFilePath); NO_OP_MERKLE_STATE_LIFECYCLES.initPlatformState(this); From c31e88e4e4d69009d686cb62d4ad7553e8eb8029 Mon Sep 17 00:00:00 2001 From: Nikita Lebedev Date: Fri, 15 Nov 2024 17:15:51 +0200 Subject: [PATCH 57/59] fix ConsistencyTestingToolState init Signed-off-by: Nikita Lebedev --- .../demo/consistency/ConsistencyTestingToolState.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java index 42b45b2eba51..23704fbcbc29 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java @@ -164,13 +164,13 @@ public void init( this.freezeAfterGenesis = testingToolConfig.freezeAfterGenesis(); final StringLeaf stateLongLeaf = getChild(STATE_LONG_INDEX); - if (stateLongLeaf != null) { - this.stateLong = Long.getLong(stateLongLeaf.getLabel()); + if (stateLongLeaf != null && stateLongLeaf.getLabel() != null) { + this.stateLong = Long.parseLong(stateLongLeaf.getLabel()); logger.info(STARTUP.getMarker(), "State initialized with state long {}.", stateLong); } final StringLeaf roundsHandledLeaf = getChild(ROUND_HANDLED_INDEX); - if (roundsHandledLeaf != null) { - this.roundsHandled = Long.getLong(roundsHandledLeaf.getLabel()); + if (roundsHandledLeaf != null && roundsHandledLeaf.getLabel() != null) { + this.roundsHandled = Long.parseLong(roundsHandledLeaf.getLabel()); logger.info(STARTUP.getMarker(), "State initialized with {} rounds handled.", roundsHandled); } From 6ed59afcb409adb5be5d761983f2da26cb539431 Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Fri, 15 Nov 2024 16:32:19 -0500 Subject: [PATCH 58/59] Moved service class registration to `StateUtils` of `swirlds-state-impl`. Added missing registration to PTT. Signed-off-by: Ivan Malygin --- .../state/merkle/MerkleSchemaRegistry.java | 88 +----------------- .../ConsistencyTestingToolMain.java | 71 +-------------- .../platform/PlatformTestingToolMain.java | 14 +++ .../com/swirlds/state/merkle/StateUtils.java | 91 +++++++++++++++++++ 4 files changed, 109 insertions(+), 155 deletions(-) diff --git a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java index bc6461b3c283..680a45d34053 100644 --- a/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java +++ b/hedera-node/hedera-app/src/main/java/com/hedera/node/app/state/merkle/MerkleSchemaRegistry.java @@ -22,6 +22,7 @@ import static com.hedera.node.app.state.merkle.VersionUtils.alreadyIncludesStateDefs; import static com.hedera.node.app.state.merkle.VersionUtils.isSoOrdered; import static com.hedera.node.app.workflows.handle.metric.UnavailableMetrics.UNAVAILABLE_METRICS; +import static com.swirlds.state.merkle.StateUtils.registerWithSystem; import static java.util.Objects.requireNonNull; import com.hedera.hapi.node.base.SemanticVersion; @@ -31,9 +32,7 @@ import com.hedera.node.app.services.MigrationStateChanges; import com.hedera.node.app.spi.state.FilteredReadableStates; import com.hedera.node.app.spi.state.FilteredWritableStates; -import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; -import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.crypto.DigestType; import com.swirlds.config.api.Configuration; import com.swirlds.merkle.map.MerkleMap; @@ -51,16 +50,10 @@ import com.swirlds.state.lifecycle.info.NetworkInfo; import com.swirlds.state.merkle.StateMetadata; import com.swirlds.state.merkle.StateUtils; -import com.swirlds.state.merkle.disk.OnDiskKey; import com.swirlds.state.merkle.disk.OnDiskKeySerializer; -import com.swirlds.state.merkle.disk.OnDiskValue; import com.swirlds.state.merkle.disk.OnDiskValueSerializer; -import com.swirlds.state.merkle.memory.InMemoryValue; -import com.swirlds.state.merkle.memory.InMemoryWritableKVState; import com.swirlds.state.merkle.queue.QueueNode; import com.swirlds.state.merkle.singleton.SingletonNode; -import com.swirlds.state.merkle.singleton.StringLeaf; -import com.swirlds.state.merkle.singleton.ValueLeaf; import com.swirlds.state.spi.WritableStates; import com.swirlds.virtualmap.VirtualMap; import edu.umd.cs.findbugs.annotations.NonNull; @@ -151,7 +144,7 @@ public SchemaRegistry register(@NonNull Schema schema) { schema.statesToCreate(bootstrapConfig).forEach(def -> { //noinspection rawtypes,unchecked final var md = new StateMetadata<>(serviceName, schema, def); - registerWithSystem(md); + registerWithSystem(md, constructableRegistry); }); return this; @@ -380,81 +373,4 @@ private RedefinedWritableStates applyStateDefinitions( final var newStates = new FilteredWritableStates(writableStates, remainingStates); return new RedefinedWritableStates(writableStates, newStates); } - - /** - * Registers with the {@link ConstructableRegistry} system a class ID and a class. While this - * will only be used for in-memory states, it is safe to register for on-disk ones as well. - * - *

The implementation will take the service name and the state key and compute a hash for it. - * It will then convert the hash to a long, and use that as the class ID. It will then register - * an {@link InMemoryWritableKVState}'s value merkle type to be deserialized, answering with the - * generated class ID. - * - * @param md The state metadata - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - private void registerWithSystem(@NonNull final StateMetadata md) { - // Register with the system the uniqueId as the "classId" of an InMemoryValue. There can be - // multiple id's associated with InMemoryValue. The secret is that the supplier captures the - // various delegate writers and parsers, and so can parse/write different types of data - // based on the id. - try { - constructableRegistry.registerConstructable(new ClassConstructorPair( - InMemoryValue.class, - () -> new InMemoryValue( - md.inMemoryValueClassId(), - md.stateDefinition().keyCodec(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKey.class, - () -> new OnDiskKey<>( - md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKeySerializer.class, - () -> new OnDiskKeySerializer<>( - md.onDiskKeySerializerClassId(), - md.onDiskKeyClassId(), - md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValue.class, - () -> new OnDiskValue<>( - md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValueSerializer.class, - () -> new OnDiskValueSerializer<>( - md.onDiskValueSerializerClassId(), - md.onDiskValueClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - SingletonNode.class, - () -> new SingletonNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.singletonClassId(), - md.stateDefinition().valueCodec(), - null))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - QueueNode.class, - () -> new QueueNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.queueNodeClassId(), - md.singletonClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); - constructableRegistry.registerConstructable(new ClassConstructorPair( - ValueLeaf.class, - () -> new ValueLeaf<>( - md.singletonClassId(), md.stateDefinition().valueCodec()))); - } catch (ConstructableRegistryException e) { - // This is a fatal error. - throw new IllegalStateException( - "Failed to register with the system '" - + serviceName - + ":" - + md.stateDefinition().stateKey() - + "'", - e); - } - } } diff --git a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java index a52c7b9c9e69..4ba378f469f9 100644 --- a/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java @@ -18,6 +18,7 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import static com.swirlds.platform.util.NoOpMerkleStateLifecycles.NO_OP_MERKLE_STATE_LIFECYCLES; +import static com.swirlds.state.merkle.StateUtils.registerWithSystem; import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; @@ -32,15 +33,6 @@ import com.swirlds.platform.system.SwirldMain; import com.swirlds.state.lifecycle.StateDefinition; import com.swirlds.state.merkle.StateMetadata; -import com.swirlds.state.merkle.disk.OnDiskKey; -import com.swirlds.state.merkle.disk.OnDiskKeySerializer; -import com.swirlds.state.merkle.disk.OnDiskValue; -import com.swirlds.state.merkle.disk.OnDiskValueSerializer; -import com.swirlds.state.merkle.memory.InMemoryValue; -import com.swirlds.state.merkle.queue.QueueNode; -import com.swirlds.state.merkle.singleton.SingletonNode; -import com.swirlds.state.merkle.singleton.StringLeaf; -import com.swirlds.state.merkle.singleton.ValueLeaf; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.security.SecureRandom; @@ -83,66 +75,7 @@ private static void registerPlatformClasses(ConstructableRegistry constructableR final var schema = new V0540PlatformStateSchema(); final StateDefinition def = schema.statesToCreate().iterator().next(); final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); - try { - constructableRegistry.registerConstructable(new ClassConstructorPair( - InMemoryValue.class, - () -> new InMemoryValue( - md.inMemoryValueClassId(), - md.stateDefinition().keyCodec(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKey.class, - () -> new OnDiskKey<>( - md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskKeySerializer.class, - () -> new OnDiskKeySerializer<>( - md.onDiskKeySerializerClassId(), - md.onDiskKeyClassId(), - md.stateDefinition().keyCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValue.class, - () -> new OnDiskValue<>( - md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - OnDiskValueSerializer.class, - () -> new OnDiskValueSerializer<>( - md.onDiskValueSerializerClassId(), - md.onDiskValueClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - SingletonNode.class, - () -> new SingletonNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.singletonClassId(), - md.stateDefinition().valueCodec(), - null))); - constructableRegistry.registerConstructable(new ClassConstructorPair( - QueueNode.class, - () -> new QueueNode<>( - md.serviceName(), - md.stateDefinition().stateKey(), - md.queueNodeClassId(), - md.singletonClassId(), - md.stateDefinition().valueCodec()))); - constructableRegistry.registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); - constructableRegistry.registerConstructable(new ClassConstructorPair( - ValueLeaf.class, - () -> new ValueLeaf<>( - md.singletonClassId(), md.stateDefinition().valueCodec()))); - logger.info( - STARTUP.getMarker(), - "PlatformState classes are successfully registered with ConstructableRegistry"); - } catch (ConstructableRegistryException e) { - // This is a fatal error. - throw new IllegalStateException( - "Failed to register with the system 'PlatformService'" - + ":" - + md.stateDefinition().stateKey() - + "'", - e); - } + registerWithSystem(md, constructableRegistry); } /** diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java index 7da132d8057b..0f72ff44f8c6 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/com/swirlds/demo/platform/PlatformTestingToolMain.java @@ -37,6 +37,7 @@ import static com.swirlds.merkle.test.fixtures.map.lifecycle.SaveExpectedMapHandler.serialize; import static com.swirlds.metrics.api.FloatFormats.FORMAT_6_2; import static com.swirlds.metrics.api.FloatFormats.FORMAT_9_6; +import static com.swirlds.state.merkle.StateUtils.registerWithSystem; import static java.lang.System.exit; import com.fasterxml.jackson.core.JsonParser; @@ -85,6 +86,8 @@ import com.swirlds.platform.listeners.ReconnectCompleteListener; import com.swirlds.platform.listeners.StateWriteToDiskCompleteListener; import com.swirlds.platform.state.MerkleStateRoot; +import com.swirlds.platform.state.service.PlatformStateService; +import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema; import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldMain; @@ -93,6 +96,8 @@ import com.swirlds.platform.system.state.notifications.NewSignedStateListener; import com.swirlds.platform.system.status.PlatformStatus; import com.swirlds.platform.util.NoOpMerkleStateLifecycles; +import com.swirlds.state.lifecycle.StateDefinition; +import com.swirlds.state.merkle.StateMetadata; import com.swirlds.virtualmap.internal.merkle.VirtualLeafNode; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.File; @@ -159,12 +164,21 @@ public class PlatformTestingToolMain implements SwirldMain { .getConstructor(PlatformTestingToolState.CLASS_ID) .get() .getClassId()); + registerPlatformClasses(ConstructableRegistry.getInstance()); } catch (ConstructableRegistryException e) { logger.error(STARTUP.getMarker(), "Failed to register PlatformTestingToolState", e); throw new RuntimeException(e); } } + private static void registerPlatformClasses(ConstructableRegistry constructableRegistry) { + logger.info(STARTUP.getMarker(), "Registering PlatformState classes with ConstructableRegistry"); + final var schema = new V0540PlatformStateSchema(); + final StateDefinition def = schema.statesToCreate().iterator().next(); + final var md = new StateMetadata<>(PlatformStateService.NAME, schema, def); + registerWithSystem(md, constructableRegistry); + } + /** * save internal file logs and expected map to file while freezing; * for restart test we should set `saveExpectedMapAtFreeze` to be true, so that diff --git a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java index 80110104e715..fdd816b472ee 100644 --- a/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java +++ b/platform-sdk/swirlds-state-impl/src/main/java/com/swirlds/state/merkle/StateUtils.java @@ -23,8 +23,21 @@ import com.hedera.pbj.runtime.ParseException; import com.hedera.pbj.runtime.io.stream.ReadableStreamingData; import com.hedera.pbj.runtime.io.stream.WritableStreamingData; +import com.swirlds.common.constructable.ClassConstructorPair; +import com.swirlds.common.constructable.ConstructableRegistry; +import com.swirlds.common.constructable.ConstructableRegistryException; import com.swirlds.common.utility.NonCryptographicHashing; import com.swirlds.logging.legacy.LogMarker; +import com.swirlds.state.merkle.disk.OnDiskKey; +import com.swirlds.state.merkle.disk.OnDiskKeySerializer; +import com.swirlds.state.merkle.disk.OnDiskValue; +import com.swirlds.state.merkle.disk.OnDiskValueSerializer; +import com.swirlds.state.merkle.memory.InMemoryValue; +import com.swirlds.state.merkle.memory.InMemoryWritableKVState; +import com.swirlds.state.merkle.queue.QueueNode; +import com.swirlds.state.merkle.singleton.SingletonNode; +import com.swirlds.state.merkle.singleton.StringLeaf; +import com.swirlds.state.merkle.singleton.ValueLeaf; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -249,4 +262,82 @@ private static boolean isAsciiLetter(char ch) { private static boolean isAsciiNumber(char ch) { return ch >= '0' && ch <= '9'; } + + /** + * Registers with the {@link ConstructableRegistry} system a class ID and a class. While this + * will only be used for in-memory states, it is safe to register for on-disk ones as well. + * + *

The implementation will take the service name and the state key and compute a hash for it. + * It will then convert the hash to a long, and use that as the class ID. It will then register + * an {@link InMemoryWritableKVState}'s value merkle type to be deserialized, answering with the + * generated class ID. + * + * @param md The state metadata + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + public static void registerWithSystem( + @NonNull final StateMetadata md, @NonNull ConstructableRegistry constructableRegistry) { + // Register with the system the uniqueId as the "classId" of an InMemoryValue. There can be + // multiple id's associated with InMemoryValue. The secret is that the supplier captures the + // various delegate writers and parsers, and so can parse/write different types of data + // based on the id. + try { + constructableRegistry.registerConstructable(new ClassConstructorPair( + InMemoryValue.class, + () -> new InMemoryValue( + md.inMemoryValueClassId(), + md.stateDefinition().keyCodec(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKey.class, + () -> new OnDiskKey<>( + md.onDiskKeyClassId(), md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskKeySerializer.class, + () -> new OnDiskKeySerializer<>( + md.onDiskKeySerializerClassId(), + md.onDiskKeyClassId(), + md.stateDefinition().keyCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValue.class, + () -> new OnDiskValue<>( + md.onDiskValueClassId(), md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + OnDiskValueSerializer.class, + () -> new OnDiskValueSerializer<>( + md.onDiskValueSerializerClassId(), + md.onDiskValueClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + SingletonNode.class, + () -> new SingletonNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.singletonClassId(), + md.stateDefinition().valueCodec(), + null))); + constructableRegistry.registerConstructable(new ClassConstructorPair( + QueueNode.class, + () -> new QueueNode<>( + md.serviceName(), + md.stateDefinition().stateKey(), + md.queueNodeClassId(), + md.singletonClassId(), + md.stateDefinition().valueCodec()))); + constructableRegistry.registerConstructable(new ClassConstructorPair(StringLeaf.class, StringLeaf::new)); + constructableRegistry.registerConstructable(new ClassConstructorPair( + ValueLeaf.class, + () -> new ValueLeaf<>( + md.singletonClassId(), md.stateDefinition().valueCodec()))); + } catch (ConstructableRegistryException e) { + // This is a fatal error. + throw new IllegalStateException( + "Failed to register with the system '" + + md.serviceName() + + ":" + + md.stateDefinition().stateKey() + + "'", + e); + } + } } From fb3011b7f71715b9a8285f01658b41c6cacf22af Mon Sep 17 00:00:00 2001 From: Ivan Malygin Date: Fri, 15 Nov 2024 18:05:21 -0500 Subject: [PATCH 59/59] Fixed dependencies Signed-off-by: Ivan Malygin --- .../tests/PlatformTestingTool/src/main/java/module-info.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java index 0ab83dd36981..818a3bcb6ce0 100644 --- a/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java +++ b/platform-sdk/platform-apps/tests/PlatformTestingTool/src/main/java/module-info.java @@ -38,6 +38,7 @@ requires com.swirlds.metrics.api; requires com.swirlds.platform.core; requires com.swirlds.state.api; + requires com.swirlds.state.impl; requires com.swirlds.virtualmap; requires com.fasterxml.jackson.annotation; requires com.fasterxml.jackson.core;