mintlayer-core
mintlayer-core copied to clipboard
Provide an error when decoding fails due to database schema changes, instead of crashing
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:
- This function must be marked unsafe, because it shouldn't be used under normal circumstances, and the risk must be understood (and documented).
- 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.
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.