Skip to content

Conversation

quantumshiro
Copy link

@quantumshiro quantumshiro commented Sep 11, 2025

i fixed #32566

  • Rationale:
    - Repeated calls to debug_getStorageAt for local simulations incur RPC round-trip overhead.
    - This PR adds batch variants to fetch multiple storage slots in one request, reducing latency and overhead.
    - This PR adds batch variants to fetch multiple storage slots in one request, reducing latency and overhead.

  • New RPC Methods:
    - debug_batchGetStorageAt
    - Params: [address, [hexKey, ...], blockNrOrHash]
    - Returns: []hexbytes in the same order as input keys.

  • debug_batchGetStorage
    - Params: [{ address: [hexKey, ...], ... }, blockNrOrHash]
    - Returns: { address: []hexbytes } with per-address order preserved.

  • Implementation:
    - Location: internal/ethapi/api.go in DebugAPI.
    - Uses api.b.StateAndHeaderByNumberOrHash and state.GetState.
    - Key parsing via existing decodeHash.
    - Errors:
    - Invalid key format returns an error (whole request fails for minimal implementation).
    - Final state.Error() propagated.

  • Example Usage:
    - Single address:
    - {"jsonrpc":"2.0","id":1,"method":"debug_batchGetStorageAt","params":["0xabc...",[ "0x0", "0x1" ],"latest"]}
    - Result: ["0x...32B","0x...32B"]

  • Multiple addresses:
    - {"jsonrpc":"2.0","id":2,"method":"debug_batchGetStorage","params":[{"0xabc...":["0x0","0x1"],"0xdef...": ["0x2"]},"latest"]}
    - Result: {"0xabc...":["0x...","0x..."],"0xdef...":["0x..."]}

  • Validation:
    - Built geth and verified RPC exposure with --dev --http.
    - Sample curl:
    - debug_batchGetStorageAt: curl -s -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":1,"method":"debug_batchGetStorageAt","params":["0x000...000",[ "0x0", "0x1" ],"latest"]}' http://127.0.0.1:18545
    - debug_batchGetStorage: curl -s -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":2,"method":"debug_batchGetStorage","params":[{"0x000...000":["0x0","0x1"]},"latest"]}' http://127.0.0.1:18545

@s1na
Copy link
Contributor

s1na commented Sep 11, 2025

Yeah I think only one of them suffices. Let's keep batchGetStorage since it's more general. I think it would be useful to query storage of multiple contracts.

Also please add some tests, I have a feeling it's vibe coded :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Batch getStorageAt RPC method
2 participants