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

Pre-handle improvements #5056

Merged
merged 10 commits into from Feb 27, 2023
Expand Up @@ -18,8 +18,8 @@

import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.meta.PreHandleContext;
import com.hedera.node.app.spi.meta.TransactionMetadata;
import com.hedera.node.app.spi.workflows.PreHandleContext;
import com.hedera.node.app.spi.workflows.TransactionHandler;
import com.hederahashgraph.api.proto.java.TransactionBody;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
1 change: 1 addition & 0 deletions hedera-node/hedera-app-spi/build.gradle.kts
Expand Up @@ -48,4 +48,5 @@ dependencies {

testFixturesCompileOnly(libs.spotbugs.annotations)
testFixturesCompileOnly(testLibs.assertj.core)
testFixturesApi(libs.swirlds.common)
}

This file was deleted.

Expand Up @@ -19,13 +19,15 @@
import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.key.HederaKey;
import com.hedera.node.app.spi.workflows.PreHandleContext;
import com.hederahashgraph.api.proto.java.AccountID;
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
import com.hederahashgraph.api.proto.java.SignatureMap;
import com.hederahashgraph.api.proto.java.TransactionBody;
import com.swirlds.common.crypto.TransactionSignature;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.List;
import java.util.Set;
import java.util.Map;

/**
* Metadata collected when transactions are handled as part of "pre-handle". This happens with
Expand All @@ -37,41 +39,44 @@
* @param payer payer for the transaction
* @param status {@link ResponseCodeEnum} status of the transaction
* @param payerKey payer key required to sign the transaction. It is null if payer is missing
* @param requiredNonPayerKeys list of keys that are required to sign the transaction, in addition
* to payer key
* @param readKeys the keys that were read during pre-handle
* @param payerSignature {@link TransactionSignature} of the payer
* @param otherSignatures lit {@link TransactionSignature} of other keys that need to sign
* @param innerMetadata {@link TransactionMetadata} of the inner transaction (where appropriate)
*/
public record TransactionMetadata(
@Nullable TransactionBody txnBody,
@Nullable AccountID payer,
@Nullable SignatureMap signatureMap,
@NonNull ResponseCodeEnum status,
@Nullable HederaKey payerKey,
@NonNull List<HederaKey> requiredNonPayerKeys,
@Nullable Object handlerMetadata,
@NonNull List<ReadKeys> readKeys) {
@Nullable TransactionSignature payerSignature,
@NonNull Map<HederaKey, TransactionSignature> otherSignatures,
netopyr marked this conversation as resolved.
Show resolved Hide resolved
@Nullable TransactionMetadata innerMetadata) {

public TransactionMetadata {
requireNonNull(status);
requireNonNull(requiredNonPayerKeys);
requireNonNull(readKeys);
requireNonNull(otherSignatures);
}

public TransactionMetadata(@NonNull final PreHandleContext context, @NonNull final List<ReadKeys> readKeys) {
public TransactionMetadata(
@NonNull final PreHandleContext context,
@NonNull final SignatureMap signatureMap,
@Nullable final TransactionSignature payerSignature,
@NonNull final Map<HederaKey, TransactionSignature> otherSignatures,
@Nullable final TransactionMetadata innerMetadata) {
this(
requireNonNull(context).getTxn(),
context.getPayer(),
requireNonNull(signatureMap),
context.getStatus(),
context.getPayerKey(),
context.getRequiredNonPayerKeys(),
context.getHandlerMetadata(),
readKeys);
payerSignature,
otherSignatures,
innerMetadata);
}

public TransactionMetadata(
@Nullable final TransactionBody txBody,
@Nullable final AccountID payerID,
@NonNull final ResponseCodeEnum status) {
this(txBody, payerID, status, null, List.of(), null, List.of());
public TransactionMetadata(@NonNull final ResponseCodeEnum status) {
this(null, null, null, status, null, null, Map.of(), null);
}

/**
Expand All @@ -82,27 +87,4 @@ public TransactionMetadata(
public boolean failed() {
return status != ResponseCodeEnum.OK;
}

/**
* An entry of read keys for a single {@link com.hedera.node.app.spi.state.ReadableKVState}
*
* <p>Each entry in the list consists of the {@code statesKey} (which identifies the {@link
* com.hedera.node.app.spi.state.ReadableStates}), the {@code stateKey} (which identifies the
* {@link com.hedera.node.app.spi.state.ReadableKVState}, and the {@link Set} of keys, that were
* read.
*
* @param statesKey index that identifies the {@link
* com.hedera.node.app.spi.state.ReadableStates}
* @param stateKey index that identifies the {@link
* com.hedera.node.app.spi.state.ReadableKVState}
* @param readKeys {@link Set} of all keys that were read
*/
public record ReadKeys(
@NonNull String statesKey, @NonNull String stateKey, @NonNull Set<? extends Comparable<?>> readKeys) {
public ReadKeys {
requireNonNull(statesKey);
requireNonNull(stateKey);
requireNonNull(readKeys);
}
}
}
Expand Up @@ -20,8 +20,8 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* An {@code InsufficientBalanceException} is a {@link PreCheckException} that is thrown, when the
* balance is not sufficient. It provides the {@link #estimatedFee}.
* An {@code InsufficientBalanceException} is a {@link PreCheckException} that is thrown, when the balance is not
* sufficient. It provides the {@link #estimatedFee}.
*/
public class InsufficientBalanceException extends PreCheckException {

Expand Down
Expand Up @@ -25,8 +25,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* An abstract class for all queries that are not free. If payment is required depends on the {@link
* ResponseType}
* An abstract class for all queries that are not free. If payment is required depends on the {@link ResponseType}
*/
public abstract class PaidQueryHandler implements QueryHandler {

Expand Down
Expand Up @@ -22,8 +22,8 @@
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Thrown if the request itself is bad. The protobuf decoded correctly, but it failed one or more of
* the ingestion pipeline pre-checks.
* Thrown if the request itself is bad. The protobuf decoded correctly, but it failed one or more of the ingestion
* pipeline pre-checks.
*/
public class PreCheckException extends Exception {
private final ResponseCodeEnum responseCode;
Expand Down