Commit 5aff485
committed
fix(router-access): align expiry semantics and fix RoleMemberCount bookkeeping Closes #716 Three related bugs in contracts/router-access/src/lib.rs: 1. Expiry comparison inconsistency (>= vs >) is_role_expired and has_direct_role_internal used >= so a role whose expires_at equalled the current timestamp was already considered expired. router-core's is_route_expired uses >, making expires_at the last valid ledger sequence. Both sites changed to > to match that convention. 2. RoleMemberCount never incremented on grant grant_role_internal had a comment promising to maintain RoleMemberCount without iterating RoleMembers, but the increment was never written. Fixed by capturing currently_active before any writes, then incrementing only when !currently_active (new grant or re-grant after expiry). An expiry update on a live role does not increment to avoid double-counting. 3. Premature storage removal in expire_role caused count decrement to be skipped expire_role removed HasRole and RoleExpiry directly before delegating to deactivate_role_grant. Because deactivate_role_grant calls has_role_internal to decide whether to decrement the count, those early removes made it always see the role as inactive and skip the decrement. Removed the redundant removes so deactivate_role_grant is the single cleanup path for both expire_role and revoke_role. Added test_role_valid_at_exact_expiry_timestamp_expired_one_second_after to pin the new boundary semantics: role is valid when current == expires_at, expired only when current > expires_at. All 50 router-access tests pass.
1 parent 8fb26a3 commit 5aff485
1 file changed
Lines changed: 56 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
140 | 146 | | |
141 | 147 | | |
142 | 148 | | |
| |||
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
150 | | - | |
| 156 | + | |
151 | 157 | | |
152 | 158 | | |
153 | 159 | | |
| |||
561 | 567 | | |
562 | 568 | | |
563 | 569 | | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | 570 | | |
571 | 571 | | |
572 | 572 | | |
| |||
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
736 | | - | |
| 736 | + | |
| 737 | + | |
737 | 738 | | |
738 | 739 | | |
739 | 740 | | |
| |||
770 | 771 | | |
771 | 772 | | |
772 | 773 | | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
773 | 790 | | |
774 | 791 | | |
775 | 792 | | |
| |||
885 | 902 | | |
886 | 903 | | |
887 | 904 | | |
888 | | - | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
889 | 909 | | |
890 | 910 | | |
891 | 911 | | |
892 | 912 | | |
893 | 913 | | |
894 | 914 | | |
895 | | - | |
| 915 | + | |
896 | 916 | | |
897 | 917 | | |
898 | 918 | | |
| |||
950 | 970 | | |
951 | 971 | | |
952 | 972 | | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
953 | 999 | | |
954 | 1000 | | |
955 | 1001 | | |
| |||
0 commit comments