Search in sources :

Example 1 with TxnValidityAndFeeReq

use of com.hedera.services.context.domain.process.TxnValidityAndFeeReq in project hedera-services by hashgraph.

the class SolvencyPrecheck method solvencyOfVerifiedPayer.

private TxnValidityAndFeeReq solvencyOfVerifiedPayer(SignedTxnAccessor accessor, boolean includeSvcFee) {
    final var payerId = EntityNum.fromAccountId(accessor.getPayer());
    final var payerAccount = accounts.get().get(payerId);
    try {
        final var now = accessor.getTxnId().getTransactionValidStart();
        final var payerKey = payerAccount.getAccountKey();
        final var estimatedFees = feeCalculator.estimateFee(accessor, payerKey, stateView.get(), now);
        final var estimatedReqFee = totalOf(estimatedFees, includeSvcFee);
        if (accessor.getTxn().getTransactionFee() < estimatedReqFee) {
            return new TxnValidityAndFeeReq(INSUFFICIENT_TX_FEE, estimatedReqFee);
        }
        final var estimatedAdj = Math.min(0L, feeCalculator.estimatedNonFeePayerAdjustments(accessor, now));
        final var requiredPayerBalance = estimatedReqFee - estimatedAdj;
        final var payerBalance = payerAccount.getBalance();
        ResponseCodeEnum finalStatus = OK;
        if (payerBalance < requiredPayerBalance) {
            final var isDetached = payerBalance == 0 && dynamicProperties.autoRenewEnabled() && !validator.isAfterConsensusSecond(payerAccount.getExpiry());
            finalStatus = isDetached ? ACCOUNT_EXPIRED_AND_PENDING_REMOVAL : INSUFFICIENT_PAYER_BALANCE;
        }
        return new TxnValidityAndFeeReq(finalStatus, estimatedReqFee);
    } catch (Exception suspicious) {
        log.warn("Fee calculation failure may be justifiable due to an expiring payer, but...", suspicious);
        return LOST_PAYER_EXPIRATION_RACE;
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq) KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) InvalidAccountIDException(com.hedera.services.legacy.exception.InvalidAccountIDException)

Example 2 with TxnValidityAndFeeReq

use of com.hedera.services.context.domain.process.TxnValidityAndFeeReq in project hedera-services by hashgraph.

the class TransactionPrecheck method performance.

private Pair<TxnValidityAndFeeReq, SignedTxnAccessor> performance(final Transaction signedTxn, final Set<Characteristic> characteristics) {
    if (currentPlatformStatus.get() != ACTIVE) {
        return WELL_KNOWN_FLAWS.get(PLATFORM_NOT_ACTIVE);
    }
    final var structuralAssessment = stagedPrechecks.assessStructure(signedTxn);
    final var accessor = structuralAssessment.getRight();
    if (null == accessor) {
        return structuralAssessment;
    }
    final var txn = accessor.getTxn();
    final var syntaxStatus = stagedPrechecks.validateSyntax(txn);
    if (syntaxStatus != OK) {
        return responseForFlawed(syntaxStatus);
    }
    final var semanticStatus = checkSemantics(accessor, characteristics);
    if (semanticStatus != OK) {
        return responseForFlawed(semanticStatus);
    }
    final var solvencyStatus = characteristics.contains(Characteristic.MUST_BE_SOLVENT_FOR_SVC_FEES) ? stagedPrechecks.assessSolvencyWithSvcFees(accessor) : stagedPrechecks.assessSolvencySansSvcFees(accessor);
    if (solvencyStatus.getValidity() != OK) {
        return failureFor(solvencyStatus);
    }
    if (characteristics.contains(Characteristic.MUST_PASS_SYSTEM_SCREEN)) {
        final var systemStatus = stagedPrechecks.systemScreen(accessor);
        if (systemStatus != OK) {
            return failureFor(new TxnValidityAndFeeReq(systemStatus, solvencyStatus.getRequiredFee()));
        }
    }
    return Pair.of(solvencyStatus, accessor);
}
Also used : TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq)

Example 3 with TxnValidityAndFeeReq

use of com.hedera.services.context.domain.process.TxnValidityAndFeeReq in project hedera-services by hashgraph.

the class TransactionPrecheck method performForQueryPayment.

public Pair<TxnValidityAndFeeReq, SignedTxnAccessor> performForQueryPayment(final Transaction signedTxn) {
    final var prelim = performance(signedTxn, QUERY_PAYMENT_CHARACTERISTICS);
    final var accessor = prelim.getRight();
    if (null == accessor) {
        return prelim;
    }
    final var xferTxn = accessor.getTxn();
    final var xfersStatus = queryFeeCheck.validateQueryPaymentTransfers(xferTxn);
    if (xfersStatus != OK) {
        return failureFor(new TxnValidityAndFeeReq(xfersStatus, prelim.getLeft().getRequiredFee()));
    }
    return prelim;
}
Also used : TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq)

Example 4 with TxnValidityAndFeeReq

use of com.hedera.services.context.domain.process.TxnValidityAndFeeReq in project hedera-services by hashgraph.

the class TransactionPrecheckTest method abortsOnInsolvencyForQueryPayment.

@Test
void abortsOnInsolvencyForQueryPayment() {
    givenActivePlatform();
    givenStructuralSoundness();
    givenValidSyntax();
    givenValidSemantics();
    given(solvencyPrecheck.assessWithSvcFees(any())).willReturn(new TxnValidityAndFeeReq(INSUFFICIENT_TX_FEE, reqFee));
    final var queryPaymentResponse = subject.performForQueryPayment(Transaction.getDefaultInstance());
    assertFailure(INSUFFICIENT_TX_FEE, reqFee, queryPaymentResponse);
}
Also used : TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TxnValidityAndFeeReq

use of com.hedera.services.context.domain.process.TxnValidityAndFeeReq in project hedera-services by hashgraph.

the class TransactionPrecheckTest method abortsOnStructuralFlawWithBadAccessor.

@Test
void abortsOnStructuralFlawWithBadAccessor() {
    givenActivePlatform();
    final Pair<TxnValidityAndFeeReq, SignedTxnAccessor> dummyPair = Pair.of(new TxnValidityAndFeeReq(OK), null);
    given(structuralPrecheck.assess(any())).willReturn(dummyPair);
    final var topLevelResponse = subject.performForTopLevel(Transaction.getDefaultInstance());
    final var queryPaymentResponse = subject.performForQueryPayment(Transaction.getDefaultInstance());
    assertFailure(OK, topLevelResponse);
    assertFailure(OK, queryPaymentResponse);
    verify(syntaxPrecheck, never()).validate(any());
}
Also used : TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TxnValidityAndFeeReq (com.hedera.services.context.domain.process.TxnValidityAndFeeReq)6 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 InvalidAccountIDException (com.hedera.services.legacy.exception.InvalidAccountIDException)1 KeyPrefixMismatchException (com.hedera.services.legacy.exception.KeyPrefixMismatchException)1 SignedTxnAccessor (com.hedera.services.utils.SignedTxnAccessor)1 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)1