Search in sources :

Example 16 with Transaction

use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.

the class HapiScheduleSign method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final ScheduleInfo info = ScheduleFeeUtils.lookupInfo(spec, schedule, loggingOff);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> scheduleOpsUsage.scheduleSignUsage(_txn, suFrom(svo), info.getExpirationTime().getSeconds());
        return spec.fees().forActivityBasedOp(HederaFunctionality.ScheduleSign, metricsCalc, txn, numPayerKeys);
    } catch (Throwable ignore) {
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) TxnUtils.asScheduleId(com.hedera.services.bdd.spec.transactions.TxnUtils.asScheduleId) ScheduleSign(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleSign) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) HapiScheduleCreate.correspondingScheduledTxnId(com.hedera.services.bdd.spec.transactions.schedule.HapiScheduleCreate.correspondingScheduledTxnId) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) ScheduleSignTransactionBody(com.hederahashgraph.api.proto.java.ScheduleSignTransactionBody) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) RegistryNotFound(com.hedera.services.bdd.spec.infrastructure.RegistryNotFound) ScheduleInfo(com.hederahashgraph.api.proto.java.ScheduleInfo) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) ScheduleInfo(com.hederahashgraph.api.proto.java.ScheduleInfo)

Example 17 with Transaction

use of com.hederahashgraph.api.proto.java.Transaction 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)

Example 18 with Transaction

use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.

the class TxnUtils method replaceTxnPayerAccount.

public static Transaction replaceTxnPayerAccount(Transaction txn, AccountID accountID) {
    Transaction newTxn = Transaction.getDefaultInstance();
    try {
        TransactionBody.Builder txnBody = TransactionBody.newBuilder().mergeFrom(txn.getBodyBytes());
        txnBody.setTransactionID(TransactionID.newBuilder().setAccountID(accountID).setTransactionValidStart(txnBody.getTransactionID().getTransactionValidStart()).build());
        return txn.toBuilder().setBodyBytes(txnBody.build().toByteString()).build();
    } catch (Exception e) {
        log.warn("Transaction's body can't be parsed: {}", txnToString(txn), e);
    }
    return null;
}
Also used : CommonUtils.extractTransactionBody(com.hedera.services.legacy.proto.utils.CommonUtils.extractTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 19 with Transaction

use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.

the class HapiTopicUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    if (!spec.registry().hasTopicMeta(topic)) {
        return spec.fees().maxFeeTinyBars();
    } else {
        /* Lookup topic metadata saved during creation. */
        long oldExpiry = spec.registry().getTopicExpiry(topic);
        ConsensusCreateTopicTransactionBody oldMeta = spec.registry().getTopicMeta(topic);
        /* Computed the increase in RBS due to this update. */
        long tentativeRbsIncrease = 0;
        try {
            TransactionBody updateTxn = CommonUtils.extractTransactionBody(txn);
            tentativeRbsIncrease = ConsensusServiceFeeBuilder.getUpdateTopicRbsIncrease(updateTxn.getTransactionID().getTransactionValidStart(), oldMeta.getAdminKey(), oldMeta.getSubmitKey(), oldMeta.getMemo(), oldMeta.hasAutoRenewAccount(), Timestamp.newBuilder().setSeconds(oldExpiry).build(), updateTxn.getConsensusUpdateTopic());
        } catch (Exception impossible) {
            throw new IllegalStateException(impossible);
        }
        /* Create a custom activity metrics calculator based on the rbsIncrease. */
        final long rbsIncrease = tentativeRbsIncrease;
        FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> ConsensusServiceFeeBuilder.getConsensusUpdateTopicFee(txBody, rbsIncrease, sigUsage);
        /* Return the net fee. */
        return spec.fees().forActivityBasedOp(ConsensusUpdateTopic, metricsCalc, txn, numPayerKeys);
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) EMPTY_KEY(com.hedera.services.bdd.suites.HapiApiSuite.EMPTY_KEY) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConsensusUpdateTopic(com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusUpdateTopic) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) TxnUtils.asTopicId(com.hedera.services.bdd.spec.transactions.TxnUtils.asTopicId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TxnUtils.asTimestamp(com.hedera.services.bdd.spec.transactions.TxnUtils.asTimestamp) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) ConsensusServiceFeeBuilder(com.hederahashgraph.fee.ConsensusServiceFeeBuilder) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MoreObjects(com.google.common.base.MoreObjects) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) TxnUtils.asDuration(com.hedera.services.bdd.spec.transactions.TxnUtils.asDuration) Consumer(java.util.function.Consumer) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody)

Example 20 with Transaction

use of com.hederahashgraph.api.proto.java.Transaction in project hedera-services by hashgraph.

the class HapiContractUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    Timestamp newExpiry = TxnFactory.expiryGiven(newExpirySecs.orElse(spec.setup().defaultExpirationSecs()));
    Timestamp oldExpiry = TxnUtils.currContractExpiry(contract, spec);
    final Timestamp expiry = TxnUtils.inConsensusOrder(oldExpiry, newExpiry) ? newExpiry : oldExpiry;
    FeeCalculator.ActivityMetrics metricsCalc = (txBody, sigUsage) -> scFees.getContractUpdateTxFeeMatrices(txBody, expiry, sigUsage);
    return spec.fees().forActivityBasedOp(HederaFunctionality.ContractUpdate, metricsCalc, txn, numPayerKeys);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) HEXED_EVM_ADDRESS_LEN(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.HEXED_EVM_ADDRESS_LEN) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CommonUtils(com.swirlds.common.CommonUtils) DEPRECATED_CID_ADMIN_KEY(com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate.DEPRECATED_CID_ADMIN_KEY) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Aggregations

Transaction (com.hederahashgraph.api.proto.java.Transaction)174 Test (org.junit.jupiter.api.Test)128 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)108 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)93 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)91 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)84 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)63 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)28 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)26 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)26 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)25 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)25 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)25 Entity (com.hedera.mirror.common.domain.entity.Entity)22 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)21 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)18 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)17 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)17