use of com.hederahashgraph.api.proto.java.TransactionResponse in project hedera-services by hashgraph.
the class TxnResponseHelper method respondWithMetrics.
private void respondWithMetrics(final Transaction signedTxn, final StreamObserver<TransactionResponse> observer, final Runnable incReceivedCount, final Runnable incSubmittedCount) {
incReceivedCount.run();
TransactionResponse response;
try {
response = submissionFlow.submit(signedTxn);
} catch (final Exception surprising) {
final var accessor = SignedTxnAccessor.uncheckedFrom(signedTxn);
log.warn("Submission flow unable to submit {}!", accessor.getSignedTxnWrapper(), surprising);
response = FAIL_INVALID_RESPONSE;
}
observer.onNext(response);
observer.onCompleted();
if (response.getNodeTransactionPrecheckCode() == OK) {
incSubmittedCount.run();
}
}
use of com.hederahashgraph.api.proto.java.TransactionResponse 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;
}
use of com.hederahashgraph.api.proto.java.TransactionResponse in project hedera-services by hashgraph.
the class HapiTxnOp method timedCall.
private TransactionResponse timedCall(HapiApiSpec spec, Transaction txn) {
submitTime = System.currentTimeMillis();
TransactionResponse response = callToUse(spec).apply(txn);
long after = System.currentTimeMillis();
stats.setResponseLatency(after - submitTime);
return response;
}
Aggregations