Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Bytes support for transaction iteration in ConsensusEvent and its ancestors #16844

Merged
merged 70 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7645c19
feat: add Bytes support for transaction iteration in ConsensusEvent a…
IvanKavaldzhiev Dec 2, 2024
575886c
feat: adapt ISSTestingTool to work with Bytes format as transaction r…
IvanKavaldzhiev Dec 2, 2024
564403b
docs: add TODO comment
IvanKavaldzhiev Dec 2, 2024
ba72ec3
docs: add TODO comment for EventMetadata
IvanKavaldzhiev Dec 2, 2024
c574bc4
style: apply spotless
IvanKavaldzhiev Dec 3, 2024
0220032
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 3, 2024
95a0680
nit: resolve PR comments
IvanKavaldzhiev Dec 3, 2024
03be061
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 3, 2024
407c9df
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 4, 2024
d36f76c
nit: resolve PR comments
IvanKavaldzhiev Dec 4, 2024
9d35d0a
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 9, 2024
6ce8d97
nit: refactor ISSTestingTool based on PR comments
IvanKavaldzhiev Dec 9, 2024
7dc7453
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 9, 2024
02a6496
test: add unit tests for ISSTestingToolState
IvanKavaldzhiev Dec 10, 2024
260b0c9
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 10, 2024
21f54d1
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 11, 2024
7b73cd4
nit: resolve PR comments
IvanKavaldzhiev Dec 11, 2024
d3d6198
test: fix unit tests
IvanKavaldzhiev Dec 11, 2024
bb702bc
refactor: add StateSignatureTransaction encoding logic + logic for di…
IvanKavaldzhiev Dec 12, 2024
181718a
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 12, 2024
b216060
style: spotless
IvanKavaldzhiev Dec 12, 2024
b878e27
fix: unit test
IvanKavaldzhiev Dec 13, 2024
4f752fc
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 13, 2024
8fa4ac5
nit: increase test coverage
IvanKavaldzhiev Dec 16, 2024
9a1a7f4
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 16, 2024
ad20198
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 16, 2024
f69f062
nit: fix unit test
IvanKavaldzhiev Dec 16, 2024
8ccbb06
nit: fix test
IvanKavaldzhiev Dec 16, 2024
013fda2
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 17, 2024
5fbbf90
refactor: update system transaction encoding logic and tests
IvanKavaldzhiev Dec 17, 2024
46190eb
refactor: resolve PR comments and simplify ISSTestingTool logic
IvanKavaldzhiev Dec 17, 2024
3cc20b9
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 17, 2024
8800ecd
nit: remove redundant changes
IvanKavaldzhiev Dec 17, 2024
b231d6f
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 17, 2024
b49a8c4
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 18, 2024
e1e8fd3
nit: resolve PR comments
IvanKavaldzhiev Dec 18, 2024
7765b26
nit: resolve PR comments
IvanKavaldzhiev Dec 18, 2024
b02fd94
style: spotless apply
IvanKavaldzhiev Dec 18, 2024
71ea11c
fix: unit test
IvanKavaldzhiev Dec 18, 2024
58007b7
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 19, 2024
ed7bc89
style: restore headers
IvanKavaldzhiev Dec 19, 2024
62f339a
style: spotless apply
IvanKavaldzhiev Dec 19, 2024
aebaae8
feat: add callback handling in preHandle
IvanKavaldzhiev Dec 19, 2024
127f6bb
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 19, 2024
63edb17
refactor: consumer for system transactions
mustafauzunn Dec 19, 2024
8478fd9
Merge branch 'develop' into 16703-refactor-consumer-system-transactions
mustafauzunn Dec 20, 2024
18a588a
refactor: rename consumer to stateSignatureTransaction
mustafauzunn Dec 20, 2024
bfae345
Merge remote-tracking branch 'origin/16703-refactor-consumer-system-t…
IvanKavaldzhiev Dec 20, 2024
bd2ba4f
nit: adapt consumer changes
IvanKavaldzhiev Dec 20, 2024
f5217e2
nit: resolve PR comment
IvanKavaldzhiev Dec 20, 2024
f95e7d3
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 20, 2024
70cc987
nit: resolve PR comments
IvanKavaldzhiev Dec 20, 2024
c4321a1
Merge remote-tracking branch 'origin/develop' into 16840-enhance-Cons…
IvanKavaldzhiev Dec 23, 2024
54428ef
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Dec 23, 2024
dd71830
nit: resolve PR comment
IvanKavaldzhiev Dec 23, 2024
ae63e82
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Dec 26, 2024
209c563
Merge branch 'main' into 16840-enhance-ConsensusEvent
rbarkerSL Jan 2, 2025
696b6ba
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 3, 2025
b745bbb
style: spotless apply
IvanKavaldzhiev Jan 3, 2025
ee0819c
Merge remote-tracking branch 'origin/16840-enhance-ConsensusEvent' in…
IvanKavaldzhiev Jan 3, 2025
9660a67
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 6, 2025
5219d82
fix: consume converted system transaction instead of the transaction …
IvanKavaldzhiev Jan 7, 2025
f213b61
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 7, 2025
620a432
style: spotless apply
IvanKavaldzhiev Jan 7, 2025
63b01f2
nit: enhance javadoc and simplify code structure
IvanKavaldzhiev Jan 8, 2025
9c6033f
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 8, 2025
7d3c03f
nit: add missing final declarations
IvanKavaldzhiev Jan 8, 2025
800ecca
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 8, 2025
52cf8de
Merge remote-tracking branch 'origin/main' into 16840-enhance-Consens…
IvanKavaldzhiev Jan 9, 2025
f71ea96
nit: fix PR comments
IvanKavaldzhiev Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +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.swirlds.common.constructable.ConstructableIgnored;
import com.swirlds.common.io.SelfSerializable;
import com.swirlds.common.io.streams.SerializableDataInputStream;
Expand Down Expand Up @@ -284,15 +286,37 @@
* @param transaction the transaction to apply
*/
private void handleTransaction(final ConsensusTransaction transaction) {
lpetrovic05 marked this conversation as resolved.
Show resolved Hide resolved
if (transaction.isSystem()) {
return;
int delta;

if (!transaction.getTransaction().equals(EventTransaction.DEFAULT)) {
if (transaction.isSystem()) {
return;

Check warning on line 293 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L293

Added line #L293 was not covered by tests
}

delta = ByteUtils.byteArrayToInt(
transaction.getApplicationTransaction().toByteArray(), 0);

Check warning on line 297 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L296-L297

Added lines #L296 - L297 were not covered by tests

} else {
if (isSystemTransaction(transaction.getTransactionsBytes())) {
return;

Check warning on line 301 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L301

Added line #L301 was not covered by tests
}

delta = ByteUtils.byteArrayToInt(transaction.getTransactionsBytes().toByteArray(), 0);

Check warning on line 304 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L304

Added line #L304 was not covered by tests
lpetrovic05 marked this conversation as resolved.
Show resolved Hide resolved
}
final int delta =
ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0);

runningSum += delta;
setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum)));
}

private boolean isSystemTransaction(final Bytes transactionBytes) {
if (transactionBytes == null || transactionBytes.length() == 0) {
return false;

Check warning on line 313 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L313

Added line #L313 was not covered by tests
}

final var transaction = transactionBytes.toByteArray();

Check warning on line 316 in platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ISSTestingTool/src/main/java/com/swirlds/demo/iss/ISSTestingToolState.java#L316

Added line #L316 was not covered by tests
lpetrovic05 marked this conversation as resolved.
Show resolved Hide resolved
return transaction[0] != 0;
}

lpetrovic05 marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class EventMetadata extends AbstractHashable {
* list of transactions
*/
private final List<TransactionWrapper> transactions;

/**
* The event descriptor for this event. Is not itself hashed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ public sealed interface Transaction permits ConsensusTransaction {
* @return the transaction
*/
@NonNull
@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()}.
*
* @return the application transaction Bytes or {@code Bytes.EMPTY} if the transaction is a system transaction
*/
@Deprecated
lpetrovic05 marked this conversation as resolved.
Show resolved Hide resolved
default @NonNull Bytes getApplicationTransaction() {
return !isSystem() ? getTransaction().transaction().as() : Bytes.EMPTY;
}
Expand All @@ -61,6 +70,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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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;

Expand All @@ -52,6 +54,7 @@
public TransactionWrapper(@NonNull final OneOf<TransactionOneOfType> transaction) {
Objects.requireNonNull(transaction, "transaction should not be null");
this.payload = new EventTransaction(transaction);
this.payloadBytes = Bytes.EMPTY;
}

/**
Expand All @@ -63,6 +66,19 @@
*/
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");

Check warning on line 81 in platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java#L79-L81

Added lines #L79 - L81 were not covered by tests
}

/**
Expand Down Expand Up @@ -117,6 +133,20 @@
return payload;
}

@Override
@NonNull
public Bytes getTransactionsBytes() {
if (payloadBytes != null && payloadBytes.length() > 0) {
return payloadBytes;

Check warning on line 140 in platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java#L140

Added line #L140 was not covered by tests
}

if (payload != null && payload.applicationTransaction() != null) {
return payload.applicationTransaction();

Check warning on line 144 in platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java#L144

Added line #L144 was not covered by tests
}

return Bytes.EMPTY;

Check warning on line 147 in platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/transaction/TransactionWrapper.java#L147

Added line #L147 was not covered by tests
}

/**
* Get the serialized size of the transaction. This method returns the same value as
* {@code SwirldsTransaction.getSerializedLength()} and {@code StateSignatureTransaction.getSerializedLength()}.
Expand Down