add: add batch storage RPC methods #32591
Open
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.
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