Skip to content

[FEATURE]: Improve the lookup time for duplicates and Nonce conflicts in mempool.py #135

Description

@shantanushok

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions