use of com.hedera.services.usage.BaseTransactionMeta in project hedera-services by hashgraph.
the class CryptoOpsUsageTest method estimatesUpdateWithAutoAssociationsAsExpected.
@Test
void estimatesUpdateWithAutoAssociationsAsExpected() {
givenUpdateOpWithMaxAutoAssociations();
var expected = new UsageAccumulator();
var baseMeta = new BaseTransactionMeta(memo.length(), 0);
var opMeta = new CryptoUpdateMeta(txn.getCryptoUpdateAccount(), txn.getTransactionID().getTransactionValidStart().getSeconds());
expected.resetForTransaction(baseMeta, sigUsage);
Key oldKey = FileOpsUsage.asKey(KeyUtils.A_KEY_LIST.getKeyList());
long oldExpiry = expiry - 1_234L;
String oldMemo = "Lettuce";
int oldMaxAutoAssociations = maxAutoAssociations - 5;
var ctx = ExtantCryptoContext.newBuilder().setCurrentExpiry(oldExpiry).setCurrentMemo(oldMemo).setCurrentKey(oldKey).setCurrentlyHasProxy(false).setCurrentNumTokenRels(numTokenRels).setCurrentMaxAutomaticAssociations(oldMaxAutoAssociations).setCurrentCryptoAllowances(Collections.emptyList()).setCurrentNftAllowances(Collections.emptyList()).setCurrentTokenAllowances(Collections.emptyList()).build();
long keyBytesUsed = getAccountKeyStorageSize(key);
long msgBytesUsed = BASIC_ENTITY_ID_SIZE + memo.getBytes().length + keyBytesUsed + LONG_SIZE + BASIC_ENTITY_ID_SIZE + INT_SIZE;
expected.addBpt(msgBytesUsed);
long newVariableBytes = memo.getBytes().length + keyBytesUsed + BASIC_ENTITY_ID_SIZE;
long tokenRelBytes = numTokenRels * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr();
long sharedFixedBytes = CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + tokenRelBytes;
long newLifetime = ESTIMATOR_UTILS.relativeLifetime(txn, expiry);
long oldLifetime = ESTIMATOR_UTILS.relativeLifetime(txn, oldExpiry);
long rbsDelta = ESTIMATOR_UTILS.changeInBsUsage(CRYPTO_ENTITY_SIZES.fixedBytesInAccountRepr() + ctx.currentNonBaseRb() + ctx.currentNumTokenRels() * CRYPTO_ENTITY_SIZES.bytesInTokenAssocRepr(), oldLifetime, sharedFixedBytes + newVariableBytes, newLifetime);
if (rbsDelta > 0) {
expected.addRbs(rbsDelta);
}
final var slotDelta = ESTIMATOR_UTILS.changeInBsUsage(oldMaxAutoAssociations * CryptoOpsUsage.UPDATE_SLOT_MULTIPLIER, oldLifetime, maxAutoAssociations * CryptoOpsUsage.UPDATE_SLOT_MULTIPLIER, newLifetime);
expected.addRbs(slotDelta);
var actual = new UsageAccumulator();
subject.cryptoUpdateUsage(sigUsage, baseMeta, opMeta, ctx, actual);
assertEquals(expected, actual);
}
use of com.hedera.services.usage.BaseTransactionMeta in project hedera-services by hashgraph.
the class CryptoOpsUsageTest method estimatesApprovalAsExpected.
@Test
void estimatesApprovalAsExpected() {
givenApprovalOp();
var expected = new UsageAccumulator();
var baseMeta = new BaseTransactionMeta(0, 0);
var opMeta = new CryptoApproveAllowanceMeta(txn.getCryptoApproveAllowance(), txn.getTransactionID().getTransactionValidStart().getSeconds());
SigUsage sigUsage = new SigUsage(1, sigSize, 1);
expected.resetForTransaction(baseMeta, sigUsage);
Key oldKey = FileOpsUsage.asKey(KeyUtils.A_KEY_LIST.getKeyList());
long oldExpiry = expiry - 1_234L;
String oldMemo = "Lettuce";
var ctx = ExtantCryptoContext.newBuilder().setCurrentExpiry(oldExpiry).setCurrentMemo(oldMemo).setCurrentKey(oldKey).setCurrentlyHasProxy(false).setCurrentNumTokenRels(numTokenRels).setCurrentMaxAutomaticAssociations(maxAutoAssociations).setCurrentCryptoAllowances(Collections.emptyList()).setCurrentNftAllowances(Collections.emptyList()).setCurrentTokenAllowances(Collections.emptyList()).build();
long msgBytesUsed = (approveOp.getCryptoAllowancesCount() * CRYPTO_ALLOWANCE_SIZE) + (approveOp.getTokenAllowancesCount() * TOKEN_ALLOWANCE_SIZE) + (approveOp.getNftAllowancesCount() * NFT_ALLOWANCE_SIZE) + countSerials(approveOp.getNftAllowancesList()) * LONG_SIZE;
expected.addBpt(msgBytesUsed);
long lifetime = ESTIMATOR_UTILS.relativeLifetime(txn, oldExpiry);
expected.addRbs(msgBytesUsed * lifetime);
var actual = new UsageAccumulator();
subject.cryptoApproveAllowanceUsage(sigUsage, baseMeta, opMeta, ctx, actual);
assertEquals(expected, actual);
}
use of com.hedera.services.usage.BaseTransactionMeta in project hedera-services by hashgraph.
the class OpsTransferUsageTest method matchesWithLegacyEstimate.
@Test
void matchesWithLegacyEstimate() {
givenOp();
// and given legacy estimate:
final var expected = FeeData.newBuilder().setNetworkdata(FeeComponents.newBuilder().setConstant(1).setBpt(18047).setVpt(3).setRbh(1)).setNodedata(FeeComponents.newBuilder().setConstant(1).setBpt(18047).setVpt(1).setBpr(4)).setServicedata(FeeComponents.newBuilder().setConstant(1).setRbh(904)).build();
// when:
final var accum = new UsageAccumulator();
subject.cryptoTransferUsage(sigUsage, new CryptoTransferMeta(tokenMultiplier, 3, 7, 0), new BaseTransactionMeta(memo.getBytes().length, 3), accum);
// then:
assertEquals(expected, feeDataFrom(accum));
}
use of com.hedera.services.usage.BaseTransactionMeta in project hedera-services by hashgraph.
the class UsageAccumulatorTest method understandsNodePartitioning.
@Test
void understandsNodePartitioning() {
// when:
subject.resetForTransaction(new BaseTransactionMeta(memoBytes, numTransfers), sigUsage);
subject.addBpt(1);
subject.addBpr(2);
subject.addSbpr(3);
// then:
assertEquals(baseBpt + 1, subject.getUniversalBpt());
assertEquals(baseBpt + 1, subject.get(NODE, BPT));
assertEquals(baseBpr + 2, subject.getNodeBpr());
assertEquals(baseBpr + 2, subject.get(NODE, BPR));
assertEquals(3, subject.getNodeSbpr());
assertEquals(3, subject.get(NODE, SBPR));
assertEquals(sigUsage.numPayerKeys(), subject.getNodeVpt());
assertEquals(sigUsage.numPayerKeys(), subject.get(NODE, VPT));
assertEquals(1, subject.get(NODE, CONSTANT));
}
use of com.hedera.services.usage.BaseTransactionMeta in project hedera-services by hashgraph.
the class HapiCryptoUpdate method feeFor.
@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
try {
final CryptoGetInfoResponse.AccountInfo info = lookupInfo(spec);
FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
var ctx = ExtantCryptoContext.newBuilder().setCurrentNumTokenRels(info.getTokenRelationshipsCount()).setCurrentExpiry(info.getExpirationTime().getSeconds()).setCurrentMemo(info.getMemo()).setCurrentKey(info.getKey()).setCurrentlyHasProxy(info.hasProxyAccountID()).setCurrentMaxAutomaticAssociations(info.getMaxAutomaticTokenAssociations()).build();
var baseMeta = new BaseTransactionMeta(_txn.getMemoBytes().size(), 0);
var opMeta = new CryptoUpdateMeta(_txn.getCryptoUpdateAccount(), _txn.getTransactionID().getTransactionValidStart().getSeconds());
var accumulator = new UsageAccumulator();
cryptoOpsUsage.cryptoUpdateUsage(suFrom(svo), baseMeta, opMeta, ctx, accumulator);
return AdapterUtils.feeDataFrom(accumulator);
};
return spec.fees().forActivityBasedOp(HederaFunctionality.CryptoUpdate, metricsCalc, txn, numPayerKeys);
} catch (Throwable ignore) {
return HapiApiSuite.ONE_HBAR;
}
}
Aggregations