test_block_full_data()
Documentation for tests/benchmark/compute/scenario/test_transaction_types.py::test_block_full_data@622620d8.
Generate fixtures for these test cases for Amsterdam with:
fill -v tests/benchmark/compute/scenario/test_transaction_types.py::test_block_full_data --gas-benchmark-values 1
Test a block full of calldata, respecting RLP size limits.
Source code in tests/benchmark/compute/scenario/test_transaction_types.py
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419 | @pytest.mark.parametrize("zero_byte", [True, False])
def test_block_full_data(
benchmark_test: BenchmarkTestFiller,
pre: Alloc,
zero_byte: bool,
intrinsic_cost: int,
gas_benchmark_value: int,
tx_gas_limit: int,
fork: Fork,
) -> None:
"""Test a block full of calldata, respecting RLP size limits."""
iteration_count = math.ceil(gas_benchmark_value / tx_gas_limit)
# check for EIP-7934 block RLP size limit and cap gas to stay under it
block_rlp_limit = fork.block_rlp_size_limit()
effective_gas = gas_benchmark_value
if block_rlp_limit:
# Max calldata bytes at 99% of limit (Osaka: 8,388,608 * 0.99 ≈ 8.3 MB)
safe_calldata_bytes = int(block_rlp_limit * 0.99)
gas_per_byte = fork.calldata_gas_calculator()(
data=b"\x00" if zero_byte else b"\xff", floor=True
)
# For zero bytes: 8.3MB * 10 = 83M gas just for calldata
max_calldata_gas = safe_calldata_bytes * gas_per_byte
# Add intrinsic cost per tx (Osaka): 83M + 6 txs * 21k ≈ 83.1M total
rlp_limited_gas = max_calldata_gas + iteration_count * intrinsic_cost
# use the min between benchmark target and the RLP limit
effective_gas = min(gas_benchmark_value, rlp_limited_gas)
gas_remaining = effective_gas
total_gas_used = 0
txs = []
for _ in range(iteration_count):
if gas_remaining <= intrinsic_cost:
break
gas_available = min(tx_gas_limit, gas_remaining) - intrinsic_cost
data = calldata_generator(
gas_available,
zero_byte,
fork,
)
total_gas_used += fork.transaction_intrinsic_cost_calculator()(
calldata=data
)
gas_remaining -= gas_available + intrinsic_cost
txs.append(
Transaction(
to=pre.fund_eoa(),
data=data,
gas_limit=gas_available + intrinsic_cost,
sender=pre.fund_eoa(),
)
)
benchmark_test(
blocks=[Block(txs=txs)],
expected_benchmark_gas_used=total_gas_used,
)
|
Parametrized Test Cases
This test generates 2 parametrized test cases across 3 forks.