kwilteam / kwil-db

Kwil DB, the database for web3
https://www.kwil.com/
Other
36 stars 12 forks source link

server,cometbft: ensure app height < chain height #1066

Open jchappelow opened 1 month ago

jchappelow commented 1 month ago

This adds a check in the node's db provider constructor to ensure app height is less than node blockstore height.

We already had this:

Error: panic while building kwild: state.AppHash does not match AppHash after replay. Got
72287A9265100116BF4564B601389D5AF0ACC6CC6068D215579F5798C058ED71, expected .

State: {{{11 1} 0.38.12} prod-chain 1 0 :0:000000000000 2024-10-14 16:12:11.499512 +0000 UTC ValidatorSet{
  Proposer: Validator{9A34D1C8EB16B73D598C2D9823C3BAC25B82E200 PubKeyEd25519{58E3FF8608521626FEA099EE08EF7EF81C2CF57A0848D8EA67B544E4797B3E06} VP:1 A:0}
  Validators:
    Validator{5959A864439F1B470F12AC69A6E5B592E07DD794 PubKeyEd25519{3A026BD5CF4A64EE8510B9012C652BD9CCC2B07505C3D442EFEAF126F8549BDE} VP:1 A:0}
    Validator{9A34D1C8EB16B73D598C2D9823C3BAC25B82E200 PubKeyEd25519{58E3FF8608521626FEA099EE08EF7EF81C2CF57A0848D8EA67B544E4797B3E06} VP:1 A:0}
} ValidatorSet{
  Proposer: Validator{5959A864439F1B470F12AC69A6E5B592E07DD794 PubKeyEd25519{3A026BD5CF4A64EE8510B9012C652BD9CCC2B07505C3D442EFEAF126F8549BDE} VP:1 A:-1}
  Validators:
    Validator{5959A864439F1B470F12AC69A6E5B592E07DD794 PubKeyEd25519{3A026BD5CF4A64EE8510B9012C652BD9CCC2B07505C3D442EFEAF126F8549BDE} VP:1 A:-1}
    Validator{9A34D1C8EB16B73D598C2D9823C3BAC25B82E200 PubKeyEd25519{58E3FF8608521626FEA099EE08EF7EF81C2CF57A0848D8EA67B544E4797B3E06} VP:1 A:1}
} ValidatorSet{
  Proposer: nil-Validator
  Validators:

} 1 {{6291456 -1} {100000 48h0m0s 1048576} {[ed25519]} {1} {0}} 1 [] []}

Did you reset CometBFT without resetting your application's data?

But it's extremely confusing. So, rather than wait for cometbft to begin replaying blocks, which is when it finds out about the invalid application state, we can give a clearer error with a possible resolution:

Error: panic while building kwild: failed to build comet node: failed to create CometBFT node: application (postgresql) height is past blockchain database -- drop postgresql to proceed.

However, this was a quick fix, and I want to reconsider this. Open to suggestions for a better resolution.

charithabandi commented 1 month ago

Looks reasonable to me.