fix: backward compat for pre-contract_flags serialization#165
Merged
bennyhodl merged 3 commits intoJun 27, 2026
Merged
Conversation
Replace macro-generated Readable impls with manual ones that detect old format (no protocol_version/contract_flags) vs new format. OfferDlc: peek first 4 bytes as u32 - if 1-10 it's protocol_version (new format), otherwise it's contract_flags+chain_hash (old format). OfferedContract: peek byte after refund_locktime - if 0x02/0x03 it's a pubkey prefix (old format, no contract_flags), if 0x00/0x01 it's contract_flags (new format).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds backward compatibility so contracts stored before the
contract_flagsPR (#157) can still be deserialized. Without this, upgrading to v1.1.0 breaks reading any existing contracts from the database.Changes
dlc-messages/src/lib.rs— Replaceimpl_dlc_writeable!macro forOfferDlcwith manualWriteable/Readableimpls. TheReadableimpl peeks 4 bytes after the type: if the value is 1–10, it'sprotocol_version(new format); otherwise it'scontract_flags+ chain_hash start (old format, defaultsprotocol_versionto 1). Serialize always writes new format.ddk-manager/src/contract/ser.rs— Same treatment forOfferedContract. Peeks 1 byte afterrefund_locktime:0x02/0x03means old format (compressed pubkey prefix = start ofcounter_party, nocontract_flagsfield),0x00/0x01means new format (contract_flagsvalue).ddk/src/storage/sled/contract.rs— Adds tests deserializing both old-format (testconfig/contract_binaries/old/Offered) and new-format (testconfig/contract_binaries/Offered) binaries to verify backward compat.Context
After upgrading dlcd-rs to ddk 1.1.0, existing contracts in postgres (stored as serialized byte blobs) fail to deserialize with
StorageError("Nonsense bytes")because the newReadableimpl expectsprotocol_version(4 bytes) andcontract_flags(1 byte) that don't exist in old data.