Skip to content

Persist wallet records in a versioned Platform-owned format, not raw serde #5713

Open

Description

@xdustinface

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 Option or 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 Serialize or FromStr, for example how an Address string 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 tb prefix that Address::from_str rejects, so those records could never be read back. fix(key-wallet): load unparsable sent addresses as None rust-dashcore#1280 works around this one case by loading unparsable Sent/Unspendable addresses as None.

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 _blob column 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:
    • Transaction and InstantLock as consensus-encoded bytes
    • addresses as script bytes (decode_script_to_address in blob.rs already does the reverse)
    • hashes and outpoints as raw bytes
    • enums such as TransactionDirection, OutputRole or 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/TryFrom conversions 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 only TransactionRecord.
  • Keep persisted_core_transactions.rs and 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 TransactionRecord so a layout break is caught before merge rather than after the pin bump.

Acceptance criteria

  • No _blob column encodes a rust-dashcore type through bincode::serde.
  • Every blob carries a format version.
  • Existing wallets load after the migration, verified against the current golden fixtures.
  • Adding a field to TransactionRecord upstream fails to compile in Platform's conversion code, and no stored wallet becomes unreadable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions