-
Notifications
You must be signed in to change notification settings - Fork 147
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
Conversation
…ransaction() Signed-off-by: Iris Simon <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
…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]>
Signed-off-by: Lev Povolotsky <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
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
…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: 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]>
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
Signed-off-by: Kim Rader <[email protected]>
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Signed-off-by: Kim Rader <[email protected]>
@NonNull | ||
Configuration configuration(); | ||
void executeInnerPureCheck(@NonNull TransactionBody body) throws PreCheckException; |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be null
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Signed-off-by: Kim Rader <[email protected]>
Signed-off-by: Lev Povolotsky <[email protected]>
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]>
# 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]>
There was a problem hiding this 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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY @iwsimon
There was a problem hiding this 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
There was a problem hiding this 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
Description:
Related issue(s):
Fixes #17358
Notes for reviewer:
Checklist