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"));
}
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);
}
};
}
Aggregations