Search in sources :

Example 1 with ExtantCryptoContext

use of com.hedera.services.usage.crypto.ExtantCryptoContext in project hedera-services by hashgraph.

the class MacroFeesChargedSanityCheckSuite method renewalCappedByAffordablePeriod.

private HapiApiSpec renewalCappedByAffordablePeriod() {
    final long briefAutoRenew = 10L;
    final long normalAutoRenew = THREE_MONTHS_IN_SECONDS;
    final long threeHoursInSeconds = 3 * 3600L;
    final AtomicLong initialExpiry = new AtomicLong();
    final AtomicLong balanceForThreeHourRenew = new AtomicLong();
    final var target = "czar";
    final String crazyMemo = "Calmer than you are!";
    final ExtantCryptoContext cryptoCtx = ExtantCryptoContext.newBuilder().setCurrentExpiry(0L).setCurrentKey(Key.newBuilder().setEd25519(copyFromUtf8(randomUppercase(32))).build()).setCurrentlyHasProxy(true).setCurrentMemo(crazyMemo).setCurrentNumTokenRels(0).build();
    return defaultHapiSpec("RenewalCappedByAffordablePeriod").given(withOpContext((spec, opLog) -> {
        final var tbFee = autoRenewFeesFor(spec, cryptoCtx);
        balanceForThreeHourRenew.set(tbFee.totalTb(3));
        opLog.info("Balance {} will pay for three-hour renewal", balanceForThreeHourRenew.get());
    }), fileUpdate(APP_PROPERTIES).payingWith(GENESIS).overridingProps(enablingAutoRenewWith(1, 1234L)), sourcing(() -> cryptoCreate(target).entityMemo(crazyMemo).balance(balanceForThreeHourRenew.get()).autoRenewSecs(briefAutoRenew)), /* Despite asking for a three month autorenew here, the account will only
						be able to afford a three hour extension. */
    cryptoUpdate(target).autoRenewPeriod(normalAutoRenew), getAccountInfo(target).exposingExpiry(initialExpiry::set)).when(sleepFor(briefAutoRenew * 1_000L + 500L), cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, FUNDING, 1L))).then(/* The account in question will have expired (and been auto-renewed);
						should only have received a three-hour renewal, and its entire balance
						been used. */
    getAccountBalance(target).hasTinyBars(0L), sourcing(() -> getAccountInfo(target).has(accountWith().expiry(initialExpiry.get() + threeHoursInSeconds, 0L))), cryptoDelete(target));
}
Also used : UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) ByteString.copyFromUtf8(com.google.protobuf.ByteString.copyFromUtf8) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) ExchangeRate(com.hederahashgraph.api.proto.java.ExchangeRate) AutoRenewConfigChoices.enablingAutoRenewWith(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.enablingAutoRenewWith) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) FeeBuilder.getTinybarsFromTinyCents(com.hederahashgraph.fee.FeeBuilder.getTinybarsFromTinyCents) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) CRYPTO_ENTITY_SIZES(com.hedera.services.usage.crypto.entities.CryptoEntitySizes.CRYPTO_ENTITY_SIZES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AccountInfoAsserts.accountWith(com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.accountWith) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.cryptoDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoDelete) FEE_DIVISOR_FACTOR(com.hederahashgraph.fee.FeeBuilder.FEE_DIVISOR_FACTOR) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) AutoRenewConfigChoices.disablingAutoRenewWithDefaults(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.disablingAutoRenewWithDefaults) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CryptoAccountAutoRenew(com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoAccountAutoRenew) Logger(org.apache.logging.log4j.Logger) UtilVerbs.assertionsHold(com.hedera.services.bdd.spec.utilops.UtilVerbs.assertionsHold) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Assertions(org.junit.jupiter.api.Assertions) TxnUtils.randomUppercase(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUppercase) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext)

Example 2 with ExtantCryptoContext

use of com.hedera.services.usage.crypto.ExtantCryptoContext in project hedera-services by hashgraph.

the class OpUsageCtxHelper method ctxForCryptoUpdate.

public ExtantCryptoContext ctxForCryptoUpdate(TransactionBody txn) {
    final var op = txn.getCryptoUpdateAccount();
    ExtantCryptoContext cryptoContext;
    var info = workingView.infoForAccount(op.getAccountIDToUpdate(), aliasManager);
    if (info.isPresent()) {
        var details = info.get();
        cryptoContext = ExtantCryptoContext.newBuilder().setCurrentKey(details.getKey()).setCurrentMemo(details.getMemo()).setCurrentExpiry(details.getExpirationTime().getSeconds()).setCurrentlyHasProxy(details.hasProxyAccountID()).setCurrentNumTokenRels(details.getTokenRelationshipsCount()).setCurrentMaxAutomaticAssociations(details.getMaxAutomaticTokenAssociations()).setCurrentCryptoAllowances(details.getGrantedCryptoAllowancesList()).setCurrentTokenAllowances(details.getGrantedTokenAllowancesList()).setCurrentNftAllowances(details.getGrantedNftAllowancesList()).build();
    } else {
        cryptoContext = ExtantCryptoContext.newBuilder().setCurrentExpiry(txn.getTransactionID().getTransactionValidStart().getSeconds()).setCurrentMemo(DEFAULT_MEMO).setCurrentKey(Key.getDefaultInstance()).setCurrentlyHasProxy(false).setCurrentNumTokenRels(0).setCurrentMaxAutomaticAssociations(0).setCurrentCryptoAllowances(Collections.emptyList()).setCurrentTokenAllowances(Collections.emptyList()).setCurrentNftAllowances(Collections.emptyList()).build();
    }
    return cryptoContext;
}
Also used : ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext)

Example 3 with ExtantCryptoContext

use of com.hedera.services.usage.crypto.ExtantCryptoContext in project hedera-services by hashgraph.

the class OpUsageCtxHelper method ctxForCryptoAllowance.

public ExtantCryptoContext ctxForCryptoAllowance(TransactionBody txn) {
    ExtantCryptoContext cryptoContext;
    var info = workingView.infoForAccount(txn.getTransactionID().getAccountID(), aliasManager);
    if (info.isPresent()) {
        var details = info.get();
        cryptoContext = ExtantCryptoContext.newBuilder().setCurrentKey(details.getKey()).setCurrentMemo(details.getMemo()).setCurrentExpiry(details.getExpirationTime().getSeconds()).setCurrentlyHasProxy(details.hasProxyAccountID()).setCurrentNumTokenRels(details.getTokenRelationshipsCount()).setCurrentMaxAutomaticAssociations(details.getMaxAutomaticTokenAssociations()).setCurrentCryptoAllowances(details.getGrantedCryptoAllowancesList()).setCurrentTokenAllowances(details.getGrantedTokenAllowancesList()).setCurrentNftAllowances(details.getGrantedNftAllowancesList()).build();
    } else {
        cryptoContext = ExtantCryptoContext.newBuilder().setCurrentExpiry(txn.getTransactionID().getTransactionValidStart().getSeconds()).setCurrentMemo(DEFAULT_MEMO).setCurrentKey(Key.getDefaultInstance()).setCurrentlyHasProxy(false).setCurrentNumTokenRels(0).setCurrentMaxAutomaticAssociations(0).setCurrentCryptoAllowances(Collections.emptyList()).setCurrentTokenAllowances(Collections.emptyList()).setCurrentNftAllowances(Collections.emptyList()).build();
    }
    return cryptoContext;
}
Also used : ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext)

Example 4 with ExtantCryptoContext

use of com.hedera.services.usage.crypto.ExtantCryptoContext in project hedera-services by hashgraph.

the class MacroFeesChargedSanityCheckSuite method feesChargedMatchNumberOfRenewals.

private HapiApiSpec feesChargedMatchNumberOfRenewals() {
    final long reqAutoRenew = 2L;
    final long startBalance = ONE_HUNDRED_HBARS;
    final var target = "czar";
    final String crazyMemo = "Calmer than you are!";
    final AtomicLong initialExpiry = new AtomicLong();
    final AtomicLong finalExpiry = new AtomicLong();
    final AtomicLong finalBalance = new AtomicLong();
    final AtomicLong duration = new AtomicLong(30);
    final AtomicReference<TimeUnit> unit = new AtomicReference<>(SECONDS);
    final AtomicInteger maxOpsPerSec = new AtomicInteger(100);
    final ExtantCryptoContext cryptoCtx = ExtantCryptoContext.newBuilder().setCurrentExpiry(0L).setCurrentKey(Key.newBuilder().setEd25519(copyFromUtf8(randomUppercase(32))).build()).setCurrentlyHasProxy(true).setCurrentMemo(crazyMemo).setCurrentNumTokenRels(0).build();
    return defaultHapiSpec("FeesChargedMatchNumberOfRenewals").given(fileUpdate(APP_PROPERTIES).payingWith(GENESIS).overridingProps(enablingAutoRenewWith(1, 1234L)), cryptoCreate(target).entityMemo(crazyMemo).balance(startBalance).autoRenewSecs(reqAutoRenew), getAccountInfo(target).exposingExpiry(initialExpiry::set)).when(sleepFor(reqAutoRenew * 1_000L + 500L), runWithProvider(getAnyOldXfers()).lasting(duration::get, unit::get).maxOpsPerSec(maxOpsPerSec::get)).then(/* The account with the crazy short auto-renew will have expired (and
						been auto-renewed) multiple times during the 30-second burst of
						CryptoTransfers. We want to confirm its balance changed as expected
						with the number of renewals. */
    assertionsHold((spec, opLog) -> {
        final var tbFee = autoRenewFeesFor(spec, cryptoCtx).totalTb(1);
        opLog.info("Expected fee in tinybars: {}", tbFee);
        var infoOp = getAccountInfo(target).exposingBalance(finalBalance::set).exposingExpiry(finalExpiry::set);
        allRunFor(spec, infoOp);
        final long balanceChange = startBalance - finalBalance.get();
        final long expiryChange = finalExpiry.get() - initialExpiry.get();
        final int numRenewals = (int) (expiryChange / reqAutoRenew);
        opLog.info("{} renewals happened, extending expiry by {} and reducing balance by {}", numRenewals, expiryChange, balanceChange);
        Assertions.assertEquals(balanceChange, numRenewals * tbFee);
    }), cryptoDelete(target));
}
Also used : UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) ByteString.copyFromUtf8(com.google.protobuf.ByteString.copyFromUtf8) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) ExchangeRate(com.hederahashgraph.api.proto.java.ExchangeRate) AutoRenewConfigChoices.enablingAutoRenewWith(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.enablingAutoRenewWith) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) FeeBuilder.getTinybarsFromTinyCents(com.hederahashgraph.fee.FeeBuilder.getTinybarsFromTinyCents) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) CRYPTO_ENTITY_SIZES(com.hedera.services.usage.crypto.entities.CryptoEntitySizes.CRYPTO_ENTITY_SIZES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AccountInfoAsserts.accountWith(com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.accountWith) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.cryptoDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoDelete) FEE_DIVISOR_FACTOR(com.hederahashgraph.fee.FeeBuilder.FEE_DIVISOR_FACTOR) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) AutoRenewConfigChoices.disablingAutoRenewWithDefaults(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.disablingAutoRenewWithDefaults) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CryptoAccountAutoRenew(com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoAccountAutoRenew) Logger(org.apache.logging.log4j.Logger) UtilVerbs.assertionsHold(com.hedera.services.bdd.spec.utilops.UtilVerbs.assertionsHold) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Assertions(org.junit.jupiter.api.Assertions) TxnUtils.randomUppercase(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUppercase) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeUnit(java.util.concurrent.TimeUnit) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext)

Aggregations

ExtantCryptoContext (com.hedera.services.usage.crypto.ExtantCryptoContext)4 ByteString.copyFromUtf8 (com.google.protobuf.ByteString.copyFromUtf8)2 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)2 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)2 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)2 AccountInfoAsserts.accountWith (com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.accountWith)2 OpProvider (com.hedera.services.bdd.spec.infrastructure.OpProvider)2 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)2 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)2 TxnUtils.randomUppercase (com.hedera.services.bdd.spec.transactions.TxnUtils.randomUppercase)2 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)2 TxnVerbs.cryptoDelete (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoDelete)2 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)2 TxnVerbs.cryptoUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate)2 TxnVerbs.fileUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate)2 HapiCryptoTransfer.tinyBarsFromTo (com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo)2 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)2 UtilVerbs.assertionsHold (com.hedera.services.bdd.spec.utilops.UtilVerbs.assertionsHold)2 UtilVerbs.runWithProvider (com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider)2 UtilVerbs.sleepFor (com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor)2