namada icon indicating copy to clipboard operation
namada copied to clipboard

Persisted db hashes may not match persisted data

Open batconjurer opened this issue 1 year ago • 6 comments

The app root hash field is stored along with all data to disk. On restart, the hash field is read but not checked against the data that has been reloaded. It is possible that flushing to disk can be interrupted and thus the correct hash is persisted but not all the data is written. Thus on start up, the ledger starts to make progress (since it has the correct app hash), but will result in state divergence one block later.

To fix

  • Try to make db flushed more atomic (likely not a foolproof solution)
  • Recompute the hash of the backing data and check it against the persisted hash on startup.

batconjurer avatar Jul 12 '23 11:07 batconjurer

Can you provide the relevant lines and files in the code where it reads the hash?

bengtlofgren avatar Jul 13 '23 09:07 bengtlofgren

https://github.com/anoma/namada/blob/4bc441e938eb7be84824deacb12d79e07c780de4/apps/src/lib/node/ledger/shell/mod.rs#L573

batconjurer avatar Jul 13 '23 09:07 batconjurer

If you chase that function down, it leads here: https://github.com/anoma/namada/blob/4bc441e938eb7be84824deacb12d79e07c780de4/core/src/ledger/storage/merkle_tree.rs#L395

batconjurer avatar Jul 13 '23 09:07 batconjurer

@batconjurer Is this issue still applicable?

cwgoes avatar Feb 05 '24 09:02 cwgoes

Oh wow, haven't thought about this in a while. I'll need to dig back into it

batconjurer avatar Feb 05 '24 09:02 batconjurer

Yes, this is still relevant @cwgoes

batconjurer avatar Feb 05 '24 09:02 batconjurer