mintlayer-core icon indicating copy to clipboard operation
mintlayer-core copied to clipboard

Provide an error when decoding fails due to database schema changes, instead of crashing

Open TheQuantumPhysicist opened this issue 2 years ago • 1 comments

Currently, changing the database schema (both in the wallet and blockchain) lead to a crash if the database is used after versioning (assuming versioning wasn't done properly):

thread 'tokio-runtime-worker' panicked at 'assertion failed: T::decode_all(&mut this.bytes()).is_ok()', serialization/src/encoded.rs:44:9

This is because of this assert: https://github.com/mintlayer/mintlayer-core/blob/3d0fd11adaaacf770f7090076d8b413e8ae58005/serialization/src/encoded.rs#L44

Two things have to be done:

  1. This function must be marked unsafe, because it shouldn't be used under normal circumstances, and the risk must be understood (and documented).
  2. There should be a variant that returns an error for this function. This is because we need to be able to display an error when decoding fails.

Note: Despite this error having a Testnet milestone, it can be done a little later because we assume we'll handle versioning properly.

TheQuantumPhysicist avatar Jul 17 '23 12:07 TheQuantumPhysicist

While a friendlier error message could be provided, I would consider this to be a part of the larger task of introducing a mechanism for database schema upgrades.

iljakuklic avatar Jul 18 '23 11:07 iljakuklic