629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726 | @EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedBeforeFork()
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.AcceptedAfterFork()
@EIPChecklist.BlockLevelConstraint.Test.ForkTransition.RejectedAfterFork()
@pytest.mark.parametrize(
"exceeds_limit_at_fork",
[
pytest.param(False, id="at_fork_within_limit"),
pytest.param(True, marks=pytest.mark.exception_test, id="at_fork_exceeds_limit"),
],
)
@pytest.mark.valid_at_transition_to("Osaka")
def test_fork_transition_block_rlp_limit(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
env: Environment,
fork: Fork,
exceeds_limit_at_fork: bool,
block_size_limit: int,
) -> None:
"""
Test block RLP size limit at fork transition boundary.
- Before fork (timestamp 14999): Block at limit +1 should be accepted
- At fork (timestamp 15000): Block at limit should be accepted
- At fork (timestamp 15000): Block at limit +1 should be rejected
"""
sender_before_fork = pre.fund_eoa()
sender_at_fork = pre.fund_eoa()
transactions_before, gas_used_before = exact_size_transactions(
sender_before_fork,
block_size_limit,
fork,
pre,
env.gas_limit,
)
transactions_at_fork, gas_used_at_fork = exact_size_transactions(
sender_at_fork,
block_size_limit,
fork,
pre,
env.gas_limit,
)
for fork_block_rlp_size in [
get_block_rlp_size(transactions_before, gas_used=gas_used_before),
get_block_rlp_size(transactions_at_fork, gas_used=gas_used_at_fork),
]:
assert fork_block_rlp_size == block_size_limit, (
f"Block RLP size {fork_block_rlp_size} does not exactly match "
f"limit {block_size_limit}, difference: "
f"{fork_block_rlp_size - block_size_limit} bytes"
)
# HEADER_TIMESTAMP (123456789) used in calculation takes 4 bytes in RLP
# encoding. Transition timestamps (14_999 and 15_000) take 2 bytes
# Re-define `_extradata_at_limit` accounting for this difference
timestamp_byte_savings = 2
_extradata_at_limit = EXTRA_DATA_AT_LIMIT + (b"\x00" * timestamp_byte_savings)
blocks = [
# before fork, block at limit +1 should be accepted
Block(
timestamp=14_999,
txs=transactions_before,
# +1 to exceed limit
extra_data=Bytes(_extradata_at_limit + b"\x00"),
)
]
# At fork (timestamp 15000): Test behavior with and without exceeding limit
if exceeds_limit_at_fork:
blocks.append(
Block(
timestamp=15_000,
txs=transactions_at_fork,
# +1 to exceed limit, should be rejected
extra_data=Bytes(_extradata_at_limit + b"\x00"),
exception=BlockException.RLP_BLOCK_LIMIT_EXCEEDED,
)
)
else:
blocks.append(
Block(
timestamp=15_000,
txs=transactions_at_fork,
# exact limit should be accepted
extra_data=Bytes(EXTRA_DATA_AT_LIMIT),
)
)
blockchain_test(
genesis_environment=env,
pre=pre,
post={},
blocks=blocks,
)
|