StabilityNexus / StabilityNexus/MiniChain
[FEATURE]: Improve the lookup time for duplicates and Nonce conflicts in mempool.py
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Feature and its Use Cases
Area of improvement :
Every call to add_transaction() iterates the entire _list to detect duplicate transactions and nonce conflicts. The current version of add_transaction() utilizes a loop serves two purposes :
1] Duplicate / RBF detection - find an existing tx with the same (sender, nonce).
2] Nonce-ordering window - compute i_min / i_max so the new tx is inserted in the right position relative to other nonces from the same sender.
Proposed Fix : Both can be answered in sub-linear time with a side index.
Add a dict keyed by (sender, nonce) maintained alongside _list:
self._index: dict[tuple, object] = {}
The index is kept in sync in three places:
insert (self._index[key] = tx)
replace / RBF (del self._index[key] before removing from list, then re-add)
eviction (self._index.pop(key, None) inside remove_transactions)
Additional Context
No response
Code of Conduct
- I have joined the Discord server and will post updates there
- I have searched existing issues to avoid duplicates
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mempool.py by reading add_transaction() and remove_transactions(), focusing on the _list scan, duplicate/RBF handling, nonce ordering, and eviction paths. Add and maintain the proposed (sender, nonce) side index, then verify duplicate detection, replacement, nonce ordering, and eviction remain correct while lookup no longer scans the entire list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- blockchain
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100