Skip to content

core: stateDb has no trie and no snap return err#2369

Merged
zzzckck merged 1 commit intobnb-chain:developfrom
weiihann:develop/rpc-state
Apr 7, 2024
Merged

core: stateDb has no trie and no snap return err#2369
zzzckck merged 1 commit intobnb-chain:developfrom
weiihann:develop/rpc-state

Conversation

@weiihann
Copy link
Copy Markdown
Contributor

@weiihann weiihann commented Apr 3, 2024

Description

This PR adds a check to Blockchain.StateAt() such that if the node is a fast node (i.e. NoTrie = true) and the snap layer cannot be found, then it will return an error.

Rationale

Refer to #2331.

By default, a fast node will have an empty trie for any state. Retrieving a value from an empty trie will give 0x00...00. It may be confusing for users as 0x00...00 could also be the actual value. Hence, it's more useful to throw an error when the state is not available.

Example

Command

curl -H 'Content-Type: application/json'  -X POST --data '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0x00020F14443e103A0B72F1f2DFDaac07DDAa6Df5", "0x0", "0x237f199"], "id": 1}' http://127.0.0.1:8545

Output

{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"state is not available"}}

Changes

  • Add StateDB.GetSnap()

Copy link
Copy Markdown
Contributor

@flywukong flywukong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zzzckck zzzckck merged commit 48f58a5 into bnb-chain:develop Apr 7, 2024
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.

4 participants