ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.26k stars 20.01k forks source link

`debug_setHead` not working #30251

Closed stwiname closed 1 month ago

stwiname commented 1 month ago

System information

Geth version: 1.14.5 CL client & version: e.g. lighthouse OS & Version: Linux Commit hash : https://github.com/ethereum/go-ethereum/commit/0dd173a727dd2d2409b8e401b22e85d20c25b71f

Expected behaviour

debug_setHead should rewind to the specified head

Actual behaviour

Rewinds to the genesis block

Steps to reproduce the behaviour

  1. Start a node with --sepolia --syncmode "full" (all other options can be default)
  2. Sync up to some block (~1.8m as ive tested for sepolia)
  3. Call debug_setHead via JSON-RPC and set to any block the is within the ancients range (e.g 1m)
  4. Let task run, it can take some time. It will sync back to block 0 and then stop.

Backtrace

The start of this is truncated there are a lot of logs repeating and working down block by block.

Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:02.231] Zero state root hash!
Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:02.347] Rewound to block with state              number=1,778,496 hash=0a022c..d54055
Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:02.633] Zero state root hash!
Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:02.753] Rewound to block with state              number=1,778,495 hash=5b9bd5..eb5712
Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:02.874] Zero state root hash!
Jul 29 02:54:02 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:02.996] Rewound to block with state              number=1,778,494 hash=ae6a91..b31620
Jul 29 02:54:03 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:03.112] Zero state root hash!
Jul 29 02:54:03 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:03.242] Rewound to block with state              number=1,778,493 hash=dfb8ab..06c6e2
Jul 29 02:54:03 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:03.377] Zero state root hash!
Jul 29 02:54:03 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:03.710] Rewound to block with state              number=1,778,492 hash=377e09..cb80db
Jul 29 02:54:03 ethereum run_geth_3.sh[390618]: ERROR[07-29|02:54:03.829] Zero state root hash!
Jul 29 02:54:11 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:11.829] Path: Block state missing, rewinding further number=1,655,443 hash=3bee39..36d952 elapsed=8.000s
Jul 29 02:54:19 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:19.829] Path: Block state missing, rewinding further number=1,529,263 hash=aa70a2..3d7431 elapsed=16.000s
Jul 29 02:54:27 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:27.829] Path: Block state missing, rewinding further number=1,397,802 hash=c4fd05..787b4d elapsed=24.000s
Jul 29 02:54:35 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:35.830] Path: Block state missing, rewinding further number=1,265,488 hash=cb52c2..abb443 elapsed=32.000s
Jul 29 02:54:43 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:43.830] Path: Block state missing, rewinding further number=1,136,586 hash=c66d9f..50c676 elapsed=40.000s
Jul 29 02:54:51 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:51.830] Path: Block state missing, rewinding further number=1,006,685 hash=7fd6ee..e2e483 elapsed=48.000s
Jul 29 02:54:59 ethereum run_geth_3.sh[390618]: INFO [07-29|02:54:59.830] Path: Block state missing, rewinding further number=878,461   hash=477bde..a5d494 elapsed=56.000s
Jul 29 02:55:07 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:07.830] Path: Block state missing, rewinding further number=750,733   hash=c54cb2..1294a4 elapsed=1m4.000s
Jul 29 02:55:15 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:15.830] Path: Block state missing, rewinding further number=624,135   hash=fe7f81..8d1b26 elapsed=1m12.000s
Jul 29 02:55:23 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:23.830] Path: Block state missing, rewinding further number=493,327   hash=c3c507..0752ea elapsed=1m20.000s
Jul 29 02:55:31 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:31.830] Path: Block state missing, rewinding further number=364,530   hash=ae4e64..13f1bc elapsed=1m28.000s
Jul 29 02:55:39 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:39.830] Path: Block state missing, rewinding further number=234,714   hash=168505..70a54f elapsed=1m36.000s
Jul 29 02:55:47 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:47.830] Path: Block state missing, rewinding further number=102,213   hash=3f3b86..5914d4 elapsed=1m44.000s
Jul 29 02:55:54 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:54.112] Genesis block reached                    number=0         hash=25a5cc..3e6dd9
Jul 29 02:55:54 ethereum run_geth_3.sh[390618]: INFO [07-29|02:55:54.113] Chain is stateless, wait state sync      number=0         hash=25a5cc..3e6dd9
Jul 29 02:55:54 ethereum run_geth_3.sh[390618]: WARN [07-29|02:55:54.120] Force rewinding till ancient limit       head=0
rjl493456442 commented 1 month ago

Geth will only reserve the latest 90K state histories by default, namely only the blocks in range of [HEAD-90K, HEAD] are suitable for rollback;

Besides, are you sure you are using 1.14.5? Path: Block state missing, rewinding further number it's not the log emitted by Geth btw (no Path prefix)

stwiname commented 1 month ago

So in order to roll back more than 90k blocks it would need to be an archive node (or configure the threshold)? Out of curiosity would it be possible to use the downloader to get a state snapshot around the desired height?

Path: was added in by me to try and understand what was going on a little further.

rjl493456442 commented 1 month ago

So in order to roll back more than 90k blocks it would need to be an archive node (or configure the threshold)?

Yes, you can specify the amount of state histories to be reserved by --history.state

Out of curiosity would it be possible to use the downloader to get a state snapshot around the desired height?

Unfortunately it's impossible. The state in network is forwarding dynamically, downloader will only pick the available state as the sync target and switch the pivot point regularly.