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

refactor: enhance consistency testing tool #17136

Merged
merged 19 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
97eac92
refactor: enhance consistency testing tool
mustafauzunn Dec 19, 2024
63edb17
refactor: consumer for system transactions
mustafauzunn Dec 19, 2024
f4caa08
Merge branch '16703-refactor-consumer-system-transactions' of github.…
mustafauzunn Dec 20, 2024
8478fd9
Merge branch 'develop' into 16703-refactor-consumer-system-transactions
mustafauzunn Dec 20, 2024
072a689
refactor: after merge with consumer refactor branch
mustafauzunn Dec 20, 2024
84a256f
Merge branch '16703-refactor-consumer-system-transactions' of github.…
mustafauzunn Dec 20, 2024
5697b4a
docs: add javadoc
mustafauzunn Dec 20, 2024
7643692
Merge branch 'develop' of github.com:hashgraph/hedera-services into 1…
mustafauzunn Dec 20, 2024
312f184
refactor: consistency testing tool
mustafauzunn Dec 20, 2024
7a1f1aa
test: add unit tests for the new logic in handle and prehandle
mustafauzunn Jan 6, 2025
9da0556
Merge branch 'main' of github.com:hashgraph/hedera-services into 1679…
mustafauzunn Jan 6, 2025
c1f7e96
refactor: address PR comments
mustafauzunn Jan 7, 2025
c8f4bbf
refactor: unit tests
mustafauzunn Jan 7, 2025
fa9cd85
Merge branch 'main' of github.com:hashgraph/hedera-services into 1679…
mustafauzunn Jan 7, 2025
f39d6ff
refactor: unit test import
mustafauzunn Jan 7, 2025
c2af1a6
refactor: implementation
mustafauzunn Jan 7, 2025
4f73ef8
refactor: implementation
mustafauzunn Jan 10, 2025
203da89
Merge branch 'main' of github.com:hashgraph/hedera-services into 1679…
mustafauzunn Jan 10, 2025
ee1eaab
refactor: PR comments
mustafauzunn Jan 10, 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,4 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 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.consistency.ConsistencyTestingToolMain"
Expand All @@ -7,6 +22,7 @@ mainModuleInfo { annotationProcessor("com.swirlds.config.processor") }

testModuleInfo {
requires("com.swirlds.common.test.fixtures")
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 @@ -139,4 +141,9 @@
public List<Class<? extends Record>> getConfigDataTypes() {
return List.of(ConsistencyTestingToolConfig.class);
}

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

Check warning on line 147 in platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolMain.java#L147

Added line #L147 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.hapi.platform.event.StateSignatureTransaction;
import com.hedera.pbj.runtime.ParseException;
import com.swirlds.common.config.StateCommonConfig;
import com.swirlds.common.constructable.ConstructableIgnored;
import com.swirlds.common.utility.NonCryptographicHashing;
Expand All @@ -36,6 +37,7 @@
import com.swirlds.platform.system.SoftwareVersion;
import com.swirlds.platform.system.events.Event;
import com.swirlds.platform.system.transaction.ConsensusTransaction;
import com.swirlds.platform.system.transaction.Transaction;
import com.swirlds.state.merkle.singleton.StringLeaf;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -250,6 +252,11 @@
if (transaction.isSystem()) {
return;
}

if (isSystemTransaction(transaction)) {
consumeSystemTransaction(transaction, event, stateSignatureTransaction);
return;
}
final long transactionContents =
byteArrayToLong(transaction.getApplicationTransaction().toByteArray(), 0);

Expand Down Expand Up @@ -284,12 +291,43 @@

roundsHandled++;

round.forEachTransaction(this::applyTransactionToState);
round.forEachEventTransaction((ev, tx) -> {
if (isSystemTransaction(tx)) {
consumeSystemTransaction(tx, ev, stateSignatureTransaction);
} else {
applyTransactionToState(tx);
}
});
stateLong = NonCryptographicHashing.hash64(stateLong, round.getRoundNum());

transactionHandlingHistory.processRound(ConsistencyTestingToolRound.fromRound(round, stateLong));

setChild(ROUND_HANDLED_INDEX, new StringLeaf(Long.toString(roundsHandled)));
setChild(STATE_LONG_INDEX, new StringLeaf(Long.toString(stateLong)));
}

/**
* Determines if the given transaction is a system transaction for this app.
*
* @param transaction the transaction to check
* @return true if the transaction is a system transaction, false otherwise
*/
private boolean isSystemTransaction(final @NonNull Transaction transaction) {
return transaction.getApplicationTransaction().length() > 8;
}

private void consumeSystemTransaction(
mustafauzunn marked this conversation as resolved.
Show resolved Hide resolved
final @NonNull Transaction transaction,
final @NonNull Event event,
final @NonNull Consumer<ScopedSystemTransaction<StateSignatureTransaction>>
stateSignatureTransactionCallback) {
try {
final var stateSignatureTransaction =
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 330 in platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java

View check run for this annotation

Codecov / codecov/patch

platform-sdk/platform-apps/tests/ConsistencyTestingTool/src/main/java/com/swirlds/demo/consistency/ConsistencyTestingToolState.java#L329-L330

Added lines #L329 - L330 were not covered by tests
}
}
}
Loading