Skip to content

introduce OutputSet, keyed by unique output IDs - #78

Draft
yuval-block wants to merge 1 commit into
keyed-setfrom
output-set
Draft

yuval-block wants to merge 1 commit into
keyed-setfrom
output-set

Conversation

@yuval-block

Copy link
Copy Markdown
Collaborator

Abstractly this is an unordered set of Output structs. Concretely, it is a hashmap keyed by the unique output ID, so that recursive merging merges disjoint field values associated with the same output ID.

@yuval-block
yuval-block added this pull request to stack #80 November 11, 2026 23:19
@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

keyed-set 5f4ab3b output-set a51984c +/-
100% 100% 0%
View coverage of the 10 most impacted files.
File keyed-set 5f4ab3b output-set a51984c +/-
crates/concurre...ons/btreemap.rs 100% 100% 0%
crates/concurre...ions/hashmap.rs 100% 100% 0%
crates/concurre...bt/keyed_set.rs 0% 100% +100%
crates/concurre...t/output_set.rs 0% 100% +100%
crates/concurre...bt/conflicts.rs 0% 100% +100%
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 16, 2026 23:54 UTC

@github-actions

This comment has been minimized.

@yuval-block
yuval-block marked this pull request as draft November 12, 2026 00:30
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Base automatically changed from output-unique-id to struct-macro November 12, 2026 17:04
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@yuval-block
yuval-block removed this pull request from stack #80 November 12, 2026 18:49
@yuval-block
yuval-block changed the base branch from struct-macro to output-unique-id November 12, 2026 18:49
@yuval-block
yuval-block added this pull request to stack #92 November 12, 2026 18:49
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
range-diff for force push a69b68379f → a2a96b1b93 November 14, 2026 19:00 UTC: 1 unchanged; 1 commit; base c201e9eab7 → 7c6e9e7824 (diverged, 4 ahead and 4 behind)

reproduce: git range-diff c201e9e..a69b683 7c6e9e7..a2a96b1

1:  a69b68379f +296 -20 4f = 1:  a2a96b1b93 +296 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push a69b68379f → a2a96b1b93 November 14, 2026 19:00 UTC: 1 unchanged; 1 commit; base c201e9eab7 → 7c6e9e7824 (diverged, 4 ahead and 4 behind)

reproduce: git range-diff c201e9e..a69b683 7c6e9e7..a2a96b1

1:  a69b68379f +296 -20 4f = 1:  a2a96b1b93 +296 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push a2a96b1b93 → ea3545eb42 November 14, 2026 22:38 UTC: 1 unchanged; 1 commit; base 7c6e9e7824 → 584ccad50a (diverged, 5 ahead and 4 behind)

reproduce: git range-diff 7c6e9e7..a2a96b1 584ccad..ea3545e

1:  a2a96b1b93 +296 -20 4f = 1:  ea3545eb42 +296 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push a2a96b1b93 → ea3545eb42 November 14, 2026 22:38 UTC: 1 unchanged; 1 commit; base 7c6e9e7824 → 584ccad50a (diverged, 5 ahead and 4 behind)

reproduce: git range-diff 7c6e9e7..a2a96b1 584ccad..ea3545e

1:  a2a96b1b93 +296 -20 4f = 1:  ea3545eb42 +296 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push ea3545eb42 → 135b77cccd November 14, 2026 23:33 UTC: 1 modified; 1 commit; base 584ccad50a → d8b2490d95 (diverged, 2 ahead and 1 behind)

reproduce: git range-diff 584ccad..ea3545e d8b2490..135b77c

1:  ea3545eb42 +296 -20 4f ! 1:  135b77cccd +301 -20 4f introduce OutputSet, keyed by unique output IDs
1: ea3545eb42 ! 1: 135b77cccd introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +            )
 +                .prop_map(|(uid, amount, redeem, witness, props)| {
 +                    let mut output = output(uid, amount);
-+                    output.redeem_script = redeem.map(ScriptBuf::from_bytes);
-+                    output.witness_script = witness.map(ScriptBuf::from_bytes);
-+                    for (k, v) in props {
-+                        let prop_key = psbt_v2::raw::ProprietaryKey {
-+                            prefix: b"test".to_vec(),
-+                            subtype: k[0],
-+                            key: k,
-+                        };
-+                        output.proprietaries.insert(prop_key, v);
-+                    }
++                    output.set_redeem_script(redeem.map(ScriptBuf::from_bytes));
++                    output.set_witness_script(witness.map(ScriptBuf::from_bytes));
++                    output.set_proprietaries(
++                        props
++                            .into_iter()
++                            .map(|(k, v)| {
++                                let prop_key = psbt_v2::raw::ProprietaryKey {
++                                    prefix: b"test".to_vec(),
++                                    subtype: k[0],
++                                    key: k,
++                                };
++                                (prop_key, v)
++                            })
++                            .collect(),
++                    );
 +                    output
 +                })
 +        }

@github-actions

Copy link
Copy Markdown
range-diff for force push ea3545eb42 → 135b77cccd November 14, 2026 23:33 UTC: 1 modified; 1 commit; base 584ccad50a → d8b2490d95 (diverged, 2 ahead and 1 behind)

reproduce: git range-diff 584ccad..ea3545e d8b2490..135b77c

1:  ea3545eb42 +296 -20 4f ! 1:  135b77cccd +301 -20 4f introduce OutputSet, keyed by unique output IDs
1: ea3545eb42 ! 1: 135b77cccd introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +            )
 +                .prop_map(|(uid, amount, redeem, witness, props)| {
 +                    let mut output = output(uid, amount);
-+                    output.redeem_script = redeem.map(ScriptBuf::from_bytes);
-+                    output.witness_script = witness.map(ScriptBuf::from_bytes);
-+                    for (k, v) in props {
-+                        let prop_key = psbt_v2::raw::ProprietaryKey {
-+                            prefix: b"test".to_vec(),
-+                            subtype: k[0],
-+                            key: k,
-+                        };
-+                        output.proprietaries.insert(prop_key, v);
-+                    }
++                    output.set_redeem_script(redeem.map(ScriptBuf::from_bytes));
++                    output.set_witness_script(witness.map(ScriptBuf::from_bytes));
++                    output.set_proprietaries(
++                        props
++                            .into_iter()
++                            .map(|(k, v)| {
++                                let prop_key = psbt_v2::raw::ProprietaryKey {
++                                    prefix: b"test".to_vec(),
++                                    subtype: k[0],
++                                    key: k,
++                                };
++                                (prop_key, v)
++                            })
++                            .collect(),
++                    );
 +                    output
 +                })
 +        }

@github-actions

Copy link
Copy Markdown
range-diff for force push 135b77cccd → bbc6975fbb November 15, 2026 02:13 UTC: 1 unchanged; 1 commit; base d8b2490d95 → 60e06c9274 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff d8b2490..135b77c 60e06c9..bbc6975

1:  135b77cccd +301 -20 4f = 1:  bbc6975fbb +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 135b77cccd → bbc6975fbb November 15, 2026 02:15 UTC: 1 unchanged; 1 commit; base d8b2490d95 → 60e06c9274 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff d8b2490..135b77c 60e06c9..bbc6975

1:  135b77cccd +301 -20 4f = 1:  bbc6975fbb +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push bbc6975fbb → 9a23fc71d1 November 15, 2026 23:52 UTC: 1 unchanged; 1 commit; base 60e06c9274 → dcf9f5d0a3 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 60e06c9..bbc6975 dcf9f5d..9a23fc7

1:  bbc6975fbb +301 -20 4f = 1:  9a23fc71d1 +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push bbc6975fbb → 9a23fc71d1 November 15, 2026 23:52 UTC: 1 unchanged; 1 commit; base 60e06c9274 → dcf9f5d0a3 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 60e06c9..bbc6975 dcf9f5d..9a23fc7

1:  bbc6975fbb +301 -20 4f = 1:  9a23fc71d1 +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 9a23fc71d1 → 800d3772d5 November 16, 2026 00:16 UTC: 1 unchanged; 1 commit; base dcf9f5d0a3 → 25198c9ee7 (diverged, 2 ahead and 2 behind)

reproduce: git range-diff dcf9f5d..9a23fc7 25198c9..800d377

1:  9a23fc71d1 +301 -20 4f = 1:  800d3772d5 +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 9a23fc71d1 → 800d3772d5 November 16, 2026 00:22 UTC: 1 unchanged; 1 commit; base dcf9f5d0a3 → 25198c9ee7 (diverged, 2 ahead and 2 behind)

reproduce: git range-diff dcf9f5d..9a23fc7 25198c9..800d377

1:  9a23fc71d1 +301 -20 4f = 1:  800d3772d5 +301 -20 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 800d3772d5 → cd20f9d27a November 16, 2026 03:20 UTC: 1 modified; 1 commit; base 25198c9ee7 → a09dc87596 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 25198c9..800d377 a09dc87..cd20f9d

1:  800d3772d5 +301 -20 4f ! 1:  cd20f9d27a +329  -0 3f introduce OutputSet, keyed by unique output IDs
1: 800d3772d5 ! 1: cd20f9d27a introduce OutputSet, keyed by unique output IDs
@@ Commit message
     hashmap keyed by the unique output ID, so that recursive merging merges
     disjoint field values associated with the same output ID.
 
- ## crates/concurrent-psbt/src/collections/hashmap.rs ##
-@@ crates/concurrent-psbt/src/collections/hashmap.rs: where
- }
- 
- /// Extension trait for transforming `HashMap` values while preserving keys.
--#[cfg_attr(
--    not(test),
--    expect(
--        dead_code,
--        reason = "temporary helper is consumed by PSBT set wrappers in later commits"
--    )
--)]
- pub(crate) trait HashMapExt {
-     type Key;
-     type Value;
-@@ crates/concurrent-psbt/src/collections/hashmap.rs: impl<K: Hash + Eq, V> HashMapExt for HashMap<K, V> {
- }
- 
- /// Extension trait for result-domain `HashMap` values.
--#[cfg_attr(
--    not(test),
--    expect(
--        dead_code,
--        reason = "temporary helper is consumed by PSBT set wrappers in later commits"
--    )
--)]
- pub(crate) trait ResultHashMapExt: Sized {
-     type Key;
-     type Value: ResultValue;
-
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
 @@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod input;
  )]
@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod input;
  mod values;
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
-@@
- #![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;
-@@ 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: impl OutputUniqueIdExt for psbt_v2::v2::Output {
      }
  }
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 @@
 +//! Output sets keyed by unique output ID, in plain and result domains.
 +
++use super::conflicts::PsbtConflict;
++use super::keyed_set::SetConflict;
++use crate::lattice::conflicts::Conflicts;
 +use crate::lattice::join::Join;
 +use crate::lattice::partial::JoinResult;
++use crate::{Lift, ResultWrapped};
 +
 +use super::keyed_set::{Freezable, KeyedSet, ResultKeyedSet};
 +use super::output::{Output, ResultOutput, UniqueId};
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +    }
 +
 +    pub fn wrap(self) -> ResultOutputSet {
-+        ResultOutputSet(self.0.wrap(Output::wrap))
++        ResultOutputSet(self.0.wrap())
 +    }
 +
 +    /// Freeze the set, as a PSBT's outputs are once they are no longer
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +}
 +
 +impl ResultOutputSet {
++    /// Borrow membership conflicts and fully addressed entry conflicts.
++    /// Iteration order between entries is unspecified.
++    pub fn conflicts(&self) -> impl Iterator<Item = PsbtConflict<'_>> {
++        self.0.conflicts().map(|conflict| match conflict {
++            SetConflict::Membership(evidence) => PsbtConflict::OutputMembership(evidence),
++            SetConflict::Entry { key, conflict } => PsbtConflict::Output { id: key, conflict },
++        })
++    }
++
 +    /// Return the number of outputs, or the conflicting sizes of the frozen
 +    /// sets and the outputs if they disagree.
 +    pub fn len(&self) -> JoinResult<usize> {
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +    }
 +}
 +
++impl Lift for OutputSet {
++    type Result = ResultOutputSet;
++
++    fn wrap(self) -> Self::Result {
++        Self::wrap(self)
++    }
++}
++
++impl ResultWrapped for ResultOutputSet {
++    type Clean = OutputSet;
++
++    fn is_ok(&self) -> bool {
++        Self::is_ok(self)
++    }
++
++    fn try_unwrap(self) -> Result<Self::Clean, Self> {
++        Self::try_unwrap(self)
++    }
++}
++
++impl Conflicts for ResultOutputSet {
++    type Item<'a> = PsbtConflict<'a>;
++
++    fn conflicts(&self) -> impl Iterator<Item = Self::Item<'_>> {
++        Self::conflicts(self)
++    }
++}
++
 +#[cfg(test)]
 +#[cfg_attr(coverage_nightly, coverage(off))]
 +mod tests {

@github-actions

Copy link
Copy Markdown
range-diff for force push cd20f9d27a → efebbb0da3 November 16, 2026 03:59 UTC: 1 modified; 1 commit; base a09dc87596 → 15e3bcc2f7 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff a09dc87..cd20f9d 15e3bcc..efebbb0

1:  cd20f9d27a +329 -0 3f ! 1:  efebbb0da3 +591 -2 5f introduce OutputSet, keyed by unique output IDs
1: cd20f9d27a ! 1: efebbb0da3 introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod input;
  mod values;
 
  ## 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: impl From<Output> for psbt_v2::v2::Output {
+ ///
+ /// Stored in the `PSBT_OUT_UNIQUE_ID` proprietary field, subtype
+ /// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output within an
+-/// `OutputSet`.
++/// [`OutputSet`].
+ ///
+ /// 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
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl OutputUniqueIdExt for psbt_v2::v2::Output {
      }
  }
@@ crates/concurrent-psbt/src/psbt/output_set.rs (new)
 +        }
 +    }
 +}
+
+ ## crates/concurrent-psbt/tests/output_conflicts.rs (new) ##
+@@
++#![cfg(any(feature = "unit-tests", feature = "prop-tests"))]
++#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
++
++#[cfg_attr(coverage_nightly, coverage(off))]
++mod cases {
++    use std::collections::{HashMap, HashSet};
++
++    use bitcoin::{Amount, ScriptBuf};
++    use concurrent_psbt::conflicts::{ConflictPath, PsbtConflict};
++    use concurrent_psbt::output::{Output, OutputConflict, OutputField, OutputSet, UniqueId};
++    use concurrent_psbt::{Conflicts, Join, Lift, ResultWrapped};
++
++    fn output(id: &UniqueId, sats: u64) -> Output {
++        Output::new(id.clone(), Amount::from_sat(sats), ScriptBuf::new())
++    }
++
++    // A fixed ID joins field-by-field, while a second ID tests frozen-set
++    // evidence independently of the amount disagreement at the first ID.
++    fn check_output_set_contract(tag: u8, sats: u64, outer_key: u8) {
++        let common = UniqueId::try_from(vec![tag, 0]).unwrap();
++        let extra = UniqueId::try_from(vec![tag, 1]).unwrap();
++        for frozen in [false, true] {
++            for field_conflict in [false, true] {
++                let other_sats = if field_conflict { sats + 1 } else { sats };
++                let left = OutputSet::try_from_outputs([output(&common, sats)]).unwrap();
++                let left = if frozen { left.freeze() } else { left };
++                let right = OutputSet::try_from_outputs([
++                    output(&common, other_sats),
++                    output(&extra, sats),
++                ])
++                .unwrap();
++                let joined = Lift::wrap(left.clone()).join(Lift::wrap(right.clone()));
++                let expected_ok = !frozen && !field_conflict;
++                assert_eq!(ResultWrapped::is_ok(&joined), expected_ok);
++                let expected = if expected_ok {
++                    Ok(right.clone())
++                } else {
++                    Err(joined.clone())
++                };
++                assert_eq!(ResultWrapped::try_unwrap(joined.clone()), expected);
++
++                let mut membership_count = 0;
++                let mut field_count = 0;
++                let mut paths = Vec::new();
++                for conflict in Conflicts::conflicts(&joined) {
++                    let path = conflict.path();
++                    paths.push(path);
++                    match conflict {
++                        PsbtConflict::OutputMembership(evidence) => {
++                            membership_count += 1;
++                            assert_eq!(path, ConflictPath::OutputMembership);
++                            assert_eq!(evidence.unexpected, &extra);
++                            assert_eq!(evidence.frozen, &HashSet::from([common.clone()]));
++                        }
++                        PsbtConflict::Output {
++                            id,
++                            conflict: OutputConflict::Amount { values },
++                        } => {
++                            field_count += 1;
++                            assert_eq!(id, &common);
++                            assert_eq!(
++                                path,
++                                ConflictPath::Output {
++                                    id: &common,
++                                    field: OutputField::Amount,
++                                }
++                            );
++                            assert_eq!(
++                                values.into_iter().copied().collect::<Vec<_>>(),
++                                [Amount::from_sat(sats), Amount::from_sat(other_sats)]
++                            );
++                        }
++                        other => panic!("unexpected output-set conflict: {other:?}"),
++                    }
++                }
++                assert_eq!(membership_count, usize::from(frozen));
++                assert_eq!(field_count, usize::from(field_conflict));
++
++                let nested = HashMap::from([(outer_key, Some(left))])
++                    .wrap()
++                    .join(HashMap::from([(outer_key, Some(right.clone()))]).wrap());
++                let nested_paths: Vec<_> = Conflicts::conflicts(&nested)
++                    .map(|(key, conflict)| {
++                        assert_eq!(key, &outer_key);
++                        conflict.path()
++                    })
++                    .collect();
++                assert_eq!(nested_paths.len(), paths.len());
++                assert!(paths.iter().all(|path| nested_paths.contains(path)));
++                assert_eq!(ResultWrapped::is_ok(&nested), expected_ok);
++                let expected = if expected_ok {
++                    Ok(HashMap::from([(outer_key, Some(right))]))
++                } else {
++                    Err(nested.clone())
++                };
++                assert_eq!(ResultWrapped::try_unwrap(nested), expected);
++            }
++        }
++    }
++
++    #[cfg(feature = "unit-tests")]
++    #[test]
++    fn output_set_traits_preserve_membership_and_field_conflicts() {
++        check_output_set_contract(7, 42, 9);
++    }
++
++    #[cfg(feature = "prop-tests")]
++    mod properties {
++        use super::*;
++        use proptest::prelude::*;
++
++        proptest! {
++            #[test]
++            fn output_set_traits_preserve_every_conflict(
++                tag in any::<u8>(), sats in 0u64..=2_100_000_000_000_000,
++                outer_key in any::<u8>(),
++            ) {
++                check_output_set_contract(tag, sats, outer_key);
++            }
++        }
++    }
++}
+
+ ## crates/concurrent-psbt/tests/psbt_conflict_paths.rs (new) ##
+@@
++#![cfg(any(feature = "unit-tests", feature = "prop-tests"))]
++#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
++
++#[cfg_attr(coverage_nightly, coverage(off))]
++mod cases {
++    use bitcoin::hashes::Hash;
++    use bitcoin::{Amount, OutPoint, ScriptBuf, Txid};
++    use concurrent_psbt::Join;
++    use concurrent_psbt::conflicts::{ConflictPath, MembershipConflict, PsbtConflict};
++    use concurrent_psbt::global::{Global, GlobalConflict, GlobalField};
++    use concurrent_psbt::input::{Input, InputConflict, InputField};
++    use concurrent_psbt::output::{Output, OutputConflict, OutputField, UniqueId};
++    use psbt_v2::raw;
++    use std::collections::{BTreeMap, HashSet};
++
++    fn check_locations(tag: u8, keydata: Vec<u8>) {
++        let keys: Vec<_> = (0..3)
++            .map(|scope| {
++                let mut key = keydata.clone();
++                key.push(scope);
++                raw::Key {
++                    type_value: 0x80,
++                    key,
++                }
++            })
++            .collect();
++        let outpoint = OutPoint {
++            txid: Txid::from_byte_array([tag; 32]),
++            vout: 0,
++        };
++        let extra_outpoint = OutPoint {
++            vout: 1,
++            ..outpoint
++        };
++        let id = UniqueId::try_from(vec![tag, 0]).unwrap();
++        let extra_id = UniqueId::try_from(vec![tag, 1]).unwrap();
++        let fields = |scope: usize, value| BTreeMap::from([(keys[scope].clone(), vec![value])]);
++        let global = |value| {
++            let mut global = Global::default();
++            global.set_unknowns(fields(0, value));
++            global
++        };
++        let input = |value| {
++            let mut input = Input::new(&outpoint);
++            input.set_unknowns(fields(1, value));
++            input
++        };
++        let output = |value| {
++            let mut output = Output::new(id.clone(), Amount::from_sat(42), ScriptBuf::new());
++            output.set_unknowns(fields(2, value));
++            output
++        };
++        let other = tag.wrapping_add(1);
++        let global = global(tag).wrap().join(global(other).wrap());
++        let input = input(tag).wrap().join(input(other).wrap());
++        let output = output(tag).wrap().join(output(other).wrap());
++        let mut diagnostics: Vec<_> = global
++            .conflicts()
++            .map(PsbtConflict::Global)
++            .chain(input.conflicts().map(|conflict| PsbtConflict::Input {
++                outpoint: &outpoint,
++                conflict,
++            }))
++            .chain(
++                output
++                    .conflicts()
++                    .map(|conflict| PsbtConflict::Output { id: &id, conflict }),
++            )
++            .collect();
++        for diagnostic in &diagnostics {
++            let values = match diagnostic {
++                PsbtConflict::Global(GlobalConflict::Unknown { values, .. })
++                | PsbtConflict::Input {
++                    conflict: InputConflict::Unknown { values, .. },
++                    ..
++                }
++                | PsbtConflict::Output {
++                    conflict: OutputConflict::Unknown { values, .. },
++                    ..
++                } => values,
++                other => panic!("unexpected conflict: {other:?}"),
++            };
++            assert_eq!(
++                values.into_iter().cloned().collect::<Vec<_>>(),
++                [vec![tag], vec![other]]
++            );
++        }
++        let frozen_inputs = HashSet::from([outpoint]);
++        let frozen_outputs = HashSet::from([id.clone()]);
++        diagnostics.push(PsbtConflict::InputMembership(MembershipConflict {
++            frozen: &frozen_inputs,
++            unexpected: &extra_outpoint,
++        }));
++        diagnostics.push(PsbtConflict::OutputMembership(MembershipConflict {
++            frozen: &frozen_outputs,
++            unexpected: &extra_id,
++        }));
++        assert_eq!(
++            diagnostics
++                .iter()
++                .map(PsbtConflict::path)
++                .collect::<Vec<_>>(),
++            [
++                ConflictPath::Global(GlobalField::Unknown(&keys[0])),
++                ConflictPath::Input {
++                    outpoint: &outpoint,
++                    field: InputField::Unknown(&keys[1])
++                },
++                ConflictPath::Output {
++                    id: &id,
++                    field: OutputField::Unknown(&keys[2])
++                },
++                ConflictPath::InputMembership,
++                ConflictPath::OutputMembership,
++            ]
++        );
++    }
++
++    #[cfg(feature = "unit-tests")]
++    #[test]
++    fn diagnostics_locate_each_scope_and_its_keydata() {
++        check_locations(7, vec![1, 2]);
++    }
++
++    #[cfg(feature = "prop-tests")]
++    mod properties {
++        use super::*;
++        use proptest::prelude::*;
++        proptest! {
++            #[test]
++            fn diagnostic_paths_keep_scope_identity_and_keydata(
++                tag in any::<u8>(), keydata in proptest::collection::vec(any::<u8>(), 0..8),
++            ) {
++                check_locations(tag, keydata);
++            }
++        }
++    }
++}

@github-actions

Copy link
Copy Markdown
range-diff for force push efebbb0da3 → 30e91d517e November 16, 2026 04:13 UTC: 1 modified; 1 commit; base 15e3bcc2f7 → fd8eb7e9dc (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 15e3bcc..efebbb0 fd8eb7e..30e91d5

1:  efebbb0da3 +591 -2 5f ! 1:  30e91d517e +453 -2 4f introduce OutputSet, keyed by unique output IDs
1: efebbb0da3 ! 1: 30e91d517e introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/tests/output_conflicts.rs (new)
 +        }
 +    }
 +}
-
- ## crates/concurrent-psbt/tests/psbt_conflict_paths.rs (new) ##
-@@
-+#![cfg(any(feature = "unit-tests", feature = "prop-tests"))]
-+#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
-+
-+#[cfg_attr(coverage_nightly, coverage(off))]
-+mod cases {
-+    use bitcoin::hashes::Hash;
-+    use bitcoin::{Amount, OutPoint, ScriptBuf, Txid};
-+    use concurrent_psbt::Join;
-+    use concurrent_psbt::conflicts::{ConflictPath, MembershipConflict, PsbtConflict};
-+    use concurrent_psbt::global::{Global, GlobalConflict, GlobalField};
-+    use concurrent_psbt::input::{Input, InputConflict, InputField};
-+    use concurrent_psbt::output::{Output, OutputConflict, OutputField, UniqueId};
-+    use psbt_v2::raw;
-+    use std::collections::{BTreeMap, HashSet};
-+
-+    fn check_locations(tag: u8, keydata: Vec<u8>) {
-+        let keys: Vec<_> = (0..3)
-+            .map(|scope| {
-+                let mut key = keydata.clone();
-+                key.push(scope);
-+                raw::Key {
-+                    type_value: 0x80,
-+                    key,
-+                }
-+            })
-+            .collect();
-+        let outpoint = OutPoint {
-+            txid: Txid::from_byte_array([tag; 32]),
-+            vout: 0,
-+        };
-+        let extra_outpoint = OutPoint {
-+            vout: 1,
-+            ..outpoint
-+        };
-+        let id = UniqueId::try_from(vec![tag, 0]).unwrap();
-+        let extra_id = UniqueId::try_from(vec![tag, 1]).unwrap();
-+        let fields = |scope: usize, value| BTreeMap::from([(keys[scope].clone(), vec![value])]);
-+        let global = |value| {
-+            let mut global = Global::default();
-+            global.set_unknowns(fields(0, value));
-+            global
-+        };
-+        let input = |value| {
-+            let mut input = Input::new(&outpoint);
-+            input.set_unknowns(fields(1, value));
-+            input
-+        };
-+        let output = |value| {
-+            let mut output = Output::new(id.clone(), Amount::from_sat(42), ScriptBuf::new());
-+            output.set_unknowns(fields(2, value));
-+            output
-+        };
-+        let other = tag.wrapping_add(1);
-+        let global = global(tag).wrap().join(global(other).wrap());
-+        let input = input(tag).wrap().join(input(other).wrap());
-+        let output = output(tag).wrap().join(output(other).wrap());
-+        let mut diagnostics: Vec<_> = global
-+            .conflicts()
-+            .map(PsbtConflict::Global)
-+            .chain(input.conflicts().map(|conflict| PsbtConflict::Input {
-+                outpoint: &outpoint,
-+                conflict,
-+            }))
-+            .chain(
-+                output
-+                    .conflicts()
-+                    .map(|conflict| PsbtConflict::Output { id: &id, conflict }),
-+            )
-+            .collect();
-+        for diagnostic in &diagnostics {
-+            let values = match diagnostic {
-+                PsbtConflict::Global(GlobalConflict::Unknown { values, .. })
-+                | PsbtConflict::Input {
-+                    conflict: InputConflict::Unknown { values, .. },
-+                    ..
-+                }
-+                | PsbtConflict::Output {
-+                    conflict: OutputConflict::Unknown { values, .. },
-+                    ..
-+                } => values,
-+                other => panic!("unexpected conflict: {other:?}"),
-+            };
-+            assert_eq!(
-+                values.into_iter().cloned().collect::<Vec<_>>(),
-+                [vec![tag], vec![other]]
-+            );
-+        }
-+        let frozen_inputs = HashSet::from([outpoint]);
-+        let frozen_outputs = HashSet::from([id.clone()]);
-+        diagnostics.push(PsbtConflict::InputMembership(MembershipConflict {
-+            frozen: &frozen_inputs,
-+            unexpected: &extra_outpoint,
-+        }));
-+        diagnostics.push(PsbtConflict::OutputMembership(MembershipConflict {
-+            frozen: &frozen_outputs,
-+            unexpected: &extra_id,
-+        }));
-+        assert_eq!(
-+            diagnostics
-+                .iter()
-+                .map(PsbtConflict::path)
-+                .collect::<Vec<_>>(),
-+            [
-+                ConflictPath::Global(GlobalField::Unknown(&keys[0])),
-+                ConflictPath::Input {
-+                    outpoint: &outpoint,
-+                    field: InputField::Unknown(&keys[1])
-+                },
-+                ConflictPath::Output {
-+                    id: &id,
-+                    field: OutputField::Unknown(&keys[2])
-+                },
-+                ConflictPath::InputMembership,
-+                ConflictPath::OutputMembership,
-+            ]
-+        );
-+    }
-+
-+    #[cfg(feature = "unit-tests")]
-+    #[test]
-+    fn diagnostics_locate_each_scope_and_its_keydata() {
-+        check_locations(7, vec![1, 2]);
-+    }
-+
-+    #[cfg(feature = "prop-tests")]
-+    mod properties {
-+        use super::*;
-+        use proptest::prelude::*;
-+        proptest! {
-+            #[test]
-+            fn diagnostic_paths_keep_scope_identity_and_keydata(
-+                tag in any::<u8>(), keydata in proptest::collection::vec(any::<u8>(), 0..8),
-+            ) {
-+                check_locations(tag, keydata);
-+            }
-+        }
-+    }
-+}

@github-actions

Copy link
Copy Markdown
range-diff for force push 30e91d517e → 935a180af6 November 16, 2026 04:27 UTC: 1 unchanged; 1 commit; base fd8eb7e9dc → bbeaafa8bf (diverged, 5 ahead and 5 behind)

reproduce: git range-diff fd8eb7e..30e91d5 bbeaafa..935a180

1:  30e91d517e +453 -2 4f = 1:  935a180af6 +453 -2 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 935a180af6 → 79f823da84 November 16, 2026 05:39 UTC: 1 modified; 1 commit; base bbeaafa8bf → 1aa57fc30c (diverged, 5 ahead and 5 behind)

reproduce: git range-diff bbeaafa..935a180 1aa57fc..79f823d

1:  935a180af6 +453 -2 4f ! 1:  79f823da84 +453 -2 4f introduce OutputSet, keyed by unique output IDs
1: 935a180af6 ! 1: 79f823da84 introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod input;
  pub mod output;
 +mod output_set;
  pub(crate) mod proprietary;
- mod tap_leaf_hashes;
  mod values;
+ 
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@

@oakagent oakagent left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typos in what this pull request adds:

crates/concurrent-psbt/tests/output_conflicts.rs

  • l.18 - "the amount disagreement" → "the amount of disagreement"

oakagent · automated

Abstractly this is an unordered set of Output structs. Concretely, it is a
hashmap keyed by the unique output ID, so that recursive merging merges
disjoint field values associated with the same output ID.
@github-actions

Copy link
Copy Markdown
range-diff for force push 79f823da84 → 549f48422c November 16, 2026 18:17 UTC: 1 unchanged; 1 commit; base 1aa57fc30c → 621eee135d (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 1aa57fc..79f823d 621eee1..549f484

1:  79f823da84 +453 -2 4f = 1:  549f48422c +453 -2 4f introduce OutputSet, keyed by unique output IDs

@github-actions

Copy link
Copy Markdown
range-diff for force push 549f48422c → a51984cb7c November 16, 2026 23:41 UTC: 1 modified; 1 commit; base 621eee135d → 839365306e (diverged, 2 ahead and 2 behind)

reproduce: git range-diff 621eee1..549f484 8393653..a51984c

1:  549f48422c +453 -2 4f ! 1:  a51984cb7c +458 -5 4f introduce OutputSet, keyed by unique output IDs
1: 549f48422c ! 1: a51984cb7c introduce OutputSet, keyed by unique output IDs
@@ crates/concurrent-psbt/src/psbt/mod.rs: pub mod input;
 
  ## crates/concurrent-psbt/src/psbt/output.rs ##
 @@
- //! Per-output field type and output set merging.
+ #![allow(clippy::result_large_err)]
+ 
+-//! PSBT output fields.
++//! 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
+-//! [`ResultOutput`] joins fields independently, retaining incompatible values
+-//! as conflicts.
++//! [`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.
++//! [`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;
  
 @@ crates/concurrent-psbt/src/psbt/output.rs: impl From<Output> for psbt_v2::v2::Output {
+ /// Opaque byte-vector identifier for a PSBT output.
  ///
  /// 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.
++/// [`PSBT_OUT_UNIQUE_ID_SUBTYPE`]. Identifies an output within an
 +/// [`OutputSet`].
  ///
  /// A unique ID built with [`TryFrom`] or read from a BIP 370 output is 1 to

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.

UnorderedPsbt with PartialJoin

4 participants