tip-1011: add periodAnchor for calendar-aligned period resets#2799
Draft
tip-1011: add periodAnchor for calendar-aligned period resets#2799
Conversation
- Add periodAnchor field to TokenLimit (0 = relative mode, nonzero = calendar-aligned) - Anchor-aware reset logic snaps periodEnd to next anchor-aligned boundary - Update RLP encoding (V3: 6-field TokenLimit), storage layout, hardfork gates - Add test cases for anchored resets and drift resistance Amp-Thread-ID: https://ampcode.com/threads/T-019c81da-3493-77b4-9a1c-6590dacb97e5 Co-authored-by: Amp <amp@ampcode.com>
820c403 to
e973477
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposal
Stacked on #2632. Adds
periodAnchortoTokenLimitfor calendar-aligned period resets.Problem
The current periodic limit reset is relative:
periodEndadvances from the last reset by whole multiples ofperiod. This prevents drift but doesn't guarantee alignment to calendar boundaries. A monthly limit that starts mid-March will always reset mid-month.This is insufficient for use cases that need deterministic calendar resets — e.g., daily limits that reset at midnight UTC, or monthly limits that reset on the 1st.
Solution
Add
periodAnchor(uint64) toTokenLimit. When nonzero, it's a fixed UTC timestamp thatperiodEndsnaps to:Reset logic with anchor:
A late transaction on day 3 of a monthly period still resets to the 1st of next month, not "now + 30 days."
periodAnchor = 0(default) preserves current relative behavior — fully backward compatible.Changes
periodAnchorfield onTokenLimitstructverifyAndUpdateSpendingpseudocodespending_limit_period_anchor[key][token]TokenLimit(V1/V2 decode withperiodAnchor=0)