test_nested_call_chain()
Documentation for tests/benchmark/compute/instruction/test_system.py::test_nested_call_chain@02aafd78.
Generate fixtures for these test cases for Bogota with:
fill -v tests/benchmark/compute/instruction/test_system.py::test_nested_call_chain --gas-benchmark-values 1
Benchmark nested call frames that each enter a different contract.
Source code in tests/benchmark/compute/instruction/test_system.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347 | def test_nested_call_chain(
benchmark_test: BenchmarkTestFiller,
pre: Alloc,
fork: Fork,
tx_gas_limit: int,
gas_benchmark_value: int,
) -> None:
"""Benchmark nested call frames that each enter a different contract."""
# Overwriting the slot keeps the tail cheaper than filling a fresh one.
tail = Op.SSTORE(0, 2, original_value=1, current_value=1, new_value=2)
tail_address = pre.deploy_contract(code=tail, storage={0: 1})
# Every level is a distinct account, so the first traversal pays cold
# access all the way down.
address = tail_address
link = Op.POP(Op.CALL(gas=Op.GAS, address=address, address_warm=False))
tail_call_gas = link.gas_cost(fork) + math.ceil(
tail.gas_cost(fork) * 64 / 63
)
gas = min(tx_gas_limit, gas_benchmark_value)
gas -= fork.transaction_intrinsic_cost_calculator()(
return_cost_deducted_prior_execution=True
)
while True:
forwarded_gas = gas - link.gas_cost(fork)
forwarded_gas -= forwarded_gas // 64
if forwarded_gas < tail_call_gas:
break
gas = forwarded_gas
address = pre.deploy_contract(code=link)
link = Op.POP(Op.CALL(gas=Op.GAS, address=address, address_warm=False))
benchmark_test(
target_opcode=Op.CALL,
skip_gas_used_validation=True,
post={tail_address: Account(storage={0: 2})},
tx=Transaction(
to=pre.deploy_contract(code=WhileGas(body=link, fork=fork)),
sender=pre.fund_eoa(),
),
)
|
Parametrized Test Cases
This test generates 1 parametrized test case across 4 forks.