Repository navigation
Description
Problem
rs-platform-wallet-storage writes rust-dashcore types straight into SQLite _blob columns with bincode::serde. TransactionRecord and dashcore::InstantLock are registered in src/sqlite/schema/core_state.rs, dashcore::OutPoint in src/sqlite/schema/blob.rs, and AssetLockEntryWire in src/sqlite/schema/asset_locks.rs embeds a dashcore::Transaction through serde.
Bincode stores field values by position, with no field names, no per-struct lengths and no version tag. The blob.rs module docs confirm there is no per-blob revision tag. This makes the in-memory layout of these types, and of every type nested inside them across key-wallet and dash, the on-disk format of Platform wallets.
As a result, routine changes in rust-dashcore break existing wallets:
- adding a field, even an
Optionor one marked#[serde(default)] - removing or reordering fields
- inserting an enum variant before existing ones, which shifts every later variant's stored index
- changing a custom
SerializeorFromStr, for example how anAddressstring parses
None of these fail to compile and rust-dashcore CI stays green. The break surfaces at runtime: the load path decodes every core_transactions.record_blob with ?, so a single undecodable blob aborts the whole wallet load.
This has already happened twice:
- The Core v24 update changed consensus structures, and keeping old blobs decodable required hand-written serde instead of derives.
- Testnet and devnet witness addresses are stored as display strings with a
tbprefix thatAddress::from_strrejects, so those records could never be read back. fix(key-wallet): load unparsable sent addresses asNonerust-dashcore#1280 works around this one case by loading unparsableSent/Unspendableaddresses asNone.
tests/integration/persisted_core_transactions.rs guards against some of this with golden blobs, but it only runs when Platform bumps its rust-dashcore pin, after the breaking change has already merged upstream.
Raised in the review of dashpay/rust-dashcore#1280: dashpay/rust-dashcore#1280 (review)
Proposal
Platform owns its storage format and converts to and from rust-dashcore types at the storage boundary.
- Define Platform-owned wire structs for every
_blobcolumn that currently holds a rust-dashcore type, directly or nested. - Inside those structs, never encode a rust-dashcore type through serde. Use formats that are stable by definition:
TransactionandInstantLockas consensus-encoded bytes- addresses as script bytes (
decode_script_to_addressinblob.rsalready does the reverse) - hashes and outpoints as raw bytes
- enums such as
TransactionDirection,OutputRoleor the transaction context mapped to explicit Platform-owned discriminants
- Prefix each blob with a format version byte so later changes are migrated, not failed.
- Write explicit
From/TryFromconversions between the wire structs and the upstream types. An upstream field change then becomes a compile error in Platform, while blobs already on disk keep decoding.
Migration
Existing blobs have no version prefix and use the current serde layout. A refinery migration should decode them with the current types and rewrite them in the new format. That migration must ship while the pinned rust-dashcore still decodes the legacy layout. If that window is missed, the legacy layout needs a frozen copy of the old types to decode it.
Scope
- Audit every
impl_persistable_blob!type for embedded rust-dashcore types, not onlyTransactionRecord. - Keep
persisted_core_transactions.rsand extend it to cover the legacy-to-new migration. - No changes are needed in rust-dashcore. Until this lands, rust-dashcore may add a golden-bytes regression test for
TransactionRecordso a layout break is caught before merge rather than after the pin bump.
Acceptance criteria
- No
_blobcolumn encodes a rust-dashcore type throughbincode::serde. - Every blob carries a format version.
- Existing wallets load after the migration, verified against the current golden fixtures.
- Adding a field to
TransactionRecordupstream fails to compile in Platform's conversion code, and no stored wallet becomes unreadable.
Activity