Skip to content

test_block_full_data()

Documentation for tests/benchmark/compute/scenario/test_transaction_types.py::test_block_full_data@20373115.

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
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
348
349
350
351
352
353
354
355
356
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
@pytest.mark.parametrize("zero_byte", [True, False])
def test_block_full_data(
    benchmark_test: BenchmarkTestFiller,
    pre: Alloc,
    zero_byte: bool,
    intrinsic_cost: int,
    total_cost_floor_per_token: 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)

        # convert to gas: zero bytes = 10 gas/byte, non-zero = 40 gas/byte
        gas_per_byte = (
            total_cost_floor_per_token
            if zero_byte
            else total_cost_floor_per_token * 4
        )
        # 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,
            total_cost_floor_per_token,
        )

        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.