kaiachain / kaia

GNU Lesser General Public License v3.0
21 stars 26 forks source link

Missing consensus modules when creating snapshot at node startup #138

Closed hyeonLewis closed 1 day ago

hyeonLewis commented 2 days ago

Describe the bug When restarting the node, the incorrectly regenerated historical state error occurs because it can't handle any reward logic in consensusModule.FinalizeHeader. Currently, the mReward module is registered after preloading staking info in backend.

How to reproduce

  1. Build node after commit 53979ad
  2. Restart the node built in (1)

Expected behavior The mReward module is loaded in consensus module before creating snapshot, so it correctly restores the state root when processing a block.

Attachments

INFO[11/24,10:54:05 +09] [41|node/cn/backend.go:383]                    Start creating istanbul snapshot
ERROR[11/24,10:54:05 +09] [44|reward/staking_manager.go:332]             incorrectly regenerated historical state  block=1 err="mistmatching state root block expected 6fcca4458b333665ce798cfb99650dc55e832c2b16366e264ac05a97a8b865f6 reexecuted 908319dab4e35d4e78211155528a66d4084536cd3a86a260e91e257029ec571a"
ERROR[11/24,10:54:05 +09] [41|node/cn/backend.go:402]                    Preload staking info failed               err="incorrectly regenerated historical state for block 1: mistmatching state root block expected 6fcca4458b333665ce798cfb99650dc55e832c2b16366e264ac05a97a8b865f6 reexecuted 908319dab4e35d4e78211155528a66d4084536cd3a86a260e91e257029ec571a"
INFO[11/24,10:54:05 +09] [41|node/cn/backend.go:413]                    Finished creating istanbul snapshot
> kaia.getBlock(0).stateRoot
"0x908319dab4e35d4e78211155528a66d4084536cd3a86a260e91e257029ec571a"
> kaia.getBlock(1).stateRoot
"0x6fcca4458b333665ce798cfb99650dc55e832c2b16366e264ac05a97a8b865f6"

Environment (please complete the following information)

go version go1.22.6 darwin/arm64
Kaia v1.0.3+53979ad99f // or above

Additional context It seems we can't temporarily set the consensus module since it's append-only unlike staking module. We can introduce either:

  1. Set mReward before creating snapshot and comment this in SetupKaiaxModules
  2. Move https://github.com/kaiachain/kaia/blob/dev/node/cn/backend.go#L421-L455 before creating snapshot
blukat29 commented 2 days ago

I'd prefer option 1, then remove the whole preload facility after we bring in the kaiax/valset. That's why I did https://github.com/kaiachain/kaia/commit/ca45d2a175113bcb7613a65a4c0618c7ed1db008.

hyeonLewis commented 2 days ago

@blukat29 Yes, then does that mean we can ignore this issue since it is in dev branch an will be resolved before next release?

blukat29 commented 2 days ago

@hyeonLewis No, could you fix it on the dev branch with a PR independent of valset? valset should take some time. It is totally fine to make a temporary UnregisterConsensusModule or something.

hyeonLewis commented 2 days ago

Sure, I'll fix it. Thanks.