-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Summary
Use the eth_getTransactionBySenderAndNonce RPC method to efficiently fetch sent transactions, significantly reducing RPC calls and improving transaction search performance.
Scope: Ethereum mainnet only (initial implementation)
Motivation
The current binary search algorithm for finding address transactions requires many RPC calls (~50+) to discover transaction history. The eth_getTransactionBySenderAndNonce method allows direct lookup of transactions by sender address and nonce, which can reduce this to just a few calls for sent transactions.
This method is supported by reth clients and several public RPC providers:
- SubQuery:
https://ethereum.rpc.subquery.network/public - Sentio:
https://rpc.sentio.xyz/mainnet - Lava:
https://eth1.lava.build - Nodies:
https://ethereum-public.nodies.app
Reference
Ethereum Execution APIs discussion: ethereum/execution-apis#494
Proposed Solution
Phase 1: Fast Sent Transaction Lookup
- Get the current nonce of the address
- Use
eth_getTransactionBySenderAndNonceto fetch the last N sent transactions directly by nonce - Call:
eth_getTransactionBySenderAndNonce(address, nonce)for each nonce
Phase 2: Optimized Received/Internal Search
- Use the block numbers from sent transactions to define search ranges
- Search for received/internal transactions only in the gaps between sent transactions
- This avoids searching the entire blockchain history
Implementation Details
- Ethereum mainnet only - other networks can be added later as RPC support grows
- Create a dedicated RPC client with the supporting providers using race strategy (call all, use fastest response)
- Run independently of user-configured RPCs (hardcoded providers for this feature)
- Graceful fallback to regular binary search if the method fails
Example
For an address with nonce 51:
- Current approach: ~50+ RPC calls with binary search
- Optimized approach:
- 5 calls to get last 5 sent txs via nonce lookup
- Binary search only for received/internal in specific block ranges
Alternatives Considered
- Relying solely on binary search (current implementation) - works but slow
- Using indexer APIs - breaks trustless/self-hosted nature of OpenScan
Additional Context
The eth_getTransactionBySenderAndNonce method is a non-standard RPC method but is gaining adoption. It's particularly useful for block explorers that need to efficiently retrieve transaction history without relying on centralized indexers.
This method is implemented in reth and exposed by several RPC providers.
Acceptance Criteria
- Create dedicated client for sender-nonce lookups with race strategy
- Implement
fetchSentTransactionsByNonce()method - Modify
searchAddressActivityOptimized()to use nonce-based lookup for sent txs - Search received/internal txs in block ranges between sent transactions
- Enable on Ethereum mainnet only
- Graceful fallback if method is unavailable
- Add tests for the new functionality