bsc icon indicating copy to clipboard operation
bsc copied to clipboard

Fast node returns wrong state siliently

Open wtdcode opened this issue 1 year ago • 1 comments

System information

Geth version: geth_linux version 1.3.9-5e74ea65-20240220 OS & Version: Linux

Command line:

             --syncmode full --datadir /work/data --cache 8000 --rpc.allow-unprotected-txs
             --history.transactions 0
             --ws --ws.addr 0.0.0.0 --ws.api net,web3,eth --ws.port 8556 --ws.origins *
             --http --http.addr 0.0.0.0
             --http.api net,web3,eth
             --http.port 8555
             --http.vhosts *
             --db.engine=pebble
             --verbosity 4
             --tries-verify-mode=none

Expected behaviour

Return missing trie root or some other error.

Actual behaviour

Return 0

Steps to reproduce the behaviour

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:8555
{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000002704c6f721947"}

After 0x237f199 falls 128 blocks behind, executing the same 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:8555
{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000000"}

The state silently changes. I would expect something like missing trie node

wtdcode avatar Mar 23 '24 12:03 wtdcode

noted, thank you for your feedback, we will fix it.

zzzckck avatar Mar 25 '24 05:03 zzzckck

The reason why 0x00...00 is returned is that the snap layer specified has expired (i.e. after 128 blocks), so the program will read from an empty trie since it's a fast node. Attempting to retrieve a value from an empty trie will return 0x00...00 by default instead of an error.

So the state doesn't change, it's just that the specified snap layer is missing.

weiihann avatar Apr 02 '24 06:04 weiihann

The reason why 0x00...00 is returned is that the snap layer specified has expired (i.e. after 128 blocks), so the program will read from an empty trie since it's a fast node. Attempting to retrieve a value from an empty trie will return 0x00...00 by default instead of an error.

So the state doesn't change, it's just that the specified snap layer is missing.

Is it ok to return error for accessing missed layer? instead of return 0x00...00

zzzckck avatar Apr 02 '24 11:04 zzzckck

I think it's possible to add a check at the API layer, rather than modifying the database layer. Let me quickly prepare a draft PR.

weiihann avatar Apr 03 '24 02:04 weiihann