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: prehandle purecheck hip 551 #17530

Merged
merged 57 commits into from
Feb 21, 2025

Conversation

kimbor
Copy link
Contributor

@kimbor kimbor commented Jan 24, 2025

Description:

Related issue(s):

Fixes #17358

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@kimbor kimbor added the HiP-551 label Jan 24, 2025
@kimbor kimbor added this to the v0.60 milestone Jan 24, 2025
@kimbor kimbor changed the base branch from main to hip-551-batch-txs January 24, 2025 03:36
@kimbor kimbor changed the title Prehandle purecheck hip 551 feat: prehandle purecheck hip 551 Jan 24, 2025
@kimbor kimbor changed the base branch from hip-551-batch-txs to 17373-batch-handle January 24, 2025 04:12
…ip-551

# Conflicts:
#	hapi/hedera-protobufs/services/basic_types.proto
#	hapi/hedera-protobufs/services/response_code.proto
#	hapi/hedera-protobufs/services/transaction.proto
#	hapi/src/main/java/com/hedera/hapi/util/HapiUtils.java
#	hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/workflows/HandleContext.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/DispatchHandleContext.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/dispatch/ChildDispatchFactory.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/handle/steps/UserTxnFactory.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/prehandle/PreHandleContextImpl.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneDispatchFactory.java
#	hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/handle/DispatchHandleContextTest.java
#	hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/handle/dispatch/ChildDispatchFactoryTest.java
#	hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/handle/steps/UserTxnTest.java
Signed-off-by: Lev Povolotsky <[email protected]>
…e-purecheck-hip-551

# Conflicts:
#	hapi/hedera-protobufs/services/basic_types.proto
#	hapi/hedera-protobufs/services/response_code.proto
#	hapi/hedera-protobufs/services/transaction.proto
#	hapi/src/main/java/com/hedera/hapi/util/HapiUtils.java
#	hedera-node/hedera-util-service-impl/src/main/java/com/hedera/node/app/service/util/impl/handlers/AtomicBatchHandler.java
Base automatically changed from 17373-batch-handle to hip-551-batch-txs February 5, 2025 16:40
povolev15 and others added 13 commits February 5, 2025 14:06
…e-purecheck-hip-551

# Conflicts:
#	hapi/hedera-protobufs/services/transaction.proto
#	hapi/src/main/java/com/hedera/hapi/util/HapiUtils.java
#	hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/workflows/PureChecksContext.java
#	hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/purechecks/PureChecksContextImpl.java
#	hedera-node/hedera-util-service-impl/src/main/java/com/hedera/node/app/service/util/impl/handlers/AtomicBatchHandler.java
#	hedera-node/hedera-util-service/src/main/java/module-info.java
Signed-off-by: Lev Povolotsky <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
…dera-services into prehandle-purecheck-hip-551

# Conflicts:
#	hedera-node/hedera-util-service-impl/src/main/java/com/hedera/node/app/service/util/impl/handlers/AtomicBatchHandler.java
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
…e-purecheck-hip-551

# Conflicts:
#	hedera-node/hedera-util-service-impl/src/main/java/com/hedera/node/app/service/util/impl/handlers/AtomicBatchHandler.java
#	hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip551/AtomicBatchTest.java
#	hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/integration/ConcurrentIntegrationTests.java
Comment on lines 109 to 118
Set<TransactionID> set = new HashSet<>();
for (final var transaction : transactions) {
final TransactionBody txBody;
try {
txBody = bodyParser.apply(transaction);
} catch (HandleException e) {
throw new PreCheckException(e.getStatus());
}

validateTruePreCheck(set.add(txBody.transactionID()), BATCH_LIST_CONTAINS_DUPLICATES);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what Michael H said, we should not do these checks in pureChecks. It will fail in pre-handle the way its implemented currently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to parse the inner transactions in order to do later validations of duplicate txs, missing batch keys, etc. In my understanding, what Michael H meant was that these kinds of checks should not happen before fees are charged and to fix that we need to move where pureChecks is called in the ingest workflow. These checks should still happen in pureChecks but where pureChecks is called should move, which is outside the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean checking transactionID is not required here. It will fail in preHandle for inner transactions @kimbor

@NonNull
Configuration configuration();
void executeInnerPureCheck(@NonNull TransactionBody body) throws PreCheckException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadocs missing.
The name of this method should be more generic IMO. Maybe dispatchPureCheck().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

for (final var transaction : op.transactions()) {
validateTruePreCheck(transaction.hasBody(), INVALID_TRANSACTION);
final TransactionBody txn = context.body();
requireNonNull(txn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should not be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

final AtomicBatchTransactionBody transactionBody = txn.atomicBatchOrThrow();

final List<Transaction> transactions = transactionBody.transactions();
requireNonNull(transactions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -153,6 +192,15 @@ public void handle(@NonNull final HandleContext context) throws HandleException
}
}

private @NonNull List<TransactionBody> getTransactionBodies(@NonNull List<Transaction> transactions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not needed. Inner transactions must always use Transaction.body

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

throw new PreCheckException(INVALID_NODE_ACCOUNT_ID);
}

if (txBody.hasFreeze() || txBody.hasAtomicBatch())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a configurable blacklist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented

// TODO
final var op = context.body();
final var atomicBatchTransactionBody = op.atomicBatchOrThrow();
requireNonNull(op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check makes no sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

final var op = context.body();
final var atomicBatchTransactionBody = op.atomicBatchOrThrow();
requireNonNull(op);
List<Transaction> transactions = atomicBatchTransactionBody.transactions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static com.hedera.hapi.node.base.ResponseCodeEnum.*;
import static org.junit.jupiter.api.Assertions.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use wildcard imports. Please update the settings of your IDE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

kimbor and others added 10 commits February 20, 2025 07:42
Signed-off-by: Lev Povolotsky <[email protected]>
# Conflicts:
#	hedera-node/hedera-app-spi/src/main/java/com/hedera/node/app/spi/workflows/PreHandleContext.java
#	hedera-node/hedera-app-spi/src/testFixtures/java/com/hedera/node/app/spi/fixtures/workflows/FakePreHandleContext.java
#	hedera-node/hedera-util-service-impl/src/main/java/com/hedera/node/app/service/util/impl/handlers/AtomicBatchHandler.java
#	hedera-node/hedera-util-service-impl/src/test/java/com/hedera/node/app/service/util/impl/test/handlers/AtomicBatchHandlerTest.java
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Kim Rader <[email protected]>
@kimbor kimbor requested a review from netopyr February 21, 2025 04:12
Copy link
Contributor

@netopyr netopyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor comments - thanks @kimbor


for (final var innerTxBody : atomicBatchTransactionBody.transactions().stream()
.map(Transaction::bodyOrThrow)
.toList()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting approach. I would recommend though to use forEach() on the stream directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwsimon this one as well please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

for (final var body : txnBodies) {
final var payerId = body.transactionIDOrThrow().accountIDOrThrow();
for (final var innerTxBody :
innerTxs.stream().map(Transaction::bodyOrThrow).toList()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. In general, I wouldn't put a complex expression inside of a foreach-loop. Using Stream.forEach() is more efficient as we do not have to create the List.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make this change in my pr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Neeharika-Sompalli Neeharika-Sompalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @kimbor @povolev15

Copy link
Contributor

@iwsimon iwsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @povolev15 @kimbor

@povolev15 povolev15 merged commit f97cf62 into hip-551-batch-txs Feb 21, 2025
44 checks passed
@povolev15 povolev15 deleted the prehandle-purecheck-hip-551 branch February 21, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement preHandle() and pureChecks() methods
8 participants