From 7645c19d03a0dad6052c0d1c27d9c85d3241cf07 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 2 Dec 2024 15:53:49 +0200 Subject: [PATCH 01/39] feat: add Bytes support for transaction iteration in ConsensusEvent and its ancestors Signed-off-by: Ivan Kavaldzhiev --- .../embedded/fakes/FakeConsensusEvent.java | 6 +++++ .../swirlds/platform/event/PlatformEvent.java | 5 ++++ .../platform/system/events/CesEvent.java | 6 +++++ .../system/events/ConsensusEvent.java | 11 ++++++++ .../platform/system/events/EventMetadata.java | 17 ++++++++++++ .../system/transaction/Transaction.java | 3 +++ .../transaction/TransactionWrapper.java | 26 +++++++++++++++++++ 7 files changed, 74 insertions(+) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java index 9d968bfe4481..1a380d1e196c 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java @@ -19,6 +19,7 @@ import static java.util.Objects.requireNonNull; import com.hedera.hapi.node.base.SemanticVersion; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; @@ -46,6 +47,11 @@ public FakeConsensusEvent( return Collections.singleton((ConsensusTransaction) transaction).iterator(); } + @Override + public @NonNull Iterator transactionBytesIterator() { + return Collections.singleton(transaction.getTransactionBytes()).iterator(); + } + @Override public long getConsensusOrder() { return consensusOrder; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java index d213a92af842..884562f58a13 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java @@ -205,6 +205,11 @@ public Iterator transactionIterator() { return new TypedIterator<>(metadata.getTransactions().iterator()); } + @Override + public Iterator transactionBytesIterator() { + return new TypedIterator<>(metadata.getTransactionsBytes().iterator()); + } + @Override public Instant getTimeCreated() { return metadata.getTimeCreated(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java index f19b279f689a..af2e9169b47e 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java @@ -146,6 +146,12 @@ public Iterator consensusTransactionIterator() { return platformEvent.consensusTransactionIterator(); } + @Override + @NonNull + public Iterator transactionBytesIterator() { + return platformEvent.transactionBytesIterator(); + } + @Override public long getConsensusOrder() { return platformEvent.getConsensusOrder(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java index 5df0be83f073..c8b8b53928bc 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java @@ -16,6 +16,7 @@ package com.swirlds.platform.system.events; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.system.ReachedConsensus; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; @@ -37,5 +38,15 @@ public interface ConsensusEvent extends Event, ReachedConsensus { * @return a consensus transaction iterator */ @NonNull + @Deprecated Iterator consensusTransactionIterator(); + + /** + * Returns an iterator over the application events in this transaction, which have all reached consensus in {@link Bytes} format. Each + * invocation returns a new iterator over the same transactions. This method is thread safe. + * + * @return a consensus transaction iterator + */ + @NonNull + Iterator transactionBytesIterator(); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index 2579d3cc906e..5416024deed9 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -20,6 +20,7 @@ import com.hedera.hapi.platform.event.EventTransaction; import com.hedera.hapi.platform.event.GossipEvent; import com.hedera.hapi.util.HapiUtils; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.AbstractHashable; import com.swirlds.common.crypto.Hash; import com.swirlds.common.platform.NodeId; @@ -27,6 +28,7 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Stream; @@ -64,6 +66,10 @@ public class EventMetadata extends AbstractHashable { * list of transactions */ private final List transactions; + /** + * The bytes of the transactions + */ + private final List transactionsBytes; /** * The event descriptor for this event. Is not itself hashed. */ @@ -97,6 +103,7 @@ public EventMetadata( this.transactions = Objects.requireNonNull(transactions, "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); + this.transactionsBytes = new ArrayList<>(); } /** @@ -126,6 +133,8 @@ public EventMetadata(@NonNull final GossipEvent gossipEvent) { Objects.requireNonNull(gossipEvent.eventTransaction(), "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); + //Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes depending on the data loaded in the protobuf + this.transactionsBytes = new ArrayList<>(); } private static long calculateGeneration(@NonNull final List allParents) { @@ -207,6 +216,14 @@ public List getTransactions() { return transactions; } + /** + * @return list of transactions bytes + */ + @NonNull + public List getTransactionsBytes() { + return transactionsBytes; + } + public long getGeneration() { return generation; } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index 18a912213f7c..25aedac4aa9c 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -36,6 +36,7 @@ public sealed interface Transaction permits ConsensusTransaction { * @return the transaction */ @NonNull + @Deprecated EventTransaction getTransaction(); /** @@ -44,6 +45,7 @@ public sealed interface Transaction permits ConsensusTransaction { * * @return the application transaction Bytes or {@code Bytes.EMPTY} if the transaction is a system transaction */ + @Deprecated default @NonNull Bytes getApplicationTransaction() { return !isSystem() ? getTransaction().transaction().as() : Bytes.EMPTY; } @@ -61,6 +63,7 @@ public sealed interface Transaction permits ConsensusTransaction { * @return {@code true} if this is a system transaction; otherwise {@code false} if this is an application * transaction */ + @Deprecated default boolean isSystem() { return TransactionUtils.isSystemTransaction(getTransaction()); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 7d39092a96b8..af60a0ae944a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -39,6 +39,8 @@ public non-sealed class TransactionWrapper implements ConsensusTransaction { private Object metadata; /** The protobuf data stored */ private final EventTransaction payload; + /** The protobuf transaction data stored as bytes */ + private final Bytes payloadBytes; /** The hash of the transaction */ private Bytes hash; @@ -52,6 +54,7 @@ public non-sealed class TransactionWrapper implements ConsensusTransaction { public TransactionWrapper(@NonNull final OneOf transaction) { Objects.requireNonNull(transaction, "transaction should not be null"); this.payload = new EventTransaction(transaction); + this.payloadBytes = Bytes.EMPTY; } /** @@ -63,6 +66,19 @@ public TransactionWrapper(@NonNull final OneOf transaction */ public TransactionWrapper(@NonNull final EventTransaction transaction) { this.payload = Objects.requireNonNull(transaction, "transaction should not be null"); + this.payloadBytes = Bytes.EMPTY; + } + + /** + * Constructs a new transaction wrapper + * + * @param payloadBytes the serialized bytes of the transaction + * + * @throws NullPointerException if payloadBytes is null + */ + public TransactionWrapper(@NonNull final Bytes payloadBytes) { + this.payload = EventTransaction.DEFAULT; + this.payloadBytes = Objects.requireNonNull(payloadBytes, "payloadBytes should not be null"); } /** @@ -117,6 +133,16 @@ public EventTransaction getTransaction() { return payload; } + /** + * Returns the payload bytes as a PBJ record + * + * @return the payload + */ + @NonNull + public Bytes getTransactionBytes() { + return payloadBytes; + } + /** * Get the serialized size of the transaction. This method returns the same value as * {@code SwirldsTransaction.getSerializedLength()} and {@code StateSignatureTransaction.getSerializedLength()}. From 575886c646d35f134ef63ddcadbef56b19699b2b Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 2 Dec 2024 17:22:29 +0200 Subject: [PATCH 02/39] feat: adapt ISSTestingTool to work with Bytes format as transaction representation Signed-off-by: Ivan Kavaldzhiev --- .../embedded/fakes/FakeConsensusEvent.java | 2 +- .../swirlds/demo/iss/ISSTestingToolState.java | 17 +++++++++++++---- .../platform/system/events/EventMetadata.java | 3 ++- .../system/transaction/Transaction.java | 7 +++++++ .../system/transaction/TransactionWrapper.java | 8 ++------ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java index 1a380d1e196c..cf819a0f657a 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java @@ -49,7 +49,7 @@ public FakeConsensusEvent( @Override public @NonNull Iterator transactionBytesIterator() { - return Collections.singleton(transaction.getTransactionBytes()).iterator(); + return Collections.singleton(transaction.getTransactionsBytes()).iterator(); } @Override 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 994c44114486..774c9d879436 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 @@ -35,6 +35,7 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; +import com.hedera.hapi.platform.event.EventTransaction; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; @@ -284,11 +285,19 @@ private void captureTimestamp(final ConsensusEvent event) { * @param transaction the transaction to apply */ private void handleTransaction(final ConsensusTransaction transaction) { - if (transaction.isSystem()) { - return; + int delta; + + if (!transaction.getTransaction().equals(EventTransaction.DEFAULT)) { + if (transaction.isSystem()) { + return; + } + + delta = ByteUtils.byteArrayToInt( + transaction.getApplicationTransaction().toByteArray(), 0); + } else { + delta = ByteUtils.byteArrayToInt(transaction.getTransactionsBytes().toByteArray(), 0); } - final int delta = - ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0); + runningSum += delta; setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index 5416024deed9..2c659f5fcc02 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -133,7 +133,8 @@ public EventMetadata(@NonNull final GossipEvent gossipEvent) { Objects.requireNonNull(gossipEvent.eventTransaction(), "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); - //Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes depending on the data loaded in the protobuf + // Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes + // depending on the data loaded in the protobuf this.transactionsBytes = new ArrayList<>(); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index 25aedac4aa9c..b3698b25bf09 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -39,6 +39,13 @@ public sealed interface Transaction permits ConsensusTransaction { @Deprecated EventTransaction getTransaction(); + /** + * Returns the transaction bytes as a PBJ record + * @return the transaction + */ + @NonNull + Bytes getTransactionsBytes(); + /** * A convenience method for retrieving the application transaction {@link Bytes} object. Before calling this method, * ensure that the transaction is not a system transaction by calling {@link #isSystem()}. diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index af60a0ae944a..0fdcbdeed725 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -133,13 +133,9 @@ public EventTransaction getTransaction() { return payload; } - /** - * Returns the payload bytes as a PBJ record - * - * @return the payload - */ + @Override @NonNull - public Bytes getTransactionBytes() { + public Bytes getTransactionsBytes() { return payloadBytes; } From 564403ba37e2925fb1b1377f2228a299a925b691 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 2 Dec 2024 17:48:40 +0200 Subject: [PATCH 03/39] docs: add TODO comment Signed-off-by: Ivan Kavaldzhiev --- .../main/java/com/swirlds/demo/iss/ISSTestingToolState.java | 3 +++ 1 file changed, 3 insertions(+) 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 774c9d879436..c551eb9208f1 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 @@ -295,6 +295,9 @@ private void handleTransaction(final ConsensusTransaction transaction) { delta = ByteUtils.byteArrayToInt( transaction.getApplicationTransaction().toByteArray(), 0); } else { + // TODO: Currently all type of transactions will update this state. Once platform registers callbacks on the + // services.app for getting back system transactions, application transactions will be filtered, so that + // only they will update the state. delta = ByteUtils.byteArrayToInt(transaction.getTransactionsBytes().toByteArray(), 0); } From ba72ec35b6e615983656287b1f313f57b7b286ed Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 2 Dec 2024 17:51:14 +0200 Subject: [PATCH 04/39] docs: add TODO comment for EventMetadata Signed-off-by: Ivan Kavaldzhiev --- .../java/com/swirlds/platform/system/events/EventMetadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index 2c659f5fcc02..dc4cb7ed3c52 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -133,7 +133,7 @@ public EventMetadata(@NonNull final GossipEvent gossipEvent) { Objects.requireNonNull(gossipEvent.eventTransaction(), "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); - // Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes + // TODO: Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes // depending on the data loaded in the protobuf this.transactionsBytes = new ArrayList<>(); } From c574bc44e6f29ad341aaccabd50a53334e91129c Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 3 Dec 2024 11:12:45 +0200 Subject: [PATCH 05/39] style: apply spotless Signed-off-by: Ivan Kavaldzhiev --- .../java/com/swirlds/platform/system/events/EventMetadata.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index dc4cb7ed3c52..d17960031ae4 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -133,7 +133,8 @@ public EventMetadata(@NonNull final GossipEvent gossipEvent) { Objects.requireNonNull(gossipEvent.eventTransaction(), "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); - // TODO: Once GossipEvent protobuf changes are merged, we should populate either transactions or transactionsBytes + // TODO: Once GossipEvent protobuf changes are merged, we should populate either transactions or + // transactionsBytes // depending on the data loaded in the protobuf this.transactionsBytes = new ArrayList<>(); } From 95a0680b45efc2cb851f3c5084bfe4215e10cd8e Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 3 Dec 2024 18:01:44 +0200 Subject: [PATCH 06/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../embedded/fakes/FakeConsensusEvent.java | 6 ------ .../swirlds/demo/iss/ISSTestingToolState.java | 20 ++++++++++++++++--- .../swirlds/platform/event/PlatformEvent.java | 5 ----- .../platform/system/events/CesEvent.java | 6 ------ .../system/events/ConsensusEvent.java | 11 ---------- 5 files changed, 17 insertions(+), 31 deletions(-) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java index cf819a0f657a..9d968bfe4481 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/junit/hedera/embedded/fakes/FakeConsensusEvent.java @@ -19,7 +19,6 @@ import static java.util.Objects.requireNonNull; import com.hedera.hapi.node.base.SemanticVersion; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; @@ -47,11 +46,6 @@ public FakeConsensusEvent( return Collections.singleton((ConsensusTransaction) transaction).iterator(); } - @Override - public @NonNull Iterator transactionBytesIterator() { - return Collections.singleton(transaction.getTransactionsBytes()).iterator(); - } - @Override public long getConsensusOrder() { return consensusOrder; 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 c551eb9208f1..defa86bfeaea 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 @@ -36,6 +36,7 @@ import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; import com.hedera.hapi.platform.event.EventTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; @@ -294,10 +295,12 @@ private void handleTransaction(final ConsensusTransaction transaction) { delta = ByteUtils.byteArrayToInt( transaction.getApplicationTransaction().toByteArray(), 0); + } else { - // TODO: Currently all type of transactions will update this state. Once platform registers callbacks on the - // services.app for getting back system transactions, application transactions will be filtered, so that - // only they will update the state. + if (isSystemTransaction(transaction.getTransactionsBytes())) { + return; + } + delta = ByteUtils.byteArrayToInt(transaction.getTransactionsBytes().toByteArray(), 0); } @@ -305,6 +308,17 @@ private void handleTransaction(final ConsensusTransaction transaction) { setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); } + // TODO Temporary method to filter out system transactions, so that platform is tested with application and system + // transactions. Once callbacks are introduced this method won't be needed. + private boolean isSystemTransaction(final Bytes transactionBytes) { + if (transactionBytes == null || transactionBytes.length() == 0) { + return false; + } + + final var transaction = transactionBytes.toByteArray(); + return transaction[0] != 0; + } + /** * Iterate over a list of planned incidents, and return the first one that should be triggered. If no incident from * the list should be triggered, return null diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java index 884562f58a13..d213a92af842 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/event/PlatformEvent.java @@ -205,11 +205,6 @@ public Iterator transactionIterator() { return new TypedIterator<>(metadata.getTransactions().iterator()); } - @Override - public Iterator transactionBytesIterator() { - return new TypedIterator<>(metadata.getTransactionsBytes().iterator()); - } - @Override public Instant getTimeCreated() { return metadata.getTimeCreated(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java index af2e9169b47e..f19b279f689a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/CesEvent.java @@ -146,12 +146,6 @@ public Iterator consensusTransactionIterator() { return platformEvent.consensusTransactionIterator(); } - @Override - @NonNull - public Iterator transactionBytesIterator() { - return platformEvent.transactionBytesIterator(); - } - @Override public long getConsensusOrder() { return platformEvent.getConsensusOrder(); diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java index c8b8b53928bc..5df0be83f073 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/ConsensusEvent.java @@ -16,7 +16,6 @@ package com.swirlds.platform.system.events; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.system.ReachedConsensus; import com.swirlds.platform.system.transaction.ConsensusTransaction; import edu.umd.cs.findbugs.annotations.NonNull; @@ -38,15 +37,5 @@ public interface ConsensusEvent extends Event, ReachedConsensus { * @return a consensus transaction iterator */ @NonNull - @Deprecated Iterator consensusTransactionIterator(); - - /** - * Returns an iterator over the application events in this transaction, which have all reached consensus in {@link Bytes} format. Each - * invocation returns a new iterator over the same transactions. This method is thread safe. - * - * @return a consensus transaction iterator - */ - @NonNull - Iterator transactionBytesIterator(); } From d36f76c5fddb6f7e89223a0a46ef0b96f9ad3e5b Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 4 Dec 2024 14:31:12 +0200 Subject: [PATCH 07/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 2 -- .../platform/system/events/EventMetadata.java | 20 +------------------ .../transaction/TransactionWrapper.java | 10 +++++++++- 3 files changed, 10 insertions(+), 22 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 defa86bfeaea..1268ff120702 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 @@ -308,8 +308,6 @@ private void handleTransaction(final ConsensusTransaction transaction) { setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); } - // TODO Temporary method to filter out system transactions, so that platform is tested with application and system - // transactions. Once callbacks are introduced this method won't be needed. private boolean isSystemTransaction(final Bytes transactionBytes) { if (transactionBytes == null || transactionBytes.length() == 0) { return false; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index d17960031ae4..8e04086a3524 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -20,7 +20,6 @@ import com.hedera.hapi.platform.event.EventTransaction; import com.hedera.hapi.platform.event.GossipEvent; import com.hedera.hapi.util.HapiUtils; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.AbstractHashable; import com.swirlds.common.crypto.Hash; import com.swirlds.common.platform.NodeId; @@ -28,7 +27,6 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.time.Instant; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Stream; @@ -66,10 +64,7 @@ public class EventMetadata extends AbstractHashable { * list of transactions */ private final List transactions; - /** - * The bytes of the transactions - */ - private final List transactionsBytes; + /** * The event descriptor for this event. Is not itself hashed. */ @@ -103,7 +98,6 @@ public EventMetadata( this.transactions = Objects.requireNonNull(transactions, "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); - this.transactionsBytes = new ArrayList<>(); } /** @@ -133,10 +127,6 @@ public EventMetadata(@NonNull final GossipEvent gossipEvent) { Objects.requireNonNull(gossipEvent.eventTransaction(), "transactions must not be null").stream() .map(TransactionWrapper::new) .toList(); - // TODO: Once GossipEvent protobuf changes are merged, we should populate either transactions or - // transactionsBytes - // depending on the data loaded in the protobuf - this.transactionsBytes = new ArrayList<>(); } private static long calculateGeneration(@NonNull final List allParents) { @@ -218,14 +208,6 @@ public List getTransactions() { return transactions; } - /** - * @return list of transactions bytes - */ - @NonNull - public List getTransactionsBytes() { - return transactionsBytes; - } - public long getGeneration() { return generation; } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 0fdcbdeed725..8cfdb534916b 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -136,7 +136,15 @@ public EventTransaction getTransaction() { @Override @NonNull public Bytes getTransactionsBytes() { - return payloadBytes; + if (payloadBytes != null && payloadBytes.length() > 0) { + return payloadBytes; + } + + if (payload != null && payload.applicationTransaction() != null) { + return payload.applicationTransaction(); + } + + return Bytes.EMPTY; } /** From 6ce8d97a55dc2de2dcd444e1b1076f700e950934 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 9 Dec 2024 15:09:14 +0200 Subject: [PATCH 08/39] nit: refactor ISSTestingTool based on PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 25 +++++-------------- .../demo/iss/TransactionGenerator.java | 13 ++++++++-- .../system/transaction/Transaction.java | 7 ------ .../transaction/TransactionWrapper.java | 24 +++--------------- 4 files changed, 21 insertions(+), 48 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 814e9e380601..45e84d970345 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 @@ -35,9 +35,8 @@ import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; -import com.hedera.hapi.platform.event.EventTransaction; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; @@ -294,24 +293,12 @@ private void captureTimestamp(final ConsensusEvent event) { * @param transaction the transaction to apply */ private void handleTransaction(final ConsensusTransaction transaction) { - int delta; - - if (!transaction.getTransaction().equals(EventTransaction.DEFAULT)) { - if (transaction.isSystem()) { - return; - } - - delta = ByteUtils.byteArrayToInt( - transaction.getApplicationTransaction().toByteArray(), 0); - - } else { - if (isSystemTransaction(transaction.getTransactionsBytes())) { - return; - } - - delta = ByteUtils.byteArrayToInt(transaction.getTransactionsBytes().toByteArray(), 0); + if (isSystemTransaction(transaction.getApplicationTransaction())) { + return; } + final int delta = + ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0); runningSum += delta; setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); } @@ -322,7 +309,7 @@ private boolean isSystemTransaction(final Bytes transactionBytes) { } final var transaction = transactionBytes.toByteArray(); - return transaction[0] != 0; + return transaction.length > 4; } /** diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java index 6c4c7ce94b10..09e20335a07b 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java @@ -16,8 +16,10 @@ package com.swirlds.demo.iss; +import static com.swirlds.common.test.fixtures.RandomUtils.nextLong; import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager; import static com.swirlds.common.utility.ByteUtils.intToByteArray; +import static com.swirlds.common.utility.ByteUtils.longToByteArray; import com.swirlds.base.state.Startable; import com.swirlds.common.threading.framework.StoppableThread; @@ -65,7 +67,14 @@ public void start() { * Generate and submit a single transaction. */ private void generateTransaction() { - // Transactions are simple: take an integer, and add it into the running sum. - platform.createTransaction(intToByteArray(random.nextInt())); + // Transactions are simple: take an integer, and add it into the running sum. On predefined condition a system + // transaction will be passed, so that ISS is tested for both application and system transactions. + + final var nextValue = random.nextInt(); + if (nextValue % 2 == 0) { + platform.createTransaction(longToByteArray(nextLong())); + } else { + platform.createTransaction(intToByteArray(nextValue)); + } } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index b3698b25bf09..25aedac4aa9c 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -39,13 +39,6 @@ public sealed interface Transaction permits ConsensusTransaction { @Deprecated EventTransaction getTransaction(); - /** - * Returns the transaction bytes as a PBJ record - * @return the transaction - */ - @NonNull - Bytes getTransactionsBytes(); - /** * A convenience method for retrieving the application transaction {@link Bytes} object. Before calling this method, * ensure that the transaction is not a system transaction by calling {@link #isSystem()}. diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 8cfdb534916b..2cec604cec29 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -30,6 +30,7 @@ * A transaction that may or may not reach consensus. */ public non-sealed class TransactionWrapper implements ConsensusTransaction { + /** * The consensus timestamp of this transaction, or null if consensus has not yet been reached. * NOT serialized and not part of object equality or hash code @@ -39,8 +40,6 @@ public non-sealed class TransactionWrapper implements ConsensusTransaction { private Object metadata; /** The protobuf data stored */ private final EventTransaction payload; - /** The protobuf transaction data stored as bytes */ - private final Bytes payloadBytes; /** The hash of the transaction */ private Bytes hash; @@ -54,7 +53,6 @@ public non-sealed class TransactionWrapper implements ConsensusTransaction { public TransactionWrapper(@NonNull final OneOf transaction) { Objects.requireNonNull(transaction, "transaction should not be null"); this.payload = new EventTransaction(transaction); - this.payloadBytes = Bytes.EMPTY; } /** @@ -66,7 +64,6 @@ public TransactionWrapper(@NonNull final OneOf transaction */ public TransactionWrapper(@NonNull final EventTransaction transaction) { this.payload = Objects.requireNonNull(transaction, "transaction should not be null"); - this.payloadBytes = Bytes.EMPTY; } /** @@ -77,8 +74,9 @@ public TransactionWrapper(@NonNull final EventTransaction transaction) { * @throws NullPointerException if payloadBytes is null */ public TransactionWrapper(@NonNull final Bytes payloadBytes) { - this.payload = EventTransaction.DEFAULT; - this.payloadBytes = Objects.requireNonNull(payloadBytes, "payloadBytes should not be null"); + this.payload = EventTransaction.newBuilder() + .applicationTransaction(payloadBytes) + .build(); } /** @@ -133,20 +131,6 @@ public EventTransaction getTransaction() { return payload; } - @Override - @NonNull - public Bytes getTransactionsBytes() { - if (payloadBytes != null && payloadBytes.length() > 0) { - return payloadBytes; - } - - if (payload != null && payload.applicationTransaction() != null) { - return payload.applicationTransaction(); - } - - return Bytes.EMPTY; - } - /** * Get the serialized size of the transaction. This method returns the same value as * {@code SwirldsTransaction.getSerializedLength()} and {@code StateSignatureTransaction.getSerializedLength()}. From 02a6496021ba77d78da3a2d366a39af7eca2154b Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 10 Dec 2024 10:55:56 +0200 Subject: [PATCH 09/39] test: add unit tests for ISSTestingToolState Signed-off-by: Ivan Kavaldzhiev --- .../tests/ISSTestingTool/build.gradle.kts | 6 + .../demo/iss/ISSTestingToolStateTest.java | 128 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts index 0ccf911efacb..eb6619667b8b 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts @@ -19,3 +19,9 @@ plugins { id("com.hedera.gradle.application") } application.mainClass.set("com.swirlds.demo.iss.ISSTestingToolMain") mainModuleInfo { annotationProcessor("com.swirlds.config.processor") } + +testModuleInfo { + requires("org.assertj.core") + requires("org.junit.jupiter.api") + requires("org.mockito") +} diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java new file mode 100644 index 000000000000..b884427cda65 --- /dev/null +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -0,0 +1,128 @@ +/* + * 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.demo.iss; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; +import com.swirlds.platform.components.transaction.system.ScopedSystemTransaction; +import com.swirlds.platform.state.MerkleStateLifecycles; +import com.swirlds.platform.state.PlatformStateModifier; +import com.swirlds.platform.system.Round; +import com.swirlds.platform.system.events.ConsensusEvent; +import com.swirlds.platform.system.transaction.ConsensusTransaction; +import com.swirlds.platform.system.transaction.TransactionWrapper; +import com.swirlds.state.merkle.singleton.StringLeaf; +import java.time.Instant; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class ISSTestingToolStateTest { + + private static final int RUNNING_SUM_INDEX = 1; + private ISSTestingToolState state; + private PlatformStateModifier platformStateModifier; + private Round round; + private ConsensusEvent event; + private Consumer>> consumer; + private ConsensusTransaction consensusTransaction; + + @BeforeEach + void setUp() { + state = new ISSTestingToolState(mock(MerkleStateLifecycles.class), mock(Function.class)); + platformStateModifier = mock(PlatformStateModifier.class); + round = mock(Round.class); + event = mock(ConsensusEvent.class); + consumer = mock(Consumer.class); + consensusTransaction = mock(TransactionWrapper.class); + } + + @Test + void handleConsensusRoundWithApplicationTransaction() { + // Given + givenRoundAndEvent(); + + final var bytes = Bytes.wrap(new byte[] {1, 1, 1, 1}); + when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) + .isGreaterThan(0L); + } + + @Test + void handleConsensusRoundWithSystemTransaction() { + // Given + givenRoundAndEvent(); + + final var bytes = Bytes.wrap(new byte[] {1, 0, 1, 1, 0, 1, 0, 0}); + when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); + } + + @Test + void handleConsensusRoundWithEmptyTransaction() { + // Given + givenRoundAndEvent(); + + final var bytes = Bytes.wrap(new byte[0]); + when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) + .isEqualTo(0L); + } + + private void givenRoundAndEvent() { + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(event.getConsensusTimestamp()).thenReturn(Instant.now()); + when(event.consensusTransactionIterator()) + .thenReturn(Collections.singletonList(consensusTransaction).iterator()); + } +} From 7b73cd4ea980b574a66a8141490a0129e1816157 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 11 Dec 2024 15:47:31 +0200 Subject: [PATCH 10/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../main/java/com/swirlds/demo/iss/ISSTestingToolState.java | 3 +-- .../com/swirlds/platform/system/transaction/Transaction.java | 1 - 2 files changed, 1 insertion(+), 3 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 569040e64fcd..cf53551db52d 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 @@ -309,8 +309,7 @@ private boolean isSystemTransaction(final Bytes transactionBytes) { return false; } - final var transaction = transactionBytes.toByteArray(); - return transaction.length > 4; + return transactionBytes.length() > 4; } /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index 25aedac4aa9c..a730091f8820 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -45,7 +45,6 @@ public sealed interface Transaction permits ConsensusTransaction { * * @return the application transaction Bytes or {@code Bytes.EMPTY} if the transaction is a system transaction */ - @Deprecated default @NonNull Bytes getApplicationTransaction() { return !isSystem() ? getTransaction().transaction().as() : Bytes.EMPTY; } From d3d61989461861e5972f22017b164cb272fd67f0 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 11 Dec 2024 17:11:07 +0200 Subject: [PATCH 11/39] test: fix unit tests Signed-off-by: Ivan Kavaldzhiev --- .../test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index b884427cda65..c262e9817e05 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -42,7 +42,7 @@ class ISSTestingToolStateTest { - private static final int RUNNING_SUM_INDEX = 1; + private static final int RUNNING_SUM_INDEX = 3; private ISSTestingToolState state; private PlatformStateModifier platformStateModifier; private Round round; From bb702bcaafd1497be66aa3e967895d7f07c0b01a Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 12 Dec 2024 18:15:44 +0200 Subject: [PATCH 12/39] refactor: add StateSignatureTransaction encoding logic + logic for distinguishing StateSignatureTransaction from Bytes Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolMain.java | 3 +- .../swirlds/demo/iss/ISSTestingToolState.java | 39 ++++++++++++++-- .../demo/iss/TransactionGenerator.java | 46 +++++++++++++++---- .../src/main/java/module-info.java | 1 + .../swirlds/platform/system/SwirldState.java | 5 ++ 5 files changed, 79 insertions(+), 15 deletions(-) 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 6718d6c10503..a75c4bdc0b40 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 @@ -102,7 +102,8 @@ public void run() { final ISSTestingToolConfig testingToolConfig = platform.getContext().getConfiguration().getConfigData(ISSTestingToolConfig.class); - new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond()).start(); + final var state = platform.getLatestImmutableState("ISSTestingToolMain.run()"); + new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond(), state.get()).start(); } /** 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 cf53551db52d..d466aeabfe95 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 @@ -26,16 +26,22 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ +import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TRANSACTION; +import static com.hedera.hapi.node.base.ResponseCodeEnum.TRANSACTION_OVERSIZE; import static com.swirlds.common.utility.CompareTo.isGreaterThan; import static com.swirlds.common.utility.CompareTo.isLessThan; import static com.swirlds.common.utility.NonCryptographicHashing.hash64; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; +import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hapi.node.base.SemanticVersion; +import com.hedera.hapi.node.base.Transaction; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; +import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.ParseException; import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; @@ -294,7 +300,7 @@ private void captureTimestamp(final ConsensusEvent event) { * @param transaction the transaction to apply */ private void handleTransaction(final ConsensusTransaction transaction) { - if (isSystemTransaction(transaction.getApplicationTransaction())) { + if (isSystemTransaction(transaction)) { return; } @@ -304,12 +310,32 @@ private void handleTransaction(final ConsensusTransaction transaction) { setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); } - private boolean isSystemTransaction(final Bytes transactionBytes) { - if (transactionBytes == null || transactionBytes.length() == 0) { + private boolean isSystemTransaction(final ConsensusTransaction transaction) { + if(transaction.isSystem()) { + return true; + } + + try { + final var parsedTransaction = Transaction.PROTOBUF.parseStrict(transaction.getApplicationTransaction().toReadableSequentialData()); + + Bytes bodyBytes; + if(parsedTransaction.signedTransactionBytes().length() > 0) { + bodyBytes = parsedTransaction.signedTransactionBytes(); + } else { + bodyBytes = parsedTransaction.bodyBytes(); + } + + final var parsedTransactionBody = TransactionBody.PROTOBUF.parseStrict(bodyBytes.toReadableSequentialData()); + + if(parsedTransactionBody.stateSignatureTransaction() != null) { + return true; + } + } catch (ParseException e) { + logger.error("Failed to parse transaction body", e); return false; } - return transactionBytes.length() > 4; + return false; } /** @@ -497,4 +523,9 @@ public int getVersion() { public int getMinimumSupportedVersion() { return ClassVersion.ORIGINAL; } + + @Override + public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + return StateSignatureTransaction.PROTOBUF.toBytes(transaction); + } } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java index 09e20335a07b..7a7b201c53cf 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java @@ -21,11 +21,15 @@ import static com.swirlds.common.utility.ByteUtils.intToByteArray; import static com.swirlds.common.utility.ByteUtils.longToByteArray; +import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.base.state.Startable; import com.swirlds.common.threading.framework.StoppableThread; import com.swirlds.common.threading.framework.config.StoppableThreadConfiguration; import com.swirlds.platform.system.Platform; +import com.swirlds.platform.system.SwirldState; import java.util.Random; +import java.util.function.Supplier; /** * Generates and submits transactional workload. @@ -34,14 +38,17 @@ public class TransactionGenerator implements Startable { private final Random random; private final Platform platform; + private final ISSTestingToolState issTestingToolState; private final StoppableThread thread; + private final StoppableThread systemTransactionsThread; public TransactionGenerator( - final Random random, final Platform platform, final int networkWideTransactionsPerSecond) { + final Random random, final Platform platform, final int networkWideTransactionsPerSecond, final SwirldState issTestingToolState) { this.random = random; this.platform = platform; + this.issTestingToolState = (ISSTestingToolState) issTestingToolState; // Each node in an N node network should create 1/N transactions per second. final int tps = networkWideTransactionsPerSecond @@ -53,6 +60,13 @@ public TransactionGenerator( .setMaximumRate(tps) .setWork(this::generateTransaction) .build(); + + systemTransactionsThread = new StoppableThreadConfiguration<>(getStaticThreadManager()) + .setComponent("iss-testing-tool") + .setThreadName("system-transaction-generator") + .setMaximumRate(tps) + .setWork(this::generateSystemTransaction) + .build(); } /** @@ -61,20 +75,32 @@ public TransactionGenerator( @Override public void start() { thread.start(); + systemTransactionsThread.start(); } /** * Generate and submit a single transaction. */ private void generateTransaction() { - // Transactions are simple: take an integer, and add it into the running sum. On predefined condition a system - // transaction will be passed, so that ISS is tested for both application and system transactions. - - final var nextValue = random.nextInt(); - if (nextValue % 2 == 0) { - platform.createTransaction(longToByteArray(nextLong())); - } else { - platform.createTransaction(intToByteArray(nextValue)); - } + // Transactions are simple: take an integer, and add it into the running sum. + platform.createTransaction(intToByteArray(random.nextInt())); + } + + /** + * Generates and submits a system transaction. + * This method creates a StateSignatureTransaction with a random round number, + * signature, and hash, encodes it, and submits it to the platform. + */ + private void generateSystemTransaction() { + final long round = nextLong(); + final byte[] signature = new byte[384]; + random.nextBytes(signature); + final byte[] hash = new byte[48]; + random.nextBytes(hash); + final var stateSignatureTransaction = StateSignatureTransaction.newBuilder().signature(Bytes.wrap(signature)).hash(Bytes.wrap(hash)).round(round).build(); + + final var encodedStateSignatureTransaction = issTestingToolState.encodeSystemTransaction(stateSignatureTransaction); + + platform.createTransaction(encodedStateSignatureTransaction.toByteArray()); } } 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 4ce4678c3c5f..164fe6d73e79 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 @@ -11,4 +11,5 @@ requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; + requires com.google.protobuf; } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java index a6d0368bea77..83db68278d8c 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java @@ -17,6 +17,7 @@ package com.swirlds.platform.system; import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.context.PlatformContext; import com.swirlds.common.merkle.MerkleNode; import com.swirlds.platform.components.transaction.system.ScopedSystemTransaction; @@ -125,4 +126,8 @@ default AddressBook updateWeight( */ @Override SwirldState copy(); + + default Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + return Bytes.EMPTY; + } } From b2160609a901b89c8c7d2c9470346c83831181b8 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 12 Dec 2024 21:43:40 +0200 Subject: [PATCH 13/39] style: spotless Signed-off-by: Ivan Kavaldzhiev --- .../com/swirlds/demo/iss/ISSTestingToolMain.java | 3 ++- .../swirlds/demo/iss/ISSTestingToolState.java | 15 +++++++-------- .../swirlds/demo/iss/TransactionGenerator.java | 16 +++++++++++----- .../src/main/java/module-info.java | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) 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 a75c4bdc0b40..72c349436343 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 @@ -103,7 +103,8 @@ public void run() { platform.getContext().getConfiguration().getConfigData(ISSTestingToolConfig.class); final var state = platform.getLatestImmutableState("ISSTestingToolMain.run()"); - new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond(), state.get()).start(); + new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond(), state.get()) + .start(); } /** 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 d466aeabfe95..b94c9ea1768b 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 @@ -26,15 +26,12 @@ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ -import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TRANSACTION; -import static com.hedera.hapi.node.base.ResponseCodeEnum.TRANSACTION_OVERSIZE; import static com.swirlds.common.utility.CompareTo.isGreaterThan; import static com.swirlds.common.utility.CompareTo.isLessThan; import static com.swirlds.common.utility.NonCryptographicHashing.hash64; import static com.swirlds.logging.legacy.LogMarker.EXCEPTION; import static com.swirlds.logging.legacy.LogMarker.STARTUP; -import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hapi.node.base.SemanticVersion; import com.hedera.hapi.node.base.Transaction; import com.hedera.hapi.node.state.roster.Roster; @@ -311,23 +308,25 @@ private void handleTransaction(final ConsensusTransaction transaction) { } private boolean isSystemTransaction(final ConsensusTransaction transaction) { - if(transaction.isSystem()) { + if (transaction.isSystem()) { return true; } try { - final var parsedTransaction = Transaction.PROTOBUF.parseStrict(transaction.getApplicationTransaction().toReadableSequentialData()); + final var parsedTransaction = Transaction.PROTOBUF.parseStrict( + transaction.getApplicationTransaction().toReadableSequentialData()); Bytes bodyBytes; - if(parsedTransaction.signedTransactionBytes().length() > 0) { + if (parsedTransaction.signedTransactionBytes().length() > 0) { bodyBytes = parsedTransaction.signedTransactionBytes(); } else { bodyBytes = parsedTransaction.bodyBytes(); } - final var parsedTransactionBody = TransactionBody.PROTOBUF.parseStrict(bodyBytes.toReadableSequentialData()); + final var parsedTransactionBody = + TransactionBody.PROTOBUF.parseStrict(bodyBytes.toReadableSequentialData()); - if(parsedTransactionBody.stateSignatureTransaction() != null) { + if (parsedTransactionBody.stateSignatureTransaction() != null) { return true; } } catch (ParseException e) { diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java index 7a7b201c53cf..2767614f6ce7 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java @@ -19,7 +19,6 @@ import static com.swirlds.common.test.fixtures.RandomUtils.nextLong; import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager; import static com.swirlds.common.utility.ByteUtils.intToByteArray; -import static com.swirlds.common.utility.ByteUtils.longToByteArray; import com.hedera.hapi.platform.event.StateSignatureTransaction; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -29,7 +28,6 @@ import com.swirlds.platform.system.Platform; import com.swirlds.platform.system.SwirldState; import java.util.Random; -import java.util.function.Supplier; /** * Generates and submits transactional workload. @@ -44,7 +42,10 @@ public class TransactionGenerator implements Startable { private final StoppableThread systemTransactionsThread; public TransactionGenerator( - final Random random, final Platform platform, final int networkWideTransactionsPerSecond, final SwirldState issTestingToolState) { + final Random random, + final Platform platform, + final int networkWideTransactionsPerSecond, + final SwirldState issTestingToolState) { this.random = random; this.platform = platform; @@ -97,9 +98,14 @@ private void generateSystemTransaction() { random.nextBytes(signature); final byte[] hash = new byte[48]; random.nextBytes(hash); - final var stateSignatureTransaction = StateSignatureTransaction.newBuilder().signature(Bytes.wrap(signature)).hash(Bytes.wrap(hash)).round(round).build(); + final var stateSignatureTransaction = StateSignatureTransaction.newBuilder() + .signature(Bytes.wrap(signature)) + .hash(Bytes.wrap(hash)) + .round(round) + .build(); - final var encodedStateSignatureTransaction = issTestingToolState.encodeSystemTransaction(stateSignatureTransaction); + final var encodedStateSignatureTransaction = + issTestingToolState.encodeSystemTransaction(stateSignatureTransaction); platform.createTransaction(encodedStateSignatureTransaction.toByteArray()); } 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 164fe6d73e79..a2944659cea7 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 @@ -8,8 +8,8 @@ requires com.swirlds.platform.core; requires com.swirlds.state.api; requires com.swirlds.state.impl; + requires com.google.protobuf; requires com.hedera.pbj.runtime; requires org.apache.logging.log4j; requires static com.github.spotbugs.annotations; - requires com.google.protobuf; } From b878e2786f2d80d2ba1a1d4ab70220bf0a05c68f Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Fri, 13 Dec 2024 08:40:57 +0200 Subject: [PATCH 14/39] fix: unit test Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 18 ++++-------------- .../src/main/java/module-info.java | 1 - .../demo/iss/ISSTestingToolStateTest.java | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 17 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 b94c9ea1768b..a6554c9e9518 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,10 +33,8 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; -import com.hedera.hapi.node.base.Transaction; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; -import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.hapi.platform.event.StateSignatureTransaction; import com.hedera.pbj.runtime.ParseException; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -313,20 +311,12 @@ private boolean isSystemTransaction(final ConsensusTransaction transaction) { } try { - final var parsedTransaction = Transaction.PROTOBUF.parseStrict( - transaction.getApplicationTransaction().toReadableSequentialData()); - - Bytes bodyBytes; - if (parsedTransaction.signedTransactionBytes().length() > 0) { - bodyBytes = parsedTransaction.signedTransactionBytes(); - } else { - bodyBytes = parsedTransaction.bodyBytes(); - } + final var transactionBytes = transaction.getApplicationTransaction(); - final var parsedTransactionBody = - TransactionBody.PROTOBUF.parseStrict(bodyBytes.toReadableSequentialData()); + final var parsedStateSignatureTransaction = + StateSignatureTransaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); - if (parsedTransactionBody.stateSignatureTransaction() != null) { + if (parsedStateSignatureTransaction.signature() != Bytes.EMPTY) { return true; } } catch (ParseException e) { 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 a2944659cea7..4ce4678c3c5f 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 @@ -8,7 +8,6 @@ requires com.swirlds.platform.core; requires com.swirlds.state.api; requires com.swirlds.state.impl; - requires com.google.protobuf; 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/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index c262e9817e05..64d6d36d3b8d 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -35,6 +35,7 @@ import java.time.Instant; import java.util.Collections; import java.util.List; +import java.util.Random; import java.util.function.Consumer; import java.util.function.Function; import org.junit.jupiter.api.BeforeEach; @@ -43,6 +44,7 @@ class ISSTestingToolStateTest { private static final int RUNNING_SUM_INDEX = 3; + private Random random; private ISSTestingToolState state; private PlatformStateModifier platformStateModifier; private Round round; @@ -53,6 +55,7 @@ class ISSTestingToolStateTest { @BeforeEach void setUp() { state = new ISSTestingToolState(mock(MerkleStateLifecycles.class), mock(Function.class)); + random = new Random(); platformStateModifier = mock(PlatformStateModifier.class); round = mock(Round.class); event = mock(ConsensusEvent.class); @@ -85,8 +88,18 @@ void handleConsensusRoundWithSystemTransaction() { // Given givenRoundAndEvent(); - final var bytes = Bytes.wrap(new byte[] {1, 0, 1, 1, 0, 1, 0, 0}); - when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + final byte[] signature = new byte[384]; + random.nextBytes(signature); + final byte[] hash = new byte[48]; + random.nextBytes(hash); + final var stateSignatureTransaction = StateSignatureTransaction.newBuilder() + .signature(Bytes.wrap(signature)) + .hash(Bytes.wrap(hash)) + .round(round.getRoundNum()) + .build(); + + final var encodedStateSignatureTransaction = state.encodeSystemTransaction(stateSignatureTransaction); + when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); // When state.handleConsensusRound(round, platformStateModifier, consumer); From 8fa4ac518bd2d3d5506c4be6cb88048627983050 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 16 Dec 2024 15:57:53 +0200 Subject: [PATCH 15/39] nit: increase test coverage Signed-off-by: Ivan Kavaldzhiev --- .../demo/iss/ISSTestingToolStateTest.java | 18 ++++++ .../demo/iss/TransactionGeneratorTest.java | 56 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 64d6d36d3b8d..8ea6c21eb886 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -112,6 +112,24 @@ void handleConsensusRoundWithSystemTransaction() { assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); } + @Test + void handleConsensusRoundWithDeprecatedSystemTransaction() { + // Given + givenRoundAndEvent(); + + when(consensusTransaction.isSystem()).thenReturn(true); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); + } + @Test void handleConsensusRoundWithEmptyTransaction() { // Given diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java new file mode 100644 index 000000000000..54cc3a6756e0 --- /dev/null +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java @@ -0,0 +1,56 @@ +/* + * 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.demo.iss; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.hedera.hapi.node.state.roster.Roster; +import com.hedera.hapi.node.state.roster.RosterEntry; +import com.hedera.pbj.runtime.io.buffer.Bytes; +import com.swirlds.platform.system.Platform; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import org.junit.jupiter.api.Test; + +class TransactionGeneratorTest { + + @Test + void startTransactionGenerator() { + // Given + final var random = new Random(); + final var platform = mock(Platform.class); + final var roster = new Roster(List.of(new RosterEntry(1, 5, Bytes.EMPTY, new ArrayList<>()))); + final var networkWideTransactionsPerSecond = 100; + final var issTestingToolState = mock(ISSTestingToolState.class); + + // When + when(platform.getRoster()).thenReturn(roster); + + final var transactionGenerator = + new TransactionGenerator(random, platform, networkWideTransactionsPerSecond, issTestingToolState); + transactionGenerator.start(); + + // Then + verify(issTestingToolState, atLeastOnce()).encodeSystemTransaction(any()); + verify(platform, atLeastOnce()).createTransaction(any()); + } +} From f69f06296e974289a06857e1f9fd4e23d69fdb8f Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 16 Dec 2024 17:00:01 +0200 Subject: [PATCH 16/39] nit: fix unit test Signed-off-by: Ivan Kavaldzhiev --- .../java/com/swirlds/demo/iss/TransactionGeneratorTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java index 54cc3a6756e0..4fc7e0c56136 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java @@ -16,6 +16,7 @@ package com.swirlds.demo.iss; +import static com.swirlds.common.utility.ByteUtils.intToByteArray; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; @@ -44,12 +45,15 @@ void startTransactionGenerator() { // When when(platform.getRoster()).thenReturn(roster); + when(issTestingToolState.encodeSystemTransaction(any())) + .thenReturn(Bytes.wrap(intToByteArray(random.nextInt()))); final var transactionGenerator = new TransactionGenerator(random, platform, networkWideTransactionsPerSecond, issTestingToolState); transactionGenerator.start(); // Then + verify(platform, atLeastOnce()).getRoster(); verify(issTestingToolState, atLeastOnce()).encodeSystemTransaction(any()); verify(platform, atLeastOnce()).createTransaction(any()); } From 8ccbb06f90e530b267f1e186870a3a58cb191f8e Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 16 Dec 2024 17:49:19 +0200 Subject: [PATCH 17/39] nit: fix test Signed-off-by: Ivan Kavaldzhiev --- .../java/com/swirlds/demo/iss/TransactionGeneratorTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java index 4fc7e0c56136..4e856cb2a877 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java @@ -54,7 +54,5 @@ void startTransactionGenerator() { // Then verify(platform, atLeastOnce()).getRoster(); - verify(issTestingToolState, atLeastOnce()).encodeSystemTransaction(any()); - verify(platform, atLeastOnce()).createTransaction(any()); } } From 5fbbf90cb90b399037f6ca37f599c77e743c90f9 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 17 Dec 2024 11:14:03 +0200 Subject: [PATCH 18/39] refactor: update system transaction encoding logic and tests Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 32 ++++++++++++++++--- .../demo/iss/ISSTestingToolStateTest.java | 24 ++++++++++++-- 2 files changed, 49 insertions(+), 7 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 a6554c9e9518..eb0d4c811e78 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,8 +33,12 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; +import com.hedera.hapi.node.base.SignatureList; +import com.hedera.hapi.node.base.SignatureMap; +import com.hedera.hapi.node.base.Transaction; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; +import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.hapi.platform.event.StateSignatureTransaction; import com.hedera.pbj.runtime.ParseException; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -313,10 +317,15 @@ private boolean isSystemTransaction(final ConsensusTransaction transaction) { try { final var transactionBytes = transaction.getApplicationTransaction(); - final var parsedStateSignatureTransaction = - StateSignatureTransaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); + if (Bytes.EMPTY.equals(transaction.getApplicationTransaction())) { + return false; + } + + final var parsedTransaction = Transaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); + + final var stateSignatureTransaction = parsedTransaction.body(); - if (parsedStateSignatureTransaction.signature() != Bytes.EMPTY) { + if (stateSignatureTransaction.stateSignatureTransaction().signature() != Bytes.EMPTY) { return true; } } catch (ParseException e) { @@ -514,7 +523,20 @@ public int getMinimumSupportedVersion() { } @Override - public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { - return StateSignatureTransaction.PROTOBUF.toBytes(transaction); + public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction systemTransaction) { + if (systemTransaction == null) { + return Bytes.EMPTY; + } + + final var transactionBody = TransactionBody.newBuilder() + .stateSignatureTransaction(systemTransaction) + .build(); + final var transaction = Transaction.newBuilder() + .body(transactionBody) + .signedTransactionBytes(Bytes.EMPTY) + .sigMap(SignatureMap.DEFAULT) + .sigs(SignatureList.DEFAULT) + .build(); + return Transaction.PROTOBUF.toBytes(transaction); } } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 8ea6c21eb886..93d240aaf773 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -135,8 +135,28 @@ void handleConsensusRoundWithEmptyTransaction() { // Given givenRoundAndEvent(); - final var bytes = Bytes.wrap(new byte[0]); - when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + final var encodedStateSignatureTransaction = state.encodeSystemTransaction(StateSignatureTransaction.DEFAULT); + when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) + .isGreaterThan(0L); + } + + @Test + void handleConsensusRoundWithNullTransaction() { + // Given + givenRoundAndEvent(); + + final var encodedStateSignatureTransaction = state.encodeSystemTransaction(null); + when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); // When state.handleConsensusRound(round, platformStateModifier, consumer); From 46190eb7423a756b9cfc5feab864956d4b3b3046 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 17 Dec 2024 19:59:18 +0200 Subject: [PATCH 19/39] refactor: resolve PR comments and simplify ISSTestingTool logic Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolMain.java | 10 ++- .../swirlds/demo/iss/ISSTestingToolState.java | 47 ++++------ .../demo/iss/TransactionGenerator.java | 44 +--------- .../demo/iss/ISSTestingToolStateTest.java | 88 +++++++++++++++---- .../demo/iss/TransactionGeneratorTest.java | 58 ------------ .../swirlds/platform/system/SwirldMain.java | 12 +++ .../swirlds/platform/system/SwirldState.java | 5 -- 7 files changed, 108 insertions(+), 156 deletions(-) delete mode 100644 platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java 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 72c349436343..6ebe8608e752 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 @@ -20,6 +20,8 @@ import static com.swirlds.platform.test.fixtures.state.FakeMerkleStateLifecycles.FAKE_MERKLE_STATE_LIFECYCLES; import static com.swirlds.platform.test.fixtures.state.FakeMerkleStateLifecycles.registerMerkleStateRootClassIds; +import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ClassConstructorPair; import com.swirlds.common.constructable.ConstructableRegistry; import com.swirlds.common.constructable.ConstructableRegistryException; @@ -103,8 +105,7 @@ public void run() { platform.getContext().getConfiguration().getConfigData(ISSTestingToolConfig.class); final var state = platform.getLatestImmutableState("ISSTestingToolMain.run()"); - new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond(), state.get()) - .start(); + new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond()).start(); } /** @@ -136,4 +137,9 @@ public BasicSoftwareVersion getSoftwareVersion() { public List> getConfigDataTypes() { return List.of(ISSTestingToolConfig.class); } + + @Override + public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + return StateSignatureTransaction.PROTOBUF.toBytes(transaction); + } } 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 eb0d4c811e78..1f7584de8835 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,12 +33,8 @@ import static com.swirlds.logging.legacy.LogMarker.STARTUP; import com.hedera.hapi.node.base.SemanticVersion; -import com.hedera.hapi.node.base.SignatureList; -import com.hedera.hapi.node.base.SignatureMap; -import com.hedera.hapi.node.base.Transaction; import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; -import com.hedera.hapi.node.transaction.TransactionBody; import com.hedera.hapi.platform.event.StateSignatureTransaction; import com.hedera.pbj.runtime.ParseException; import com.hedera.pbj.runtime.io.buffer.Bytes; @@ -70,6 +66,7 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -255,10 +252,17 @@ public void handleConsensusRound( throwIfImmutable(); final Iterator eventIterator = round.iterator(); + final var scopedSystemTransactions = new ArrayList>(); while (eventIterator.hasNext()) { final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); - event.consensusTransactionIterator().forEachRemaining(this::handleTransaction); + event.consensusTransactionIterator().forEachRemaining(transaction -> { + final var systemTransaction = handleTransaction(transaction); + if (systemTransaction != null) { + scopedSystemTransactions.add( + new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + } + }); if (!eventIterator.hasNext()) { final Instant currentTimestamp = event.getConsensusTimestamp(); final Duration elapsedSinceGenesis = Duration.between(genesisTimestamp, currentTimestamp); @@ -281,6 +285,8 @@ public void handleConsensusRound( } } } + + stateSignatureTransactions.accept(scopedSystemTransactions); } /** @@ -298,15 +304,17 @@ private void captureTimestamp(final ConsensusEvent event) { * * @param transaction the transaction to apply */ - private void handleTransaction(final ConsensusTransaction transaction) { + private ConsensusTransaction handleTransaction(final ConsensusTransaction transaction) { if (isSystemTransaction(transaction)) { - return; + return transaction; } final int delta = ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0); runningSum += delta; setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); + + return null; } private boolean isSystemTransaction(final ConsensusTransaction transaction) { @@ -321,11 +329,10 @@ private boolean isSystemTransaction(final ConsensusTransaction transaction) { return false; } - final var parsedTransaction = Transaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); - - final var stateSignatureTransaction = parsedTransaction.body(); + final var parsedTransaction = + StateSignatureTransaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); - if (stateSignatureTransaction.stateSignatureTransaction().signature() != Bytes.EMPTY) { + if (parsedTransaction.signature() != Bytes.EMPTY) { return true; } } catch (ParseException e) { @@ -521,22 +528,4 @@ public int getVersion() { public int getMinimumSupportedVersion() { return ClassVersion.ORIGINAL; } - - @Override - public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction systemTransaction) { - if (systemTransaction == null) { - return Bytes.EMPTY; - } - - final var transactionBody = TransactionBody.newBuilder() - .stateSignatureTransaction(systemTransaction) - .build(); - final var transaction = Transaction.newBuilder() - .body(transactionBody) - .signedTransactionBytes(Bytes.EMPTY) - .sigMap(SignatureMap.DEFAULT) - .sigs(SignatureList.DEFAULT) - .build(); - return Transaction.PROTOBUF.toBytes(transaction); - } } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java index 2767614f6ce7..96ab684dd478 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java @@ -16,17 +16,13 @@ package com.swirlds.demo.iss; -import static com.swirlds.common.test.fixtures.RandomUtils.nextLong; import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager; import static com.swirlds.common.utility.ByteUtils.intToByteArray; -import com.hedera.hapi.platform.event.StateSignatureTransaction; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.base.state.Startable; import com.swirlds.common.threading.framework.StoppableThread; import com.swirlds.common.threading.framework.config.StoppableThreadConfiguration; import com.swirlds.platform.system.Platform; -import com.swirlds.platform.system.SwirldState; import java.util.Random; /** @@ -36,20 +32,13 @@ public class TransactionGenerator implements Startable { private final Random random; private final Platform platform; - private final ISSTestingToolState issTestingToolState; - private final StoppableThread thread; - private final StoppableThread systemTransactionsThread; public TransactionGenerator( - final Random random, - final Platform platform, - final int networkWideTransactionsPerSecond, - final SwirldState issTestingToolState) { + final Random random, final Platform platform, final int networkWideTransactionsPerSecond) { this.random = random; this.platform = platform; - this.issTestingToolState = (ISSTestingToolState) issTestingToolState; // Each node in an N node network should create 1/N transactions per second. final int tps = networkWideTransactionsPerSecond @@ -61,13 +50,6 @@ public TransactionGenerator( .setMaximumRate(tps) .setWork(this::generateTransaction) .build(); - - systemTransactionsThread = new StoppableThreadConfiguration<>(getStaticThreadManager()) - .setComponent("iss-testing-tool") - .setThreadName("system-transaction-generator") - .setMaximumRate(tps) - .setWork(this::generateSystemTransaction) - .build(); } /** @@ -76,7 +58,6 @@ public TransactionGenerator( @Override public void start() { thread.start(); - systemTransactionsThread.start(); } /** @@ -86,27 +67,4 @@ private void generateTransaction() { // Transactions are simple: take an integer, and add it into the running sum. platform.createTransaction(intToByteArray(random.nextInt())); } - - /** - * Generates and submits a system transaction. - * This method creates a StateSignatureTransaction with a random round number, - * signature, and hash, encodes it, and submits it to the platform. - */ - private void generateSystemTransaction() { - final long round = nextLong(); - final byte[] signature = new byte[384]; - random.nextBytes(signature); - final byte[] hash = new byte[48]; - random.nextBytes(hash); - final var stateSignatureTransaction = StateSignatureTransaction.newBuilder() - .signature(Bytes.wrap(signature)) - .hash(Bytes.wrap(hash)) - .round(round) - .build(); - - final var encodedStateSignatureTransaction = - issTestingToolState.encodeSystemTransaction(stateSignatureTransaction); - - platform.createTransaction(encodedStateSignatureTransaction.toByteArray()); - } } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 93d240aaf773..ad696ce4a7ac 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -45,22 +45,37 @@ class ISSTestingToolStateTest { private static final int RUNNING_SUM_INDEX = 3; private Random random; + private ISSTestingToolMain main; private ISSTestingToolState state; private PlatformStateModifier platformStateModifier; private Round round; private ConsensusEvent event; private Consumer>> consumer; + private int consumerSize; private ConsensusTransaction consensusTransaction; + private StateSignatureTransaction stateSignatureTransaction; @BeforeEach void setUp() { state = new ISSTestingToolState(mock(MerkleStateLifecycles.class), mock(Function.class)); + main = mock(ISSTestingToolMain.class); random = new Random(); platformStateModifier = mock(PlatformStateModifier.class); round = mock(Round.class); event = mock(ConsensusEvent.class); - consumer = mock(Consumer.class); + + consumer = systemTransactions -> consumerSize = systemTransactions.size(); consensusTransaction = mock(TransactionWrapper.class); + + final byte[] signature = new byte[384]; + random.nextBytes(signature); + final byte[] hash = new byte[48]; + random.nextBytes(hash); + stateSignatureTransaction = StateSignatureTransaction.newBuilder() + .signature(Bytes.wrap(signature)) + .hash(Bytes.wrap(hash)) + .round(round.getRoundNum()) + .build(); } @Test @@ -80,7 +95,8 @@ void handleConsensusRoundWithApplicationTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) - .isGreaterThan(0L); + .isPositive(); + assertThat(consumerSize).isZero(); } @Test @@ -88,18 +104,40 @@ void handleConsensusRoundWithSystemTransaction() { // Given givenRoundAndEvent(); - final byte[] signature = new byte[384]; - random.nextBytes(signature); - final byte[] hash = new byte[48]; - random.nextBytes(hash); - final var stateSignatureTransaction = StateSignatureTransaction.newBuilder() - .signature(Bytes.wrap(signature)) - .hash(Bytes.wrap(hash)) - .round(round.getRoundNum()) - .build(); + final var stateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); + when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes); + when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + + // When + state.handleConsensusRound(round, platformStateModifier, consumer); + + // Then + verify(round, times(1)).iterator(); + verify(event, times(2)).getConsensusTimestamp(); + verify(event, times(1)).consensusTransactionIterator(); + + assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); + assertThat(consumerSize).isEqualTo(1); + } + + @Test + void handleConsensusRoundWithMultipleSystemTransaction() { + // Given + final var secondConsensusTransaction = mock(TransactionWrapper.class); + final var thirdConsensusTransaction = mock(TransactionWrapper.class); + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(event.getConsensusTimestamp()).thenReturn(Instant.now()); + when(event.consensusTransactionIterator()) + .thenReturn(List.of(consensusTransaction, secondConsensusTransaction, thirdConsensusTransaction) + .iterator()); - final var encodedStateSignatureTransaction = state.encodeSystemTransaction(stateSignatureTransaction); - when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); + final var stateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); + when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes); + when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(secondConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(thirdConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -110,6 +148,7 @@ void handleConsensusRoundWithSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); + assertThat(consumerSize).isEqualTo(3); } @Test @@ -128,6 +167,7 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); + assertThat(consumerSize).isEqualTo(1); } @Test @@ -135,8 +175,12 @@ void handleConsensusRoundWithEmptyTransaction() { // Given givenRoundAndEvent(); - final var encodedStateSignatureTransaction = state.encodeSystemTransaction(StateSignatureTransaction.DEFAULT); - when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); + final var emptyStateSignatureTransaction = StateSignatureTransaction.DEFAULT; + final var emptyStateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction); + when(main.encodeSystemTransaction(emptyStateSignatureTransaction)) + .thenReturn(emptyStateSignatureTransactionBytes); + when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -147,7 +191,8 @@ void handleConsensusRoundWithEmptyTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) - .isGreaterThan(0L); + .isZero(); + assertThat(consumerSize).isZero(); } @Test @@ -155,8 +200,12 @@ void handleConsensusRoundWithNullTransaction() { // Given givenRoundAndEvent(); - final var encodedStateSignatureTransaction = state.encodeSystemTransaction(null); - when(consensusTransaction.getApplicationTransaction()).thenReturn(encodedStateSignatureTransaction); + final var emptyStateSignatureTransaction = StateSignatureTransaction.DEFAULT; + final var emptyStateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction); + when(main.encodeSystemTransaction(null)) + .thenReturn(StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction)); + when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -167,7 +216,8 @@ void handleConsensusRoundWithNullTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) - .isEqualTo(0L); + .isZero(); + assertThat(consumerSize).isZero(); } private void givenRoundAndEvent() { diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java deleted file mode 100644 index 4e856cb2a877..000000000000 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/TransactionGeneratorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.demo.iss; - -import static com.swirlds.common.utility.ByteUtils.intToByteArray; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.hedera.hapi.node.state.roster.Roster; -import com.hedera.hapi.node.state.roster.RosterEntry; -import com.hedera.pbj.runtime.io.buffer.Bytes; -import com.swirlds.platform.system.Platform; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import org.junit.jupiter.api.Test; - -class TransactionGeneratorTest { - - @Test - void startTransactionGenerator() { - // Given - final var random = new Random(); - final var platform = mock(Platform.class); - final var roster = new Roster(List.of(new RosterEntry(1, 5, Bytes.EMPTY, new ArrayList<>()))); - final var networkWideTransactionsPerSecond = 100; - final var issTestingToolState = mock(ISSTestingToolState.class); - - // When - when(platform.getRoster()).thenReturn(roster); - when(issTestingToolState.encodeSystemTransaction(any())) - .thenReturn(Bytes.wrap(intToByteArray(random.nextInt()))); - - final var transactionGenerator = - new TransactionGenerator(random, platform, networkWideTransactionsPerSecond, issTestingToolState); - transactionGenerator.start(); - - // Then - verify(platform, atLeastOnce()).getRoster(); - } -} diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index 588a58b8e530..bb942d52dc18 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -16,6 +16,8 @@ package com.swirlds.platform.system; +import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.platform.NodeId; import com.swirlds.platform.state.MerkleRoot; import edu.umd.cs.findbugs.annotations.NonNull; @@ -91,4 +93,14 @@ default List> getConfigDataTypes() { */ @NonNull SoftwareVersion getSoftwareVersion(); + + /** + * Encodes a system transaction to {@link Bytes} representation of a {@link com.hedera.hapi.node.base.Transaction}. + * + * @param transaction the {@link StateSignatureTransaction} to encode + * @return {@link Bytes} representation of the transaction + */ + default Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + return Bytes.EMPTY; + } } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java index 83db68278d8c..a6d0368bea77 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java @@ -17,7 +17,6 @@ package com.swirlds.platform.system; import com.hedera.hapi.platform.event.StateSignatureTransaction; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.context.PlatformContext; import com.swirlds.common.merkle.MerkleNode; import com.swirlds.platform.components.transaction.system.ScopedSystemTransaction; @@ -126,8 +125,4 @@ default AddressBook updateWeight( */ @Override SwirldState copy(); - - default Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { - return Bytes.EMPTY; - } } From 8800ecd665f8e1ea683ed8d77e701223d94bda33 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 17 Dec 2024 23:22:47 +0200 Subject: [PATCH 20/39] nit: remove redundant changes Signed-off-by: Ivan Kavaldzhiev --- .../src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java | 1 - .../src/main/java/com/swirlds/demo/iss/TransactionGenerator.java | 1 + .../java/com/swirlds/platform/system/events/EventMetadata.java | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) 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 6ebe8608e752..52fba53af767 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 @@ -104,7 +104,6 @@ public void run() { final ISSTestingToolConfig testingToolConfig = platform.getContext().getConfiguration().getConfigData(ISSTestingToolConfig.class); - final var state = platform.getLatestImmutableState("ISSTestingToolMain.run()"); new TransactionGenerator(new Random(), platform, testingToolConfig.transactionsPerSecond()).start(); } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java index 96ab684dd478..6c4c7ce94b10 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/TransactionGenerator.java @@ -32,6 +32,7 @@ public class TransactionGenerator implements Startable { private final Random random; private final Platform platform; + private final StoppableThread thread; public TransactionGenerator( diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java index 8e04086a3524..2579d3cc906e 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/events/EventMetadata.java @@ -64,7 +64,6 @@ public class EventMetadata extends AbstractHashable { * list of transactions */ private final List transactions; - /** * The event descriptor for this event. Is not itself hashed. */ From e1e8fd3b3a27ba54f50144f3c023f6183ac6760a Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 18 Dec 2024 23:36:51 +0200 Subject: [PATCH 21/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolMain.java | 17 +------- .../swirlds/demo/iss/ISSTestingToolState.java | 41 ++----------------- .../demo/iss/ISSTestingToolStateTest.java | 17 +------- .../swirlds/platform/system/SwirldMain.java | 17 +------- .../system/transaction/Transaction.java | 17 +------- .../transaction/TransactionWrapper.java | 17 +------- 6 files changed, 8 insertions(+), 118 deletions(-) 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 52fba53af767..6c7b89c1dc55 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 @@ -1,19 +1,4 @@ -/* - * Copyright (C) 2022-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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.demo.iss; import static com.swirlds.logging.legacy.LogMarker.STARTUP; 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 1f7584de8835..b63e6c067311 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 @@ -1,19 +1,4 @@ -/* - * Copyright (C) 2022-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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.demo.iss; /* * This file is public domain. @@ -36,8 +21,6 @@ import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; import com.hedera.hapi.platform.event.StateSignatureTransaction; -import com.hedera.pbj.runtime.ParseException; -import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; @@ -318,29 +301,11 @@ private ConsensusTransaction handleTransaction(final ConsensusTransaction transa } private boolean isSystemTransaction(final ConsensusTransaction transaction) { - if (transaction.isSystem()) { + if (transaction.isSystem() || transaction.getApplicationTransaction().length() > 4) { return true; - } - - try { - final var transactionBytes = transaction.getApplicationTransaction(); - - if (Bytes.EMPTY.equals(transaction.getApplicationTransaction())) { - return false; - } - - final var parsedTransaction = - StateSignatureTransaction.PROTOBUF.parseStrict(transactionBytes.toReadableSequentialData()); - - if (parsedTransaction.signature() != Bytes.EMPTY) { - return true; - } - } catch (ParseException e) { - logger.error("Failed to parse transaction body", e); + } else { return false; } - - return false; } /** diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index ad696ce4a7ac..53b6cb93f7a0 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -1,19 +1,4 @@ -/* - * 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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.demo.iss; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index bb942d52dc18..c496384813f5 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -1,19 +1,4 @@ -/* - * 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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.platform.system; import com.hedera.hapi.platform.event.StateSignatureTransaction; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index a730091f8820..e2b1bfd5c930 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -1,19 +1,4 @@ -/* - * 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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.platform.system.transaction; import com.hedera.hapi.platform.event.EventTransaction; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 2cec604cec29..27f255500218 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -1,19 +1,4 @@ -/* - * 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. - */ - +// SPDX-License-Identifier: Apache-2.0 package com.swirlds.platform.system.transaction; import com.hedera.hapi.platform.event.EventTransaction; From 7765b26a0e7925c6cf74b39461f8477d077cc210 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 18 Dec 2024 23:46:22 +0200 Subject: [PATCH 22/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 b63e6c067311..234851138042 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 @@ -240,10 +240,10 @@ public void handleConsensusRound( final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { - final var systemTransaction = handleTransaction(transaction); - if (systemTransaction != null) { + final var transactionWithSystemBytes = handleTransaction(transaction); + if (transactionWithSystemBytes != null) { scopedSystemTransactions.add( - new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes)); } }); if (!eventIterator.hasNext()) { @@ -286,9 +286,14 @@ private void captureTimestamp(final ConsensusEvent event) { * Apply a transaction to the state. * * @param transaction the transaction to apply + * @return {@link ConsensusTransaction} only if it represents system transaction wrapped in Bytes */ private ConsensusTransaction handleTransaction(final ConsensusTransaction transaction) { - if (isSystemTransaction(transaction)) { + if (transaction.isSystem()) { + return null; + } + + if (areTransactionBytesSystemOnes(transaction)) { return transaction; } @@ -300,8 +305,8 @@ private ConsensusTransaction handleTransaction(final ConsensusTransaction transa return null; } - private boolean isSystemTransaction(final ConsensusTransaction transaction) { - if (transaction.isSystem() || transaction.getApplicationTransaction().length() > 4) { + private boolean areTransactionBytesSystemOnes(final ConsensusTransaction transaction) { + if (transaction.getApplicationTransaction().length() > 4) { return true; } else { return false; From b02fd948b1068861885f7639465edf0c620dc595 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 18 Dec 2024 23:55:22 +0200 Subject: [PATCH 23/39] style: spotless apply Signed-off-by: Ivan Kavaldzhiev --- .../main/java/com/swirlds/demo/iss/ISSTestingToolState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 234851138042..11e62bf8fd4d 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 @@ -242,8 +242,8 @@ public void handleConsensusRound( event.consensusTransactionIterator().forEachRemaining(transaction -> { final var transactionWithSystemBytes = handleTransaction(transaction); if (transactionWithSystemBytes != null) { - scopedSystemTransactions.add( - new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes)); + scopedSystemTransactions.add(new ScopedSystemTransaction( + event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes)); } }); if (!eventIterator.hasNext()) { From 71ea11ca5956386bfb0c7db0be03c26e038fb610 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 19 Dec 2024 00:23:11 +0200 Subject: [PATCH 24/39] fix: unit test Signed-off-by: Ivan Kavaldzhiev --- .../test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 53b6cb93f7a0..f9958d4c6ab4 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -152,7 +152,7 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); - assertThat(consumerSize).isEqualTo(1); + assertThat(consumerSize).isEqualTo(0); } @Test From ed7bc8921c8dd4099738088b76d4f7eedc200d37 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 19 Dec 2024 13:10:28 +0200 Subject: [PATCH 25/39] style: restore headers Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolMain.java | 17 ++++++++++++++++- .../swirlds/demo/iss/ISSTestingToolState.java | 17 ++++++++++++++++- .../demo/iss/ISSTestingToolStateTest.java | 17 ++++++++++++++++- .../com/swirlds/platform/system/SwirldMain.java | 17 ++++++++++++++++- .../system/transaction/Transaction.java | 17 ++++++++++++++++- .../system/transaction/TransactionWrapper.java | 17 ++++++++++++++++- 6 files changed, 96 insertions(+), 6 deletions(-) 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 6c7b89c1dc55..fa21100f5833 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 @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.demo.iss; import static com.swirlds.logging.legacy.LogMarker.STARTUP; 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 11e62bf8fd4d..02bcc5957248 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 @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.demo.iss; /* * This file is public domain. diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index f9958d4c6ab4..c4e517049b29 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.demo.iss; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index c496384813f5..5b122b90187a 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.system; import com.hedera.hapi.platform.event.StateSignatureTransaction; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index e2b1bfd5c930..c8b9784044eb 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.system.transaction; import com.hedera.hapi.platform.event.EventTransaction; diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 27f255500218..070c5857e467 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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.system.transaction; import com.hedera.hapi.platform.event.EventTransaction; From 62f339aaad1db3fea0d06d5e41f1d040b8c0685d Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 19 Dec 2024 13:27:27 +0200 Subject: [PATCH 26/39] style: spotless apply Signed-off-by: Ivan Kavaldzhiev --- .../tests/ISSTestingTool/build.gradle.kts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts index fdee767aa512..4fe5810b41a8 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts @@ -1,4 +1,19 @@ -// SPDX-License-Identifier: Apache-2.0 +/* + * 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. + */ + plugins { id("org.hiero.gradle.module.application") } application.mainClass = "com.swirlds.demo.iss.ISSTestingToolMain" From aebaae82848f2bbba25e1c57f044a2901445f339 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 19 Dec 2024 18:03:21 +0200 Subject: [PATCH 27/39] feat: add callback handling in preHandle Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 16 +++++ .../demo/iss/ISSTestingToolStateTest.java | 70 +++++++++++++++++++ 2 files changed, 86 insertions(+) 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 02bcc5957248..f3f662438054 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 @@ -53,6 +53,7 @@ import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; 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.test.fixtures.state.FakeMerkleStateLifecycles; import com.swirlds.state.merkle.singleton.StringLeaf; @@ -237,6 +238,21 @@ void writeObjectByChildIndex(int index, List lis } } + @Override + public void preHandle( + @NonNull Event event, + @NonNull Consumer>> stateSignatureTransactions) { + final var scopedSystemTransactions = new ArrayList>(); + ((ConsensusEvent) event).consensusTransactionIterator().forEachRemaining(transaction -> { + if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { + scopedSystemTransactions.add( + new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + } + }); + + stateSignatureTransactions.accept(scopedSystemTransactions); + } + /** * {@inheritDoc} */ diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index c4e517049b29..1acb20177f1d 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -220,6 +220,76 @@ void handleConsensusRoundWithNullTransaction() { assertThat(consumerSize).isZero(); } + @Test + void preHandleEventWithMultipleSystemTransaction() { + // Given + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + final var secondConsensusTransaction = mock(TransactionWrapper.class); + final var thirdConsensusTransaction = mock(TransactionWrapper.class); + when(event.consensusTransactionIterator()) + .thenReturn(List.of(consensusTransaction, secondConsensusTransaction, thirdConsensusTransaction) + .iterator()); + final var stateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); + when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(secondConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(thirdConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + + // When + state.preHandle(event, consumer); + + // Then + assertThat(consumerSize).isEqualTo(3); + } + + @Test + void preHandleEventWithSystemTransaction() { + // Given + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(event.consensusTransactionIterator()) + .thenReturn(Collections.singletonList(consensusTransaction).iterator()); + final var emptyStateSignatureBytes = StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); + when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureBytes); + + // When + state.preHandle(event, consumer); + + // Then + assertThat(consumerSize).isEqualTo(1); + } + + @Test + void preHandleEventWithDeprecatedSystemTransaction() { + // Given + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(event.consensusTransactionIterator()) + .thenReturn(Collections.singletonList(consensusTransaction).iterator()); + when(consensusTransaction.isSystem()).thenReturn(true); + + // When + state.preHandle(event, consumer); + + // Then + assertThat(consumerSize).isZero(); + } + + @Test + void preHandleEventWithEmptyTransaction() { + // Given + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(event.consensusTransactionIterator()) + .thenReturn(Collections.singletonList(consensusTransaction).iterator()); + final var emptyStateSignatureBytes = + StateSignatureTransaction.PROTOBUF.toBytes(StateSignatureTransaction.DEFAULT); + when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureBytes); + + // When + state.preHandle(event, consumer); + + // Then + assertThat(consumerSize).isZero(); + } + private void givenRoundAndEvent() { when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); when(event.getConsensusTimestamp()).thenReturn(Instant.now()); From 63edb17e571887330c0289b1dd915d970e626cc9 Mon Sep 17 00:00:00 2001 From: Mustafa Uzun Date: Thu, 19 Dec 2024 20:52:37 +0200 Subject: [PATCH 28/39] refactor: consumer for system transactions Signed-off-by: Mustafa Uzun --- .../com/swirlds/demo/crypto/CryptocurrencyDemoState.java | 4 +--- .../com/swirlds/demo/hello/HelloSwirldDemoState.java | 4 +--- .../main/java/com/swirlds/demo/stats/StatsDemoState.java | 5 +---- .../demo/addressbook/AddressBookTestingToolState.java | 5 +---- .../demo/consistency/ConsistencyTestingToolState.java | 9 ++------- .../java/com/swirlds/demo/iss/ISSTestingToolState.java | 4 +--- .../demo/migration/MigrationTestingToolState.java | 4 +--- .../swirlds/demo/platform/PlatformTestingToolState.java | 8 ++------ .../demo/stats/signing/StatsSigningTestingToolState.java | 8 ++------ .../com/swirlds/demo/stress/StressTestingToolState.java | 9 ++------- .../eventhandling/DefaultTransactionPrehandler.java | 2 +- .../swirlds/platform/state/PlatformMerkleStateRoot.java | 9 ++------- .../com/swirlds/platform/state/SwirldStateManager.java | 2 +- .../java/com/swirlds/platform/system/SwirldState.java | 5 ++--- .../platform/turtle/runner/TurtleTestingToolState.java | 5 +---- .../test/fixtures/state/BlockingSwirldState.java | 5 +---- 16 files changed, 22 insertions(+), 66 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 624f1bc15dcf..417e42ef1bc8 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 @@ -211,9 +211,7 @@ public synchronized CryptocurrencyDemoState copy() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); round.forEachEventTransaction((event, transaction) -> handleTransaction(event.getCreatorId(), transaction)); } 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 c7d66c8090df..091f995c2cba 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 @@ -111,9 +111,7 @@ private HelloSwirldDemoState(final HelloSwirldDemoState sourceState) { public synchronized void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } 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 64d9e5a976f5..95edc58169bd 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 @@ -36,7 +36,6 @@ import com.swirlds.platform.system.Round; import com.swirlds.platform.system.SoftwareVersion; import edu.umd.cs.findbugs.annotations.NonNull; -import java.util.List; import java.util.function.Consumer; import java.util.function.Function; @@ -83,9 +82,7 @@ private StatsDemoState(final StatsDemoState sourceState) { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) {} + @NonNull final Consumer> stateSignatureTransactions) {} /** * {@inheritDoc} 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 76f36aafdae0..fe1c74e122e0 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 @@ -71,7 +71,6 @@ import java.text.ParseException; import java.time.Duration; import java.util.Iterator; -import java.util.List; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -222,9 +221,7 @@ public void init( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { Objects.requireNonNull(round, "the round cannot be null"); Objects.requireNonNull(platformState, "the platform state cannot be null"); throwIfImmutable(); 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 c0313c161976..4dba460083f5 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 @@ -44,7 +44,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; -import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -246,9 +245,7 @@ private void applyTransactionToState(final @NonNull ConsensusTransaction transac @Override public void preHandle( @NonNull final Event event, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { event.forEachTransaction(transaction -> { if (transaction.isSystem()) { return; @@ -272,9 +269,7 @@ public void preHandle( public void handleConsensusRound( final @NonNull Round round, final @NonNull PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { Objects.requireNonNull(round); Objects.requireNonNull(platformState); 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 f78d3e6eebc4..746aee8c9353 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 @@ -243,9 +243,7 @@ void writeObjectByChildIndex(int index, List lis public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); final Iterator eventIterator = round.iterator(); 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 504679ccff2e..c58c83cf8a72 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 @@ -285,9 +285,7 @@ public void init( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); for (final Iterator eventIt = round.iterator(); eventIt.hasNext(); ) { final ConsensusEvent event = eventIt.next(); 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 48a2b0ea9694..427cc93c6a41 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 @@ -1056,9 +1056,7 @@ protected void preHandleTransaction(final Transaction transaction) { public synchronized void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); if (!initialized.get()) { throw new IllegalStateException("handleConsensusRound() called before init()"); @@ -1662,9 +1660,7 @@ private static class ChildIndices { @Override public void preHandle( @NonNull final Event event, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { event.forEachTransaction(this::preHandleTransaction); } } 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 dabd0b8fff3c..429c4926fde6 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 @@ -115,9 +115,7 @@ public synchronized StatsSigningTestingToolState copy() { @Override public void preHandle( @NonNull final Event event, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { final SttTransactionPool sttTransactionPool = transactionPoolSupplier.get(); if (sttTransactionPool != null) { event.forEachTransaction(transaction -> { @@ -141,9 +139,7 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } 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 3225ecffe8f3..769543cf6beb 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 @@ -43,7 +43,6 @@ import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.time.Duration; -import java.util.List; import java.util.function.Consumer; import java.util.function.Function; @@ -103,9 +102,7 @@ public void init( @Override public void preHandle( @NonNull final Event event, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { busyWait(config.preHandleTime()); } @@ -116,9 +113,7 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/eventhandling/DefaultTransactionPrehandler.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/eventhandling/DefaultTransactionPrehandler.java index 6ddb39c0aade..884991c5eb80 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/eventhandling/DefaultTransactionPrehandler.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/eventhandling/DefaultTransactionPrehandler.java @@ -42,7 +42,7 @@ public class DefaultTransactionPrehandler implements TransactionPrehandler { private static final Logger logger = LogManager.getLogger(DefaultTransactionPrehandler.class); - public static final Consumer>> NO_OP_CONSUMER = + public static final Consumer> NO_OP_CONSUMER = systemTransactions -> {}; /** diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java index b6c9b1c7fc37..ae21d3ce8d66 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java @@ -48,7 +48,6 @@ import com.swirlds.state.spi.WritableStates; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.util.List; import java.util.function.Consumer; import java.util.function.Function; @@ -153,9 +152,7 @@ protected PlatformMerkleStateRoot copyingConstructor() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { throwIfImmutable(); lifecycles.onHandleConsensusRound(round, this); } @@ -173,9 +170,7 @@ public void sealConsensusRound(@NonNull final Round round) { @Override public void preHandle( @NonNull final Event event, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { lifecycles.onPreHandle(event, this); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/SwirldStateManager.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/SwirldStateManager.java index ce99739dc690..06a9d89e1456 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/SwirldStateManager.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/SwirldStateManager.java @@ -123,7 +123,7 @@ public void setInitialState(@NonNull final MerkleRoot state) { /** * Handles the events in a consensus round. Implementations are responsible for invoking - * {@link SwirldState#handleConsensusRound(Round, PlatformStateModifier, Consumer>>)}. + * {@link SwirldState#handleConsensusRound(Round, PlatformStateModifier, Consumer>)}. * * @param round the round to handle */ diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java index a6d0368bea77..7c09a13ecea8 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java @@ -26,7 +26,6 @@ import com.swirlds.platform.system.transaction.Transaction; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; -import java.util.List; import java.util.Objects; import java.util.function.Consumer; @@ -77,7 +76,7 @@ default void init( */ default void preHandle( final Event event, - final Consumer>> stateSignatureTransactions) {} + final Consumer> stateSignatureTransactions) {} /** * This method should apply the transactions in the provided round to the state. Only called on mutable states. @@ -90,7 +89,7 @@ default void preHandle( void handleConsensusRound( final Round round, final PlatformStateModifier platformState, - final Consumer>> stateSignatureTransactions); + final Consumer> stateSignatureTransactions); /** * Called by the platform after it has made all its changes to this state for the given round. 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 e1d23cd50e89..4e59efa87143 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 @@ -25,7 +25,6 @@ import com.swirlds.platform.system.BasicSoftwareVersion; import com.swirlds.platform.system.Round; import edu.umd.cs.findbugs.annotations.NonNull; -import java.util.List; import java.util.function.Consumer; /** @@ -84,9 +83,7 @@ public int getVersion() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { state = NonCryptographicHashing.hash64( state, round.getRoundNum(), diff --git a/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java b/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java index e5537a738c89..2ee22c376ec7 100644 --- a/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java @@ -36,7 +36,6 @@ import com.swirlds.state.merkle.singleton.StringLeaf; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.IOException; -import java.util.List; import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; @@ -86,9 +85,7 @@ private BlockingSwirldState(final BlockingSwirldState that) { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull - final Consumer>> - stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransactions) { // intentionally does nothing } From 18a588a361c063613d3e30fbb19e0f4fc0f45feb Mon Sep 17 00:00:00 2001 From: Mustafa Uzun Date: Fri, 20 Dec 2024 14:04:25 +0200 Subject: [PATCH 29/39] refactor: rename consumer to stateSignatureTransaction Signed-off-by: Mustafa Uzun --- .../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 | 4 ++-- .../java/com/swirlds/demo/iss/ISSTestingToolState.java | 2 +- .../swirlds/demo/migration/MigrationTestingToolState.java | 2 +- .../swirlds/demo/platform/PlatformTestingToolState.java | 4 ++-- .../demo/stats/signing/StatsSigningTestingToolState.java | 4 ++-- .../com/swirlds/demo/stress/StressTestingToolState.java | 4 ++-- .../swirlds/platform/state/PlatformMerkleStateRoot.java | 4 ++-- .../java/com/swirlds/platform/system/SwirldState.java | 8 ++++---- .../platform/turtle/runner/TurtleTestingToolState.java | 2 +- .../platform/test/fixtures/state/BlockingSwirldState.java | 2 +- 14 files changed, 22 insertions(+), 22 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 417e42ef1bc8..67bf3acd5581 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 @@ -211,7 +211,7 @@ public synchronized CryptocurrencyDemoState copy() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); round.forEachEventTransaction((event, transaction) -> handleTransaction(event.getCreatorId(), transaction)); } 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 091f995c2cba..70d659567fb0 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 @@ -111,7 +111,7 @@ private HelloSwirldDemoState(final HelloSwirldDemoState sourceState) { public synchronized void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } 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 95edc58169bd..10d59a52847b 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 @@ -82,7 +82,7 @@ private StatsDemoState(final StatsDemoState sourceState) { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) {} + @NonNull final Consumer> stateSignatureTransaction) {} /** * {@inheritDoc} 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 fe1c74e122e0..6614c1624baa 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 @@ -221,7 +221,7 @@ public void init( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { Objects.requireNonNull(round, "the round cannot be null"); Objects.requireNonNull(platformState, "the platform state cannot be null"); throwIfImmutable(); 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 4dba460083f5..5e25d3b0eacb 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 @@ -245,7 +245,7 @@ private void applyTransactionToState(final @NonNull ConsensusTransaction transac @Override public void preHandle( @NonNull final Event event, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { event.forEachTransaction(transaction -> { if (transaction.isSystem()) { return; @@ -269,7 +269,7 @@ public void preHandle( public void handleConsensusRound( final @NonNull Round round, final @NonNull PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { Objects.requireNonNull(round); Objects.requireNonNull(platformState); 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 746aee8c9353..78d7515250be 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 @@ -243,7 +243,7 @@ void writeObjectByChildIndex(int index, List lis public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); final Iterator eventIterator = round.iterator(); 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 c58c83cf8a72..7ec5c81b4690 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 @@ -285,7 +285,7 @@ public void init( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); for (final Iterator eventIt = round.iterator(); eventIt.hasNext(); ) { final ConsensusEvent event = eventIt.next(); 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 427cc93c6a41..518d1445a862 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 @@ -1056,7 +1056,7 @@ protected void preHandleTransaction(final Transaction transaction) { public synchronized void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); if (!initialized.get()) { throw new IllegalStateException("handleConsensusRound() called before init()"); @@ -1660,7 +1660,7 @@ private static class ChildIndices { @Override public void preHandle( @NonNull final Event event, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { event.forEachTransaction(this::preHandleTransaction); } } 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 429c4926fde6..5a2d95eb0f19 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 @@ -115,7 +115,7 @@ public synchronized StatsSigningTestingToolState copy() { @Override public void preHandle( @NonNull final Event event, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { final SttTransactionPool sttTransactionPool = transactionPoolSupplier.get(); if (sttTransactionPool != null) { event.forEachTransaction(transaction -> { @@ -139,7 +139,7 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } 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 769543cf6beb..347b5dfb0cff 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 @@ -102,7 +102,7 @@ public void init( @Override public void preHandle( @NonNull final Event event, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { busyWait(config.preHandleTime()); } @@ -113,7 +113,7 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); round.forEachTransaction(this::handleTransaction); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java index ae21d3ce8d66..7fff84b01b46 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/state/PlatformMerkleStateRoot.java @@ -152,7 +152,7 @@ protected PlatformMerkleStateRoot copyingConstructor() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { throwIfImmutable(); lifecycles.onHandleConsensusRound(round, this); } @@ -170,7 +170,7 @@ public void sealConsensusRound(@NonNull final Round round) { @Override public void preHandle( @NonNull final Event event, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { lifecycles.onPreHandle(event, this); } diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java index 7c09a13ecea8..c49f3047d4d1 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldState.java @@ -71,25 +71,25 @@ default void init( * This method is always invoked on an immutable state. * * @param event the event to perform pre-handling on - * @param stateSignatureTransactions a consumer that accepts a list of {@link ScopedSystemTransaction}s that + * @param stateSignatureTransaction a consumer that accepts a list of {@link ScopedSystemTransaction}s that * will be used for callbacks */ default void preHandle( final Event event, - final Consumer> stateSignatureTransactions) {} + final Consumer> stateSignatureTransaction) {} /** * This method should apply the transactions in the provided round to the state. Only called on mutable states. * * @param round the round to apply * @param platformState the platform state - * @param stateSignatureTransactions a consumer that accepts a list of {@link ScopedSystemTransaction}s that + * @param stateSignatureTransaction a consumer that accepts a list of {@link ScopedSystemTransaction}s that * will be used for callbacks */ void handleConsensusRound( final Round round, final PlatformStateModifier platformState, - final Consumer> stateSignatureTransactions); + final Consumer> stateSignatureTransaction); /** * Called by the platform after it has made all its changes to this state for the given round. 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 4e59efa87143..f4547d45a1cd 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 @@ -83,7 +83,7 @@ public int getVersion() { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { state = NonCryptographicHashing.hash64( state, round.getRoundNum(), diff --git a/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java b/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java index 2ee22c376ec7..29b3ade2f864 100644 --- a/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java +++ b/platform-sdk/swirlds-platform-core/src/testFixtures/java/com/swirlds/platform/test/fixtures/state/BlockingSwirldState.java @@ -85,7 +85,7 @@ private BlockingSwirldState(final BlockingSwirldState that) { public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactions) { + @NonNull final Consumer> stateSignatureTransaction) { // intentionally does nothing } From bd2ba4f75f728716c20f5fa6d71ec604e7b375f1 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Fri, 20 Dec 2024 14:34:28 +0200 Subject: [PATCH 30/39] nit: adapt consumer changes Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 13 ++------- .../demo/iss/ISSTestingToolStateTest.java | 28 ++++++++++--------- 2 files changed, 18 insertions(+), 23 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 f1df71e52b7a..dd3f3027627f 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 @@ -65,7 +65,6 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -241,16 +240,13 @@ void writeObjectByChildIndex(int index, List lis @Override public void preHandle( @NonNull Event event, - @NonNull Consumer>> stateSignatureTransactions) { - final var scopedSystemTransactions = new ArrayList>(); + @NonNull Consumer> stateSignatureTransaction) { ((ConsensusEvent) event).consensusTransactionIterator().forEachRemaining(transaction -> { if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { - scopedSystemTransactions.add( + stateSignatureTransaction.accept( new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); } }); - - stateSignatureTransactions.accept(scopedSystemTransactions); } /** @@ -264,14 +260,13 @@ public void handleConsensusRound( throwIfImmutable(); final Iterator eventIterator = round.iterator(); - final var scopedSystemTransactions = new ArrayList>(); while (eventIterator.hasNext()) { final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { final var transactionWithSystemBytes = handleTransaction(transaction); if (transactionWithSystemBytes != null) { - scopedSystemTransactions.add(new ScopedSystemTransaction( + stateSignatureTransaction.accept(new ScopedSystemTransaction( event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes)); } }); @@ -297,8 +292,6 @@ public void handleConsensusRound( } } } - - stateSignatureTransactions.accept(scopedSystemTransactions); } /** diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 1acb20177f1d..578db1bf2f4d 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -33,6 +33,7 @@ import com.swirlds.platform.system.transaction.TransactionWrapper; import com.swirlds.state.merkle.singleton.StringLeaf; import java.time.Instant; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; @@ -50,8 +51,8 @@ class ISSTestingToolStateTest { private PlatformStateModifier platformStateModifier; private Round round; private ConsensusEvent event; - private Consumer>> consumer; - private int consumerSize; + private List> consumedTransactions; + private Consumer> consumer; private ConsensusTransaction consensusTransaction; private StateSignatureTransaction stateSignatureTransaction; @@ -64,7 +65,8 @@ void setUp() { round = mock(Round.class); event = mock(ConsensusEvent.class); - consumer = systemTransactions -> consumerSize = systemTransactions.size(); + consumedTransactions = new ArrayList<>(); + consumer = systemTransaction -> consumedTransactions.add(systemTransaction); consensusTransaction = mock(TransactionWrapper.class); final byte[] signature = new byte[384]; @@ -96,7 +98,7 @@ void handleConsensusRoundWithApplicationTransaction() { assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) .isPositive(); - assertThat(consumerSize).isZero(); + assertThat(consumedTransactions).isEmpty(); } @Test @@ -118,7 +120,7 @@ void handleConsensusRoundWithSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); - assertThat(consumerSize).isEqualTo(1); + assertThat(consumedTransactions).hasSize(1); } @Test @@ -148,7 +150,7 @@ void handleConsensusRoundWithMultipleSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); - assertThat(consumerSize).isEqualTo(3); + assertThat(consumedTransactions).hasSize(3); } @Test @@ -167,7 +169,7 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() { verify(event, times(1)).consensusTransactionIterator(); assertThat((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).isNull(); - assertThat(consumerSize).isEqualTo(0); + assertThat(consumedTransactions).isEmpty(); } @Test @@ -192,7 +194,7 @@ void handleConsensusRoundWithEmptyTransaction() { assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) .isZero(); - assertThat(consumerSize).isZero(); + assertThat(consumedTransactions).isEmpty(); } @Test @@ -217,7 +219,7 @@ void handleConsensusRoundWithNullTransaction() { assertThat(Long.parseLong(((StringLeaf) state.getChild(RUNNING_SUM_INDEX)).getLabel())) .isZero(); - assertThat(consumerSize).isZero(); + assertThat(consumedTransactions).isEmpty(); } @Test @@ -239,7 +241,7 @@ void preHandleEventWithMultipleSystemTransaction() { state.preHandle(event, consumer); // Then - assertThat(consumerSize).isEqualTo(3); + assertThat(consumedTransactions).hasSize(3); } @Test @@ -255,7 +257,7 @@ void preHandleEventWithSystemTransaction() { state.preHandle(event, consumer); // Then - assertThat(consumerSize).isEqualTo(1); + assertThat(consumedTransactions).hasSize(1); } @Test @@ -270,7 +272,7 @@ void preHandleEventWithDeprecatedSystemTransaction() { state.preHandle(event, consumer); // Then - assertThat(consumerSize).isZero(); + assertThat(consumedTransactions).isEmpty(); } @Test @@ -287,7 +289,7 @@ void preHandleEventWithEmptyTransaction() { state.preHandle(event, consumer); // Then - assertThat(consumerSize).isZero(); + assertThat(consumedTransactions).isEmpty(); } private void givenRoundAndEvent() { From f5217e2428e39242d665be8f4504c9864007d958 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Fri, 20 Dec 2024 14:38:34 +0200 Subject: [PATCH 31/39] nit: resolve PR comment Signed-off-by: Ivan Kavaldzhiev --- .../com/swirlds/demo/iss/ISSTestingToolState.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 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 dd3f3027627f..15a55a26cf00 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 @@ -327,12 +327,14 @@ private ConsensusTransaction handleTransaction(final ConsensusTransaction transa return null; } + /** + * Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4. System transactions will be always bigger than that. + * + * @param transaction the consensus transaction to check + * @return true if the transaction bytes are system ones, false otherwise + */ private boolean areTransactionBytesSystemOnes(final ConsensusTransaction transaction) { - if (transaction.getApplicationTransaction().length() > 4) { - return true; - } else { - return false; - } + return transaction.getApplicationTransaction().length() > 4; } /** From 70cc9874e3e2fce1efbd8fb98ded5c6859892544 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Fri, 20 Dec 2024 16:34:07 +0200 Subject: [PATCH 32/39] nit: resolve PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 23 ++++++++----------- .../demo/iss/ISSTestingToolStateTest.java | 1 + 2 files changed, 10 insertions(+), 14 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 15a55a26cf00..a5c2da29d1a9 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 @@ -264,10 +264,11 @@ public void handleConsensusRound( final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { - final var transactionWithSystemBytes = handleTransaction(transaction); - if (transactionWithSystemBytes != null) { - stateSignatureTransaction.accept(new ScopedSystemTransaction( - event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes)); + if (areTransactionBytesSystemOnes(transaction)) { + stateSignatureTransaction.accept( + new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + } else { + handleTransaction(transaction); } }); if (!eventIterator.hasNext()) { @@ -308,27 +309,21 @@ private void captureTimestamp(final ConsensusEvent event) { * Apply a transaction to the state. * * @param transaction the transaction to apply - * @return {@link ConsensusTransaction} only if it represents system transaction wrapped in Bytes */ - private ConsensusTransaction handleTransaction(final ConsensusTransaction transaction) { + private void handleTransaction(final ConsensusTransaction transaction) { if (transaction.isSystem()) { - return null; - } - - if (areTransactionBytesSystemOnes(transaction)) { - return transaction; + return; } final int delta = ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0); runningSum += delta; setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum))); - - return null; } /** - * Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4. System transactions will be always bigger than that. + * Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4. + * System transactions will be always bigger than that. * * @param transaction the consensus transaction to check * @return true if the transaction bytes are system ones, false otherwise diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index 578db1bf2f4d..e1f98ffd2407 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -158,6 +158,7 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() { // Given givenRoundAndEvent(); + when(consensusTransaction.getApplicationTransaction()).thenReturn(Bytes.EMPTY); when(consensusTransaction.isSystem()).thenReturn(true); // When From dd71830ed98185400404bb1519f14c0266e866ee Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Mon, 23 Dec 2024 16:15:09 +0200 Subject: [PATCH 33/39] nit: resolve PR comment Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 5 +- .../demo/iss/ISSTestingToolStateTest.java | 129 +++++++++++++----- 2 files changed, 100 insertions(+), 34 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 a5c2da29d1a9..c464eeb456f2 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 @@ -55,6 +55,7 @@ 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.test.fixtures.state.FakeMerkleStateLifecycles; import com.swirlds.state.merkle.singleton.StringLeaf; import edu.umd.cs.findbugs.annotations.NonNull; @@ -241,7 +242,7 @@ void writeObjectByChildIndex(int index, List lis public void preHandle( @NonNull Event event, @NonNull Consumer> stateSignatureTransaction) { - ((ConsensusEvent) event).consensusTransactionIterator().forEachRemaining(transaction -> { + event.forEachTransaction(transaction -> { if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { stateSignatureTransaction.accept( new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); @@ -328,7 +329,7 @@ private void handleTransaction(final ConsensusTransaction transaction) { * @param transaction the consensus transaction to check * @return true if the transaction bytes are system ones, false otherwise */ - private boolean areTransactionBytesSystemOnes(final ConsensusTransaction transaction) { + private boolean areTransactionBytesSystemOnes(final Transaction transaction) { return transaction.getApplicationTransaction().length() > 4; } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index e1f98ffd2407..ecd22386403f 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -22,14 +22,22 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.hedera.hapi.node.base.Timestamp; +import com.hedera.hapi.platform.event.EventCore; +import com.hedera.hapi.platform.event.EventTransaction; +import com.hedera.hapi.platform.event.EventTransaction.TransactionOneOfType; +import com.hedera.hapi.platform.event.GossipEvent; import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.OneOf; import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.components.transaction.system.ScopedSystemTransaction; +import com.swirlds.platform.event.PlatformEvent; import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.PlatformStateModifier; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; +import com.swirlds.platform.system.transaction.Transaction; import com.swirlds.platform.system.transaction.TransactionWrapper; import com.swirlds.state.merkle.singleton.StringLeaf; import java.time.Instant; @@ -53,7 +61,7 @@ class ISSTestingToolStateTest { private ConsensusEvent event; private List> consumedTransactions; private Consumer> consumer; - private ConsensusTransaction consensusTransaction; + private Transaction transaction; private StateSignatureTransaction stateSignatureTransaction; @BeforeEach @@ -67,7 +75,7 @@ void setUp() { consumedTransactions = new ArrayList<>(); consumer = systemTransaction -> consumedTransactions.add(systemTransaction); - consensusTransaction = mock(TransactionWrapper.class); + transaction = mock(TransactionWrapper.class); final byte[] signature = new byte[384]; random.nextBytes(signature); @@ -86,7 +94,7 @@ void handleConsensusRoundWithApplicationTransaction() { givenRoundAndEvent(); final var bytes = Bytes.wrap(new byte[] {1, 1, 1, 1}); - when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes); + when(transaction.getApplicationTransaction()).thenReturn(bytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -109,7 +117,7 @@ void handleConsensusRoundWithSystemTransaction() { final var stateSignatureTransactionBytes = StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes); - when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(transaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -131,13 +139,16 @@ void handleConsensusRoundWithMultipleSystemTransaction() { when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); when(event.getConsensusTimestamp()).thenReturn(Instant.now()); when(event.consensusTransactionIterator()) - .thenReturn(List.of(consensusTransaction, secondConsensusTransaction, thirdConsensusTransaction) + .thenReturn(List.of( + (ConsensusTransaction) transaction, + secondConsensusTransaction, + thirdConsensusTransaction) .iterator()); final var stateSignatureTransactionBytes = StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes); - when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + when(transaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); when(secondConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); when(thirdConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); @@ -158,8 +169,8 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() { // Given givenRoundAndEvent(); - when(consensusTransaction.getApplicationTransaction()).thenReturn(Bytes.EMPTY); - when(consensusTransaction.isSystem()).thenReturn(true); + when(transaction.getApplicationTransaction()).thenReturn(Bytes.EMPTY); + when(transaction.isSystem()).thenReturn(true); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -183,7 +194,7 @@ void handleConsensusRoundWithEmptyTransaction() { StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction); when(main.encodeSystemTransaction(emptyStateSignatureTransaction)) .thenReturn(emptyStateSignatureTransactionBytes); - when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); + when(transaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -208,7 +219,7 @@ void handleConsensusRoundWithNullTransaction() { StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction); when(main.encodeSystemTransaction(null)) .thenReturn(StateSignatureTransaction.PROTOBUF.toBytes(emptyStateSignatureTransaction)); - when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); + when(transaction.getApplicationTransaction()).thenReturn(emptyStateSignatureTransactionBytes); // When state.handleConsensusRound(round, platformStateModifier, consumer); @@ -226,17 +237,36 @@ void handleConsensusRoundWithNullTransaction() { @Test void preHandleEventWithMultipleSystemTransaction() { // Given - when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); - final var secondConsensusTransaction = mock(TransactionWrapper.class); - final var thirdConsensusTransaction = mock(TransactionWrapper.class); - when(event.consensusTransactionIterator()) - .thenReturn(List.of(consensusTransaction, secondConsensusTransaction, thirdConsensusTransaction) - .iterator()); + final var gossipEvent = mock(GossipEvent.class); + final var eventCore = mock(EventCore.class); + when(gossipEvent.eventCore()).thenReturn(eventCore); + when(eventCore.timeCreated()).thenReturn(Timestamp.DEFAULT); + when(eventCore.creatorNodeId()).thenReturn(1L); + when(eventCore.parents()).thenReturn(Collections.emptyList()); + final var eventTransaction = mock(EventTransaction.class); + final var secondEventTransaction = mock(EventTransaction.class); + final var thirdEventTransaction = mock(EventTransaction.class); + final var stateSignatureTransactionBytes = StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); - when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); - when(secondConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); - when(thirdConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes); + final var transactionProto = com.hedera.hapi.node.base.Transaction.newBuilder() + .bodyBytes(stateSignatureTransactionBytes) + .build(); + final var transactionBytes = com.hedera.hapi.node.base.Transaction.PROTOBUF.toBytes(transactionProto); + + final var systemTransactionWithType = + new OneOf<>(TransactionOneOfType.APPLICATION_TRANSACTION, transactionBytes); + + when(eventTransaction.transaction()).thenReturn(systemTransactionWithType); + when(secondEventTransaction.transaction()).thenReturn(systemTransactionWithType); + when(thirdEventTransaction.transaction()).thenReturn(systemTransactionWithType); + when(gossipEvent.eventTransaction()) + .thenReturn(List.of(eventTransaction, secondEventTransaction, thirdEventTransaction)); + event = new PlatformEvent(gossipEvent); + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(transaction.getApplicationTransaction()).thenReturn(transactionBytes); + when(secondEventTransaction.applicationTransaction()).thenReturn(transactionBytes); + when(thirdEventTransaction.applicationTransaction()).thenReturn(transactionBytes); // When state.preHandle(event, consumer); @@ -248,11 +278,29 @@ void preHandleEventWithMultipleSystemTransaction() { @Test void preHandleEventWithSystemTransaction() { // Given + final var gossipEvent = mock(GossipEvent.class); + final var eventCore = mock(EventCore.class); + when(eventCore.timeCreated()).thenReturn(Timestamp.DEFAULT); + when(eventCore.creatorNodeId()).thenReturn(1L); + when(eventCore.parents()).thenReturn(Collections.emptyList()); + final var eventTransaction = mock(EventTransaction.class); + when(gossipEvent.eventCore()).thenReturn(eventCore); + when(gossipEvent.eventTransaction()).thenReturn(List.of(eventTransaction)); + + final var stateSignatureTransactionBytes = + StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); + final var transactionProto = com.hedera.hapi.node.base.Transaction.newBuilder() + .bodyBytes(stateSignatureTransactionBytes) + .build(); + final var transactionBytes = com.hedera.hapi.node.base.Transaction.PROTOBUF.toBytes(transactionProto); + final var systemTransactionWithType = + new OneOf<>(TransactionOneOfType.APPLICATION_TRANSACTION, transactionBytes); + when(eventTransaction.transaction()).thenReturn(systemTransactionWithType); + + event = new PlatformEvent(gossipEvent); + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); - when(event.consensusTransactionIterator()) - .thenReturn(Collections.singletonList(consensusTransaction).iterator()); - final var emptyStateSignatureBytes = StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction); - when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureBytes); + when(transaction.getApplicationTransaction()).thenReturn(transactionBytes); // When state.preHandle(event, consumer); @@ -264,10 +312,10 @@ void preHandleEventWithSystemTransaction() { @Test void preHandleEventWithDeprecatedSystemTransaction() { // Given + event = mock(PlatformEvent.class); + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); - when(event.consensusTransactionIterator()) - .thenReturn(Collections.singletonList(consensusTransaction).iterator()); - when(consensusTransaction.isSystem()).thenReturn(true); + when(transaction.isSystem()).thenReturn(true); // When state.preHandle(event, consumer); @@ -279,12 +327,28 @@ void preHandleEventWithDeprecatedSystemTransaction() { @Test void preHandleEventWithEmptyTransaction() { // Given - when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); - when(event.consensusTransactionIterator()) - .thenReturn(Collections.singletonList(consensusTransaction).iterator()); - final var emptyStateSignatureBytes = + final var gossipEvent = mock(GossipEvent.class); + final var eventCore = mock(EventCore.class); + when(eventCore.timeCreated()).thenReturn(Timestamp.DEFAULT); + when(eventCore.creatorNodeId()).thenReturn(1L); + when(eventCore.parents()).thenReturn(Collections.emptyList()); + final var eventTransaction = mock(EventTransaction.class); + when(gossipEvent.eventCore()).thenReturn(eventCore); + when(gossipEvent.eventTransaction()).thenReturn(List.of(eventTransaction)); + + final var stateSignatureTransactionBytes = StateSignatureTransaction.PROTOBUF.toBytes(StateSignatureTransaction.DEFAULT); - when(consensusTransaction.getApplicationTransaction()).thenReturn(emptyStateSignatureBytes); + final var transactionProto = com.hedera.hapi.node.base.Transaction.newBuilder() + .bodyBytes(stateSignatureTransactionBytes) + .build(); + final var transactionBytes = com.hedera.hapi.node.base.Transaction.PROTOBUF.toBytes(transactionProto); + final var systemTransactionWithType = + new OneOf<>(TransactionOneOfType.APPLICATION_TRANSACTION, transactionBytes); + when(eventTransaction.transaction()).thenReturn(systemTransactionWithType); + + event = new PlatformEvent(gossipEvent); + when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); + when(transaction.getApplicationTransaction()).thenReturn(transactionBytes); // When state.preHandle(event, consumer); @@ -297,6 +361,7 @@ private void givenRoundAndEvent() { when(round.iterator()).thenReturn(Collections.singletonList(event).iterator()); when(event.getConsensusTimestamp()).thenReturn(Instant.now()); when(event.consensusTransactionIterator()) - .thenReturn(Collections.singletonList(consensusTransaction).iterator()); + .thenReturn(Collections.singletonList((ConsensusTransaction) transaction) + .iterator()); } } From b745bbb47203ccef76a0c7b1b2b0826399641f9f Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Fri, 3 Jan 2025 12:41:02 +0200 Subject: [PATCH 34/39] style: spotless apply Signed-off-by: Ivan Kavaldzhiev --- .../platform-apps/tests/ISSTestingTool/build.gradle.kts | 2 +- .../src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java | 2 +- .../src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java | 2 +- .../test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java | 2 +- .../src/main/java/com/swirlds/platform/system/SwirldMain.java | 2 +- .../com/swirlds/platform/system/transaction/Transaction.java | 2 +- .../swirlds/platform/system/transaction/TransactionWrapper.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts index 4fe5810b41a8..0abcf6dbe42b 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. 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 fa21100f5833..95b8741dee7a 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. 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 c464eeb456f2..c9877de1f4e0 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index ecd22386403f..fe72fca938dd 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index 34c9313afadd..8b3b11ecd4cb 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java index c8b9784044eb..a45acc3b15ff 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/Transaction.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java index 070c5857e467..549888a0169b 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. From 5219d82a96f5180d9cdafe382aa4be6cb7556e7e Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 7 Jan 2025 15:03:19 +0200 Subject: [PATCH 35/39] fix: consume converted system transaction instead of the transaction itself Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 23 +++++++++++++------ .../demo/iss/ISSTestingToolStateTest.java | 3 +-- 2 files changed, 17 insertions(+), 9 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 c9877de1f4e0..eb123c53dec0 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 @@ -36,6 +36,7 @@ import com.hedera.hapi.node.state.roster.Roster; import com.hedera.hapi.node.state.roster.RosterEntry; import com.hedera.hapi.platform.event.StateSignatureTransaction; +import com.hedera.pbj.runtime.ParseException; import com.swirlds.common.constructable.ConstructableIgnored; import com.swirlds.common.io.SelfSerializable; import com.swirlds.common.io.streams.SerializableDataInputStream; @@ -241,11 +242,10 @@ void writeObjectByChildIndex(int index, List lis @Override public void preHandle( @NonNull Event event, - @NonNull Consumer> stateSignatureTransaction) { + @NonNull Consumer> stateSignatureTransactionCallback) { event.forEachTransaction(transaction -> { if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { - stateSignatureTransaction.accept( - new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + consumeSystemTransaction(transaction, event, stateSignatureTransactionCallback); } }); } @@ -257,7 +257,7 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransaction) { + @NonNull final Consumer> stateSignatureTransactionCallback) { throwIfImmutable(); final Iterator eventIterator = round.iterator(); @@ -265,9 +265,8 @@ public void handleConsensusRound( final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { - if (areTransactionBytesSystemOnes(transaction)) { - stateSignatureTransaction.accept( - new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction)); + if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { + consumeSystemTransaction(transaction, event, stateSignatureTransactionCallback); } else { handleTransaction(transaction); } @@ -333,6 +332,16 @@ private boolean areTransactionBytesSystemOnes(final Transaction transaction) { return transaction.getApplicationTransaction().length() > 4; } + private void consumeSystemTransaction(final Transaction transaction, final Event event, final Consumer> stateSignatureTransactionCallback) { + try { + final var stateSignatureTransaction = StateSignatureTransaction.PROTOBUF.parse(transaction.getApplicationTransaction()); + stateSignatureTransactionCallback.accept( + new ScopedSystemTransaction<>(event.getCreatorId(), event.getSoftwareVersion(), stateSignatureTransaction)); + } catch (ParseException e) { + logger.error("Failed to parse StateSignatureTransaction", e); + } + } + /** * Iterate over a list of planned incidents, and return the first one that should be triggered. If no incident from * the list should be triggered, return null diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index fe72fca938dd..e37521d5a194 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -53,7 +53,6 @@ class ISSTestingToolStateTest { private static final int RUNNING_SUM_INDEX = 3; - private Random random; private ISSTestingToolMain main; private ISSTestingToolState state; private PlatformStateModifier platformStateModifier; @@ -68,7 +67,7 @@ class ISSTestingToolStateTest { void setUp() { state = new ISSTestingToolState(mock(MerkleStateLifecycles.class), mock(Function.class)); main = mock(ISSTestingToolMain.class); - random = new Random(); + final var random = new Random(); platformStateModifier = mock(PlatformStateModifier.class); round = mock(Round.class); event = mock(ConsensusEvent.class); From 620a432910c2032f35241154113f6035b68f8197 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Tue, 7 Jan 2025 18:07:46 +0200 Subject: [PATCH 36/39] style: spotless apply Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 16 +++++++++++----- .../demo/iss/ISSTestingToolStateTest.java | 4 ++-- 2 files changed, 13 insertions(+), 7 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 580378e1a412..d5e420e049cd 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 @@ -257,7 +257,9 @@ public void preHandle( public void handleConsensusRound( @NonNull final Round round, @NonNull final PlatformStateModifier platformState, - @NonNull final Consumer> stateSignatureTransactionCallback) { + @NonNull + final Consumer> + stateSignatureTransactionCallback) { throwIfImmutable(); final Iterator eventIterator = round.iterator(); @@ -332,11 +334,15 @@ private boolean areTransactionBytesSystemOnes(final Transaction transaction) { return transaction.getApplicationTransaction().length() > 4; } - private void consumeSystemTransaction(final Transaction transaction, final Event event, final Consumer> stateSignatureTransactionCallback) { + private void consumeSystemTransaction( + final Transaction transaction, + final Event event, + final Consumer> stateSignatureTransactionCallback) { try { - final var stateSignatureTransaction = StateSignatureTransaction.PROTOBUF.parse(transaction.getApplicationTransaction()); - stateSignatureTransactionCallback.accept( - new ScopedSystemTransaction<>(event.getCreatorId(), event.getSoftwareVersion(), stateSignatureTransaction)); + final var stateSignatureTransaction = + StateSignatureTransaction.PROTOBUF.parse(transaction.getApplicationTransaction()); + stateSignatureTransactionCallback.accept(new ScopedSystemTransaction<>( + event.getCreatorId(), event.getSoftwareVersion(), stateSignatureTransaction)); } catch (ParseException e) { logger.error("Failed to parse StateSignatureTransaction", e); } diff --git a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java index e37521d5a194..0bdecce5accd 100644 --- a/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java +++ b/platform-sdk/platform-apps/tests/ISSTestingTool/src/test/java/com/swirlds/demo/iss/ISSTestingToolStateTest.java @@ -32,8 +32,8 @@ import com.hedera.pbj.runtime.io.buffer.Bytes; import com.swirlds.platform.components.transaction.system.ScopedSystemTransaction; import com.swirlds.platform.event.PlatformEvent; -import com.swirlds.platform.state.MerkleStateLifecycles; import com.swirlds.platform.state.PlatformStateModifier; +import com.swirlds.platform.state.StateLifecycles; import com.swirlds.platform.system.Round; import com.swirlds.platform.system.events.ConsensusEvent; import com.swirlds.platform.system.transaction.ConsensusTransaction; @@ -65,7 +65,7 @@ class ISSTestingToolStateTest { @BeforeEach void setUp() { - state = new ISSTestingToolState(mock(MerkleStateLifecycles.class), mock(Function.class)); + state = new ISSTestingToolState(mock(StateLifecycles.class), mock(Function.class)); main = mock(ISSTestingToolMain.class); final var random = new Random(); platformStateModifier = mock(PlatformStateModifier.class); From 63b01f2b45ad7b8e4f64eb14f3012d0c6fa32cd0 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 8 Jan 2025 11:21:06 +0200 Subject: [PATCH 37/39] nit: enhance javadoc and simplify code structure Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 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 d5e420e049cd..fa5debc14fad 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 @@ -241,10 +241,24 @@ void writeObjectByChildIndex(int index, List lis @Override public void preHandle( - @NonNull Event event, - @NonNull Consumer> stateSignatureTransactionCallback) { + @NonNull final Event event, + @NonNull + final Consumer> + stateSignatureTransactionCallback) { event.forEachTransaction(transaction -> { - if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { + // We are not interested in pre-handling any system transactions, as they are + // specific for the platform only.We also don't want to consume deprecated + // EventTransaction.STATE_SIGNATURE_TRANSACTION system transactions in the + // callback,since it's intended to be used only for the new form of encoded system + // transactions in Bytes. Thus, we can directly skip the current + // iteration, if it processes a deprecated system transaction with the + // EventTransaction.STATE_SIGNATURE_TRANSACTION type. + if (transaction.isSystem()) { + return; + } + + // We should consume in the callback the new form of system transactions in Bytes + if (areTransactionBytesSystemOnes(transaction)) { consumeSystemTransaction(transaction, event, stateSignatureTransactionCallback); } }); @@ -267,7 +281,19 @@ public void handleConsensusRound( final ConsensusEvent event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { - if (!transaction.isSystem() && areTransactionBytesSystemOnes(transaction)) { + // We are not interested in handling any system transactions, as they are specific + // for the platform only.We also don't want to consume deprecated + // EventTransaction.STATE_SIGNATURE_TRANSACTION system transactions in the + // callback,since it's intended to be used only for the new form of encoded system + // transactions in Bytes. Thus, we can directly skip the current + // iteration, if it processes a deprecated system transaction with the + // EventTransaction.STATE_SIGNATURE_TRANSACTION type. + if (transaction.isSystem()) { + return; + } + + // We should consume in the callback the new form of system transactions in Bytes + if (areTransactionBytesSystemOnes(transaction)) { consumeSystemTransaction(transaction, event, stateSignatureTransactionCallback); } else { handleTransaction(transaction); @@ -313,10 +339,6 @@ private void captureTimestamp(final ConsensusEvent event) { * @param transaction the transaction to apply */ private void handleTransaction(final ConsensusTransaction transaction) { - if (transaction.isSystem()) { - return; - } - final int delta = ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0); runningSum += delta; @@ -324,8 +346,8 @@ private void handleTransaction(final ConsensusTransaction transaction) { } /** - * Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4. - * System transactions will be always bigger than that. + * Checks if the transaction bytes are system ones. The test creates application transactions + * with max length of 4. System transactions will be always bigger than that. * * @param transaction the consensus transaction to check * @return true if the transaction bytes are system ones, false otherwise @@ -343,7 +365,7 @@ private void consumeSystemTransaction( StateSignatureTransaction.PROTOBUF.parse(transaction.getApplicationTransaction()); stateSignatureTransactionCallback.accept(new ScopedSystemTransaction<>( event.getCreatorId(), event.getSoftwareVersion(), stateSignatureTransaction)); - } catch (ParseException e) { + } catch (final ParseException e) { logger.error("Failed to parse StateSignatureTransaction", e); } } From 7d3c03faa4058c60d59fe4f55b22f3737d49e212 Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Wed, 8 Jan 2025 11:50:07 +0200 Subject: [PATCH 38/39] nit: add missing final declarations Signed-off-by: Ivan Kavaldzhiev --- .../src/main/java/com/swirlds/demo/iss/ISSTestingToolMain.java | 2 +- .../src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java | 2 +- .../src/main/java/com/swirlds/platform/system/SwirldMain.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 872335fb62b1..8caa91b9e9d4 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 @@ -138,7 +138,7 @@ public List> getConfigDataTypes() { } @Override - public Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + public Bytes encodeSystemTransaction(@NonNull final StateSignatureTransaction transaction) { return StateSignatureTransaction.PROTOBUF.toBytes(transaction); } } 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 fa5debc14fad..b09c93d1ee58 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 @@ -278,7 +278,7 @@ public void handleConsensusRound( final Iterator eventIterator = round.iterator(); while (eventIterator.hasNext()) { - final ConsensusEvent event = eventIterator.next(); + final var event = eventIterator.next(); captureTimestamp(event); event.consensusTransactionIterator().forEachRemaining(transaction -> { // We are not interested in handling any system transactions, as they are specific diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index 8b3b11ecd4cb..75df6a8cdad9 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -100,7 +100,7 @@ default List> getConfigDataTypes() { * @param transaction the {@link StateSignatureTransaction} to encode * @return {@link Bytes} representation of the transaction */ - default Bytes encodeSystemTransaction(@NonNull StateSignatureTransaction transaction) { + default Bytes encodeSystemTransaction(@NonNull final StateSignatureTransaction transaction) { return Bytes.EMPTY; } } From f71ea965815125f1e628c298d9042aca10c3bc3a Mon Sep 17 00:00:00 2001 From: Ivan Kavaldzhiev Date: Thu, 9 Jan 2025 16:42:17 +0200 Subject: [PATCH 39/39] nit: fix PR comments Signed-off-by: Ivan Kavaldzhiev --- .../swirlds/demo/iss/ISSTestingToolState.java | 24 +++++++++---------- .../swirlds/platform/system/SwirldMain.java | 2 +- 2 files changed, 13 insertions(+), 13 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 b09c93d1ee58..9ecda4703be1 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 @@ -196,11 +196,11 @@ public void init( writeObjectByChildIndex(PLANNED_ISS_LIST_INDEX, plannedIssList); writeObjectByChildIndex(PLANNED_LOG_ERROR_LIST_INDEX, plannedLogErrorList); } else { - StringLeaf runningSumLeaf = getChild(RUNNING_SUM_INDEX); + final StringLeaf runningSumLeaf = getChild(RUNNING_SUM_INDEX); if (runningSumLeaf != null) { runningSum = Long.parseLong(runningSumLeaf.getLabel()); } - StringLeaf genesisTimestampLeaf = getChild(GENESIS_TIMESTAMP_INDEX); + final StringLeaf genesisTimestampLeaf = getChild(GENESIS_TIMESTAMP_INDEX); if (genesisTimestampLeaf != null) { genesisTimestamp = Instant.parse(genesisTimestampLeaf.getLabel()); } @@ -213,14 +213,14 @@ public void init( Scratchpad.create(platform.getContext(), selfId, IssTestingToolScratchpad.class, "ISSTestingTool"); } - List readObjectByChildIndex(int index, Supplier factory) { - StringLeaf stringValue = getChild(index); + List readObjectByChildIndex(final int index, final Supplier factory) { + final StringLeaf stringValue = getChild(index); if (stringValue != null) { try { - SerializableDataInputStream in = new SerializableDataInputStream( + final SerializableDataInputStream in = new SerializableDataInputStream( new ByteArrayInputStream(stringValue.getLabel().getBytes(StandardCharsets.UTF_8))); return in.readSerializableList(1024, false, factory); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } } else { @@ -228,13 +228,13 @@ List readObjectByChildIndex(int index, Supplier< } } - void writeObjectByChildIndex(int index, List list) { + void writeObjectByChildIndex(final int index, final List list) { try { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - SerializableDataOutputStream out = new SerializableDataOutputStream(byteOut); + final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + final SerializableDataOutputStream out = new SerializableDataOutputStream(byteOut); out.writeSerializableList(list, false, true); setChild(index, new StringLeaf(byteOut.toString(StandardCharsets.UTF_8))); - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException(e); } } @@ -250,7 +250,7 @@ public void preHandle( // specific for the platform only.We also don't want to consume deprecated // EventTransaction.STATE_SIGNATURE_TRANSACTION system transactions in the // callback,since it's intended to be used only for the new form of encoded system - // transactions in Bytes. Thus, we can directly skip the current + // transactions in Bytes.Thus, we can directly skip the current // iteration, if it processes a deprecated system transaction with the // EventTransaction.STATE_SIGNATURE_TRANSACTION type. if (transaction.isSystem()) { @@ -285,7 +285,7 @@ public void handleConsensusRound( // for the platform only.We also don't want to consume deprecated // EventTransaction.STATE_SIGNATURE_TRANSACTION system transactions in the // callback,since it's intended to be used only for the new form of encoded system - // transactions in Bytes. Thus, we can directly skip the current + // transactions in Bytes.Thus, we can directly skip the current // iteration, if it processes a deprecated system transaction with the // EventTransaction.STATE_SIGNATURE_TRANSACTION type. if (transaction.isSystem()) { diff --git a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java index 75df6a8cdad9..6bd799f9348f 100644 --- a/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java +++ b/platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/SwirldMain.java @@ -101,6 +101,6 @@ default List> getConfigDataTypes() { * @return {@link Bytes} representation of the transaction */ default Bytes encodeSystemTransaction(@NonNull final StateSignatureTransaction transaction) { - return Bytes.EMPTY; + throw new IllegalStateException("Invoke the method on the appropriate SwirldMain implementation!"); } }