Search in sources :

Example 1 with HapiTxnPrecheckStateException

use of com.hedera.services.bdd.spec.exceptions.HapiTxnPrecheckStateException in project hedera-services by hashgraph.

the class HapiTxnOp method submitOp.

@Override
protected boolean submitOp(HapiApiSpec spec) throws Throwable {
    stats = new TxnObs(type());
    fixNodeFor(spec);
    configureTlsFor(spec);
    int retryCount = 1;
    while (true) {
        Transaction txn = finalizedTxn(spec, opBodyDef(spec));
        if (!loggingOff) {
            log.info(spec.logPrefix() + " submitting " + this + " via " + txnToString(txn));
        }
        TransactionResponse response = null;
        try {
            if (fiddler.isPresent()) {
                txn = fiddler.get().apply(txn);
            }
            response = timedCall(spec, txn);
        } catch (StatusRuntimeException e) {
            var msg = e.toString();
            if (isRecognizedRecoverable(msg)) {
                log.info("Recognized recoverable runtime exception {}, retrying status resolution...", msg);
                continue;
            } else {
                if (spec.setup().suppressUnrecoverableNetworkFailures()) {
                    return false;
                }
                log.error("{} Status resolution failed due to unrecoverable runtime exception, " + "possibly network connection lost.", TxnUtils.toReadableString(txn));
                throw new HapiTxnCheckStateException("Unable to resolve txn status!");
            }
        }
        /* Used by superclass to perform standard housekeeping. */
        txnSubmitted = txn;
        actualPrecheck = response.getNodeTransactionPrecheckCode();
        if (retryPrechecks.isPresent() && retryPrechecks.get().contains(actualPrecheck) && isWithInRetryLimit(retryCount)) {
            retryCount++;
            sleep(10);
        } else {
            break;
        }
    }
    spec.updatePrecheckCounts(actualPrecheck);
    stats.setAccepted(actualPrecheck == OK);
    if (actualPrecheck == INSUFFICIENT_PAYER_BALANCE || actualPrecheck == INSUFFICIENT_TX_FEE) {
        if (payerIsRechargingFor(spec)) {
            addIpbToPermissiblePrechecks();
            if (payerNotRecentlyRecharged(spec)) {
                rechargePayerFor(spec);
            }
        }
    }
    if (!acceptAnyPrecheck) {
        if (permissiblePrechecks.isPresent()) {
            if (permissiblePrechecks.get().contains(actualPrecheck)) {
                expectedPrecheck = Optional.of(actualPrecheck);
            } else {
                // permissiblePrechecks.get());
                throw new HapiTxnPrecheckStateException(String.format("Wrong precheck status! Expected one of %s, actual %s", permissiblePrechecks.get(), actualPrecheck));
            }
        } else {
            if (getExpectedPrecheck() != actualPrecheck) {
                // Change to an info until HapiClientValidator can be modified and can understand new errors
                log.info("{} {} Wrong actual precheck status {}, expecting {}", spec.logPrefix(), this, actualPrecheck, getExpectedPrecheck());
                throw new HapiTxnPrecheckStateException(String.format("Wrong precheck status! Expected %s, actual %s", getExpectedPrecheck(), actualPrecheck));
            }
        }
    }
    if (actualPrecheck != OK) {
        considerRecording(spec, stats);
        return false;
    }
    spec.adhocIncrement();
    if (!deferStatusResolution) {
        resolveStatus(spec);
        if (!hasStatsToCollectDuringFinalization(spec)) {
            considerRecording(spec, stats);
        }
    }
    if (requiresFinalization(spec)) {
        spec.offerFinisher(new DelegatingOpFinisher(this));
    }
    return !deferStatusResolution;
}
Also used : HapiTxnPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiTxnPrecheckStateException) TxnObs(com.hedera.services.bdd.spec.stats.TxnObs) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Transaction(com.hederahashgraph.api.proto.java.Transaction) StatusRuntimeException(io.grpc.StatusRuntimeException) HapiTxnCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiTxnCheckStateException) DelegatingOpFinisher(com.hedera.services.bdd.spec.infrastructure.DelegatingOpFinisher)

Aggregations

HapiTxnCheckStateException (com.hedera.services.bdd.spec.exceptions.HapiTxnCheckStateException)1 HapiTxnPrecheckStateException (com.hedera.services.bdd.spec.exceptions.HapiTxnPrecheckStateException)1 DelegatingOpFinisher (com.hedera.services.bdd.spec.infrastructure.DelegatingOpFinisher)1 TxnObs (com.hedera.services.bdd.spec.stats.TxnObs)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1 TransactionResponse (com.hederahashgraph.api.proto.java.TransactionResponse)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1