Skip to content

define own Global, Input and Output structs - #116

Draft
yuval-block wants to merge 3 commits into
joinable-struct-liftfrom
own-psbt-structs
Draft

yuval-block wants to merge 3 commits into
joinable-struct-liftfrom
own-psbt-structs

Conversation

@yuval-block

@yuval-block yuval-block commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

This crate now owns its Global, Input, and Output types. Building on #121, joinable_struct! defines each source type, result type, conflict variants, and conversions from one field list, subsuming the temporary record_conflicts! macro.

  1. define own Global, Input and Output structs. joinable_struct! generates the plain struct alongside its result-domain counterpart, plus the From conversions from the psbt_v2 field lists. wrap becomes an inherent method, replacing GlobalExt, InputExt and OutputExt. Fields are private, with public getters and set_ setters by default. [accessors(pub(crate))] restricts accessor visibility when needed. Global drops the PSBT version and the input and output counts, which a conversion derives. OutputUniqueIdExt still reads and writes the unique ID.
  2. require a unique ID on every Output. UniqueId becomes a required, immutable field. Output::new sets it, and TryFrom reads it from PSBT_OUT_UNIQUE_ID, which must be 1 to 32 bytes. Proprietary fields are declared in the macro through ProprietaryField codecs.

closes #104, closes #89, supersedes #76

refs #83: building with psbt-v2/silent-payments no longer fails, but its fields are dropped until this crate has matching features.

Taproot key origins keep psbt-v2’s (Vec<TapLeafHash>, KeySource) representation and use structural equality for joins. Order, repetitions, and the key source must match; differing values remain conflicts.

🤖 Generated with Claude Code

@nothingmuch nothingmuch added this to the Semi-honest MVP milestone Nov 14, 2026
@nothingmuch
nothingmuch added this pull request to stack #117 November 14, 2026 08:07
@github-actions

Copy link
Copy Markdown
range-diff for force push 57013dcca3 → 19a23f490a November 14, 2026 09:01 UTC: 1 modified; 1 commit; same base 933eca83ff

reproduce: git range-diff 933eca8..57013dc 933eca8..19a23f4

1:  57013dcca3 +561 -220 4f ! 1:  19a23f490a +613 -224 4f define own Global, Input and Output structs
1: 57013dcca3 ! 1: 19a23f490a define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/global.rs
 +impl Global {
 +    /// Convert to a BIP 370 global map for a PSBT with `input_count` inputs
 +    /// and `output_count` outputs.
-+    #[allow(
++    #[expect(
 +        clippy::needless_update,
 +        reason = "psbt-v2's silent-payments feature adds fields this crate does not support yet"
 +    )]
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +}
 +
 +impl From<Input> for psbt_v2::v2::Input {
-+    #[allow(
++    #[expect(
 +        clippy::needless_update,
 +        reason = "keeps building if psbt-v2 adds fields this crate does not support yet"
 +    )]
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
  #[cfg_attr(coverage_nightly, coverage(off))]
  pub(crate) fn out_point(input: &Input) -> OutPoint {
      OutPoint {
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+             assert_eq!(fields, ALL_CONFLICT_FIELDS);
+         }
+ 
++        #[test]
++        fn v2_conversion_keeps_every_field() {
++            let mut input = make_input(1, 2);
++            input.sequence = Some(Sequence(3));
++            input.proprietaries.insert(
++                raw::ProprietaryKey {
++                    prefix: vec![1],
++                    subtype: 2,
++                    key: vec![],
++                },
++                vec![4],
++            );
++            let v2 = psbt_v2::v2::Input::from(input.clone());
++            assert_eq!(
++                (v2.previous_txid, v2.spent_output_index, v2.sequence),
++                (input.previous_txid, 2, Some(Sequence(3)))
++            );
++            assert_eq!(Input::from(v2), input);
++        }
++
+         #[test]
+         fn out_point_extraction() {
+             let op = out_point(&make_input(1, 42));
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
                  prop_assert!(wrapped.try_unwrap().is_ok());
              }
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +pub enum InvalidOutput {
 +    /// It has no `PSBT_OUT_UNIQUE_ID`.
 +    MissingUniqueId,
-+    /// Its `PSBT_OUT_UNIQUE_ID` is longer than [`UniqueId::MAX_LEN`] bytes.
-+    UniqueIdTooLong(InvalidUniqueId),
++    /// Its `PSBT_OUT_UNIQUE_ID` is empty or longer than [`UniqueId::MAX_LEN`]
++    /// bytes.
++    InvalidUniqueId(InvalidUniqueId),
 +}
 +
 +impl std::fmt::Display for InvalidOutput {
 +    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 +        match self {
 +            Self::MissingUniqueId => write!(f, "output missing PSBT_OUT_UNIQUE_ID"),
-+            Self::UniqueIdTooLong(error) => write!(f, "output {error}"),
++            Self::InvalidUniqueId(error) => write!(f, "output {error}"),
 +        }
 +    }
 +}
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +            .get(&unique_id_key())
 +            .ok_or(InvalidOutput::MissingUniqueId)?;
 +        let unique_id =
-+            UniqueId::try_from(bytes.clone()).map_err(InvalidOutput::UniqueIdTooLong)?;
++            UniqueId::try_from(bytes.clone()).map_err(InvalidOutput::InvalidUniqueId)?;
 +        Ok(Self::with_unique_id(output, unique_id))
 +    }
 +}
 +
 +/// Writes the unique ID to `PSBT_OUT_UNIQUE_ID`.
 +impl From<Output> for psbt_v2::v2::Output {
-+    #[allow(
++    #[expect(
 +        clippy::needless_update,
 +        reason = "psbt-v2's silent-payments feature adds fields this crate does not support yet"
 +    )]
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
  }
  
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
+ /// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Used as the map key in `OutputSet`
  /// so that outputs can be merged in an order-independent way.
  ///
- /// Built with [`TryFrom`], a unique ID is at most [`UniqueId::MAX_LEN`]
+-/// Built with [`TryFrom`], a unique ID is at most [`UniqueId::MAX_LEN`]
 -/// bytes long. One read from an output is not checked.
-+/// bytes long, as is one read from a BIP 370 output.
++/// Built with [`TryFrom`], a unique ID is 1 to [`UniqueId::MAX_LEN`] bytes
++/// long, as is one read from a BIP 370 output. An empty ID would make
++/// unrelated outputs join as one.
  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
  pub struct UniqueId(Vec<u8>);
  
+@@ crates/concurrent-psbt/src/psbt/output.rs: impl UniqueId {
+ 
+ impl crate::values::IdempotentValue for UniqueId {}
+ 
+-/// The bytes are too long for a [`UniqueId`]; they are returned unchanged.
++/// The bytes are empty or too long for a [`UniqueId`]; they are returned
++/// unchanged.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct InvalidUniqueId(pub Vec<u8>);
+ 
+@@ crates/concurrent-psbt/src/psbt/output.rs: impl TryFrom<Vec<u8>> for UniqueId {
+     type Error = InvalidUniqueId;
+ 
+     fn try_from(bytes: Vec<u8>) -> Result<Self, InvalidUniqueId> {
+-        if bytes.len() > Self::MAX_LEN {
++        if bytes.is_empty() || bytes.len() > Self::MAX_LEN {
+             return Err(InvalidUniqueId(bytes));
+         }
+         Ok(Self(bytes))
+@@ crates/concurrent-psbt/src/psbt/output.rs: impl std::fmt::Display for InvalidUniqueId {
+     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+         write!(
+             f,
+-            "unique ID is {} bytes, more than {}",
++            "unique ID is {} bytes, not 1 to {}",
+             self.0.len(),
+             UniqueId::MAX_LEN
+         )
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl std::error::Error for InvalidUniqueId {}
  
  pub const PSBT_OUT_UNIQUE_ID_SUBTYPE: u8 = 0x01;
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
          }
  
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+ 
+         proptest! {
+             #[test]
+-            fn unique_id_roundtrip(uid in proptest::collection::vec(0u8..=255, 1..=40)) {
++            fn unique_id_roundtrip(uid in proptest::collection::vec(0u8..=255, 0..=40)) {
+                 let Ok(id) = UniqueId::try_from(uid.clone()) else {
+-                    prop_assert!(uid.len() > UniqueId::MAX_LEN);
++                    prop_assert!(uid.is_empty() || uid.len() > UniqueId::MAX_LEN);
+                     let error = InvalidUniqueId(uid.clone());
+-                    prop_assert!(error.to_string().contains("more than 32"));
++                    prop_assert!(error.to_string().contains("not 1 to 32"));
+                     prop_assert_eq!(UniqueId::try_from(uid), Err(error));
+                     return Ok(());
                  };
                  prop_assert_eq!(&id, &UniqueId::new(uid.clone()));
                  prop_assert_eq!(id.as_bytes(), uid.as_slice());
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +                v2.set_unique_id(UniqueId::new(uid.clone()));
 +                match Output::try_from(v2.clone()) {
 +                    Ok(output) => {
-+                        prop_assert!(uid.len() <= UniqueId::MAX_LEN);
++                        prop_assert!((1..=UniqueId::MAX_LEN).contains(&uid.len()));
 +                        prop_assert_eq!(output.unique_id().as_bytes(), uid.as_slice());
 +                        prop_assert!(output.proprietaries.is_empty());
 +                        prop_assert_eq!(output.amount, Amount::from_sat(amount));
 +                        prop_assert_eq!(psbt_v2::v2::Output::from(output), v2);
 +                    }
 +                    Err(error) => {
-+                        prop_assert!(uid.len() > UniqueId::MAX_LEN);
++                        prop_assert!(uid.is_empty() || uid.len() > UniqueId::MAX_LEN);
 +                        prop_assert!(error.to_string().starts_with("output unique ID is"));
 +                        prop_assert_eq!(
 +                            error,
-+                            InvalidOutput::UniqueIdTooLong(InvalidUniqueId(uid))
++                            InvalidOutput::InvalidUniqueId(InvalidUniqueId(uid))
 +                        );
 +                    }
 +                }
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 -            let output = output_with_uid(&[1, 2, 3]);
 -            assert!(output.has_unique_id());
 -            assert_eq!(output.unique_id().unwrap().into_bytes(), vec![1, 2, 3]);
--        }
--
--        #[test]
--        fn unique_id_absent() {
--            let output = Output::default();
--            assert!(!output.has_unique_id());
--            assert!(output.unique_id().is_none());
 +            let v2 = psbt_v2::v2::Output::from(output(7));
 +            assert_eq!(v2.proprietaries.get(&key), Some(&vec![7]));
 +            let mut set = psbt_v2::v2::Output::default();
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +            );
          }
  
+         #[test]
+-        fn unique_id_absent() {
+-            let output = Output::default();
+-            assert!(!output.has_unique_id());
+-            assert!(output.unique_id().is_none());
++        fn unique_id_is_1_to_32_bytes() {
++            for len in [1, 32] {
++                let mut v2 = psbt_v2::v2::Output::default();
++                v2.set_unique_id(UniqueId::new(vec![0; len]));
++                let output = Output::try_from(v2).expect("a valid unique ID");
++                assert_eq!(output.unique_id(), &UniqueId::new(vec![0; len]));
++            }
++            for len in [0, 33] {
++                let error = UniqueId::try_from(vec![0; len]).unwrap_err();
++                assert_eq!(error, InvalidUniqueId(vec![0; len]));
++                assert_eq!(
++                    error.to_string(),
++                    format!("unique ID is {len} bytes, not 1 to 32")
++                );
++                let mut v2 = psbt_v2::v2::Output::default();
++                v2.set_unique_id(UniqueId::new(vec![0; len]));
++                let error = Output::try_from(v2).unwrap_err();
++                assert_eq!(
++                    error.to_string(),
++                    format!("output unique ID is {len} bytes, not 1 to 32")
++                );
++            }
+         }
+ 
          #[test]
 -        fn unique_id_construction_generation_and_setting() {
 -            let id = UniqueId::new(vec![1, 2, 3]);

@github-actions

Copy link
Copy Markdown
range-diff for force push 19a23f490a → 83c0bbb0a0 November 14, 2026 09:38 UTC: 1 modified; 1 commit; same base 933eca83ff

reproduce: git range-diff 933eca8..19a23f4 933eca8..83c0bbb

1:  19a23f490a +613 -224 4f ! 1:  83c0bbb0a0 +775 -317 8f define own Global, Input and Output structs
1: 19a23f490a ! 1: 83c0bbb0a0 define own Global, Input and Output structs
@@ Metadata
  ## Commit message ##
     define own Global, Input and Output structs
 
-    joinable_struct! now generates the plain struct alongside its
-    result-domain counterpart, so the PSBT maps are this crate's types
-    rather than psbt_v2's, converted with From and TryFrom at the boundary.
-    wrap becomes an inherent method, replacing the GlobalExt, InputExt and
-    OutputExt traits.
+    joinable_struct! generates both a plain struct and its result-domain
+    counterpart, so Global, Input and Output are this crate's types. From
+    and TryFrom convert them to and from the psbt_v2 types. wrap is an
+    inherent method, which replaces the GlobalExt, InputExt and OutputExt
+    traits.
 
-    Global drops the fields a conversion derives: the PSBT version and the
-    input and output counts.
+    Global has no PSBT version or input and output counts. Global::into_v2
+    takes the counts as arguments and sets the version to 2.
 
-    Output carries its UniqueId as a required field, set only by
-    Output::new or by converting a BIP 370 output that has
-    PSBT_OUT_UNIQUE_ID, replacing OutputUniqueIdExt.
+    UniqueId is now a required and immutable field of Output. Output::new
+    sets it, and TryFrom<psbt_v2::v2::Output> reads it from
+    PSBT_OUT_UNIQUE_ID. This replaces OutputUniqueIdExt.
 
-    closes #104, closes #89
+    tap_key_origins stores each key's leaf hashes as TapLeafHashes, whose
+    equality ignores order and repetition. This replaces the custom join on
+    (Vec<TapLeafHash>, KeySource).
+
+    closes #104, closes #89, closes #76
 
     Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
 
+ ## crates/concurrent-psbt/src/lib.rs ##
+@@ crates/concurrent-psbt/src/lib.rs: mod psbt;
+ 
+ pub use lattice::join::{Join, JoinMut};
+ pub use lattice::partial::{Conflict, JoinResult, PartialJoin};
++pub use psbt::TapLeafHashes;
+ pub use psbt::input;
+ pub use psbt::output;
+
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
      )
@@ crates/concurrent-psbt/src/psbt/global.rs
 +    /// The global fields of a PSBT.
      ///
 -    /// Produced by joining two [`Global`] values via [`GlobalExt::wrap`].
-+    /// Mirrors the BIP 370 global map, less the fields that converting to a
-+    /// [`psbt_v2::v2::Global`] derives: `PSBT_GLOBAL_VERSION` is always 2, and
-+    /// the input and output counts are those of the PSBT's inputs and outputs.
++    /// Mirrors the BIP 370 global map except `PSBT_GLOBAL_VERSION`, which is
++    /// always 2, and the input and output counts. [`Global::into_v2`] fills
++    /// those in.
 +    source: Global,
 +    /// Result-domain counterpart of [`Global`].
 +    ///
@@ crates/concurrent-psbt/src/psbt/global.rs
 +    }
 +}
 +
-+/// Drops the version and the input and output counts, which converting back
-+/// derives.
++/// Drops the version and the input and output counts.
 +impl From<psbt_v2::v2::Global> for Global {
 +    fn from(global: psbt_v2::v2::Global) -> Self {
 +        let psbt_v2::v2::Global {
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +use psbt_v2::PsbtSighashType;
  use psbt_v2::raw;
 -use psbt_v2::{PsbtSighashType, v2::Input};
++
++use super::tap_leaf_hashes::{TapLeafHashes, tap_key_origins_from_v2, tap_key_origins_into_v2};
  
  joinable_struct! {
 -    /// Result-domain representation of a PSBT input.
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
      source: Input,
 +    /// Result-domain counterpart of [`Input`].
 +    ///
-+    /// Each field is represented in the internal result domain, recording
-+    /// either a clean value or an accumulated conflict. Use [`Input::wrap`] to
-+    /// lift a clean [`Input`] into this type, and [`ResultInput::try_unwrap`]
-+    /// to recover the clean value once all conflicts are resolved.
++    /// Each field holds a clean value or a conflict. [`Input::wrap`] lifts an
++    /// [`Input`] into this type, and [`ResultInput::try_unwrap`] returns it if
++    /// no field conflicts.
      result: ResultInput,
 -    ext: InputExt,
      fields: {
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +        pub tap_key_sig: Option<taproot::Signature>,
 +        pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature>,
 +        pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)>,
 +        pub tap_internal_key: Option<XOnlyPublicKey>,
 +        pub tap_merkle_root: Option<TapNodeHash>,
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +            tap_key_sig,
 +            tap_script_sigs,
 +            tap_scripts,
-+            tap_key_origins,
++            tap_key_origins: tap_key_origins_from_v2(tap_key_origins),
 +            tap_internal_key,
 +            tap_merkle_root,
 +            proprietaries,
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +            tap_key_sig: input.tap_key_sig,
 +            tap_script_sigs: input.tap_script_sigs,
 +            tap_scripts: input.tap_scripts,
-+            tap_key_origins: input.tap_key_origins,
++            tap_key_origins: tap_key_origins_into_v2(input.tap_key_origins),
 +            tap_internal_key: input.tap_internal_key,
 +            tap_merkle_root: input.tap_merkle_root,
 +            proprietaries: input.proprietaries,
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod tests {
              scalar: u8,
              option: Option<u8>,
 
+ ## crates/concurrent-psbt/src/psbt/mod.rs ##
+@@ crates/concurrent-psbt/src/psbt/mod.rs: mod joinable_struct_macro;
+ pub(crate) mod global;
+ pub mod input;
+ pub mod output;
++mod tap_leaf_hashes;
+ mod values;
++
++pub use tap_leaf_hashes::TapLeafHashes;
+
  ## crates/concurrent-psbt/src/psbt/output.rs ##
-@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
- use bitcoin::taproot::{TapLeafHash, TapTree};
+@@
+ 
+ use bitcoin::bip32::KeySource;
+ use bitcoin::key::{PublicKey, XOnlyPublicKey};
+-use bitcoin::taproot::{TapLeafHash, TapTree};
++use bitcoin::taproot::TapTree;
  use bitcoin::{Amount, ScriptBuf};
  use psbt_v2::raw;
 -use psbt_v2::v2::Output;
++
++use super::tap_leaf_hashes::{TapLeafHashes, tap_key_origins_from_v2, tap_key_origins_into_v2};
  
  joinable_struct! {
 -    /// Result-domain representation of a PSBT output.
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
      source: Output,
 +    /// Result-domain counterpart of [`Output`].
 +    ///
-+    /// Each field is represented in the internal result domain, recording
-+    /// either a clean value or an accumulated conflict.
++    /// Each field holds a clean value or a conflict.
      result: ResultOutput,
 -    ext: OutputExt,
      fields: {
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +        pub bip32_derivations: BTreeMap<PublicKey, KeySource>,
 +        pub tap_internal_key: Option<XOnlyPublicKey>,
 +        pub tap_tree: Option<TapTree>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)>,
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    }
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +            bip32_derivations,
 +            tap_internal_key,
 +            tap_tree,
-+            tap_key_origins,
++            tap_key_origins: tap_key_origins_from_v2(tap_key_origins),
 +            proprietaries,
 +            unknowns,
 +        }
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +            bip32_derivations: output.bip32_derivations,
 +            tap_internal_key: output.tap_internal_key,
 +            tap_tree: output.tap_tree,
-+            tap_key_origins: output.tap_key_origins,
++            tap_key_origins: tap_key_origins_into_v2(output.tap_key_origins),
 +            proprietaries,
 +            unknowns: output.unknowns,
 +            ..psbt_v2::v2::Output::default()
@@ crates/concurrent-psbt/src/psbt/output.rs: impl UniqueId {
  impl crate::values::IdempotentValue for UniqueId {}
  
 -/// The bytes are too long for a [`UniqueId`]; they are returned unchanged.
-+/// The bytes are empty or too long for a [`UniqueId`]; they are returned
-+/// unchanged.
++/// Bytes that are not a valid [`UniqueId`]: empty, or longer than
++/// [`UniqueId::MAX_LEN`].
  #[derive(Debug, Clone, PartialEq, Eq)]
  pub struct InvalidUniqueId(pub Vec<u8>);
  
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
          }
      }
  }
+
+ ## crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new) ##
+@@
++//! The leaf hashes of a BIP 371 taproot key origin.
++
++use std::collections::{BTreeMap, BTreeSet};
++
++use bitcoin::TapLeafHash;
++use bitcoin::bip32::KeySource;
++use bitcoin::secp256k1::XOnlyPublicKey;
++
++use crate::values::IdempotentValue;
++
++/// The leaf hashes of a taproot key in `PSBT_{IN,OUT}_TAP_BIP32_DERIVATION`.
++///
++/// Two values are equal when they hold the same hashes, in any order and with
++/// any repetition. The hashes keep the order they were given in, and joining
++/// equal values keeps the left one.
++#[derive(Debug, Clone)]
++pub struct TapLeafHashes(Vec<TapLeafHash>);
++
++impl TapLeafHashes {
++    /// The leaf hashes, in the order they were given in.
++    pub fn as_slice(&self) -> &[TapLeafHash] {
++        &self.0
++    }
++
++    fn set(&self) -> BTreeSet<&TapLeafHash> {
++        self.0.iter().collect()
++    }
++}
++
++impl PartialEq for TapLeafHashes {
++    fn eq(&self, other: &Self) -> bool {
++        self.set() == other.set()
++    }
++}
++
++impl Eq for TapLeafHashes {}
++
++// Every value is built here, so sorting and deduplicating `leaves` here would
++// make equal values structurally equal.
++impl From<Vec<TapLeafHash>> for TapLeafHashes {
++    fn from(leaves: Vec<TapLeafHash>) -> Self {
++        Self(leaves)
++    }
++}
++
++impl From<TapLeafHashes> for Vec<TapLeafHash> {
++    fn from(leaves: TapLeafHashes) -> Self {
++        leaves.0
++    }
++}
++
++impl IdempotentValue for (TapLeafHashes, KeySource) {}
++
++/// `PSBT_{IN,OUT}_TAP_BIP32_DERIVATION` as psbt-v2 stores it.
++type V2TapKeyOrigins = BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>;
++
++/// `PSBT_{IN,OUT}_TAP_BIP32_DERIVATION` with set equality on the leaf hashes.
++type TapKeyOrigins = BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)>;
++
++pub(crate) fn tap_key_origins_from_v2(origins: V2TapKeyOrigins) -> TapKeyOrigins {
++    origins
++        .into_iter()
++        .map(|(key, (leaves, source))| (key, (leaves.into(), source)))
++        .collect()
++}
++
++pub(crate) fn tap_key_origins_into_v2(origins: TapKeyOrigins) -> V2TapKeyOrigins {
++    origins
++        .into_iter()
++        .map(|(key, (leaves, source))| (key, (leaves.into(), source)))
++        .collect()
++}
++
++#[cfg(all(test, feature = "prop-tests"))]
++#[cfg_attr(coverage_nightly, coverage(off))]
++mod tests {
++    use bitcoin::bip32::{DerivationPath, Fingerprint};
++    use bitcoin::hashes::Hash;
++    use bitcoin::secp256k1::{Secp256k1, SecretKey};
++    use proptest::prelude::*;
++
++    use super::*;
++    use crate::lattice::join::Join;
++    use crate::lattice::partial::{JoinResult, PartialJoin};
++
++    fn arb_leaves() -> impl Strategy<Value = Vec<TapLeafHash>> {
++        proptest::collection::vec(0u8..3, 0..4).prop_map(|bytes| {
++            bytes
++                .into_iter()
++                .map(|byte| TapLeafHash::from_byte_array([byte; 32]))
++                .collect()
++        })
++    }
++
++    /// `leaves` in reverse, with each hash repeated.
++    fn shuffled(leaves: &[TapLeafHash]) -> Vec<TapLeafHash> {
++        leaves.iter().rev().flat_map(|&leaf| [leaf, leaf]).collect()
++    }
++
++    fn arb_origin() -> impl Strategy<Value = (TapLeafHashes, KeySource)> {
++        (arb_leaves(), 0u8..2).prop_map(|(leaves, source)| {
++            let source = (Fingerprint::from([source; 4]), DerivationPath::master());
++            (leaves.into(), source)
++        })
++    }
++
++    fn arb_result_origin() -> impl Strategy<Value = JoinResult<(TapLeafHashes, KeySource)>> {
++        prop_oneof![
++            arb_origin().prop_map(Ok),
++            (arb_origin(), arb_origin()).prop_map(|(a, b)| a.wrap().join(b.wrap())),
++        ]
++    }
++
++    fn arb_v2_tap_key_origins() -> impl Strategy<Value = V2TapKeyOrigins> {
++        let origin = arb_origin().prop_map(|(leaves, source)| (leaves.into(), source));
++        proptest::collection::btree_map(1u8..4, origin, 0..3).prop_map(|origins| {
++            origins
++                .into_iter()
++                .map(|(seed, origin)| {
++                    let secret_key = SecretKey::from_slice(&[seed; 32]).expect("nonzero seed");
++                    (secret_key.x_only_public_key(&Secp256k1::new()).0, origin)
++                })
++                .collect()
++        })
++    }
++
++    assert_partial_join_laws!(arb_origin(), arb_result_origin());
++
++    proptest! {
++        #[test]
++        fn reordered_and_repeated_hashes_are_equal(a in arb_leaves()) {
++            prop_assert_eq!(TapLeafHashes::from(shuffled(&a)), TapLeafHashes::from(a));
++        }
++
++        #[test]
++        fn an_extra_hash_is_unequal(a in arb_leaves(), extra in 3u8..6) {
++            let mut b = a.clone();
++            b.push(TapLeafHash::from_byte_array([extra; 32]));
++            prop_assert_ne!(TapLeafHashes::from(a), TapLeafHashes::from(b));
++        }
++
++        #[test]
++        fn join_keeps_the_left_list(a in arb_leaves()) {
++            let source = (Fingerprint::default(), DerivationPath::master());
++            let left = (TapLeafHashes::from(a.clone()), source.clone());
++            let right = (TapLeafHashes::from(shuffled(&a)), source);
++            let (joined, _) = left.try_join(right).expect("equal values join");
++            prop_assert_eq!(joined.as_slice(), a.as_slice());
++        }
++
++        #[test]
++        fn v2_round_trip_keeps_the_lists(origins in arb_v2_tap_key_origins()) {
++            prop_assert_eq!(tap_key_origins_into_v2(tap_key_origins_from_v2(origins.clone())), origins);
++        }
++    }
++}
+
+ ## crates/concurrent-psbt/src/psbt/values.rs ##
+@@
+ //! [`IdempotentValue`](crate::values::IdempotentValue) implementations for
+ //! bitcoin and psbt-v2 types used as PSBT fields.
+ 
+-use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
+ use crate::values::IdempotentValue;
+ 
+ impl IdempotentValue for bitcoin::absolute::Height {}
+@@ crates/concurrent-psbt/src/psbt/values.rs: impl IdempotentValue for psbt_v2::PsbtSighashType {}
+ impl IdempotentValue for psbt_v2::Version {}
+ 
+ impl IdempotentValue for (bitcoin::ScriptBuf, bitcoin::taproot::LeafVersion) {}
+-
+-/// BIP 371 taproot BIP 32 derivation values: `(Vec<TapLeafHash>, KeySource)`.
+-///
+-/// The leaf-hash list is the set of tap leaves the key participates in; BIP 371
+-/// imposes no ordering on it, so join equality is order-insensitive: two values
+-/// join iff the key sources match and the leaf lists are equal as multisets.
+-/// `self`'s representation (its leaf order) is kept on `Ok`.
+-impl PartialJoin for (Vec<bitcoin::TapLeafHash>, bitcoin::bip32::KeySource) {
+-    fn try_join(self, other: Self) -> JoinResult<Self> {
+-        fn sorted(leaves: &[bitcoin::TapLeafHash]) -> Vec<bitcoin::TapLeafHash> {
+-            let mut copy = leaves.to_vec();
+-            copy.sort_unstable();
+-            copy
+-        }
+-
+-        if self.1 == other.1 && sorted(&self.0) == sorted(&other.0) {
+-            Ok(self)
+-        } else {
+-            Err(Conflict::from_values([self, other]))
+-        }
+-    }
+-}
+-
+-#[cfg(test)]
+-#[cfg_attr(coverage_nightly, coverage(off))]
+-mod tests {
+-    #[cfg(feature = "unit-tests")]
+-    mod unit {
+-        use bitcoin::TapLeafHash;
+-        use bitcoin::bip32::{DerivationPath, Fingerprint, KeySource};
+-        use bitcoin::hashes::Hash;
+-
+-        use crate::lattice::partial::{Conflict, PartialJoin};
+-
+-        fn key_source() -> KeySource {
+-            (Fingerprint::from([0u8; 4]), DerivationPath::master())
+-        }
+-
+-        fn leaf(byte: u8) -> TapLeafHash {
+-            TapLeafHash::from_byte_array([byte; 32])
+-        }
+-
+-        #[test]
+-        fn reordered_tap_leaf_hashes_join_ok() {
+-            let a = (vec![leaf(1), leaf(2)], key_source());
+-            let b = (vec![leaf(2), leaf(1)], key_source());
+-            // Same leaves as a multiset: joins Ok, keeping self's representation.
+-            assert_eq!(a.clone().try_join(b), Ok(a));
+-        }
+-
+-        #[test]
+-        fn different_tap_leaf_hashes_conflict() {
+-            let a = (vec![leaf(1)], key_source());
+-            let b = (vec![leaf(2)], key_source());
+-            assert_eq!(
+-                a.clone().try_join(b.clone()),
+-                Err(Conflict::from_values([a, b]))
+-            );
+-        }
+-    }
+-
+-    #[cfg(feature = "prop-tests")]
+-    mod prop {
+-        use bitcoin::TapLeafHash;
+-        use bitcoin::bip32::{DerivationPath, Fingerprint, KeySource};
+-        use bitcoin::hashes::Hash;
+-        use proptest::prelude::*;
+-
+-        use crate::lattice::partial::PartialJoin;
+-
+-        fn key_source(byte: u8) -> KeySource {
+-            (Fingerprint::from([byte; 4]), DerivationPath::master())
+-        }
+-
+-        fn leaves(bytes: &[u8]) -> Vec<TapLeafHash> {
+-            bytes
+-                .iter()
+-                .map(|byte| TapLeafHash::from_byte_array([*byte; 32]))
+-                .collect()
+-        }
+-
+-        proptest! {
+-            #[test]
+-            fn different_key_sources_conflict(bytes in proptest::collection::vec(any::<u8>(), 0..8)) {
+-                let a = (leaves(&bytes), key_source(0));
+-                let b = (leaves(&bytes), key_source(1));
+-                prop_assert!(a.try_join(b).is_err());
+-            }
+-        }
+-    }
+-}

@github-actions

Copy link
Copy Markdown
range-diff for force push 83c0bbb0a0 → e10fb51e3d November 14, 2026 09:55 UTC: 1 unchanged, 1 added; 1 → 2 commits; same base 933eca83ff

reproduce: git range-diff 933eca8..83c0bbb 933eca8..e10fb51

-:  ----------              > 1:  ddba010255   +3   -0 1f nix: build mutants incrementally
1:  83c0bbb0a0 +775 -317 8f = 2:  e10fb51e3d +775 -317 8f define own Global, Input and Output structs

@github-actions

Copy link
Copy Markdown
range-diff for force push e10fb51e3d → 1d0d5c5a96 November 14, 2026 13:22 UTC: 1 modified, 1 unchanged; 2 commits; same base 933eca83ff

reproduce: git range-diff 933eca8..e10fb51 933eca8..1d0d5c5

1:  ddba010255   +3   -0 1f = 1:  ddba010255   +3   -0 1f nix: build mutants incrementally
2:  e10fb51e3d +775 -317 8f ! 2:  1d0d5c5a96 +775 -317 8f define own Global, Input and Output structs
2: e10fb51e3d ! 2: 1d0d5c5a96 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/global.rs
      ///
 -    /// Produced by joining two [`Global`] values via [`GlobalExt::wrap`].
 +    /// Mirrors the BIP 370 global map except `PSBT_GLOBAL_VERSION`, which is
-+    /// always 2, and the input and output counts. [`Global::into_v2`] fills
-+    /// those in.
++    /// always 2, and the input and output counts, which are filled in when
++    /// converting to a BIP 370 PSBT.
 +    source: Global,
 +    /// Result-domain counterpart of [`Global`].
 +    ///

@github-actions

Copy link
Copy Markdown
range-diff for force push 1d0d5c5a96 → dc75494692 November 14, 2026 19:00 UTC: 1 modified, 1 unchanged; 2 commits; same base 933eca83ff

reproduce: git range-diff 933eca8..1d0d5c5 933eca8..dc75494

1:  ddba010255   +3   -0 1f = 1:  ddba010255   +3   -0 1f nix: build mutants incrementally
2:  1d0d5c5a96 +775 -317 8f ! 2:  dc75494692 +915 -315 8f define own Global, Input and Output structs
2: 1d0d5c5a96 ! 2: dc75494692 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/global.rs
 +impl Global {
 +    /// Convert to a BIP 370 global map for a PSBT with `input_count` inputs
 +    /// and `output_count` outputs.
-+    #[expect(
-+        clippy::needless_update,
-+        reason = "psbt-v2's silent-payments feature adds fields this crate does not support yet"
-+    )]
 +    pub(crate) fn into_v2(self, input_count: usize, output_count: usize) -> psbt_v2::v2::Global {
 +        psbt_v2::v2::Global {
-+            version: psbt_v2::Version::TWO,
 +            tx_version: self.tx_version,
 +            fallback_lock_time: self.fallback_lock_time,
 +            tx_modifiable_flags: self.tx_modifiable_flags,
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
          fn for_each_conflict_reports_the_conflicted_field() {
              let mut a = Global::default();
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+     #[cfg(feature = "prop-tests")]
+     mod prop {
+         use super::*;
++        use bitcoin::Network;
++        use bitcoin::bip32::{DerivationPath, Xpriv};
++        use bitcoin::secp256k1::Secp256k1;
+         use proptest::prelude::*;
+ 
+         fn arb_proprietary_key() -> impl Strategy<Value = raw::ProprietaryKey> {
+@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+                 })
+         }
+ 
++        /// The master xpub of `seed`, with its own fingerprint as key source.
++        fn xpub_from_seed(seed: u8) -> (Xpub, KeySource) {
++            let xpriv = Xpriv::new_master(Network::Bitcoin, &[seed; 16]).expect("valid seed");
++            let xpub = Xpub::from_priv(&Secp256k1::new(), &xpriv);
++            (xpub, (xpub.fingerprint(), DerivationPath::master()))
++        }
++
+         fn arb_global() -> impl Strategy<Value = Global> {
+             (
                  proptest::bool::ANY,
                  0u8..4,
                  proptest::bool::ANY,
 -                0usize..4,
 -                0usize..4,
++                proptest::option::of(0u8..2),
                  proptest::collection::btree_map(
                      arb_proprietary_key(),
                      proptest::collection::vec(0u8..=255, 0..=8),
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
-                     0..=2,
                  ),
              )
--                .prop_map(
+                 .prop_map(
 -                    |(
 -                        use_v1,
 -                        flags,
 -                        has_lock_time,
 -                        in_count,
 -                        out_count,
-+                .prop_map(|(use_v1, flags, has_lock_time, proprietaries, unknowns)| {
-+                    Global {
++                    |(use_v1, flags, has_lock_time, xpub, proprietaries, unknowns)| Global {
 +                        tx_version: if use_v1 {
 +                            transaction::Version::ONE
 +                        } else {
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +                        } else {
 +                            None
 +                        },
++                        xpubs: xpub.map(xpub_from_seed).into_iter().collect(),
                          proprietaries,
                          unknowns,
 -                    )| {
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 -                            unknowns,
 -                            ..Global::default()
 -                        }
--                    },
--                )
-+                        ..Global::default()
-+                    }
-+                })
+                     },
+                 )
          }
- 
-         fn arb_result_global() -> impl Strategy<Value = ResultGlobal> {
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
                  prop_assert_eq!(unwrapped.wrap(), wrapped);
              }
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
  #[cfg_attr(coverage_nightly, coverage(off))]
  pub(crate) fn out_point(input: &Input) -> OutPoint {
      OutPoint {
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+     mod unit {
+         use super::*;
+         use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
++        use bitcoin::bip32::{DerivationPath, Fingerprint};
+         use bitcoin::hashes::Hash;
+-        use bitcoin::secp256k1::{Secp256k1, SecretKey};
++        use bitcoin::secp256k1::{Keypair, Message, Secp256k1, SecretKey};
++        use bitcoin::sighash::TapSighashType;
++        use std::collections::BTreeMap;
+ 
+         const ALL_CONFLICT_FIELDS: &[&str] = &[
+             "previous_txid",
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
              assert_eq!(fields, ALL_CONFLICT_FIELDS);
          }
  
++        /// An input with every field set, so a conversion that drops one
++        /// changes the input.
++        fn populated_input() -> Input {
++            let secp = Secp256k1::new();
++            let secret_key = SecretKey::from_slice(&[1; 32]).expect("valid secret key");
++            let keypair = Keypair::from_secret_key(&secp, &secret_key);
++            let public_key = PublicKey::new(secret_key.public_key(&secp));
++            let (x_only_public_key, _) = keypair.x_only_public_key();
++            let message = Message::from_digest([2; 32]);
++            let ecdsa_signature =
++                ecdsa::Signature::sighash_all(secp.sign_ecdsa(&message, &secret_key));
++            let taproot_signature = taproot::Signature {
++                signature: secp.sign_schnorr_no_aux_rand(&message, &keypair),
++                sighash_type: TapSighashType::Default,
++            };
++            let leaf = TapLeafHash::from_byte_array([3; 32]);
++            let source = (Fingerprint::from([4; 4]), DerivationPath::master());
++            let mut control_block = vec![0xc0];
++            control_block.extend(x_only_public_key.serialize());
++            let control_block = ControlBlock::decode(&control_block).expect("valid control block");
++            let script = ScriptBuf::from_bytes(vec![5]);
++            Input {
++                sequence: Some(Sequence(6)),
++                min_time: Some(absolute::Time::MIN),
++                min_height: Some(absolute::Height::MIN),
++                non_witness_utxo: Some(Transaction {
++                    version: bitcoin::transaction::Version::TWO,
++                    lock_time: absolute::LockTime::ZERO,
++                    input: vec![],
++                    output: vec![],
++                }),
++                witness_utxo: Some(TxOut {
++                    value: bitcoin::Amount::from_sat(7),
++                    script_pubkey: script.clone(),
++                }),
++                partial_sigs: BTreeMap::from([(public_key, ecdsa_signature)]),
++                sighash_type: Some(PsbtSighashType::from_u32(1)),
++                redeem_script: Some(script.clone()),
++                witness_script: Some(script.clone()),
++                bip32_derivations: BTreeMap::from([(public_key, source.clone())]),
++                final_script_sig: Some(script.clone()),
++                final_script_witness: Some(Witness::from_slice(&[[8]])),
++                ripemd160_preimages: BTreeMap::from([(
++                    ripemd160::Hash::from_byte_array([9; 20]),
++                    vec![9],
++                )]),
++                sha256_preimages: BTreeMap::from([(
++                    sha256::Hash::from_byte_array([10; 32]),
++                    vec![10],
++                )]),
++                hash160_preimages: BTreeMap::from([(
++                    hash160::Hash::from_byte_array([11; 20]),
++                    vec![11],
++                )]),
++                hash256_preimages: BTreeMap::from([(
++                    sha256d::Hash::from_byte_array([12; 32]),
++                    vec![12],
++                )]),
++                tap_key_sig: Some(taproot_signature),
++                tap_script_sigs: BTreeMap::from([((x_only_public_key, leaf), taproot_signature)]),
++                tap_scripts: BTreeMap::from([(control_block, (script, LeafVersion::TapScript))]),
++                tap_key_origins: BTreeMap::from([(
++                    x_only_public_key,
++                    (TapLeafHashes::from(vec![leaf]), source),
++                )]),
++                tap_internal_key: Some(x_only_public_key),
++                tap_merkle_root: Some(TapNodeHash::from_byte_array([13; 32])),
++                proprietaries: BTreeMap::from([(
++                    raw::ProprietaryKey {
++                        prefix: vec![14],
++                        subtype: 15,
++                        key: vec![],
++                    },
++                    vec![16],
++                )]),
++                unknowns: BTreeMap::from([(
++                    raw::Key {
++                        type_value: 0xfe,
++                        key: vec![17],
++                    },
++                    vec![18],
++                )]),
++                ..make_input(19, 20)
++            }
++        }
++
 +        #[test]
 +        fn v2_conversion_keeps_every_field() {
-+            let mut input = make_input(1, 2);
-+            input.sequence = Some(Sequence(3));
-+            input.proprietaries.insert(
-+                raw::ProprietaryKey {
-+                    prefix: vec![1],
-+                    subtype: 2,
-+                    key: vec![],
-+                },
-+                vec![4],
-+            );
-+            let v2 = psbt_v2::v2::Input::from(input.clone());
-+            assert_eq!(
-+                (v2.previous_txid, v2.spent_output_index, v2.sequence),
-+                (input.previous_txid, 2, Some(Sequence(3)))
-+            );
-+            assert_eq!(Input::from(v2), input);
++            let input = populated_input();
++            assert_eq!(Input::from(psbt_v2::v2::Input::from(input.clone())), input);
 +        }
 +
          #[test]
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
      #[cfg(feature = "unit-tests")]
      mod unit {
          use super::*;
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+         use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
++        use bitcoin::bip32::{DerivationPath, Fingerprint};
++        use bitcoin::hashes::Hash;
          use bitcoin::secp256k1::{Secp256k1, SecretKey};
++        use bitcoin::taproot::{TapLeafHash, TaprootBuilder};
++        use std::collections::BTreeMap;
  
          const ALL_CONFLICT_FIELDS: &[&str] = &[
 +            "unique_id",
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
              };
              assert!(a.wrap().join(b.wrap()).try_unwrap().is_err());
          }
+@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+             result.for_each_conflict(|field, _, _| fields.push(field.to_owned()));
+             assert_eq!(fields, ALL_CONFLICT_FIELDS);
+         }
++
++        /// An output with every field set, so a conversion that drops one
++        /// changes the output.
++        fn populated_output() -> Output {
++            let secret_key = SecretKey::from_slice(&[1; 32]).expect("valid secret key");
++            let public_key = PublicKey::new(secret_key.public_key(&Secp256k1::new()));
++            let (x_only_public_key, _) = public_key.inner.x_only_public_key();
++            let source = (Fingerprint::from([2; 4]), DerivationPath::master());
++            let script = ScriptBuf::from_bytes(vec![3]);
++            let tap_tree = TaprootBuilder::new()
++                .add_leaf(0, script.clone())
++                .expect("valid leaf");
++            Output {
++                amount: bitcoin::Amount::from_sat(4),
++                script_pubkey: script.clone(),
++                redeem_script: Some(script.clone()),
++                witness_script: Some(script),
++                bip32_derivations: BTreeMap::from([(public_key, source.clone())]),
++                tap_internal_key: Some(x_only_public_key),
++                tap_tree: Some(TapTree::try_from(tap_tree).expect("complete tree")),
++                tap_key_origins: BTreeMap::from([(
++                    x_only_public_key,
++                    (
++                        TapLeafHashes::from(vec![TapLeafHash::from_byte_array([5; 32])]),
++                        source,
++                    ),
++                )]),
++                proprietaries: BTreeMap::from([(
++                    raw::ProprietaryKey {
++                        prefix: vec![6],
++                        subtype: 7,
++                        key: vec![],
++                    },
++                    vec![8],
++                )]),
++                unknowns: BTreeMap::from([(
++                    raw::Key {
++                        type_value: 0xfe,
++                        key: vec![9],
++                    },
++                    vec![10],
++                )]),
++                ..output(11)
++            }
++        }
++
++        #[test]
++        fn v2_conversion_keeps_every_field() {
++            let output = populated_output();
++            assert_eq!(
++                Output::try_from(psbt_v2::v2::Output::from(output.clone())),
++                Ok(output)
++            );
++        }
+     }
+ 
+     #[cfg(feature = "prop-tests")]
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                      script_pubkey: ScriptBuf::new(),
                      redeem_script: redeem.map(ScriptBuf::from_bytes),
@@ crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new)
 +        leaves.iter().rev().flat_map(|&leaf| [leaf, leaf]).collect()
 +    }
 +
-+    fn arb_origin() -> impl Strategy<Value = (TapLeafHashes, KeySource)> {
++    fn arb_v2_origin() -> impl Strategy<Value = (Vec<TapLeafHash>, KeySource)> {
 +        (arb_leaves(), 0u8..2).prop_map(|(leaves, source)| {
 +            let source = (Fingerprint::from([source; 4]), DerivationPath::master());
-+            (leaves.into(), source)
++            (leaves, source)
 +        })
 +    }
 +
++    fn arb_origin() -> impl Strategy<Value = (TapLeafHashes, KeySource)> {
++        arb_v2_origin().prop_map(|(leaves, source)| (leaves.into(), source))
++    }
++
 +    fn arb_result_origin() -> impl Strategy<Value = JoinResult<(TapLeafHashes, KeySource)>> {
 +        prop_oneof![
 +            arb_origin().prop_map(Ok),
@@ crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new)
 +    }
 +
 +    fn arb_v2_tap_key_origins() -> impl Strategy<Value = V2TapKeyOrigins> {
-+        let origin = arb_origin().prop_map(|(leaves, source)| (leaves.into(), source));
-+        proptest::collection::btree_map(1u8..4, origin, 0..3).prop_map(|origins| {
++        proptest::collection::btree_map(1u8..4, arb_v2_origin(), 0..3).prop_map(|origins| {
 +            origins
 +                .into_iter()
 +                .map(|(seed, origin)| {

@github-actions

Copy link
Copy Markdown
range-diff for force push 950a11b30a → 3e05d55356 November 14, 2026 22:38 UTC: 3 unchanged; 3 commits; base ddba010255 → 3e0c2248af (descendant, 1 commit ahead)

reproduce: git range-diff ddba010..950a11b 3e0c224..3e05d55

1:  dc75494692 +915 -315  8f = 1:  0db8544246 +915 -315  8f define own Global, Input and Output structs
2:  b1a4e3f410 +313 -590 10f = 2:  5e37ffb7b5 +313 -590 10f lift joinable_struct fields by type, not by token
3:  950a11b30a +241 -204  7f = 3:  3e05d55356 +241 -204  7f generate v2 conversions from the field lists

@github-actions

Copy link
Copy Markdown
range-diff for force push 20c3f12f9d → a1723301e7 November 15, 2026 02:13 UTC: 3 modified, 1 unchanged; 4 commits; same base 3e0c2248af

reproduce: git range-diff 3e0c224..20c3f12 3e0c224..a172330

1:  0db8544246 +915 -315  8f ! 1:  91dd03bef5 +909 -315  8f define own Global, Input and Output structs
2:  5e37ffb7b5 +313 -590 10f = 2:  b2a9b9e0e3 +313 -590 10f lift joinable_struct fields by type, not by token
3:  3e05d55356 +241 -204  7f ! 3:  3943f9919b +241 -198  7f generate v2 conversions from the field lists
4:  20c3f12f9d  +32   -8  4f ! 4:  a1723301e7  +42   -8  5f make Global, Input and Output fields private
1: 0db8544246 ! 1: 91dd03bef5 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +}
 +
 +impl From<Input> for psbt_v2::v2::Input {
-+    #[expect(
-+        clippy::needless_update,
-+        reason = "keeps building if psbt-v2 adds fields this crate does not support yet"
-+    )]
 +    fn from(input: Input) -> Self {
 +        let outpoint = out_point(&input);
 +        Self {
-+            previous_txid: input.previous_txid,
-+            spent_output_index: input.spent_output_index,
 +            sequence: input.sequence,
 +            min_time: input.min_time,
 +            min_height: input.min_height,
3: 3e05d55356 ! 3: 3943f9919b generate v2 conversions from the field lists
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
  }
  
  impl From<Input> for psbt_v2::v2::Input {
--    #[expect(
--        clippy::needless_update,
--        reason = "keeps building if psbt-v2 adds fields this crate does not support yet"
--    )]
      fn from(input: Input) -> Self {
 -        let outpoint = out_point(&input);
 -        Self {
--            previous_txid: input.previous_txid,
--            spent_output_index: input.spent_output_index,
 -            sequence: input.sequence,
 -            min_time: input.min_time,
 -            min_height: input.min_height,
4: 20c3f12f9d ! 4: a1723301e7 make Global, Input and Output fields private
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
          impl $Source {
              /// The mirrored fields of `v2`, with these proprietary fields.
              fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
+
+ ## crates/concurrent-psbt/src/psbt/output.rs ##
+@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
+             }
+ 
++            #[test]
++            fn a_set_field_reads_back(
++                mut o in arb_output(),
++                redeem in proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)),
++            ) {
++                let redeem = redeem.map(ScriptBuf::from_bytes);
++                o.set_redeem_script(redeem.clone());
++                prop_assert_eq!(o.redeem_script(), &redeem);
++            }
++
+         }
+     }
+ 

@github-code-quality

github-code-quality Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

joinable-struct-lift 5f4ab3b own-psbt-structs 50eab5b +/-
100% 100% 0%
View coverage of the 10 most impacted files.
File joinable-struct-lift 5f4ab3b own-psbt-structs 50eab5b +/-
crates/concurre...ons/btreemap.rs 100% 100% 0%
crates/concurre...ions/hashmap.rs 100% 100% 0%
crates/concurre...tions/option.rs 100% 100% 0%
crates/concurre...tice/partial.rs 100% 100% 0%
crates/concurre...struct_macro.rs 100% 100% 0%
crates/concurre.../psbt/global.rs 0% 100% +100%
crates/concurre...lattice/lift.rs 0% 100% +100%
crates/concurre...c/psbt/input.rs 0% 100% +100%
crates/concurre.../proprietary.rs 0% 100% +100%
crates/concurre...ce/conflicts.rs 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 17, 2026 00:01 UTC

@github-actions

Copy link
Copy Markdown
range-diff for force push a1723301e7 → e4468abab2 November 15, 2026 23:52 UTC: 1 modified, 3 dropped, 3 added; 4 commits; same base 3e0c2248af

reproduce: git range-diff 3e0c224..a172330 3e0c224..e4468ab

1:  91dd03bef5 +909 -315  8f < -:  ----------               define own Global, Input and Output structs
2:  b2a9b9e0e3 +313 -590 10f ! 1:  439d9e2a38 +319 -550 10f lift joinable_struct fields by type, not by token
3:  3943f9919b +241 -198  7f < -:  ----------               generate v2 conversions from the field lists
4:  a1723301e7  +42   -8  5f < -:  ----------               make Global, Input and Output fields private
-:  ----------               > 2:  3a5f624ca5 +464 -151  6f define own Global, Input and Output structs
-:  ----------               > 3:  86572d9e5f +284  -89  6f require a unique ID on every Output
-:  ----------               > 4:  e4468abab2 +220 -103  7f store tap leaf hashes as TapLeafHashes
2: b2a9b9e0e3 ! 1: 439d9e2a38 lift joinable_struct fields by type, not by token
@@ crates/concurrent-psbt/src/lattice/mod.rs
 
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
- //! each of them in the internal result domain, enabling field-by-field merging
- //! that accumulates conflicts without short-circuiting.
+ //! enabling field-by-field merging that accumulates conflicts without short-circuiting.
+ //! [`GlobalExt::wrap`] lifts a clean [`Global`] into the result domain.
  
 +use std::collections::BTreeMap;
 +
@@ crates/concurrent-psbt/src/psbt/input.rs
  use bitcoin::bip32::KeySource;
  use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
  use bitcoin::key::{PublicKey, XOnlyPublicKey};
+@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
+ 
+ /// Extract the [`OutPoint`] this input spends (previous txid + output index).
+ #[cfg_attr(
+-    not(test),
++    not(all(test, feature = "unit-tests")),
+     expect(
+         dead_code,
+         reason = "used by InputSet once inputs are keyed by spent outpoint"
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
      #[cfg(feature = "unit-tests")]
      mod unit {
          use super::*;
 -        use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
-         use bitcoin::bip32::{DerivationPath, Fingerprint};
          use bitcoin::hashes::Hash;
-         use bitcoin::secp256k1::{Keypair, Message, Secp256k1, SecretKey};
-         use bitcoin::sighash::TapSighashType;
-         use std::collections::BTreeMap;
- 
+-        use bitcoin::secp256k1::{Secp256k1, SecretKey};
+-
 -        const ALL_CONFLICT_FIELDS: &[&str] = &[
 -            "previous_txid",
 -            "spent_output_index",
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
 -
 -            result
 -        }
--
+ 
          fn make_input(txid_byte: u8, vout: u32) -> Input {
              let txid = bitcoin::Txid::from_byte_array([txid_byte; 32]);
-             Input::new(&bitcoin::OutPoint { txid, vout })
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
          }
  
          #[test]
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
 +            assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
  
-         /// An input with every field set, so a conversion that drops one
-@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
-         }
- 
          #[test]
--        fn v2_conversion_keeps_every_field() {
-+        fn v2_conversion_round_trips_a_populated_input() {
-             let input = populated_input();
-             assert_eq!(Input::from(psbt_v2::v2::Input::from(input.clone())), input);
-         }
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
          proptest! {
              #[test]
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
 +                prop_assert_eq!(i.clone().wrap().try_unwrap(), Ok(i));
              }
  
-             #[test]
-@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
-             }
- 
              #[test]
 -            fn is_ok_try_unwrap_consistent(r in arb_result_input()) {
 -                if r.is_ok() {
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
 
  ## crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs ##
 @@
- /// Generate a product type, its result-domain counterpart, and their lattice
- /// operations from a single field list using standard Rust type syntax.
+ /// Generate a result-domain product type and its lattice operations from a
+ /// single field list using standard Rust type syntax.
  ///
 -/// Fields are classified automatically:
 -///
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +/// [`PartialJoin`](crate::PartialJoin) scalar as a
 +/// [`JoinResult`](crate::JoinResult), and `Option` and `BTreeMap` by lifting
 +/// their contents. Paths and type aliases resolve like any other type.
- ///
- /// Each field may carry attributes and a visibility, which apply to the
- /// `$Source` field; fields of `$Result` are `pub(crate)`.
  ///
  /// Generates:
- /// 1. `$Source` struct with the fields as written
--/// 2. `$Result` struct with transformed field types
-+/// 2. `$Result` struct with the lifted field types
- /// 3. `$Source::wrap`
- /// 4. `Join for $Result`
--/// 5. `$Result::is_ok`
--/// 6. `$Result::try_unwrap`
--///
--/// The field list must name at least one field: `is_ok` is generated as the
+-/// 1. `$Result` struct with transformed field types
++/// 1. `$Result` struct with the lifted field types
+ /// 2. `$Ext` trait with `wrap` method on the source type
+ /// 3. `Join for $Result`
+-/// 4. `$Result::is_ok`
+-/// 5. `$Result::try_unwrap`
++/// 4. `$Result::is_ok`, `$Result::for_each_conflict` and `$Result::try_unwrap`
++/// 5. `ResultValue for $Result`
+ ///
+ /// The field list must name at least one field: `is_ok` is generated as the
 -/// conjunction of the per-field checks, which has no expansion for an empty
 -/// list.
-+/// 5. `$Result::is_ok`, `$Result::for_each_conflict` and `$Result::try_unwrap`
-+/// 6. `ResultValue for $Result`
++/// conjunction of the per-field checks.
  macro_rules! joinable_struct {
 -    // ── Entry point ──────────────────────────────────────────
      (
-         $(#[$source_meta:meta])*
-         source: $Source:ident,
          $(#[$result_meta:meta])*
+         source: $Source:ident,
          result: $Result:ident,
+         ext: $Ext:ident,
 -        fields: { $($fields:tt)* }
 -    ) => {
 -        joinable_struct!(@munch
--            source_meta: [ $(#[$source_meta])* ]
--            result_meta: [ $(#[$result_meta])* ]
+-            meta: [ $(#[$result_meta])* ]
 -            source: $Source
 -            result: $Result
+-            ext: $Ext
 -            classified: []
 -            rest: [ $($fields)* ]
 -        );
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 -
 -    // ── Option<T> ────────────────────────────────────────────
 -    (@munch
--        source_meta: $source_meta:tt
--        result_meta: $result_meta:tt
+-        meta: $meta:tt
 -        source: $Source:ident
 -        result: $Result:ident
+-        ext: $Ext:ident
 -        classified: [ $($classified:tt)* ]
--        rest: [
--            $(#[$field_meta:meta])* $vis:vis $field:ident : Option < $T:ty > ,
--            $($rest:tt)*
--        ]
+-        rest: [ $field:ident : Option < $T:ty > , $($rest:tt)* ]
 -    ) => {
 -        joinable_struct!(@munch
--            source_meta: $source_meta
--            result_meta: $result_meta
+-            meta: $meta
 -            source: $Source
 -            result: $Result
--            classified: [
--                $($classified)*
--                (option [ $(#[$field_meta])* ] [ $vis ] $field $T)
--            ]
+-            ext: $Ext
+-            classified: [ $($classified)* (option $field $T) ]
 -            rest: [ $($rest)* ]
 -        );
 -    };
 -
 -    // ── BTreeMap<K, V> ──────────────────────────────────────
 -    (@munch
--        source_meta: $source_meta:tt
--        result_meta: $result_meta:tt
+-        meta: $meta:tt
 -        source: $Source:ident
 -        result: $Result:ident
+-        ext: $Ext:ident
 -        classified: [ $($classified:tt)* ]
--        rest: [
--            $(#[$field_meta:meta])* $vis:vis $field:ident : BTreeMap < $K:ty , $V:ty > ,
--            $($rest:tt)*
--        ]
+-        rest: [ $field:ident : BTreeMap < $K:ty , $V:ty > , $($rest:tt)* ]
 -    ) => {
 -        joinable_struct!(@munch
--            source_meta: $source_meta
--            result_meta: $result_meta
+-            meta: $meta
 -            source: $Source
 -            result: $Result
--            classified: [
--                $($classified)*
--                (map [ $(#[$field_meta])* ] [ $vis ] $field [ $K => $V ])
--            ]
+-            ext: $Ext
+-            classified: [ $($classified)* (map $field [ $K => $V ]) ]
 -            rest: [ $($rest)* ]
 -        );
 -    };
 -
 -    // ── Scalar T (catch-all; must come after Option, BTreeMap) ─
 -    (@munch
--        source_meta: $source_meta:tt
--        result_meta: $result_meta:tt
+-        meta: $meta:tt
 -        source: $Source:ident
 -        result: $Result:ident
+-        ext: $Ext:ident
 -        classified: [ $($classified:tt)* ]
--        rest: [
--            $(#[$field_meta:meta])* $vis:vis $field:ident : $T:ty ,
--            $($rest:tt)*
--        ]
+-        rest: [ $field:ident : $T:ty , $($rest:tt)* ]
 -    ) => {
 -        joinable_struct!(@munch
--            source_meta: $source_meta
--            result_meta: $result_meta
+-            meta: $meta
 -            source: $Source
 -            result: $Result
--            classified: [
--                $($classified)*
--                (scalar [ $(#[$field_meta])* ] [ $vis ] $field $T)
--            ]
+-            ext: $Ext
+-            classified: [ $($classified)* (scalar $field $T) ]
 -            rest: [ $($rest)* ]
 -        );
 -    };
 -
 -    // ── Terminal: no more fields ─────────────────────────────
 -    (@munch
--        source_meta: [ $(#[$source_meta:meta])* ]
--        result_meta: [ $(#[$result_meta:meta])* ]
+-        meta: [ $(#[$result_meta:meta])* ]
 -        source: $Source:ident
 -        result: $Result:ident
--        classified: [
--            $( (
--                $category:ident
--                [ $(#[$field_meta:meta])* ]
--                [ $vis:vis ]
--                $field:ident
--                $type_tokens:tt
--            ) )*
--        ]
+-        ext: $Ext:ident
+-        classified: [ $( ($category:ident $field:ident $type_tokens:tt) )* ]
 -        rest: []
 +        fields: {
-+            $( $(#[$field_meta:meta])* $vis:vis $field:ident : $T:ty ),+ $(,)?
++            $( $field:ident : $T:ty ),+ $(,)?
 +        }
      ) => {
--        // 1. Source struct
-         $(#[$source_meta])*
-         #[derive(Debug, Clone, PartialEq, Eq)]
-         pub struct $Source {
-             $(
-                 $(#[$field_meta])*
--                $vis $field: joinable_struct!(@source_type $category $type_tokens),
--            )*
-+                $vis $field: $T,
-+            )+
-         }
- 
--        // 2. Result struct
+-        // 1. Result struct
          $(#[$result_meta])*
          #[derive(Debug, Clone, PartialEq)]
          pub struct $Result {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +            )+
          }
  
--        // 3. wrap
-         impl $Source {
-             #[doc = concat!(
-                 "Lift into the result domain as a conflict-free [`",
+-        // 2. Ext trait + impl
+         pub trait $Ext {
++            #[doc = concat!(
++                "Lift into the result domain as a conflict-free [`",
++                stringify!($Result),
++                "`]."
++            )]
+             fn wrap(self) -> $Result;
+         }
+ 
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             pub fn wrap(self) -> $Result {
+             fn wrap(self) -> $Result {
                  $Result {
                      $(
 -                        $field: joinable_struct!(@wrap $category self . $field),
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              }
          }
  
--        // 4. Join
+-        // 3. Join
          impl $crate::lattice::join::Join for $Result {
              fn join(self, other: Self) -> Self {
                  $Result {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              }
          }
  
--        // 5. is_ok + 6. try_unwrap
+-        // 4. is_ok + 5. try_unwrap
          impl $Result {
 +            /// Returns `true` if no field holds a conflict.
              pub fn is_ok(&self) -> bool {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              }
          }
 -    };
- 
--    // --- Type rules ---
 -
--    (@source_type scalar $T:ty) => {
--        $T
--    };
--    (@source_type option $T:ty) => {
--        Option<$T>
--    };
--    (@source_type map [$K:ty => $V:ty]) => {
--        std::collections::BTreeMap<$K, $V>
--    };
+-    // --- Type transformation rules ---
 -
 -    (@result_type scalar $T:ty) => {
 -        $crate::lattice::partial::JoinResult<$T>
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -    (@result_type map [$K:ty => $V:ty]) => {
 -        std::collections::BTreeMap<$K, $crate::lattice::partial::JoinResult<$V>>
 -    };
-+        impl $crate::lattice::lift::ResultValue for $Result {
-+            type Clean = $Source;
- 
+-
 -    // --- Wrap rules ---
 -
 -    (@wrap scalar $self:ident . $field:ident) => {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -    };
 -
 -    // --- is_ok rules ---
--
+ 
 -    (@is_ok scalar $self:ident . $field:ident) => {
 -        $self.$field.is_ok()
 -    };
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -    (@is_ok map $self:ident . $field:ident) => {
 -        $crate::collections::btreemap::ResultBTreeMapExt::is_ok(&$self.$field)
 -    };
--
++        impl $crate::lattice::lift::ResultValue for $Result {
++            type Clean = $Source;
+ 
 -    // --- Visit-conflict rules ---
 +            fn is_ok(&self) -> bool {
 +                $Result::is_ok(self)
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
  
 -    use crate::lattice::join::Join;
 -
++    /// One field per kind of lifting, the option spelled as a path.
+     #[derive(Debug, PartialEq)]
+     pub struct Sample {
+-        scalar: u8,
+-        option: Option<u8>,
+-        map: BTreeMap<u8, u8>,
++        pub scalar: u8,
++        pub option: std::option::Option<u8>,
++        pub map: BTreeMap<u8, u8>,
+     }
+ 
      joinable_struct! {
--        /// One field per category.
-+        /// One field per kind of lifting, the option spelled as a path.
+-        /// Result-domain form of [`Sample`], one field per category.
++        /// Result-domain form of [`Sample`].
          source: Sample,
-         /// Result-domain form of [`Sample`].
          result: ResultSample,
+         ext: SampleExt,
          fields: {
--            scalar: u8,
+             scalar: u8,
 -            option: Option<u8>,
--            map: BTreeMap<u8, u8>,
-+            pub scalar: u8,
-+            pub option: std::option::Option<u8>,
-+            pub map: BTreeMap<u8, u8>,
++            option: std::option::Option<u8>,
+             map: BTreeMap<u8, u8>,
          }
      }
 +}
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 +mod tests {
 +    use std::collections::BTreeMap;
 +
-+    use super::sample::Sample;
++    use super::sample::{Sample, SampleExt};
 +    use crate::lattice::join::Join;
 +    use crate::lattice::lift::ResultValue;
  
@@ crates/concurrent-psbt/src/psbt/output.rs
 +
  use bitcoin::bip32::KeySource;
  use bitcoin::key::{PublicKey, XOnlyPublicKey};
- use bitcoin::taproot::TapTree;
+ use bitcoin::taproot::{TapLeafHash, TapTree};
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
      #[cfg(feature = "unit-tests")]
      mod unit {
          use super::*;
 -        use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
-         use bitcoin::bip32::{DerivationPath, Fingerprint};
-         use bitcoin::hashes::Hash;
-         use bitcoin::secp256k1::{Secp256k1, SecretKey};
-         use bitcoin::taproot::{TapLeafHash, TaprootBuilder};
-         use std::collections::BTreeMap;
- 
+-        use bitcoin::secp256k1::{Secp256k1, SecretKey};
+-
 -        const ALL_CONFLICT_FIELDS: &[&str] = &[
--            "unique_id",
 -            "amount",
 -            "script_pubkey",
 -            "redeem_script",
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 -        }
 -
 -        fn all_fields_conflict(seed: u8) -> ResultOutput {
--            let mut result = output(seed).wrap();
--            result.unique_id = empty_conflict();
+-            let mut result = Output::default().wrap();
 -            result.amount = empty_conflict();
 -            result.script_pubkey = empty_conflict();
 -            result.redeem_script = Some(empty_conflict());
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 -            );
 -            result
 -        }
--
+ 
          #[test]
 -        fn try_unwrap_conflicting_returns_err() {
 -            let a = Output {
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +        fn outputs_with_different_amounts_conflict() {
 +            let with_amount = |sats| Output {
 +                amount: Amount::from_sat(sats),
-                 ..output(1)
+                 ..Output::default()
              };
 -            let b = Output {
 -                amount: bitcoin::Amount::from_sat(200),
--                ..output(1)
+-                ..Output::default()
 -            };
 -            assert!(a.wrap().join(b.wrap()).try_unwrap().is_err());
 -        }
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +            assert_eq!(fields, ["amount"]);
 +            assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
+     }
  
-         /// An output with every field set, so a conversion that drops one
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
          proptest! {
              #[test]

@yuval-block
yuval-block removed this pull request from stack #117 November 16, 2026 00:03
@yuval-block
yuval-block changed the base branch from main to joinable-struct-lift November 16, 2026 00:03
@yuval-block
yuval-block added this pull request to stack #123 November 16, 2026 00:03
@github-actions

Copy link
Copy Markdown
range-diff for force push e4468abab2 → 5cf8f49ac9 November 16, 2026 00:16 UTC: 1 modified, 2 unchanged; 3 commits; same base 439d9e2a38

reproduce: git range-diff 439d9e2..e4468ab 439d9e2..5cf8f49

1:  3a5f624ca5 +464 -151 6f = 1:  3a5f624ca5 +464 -151 6f define own Global, Input and Output structs
2:  86572d9e5f +284  -89 6f = 2:  86572d9e5f +284  -89 6f require a unique ID on every Output
3:  e4468abab2 +220 -103 7f ! 3:  5cf8f49ac9 +220 -103 7f store tap leaf hashes as TapLeafHashes
3: e4468abab2 ! 3: 5cf8f49ac9 store tap leaf hashes as TapLeafHashes
@@ Commit message
     after the type names a MirroredField that converts between them.
     tap_key_origins uses TapKeyOrigins to convert each key's leaf hashes.
 
-    closes #76
+    supersedes #76
 
     Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@github-actions

Copy link
Copy Markdown
range-diff for force push 5cf8f49ac9 → 3bebd68a9b November 16, 2026 03:15 UTC: 3 modified; 3 commits; base 439d9e2a38 → b72b43e9b8 (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 439d9e2..5cf8f49 b72b43e..3bebd68

1:  3a5f624ca5 +464 -151 6f ! 1:  5088693414 +491 -182 6f define own Global, Input and Output structs
2:  86572d9e5f +284  -89 6f ! 2:  b8f825d24f +285  -89 6f require a unique ID on every Output
3:  5cf8f49ac9 +220 -103 7f ! 3:  3bebd68a9b +374 -157 8f store tap leaf hashes as TapLeafHashes
1: 3a5f624ca5 ! 1: 5088693414 define own Global, Input and Output structs
@@ crates/concurrent-psbt/Cargo.toml: prop-tests = []
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
  #![allow(clippy::result_large_err)]
--#![cfg_attr(
--    not(test),
--    expect(
--        dead_code,
--        reason = "exported once UnorderedPsbt composes the PSBT types"
--    )
 +#![expect(
 +    dead_code,
 +    reason = "exported once UnorderedPsbt composes the PSBT types"
- )]
++)]
  
 -//! PSBT global field merging.
 +//! PSBT global fields and their merging.
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 -        xpubs: BTreeMap<Xpub, KeySource>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
+-    }
 +        pub tx_version: transaction::Version,
 +        pub fallback_lock_time: Option<absolute::LockTime>,
 +        pub tx_modifiable_flags: u8,
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
-+}
-+
+ }
+ 
+ record_conflicts! {
+     ResultGlobal, GlobalConflict, GlobalField {
+-    Version => version: Version,
+-    InputCount => input_count: usize,
+-    OutputCount => output_count: usize,
+     TxVersion => tx_version: transaction::Version,
+     FallbackLockTime => fallback_lock_time: absolute::LockTime,
+     TxModifiableFlags => tx_modifiable_flags: u8,
+@@ crates/concurrent-psbt/src/psbt/global.rs: record_conflicts! {
+     }
+ }
+ 
 +impl Default for Global {
 +    fn default() -> Self {
 +        Self::from_v2_fields(psbt_v2::v2::Global::default())
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 +            output_count,
 +            ..psbt_v2::v2::Global::default()
 +        })
-     }
- }
- 
++    }
++}
++
+ #[cfg(test)]
+ #[cfg_attr(coverage_nightly, coverage(off))]
+ mod tests {
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
              assert!(joined.try_unwrap().is_err());
          }
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
 +        }
 +
          #[test]
-         fn for_each_conflict_reports_the_conflicted_field() {
+         fn conflicts_identify_the_field() {
              let mut a = Global::default();
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+             a.tx_version = transaction::Version::ONE;
+             b.tx_version = transaction::Version::TWO;
+             let joined = a.wrap().join(b.wrap());
+-            assert_eq!(
+-                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
+-                [GlobalField::TxVersion]
+-            );
++            assert_eq!(joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(), [GlobalField::TxVersion]);
+         }
+     }
+ 
      #[cfg(feature = "prop-tests")]
      mod prop {
          use super::*;
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 -        tap_merkle_root: Option<TapNodeHash>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
+-    }
 +        pub previous_txid: Txid,
 +        pub spent_output_index: u32,
 +        pub sequence: Option<Sequence>,
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
-+}
-+
+ }
+ 
+ record_conflicts! {
+@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
+     }
+ }
+ 
 +impl Input {
 +    /// Create an input spending `outpoint`, with every other field unset.
 +    pub fn new(outpoint: &OutPoint) -> Self {
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +    fn from(input: Input) -> Self {
 +        let base = psbt_v2::v2::Input::new(&out_point(&input));
 +        input.encode_v2(base)
-     }
- }
- 
++    }
++}
++
  /// Extract the [`OutPoint`] this input spends (previous txid + output index).
 -#[cfg_attr(
 -    not(all(test, feature = "unit-tests")),
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  ///
  /// Each field's result-domain type is `<Type as Lift>::Result`, so a field
  /// joins the way its type [`Lift`](crate::lattice::lift::Lift)s: a
-@@
- /// [`JoinResult`](crate::JoinResult), and `Option` and `BTreeMap` by lifting
+ /// [`PartialJoin`](crate::PartialJoin) scalar as a
+-/// [`JoinResult`](crate::JoinResult), and `Option`, `BTreeMap` and `HashMap` by lifting
++/// [`JoinResult`](crate::JoinResult), and `Option` and `BTreeMap` by lifting
  /// their contents. Paths and type aliases resolve like any other type.
  ///
 +/// Each field may carry attributes and a visibility, which apply to the
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 -/// 1. `$Result` struct with the lifted field types
 -/// 2. `$Ext` trait with `wrap` method on the source type
 -/// 3. `Join for $Result`
--/// 4. `$Result::is_ok`, `$Result::for_each_conflict` and `$Result::try_unwrap`
--/// 5. `ResultValue for $Result`
+-/// 4. `$Result::is_ok` and `$Result::try_unwrap`
+-/// 5. `Lift for $Source` and `ResultWrapped for $Result`
 +/// 1. `$Source` struct with the fields as written
 +/// 2. `$Result` struct with the lifted field types
 +/// 3. `$Source::wrap`
 +/// 4. `Join for $Result`
-+/// 5. `$Result::is_ok`, `$Result::for_each_conflict` and `$Result::try_unwrap`
-+/// 6. `ResultValue for $Result`
++/// 5. `$Result::is_ok` and `$Result::try_unwrap`
++/// 6. `ResultWrapped for $Result`
 +///
 +/// Each entry in `fields` mirrors the field of the same name, and type, in the
 +/// `v2` type. The field itself is private: its visibility
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              )+
          }
  
--        pub trait $Ext {
-+        impl $Source {
-             #[doc = concat!(
-                 "Lift into the result domain as a conflict-free [`",
-                 stringify!($Result),
-                 "`]."
-             )]
--            fn wrap(self) -> $Result;
--        }
+-        pub use $crate::Lift as $Ext;
+-
+-        impl $crate::lattice::lift::Lift for $Source {
+-            type Result = $Result;
 -
--        impl $Ext for $Source {
 -            fn wrap(self) -> $Result {
++        impl $Source {
++            #[doc = concat!(
++                "Lift into the result domain as a conflict-free [`",
++                stringify!($Result),
++                "`]."
++            )]
 +            pub fn wrap(self) -> $Result {
                  $Result {
                      $(
-                         $field: $crate::lattice::lift::Lift::lift(self.$field),
+                         $field: $crate::lattice::lift::Lift::wrap(self.$field),
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             }
+         }
+ 
++        impl $crate::Lift for $Source {
++            type Result = $Result;
++            fn wrap(self) -> $Result { Self::wrap(self) }
++        }
++
+         impl $crate::lattice::join::Join for $Result {
+             fn join(self, other: Self) -> Self {
+                 $Result {
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
  mod sample {
      use std::collections::BTreeMap;
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 -            scalar: u8,
 -            option: std::option::Option<u8>,
 -            map: BTreeMap<u8, u8>,
+-        }
+-    }
+-    record_conflicts! {
+-        ResultSample, SampleConflict, SampleField {
+-            Scalar => scalar: u8,
+-            Option => option: u8,
+-            Map => map[u8]: u8,
 +            pub scalar: u8,
 +            pub option: std::option::Option<u8>,
 +            pub map: BTreeMap<u8, u8>,
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod sample {
 -    use super::sample::{Sample, SampleExt};
 +    use super::sample::Sample;
      use crate::lattice::join::Join;
-     use crate::lattice::lift::ResultValue;
+-    use crate::lattice::lift::ResultWrapped;
++    use crate::lattice::lift::{Lift, ResultWrapped};
  
+     fn sample(scalar: u8, option: u8, value: u8) -> Sample {
+         Sample {
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod tests {
+     }
+ 
+     #[test]
+-    fn conflicting_fields_retain_typed_paths() {
++    fn conflicting_fields_are_preserved() {
+         let joined = sample(1, 2, 3).wrap().join(sample(4, 5, 6).wrap());
+         assert!(!joined.is_ok());
+-        use super::sample::SampleField;
++        use crate::lattice::conflicts::Conflicts;
++        assert_eq!(joined.scalar.conflicts().count(), 1);
++        assert_eq!(joined.option.conflicts().count(), 1);
+         assert_eq!(
+-            joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
+-            [
+-                SampleField::Scalar,
+-                SampleField::Option,
+-                SampleField::Map(&0)
+-            ]
++            joined
++                .map
++                .conflicts()
++                .map(|(key, _)| *key)
++                .collect::<Vec<_>>(),
++            [0]
+         );
+-        use super::sample::SampleConflict;
+-        for (conflict, expected) in joined.conflicts().zip([[1, 4], [2, 5], [3, 6]]) {
+-            match conflict {
+-                SampleConflict::Scalar { values }
+-                | SampleConflict::Option { values }
+-                | SampleConflict::Map { values, .. } => {
+-                    assert_eq!(values.into_iter().copied().collect::<Vec<_>>(), expected);
+-                }
+-            }
+-        }
+         assert_eq!(ResultWrapped::try_unwrap(joined.clone()), Err(joined));
+     }
+ }
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 -        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
+-    }
 +        pub amount: Amount,
 +        pub script_pubkey: ScriptBuf,
 +        pub redeem_script: Option<ScriptBuf>,
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
-+}
-+
+ }
+ 
+ record_conflicts! {
+@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
+     }
+ }
+ 
 +impl Output {
 +    /// Create an output paying `amount` to `script_pubkey`, with every other
 +    /// field unset.
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +impl From<Output> for psbt_v2::v2::Output {
 +    fn from(output: Output) -> Self {
 +        output.encode_v2(psbt_v2::v2::Output::default())
-     }
- }
- 
++    }
++}
++
+ /// Opaque byte-vector identifier for a PSBT output.
+ ///
+ /// Computed from the `PSBT_OUT_UNIQUE_ID` proprietary field, keyed by subtype
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl std::error::Error for InvalidUniqueId {}
  
  pub const PSBT_OUT_UNIQUE_ID_SUBTYPE: u8 = 0x01;
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +                ..output()
              };
              let joined = with_amount(100).wrap().join(with_amount(200).wrap());
-             let mut fields = Vec::new();
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-             assert_eq!(fields, ["amount"]);
+             let fields: Vec<_> = joined.conflicts().map(|c| c.path()).collect();
+             assert_eq!(fields, [OutputField::Amount]);
              assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
 +
2: 86572d9e5f ! 2: b8f825d24f require a unique ID on every Output
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +    proprietary: {},
  }
  
- impl Default for Global {
+ record_conflicts! {
 @@ crates/concurrent-psbt/src/psbt/global.rs: impl Default for Global {
  /// Drops the version and the input and output counts.
  impl From<psbt_v2::v2::Global> for Global {
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
 +    proprietary: {},
  }
  
- impl Input {
+ record_conflicts! {
 @@ crates/concurrent-psbt/src/psbt/input.rs: impl Input {
  
  impl From<psbt_v2::v2::Input> for Input {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
 @@ crates/concurrent-psbt/src/psbt/mod.rs: mod joinable_struct_macro;
- pub(crate) mod global;
+ pub mod global;
  pub mod input;
  pub mod output;
 +pub(crate) mod proprietary;
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
 +    },
  }
  
+ record_conflicts! {
+@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
+     TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+     Unknown => unknowns[raw::Key]: Vec<u8>,
++    UniqueId => unique_id: UniqueId,
+     }
+ }
+ 
  impl Output {
 -    /// Create an output paying `amount` to `script_pubkey`, with every other
 -    /// field unset.
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +                ..output(1)
              };
              let joined = with_amount(100).wrap().join(with_amount(200).wrap());
-             let mut fields = Vec::new();
+             let fields: Vec<_> = joined.conflicts().map(|c| c.path()).collect();
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                      },
                      vec![10],
3: 5cf8f49ac9 ! 3: 3bebd68a9b store tap leaf hashes as TapLeafHashes
@@ crates/concurrent-psbt/src/lib.rs: mod psbt;
 +pub use psbt::TapLeafHashes;
  pub use psbt::input;
  pub use psbt::output;
+ 
+
+ ## crates/concurrent-psbt/src/psbt/global.rs ##
+@@
+ #![allow(clippy::result_large_err)]
+-#![expect(
+-    dead_code,
+-    reason = "exported once UnorderedPsbt composes the PSBT types"
++#![cfg_attr(
++    not(test),
++    expect(dead_code, reason = "global serialization is used by UnorderedPsbt")
+ )]
+-
+ //! PSBT global fields and their merging.
+ //!
+ //! [`Global`] holds the global fields of a PSBT, and [`ResultGlobal`] wraps
+@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+             a.tx_version = transaction::Version::ONE;
+             b.tx_version = transaction::Version::TWO;
+             let joined = a.wrap().join(b.wrap());
+-            assert_eq!(joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(), [GlobalField::TxVersion]);
++            assert_eq!(
++                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
++                [GlobalField::TxVersion]
++            );
+         }
+     }
+ 
+@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
+ 
+             #[test]
+             fn is_ok_consistency(a in arb_result_global()) {
++                prop_assert_eq!(a.conflicts().next().is_none(), a.is_ok());
+                 if a.is_ok() {
+                     prop_assert!(a.try_unwrap().is_ok());
+                 } else {
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
+@@
+ #![allow(clippy::result_large_err)]
+ 
++//! Per-input field type and input set merging.
++//!
++//! [`ResultInput`] wraps each per-input field in the internal result domain.
++//! [`InputSet`] and [`ResultInputSet`] are sets of inputs identified by the
++//! outpoint each spends. Joining two sets joins the inputs that spend the same
++//! outpoint field by field, and fields that differ become conflicts.
++
+ use std::collections::BTreeMap;
+ 
+ use bitcoin::bip32::KeySource;
 @@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Sequence, Transaction, TxOut, Txid, Witness,
  use psbt_v2::PsbtSighashType;
  use psbt_v2::raw;
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
          pub tap_internal_key: Option<XOnlyPublicKey>,
          pub tap_merkle_root: Option<TapNodeHash>,
          pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
+@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
+     TapKeySig => tap_key_sig: taproot::Signature,
+     TapScriptSig => tap_script_sigs[(XOnlyPublicKey, TapLeafHash)]: taproot::Signature,
+     TapScript => tap_scripts[ControlBlock]: (ScriptBuf, LeafVersion),
+-    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
++    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
+     TapInternalKey => tap_internal_key: XOnlyPublicKey,
+     TapMerkleRoot => tap_merkle_root: TapNodeHash,
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
+ 
+ #[cfg(test)]
+ #[cfg_attr(coverage_nightly, coverage(off))]
+-mod tests {
++pub(crate) mod tests {
+     use super::*;
+     use crate::lattice::join::Join;
+ 
+     #[cfg(feature = "unit-tests")]
+-    mod unit {
++    pub(crate) mod unit {
+         use super::*;
+         use bitcoin::bip32::{DerivationPath, Fingerprint};
+         use bitcoin::hashes::Hash;
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+         use bitcoin::sighash::TapSighashType;
+         use std::collections::BTreeMap;
+ 
+-        fn make_input(txid_byte: u8, vout: u32) -> Input {
++        pub(crate) fn make_input(txid_byte: u8, vout: u32) -> Input {
+             let txid = bitcoin::Txid::from_byte_array([txid_byte; 32]);
+             Input::new(&bitcoin::OutPoint { txid, vout })
+         }
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+         #[test]
+         fn inputs_spending_different_outpoints_conflict() {
+             let joined = make_input(1, 0).wrap().join(make_input(2, 0).wrap());
+-            let fields: Vec<_> = joined.conflicts().map(|c| c.path()).collect();
+-            assert_eq!(fields, [InputField::PreviousTxid]);
++            assert_eq!(
++                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
++                [InputField::PreviousTxid]
++            );
+             assert_eq!(joined.clone().try_unwrap(), Err(joined));
+         }
+ 
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
                  tap_key_sig: Some(taproot_signature),
                  tap_script_sigs: BTreeMap::from([((x_only_public_key, leaf), taproot_signature)]),
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
                  tap_internal_key: Some(x_only_public_key),
                  tap_merkle_root: Some(TapNodeHash::from_byte_array([13; 32])),
                  proprietaries: BTreeMap::from([(
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+             }
+         }
+ 
++        #[test]
++        fn compound_and_proprietary_keydata_identify_conflicts() {
++            let input = populated_input();
++            let mut other = input.clone();
++            let tap_key = *input.tap_script_sigs.keys().next().unwrap();
++            other
++                .tap_script_sigs
++                .get_mut(&tap_key)
++                .unwrap()
++                .sighash_type = TapSighashType::All;
++            let proprietary_key = input.proprietaries.keys().next().unwrap().clone();
++            other
++                .proprietaries
++                .get_mut(&proprietary_key)
++                .unwrap()
++                .push(99);
++            let joined = input.clone().wrap().join(other.wrap());
++            let conflicts: Vec<_> = joined.conflicts().collect();
++            assert_eq!(
++                conflicts.iter().map(|c| c.path()).collect::<Vec<_>>(),
++                [
++                    InputField::TapScriptSig(&tap_key),
++                    InputField::Proprietary(&proprietary_key),
++                ]
++            );
++            let InputConflict::TapScriptSig { key, values } = conflicts[0] else {
++                panic!("taproot signature");
++            };
++            assert_eq!(key, &tap_key);
++            assert_eq!(
++                values
++                    .into_iter()
++                    .map(|signature| signature.sighash_type)
++                    .collect::<Vec<_>>(),
++                [TapSighashType::Default, TapSighashType::All]
++            );
++            let InputConflict::Proprietary { key, values } = conflicts[1] else {
++                panic!("proprietary field");
++            };
++            assert_eq!(key, &proprietary_key);
++            assert_eq!(values.into_iter().next(), input.proprietaries.get(key));
++        }
++
+         #[test]
+         fn v2_conversion_round_trips_a_populated_input() {
+             let input = populated_input();
+@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
+     }
+ 
+     #[cfg(feature = "prop-tests")]
+-    mod prop {
++    pub(crate) mod prop {
+         use super::*;
+         use bitcoin::hashes::Hash;
+         use proptest::prelude::*;
+ 
+-        fn arb_outpoint() -> impl Strategy<Value = OutPoint> {
++        // Small domain for outpoints to ensure collisions
++        pub(crate) fn arb_outpoint() -> impl Strategy<Value = OutPoint> {
+             (0u8..3, 0u32..2).prop_map(|(txid_byte, vout)| OutPoint {
+                 txid: Txid::from_byte_array([txid_byte; 32]),
+                 vout,
+             })
+         }
+ 
+-        fn arb_input() -> impl Strategy<Value = Input> {
+-            (
+-                arb_outpoint(),
+-                proptest::option::of(0u32..8),
+-                proptest::option::of(1u64..10_000),
+-                proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)),
+-                proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)),
+-            )
+-                .prop_map(|(op, seq, utxo_val, redeem, witness)| Input {
+-                    sequence: seq.map(Sequence),
+-                    witness_utxo: utxo_val.map(|v| TxOut {
+-                        value: bitcoin::Amount::from_sat(v),
+-                        script_pubkey: ScriptBuf::new(),
+-                    }),
+-                    redeem_script: redeem.map(ScriptBuf::from_bytes),
+-                    witness_script: witness.map(ScriptBuf::from_bytes),
+-                    ..Input::new(&op)
+-                })
++        pub(crate) fn arb_input() -> impl Strategy<Value = Input> {
++            arb_outpoint().prop_map(|op| Input::new(&op))
+         }
+ 
+-        fn arb_result_input() -> impl Strategy<Value = ResultInput> {
++        /// Wrapped inputs, and joins of two, drawn with optional and map fields
++        /// populated so the join laws exercise every field category.
++        pub(crate) fn arb_result_input() -> impl Strategy<Value = ResultInput> {
+             prop_oneof![
+-                arb_input().prop_map(|i| i.wrap()),
+-                (arb_input(), arb_input()).prop_map(|(a, b)| a.wrap().join(b.wrap())),
++                arb_input_with_fields().prop_map(|i| i.wrap()),
++                (arb_input_with_fields(), arb_input_with_fields())
++                    .prop_map(|(a, b)| a.wrap().join(b.wrap())),
+             ]
+         }
+ 
+-        assert_join_laws!(arb_result_input());
++        // An input with some optional and proprietary fields populated.
++        pub(crate) fn arb_input_with_fields() -> impl Strategy<Value = Input> {
++            (
++                arb_outpoint(),
++                proptest::option::of(0u32..8),      // sequence
++                proptest::option::of(1u64..10_000), // witness_utxo value (sats)
++                proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)), // redeem_script
++                proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)), // witness_script
++                proptest::option::of(proptest::collection::vec(0u8..255, 0..=8)), // final_script_sig
++                proptest::collection::btree_map(
++                    proptest::collection::vec(0u8..255, 1..=4),
++                    proptest::collection::vec(0u8..255, 0..=4),
++                    0..=2,
++                ), // proprietaries
++            )
++                .prop_map(
++                    |(op, seq, utxo_val, redeem, witness_s, final_sig, props)| {
++                        let mut input = Input {
++                            sequence: seq.map(Sequence),
++                            witness_utxo: utxo_val.map(|v| TxOut {
++                                value: bitcoin::Amount::from_sat(v),
++                                script_pubkey: ScriptBuf::new(),
++                            }),
++                            redeem_script: redeem.map(ScriptBuf::from_bytes),
++                            witness_script: witness_s.map(ScriptBuf::from_bytes),
++                            final_script_sig: final_sig.map(ScriptBuf::from_bytes),
++                            ..Input::new(&op)
++                        };
++                        for (k, v) in props {
++                            input.proprietaries.insert(
++                                raw::ProprietaryKey {
++                                    prefix: b"test".to_vec(),
++                                    subtype: k[0],
++                                    key: k,
++                                },
++                                v,
++                            );
++                        }
++                        input
++                    },
++                )
++        }
+ 
+         proptest! {
+             #[test]
+-            fn wrap_try_unwrap_roundtrip(i in arb_input()) {
++            fn wrap_try_unwrap_roundtrip(i in prop_oneof![arb_input(), arb_input_with_fields()]) {
+                 prop_assert_eq!(i.clone().wrap().try_unwrap(), Ok(i));
+             }
+ 
+             #[test]
+-            fn v2_roundtrip(i in arb_input()) {
++            fn v2_roundtrip(i in arb_input_with_fields()) {
+                 prop_assert_eq!(Input::from(psbt_v2::v2::Input::from(i.clone())), i);
+             }
+ 
+             #[test]
+             fn is_ok_iff_try_unwrap_succeeds(r in arb_result_input()) {
++                prop_assert_eq!(r.conflicts().next().is_none(), r.is_ok());
+                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
+             }
+-
+         }
++
++        assert_join_laws!(arb_result_input());
+     }
+ }
 
  ## crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs ##
 @@
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  /// Generate a product type, its result-domain counterpart, and their lattice
  /// operations from a single field list using standard Rust type syntax.
  ///
+ /// Each field's result-domain type is `<Type as Lift>::Result`, so a field
+ /// joins the way its type [`Lift`](crate::lattice::lift::Lift)s: a
+ /// [`PartialJoin`](crate::PartialJoin) scalar as a
+-/// [`JoinResult`](crate::JoinResult), and `Option` and `BTreeMap` by lifting
++/// [`JoinResult`](crate::JoinResult), and `Option`, `BTreeMap` and `HashMap` by lifting
+ /// their contents. Paths and type aliases resolve like any other type.
+ ///
+ /// Each field may carry attributes and a visibility, which apply to the
 @@
- /// 5. `$Result::is_ok`, `$Result::for_each_conflict` and `$Result::try_unwrap`
- /// 6. `ResultValue for $Result`
+ /// 3. `$Source::wrap`
+ /// 4. `Join for $Result`
+ /// 5. `$Result::is_ok` and `$Result::try_unwrap`
+-/// 6. `ResultWrapped for $Result`
++/// 6. `Lift for $Source` and `ResultWrapped for $Result`
  ///
 -/// Each entry in `fields` mirrors the field of the same name, and type, in the
 -/// `v2` type. The field itself is private: its visibility
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
      (@decode $v2:ident []) => {
          Ok(Self::from_v2_fields($v2))
      };
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+                 "`]."
+             )]
+             pub fn wrap(self) -> $Result {
++                $crate::lattice::lift::Lift::wrap(self)
++            }
++        }
++
++        impl $crate::lattice::lift::Lift for $Source {
++            type Result = $Result;
++
++            fn wrap(self) -> $Result {
+                 $Result {
+                     $(
+                         $field: $crate::lattice::lift::Lift::wrap(self.$field),
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             }
+         }
+ 
+-        impl $crate::Lift for $Source {
+-            type Result = $Result;
+-            fn wrap(self) -> $Result { Self::wrap(self) }
+-        }
+-
+         impl $crate::lattice::join::Join for $Result {
+             fn join(self, other: Self) -> Self {
+                 $Result {
 
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
-@@ crates/concurrent-psbt/src/psbt/mod.rs: pub(crate) mod global;
+@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod global;
  pub mod input;
  pub mod output;
  pub(crate) mod proprietary;
@@ crates/concurrent-psbt/src/psbt/mod.rs: pub(crate) mod global;
 +pub use tap_leaf_hashes::TapLeafHashes;
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
-@@ crates/concurrent-psbt/src/psbt/output.rs: use std::collections::BTreeMap;
+@@
+ #![allow(clippy::result_large_err)]
+ 
++//! Per-output field type and output set merging.
++//!
++//! [`ResultOutput`] wraps each per-output field in the internal result domain.
++//! [`OutputSet`] and [`ResultOutputSet`] are sets of outputs identified by their
++//! [`UniqueId`]. Joining two sets joins the outputs that have the same unique ID
++//! field by field, and fields that differ become conflicts.
++
+ use std::collections::BTreeMap;
  
  use bitcoin::bip32::KeySource;
  use bitcoin::key::{PublicKey, XOnlyPublicKey};
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
          pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
          pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
      },
+@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
+     Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
+     TapInternalKey => tap_internal_key: XOnlyPublicKey,
+     TapTree => tap_tree: TapTree,
+-    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
++    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
+     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+     Unknown => unknowns[raw::Key]: Vec<u8>,
+     UniqueId => unique_id: UniqueId,
+@@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {
+ 
+ /// Opaque byte-vector identifier for a PSBT output.
+ ///
+-/// Computed from the `PSBT_OUT_UNIQUE_ID` proprietary field, keyed by subtype
+-/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Used as the map key in `OutputSet`
+-/// so that outputs can be merged in an order-independent way.
++/// Stored in the `PSBT_OUT_UNIQUE_ID` proprietary field, subtype
++/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output within an
++/// [`OutputSet`].
+ ///
+-/// Built with [`TryFrom`], a unique ID is 1 to [`UniqueId::MAX_LEN`] bytes
+-/// long, as is one read from a BIP 370 output. An empty ID would make
+-/// unrelated outputs join as one.
++/// A unique ID built with [`TryFrom`] or read from a BIP 370 output is 1 to
++/// [`UniqueId::MAX_LEN`] bytes long. An empty ID would make unrelated outputs
++/// join as one.
+ #[derive(Debug, Clone, PartialEq, Eq, Hash)]
+ pub struct UniqueId(Vec<u8>);
+ 
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
          use bitcoin::bip32::{DerivationPath, Fingerprint};
          use bitcoin::hashes::Hash;
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
          use std::collections::BTreeMap;
  
          #[test]
+@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+                 ..output(1)
+             };
+             let joined = with_amount(100).wrap().join(with_amount(200).wrap());
+-            let fields: Vec<_> = joined.conflicts().map(|c| c.path()).collect();
+-            assert_eq!(fields, [OutputField::Amount]);
++            assert_eq!(
++                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
++                [OutputField::Amount]
++            );
+             assert_eq!(joined.clone().try_unwrap(), Err(joined));
+         }
+ 
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  tap_tree: Some(TapTree::try_from(tap_tree).expect("complete tree")),
                  tap_key_origins: BTreeMap::from([(
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  )]),
                  proprietaries: BTreeMap::from([(
                      raw::ProprietaryKey {
+@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
+ 
+             #[test]
+             fn is_ok_iff_try_unwrap_succeeds(r in arb_result_output()) {
++                prop_assert_eq!(r.conflicts().next().is_none(), r.is_ok());
+                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
+             }
+ 
 
  ## crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new) ##
 @@
@@ crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new)
 +    use proptest::prelude::*;
 +
 +    use super::*;
++    use crate::Lift;
 +    use crate::lattice::join::Join;
 +    use crate::lattice::partial::{JoinResult, PartialJoin};
 +

@github-actions

Copy link
Copy Markdown
range-diff for force push 3bebd68a9b → 5d0742b812 November 16, 2026 03:35 UTC: 3 modified; 3 commits; base b72b43e9b8 → 4c1849a74d (diverged, 1 ahead and 1 behind)

reproduce: git range-diff b72b43e..3bebd68 4c1849a..5d0742b

1:  5088693414 +491 -182 6f ! 1:  ca369b9623 +479 -150 6f define own Global, Input and Output structs
2:  b8f825d24f +285  -89 6f ! 2:  0edaf30448 +285  -89 6f require a unique ID on every Output
3:  3bebd68a9b +374 -157 8f ! 3:  5d0742b812 +370 -156 8f store tap leaf hashes as TapLeafHashes
1: 5088693414 ! 1: ca369b9623 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
  
 -use psbt_v2::Version;
  use psbt_v2::raw;
--use psbt_v2::v2::Global;
+-pub use psbt_v2::v2::Global;
  
  joinable_struct! {
 -    /// Result-domain wrapper around a BIP 370 [`Global`].
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
      /// [`ResultGlobal::try_unwrap`] to extract.
 -    source: Global,
      result: ResultGlobal,
+     conflicts: GlobalConflict, GlobalField {
+-        Version => version: Version,
+-        InputCount => input_count: usize,
+-        OutputCount => output_count: usize,
+         TxVersion => tx_version: transaction::Version,
+         FallbackLockTime => fallback_lock_time: absolute::LockTime,
+         TxModifiableFlags => tx_modifiable_flags: u8,
+@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+         Unknown => unknowns[raw::Key]: Vec<u8>,
+     },
 -    ext: GlobalExt,
 +    v2: psbt_v2::v2::Global,
      fields: {
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 -        xpubs: BTreeMap<Xpub, KeySource>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
--    }
 +        pub tx_version: transaction::Version,
 +        pub fallback_lock_time: Option<absolute::LockTime>,
 +        pub tx_modifiable_flags: u8,
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
- }
- 
- record_conflicts! {
-     ResultGlobal, GlobalConflict, GlobalField {
--    Version => version: Version,
--    InputCount => input_count: usize,
--    OutputCount => output_count: usize,
-     TxVersion => tx_version: transaction::Version,
-     FallbackLockTime => fallback_lock_time: absolute::LockTime,
-     TxModifiableFlags => tx_modifiable_flags: u8,
-@@ crates/concurrent-psbt/src/psbt/global.rs: record_conflicts! {
-     }
- }
- 
++}
++
 +impl Default for Global {
 +    fn default() -> Self {
 +        Self::from_v2_fields(psbt_v2::v2::Global::default())
@@ crates/concurrent-psbt/src/psbt/global.rs: record_conflicts! {
 +            output_count,
 +            ..psbt_v2::v2::Global::default()
 +        })
-+    }
-+}
-+
- #[cfg(test)]
- #[cfg_attr(coverage_nightly, coverage(off))]
- mod tests {
+     }
+ }
+ 
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
              assert!(joined.try_unwrap().is_err());
          }
@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
          fn conflicts_identify_the_field() {
              let mut a = Global::default();
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
-             a.tx_version = transaction::Version::ONE;
-             b.tx_version = transaction::Version::TWO;
-             let joined = a.wrap().join(b.wrap());
--            assert_eq!(
--                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
--                [GlobalField::TxVersion]
--            );
-+            assert_eq!(joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(), [GlobalField::TxVersion]);
-         }
-     }
- 
      #[cfg(feature = "prop-tests")]
      mod prop {
          use super::*;
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +    /// [`Input`] into this type, and [`ResultInput::try_unwrap`] returns it if
 +    /// no field conflicts.
      result: ResultInput,
+     conflicts: InputConflict, InputField {
+         PreviousTxid => previous_txid: Txid,
+@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+         Unknown => unknowns[raw::Key]: Vec<u8>,
+     },
 -    ext: InputExt,
 +    v2: psbt_v2::v2::Input,
      fields: {
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 -        tap_merkle_root: Option<TapNodeHash>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
--    }
 +        pub previous_txid: Txid,
 +        pub spent_output_index: u32,
 +        pub sequence: Option<Sequence>,
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
- }
- 
- record_conflicts! {
-@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
-     }
- }
- 
++}
++
 +impl Input {
 +    /// Create an input spending `outpoint`, with every other field unset.
 +    pub fn new(outpoint: &OutPoint) -> Self {
@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
 +    fn from(input: Input) -> Self {
 +        let base = psbt_v2::v2::Input::new(&out_point(&input));
 +        input.encode_v2(base)
-+    }
-+}
-+
+     }
+ }
+ 
  /// Extract the [`OutPoint`] this input spends (previous txid + output index).
 -#[cfg_attr(
 -    not(all(test, feature = "unit-tests")),
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +        source: $Source:ident,
          $(#[$result_meta:meta])*
 +        result: $Result:ident,
++        conflicts: $Conflict:ident, $Field:ident { $($conflict_fields:tt)* },
 +        v2: $V2:path,
 +        fields: {
 +            $(
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +            source: $Source,
 +            $(#[$result_meta])*
 +            result: $Result,
++            conflicts: $Conflict, $Field { $($conflict_fields)* },
 +            fields: {
 +                $( $(#[$field_meta])* $field: $T, )+
 +            }
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
          source: $Source:ident,
 +        $(#[$result_meta:meta])*
          result: $Result:ident,
+         conflicts: $Conflict:ident, $Field:ident { $($conflict_fields:tt)* },
 -        ext: $Ext:ident,
          fields: {
 -            $( $field:ident : $T:ty ),+ $(,)?
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
          source: Sample,
 +        /// Result-domain form of [`Sample`].
          result: ResultSample,
+         conflicts: SampleConflict, SampleField {
+             Scalar => scalar: u8,
+             Option => option: u8,
+             Map => map[u8]: u8,
+         },
 -        ext: SampleExt,
          fields: {
 -            scalar: u8,
 -            option: std::option::Option<u8>,
 -            map: BTreeMap<u8, u8>,
--        }
--    }
--    record_conflicts! {
--        ResultSample, SampleConflict, SampleField {
--            Scalar => scalar: u8,
--            Option => option: u8,
--            Map => map[u8]: u8,
 +            pub scalar: u8,
 +            pub option: std::option::Option<u8>,
 +            pub map: BTreeMap<u8, u8>,
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod sample {
  
      fn sample(scalar: u8, option: u8, value: u8) -> Sample {
          Sample {
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod tests {
-     }
- 
-     #[test]
--    fn conflicting_fields_retain_typed_paths() {
-+    fn conflicting_fields_are_preserved() {
-         let joined = sample(1, 2, 3).wrap().join(sample(4, 5, 6).wrap());
-         assert!(!joined.is_ok());
--        use super::sample::SampleField;
-+        use crate::lattice::conflicts::Conflicts;
-+        assert_eq!(joined.scalar.conflicts().count(), 1);
-+        assert_eq!(joined.option.conflicts().count(), 1);
-         assert_eq!(
--            joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
--            [
--                SampleField::Scalar,
--                SampleField::Option,
--                SampleField::Map(&0)
--            ]
-+            joined
-+                .map
-+                .conflicts()
-+                .map(|(key, _)| *key)
-+                .collect::<Vec<_>>(),
-+            [0]
-         );
--        use super::sample::SampleConflict;
--        for (conflict, expected) in joined.conflicts().zip([[1, 4], [2, 5], [3, 6]]) {
--            match conflict {
--                SampleConflict::Scalar { values }
--                | SampleConflict::Option { values }
--                | SampleConflict::Map { values, .. } => {
--                    assert_eq!(values.into_iter().copied().collect::<Vec<_>>(), expected);
--                }
--            }
--        }
-         assert_eq!(ResultWrapped::try_unwrap(joined.clone()), Err(joined));
-     }
- }
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +    ///
 +    /// Each field holds a clean value or a conflict.
      result: ResultOutput,
+     conflicts: OutputConflict, OutputField {
+         Amount => amount: Amount,
+@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+         Unknown => unknowns[raw::Key]: Vec<u8>,
+     },
 -    ext: OutputExt,
 +    v2: psbt_v2::v2::Output,
      fields: {
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 -        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
--    }
 +        pub amount: Amount,
 +        pub script_pubkey: ScriptBuf,
 +        pub redeem_script: Option<ScriptBuf>,
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 +        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
 +    },
- }
- 
- record_conflicts! {
-@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
-     }
- }
- 
++}
++
 +impl Output {
 +    /// Create an output paying `amount` to `script_pubkey`, with every other
 +    /// field unset.
@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
 +impl From<Output> for psbt_v2::v2::Output {
 +    fn from(output: Output) -> Self {
 +        output.encode_v2(psbt_v2::v2::Output::default())
-+    }
-+}
-+
- /// Opaque byte-vector identifier for a PSBT output.
- ///
- /// Computed from the `PSBT_OUT_UNIQUE_ID` proprietary field, keyed by subtype
+     }
+ }
+ 
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl std::error::Error for InvalidUniqueId {}
  
  pub const PSBT_OUT_UNIQUE_ID_SUBTYPE: u8 = 0x01;
2: b8f825d24f ! 2: 0edaf30448 require a unique ID on every Output
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 +    proprietary: {},
  }
  
- record_conflicts! {
+ impl Default for Global {
 @@ crates/concurrent-psbt/src/psbt/global.rs: impl Default for Global {
  /// Drops the version and the input and output counts.
  impl From<psbt_v2::v2::Global> for Global {
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
 +    proprietary: {},
  }
  
- record_conflicts! {
+ impl Input {
 @@ crates/concurrent-psbt/src/psbt/input.rs: impl Input {
  
  impl From<psbt_v2::v2::Input> for Input {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
      ) => {
          joinable_struct! {
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             result: $Result,
+             conflicts: $Conflict, $Field { $($conflict_fields)* },
              fields: {
                  $( $(#[$field_meta])* $field: $T, )+
 +                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )*
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, T
      source: Output,
      /// Result-domain counterpart of [`Output`].
      ///
+@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
+         TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+         Unknown => unknowns[raw::Key]: Vec<u8>,
++        UniqueId => unique_id: UniqueId,
+     },
+     v2: psbt_v2::v2::Output,
+     fields: {
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
          pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
          pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
 +    },
  }
  
- record_conflicts! {
-@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
-     TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-     Unknown => unknowns[raw::Key]: Vec<u8>,
-+    UniqueId => unique_id: UniqueId,
-     }
- }
- 
  impl Output {
 -    /// Create an output paying `amount` to `script_pubkey`, with every other
 -    /// field unset.
3: 3bebd68a9b ! 3: 5d0742b812 store tap leaf hashes as TapLeafHashes
@@ crates/concurrent-psbt/src/psbt/global.rs
  //! PSBT global fields and their merging.
  //!
  //! [`Global`] holds the global fields of a PSBT, and [`ResultGlobal`] wraps
-@@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
-             a.tx_version = transaction::Version::ONE;
-             b.tx_version = transaction::Version::TWO;
-             let joined = a.wrap().join(b.wrap());
--            assert_eq!(joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(), [GlobalField::TxVersion]);
-+            assert_eq!(
-+                joined.conflicts().map(|c| c.path()).collect::<Vec<_>>(),
-+                [GlobalField::TxVersion]
-+            );
-         }
-     }
- 
 @@ crates/concurrent-psbt/src/psbt/global.rs: mod tests {
  
              #[test]
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Seq
  joinable_struct! {
      /// A PSBT input, mirroring the BIP 370 per-input map.
      source: Input,
+@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
+         TapKeySig => tap_key_sig: taproot::Signature,
+         TapScriptSig => tap_script_sigs[(XOnlyPublicKey, TapLeafHash)]: taproot::Signature,
+         TapScript => tap_scripts[ControlBlock]: (ScriptBuf, LeafVersion),
+-        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
++        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
+         TapInternalKey => tap_internal_key: XOnlyPublicKey,
+         TapMerkleRoot => tap_merkle_root: TapNodeHash,
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
          pub tap_key_sig: Option<taproot::Signature>,
          pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature>,
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
          pub tap_internal_key: Option<XOnlyPublicKey>,
          pub tap_merkle_root: Option<TapNodeHash>,
          pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-@@ crates/concurrent-psbt/src/psbt/input.rs: record_conflicts! {
-     TapKeySig => tap_key_sig: taproot::Signature,
-     TapScriptSig => tap_script_sigs[(XOnlyPublicKey, TapLeafHash)]: taproot::Signature,
-     TapScript => tap_scripts[ControlBlock]: (ScriptBuf, LeafVersion),
--    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-+    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
-     TapInternalKey => tap_internal_key: XOnlyPublicKey,
-     TapMerkleRoot => tap_merkle_root: TapNodeHash,
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
  
  #[cfg(test)]
@@ crates/concurrent-psbt/src/psbt/output.rs
  
  joinable_struct! {
      /// A PSBT output, mirroring the BIP 370 per-output map, identified by its
+@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
+         Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
+         TapInternalKey => tap_internal_key: XOnlyPublicKey,
+         TapTree => tap_tree: TapTree,
+-        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
++        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
+         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+         Unknown => unknowns[raw::Key]: Vec<u8>,
+         UniqueId => unique_id: UniqueId,
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
          pub bip32_derivations: BTreeMap<PublicKey, KeySource>,
          pub tap_internal_key: Option<XOnlyPublicKey>,
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
          pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
          pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
      },
-@@ crates/concurrent-psbt/src/psbt/output.rs: record_conflicts! {
-     Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
-     TapInternalKey => tap_internal_key: XOnlyPublicKey,
-     TapTree => tap_tree: TapTree,
--    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-+    TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
-     Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-     Unknown => unknowns[raw::Key]: Vec<u8>,
-     UniqueId => unique_id: UniqueId,
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {
  
  /// Opaque byte-vector identifier for a PSBT output.

@github-actions

Copy link
Copy Markdown
range-diff for force push 5d0742b812 → 558e0c9d6c November 16, 2026 03:45 UTC: 3 modified; 3 commits; base 4c1849a74d → 4bc24cac39 (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 4c1849a..5d0742b 4bc24ca..558e0c9

1:  ca369b9623 +479 -150 6f ! 1:  30e1324285 +537 -268 8f define own Global, Input and Output structs
2:  0edaf30448 +285  -89 6f ! 2:  79b53040ad +285  -89 6f require a unique ID on every Output
3:  5d0742b812 +370 -156 8f ! 3:  558e0c9d6c +366 -151 8f store tap leaf hashes as TapLeafHashes
1: ca369b9623 ! 1: 30e1324285 define own Global, Input and Output structs
@@ crates/concurrent-psbt/Cargo.toml: prop-tests = []
  rand = "0.9"
  
 
+ ## crates/concurrent-psbt/src/psbt/conflict_macro.rs (deleted) ##
+@@
+-//! Generates typed conflict enums for the external PSBT types.
+-//!
+-//! Temporary: `joinable_struct!` subsumes this when PR #109 introduces our own
+-//! PSBT structs, using one field list for the structs and their conflict API.
+-
+-macro_rules! record_conflicts {
+-    (
+-        $Result:ident, $Conflict:ident, $Field:ident {
+-            $( $Variant:ident => $field:ident $( [ $Key:ty ] )? : $Value:ty ),+ $(,)?
+-        }
+-    ) => {
+-        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+-        pub enum $Field<'a> {
+-            $( $Variant $( (&'a $Key) )?, )+
+-        }
+-
+-        #[derive(Debug, Clone, Copy)]
+-        pub enum $Conflict<'a> {
+-            $( $Variant { $( key: &'a $Key, )? values: &'a $crate::Conflict<$Value> }, )+
+-        }
+-
+-        impl<'a> $Conflict<'a> {
+-            pub fn path(&self) -> $Field<'a> {
+-                match self {
+-                    $( Self::$Variant { $( key: record_conflicts!(@key $Key, key), )? .. } => {
+-                        record_conflicts!(@path $Field $Variant key $( [ $Key ] )?)
+-                    }, )+
+-                }
+-            }
+-        }
+-
+-        impl $Result {
+-            /// Borrow each conflicted field, retaining its keydata and value type.
+-            pub fn conflicts(&self) -> impl Iterator<Item = $Conflict<'_>> {
+-                // Exhaustive destructuring requires a mapping for every field.
+-                let Self { $( $field, )+ } = self;
+-                std::iter::empty()
+-                    $( .chain($crate::lattice::conflicts::Conflicts::conflicts($field)
+-                        .map(record_conflicts!(@item $Conflict $Variant $( [ $Key ] )?))) )+
+-            }
+-        }
+-
+-        impl $crate::lattice::conflicts::Conflicts for $Result {
+-            type Item<'a> = $Conflict<'a>;
+-
+-            fn conflicts(&self) -> impl Iterator<Item = Self::Item<'_>> {
+-                Self::conflicts(self)
+-            }
+-        }
+-    };
+-    (@key $Key:ty, $key:ident) => { $key };
+-    (@path $Field:ident $Variant:ident $key:ident [ $Key:ty ]) => { $Field::$Variant(*$key) };
+-    (@path $Field:ident $Variant:ident $key:ident) => { $Field::$Variant };
+-    (@item $Conflict:ident $Variant:ident [ $Key:ty ]) => {
+-        |(key, values)| $Conflict::$Variant { key, values }
+-    };
+-    (@item $Conflict:ident $Variant:ident) => {
+-        |values| $Conflict::$Variant { values }
+-    };
+-}
+
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
  #![allow(clippy::result_large_err)]
-+#![expect(
-+    dead_code,
-+    reason = "exported once UnorderedPsbt composes the PSBT types"
++#![cfg_attr(
++    not(test),
++    expect(dead_code, reason = "global serialization is used by UnorderedPsbt")
 +)]
  
 -//! PSBT global field merging.
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
      /// [`ResultGlobal::try_unwrap`] to extract.
 -    source: Global,
      result: ResultGlobal,
-     conflicts: GlobalConflict, GlobalField {
+-    conflicts: GlobalConflict, GlobalField {
 -        Version => version: Version,
 -        InputCount => input_count: usize,
 -        OutputCount => output_count: usize,
-         TxVersion => tx_version: transaction::Version,
-         FallbackLockTime => fallback_lock_time: absolute::LockTime,
-         TxModifiableFlags => tx_modifiable_flags: u8,
-@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-         Unknown => unknowns[raw::Key]: Vec<u8>,
-     },
+-        TxVersion => tx_version: transaction::Version,
+-        FallbackLockTime => fallback_lock_time: absolute::LockTime,
+-        TxModifiableFlags => tx_modifiable_flags: u8,
+-        Xpub => xpubs[Xpub]: KeySource,
+-        Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+-        Unknown => unknowns[raw::Key]: Vec<u8>,
+-    },
 -    ext: GlobalExt,
++    conflicts: GlobalConflict, GlobalField,
 +    v2: psbt_v2::v2::Global,
      fields: {
 -        version: Version,
@@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
 -        xpubs: BTreeMap<Xpub, KeySource>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub tx_version: transaction::Version,
-+        pub fallback_lock_time: Option<absolute::LockTime>,
-+        pub tx_modifiable_flags: u8,
-+        pub xpubs: BTreeMap<Xpub, KeySource>,
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
++        pub tx_version: transaction::Version => TxVersion,
++        pub fallback_lock_time: Option<absolute::LockTime> => FallbackLockTime(absolute::LockTime),
++        pub tx_modifiable_flags: u8 => TxModifiableFlags,
++        pub xpubs: BTreeMap<Xpub, KeySource> => Xpub[Xpub](KeySource),
++        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 +    /// [`Input`] into this type, and [`ResultInput::try_unwrap`] returns it if
 +    /// no field conflicts.
      result: ResultInput,
-     conflicts: InputConflict, InputField {
-         PreviousTxid => previous_txid: Txid,
-@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-         Unknown => unknowns[raw::Key]: Vec<u8>,
-     },
+-    conflicts: InputConflict, InputField {
+-        PreviousTxid => previous_txid: Txid,
+-        SpentOutputIndex => spent_output_index: u32,
+-        Sequence => sequence: Sequence,
+-        MinTime => min_time: absolute::Time,
+-        MinHeight => min_height: absolute::Height,
+-        NonWitnessUtxo => non_witness_utxo: Transaction,
+-        WitnessUtxo => witness_utxo: TxOut,
+-        PartialSig => partial_sigs[PublicKey]: ecdsa::Signature,
+-        SighashType => sighash_type: PsbtSighashType,
+-        RedeemScript => redeem_script: ScriptBuf,
+-        WitnessScript => witness_script: ScriptBuf,
+-        Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
+-        FinalScriptSig => final_script_sig: ScriptBuf,
+-        FinalScriptWitness => final_script_witness: Witness,
+-        Ripemd160Preimage => ripemd160_preimages[ripemd160::Hash]: Vec<u8>,
+-        Sha256Preimage => sha256_preimages[sha256::Hash]: Vec<u8>,
+-        Hash160Preimage => hash160_preimages[hash160::Hash]: Vec<u8>,
+-        Hash256Preimage => hash256_preimages[sha256d::Hash]: Vec<u8>,
+-        TapKeySig => tap_key_sig: taproot::Signature,
+-        TapScriptSig => tap_script_sigs[(XOnlyPublicKey, TapLeafHash)]: taproot::Signature,
+-        TapScript => tap_scripts[ControlBlock]: (ScriptBuf, LeafVersion),
+-        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
+-        TapInternalKey => tap_internal_key: XOnlyPublicKey,
+-        TapMerkleRoot => tap_merkle_root: TapNodeHash,
+-        Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+-        Unknown => unknowns[raw::Key]: Vec<u8>,
+-    },
 -    ext: InputExt,
++    conflicts: InputConflict, InputField,
 +    v2: psbt_v2::v2::Input,
      fields: {
 -        previous_txid: Txid,
@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
 -        tap_merkle_root: Option<TapNodeHash>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub previous_txid: Txid,
-+        pub spent_output_index: u32,
-+        pub sequence: Option<Sequence>,
-+        pub min_time: Option<absolute::Time>,
-+        pub min_height: Option<absolute::Height>,
-+        pub non_witness_utxo: Option<Transaction>,
-+        pub witness_utxo: Option<TxOut>,
-+        pub partial_sigs: BTreeMap<PublicKey, ecdsa::Signature>,
-+        pub sighash_type: Option<PsbtSighashType>,
-+        pub redeem_script: Option<ScriptBuf>,
-+        pub witness_script: Option<ScriptBuf>,
-+        pub bip32_derivations: BTreeMap<PublicKey, KeySource>,
-+        pub final_script_sig: Option<ScriptBuf>,
-+        pub final_script_witness: Option<Witness>,
-+        pub ripemd160_preimages: BTreeMap<ripemd160::Hash, Vec<u8>>,
-+        pub sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>>,
-+        pub hash160_preimages: BTreeMap<hash160::Hash, Vec<u8>>,
-+        pub hash256_preimages: BTreeMap<sha256d::Hash, Vec<u8>>,
-+        pub tap_key_sig: Option<taproot::Signature>,
-+        pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature>,
-+        pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
-+        pub tap_internal_key: Option<XOnlyPublicKey>,
-+        pub tap_merkle_root: Option<TapNodeHash>,
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
++        pub previous_txid: Txid => PreviousTxid,
++        pub spent_output_index: u32 => SpentOutputIndex,
++        pub sequence: Option<Sequence> => Sequence(Sequence),
++        pub min_time: Option<absolute::Time> => MinTime(absolute::Time),
++        pub min_height: Option<absolute::Height> => MinHeight(absolute::Height),
++        pub non_witness_utxo: Option<Transaction> => NonWitnessUtxo(Transaction),
++        pub witness_utxo: Option<TxOut> => WitnessUtxo(TxOut),
++        pub partial_sigs: BTreeMap<PublicKey, ecdsa::Signature> => PartialSig[PublicKey](ecdsa::Signature),
++        pub sighash_type: Option<PsbtSighashType> => SighashType(PsbtSighashType),
++        pub redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
++        pub witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
++        pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
++        pub final_script_sig: Option<ScriptBuf> => FinalScriptSig(ScriptBuf),
++        pub final_script_witness: Option<Witness> => FinalScriptWitness(Witness),
++        pub ripemd160_preimages: BTreeMap<ripemd160::Hash, Vec<u8>> => Ripemd160Preimage[ripemd160::Hash](Vec<u8>),
++        pub sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>> => Sha256Preimage[sha256::Hash](Vec<u8>),
++        pub hash160_preimages: BTreeMap<hash160::Hash, Vec<u8>> => Hash160Preimage[hash160::Hash](Vec<u8>),
++        pub hash256_preimages: BTreeMap<sha256d::Hash, Vec<u8>> => Hash256Preimage[sha256d::Hash](Vec<u8>),
++        pub tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
++        pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
++        pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
++        pub tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
++        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  ///
 +/// Each field may carry attributes and a visibility, which apply to the
 +/// `$Source` field; fields of `$Result` are `pub(crate)`.
++/// `=> Variant` names its conflict variant. Container fields also name the
++/// conflicted value type in parentheses and, for maps, the key type in brackets.
 +///
  /// Generates:
 -/// 1. `$Result` struct with the lifted field types
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +        source: $Source:ident,
          $(#[$result_meta:meta])*
 +        result: $Result:ident,
-+        conflicts: $Conflict:ident, $Field:ident { $($conflict_fields:tt)* },
++        conflicts: $Conflict:ident, $Field:ident,
 +        v2: $V2:path,
 +        fields: {
 +            $(
 +                $(#[$field_meta:meta])* $vis:vis
 +                $field:ident : $T:ty
++                => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
 +            ),+ $(,)?
 +        } $(,)?
 +    ) => {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +            source: $Source,
 +            $(#[$result_meta])*
 +            result: $Result,
-+            conflicts: $Conflict, $Field { $($conflict_fields)* },
++            conflicts: $Conflict, $Field,
 +            fields: {
-+                $( $(#[$field_meta])* $field: $T, )+
++                $( $(#[$field_meta])* $field: $T => $Variant $( [ $Key ] )? $( ( $Value ) )?, )+
 +            }
 +        }
 +
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
          source: $Source:ident,
 +        $(#[$result_meta:meta])*
          result: $Result:ident,
-         conflicts: $Conflict:ident, $Field:ident { $($conflict_fields:tt)* },
+-        conflicts: $Conflict:ident, $Field:ident { $($conflict_fields:tt)* },
 -        ext: $Ext:ident,
++        conflicts: $Conflict:ident, $Field:ident,
          fields: {
 -            $( $field:ident : $T:ty ),+ $(,)?
-+            $( $(#[$field_meta:meta])* $vis:vis $field:ident : $T:ty ),+ $(,)?
++            $( $(#[$field_meta:meta])* $vis:vis $field:ident : $T:ty
++                => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )? ),+ $(,)?
          }
      ) => {
 +        $(#[$source_meta])*
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
          impl $crate::lattice::join::Join for $Result {
              fn join(self, other: Self) -> Self {
                  $Result {
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             }
+         }
+ 
+-        record_conflicts! {
+-            $Result, $Conflict, $Field { $($conflict_fields)* }
++        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
++        pub enum $Field<'a> {
++            $( $Variant $( (&'a $Key) )?, )+
++        }
++
++        #[derive(Debug, Clone, Copy)]
++        pub enum $Conflict<'a> {
++            $( $Variant { $( key: &'a $Key, )? values: &'a $crate::Conflict<joinable_struct!(@conflict_value $T $(, $Value)?)> }, )+
++        }
++
++        impl<'a> $Conflict<'a> {
++            pub fn path(&self) -> $Field<'a> {
++                match self {
++                    $( Self::$Variant { $( key: joinable_struct!(@conflict_key $Key, key), )? .. } => {
++                        joinable_struct!(@conflict_path $Field $Variant key $( [ $Key ] )?)
++                    }, )+
++                }
++            }
++        }
++
++        impl $Result {
++            /// Borrow each conflicted field, retaining its keydata and value type.
++            pub fn conflicts(&self) -> impl Iterator<Item = $Conflict<'_>> {
++                // Exhaustive destructuring requires a mapping for every field.
++                let Self { $( $field, )+ } = self;
++                std::iter::empty()
++                    $( .chain($crate::lattice::conflicts::Conflicts::conflicts($field)
++                        .map(joinable_struct!(@conflict_item $Conflict $Variant $( [ $Key ] )?))) )+
++            }
++        }
++
++        impl $crate::lattice::conflicts::Conflicts for $Result {
++            type Item<'a> = $Conflict<'a>;
++
++            fn conflicts(&self) -> impl Iterator<Item = Self::Item<'_>> {
++                Self::conflicts(self)
++            }
+         }
+ 
+         impl $crate::lattice::lift::ResultWrapped for $Result {
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
+             }
+         }
+     };
++    (@conflict_key $Key:ty, $key:ident) => { $key };
++    (@conflict_path $Field:ident $Variant:ident $key:ident [ $Key:ty ]) => { $Field::$Variant(*$key) };
++    (@conflict_path $Field:ident $Variant:ident $key:ident) => { $Field::$Variant };
++    (@conflict_item $Conflict:ident $Variant:ident [ $Key:ty ]) => {
++        |(key, values)| $Conflict::$Variant { key, values }
++    };
++    (@conflict_item $Conflict:ident $Variant:ident) => {
++        |values| $Conflict::$Variant { values }
++    };
++    (@conflict_value $T:ty) => { $T };
++    (@conflict_value $T:ty, $Value:ty) => { $Value };
++
+ }
+ 
+ // Outside the `coverage(off)` test module, so that this expansion of the
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
  mod sample {
      use std::collections::BTreeMap;
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
          source: Sample,
 +        /// Result-domain form of [`Sample`].
          result: ResultSample,
-         conflicts: SampleConflict, SampleField {
-             Scalar => scalar: u8,
-             Option => option: u8,
-             Map => map[u8]: u8,
-         },
+-        conflicts: SampleConflict, SampleField {
+-            Scalar => scalar: u8,
+-            Option => option: u8,
+-            Map => map[u8]: u8,
+-        },
 -        ext: SampleExt,
++        conflicts: SampleConflict, SampleField,
          fields: {
 -            scalar: u8,
 -            option: std::option::Option<u8>,
 -            map: BTreeMap<u8, u8>,
-+            pub scalar: u8,
-+            pub option: std::option::Option<u8>,
-+            pub map: BTreeMap<u8, u8>,
++            pub scalar: u8 => Scalar,
++            pub option: std::option::Option<u8> => Option(u8),
++            pub map: BTreeMap<u8, u8> => Map[u8](u8),
          }
      }
  }
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod sample {
      fn sample(scalar: u8, option: u8, value: u8) -> Sample {
          Sample {
 
+ ## crates/concurrent-psbt/src/psbt/mod.rs ##
+@@
+ #[macro_use]
+-mod conflict_macro;
+-#[macro_use]
+ mod joinable_struct_macro;
+ pub mod global;
+ pub mod input;
+
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
  use bitcoin::taproot::{TapLeafHash, TapTree};
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 +    ///
 +    /// Each field holds a clean value or a conflict.
      result: ResultOutput,
-     conflicts: OutputConflict, OutputField {
-         Amount => amount: Amount,
-@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-         Unknown => unknowns[raw::Key]: Vec<u8>,
-     },
+-    conflicts: OutputConflict, OutputField {
+-        Amount => amount: Amount,
+-        ScriptPubkey => script_pubkey: ScriptBuf,
+-        RedeemScript => redeem_script: ScriptBuf,
+-        WitnessScript => witness_script: ScriptBuf,
+-        Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
+-        TapInternalKey => tap_internal_key: XOnlyPublicKey,
+-        TapTree => tap_tree: TapTree,
+-        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
+-        Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
+-        Unknown => unknowns[raw::Key]: Vec<u8>,
+-    },
 -    ext: OutputExt,
++    conflicts: OutputConflict, OutputField,
 +    v2: psbt_v2::v2::Output,
      fields: {
 -        amount: Amount,
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
 -        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub amount: Amount,
-+        pub script_pubkey: ScriptBuf,
-+        pub redeem_script: Option<ScriptBuf>,
-+        pub witness_script: Option<ScriptBuf>,
-+        pub bip32_derivations: BTreeMap<PublicKey, KeySource>,
-+        pub tap_internal_key: Option<XOnlyPublicKey>,
-+        pub tap_tree: Option<TapTree>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
++        pub amount: Amount => Amount,
++        pub script_pubkey: ScriptBuf => ScriptPubkey,
++        pub redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
++        pub witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
++        pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
++        pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
++        pub tap_tree: Option<TapTree> => TapTree(TapTree),
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
2: 0edaf30448 ! 2: 79b53040ad require a unique ID on every Output
@@ Commit message
 
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {},
  }
@@ crates/concurrent-psbt/src/psbt/global.rs: impl Default for Global {
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {},
  }
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  macro_rules! joinable_struct {
      (
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-                 $(#[$field_meta:meta])* $vis:vis
                  $field:ident : $T:ty
+                 => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
              ),+ $(,)?
 +        },
 +        proprietary: {
 +            $(
 +                $(#[$proprietary_meta:meta])* $proprietary_vis:vis
 +                $proprietary:ident : $P:ty = $Codec:ty
++                => $ProprietaryVariant:ident $( [ $ProprietaryKey:ty ] )? $( ( $ProprietaryValue:ty ) )?
 +            ),* $(,)?
          } $(,)?
      ) => {
          joinable_struct! {
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             conflicts: $Conflict, $Field { $($conflict_fields)* },
+             conflicts: $Conflict, $Field,
              fields: {
-                 $( $(#[$field_meta])* $field: $T, )+
-+                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P, )*
+                 $( $(#[$field_meta])* $field: $T => $Variant $( [ $Key ] )? $( ( $Value ) )?, )+
++                $( $(#[$proprietary_meta])* $proprietary_vis $proprietary: $P => $ProprietaryVariant $( [ $ProprietaryKey ] )? $( ( $ProprietaryValue ) )?, )*
              }
          }
  
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, T
      /// Result-domain counterpart of [`Output`].
      ///
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-         Unknown => unknowns[raw::Key]: Vec<u8>,
-+        UniqueId => unique_id: UniqueId,
-     },
-     v2: psbt_v2::v2::Output,
-     fields: {
-@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {
-+        unique_id: UniqueId = UniqueIdField,
++        unique_id: UniqueId = UniqueIdField => UniqueId,
 +    },
  }
3: 5d0742b812 ! 3: 558e0c9d6c store tap leaf hashes as TapLeafHashes
@@ crates/concurrent-psbt/src/lib.rs: mod psbt;
 
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
- #![allow(clippy::result_large_err)]
--#![expect(
--    dead_code,
--    reason = "exported once UnorderedPsbt composes the PSBT types"
-+#![cfg_attr(
-+    not(test),
-+    expect(dead_code, reason = "global serialization is used by UnorderedPsbt")
+     not(test),
+     expect(dead_code, reason = "global serialization is used by UnorderedPsbt")
  )]
 -
  //! PSBT global fields and their merging.
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Seq
      /// A PSBT input, mirroring the BIP 370 per-input map.
      source: Input,
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         TapKeySig => tap_key_sig: taproot::Signature,
-         TapScriptSig => tap_script_sigs[(XOnlyPublicKey, TapLeafHash)]: taproot::Signature,
-         TapScript => tap_scripts[ControlBlock]: (ScriptBuf, LeafVersion),
--        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-+        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
-         TapInternalKey => tap_internal_key: XOnlyPublicKey,
-         TapMerkleRoot => tap_merkle_root: TapNodeHash,
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         pub tap_key_sig: Option<taproot::Signature>,
-         pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature>,
-         pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)>,
--        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins,
-         pub tap_internal_key: Option<XOnlyPublicKey>,
-         pub tap_merkle_root: Option<TapNodeHash>,
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
+         pub tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
+         pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
+         pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
+-        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
+         pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
+         pub tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
+         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
  
  #[cfg(test)]
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  /// 5. `$Result::is_ok` and `$Result::try_unwrap`
 -/// 6. `ResultWrapped for $Result`
 +/// 6. `Lift for $Source` and `ResultWrapped for $Result`
++/// 7. Typed conflict paths and `Conflicts for $Result`
  ///
 -/// Each entry in `fields` mirrors the field of the same name, and type, in the
 -/// `v2` type. The field itself is private: its visibility
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
                  $(#[$field_meta:meta])* $vis:vis
 -                $field:ident : $T:ty
 +                $field:ident : $T:ty $( = $Conversion:ty )?
+                 => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
              ),+ $(,)?
          },
-         proprietary: {
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
              /// The mirrored fields of `v2`, with these proprietary fields.
              fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
@@ crates/concurrent-psbt/src/psbt/output.rs
 +//! Per-output field type and output set merging.
 +//!
 +//! [`ResultOutput`] wraps each per-output field in the internal result domain.
-+//! [`OutputSet`] and [`ResultOutputSet`] are sets of outputs identified by their
++//! `OutputSet` and `ResultOutputSet` are sets of outputs identified by their
 +//! [`UniqueId`]. Joining two sets joins the outputs that have the same unique ID
 +//! field by field, and fields that differ become conflicts.
 +
@@ crates/concurrent-psbt/src/psbt/output.rs
  joinable_struct! {
      /// A PSBT output, mirroring the BIP 370 per-output map, identified by its
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         Bip32Derivation => bip32_derivations[PublicKey]: KeySource,
-         TapInternalKey => tap_internal_key: XOnlyPublicKey,
-         TapTree => tap_tree: TapTree,
--        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (Vec<TapLeafHash>, KeySource),
-+        TapKeyOrigin => tap_key_origins[XOnlyPublicKey]: (TapLeafHashes, KeySource),
-         Proprietary => proprietaries[raw::ProprietaryKey]: Vec<u8>,
-         Unknown => unknowns[raw::Key]: Vec<u8>,
-         UniqueId => unique_id: UniqueId,
-@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         pub bip32_derivations: BTreeMap<PublicKey, KeySource>,
-         pub tap_internal_key: Option<XOnlyPublicKey>,
-         pub tap_tree: Option<TapTree>,
--        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins,
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>>,
+         pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
+         pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
+         pub tap_tree: Option<TapTree> => TapTree(TapTree),
+-        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
+         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {
  
@@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Ou
 -/// so that outputs can be merged in an order-independent way.
 +/// Stored in the `PSBT_OUT_UNIQUE_ID` proprietary field, subtype
 +/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output within an
-+/// [`OutputSet`].
++/// `OutputSet`.
  ///
 -/// Built with [`TryFrom`], a unique ID is 1 to [`UniqueId::MAX_LEN`] bytes
 -/// long, as is one read from a BIP 370 output. An empty ID would make

@github-actions

Copy link
Copy Markdown
range-diff for force push 558e0c9d6c → bfa047201a November 16, 2026 03:48 UTC: 1 modified, 2 unchanged; 3 commits; same base 4bc24cac39

reproduce: git range-diff 4bc24ca..558e0c9 4bc24ca..bfa0472

1:  30e1324285 +537 -268 8f = 1:  30e1324285 +537 -268 8f define own Global, Input and Output structs
2:  79b53040ad +285  -89 6f = 2:  79b53040ad +285  -89 6f require a unique ID on every Output
3:  558e0c9d6c +366 -151 8f ! 3:  bfa047201a +366 -151 8f store tap leaf hashes as TapLeafHashes
3: 558e0c9d6c ! 3: bfa047201a store tap leaf hashes as TapLeafHashes
@@ crates/concurrent-psbt/src/psbt/input.rs
 +//! Per-input field type and input set merging.
 +//!
 +//! [`ResultInput`] wraps each per-input field in the internal result domain.
-+//! [`InputSet`] and [`ResultInputSet`] are sets of inputs identified by the
++//! `InputSet` and `ResultInputSet` are sets of inputs identified by the
 +//! outpoint each spends. Joining two sets joins the inputs that spend the same
 +//! outpoint field by field, and fields that differ become conflicts.
 +

@github-actions

Copy link
Copy Markdown
range-diff for force push bfa047201a → 13974295ec November 16, 2026 04:22 UTC: 3 modified; 3 commits; base 4bc24cac39 → 26f6320adb (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 4bc24ca..bfa0472 26f6320..1397429

1:  30e1324285 +537 -268 8f ! 1:  9c8648af95 +560 -268 8f define own Global, Input and Output structs
2:  79b53040ad +285  -89 6f ! 2:  1d4c70d008 +285  -89 6f require a unique ID on every Output
3:  bfa047201a +366 -151 8f ! 3:  13974295ec +366 -154 8f store tap leaf hashes as TapLeafHashes
1: 30e1324285 ! 1: 9c8648af95 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/conflict_macro.rs (deleted)
 @@
 -//! Generates typed conflict enums for the external PSBT types.
 -//!
--//! Temporary: `joinable_struct!` subsumes this when PR #109 introduces our own
--//! PSBT structs, using one field list for the structs and their conflict API.
+-//! Temporary until `joinable_struct!` defines the source structs and generates
+-//! their conflict API from the same field list.
 -
 -macro_rules! record_conflicts {
 -    (
@@ crates/concurrent-psbt/src/psbt/global.rs: use bitcoin::bip32::{KeySource, Xpub}
 -        xpubs: BTreeMap<Xpub, KeySource>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub tx_version: transaction::Version => TxVersion,
-+        pub fallback_lock_time: Option<absolute::LockTime> => FallbackLockTime(absolute::LockTime),
-+        pub tx_modifiable_flags: u8 => TxModifiableFlags,
-+        pub xpubs: BTreeMap<Xpub, KeySource> => Xpub[Xpub](KeySource),
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
++        tx_version: transaction::Version => TxVersion,
++        fallback_lock_time: Option<absolute::LockTime> => FallbackLockTime(absolute::LockTime),
++        tx_modifiable_flags: u8 => TxModifiableFlags,
++        xpubs: BTreeMap<Xpub, KeySource> => Xpub[Xpub](KeySource),
++        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::key::{PublicKey, XOnlyPub
 -        tap_merkle_root: Option<TapNodeHash>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub previous_txid: Txid => PreviousTxid,
-+        pub spent_output_index: u32 => SpentOutputIndex,
-+        pub sequence: Option<Sequence> => Sequence(Sequence),
-+        pub min_time: Option<absolute::Time> => MinTime(absolute::Time),
-+        pub min_height: Option<absolute::Height> => MinHeight(absolute::Height),
-+        pub non_witness_utxo: Option<Transaction> => NonWitnessUtxo(Transaction),
-+        pub witness_utxo: Option<TxOut> => WitnessUtxo(TxOut),
-+        pub partial_sigs: BTreeMap<PublicKey, ecdsa::Signature> => PartialSig[PublicKey](ecdsa::Signature),
-+        pub sighash_type: Option<PsbtSighashType> => SighashType(PsbtSighashType),
-+        pub redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
-+        pub witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
-+        pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
-+        pub final_script_sig: Option<ScriptBuf> => FinalScriptSig(ScriptBuf),
-+        pub final_script_witness: Option<Witness> => FinalScriptWitness(Witness),
-+        pub ripemd160_preimages: BTreeMap<ripemd160::Hash, Vec<u8>> => Ripemd160Preimage[ripemd160::Hash](Vec<u8>),
-+        pub sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>> => Sha256Preimage[sha256::Hash](Vec<u8>),
-+        pub hash160_preimages: BTreeMap<hash160::Hash, Vec<u8>> => Hash160Preimage[hash160::Hash](Vec<u8>),
-+        pub hash256_preimages: BTreeMap<sha256d::Hash, Vec<u8>> => Hash256Preimage[sha256d::Hash](Vec<u8>),
-+        pub tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
-+        pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
-+        pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-+        pub tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
++        previous_txid: Txid => PreviousTxid,
++        spent_output_index: u32 => SpentOutputIndex,
++        sequence: Option<Sequence> => Sequence(Sequence),
++        min_time: Option<absolute::Time> => MinTime(absolute::Time),
++        min_height: Option<absolute::Height> => MinHeight(absolute::Height),
++        non_witness_utxo: Option<Transaction> => NonWitnessUtxo(Transaction),
++        witness_utxo: Option<TxOut> => WitnessUtxo(TxOut),
++        partial_sigs: BTreeMap<PublicKey, ecdsa::Signature> => PartialSig[PublicKey](ecdsa::Signature),
++        sighash_type: Option<PsbtSighashType> => SighashType(PsbtSighashType),
++        redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
++        witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
++        bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
++        final_script_sig: Option<ScriptBuf> => FinalScriptSig(ScriptBuf),
++        final_script_witness: Option<Witness> => FinalScriptWitness(Witness),
++        ripemd160_preimages: BTreeMap<ripemd160::Hash, Vec<u8>> => Ripemd160Preimage[ripemd160::Hash](Vec<u8>),
++        sha256_preimages: BTreeMap<sha256::Hash, Vec<u8>> => Sha256Preimage[sha256::Hash](Vec<u8>),
++        hash160_preimages: BTreeMap<hash160::Hash, Vec<u8>> => Hash160Preimage[hash160::Hash](Vec<u8>),
++        hash256_preimages: BTreeMap<sha256d::Hash, Vec<u8>> => Hash256Preimage[sha256d::Hash](Vec<u8>),
++        tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
++        tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
++        tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
++        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
++        tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
++        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +/// [`JoinResult`](crate::JoinResult), and `Option` and `BTreeMap` by lifting
  /// their contents. Paths and type aliases resolve like any other type.
  ///
-+/// Each field may carry attributes and a visibility, which apply to the
-+/// `$Source` field; fields of `$Result` are `pub(crate)`.
++/// Mirrored fields are private, with public getters and setters by default.
++/// Prefix a field with `[accessors(pub(crate))]` to restrict its accessors.
++/// Fields of `$Result` are `pub(crate)`.
 +/// `=> Variant` names its conflict variant. Container fields also name the
 +/// conflicted value type in parentheses and, for maps, the key type in brackets.
 +///
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +        v2: $V2:path,
 +        fields: {
 +            $(
-+                $(#[$field_meta:meta])* $vis:vis
++                $(#[$field_meta:meta])*
++                $( [accessors($accessor_vis:vis)] )?
 +                $field:ident : $T:ty
 +                => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
 +            ),+ $(,)?
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +        }
 +
 +        impl $Source {
-+            $(
-+                pastey::paste! {
-+                    #[doc = concat!("The `", stringify!($field), "` field.")]
-+                    $vis fn $field(&self) -> &$T {
-+                        &self.$field
-+                    }
-+
-+                    #[doc = concat!("Replace the `", stringify!($field), "` field.")]
-+                    $vis fn [<set_ $field>](&mut self, $field: $T) {
-+                        self.$field = $field;
-+                    }
-+                }
-+            )+
++            $( joinable_struct!(@accessors $(($accessor_vis))? $field: $T); )+
 +        }
 +
 +        impl $Source {
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              }
          }
      };
++    (@accessors $field:ident: $T:ty) => {
++        joinable_struct!(@accessors (pub) $field: $T);
++    };
++    (@accessors ($vis:vis) $field:ident: $T:ty) => {
++        pastey::paste! {
++            #[doc = concat!("The `", stringify!($field), "` field.")]
++            $vis fn $field(&self) -> &$T {
++                &self.$field
++            }
++
++            #[doc = concat!("Replace the `", stringify!($field), "` field.")]
++            $vis fn [<set_ $field>](&mut self, $field: $T) {
++                self.$field = $field;
++            }
++        }
++    };
++
 +    (@conflict_key $Key:ty, $key:ident) => { $key };
 +    (@conflict_path $Field:ident $Variant:ident $key:ident [ $Key:ty ]) => { $Field::$Variant(*$key) };
 +    (@conflict_path $Field:ident $Variant:ident $key:ident) => { $Field::$Variant };
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
 +            pub map: BTreeMap<u8, u8> => Map[u8](u8),
          }
      }
++
++    impl Sample {
++        joinable_struct!(@accessors scalar: u8);
++        joinable_struct!(@accessors (pub(crate)) option: std::option::Option<u8>);
++    }
  }
+ 
+ #[cfg(all(test, feature = "unit-tests"))]
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod sample {
  mod tests {
      use std::collections::BTreeMap;
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod sample {
  
      fn sample(scalar: u8, option: u8, value: u8) -> Sample {
          Sample {
+@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: mod tests {
+         }
+     }
+ 
++    #[test]
++    fn default_and_restricted_accessors_read_and_update_fields() {
++        let mut value = sample(1, 2, 3);
++        assert_eq!(value.scalar(), &1);
++        assert_eq!(value.option(), &Some(2));
++        value.set_scalar(4);
++        value.set_option(None);
++        assert_eq!(value.scalar(), &4);
++        assert_eq!(value.option(), &None);
++    }
++
+     #[test]
+     fn structs_lift_inside_a_map() {
+         let clean = std::collections::HashMap::from([(0u8, sample(1, 2, 3))]);
 
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
 @@
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPu
 -        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>,
 -        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>>,
 -        unknowns: BTreeMap<raw::Key, Vec<u8>>,
-+        pub amount: Amount => Amount,
-+        pub script_pubkey: ScriptBuf => ScriptPubkey,
-+        pub redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
-+        pub witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
-+        pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
-+        pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-+        pub tap_tree: Option<TapTree> => TapTree(TapTree),
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-+        pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
++        amount: Amount => Amount,
++        script_pubkey: ScriptBuf => ScriptPubkey,
++        redeem_script: Option<ScriptBuf> => RedeemScript(ScriptBuf),
++        witness_script: Option<ScriptBuf> => WitnessScript(ScriptBuf),
++        bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
++        tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
++        tap_tree: Option<TapTree> => TapTree(TapTree),
++        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
++        unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
 +    },
 +}
 +
2: 79b53040ad ! 2: 1d4c70d008 require a unique ID on every Output
@@ Commit message
 
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@ crates/concurrent-psbt/src/psbt/global.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {},
  }
@@ crates/concurrent-psbt/src/psbt/global.rs: impl Default for Global {
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {},
  }
@@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, T
      /// Result-domain counterpart of [`Output`].
      ///
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 +    proprietary: {
 +        unique_id: UniqueId = UniqueIdField => UniqueId,
3: bfa047201a ! 3: 13974295ec store tap leaf hashes as TapLeafHashes
@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Seq
      /// A PSBT input, mirroring the BIP 370 per-input map.
      source: Input,
 @@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         pub tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
-         pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
-         pub tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
--        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
-         pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-         pub tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
+         tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
+         tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
+-        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
+         tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
+         tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
  
  #[cfg(test)]
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 +/// [`JoinResult`](crate::JoinResult), and `Option`, `BTreeMap` and `HashMap` by lifting
  /// their contents. Paths and type aliases resolve like any other type.
  ///
- /// Each field may carry attributes and a visibility, which apply to the
+ /// Mirrored fields are private, with public getters and setters by default.
 @@
  /// 3. `$Source::wrap`
  /// 4. `Join for $Result`
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
  ///
 -/// Each entry in `fields` mirrors the field of the same name, and type, in the
 -/// `v2` type. The field itself is private: its visibility
+-/// applies to a getter of the same name and a `set_` setter, so the
+-/// representation can change, and invariants can be added, without breaking
+-/// callers. Each entry in `proprietary` is written
 +/// Each entry in `fields` mirrors the field of the same name in the `v2` type.
 +/// If the two types differ, an `=` after the type names the [`MirroredField`]
-+/// that converts between them. The field itself is private: its visibility
- /// applies to a getter of the same name and a `set_` setter, so the
- /// representation can change, and invariants can be added, without breaking
- /// callers. Each entry in `proprietary` is written
++/// that converts between them. Each entry in `proprietary` is written
+ /// `name: Type = Codec`, and is stored in a proprietary key of `v2` by the
+ /// [`ProprietaryField`](crate::psbt::proprietary::ProprietaryField) impl
+ /// `Codec`. The struct then has private conversions:
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-         fields: {
              $(
-                 $(#[$field_meta:meta])* $vis:vis
+                 $(#[$field_meta:meta])*
+                 $( [accessors($accessor_vis:vis)] )?
 -                $field:ident : $T:ty
 +                $field:ident : $T:ty $( = $Conversion:ty )?
                  => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
@@ crates/concurrent-psbt/src/psbt/output.rs
  joinable_struct! {
      /// A PSBT output, mirroring the BIP 370 per-output map, identified by its
 @@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         pub bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
-         pub tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-         pub tap_tree: Option<TapTree> => TapTree(TapTree),
--        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        pub tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
-         pub proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-         pub unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
+         bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
+         tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
+         tap_tree: Option<TapTree> => TapTree(TapTree),
+-        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
++        tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
+         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
+         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
      },
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {

nothingmuch and others added 3 commits November 16, 2026 04:49
joinable_struct! generates both a plain struct and its result-domain
counterpart, so Global, Input and Output are this crate's types. wrap is
an inherent method, which replaces the GlobalExt, InputExt and OutputExt
traits.

The macro takes the psbt_v2 type and the field list. Each field mirrors
the psbt_v2 field of the same name, so the macro generates the
conversions: from_v2_fields moves the mirrored fields out of a psbt_v2
value, and encode_v2 moves them into one, keeping the psbt_v2 fields
that this crate does not mirror. From converts each type from psbt_v2
and back. Global has no PSBT version or input and output counts, so
Global::into_v2 takes the counts as arguments and sets the version to 2.

The fields are private. A public field cannot enforce an invariant that
the type system does not encode, and cannot be made private again
without breaking callers. The macro generates a getter of the same name
and a `set_` setter with the field's declared visibility, using pastey
to name the setters. OutputUniqueIdExt still reads and writes the unique
ID of an Output.

closes #104

Suggested-by: Codex
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UniqueId becomes a required and immutable field of Output. Output::new
takes it, and TryFrom<psbt_v2::v2::Output> reads it from
PSBT_OUT_UNIQUE_ID. An output without one, or with an empty or overlong
one, is rejected: an empty ID would make unrelated outputs join as one.
This replaces OutputUniqueIdExt.

joinable_struct! takes the field in a new `proprietary` list. Each entry
names a ProprietaryField codec, which defines the field's key subtype
and encoding, so changing the key later does not change the field's type
or join. The macro decodes the proprietary fields in order, removing
their keys, and encodes them back.

closes #89

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check compound and proprietary keydata in conflict paths, and exercise
optional and map fields in the owned PSBT join and conversion properties.
@github-actions

Copy link
Copy Markdown
range-diff for force push 13974295ec → 3e19b232fd November 16, 2026 04:53 UTC: 3 modified, 1 added; 3 → 4 commits; base 26f6320adb → 3e0c2248af (ancestor, 1 commit behind)

reproduce: git range-diff 26f6320..1397429 3e0c224..3e19b23

-:  ----------               > 1:  e1f2b28b81 +585 -662 18f Lift PSBT fields recursively and retain typed conflict paths
1:  9c8648af95 +560 -268  8f ! 2:  62f3e27701 +560 -268  8f define own Global, Input and Output structs
2:  1d4c70d008 +285  -89  6f ! 3:  e28987387e +285  -89  6f require a unique ID on every Output
3:  13974295ec +366 -154  8f ! 4:  3e19b232fd +148  -55  4f store tap leaf hashes as TapLeafHashes
1: 9c8648af95 ! 2: 62f3e27701 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/mod.rs
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
  use bitcoin::taproot::{TapLeafHash, TapTree};
- use bitcoin::{Amount, ScriptBuf};
+ use bitcoin::{Amount, ScriptBuf, TapLeafHash};
  use psbt_v2::raw;
 -use psbt_v2::v2::Output;
2: 1d4c70d008 ! 3: e28987387e require a unique ID on every Output
@@ crates/concurrent-psbt/src/psbt/mod.rs: mod joinable_struct_macro;
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, TapTree};
- use bitcoin::{Amount, ScriptBuf};
+ use bitcoin::{Amount, ScriptBuf, TapLeafHash};
  use psbt_v2::raw;
  
 +use super::proprietary::ProprietaryField;
3: 13974295ec ! 4: 3e19b232fd store tap leaf hashes as TapLeafHashes
@@ Metadata
 Author: Yuval Kogman <nothingmuch@woobling.org>
 
  ## Commit message ##
-    store tap leaf hashes as TapLeafHashes
+    Exercise owned PSBT conflict paths and conversions
 
-    tap_key_origins stores each key's leaf hashes as TapLeafHashes, whose
-    equality ignores order and repetition: BIP 371 gives the list no order.
-    This replaces the custom join on (Vec<TapLeafHash>, KeySource), which
-    compared the lists as multisets. TapLeafHashes joins as an
-    IdempotentValue, so joining equal values keeps the left one's list.
-
-    A mirrored field's type may now differ from the psbt_v2 field's: an `=`
-    after the type names a MirroredField that converts between them.
-    tap_key_origins uses TapKeyOrigins to convert each key's leaf hashes.
-
-    supersedes #76
-
-    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-
- ## crates/concurrent-psbt/src/lib.rs ##
-@@ crates/concurrent-psbt/src/lib.rs: mod psbt;
- 
- pub use lattice::join::{Join, JoinMut};
- pub use lattice::partial::{Conflict, JoinResult, PartialJoin};
-+pub use psbt::TapLeafHashes;
- pub use psbt::input;
- pub use psbt::output;
- 
+    Check compound and proprietary keydata in conflict paths, and exercise
+    optional and map fields in the owned PSBT join and conversion properties.
 
  ## crates/concurrent-psbt/src/psbt/global.rs ##
 @@
@@ crates/concurrent-psbt/src/psbt/input.rs
  use std::collections::BTreeMap;
  
  use bitcoin::bip32::KeySource;
-@@ crates/concurrent-psbt/src/psbt/input.rs: use bitcoin::{OutPoint, ScriptBuf, Sequence, Transaction, TxOut, Txid, Witness,
- use psbt_v2::PsbtSighashType;
- use psbt_v2::raw;
- 
-+use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
-+
- joinable_struct! {
-     /// A PSBT input, mirroring the BIP 370 per-input map.
-     source: Input,
-@@ crates/concurrent-psbt/src/psbt/input.rs: joinable_struct! {
-         tap_key_sig: Option<taproot::Signature> => TapKeySig(taproot::Signature),
-         tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), taproot::Signature> => TapScriptSig[(XOnlyPublicKey, TapLeafHash)](taproot::Signature),
-         tap_scripts: BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)> => TapScript[ControlBlock]((ScriptBuf, LeafVersion)),
--        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
-         tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-         tap_merkle_root: Option<TapNodeHash> => TapMerkleRoot(TapNodeHash),
-         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
  
  #[cfg(test)]
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
              assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
  
-@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
-                 tap_key_sig: Some(taproot_signature),
-                 tap_script_sigs: BTreeMap::from([((x_only_public_key, leaf), taproot_signature)]),
-                 tap_scripts: BTreeMap::from([(control_block, (script, LeafVersion::TapScript))]),
--                tap_key_origins: BTreeMap::from([(x_only_public_key, (vec![leaf], source))]),
-+                tap_key_origins: BTreeMap::from([(
-+                    x_only_public_key,
-+                    (TapLeafHashes::from(vec![leaf]), source),
-+                )]),
-                 tap_internal_key: Some(x_only_public_key),
-                 tap_merkle_root: Some(TapNodeHash::from_byte_array([13; 32])),
-                 proprietaries: BTreeMap::from([(
 @@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
              }
          }
@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
 
  ## crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs ##
 @@
-+/// Converts a mirrored field whose type differs from the psbt-v2 field of the
-+/// same name.
-+pub(crate) trait MirroredField {
-+    /// The psbt-v2 field's type.
-+    type V2;
-+    /// The field's type.
-+    type Value;
-+    /// Convert from the psbt-v2 field.
-+    fn from_v2(value: Self::V2) -> Self::Value;
-+    /// Convert into the psbt-v2 field.
-+    fn into_v2(value: Self::Value) -> Self::V2;
-+}
-+
- /// Generate a product type, its result-domain counterpart, and their lattice
- /// operations from a single field list using standard Rust type syntax.
- ///
  /// Each field's result-domain type is `<Type as Lift>::Result`, so a field
  /// joins the way its type [`Lift`](crate::lattice::lift::Lift)s: a
  /// [`PartialJoin`](crate::PartialJoin) scalar as a
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs
 -/// representation can change, and invariants can be added, without breaking
 -/// callers. Each entry in `proprietary` is written
 +/// Each entry in `fields` mirrors the field of the same name in the `v2` type.
-+/// If the two types differ, an `=` after the type names the [`MirroredField`]
-+/// that converts between them. Each entry in `proprietary` is written
++/// Each entry in `proprietary` is written
  /// `name: Type = Codec`, and is stored in a proprietary key of `v2` by the
  /// [`ProprietaryField`](crate::psbt::proprietary::ProprietaryField) impl
  /// `Codec`. The struct then has private conversions:
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             $(
-                 $(#[$field_meta:meta])*
-                 $( [accessors($accessor_vis:vis)] )?
--                $field:ident : $T:ty
-+                $field:ident : $T:ty $( = $Conversion:ty )?
-                 => $Variant:ident $( [ $Key:ty ] )? $( ( $Value:ty ) )?
-             ),+ $(,)?
-         },
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             /// The mirrored fields of `v2`, with these proprietary fields.
-             fn from_v2_fields(v2: $V2, $( $proprietary: $P ),*) -> Self {
-                 Self {
--                    $( $field: v2.$field, )+
-+                    $( $field: joinable_struct!(@from_v2 v2.$field $(, $Conversion)?), )+
-                     $( $proprietary, )*
-                 }
-             }
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-             /// If a proprietary field encodes to `None`, its key is removed from
-             /// `base`, even if `self.proprietaries` has it.
-             fn encode_v2(self, mut base: $V2) -> $V2 {
--                $( base.$field = self.$field; )+
-+                $( base.$field = joinable_struct!(@into_v2 self.$field $(, $Conversion)?); )+
-                 $(
-                     let key = $crate::psbt::proprietary::key(
-                         <$Codec as $crate::psbt::proprietary::ProprietaryField>::SUBTYPE,
-@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
-         }
-     };
- 
-+    (@from_v2 $value:expr) => {
-+        $value
-+    };
-+
-+    (@from_v2 $value:expr, $Conversion:ty) => {
-+        <$Conversion as $crate::psbt::joinable_struct_macro::MirroredField>::from_v2($value)
-+    };
-+
-+    (@into_v2 $value:expr) => {
-+        $value
-+    };
-+
-+    (@into_v2 $value:expr, $Conversion:ty) => {
-+        <$Conversion as $crate::psbt::joinable_struct_macro::MirroredField>::into_v2($value)
-+    };
-+
-     (@decode $v2:ident []) => {
-         Ok(Self::from_v2_fields($v2))
-     };
 @@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_struct {
                  "`]."
              )]
@@ crates/concurrent-psbt/src/psbt/joinable_struct_macro.rs: macro_rules! joinable_
              fn join(self, other: Self) -> Self {
                  $Result {
 
- ## crates/concurrent-psbt/src/psbt/mod.rs ##
-@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod global;
- pub mod input;
- pub mod output;
- pub(crate) mod proprietary;
-+mod tap_leaf_hashes;
- mod values;
-+
-+pub use tap_leaf_hashes::TapLeafHashes;
-
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@
  #![allow(clippy::result_large_err)]
@@ crates/concurrent-psbt/src/psbt/output.rs
  use bitcoin::key::{PublicKey, XOnlyPublicKey};
 -use bitcoin::taproot::{TapLeafHash, TapTree};
 +use bitcoin::taproot::TapTree;
- use bitcoin::{Amount, ScriptBuf};
+ use bitcoin::{Amount, ScriptBuf, TapLeafHash};
  use psbt_v2::raw;
  
  use super::proprietary::ProprietaryField;
-+use super::tap_leaf_hashes::{TapKeyOrigins, TapLeafHashes};
- 
+-
  joinable_struct! {
      /// A PSBT output, mirroring the BIP 370 per-output map, identified by its
-@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
-         bip32_derivations: BTreeMap<PublicKey, KeySource> => Bip32Derivation[PublicKey](KeySource),
-         tap_internal_key: Option<XOnlyPublicKey> => TapInternalKey(XOnlyPublicKey),
-         tap_tree: Option<TapTree> => TapTree(TapTree),
--        tap_key_origins: BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)> => TapKeyOrigin[XOnlyPublicKey]((Vec<TapLeafHash>, KeySource)),
-+        tap_key_origins: BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)> = TapKeyOrigins => TapKeyOrigin[XOnlyPublicKey]((TapLeafHashes, KeySource)),
-         proprietaries: BTreeMap<raw::ProprietaryKey, Vec<u8>> => Proprietary[raw::ProprietaryKey](Vec<u8>),
-         unknowns: BTreeMap<raw::Key, Vec<u8>> => Unknown[raw::Key](Vec<u8>),
-     },
+     /// [`UniqueId`].
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {
  
  /// Opaque byte-vector identifier for a PSBT output.
@@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Ou
  #[derive(Debug, Clone, PartialEq, Eq, Hash)]
  pub struct UniqueId(Vec<u8>);
  
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-         use bitcoin::bip32::{DerivationPath, Fingerprint};
-         use bitcoin::hashes::Hash;
-         use bitcoin::secp256k1::{Secp256k1, SecretKey};
--        use bitcoin::taproot::TaprootBuilder;
-+        use bitcoin::taproot::{TapLeafHash, TaprootBuilder};
-         use std::collections::BTreeMap;
- 
-         #[test]
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  ..output(1)
              };
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
              assert_eq!(joined.clone().try_unwrap(), Err(joined));
          }
  
-@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
-                 tap_tree: Some(TapTree::try_from(tap_tree).expect("complete tree")),
-                 tap_key_origins: BTreeMap::from([(
-                     x_only_public_key,
--                    (vec![TapLeafHash::from_byte_array([5; 32])], source),
-+                    (
-+                        TapLeafHashes::from(vec![TapLeafHash::from_byte_array([5; 32])]),
-+                        source,
-+                    ),
-                 )]),
-                 proprietaries: BTreeMap::from([(
-                     raw::ProprietaryKey {
 @@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
  
              #[test]
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
                  prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
              }
  
-
- ## crates/concurrent-psbt/src/psbt/tap_leaf_hashes.rs (new) ##
-@@
-+//! The leaf hashes of a BIP 371 taproot key origin.
-+
-+use std::collections::{BTreeMap, BTreeSet};
-+
-+use bitcoin::TapLeafHash;
-+use bitcoin::bip32::KeySource;
-+use bitcoin::secp256k1::XOnlyPublicKey;
-+
-+use super::joinable_struct_macro::MirroredField;
-+use crate::values::IdempotentValue;
-+
-+/// The leaf hashes of a taproot key in `PSBT_{IN,OUT}_TAP_BIP32_DERIVATION`.
-+///
-+/// Two values are equal when they hold the same hashes, in any order and with
-+/// any repetition. The hashes keep the order they were given in, and joining
-+/// equal values keeps the left one.
-+#[derive(Debug, Clone)]
-+pub struct TapLeafHashes(Vec<TapLeafHash>);
-+
-+impl TapLeafHashes {
-+    /// The leaf hashes, in the order they were given in.
-+    pub fn as_slice(&self) -> &[TapLeafHash] {
-+        &self.0
-+    }
-+
-+    fn set(&self) -> BTreeSet<&TapLeafHash> {
-+        self.0.iter().collect()
-+    }
-+}
-+
-+impl PartialEq for TapLeafHashes {
-+    fn eq(&self, other: &Self) -> bool {
-+        self.set() == other.set()
-+    }
-+}
-+
-+impl Eq for TapLeafHashes {}
-+
-+// Every value is built here, so sorting and deduplicating `leaves` here would
-+// make equal values structurally equal.
-+impl From<Vec<TapLeafHash>> for TapLeafHashes {
-+    fn from(leaves: Vec<TapLeafHash>) -> Self {
-+        Self(leaves)
-+    }
-+}
-+
-+impl From<TapLeafHashes> for Vec<TapLeafHash> {
-+    fn from(leaves: TapLeafHashes) -> Self {
-+        leaves.0
-+    }
-+}
-+
-+impl IdempotentValue for (TapLeafHashes, KeySource) {}
-+
-+/// `PSBT_{IN,OUT}_TAP_BIP32_DERIVATION` as psbt-v2 stores it.
-+type V2TapKeyOrigins = BTreeMap<XOnlyPublicKey, (Vec<TapLeafHash>, KeySource)>;
-+
-+/// Converts `tap_key_origins` between psbt-v2's leaf hash lists and
-+/// [`TapLeafHashes`].
-+pub(crate) enum TapKeyOrigins {}
-+
-+impl MirroredField for TapKeyOrigins {
-+    type V2 = V2TapKeyOrigins;
-+    type Value = BTreeMap<XOnlyPublicKey, (TapLeafHashes, KeySource)>;
-+
-+    fn from_v2(origins: Self::V2) -> Self::Value {
-+        origins
-+            .into_iter()
-+            .map(|(key, (leaves, source))| (key, (leaves.into(), source)))
-+            .collect()
-+    }
-+
-+    fn into_v2(origins: Self::Value) -> Self::V2 {
-+        origins
-+            .into_iter()
-+            .map(|(key, (leaves, source))| (key, (leaves.into(), source)))
-+            .collect()
-+    }
-+}
-+
-+#[cfg(all(test, feature = "prop-tests"))]
-+#[cfg_attr(coverage_nightly, coverage(off))]
-+mod tests {
-+    use bitcoin::bip32::{DerivationPath, Fingerprint};
-+    use bitcoin::hashes::Hash;
-+    use bitcoin::secp256k1::{Secp256k1, SecretKey};
-+    use proptest::prelude::*;
-+
-+    use super::*;
-+    use crate::Lift;
-+    use crate::lattice::join::Join;
-+    use crate::lattice::partial::{JoinResult, PartialJoin};
-+
-+    fn arb_leaves() -> impl Strategy<Value = Vec<TapLeafHash>> {
-+        proptest::collection::vec(0u8..3, 0..4).prop_map(|bytes| {
-+            bytes
-+                .into_iter()
-+                .map(|byte| TapLeafHash::from_byte_array([byte; 32]))
-+                .collect()
-+        })
-+    }
-+
-+    /// `leaves` in reverse, with each hash repeated.
-+    fn shuffled(leaves: &[TapLeafHash]) -> Vec<TapLeafHash> {
-+        leaves.iter().rev().flat_map(|&leaf| [leaf, leaf]).collect()
-+    }
-+
-+    fn arb_v2_origin() -> impl Strategy<Value = (Vec<TapLeafHash>, KeySource)> {
-+        (arb_leaves(), 0u8..2).prop_map(|(leaves, source)| {
-+            let source = (Fingerprint::from([source; 4]), DerivationPath::master());
-+            (leaves, source)
-+        })
-+    }
-+
-+    fn arb_origin() -> impl Strategy<Value = (TapLeafHashes, KeySource)> {
-+        arb_v2_origin().prop_map(|(leaves, source)| (leaves.into(), source))
-+    }
-+
-+    fn arb_result_origin() -> impl Strategy<Value = JoinResult<(TapLeafHashes, KeySource)>> {
-+        prop_oneof![
-+            arb_origin().prop_map(Ok),
-+            (arb_origin(), arb_origin()).prop_map(|(a, b)| a.wrap().join(b.wrap())),
-+        ]
-+    }
-+
-+    fn arb_v2_tap_key_origins() -> impl Strategy<Value = V2TapKeyOrigins> {
-+        proptest::collection::btree_map(1u8..4, arb_v2_origin(), 0..3).prop_map(|origins| {
-+            origins
-+                .into_iter()
-+                .map(|(seed, origin)| {
-+                    let secret_key = SecretKey::from_slice(&[seed; 32]).expect("nonzero seed");
-+                    (secret_key.x_only_public_key(&Secp256k1::new()).0, origin)
-+                })
-+                .collect()
-+        })
-+    }
-+
-+    assert_partial_join_laws!(arb_origin(), arb_result_origin());
-+
-+    proptest! {
-+        #[test]
-+        fn reordered_and_repeated_hashes_are_equal(a in arb_leaves()) {
-+            prop_assert_eq!(TapLeafHashes::from(shuffled(&a)), TapLeafHashes::from(a));
-+        }
-+
-+        #[test]
-+        fn an_extra_hash_is_unequal(a in arb_leaves(), extra in 3u8..6) {
-+            let mut b = a.clone();
-+            b.push(TapLeafHash::from_byte_array([extra; 32]));
-+            prop_assert_ne!(TapLeafHashes::from(a), TapLeafHashes::from(b));
-+        }
-+
-+        #[test]
-+        fn join_keeps_the_left_list(a in arb_leaves()) {
-+            let source = (Fingerprint::default(), DerivationPath::master());
-+            let left = (TapLeafHashes::from(a.clone()), source.clone());
-+            let right = (TapLeafHashes::from(shuffled(&a)), source);
-+            let (joined, _) = left.try_join(right).expect("equal values join");
-+            prop_assert_eq!(joined.as_slice(), a.as_slice());
-+        }
-+
-+        #[test]
-+        fn v2_round_trip_keeps_the_lists(origins in arb_v2_tap_key_origins()) {
-+            prop_assert_eq!(TapKeyOrigins::into_v2(TapKeyOrigins::from_v2(origins.clone())), origins);
-+        }
-+    }
-+}
-
- ## crates/concurrent-psbt/src/psbt/values.rs ##
-@@
- //! [`IdempotentValue`](crate::values::IdempotentValue) implementations for
- //! bitcoin and psbt-v2 types used as PSBT fields.
- 
--use crate::lattice::partial::{Conflict, JoinResult, PartialJoin};
- use crate::values::IdempotentValue;
- 
- impl IdempotentValue for bitcoin::absolute::Height {}
-@@ crates/concurrent-psbt/src/psbt/values.rs: impl IdempotentValue for psbt_v2::PsbtSighashType {}
- impl IdempotentValue for psbt_v2::Version {}
- 
- impl IdempotentValue for (bitcoin::ScriptBuf, bitcoin::taproot::LeafVersion) {}
--
--/// BIP 371 taproot BIP 32 derivation values: `(Vec<TapLeafHash>, KeySource)`.
--///
--/// The leaf-hash list is the set of tap leaves the key participates in; BIP 371
--/// imposes no ordering on it, so join equality is order-insensitive: two values
--/// join iff the key sources match and the leaf lists are equal as multisets.
--/// `self`'s representation (its leaf order) is kept on `Ok`.
--impl PartialJoin for (Vec<bitcoin::TapLeafHash>, bitcoin::bip32::KeySource) {
--    fn try_join(self, other: Self) -> JoinResult<Self> {
--        fn sorted(leaves: &[bitcoin::TapLeafHash]) -> Vec<bitcoin::TapLeafHash> {
--            let mut copy = leaves.to_vec();
--            copy.sort_unstable();
--            copy
--        }
--
--        if self.1 == other.1 && sorted(&self.0) == sorted(&other.0) {
--            Ok(self)
--        } else {
--            Err(Conflict::from_values([self, other]))
--        }
--    }
--}
--
--#[cfg(test)]
--#[cfg_attr(coverage_nightly, coverage(off))]
--mod tests {
--    #[cfg(feature = "unit-tests")]
--    mod unit {
--        use bitcoin::TapLeafHash;
--        use bitcoin::bip32::{DerivationPath, Fingerprint, KeySource};
--        use bitcoin::hashes::Hash;
--
--        use crate::lattice::partial::{Conflict, PartialJoin};
--
--        fn key_source() -> KeySource {
--            (Fingerprint::from([0u8; 4]), DerivationPath::master())
--        }
--
--        fn leaf(byte: u8) -> TapLeafHash {
--            TapLeafHash::from_byte_array([byte; 32])
--        }
--
--        #[test]
--        fn reordered_tap_leaf_hashes_join_ok() {
--            let a = (vec![leaf(1), leaf(2)], key_source());
--            let b = (vec![leaf(2), leaf(1)], key_source());
--            // Same leaves as a multiset: joins Ok, keeping self's representation.
--            assert_eq!(a.clone().try_join(b), Ok(a));
--        }
--
--        #[test]
--        fn different_tap_leaf_hashes_conflict() {
--            let a = (vec![leaf(1)], key_source());
--            let b = (vec![leaf(2)], key_source());
--            assert_eq!(
--                a.clone().try_join(b.clone()),
--                Err(Conflict::from_values([a, b]))
--            );
--        }
--    }
--
--    #[cfg(feature = "prop-tests")]
--    mod prop {
--        use bitcoin::TapLeafHash;
--        use bitcoin::bip32::{DerivationPath, Fingerprint, KeySource};
--        use bitcoin::hashes::Hash;
--        use proptest::prelude::*;
--
--        use crate::lattice::partial::PartialJoin;
--
--        fn key_source(byte: u8) -> KeySource {
--            (Fingerprint::from([byte; 4]), DerivationPath::master())
--        }
--
--        fn leaves(bytes: &[u8]) -> Vec<TapLeafHash> {
--            bytes
--                .iter()
--                .map(|byte| TapLeafHash::from_byte_array([*byte; 32]))
--                .collect()
--        }
--
--        proptest! {
--            #[test]
--            fn different_key_sources_conflict(bytes in proptest::collection::vec(any::<u8>(), 0..8)) {
--                let a = (leaves(&bytes), key_source(0));
--                let b = (leaves(&bytes), key_source(1));
--                prop_assert!(a.try_join(b).is_err());
--            }
--        }
--    }
--}

@github-actions

Copy link
Copy Markdown
range-diff for force push 3e19b232fd → 8c2e1d8f34 November 16, 2026 04:57 UTC: 3 modified, 1 dropped; 4 → 3 commits; base 3e0c2248af → 0e4597c7b1 (descendant, 1 commit ahead)

reproduce: git range-diff 3e0c224..3e19b23 0e4597c..8c2e1d8

1:  e1f2b28b81 +585 -662 18f < -:  ----------               Lift PSBT fields recursively and retain typed conflict paths
2:  62f3e27701 +560 -268  8f ! 1:  aca5c18ed5 +560 -268  8f define own Global, Input and Output structs
3:  e28987387e +285  -89  6f ! 2:  5d7cad32fd +285  -89  6f require a unique ID on every Output
4:  3e19b232fd +148  -55  4f ! 3:  8c2e1d8f34 +149  -56  4f Exercise owned PSBT conflict paths and conversions
2: 62f3e27701 ! 1: aca5c18ed5 define own Global, Input and Output structs
@@ crates/concurrent-psbt/src/psbt/mod.rs
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::key::{PublicKey, XOnlyPublicKey};
  use bitcoin::taproot::{TapLeafHash, TapTree};
- use bitcoin::{Amount, ScriptBuf, TapLeafHash};
+ use bitcoin::{Amount, ScriptBuf};
  use psbt_v2::raw;
 -use psbt_v2::v2::Output;
3: e28987387e ! 2: 5d7cad32fd require a unique ID on every Output
@@ crates/concurrent-psbt/src/psbt/mod.rs: mod joinable_struct_macro;
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@ crates/concurrent-psbt/src/psbt/output.rs: use bitcoin::taproot::{TapLeafHash, TapTree};
- use bitcoin::{Amount, ScriptBuf, TapLeafHash};
+ use bitcoin::{Amount, ScriptBuf};
  use psbt_v2::raw;
  
 +use super::proprietary::ProprietaryField;
4: 3e19b232fd ! 3: 8c2e1d8f34 Exercise owned PSBT conflict paths and conversions
@@ crates/concurrent-psbt/src/psbt/output.rs
  use bitcoin::bip32::KeySource;
  use bitcoin::key::{PublicKey, XOnlyPublicKey};
 -use bitcoin::taproot::{TapLeafHash, TapTree};
+-use bitcoin::{Amount, ScriptBuf};
 +use bitcoin::taproot::TapTree;
- use bitcoin::{Amount, ScriptBuf, TapLeafHash};
++use bitcoin::{Amount, ScriptBuf, TapLeafHash};
  use psbt_v2::raw;
  
  use super::proprietary::ProprietaryField;

//! Per-output field type and output set merging.
//!
//! [`ResultOutput`] wraps each per-output field in the internal result domain.
//! `OutputSet` and `ResultOutputSet` are sets of outputs identified by their

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set docs name types the crate lacks

The new input and output module docs present InputSet/ResultInputSet and OutputSet/ResultOutputSet as the set types, and the UniqueId doc repeats OutputSet, but no such items exist in the crate at this commit; the documented join behavior describes API readers cannot find or use.

/// OutputSet.

— fungi-protocol/concurrent-psbt@8c2e1d8 · crates/concurrent-psbt/src/psbt/output.rs#L111

oakagent · automated · 8c2e1d8

@github-actions

Copy link
Copy Markdown
range-diff for force push 8c2e1d8f34 → 50eab5bc68 November 16, 2026 23:40 UTC: 1 modified, 2 unchanged; 3 commits; same base 0e4597c7b1

reproduce: git range-diff 0e4597c..8c2e1d8 0e4597c..50eab5b

1:  aca5c18ed5 +560 -268 8f = 1:  aca5c18ed5 +560 -268 8f define own Global, Input and Output structs
2:  5d7cad32fd +285  -89 6f = 2:  5d7cad32fd +285  -89 6f require a unique ID on every Output
3:  8c2e1d8f34 +149  -56 4f ! 3:  50eab5bc68 +145  -56 4f Exercise owned PSBT conflict paths and conversions
3: 8c2e1d8f34 ! 3: 50eab5bc68 Exercise owned PSBT conflict paths and conversions
@@ crates/concurrent-psbt/src/psbt/input.rs
 @@
  #![allow(clippy::result_large_err)]
  
-+//! Per-input field type and input set merging.
++//! PSBT input fields.
 +//!
-+//! [`ResultInput`] wraps each per-input field in the internal result domain.
-+//! `InputSet` and `ResultInputSet` are sets of inputs identified by the
-+//! outpoint each spends. Joining two sets joins the inputs that spend the same
-+//! outpoint field by field, and fields that differ become conflicts.
++//! [`ResultInput`] joins fields independently, retaining incompatible values
++//! as conflicts.
 +
  use std::collections::BTreeMap;
  
@@ crates/concurrent-psbt/src/psbt/output.rs
 @@
  #![allow(clippy::result_large_err)]
  
-+//! Per-output field type and output set merging.
++//! PSBT output fields.
 +//!
-+//! [`ResultOutput`] wraps each per-output field in the internal result domain.
-+//! `OutputSet` and `ResultOutputSet` are sets of outputs identified by their
-+//! [`UniqueId`]. Joining two sets joins the outputs that have the same unique ID
-+//! field by field, and fields that differ become conflicts.
++//! [`ResultOutput`] joins fields independently, retaining incompatible values
++//! as conflicts.
 +
  use std::collections::BTreeMap;
  
@@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Ou
 -/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Used as the map key in `OutputSet`
 -/// so that outputs can be merged in an order-independent way.
 +/// Stored in the `PSBT_OUT_UNIQUE_ID` proprietary field, subtype
-+/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output within an
-+/// `OutputSet`.
++/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output independently of its
++/// position in a transaction.
  ///
 -/// Built with [`TryFrom`], a unique ID is 1 to [`UniqueId::MAX_LEN`] bytes
 -/// long, as is one read from a BIP 370 output. An empty ID would make

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

define our own instead of reusing upstream Input, Output and Global structs Unique Output id potential follow up

3 participants