Search in sources :

Example 1 with HapiQueryPrecheckStateException

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

the class HapiQueryOp method fittedPayment.

private Transaction fittedPayment(HapiApiSpec spec) throws Throwable {
    if (explicitPayment.isPresent()) {
        return explicitPayment.get().signedTxnFor(spec);
    } else if (nodePaymentFn.isPresent()) {
        return finalizedTxn(spec, opDef(spec, nodePaymentFn.get().apply(spec)));
    } else if (nodePayment.isPresent()) {
        return finalizedTxn(spec, opDef(spec, nodePayment.get()));
    } else {
        long initNodePayment = costOnlyNodePayment(spec);
        Transaction payment = finalizedTxn(spec, opDef(spec, initNodePayment), true);
        if (!loggingOff) {
            log.info(spec.logPrefix() + "Paying for COST_ANSWER of " + this + " with " + txnToString(payment));
        }
        long realNodePayment = timedCostLookupWith(spec, payment);
        if (recordsNodePayment) {
            spec.registry().saveAmount(nodePaymentName, realNodePayment);
        }
        if (!suppressStats) {
            spec.incrementNumLedgerOps();
        }
        if (expectedCostAnswerPrecheck() != OK) {
            return null;
        }
        if (spec.setup().costSnapshotMode() != OFF) {
            spec.recordPayment(new Payment(initNodePayment, self().getClass().getSimpleName(), COST_ANSWER_QUERY_COST));
            spec.recordPayment(new Payment(realNodePayment, self().getClass().getSimpleName(), ANSWER_ONLY_QUERY_COST));
        }
        txnSubmitted = payment;
        if (!loggingOff) {
            log.info(spec.logPrefix() + "--> Node payment for " + this + " is " + realNodePayment + " tinyBars.");
        }
        if (expectStrictCostAnswer) {
            Transaction insufficientPayment = finalizedTxn(spec, opDef(spec, realNodePayment - 1));
            submitWith(spec, insufficientPayment);
            if (INSUFFICIENT_TX_FEE != reflectForPrecheck(response)) {
                String errMsg = String.format("Strict cost of answer! suppose to be %s, but get %s", INSUFFICIENT_TX_FEE, reflectForPrecheck(response));
                log.error(errMsg);
                throw new HapiQueryPrecheckStateException(errMsg);
            } else {
                log.info("Query with node payment of {} tinyBars got INSUFFICIENT_TX_FEE as expected!", realNodePayment - 1);
            }
        }
        return finalizedTxn(spec, opDef(spec, realNodePayment));
    }
}
Also used : Payment(com.hedera.services.bdd.spec.fees.Payment) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiQueryPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException) TxnUtils.txnToString(com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)

Example 2 with HapiQueryPrecheckStateException

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

the class HapiQueryOp method submitOp.

@Override
protected boolean submitOp(HapiApiSpec spec) throws Throwable {
    fixNodeFor(spec);
    configureTlsFor(spec);
    Transaction payment = Transaction.getDefaultInstance();
    int retryCount = 1;
    while (true) {
        /* Note that HapiQueryOp#fittedPayment makes a COST_ANSWER query if necessary. */
        if (needsPayment()) {
            payment = fittedPayment(spec);
        }
        if (stopAfterCostAnswer) {
            return false;
        }
        /* If the COST_ANSWER query was expected to fail, we will not do anything else for this query. */
        if (needsPayment() && !nodePayment.isPresent() && expectedCostAnswerPrecheck() != OK) {
            return false;
        }
        if (needsPayment() && !loggingOff) {
            log.info(spec.logPrefix() + "Paying for " + this + " with " + txnToString(payment));
        }
        timedSubmitWith(spec, payment);
        actualPrecheck = reflectForPrecheck(response);
        if (answerOnlyRetryPrechecks.isPresent() && answerOnlyRetryPrechecks.get().contains(actualPrecheck) && isWithInRetryLimit(retryCount)) {
            retryCount++;
            sleep(10);
        } else {
            break;
        }
    }
    if (permissibleAnswerOnlyPrechecks.isPresent()) {
        if (permissibleAnswerOnlyPrechecks.get().contains(actualPrecheck)) {
            answerOnlyPrecheck = Optional.of(actualPrecheck);
        } else {
            String errMsg = String.format("Answer-only precheck was %s, not one of %s!", actualPrecheck, permissibleAnswerOnlyPrechecks.get());
            if (!loggingOff) {
                log.error(errMsg);
            }
            throw new HapiQueryPrecheckStateException(errMsg);
        }
    } else {
        if (expectedAnswerOnlyPrecheck() != actualPrecheck) {
            String errMsg = String.format("Bad answerOnlyPrecheck! expected %s, actual %s", expectedAnswerOnlyPrecheck(), actualPrecheck);
            if (!loggingOff) {
                log.error(errMsg);
            }
            throw new HapiQueryPrecheckStateException(errMsg);
        }
    }
    if (expectedCostAnswerPrecheck() != OK || expectedAnswerOnlyPrecheck() != OK) {
        return false;
    }
    txnSubmitted = payment;
    return true;
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiQueryPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException) TxnUtils.txnToString(com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)

Aggregations

HapiQueryPrecheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException)2 TxnUtils.txnToString (com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)2 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 Payment (com.hedera.services.bdd.spec.fees.Payment)1