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 68 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
@@ -1,6 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
/*
* 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.
* 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"

mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }

testModuleInfo {
requires("org.assertj.core")
requires("org.junit.jupiter.api")
requires("org.mockito")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static com.swirlds.platform.test.fixtures.state.FakeStateLifecycles.FAKE_MERKLE_STATE_LIFECYCLES;
import static com.swirlds.platform.test.fixtures.state.FakeStateLifecycles.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;
Expand Down Expand Up @@ -134,4 +136,9 @@
public List<Class<? extends Record>> getConfigDataTypes() {
return List.of(ISSTestingToolConfig.class);
}

@Override
public Bytes encodeSystemTransaction(@NonNull final StateSignatureTransaction transaction) {
return StateSignatureTransaction.PROTOBUF.toBytes(transaction);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L142 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,7 +54,9 @@
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.system.transaction.Transaction;
import com.swirlds.platform.test.fixtures.state.FakeStateLifecycles;
import com.swirlds.state.merkle.singleton.StringLeaf;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -236,21 +239,66 @@
}
}

@Override
public void preHandle(
@NonNull final Event event,
@NonNull
final Consumer<ScopedSystemTransaction<StateSignatureTransaction>>
stateSignatureTransactionCallback) {
event.forEachTransaction(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;

Check warning on line 257 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#L257

Added line #L257 was not covered by tests
}

// We should consume in the callback the new form of system transactions in Bytes
if (areTransactionBytesSystemOnes(transaction)) {
consumeSystemTransaction(transaction, event, stateSignatureTransactionCallback);
}
});
}

/**
* {@inheritDoc}
*/
@Override
public void handleConsensusRound(
@NonNull final Round round,
@NonNull final PlatformStateModifier platformState,
@NonNull final Consumer<ScopedSystemTransaction<StateSignatureTransaction>> stateSignatureTransaction) {
@NonNull
final Consumer<ScopedSystemTransaction<StateSignatureTransaction>>
stateSignatureTransactionCallback) {
throwIfImmutable();
final Iterator<ConsensusEvent> eventIterator = round.iterator();

while (eventIterator.hasNext()) {
final ConsensusEvent event = eventIterator.next();
final var event = eventIterator.next();
captureTimestamp(event);
event.consensusTransactionIterator().forEachRemaining(this::handleTransaction);
event.consensusTransactionIterator().forEachRemaining(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);
}
});
if (!eventIterator.hasNext()) {
final Instant currentTimestamp = event.getConsensusTimestamp();
final Duration elapsedSinceGenesis = Duration.between(genesisTimestamp, currentTimestamp);
Expand Down Expand Up @@ -291,15 +339,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;
}
final int delta =
ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0);
runningSum += delta;
setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum)));
}

/**
* 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 Transaction transaction) {
return transaction.getApplicationTransaction().length() > 4;
}

private void consumeSystemTransaction(
final Transaction transaction,
final Event event,
final Consumer<ScopedSystemTransaction<StateSignatureTransaction>> stateSignatureTransactionCallback) {
try {
final var stateSignatureTransaction =
mustafauzunn marked this conversation as resolved.
Show resolved Hide resolved
StateSignatureTransaction.PROTOBUF.parse(transaction.getApplicationTransaction());
stateSignatureTransactionCallback.accept(new ScopedSystemTransaction<>(
event.getCreatorId(), event.getSoftwareVersion(), stateSignatureTransaction));
} catch (final ParseException e) {
logger.error("Failed to parse StateSignatureTransaction", e);

Check warning on line 369 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#L368-L369

Added lines #L368 - L369 were not covered by tests
}
}

/**
* 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
Loading