Search in sources :

Example 1 with ADD_NTH_FIB_ABI

use of com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI in project hedera-services by hashgraph.

the class ContractCreateSuite method canCallPendingContractSafely.

private HapiApiSpec canCallPendingContractSafely() {
    final int numSlots = 64;
    final int createBurstSize = 500;
    final int[] targets = { 19, 24 };
    final AtomicLong createdFileNum = new AtomicLong();
    final var callTxn = "callTxn";
    final var initcode = "initcode";
    return defaultHapiSpec("CanCallPendingContractSafely").given(UtilVerbs.overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(FIBONACCI_PLUS_PATH).payingWith(GENESIS).exposingNumTo(createdFileNum::set), inParallel(IntStream.range(0, createBurstSize).mapToObj(i -> contractCreate("contract" + i, FIBONACCI_PLUS_CONSTRUCTOR_ABI, numSlots).fee(ONE_HUNDRED_HBARS).gas(300_000L).payingWith(GENESIS).noLogging().deferStatusResolution().bytecode(initcode).adminKey(THRESHOLD)).toArray(HapiSpecOperation[]::new))).when().then(sourcing(() -> contractCall("0.0." + (createdFileNum.get() + createBurstSize), ADD_NTH_FIB_ABI, targets, 12).payingWith(GENESIS).gas(300_000L).via(callTxn)), UtilVerbs.resetAppPropertiesTo("src/main/resource/bootstrap.properties"));
}
Also used : Arrays(java.util.Arrays) ContractFnResultAsserts.isContractWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isContractWith) SEND_REPEATEDLY_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_REPEATEDLY_ABI) SigControl(com.hedera.services.bdd.spec.keys.SigControl) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ContractID(com.hederahashgraph.api.proto.java.ContractID) EMPTY_CONSTRUCTOR(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.EMPTY_CONSTRUCTOR) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) FIBONACCI_PLUS_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI) CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.CONTRACT) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) BigInteger(java.math.BigInteger) Bytes32(org.apache.tuweni.bytes.Bytes32) Path(java.nio.file.Path) Longs(com.google.common.primitives.Longs) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TRANSACTION_OVERSIZE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_OVERSIZE) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) UncheckedIOException(java.io.UncheckedIOException) MEMO_TOO_LONG(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MEMO_TOO_LONG) List(java.util.List) ControlForKey.forKey(com.hedera.services.bdd.spec.keys.ControlForKey.forKey) Logger(org.apache.logging.log4j.Logger) CONSPICUOUS_DONATION_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CONSPICUOUS_DONATION_ABI) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) IntStream(java.util.stream.IntStream) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) SEND_THEN_REVERT_NESTED_SENDS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_THEN_REVERT_NESTED_SENDS_ABI) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) MAX_GAS_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_GAS_LIMIT_EXCEEDED) MULTIPURPOSE_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPURPOSE_BYTECODE_PATH) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) UtilVerbs.newKeyListNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyListNamed) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PROPAGATE_NESTED_CREATIONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.PROPAGATE_NESTED_CREATIONS_ABI) FIBONACCI_PLUS_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH) Files(java.nio.file.Files) ERROR_DECODING_BYTESTRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ERROR_DECODING_BYTESTRING) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) IOException(java.io.IOException) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) UtilVerbs.contractListWithPropertiesInheritedFrom(com.hedera.services.bdd.spec.utilops.UtilVerbs.contractListWithPropertiesInheritedFrom) ContractFnResultAsserts.isLiteralResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) HapiPropertySource.asSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asSolidityAddress) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) OFF(com.hedera.services.bdd.spec.keys.SigControl.OFF) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) THRESHOLD(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType.THRESHOLD) Assertions(org.junit.jupiter.api.Assertions) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) ADD_NTH_FIB_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) ContractInfoAsserts.contractWith(com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with ADD_NTH_FIB_ABI

use of com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI in project hedera-services by hashgraph.

the class FibonacciPlusLoadProvider method contractOpsFactory.

private Function<HapiApiSpec, OpProvider> contractOpsFactory() {
    final String civilian = "civilian";
    final String bytecode = "bytecode";
    final SplittableRandom random = new SplittableRandom(1_234_567L);
    final IntFunction<String> contractNameFn = i -> "contract" + i;
    final int r = powerLawBaseReciprocal.get();
    final DoubleUnaryOperator logBaseReciprocal = x -> Math.log(x) / Math.log(r);
    final int numDiscreteSizes = (int) ceil(logBaseReciprocal.applyAsDouble(numContracts.get() * (r - 1)));
    double scale = powerLawScale.get();
    int numSlots = (int) Math.pow(scale, numDiscreteSizes - 1) * smallestNumSlots.get();
    int numContractsWithThisManySlots = 1;
    int nextContractNum = 0;
    for (int i = 0; i < numDiscreteSizes; i++) {
        log.info("Will use {} contracts with {} slots", numContractsWithThisManySlots, numSlots);
        for (int j = 0; j < numContractsWithThisManySlots; j++) {
            final var thisContractNum = nextContractNum++;
            final var thisContract = contractNameFn.apply(thisContractNum);
            contractSlots.put(thisContract, numSlots);
            if (validateStorage.get()) {
                final var slots = new BigInteger[numSlots];
                Arrays.fill(slots, BigInteger.ZERO);
                contractStorage.put(thisContract, slots);
            }
        }
        numSlots /= scale;
        numContractsWithThisManySlots *= r;
    }
    log.info("Will use {} contracts in total", nextContractNum);
    numContracts.set(nextContractNum);
    Supplier<String> randomCallChoice = () -> {
        final var iter = createdSoFar.iterator();
        final var n = createdSoFar.size();
        if (n == 1) {
            return iter.next();
        }
        for (int i = 0; i < random.nextInt(n - 1); i++, iter.next()) {
        /* No-op */
        }
        return iter.next();
    };
    final var that = this;
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            final List<HapiSpecOperation> inits = new ArrayList<>();
            inits.add(fileCreate(bytecode).path(FIBONACCI_PLUS_PATH).noLogging().payingWith(GENESIS));
            inits.add(cryptoCreate(civilian).balance(100 * ONE_MILLION_HBARS).payingWith(GENESIS));
            return inits;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            final var aCallNum = submittedOps.incrementAndGet();
            if (aCallNum == 1) {
                effStart.set(Instant.now());
            }
            final var choice = (createdSoFar.isEmpty() || random.nextDouble() > MIN_CALL_PROB) ? contractNameFn.apply(random.nextInt(numContracts.get())) : randomCallChoice.get();
            final HapiSpecOperation op;
            if (createdSoFar.contains(choice)) {
                final var n = slotsPerCall.get();
                final int[] targets = new int[n];
                final var m = contractSlots.get(choice);
                for (int i = 0; i < n; i++) {
                    targets[i] = random.nextInt(m);
                }
                final var targetsDesc = Arrays.toString(targets);
                if (verbose.get()) {
                    log.info("Calling {} with targets {} and fibN {}", choice, targetsDesc, fibN.get());
                }
                op = contractCall(choice, ADD_NTH_FIB_ABI, targets, fibN.get()).noLogging().payingWith(civilian).gas(GAS_TO_OFFER).exposingGasTo((code, gas) -> {
                    if (verbose.get()) {
                        log.info("(Tried to) call {} (targets = {}, fibN = {}) with {} gas --> {}", choice, targetsDesc, fibN.get(), gas, code);
                    }
                    that.observeExposedGas(gas);
                    if (code == SUCCESS && validateStorage.get()) {
                        final var curSlots = contractStorage.get(choice);
                        final var newSlots = Arrays.copyOf(curSlots, m);
                        for (int i = 0; i < n; i++) {
                            final var j = targets[i];
                            newSlots[j] = newSlots[j].add(fibNValue.get());
                        }
                        contractStorage.put(choice, newSlots);
                    }
                }).hasKnownStatusFrom(SUCCESS, CONTRACT_REVERT_EXECUTED, INSUFFICIENT_GAS).deferStatusResolution();
            } else {
                final var numSlots = contractSlots.get(choice);
                op = contractCreate(choice, FIBONACCI_PLUS_CONSTRUCTOR_ABI, numSlots).bytecode(bytecode).payingWith(civilian).balance(0L).gas(GAS_TO_OFFER).exposingGasTo((code, gas) -> {
                    if (code == SUCCESS) {
                        createdSoFar.add(choice);
                    }
                    log.info("(Tried to) create {} ({} slots) with {} gas --> {}", choice, numSlots, gas, code);
                    that.observeExposedGas(gas);
                }).noLogging().hasKnownStatusFrom(SUCCESS, INSUFFICIENT_GAS).deferStatusResolution();
            }
            return Optional.of(op);
        }
    };
}
Also used : UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) Arrays(java.util.Arrays) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) QueryVerbs.getExecTime(com.hedera.services.bdd.spec.queries.QueryVerbs.getExecTime) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) FIBONACCI_PLUS_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) SplittableRandom(java.util.SplittableRandom) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) BigInteger(java.math.BigInteger) ContractFnResultAsserts.isLiteralArrayResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralArrayResult) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) Set(java.util.Set) Math.ceil(java.lang.Math.ceil) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) UtilVerbs.noOp(com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) PerfUtilOps.mgmtOfBooleanProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfBooleanProp) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) CURRENT_FIB_SLOTS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CURRENT_FIB_SLOTS_ABI) IntFunction(java.util.function.IntFunction) FIBONACCI_PLUS_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) ADD_NTH_FIB_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) BigInteger(java.math.BigInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) SplittableRandom(java.util.SplittableRandom) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Aggregations

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 ContractFnResultAsserts.resultWith (com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith)2 ADD_NTH_FIB_ABI (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI)2 FIBONACCI_PLUS_CONSTRUCTOR_ABI (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI)2 FIBONACCI_PLUS_PATH (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH)2 TxnVerbs.contractCall (com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall)2 TxnVerbs.contractCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate)2 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)2 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)2 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)2 UtilVerbs.sourcing (com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing)2 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)2 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)2 CONTRACT_REVERT_EXECUTED (com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED)2 INSUFFICIENT_GAS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS)2 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)2 BigInteger (java.math.BigInteger)2 Arrays (java.util.Arrays)2