Commit d904a5b
fix(l1): make cumulative balance check fail closed and exclude replaced tx cleanly
Phase 2 review (Copilot + greptile) flagged four related issues with
the saturating arithmetic in the cumulative-balance gate:
1. `sum_cost_for_sender` silently skipped entries when `txs_by_sender_nonce`
pointed to a hash missing from `transaction_pool`, undercounting.
2. The replacement adjustment `saturating_sub(old_cost)` on a saturated
sum could drop the total to 0 and admit a tx that should be rejected.
3. When a tx with `cost_without_base_fee() = None` was both summed
(as MAX) AND replaced (`old_cost` also MAX), `MAX - MAX = 0` erased
every sibling tx's contribution.
4. `cost_without_base_fee()` was called twice on the same `tx` (once for
the single-tx balance check, once as `new_cost`), inviting drift.
Single rewrite addresses all four:
- `sum_cost_for_sender` now takes an `exclude: Option<H256>` so the
caller can drop the replaced tx's contribution at scan time instead
of via a non-invertible `saturating_sub` afterward.
- Index/pool inconsistency and `None`-cost txs return `MempoolError`
rather than silently saturating, so the gate can't be bypassed by
an invariant violation.
- `checked_add` instead of `saturating_add` for the running total.
- `tx_cost` in `validate_transaction` is computed once and used for
both the single-tx and cumulative checks.
Existing unit tests updated to the new `(sender, None)` signature.1 parent 79b598e commit d904a5b
2 files changed
Lines changed: 49 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2975 | 2975 | | |
2976 | 2976 | | |
2977 | 2977 | | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
2978 | 2984 | | |
2979 | 2985 | | |
2980 | 2986 | | |
| |||
3021 | 3027 | | |
3022 | 3028 | | |
3023 | 3029 | | |
3024 | | - | |
3025 | | - | |
3026 | | - | |
3027 | | - | |
3028 | 3030 | | |
3029 | 3031 | | |
3030 | 3032 | | |
| |||
3042 | 3044 | | |
3043 | 3045 | | |
3044 | 3046 | | |
3045 | | - | |
3046 | | - | |
3047 | | - | |
3048 | | - | |
3049 | | - | |
3050 | | - | |
3051 | | - | |
3052 | | - | |
3053 | | - | |
3054 | | - | |
3055 | | - | |
3056 | | - | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
3057 | 3059 | | |
3058 | | - | |
3059 | 3060 | | |
3060 | 3061 | | |
3061 | 3062 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
628 | | - | |
629 | | - | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
630 | 632 | | |
631 | 633 | | |
632 | 634 | | |
633 | 635 | | |
634 | 636 | | |
635 | 637 | | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
642 | 648 | | |
643 | 649 | | |
644 | 650 | | |
645 | 651 | | |
646 | 652 | | |
647 | 653 | | |
648 | | - | |
| 654 | + | |
649 | 655 | | |
650 | | - | |
651 | | - | |
652 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
653 | 668 | | |
654 | 669 | | |
655 | 670 | | |
| |||
871 | 886 | | |
872 | 887 | | |
873 | 888 | | |
874 | | - | |
| 889 | + | |
875 | 890 | | |
876 | 891 | | |
877 | 892 | | |
| |||
892 | 907 | | |
893 | 908 | | |
894 | 909 | | |
895 | | - | |
| 910 | + | |
896 | 911 | | |
897 | 912 | | |
898 | 913 | | |
| |||
910 | 925 | | |
911 | 926 | | |
912 | 927 | | |
913 | | - | |
| 928 | + | |
914 | 929 | | |
915 | 930 | | |
916 | 931 | | |
| |||
928 | 943 | | |
929 | 944 | | |
930 | 945 | | |
931 | | - | |
| 946 | + | |
932 | 947 | | |
933 | 948 | | |
934 | 949 | | |
0 commit comments