feat(precompiles): unbounded buffer with cascading cleanup for expiring nonces#2157
Closed
feat(precompiles): unbounded buffer with cascading cleanup for expiring nonces#2157
Conversation
- Skip mark_invalid for expiring nonce txs (they're independent) - Fix remove_transactions_by_sender to remove expiring nonce txs - Fix senders_iter to include expiring nonce txs - Update assert_invariants to account for expiring nonce txs
Unfortunally pushed old [tip1000](#2116) branch to staging-revm so needed new branch --------- Co-authored-by: 0xKitsune <0xKitsune@protonmail.com>
…ng nonces This PR implements two improvements to the txhash replay protection buffer: 1. **Unbounded buffer with head/tail pointers**: Instead of a fixed-size circular buffer, use dynamically growing/shrinking storage. The tail pointer tracks where new entries are appended, while the head pointer tracks the oldest entry for cleanup. This removes the risk of running out of space. 2. **Cascading cleanup**: When writing a new entry, check expired entries at the head. If an entry is expired, check the next one too (up to MAX_CASCADE_CLEANUP=10). This allows the buffer to shrink quickly during low-traffic periods. Benefits: - No fixed capacity limit - buffer grows under high load - Space-efficient - buffer shrinks when entries expire - No 'buffer full' error condition Stacked on #2121
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
f389c7f to
d57af09
Compare
eb7e596 to
6da3734
Compare
a9138b6 to
1bcc84a
Compare
1bcc84a to
c77380f
Compare
Contributor
|
Great way to make it unbounded while keeping the invariants. Need to update TIP-1009 docs |
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.
Summary
This PR implements two improvements to the txhash replay protection buffer, as discussed in #2121:
1. Unbounded buffer with head/tail pointers
Instead of a fixed-size circular buffer with
EXPIRING_NONCE_SET_CAPACITY = 300,000, use dynamically growing/shrinking storage:Every write to the tail also checks the head and clears expired entries. Since we're not charging for fresh SSTOREs in the precompile anyway, growing the array has no gas cost disadvantage.
2. Cascading cleanup
When checking the head for expiry, if it's expired, also check the next entry. This cascades up to
MAX_CASCADE_CLEANUP = 10entries per write.This allows the buffer to shrink quickly during low-traffic periods.
Benefits
ExpiringNonceSetFullerror since buffer is unboundedChanges
crates/precompiles/src/nonce/mod.rs: Updated storage layout and algorithmcrates/contracts/src/precompiles/nonce.rs: RemovedExpiringNonceSetFullerrordocs/pages/protocol/tips/tip-1009.mdx: Updated documentationTesting
Added new tests:
test_expiring_nonce_cascading_cleanup: Verifies multiple entries are cleaned in one writetest_expiring_nonce_unbounded_growth: Verifies buffer can grow beyond old capacityStacked on #2121