Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Json RPC] Catch Trie exception on eth_getStorage call #7878

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brbrr
Copy link
Contributor

@brbrr brbrr commented Dec 9, 2024

When trying to get a missing storage via RPC call, we not handling the missing node well, so we end up returning exception trace into the RPC response. example call & response:

curl 172.234.253.190:8545 \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc": "2.0", "method": "eth_getStorageAt", "params": ["0x4d9079bb4165aeb4084c526a32695dcfd2f77381", "0x0000000000000000000000000000000000000000000000000000000000000002", "0xda7485"], "id": 662251708906005292}'

Response:

{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal error","data":"Nethermind.Trie.MissingTrieNodeException: Node 0x7624432bf4159f20277937ee01260167ef485023da8e2814c7e5b6dd2665346f is missing from the DB\n ---> Nethermind.Trie.TrieNodeException: Failed to load root hash 0x7624432bf4159f20277937ee01260167ef485023da8e2814c7e5b6dd2665346f while loading key d2313780e872947b0af5192f9f8a83047a495d8fba883ae44701b43000eb1a32.\nNode 0x7624432bf4159f20277937ee01260167ef485023da8e2814c7e5b6dd2665346f is missing from the DB\n   at Nethermind.Trie.Pruning.ReadOnlyTrieStore.ScopedReadOnlyTrieStore.Nethermind.Trie.Pruning.ITrieNodeResolver.LoadRlp(TreePath& path, Hash256 hash, ReadFlags flags)\n   at Nethermind.Trie.PatriciaTree.ResolveNode(TrieNode node, TraverseContext& traverseContext, TreePath& path) in /src/Nethermind/Nethermind.Trie/PatriciaTree.cs:line 571\n   --- End of inner exception stack trace ---\n   at Nethermind.Trie.PatriciaTree.ResolveNode(TrieNode node, TraverseContext& traverseContext, TreePath& path) in /src/Nethermind/Nethermind.Trie/PatriciaTree.cs:line 579\n   at Nethermind.Trie.PatriciaTree.Get(ReadOnlySpan`1 rawKey, Hash256 rootHash) in /src/Nethermind/Nethermind.Trie/PatriciaTree.cs:line 333\n   at Nethermind.State.StateReader.TryGetState(Hash256 stateRoot, Address address, AccountStruct& account) in /src/Nethermind/Nethermind.State/StateReader.cs:line 70\n   at Nethermind.State.StateReader.GetStorage(Hash256 stateRoot, Address address, UInt256& index) in /src/Nethermind/Nethermind.State/StateReader.cs:line 27\n   at Nethermind.State.StateReader.Nethermind.State.IStateReader.GetStorage(Hash256 stateRoot, Address address, UInt256& index)\n   at Nethermind.JsonRpc.Modules.Eth.EthRpcModule.eth_getStorageAt(Address address, UInt256 positionIndex, BlockParameter blockParameter) in /src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs:line 181\n   at InvokeStub_IEthRpcModule.eth_getStorageAt(Object, Object, Object, Object, Object)\n   at System.Reflection.MethodInvoker.InvokeImpl(Object obj, Object arg1, Object arg2, Object arg3, Object arg4)\n   at System.Reflection.MethodInvoker.Invoke(Object obj, Span`1 arguments)\n   at Nethermind.JsonRpc.JsonRpcService.ExecuteAsync(JsonRpcRequest request, String methodName, ResolvedMethodInfo method, JsonRpcContext context) in /src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs:line 175"},"id":662251708906005292}

I went for a most obvious solution, although not sure if it's the best one.

I've updated the response to match geth implementation (with wrong-ish error code):

{
    "jsonrpc": "2.0",
    "error": {
        "code": -32000,
        "message": "missing trie node 0x7624432bf4159f20277937ee01260167ef485023da8e2814c7e5b6dd2665346f (path ) state 0x7624432bf4159f20277937ee01260167ef485023da8e2814c7e5b6dd2665346f is not available"
    },
    "id": 662251708906005292
}

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Optional. Remove if not applicable.

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

If yes, fill in the details here. Remove if not applicable.

Remarks

Optional. Remove if not applicable.

@brbrr brbrr requested review from ak88 and LukaszRozmej December 9, 2024 07:32
@brbrr brbrr self-assigned this Dec 9, 2024
@brbrr brbrr requested a review from flcl42 December 9, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants