Skip to content

Introduce InputSet, keyed by outpoint - #79

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

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

Conversation

@yuval-block

Copy link
Copy Markdown
Collaborator

Abstractly this is an unordered set of Input structs. Concretely, it is a hashmap keyed by the spent coin's outpoint, so that recursive merging merges disjoint field values associated with the same input.

@yuval-block
yuval-block added this pull request to stack #81 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 input-set 213e6e2 +/-
100% 100% 0%
View coverage of the 10 most impacted files.
File keyed-set 5f4ab3b input-set 213e6e2 +/-
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...bt/input_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:56 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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@yuval-block
yuval-block marked this pull request as ready for review November 12, 2026 23:17
@github-actions

This comment has been minimized.

@github-actions

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

reproduce: git range-diff 60e06c9..77d58e9 dcf9f5d..95c869e

1:  77d58e903b +337 -44 4f = 1:  95c869edff +337 -44 4f Introduce InputSet, keyed by outpoint

@github-actions

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

reproduce: git range-diff 60e06c9..77d58e9 dcf9f5d..95c869e

1:  77d58e903b +337 -44 4f = 1:  95c869edff +337 -44 4f Introduce InputSet, keyed by outpoint

@github-actions

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

reproduce: git range-diff dcf9f5d..95c869e 25198c9..2a7612e

1:  95c869edff +337 -44 4f = 1:  2a7612e4db +337 -44 4f Introduce InputSet, keyed by outpoint

@github-actions

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

reproduce: git range-diff dcf9f5d..95c869e 25198c9..2a7612e

1:  95c869edff +337 -44 4f = 1:  2a7612e4db +337 -44 4f Introduce InputSet, keyed by outpoint

@github-actions

Copy link
Copy Markdown
range-diff for force push 2a7612e4db → 35910fca22 November 16, 2026 03:19 UTC: 1 modified; 1 commit; base 25198c9ee7 → a09dc87596 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 25198c9..2a7612e a09dc87..35910fc

1:  2a7612e4db +337 -44 4f ! 1:  35910fca22 +315  -1 3f Introduce InputSet, keyed by outpoint
1: 2a7612e4db ! 1: 35910fca22 Introduce InputSet, keyed by outpoint
@@ Commit message
     hashmap keyed by the spent coin's outpoint, so that recursive merging merges
     disjoint field values associated with the same input.
 
- ## 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/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: pub(crate) fn out_point(input: &Input) -> OutPoint {
      }
  }
@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input)
 +pub use super::input_set::{DuplicateInput, InputSet, ResultInputSet};
  #[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 {
-     }
- 
-     #[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
-+                    },
-+                )
-+        }
+ pub(crate) mod tests {
+@@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) mod tests {
  
          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()]) {
 +            fn wrap_try_unwrap_roundtrip(i in 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);
-             }
- 
-@@ crates/concurrent-psbt/src/psbt/input.rs: mod tests {
-             fn is_ok_iff_try_unwrap_succeeds(r in arb_result_input()) {
-                 prop_assert_eq!(r.is_ok(), r.try_unwrap().is_ok());
-             }
--
-         }
-+
-+        assert_join_laws!(arb_result_input());
-     }
- }
 
  ## crates/concurrent-psbt/src/psbt/input_set.rs (new) ##
 @@
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +
 +use bitcoin::OutPoint;
 +
++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::input::{Input, ResultInput, out_point};
 +use super::keyed_set::{Freezable, KeyedSet, ResultKeyedSet};
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +
 +    /// Lift into the result domain as a conflict-free [`ResultInputSet`].
 +    pub fn wrap(self) -> ResultInputSet {
-+        ResultInputSet(self.0.wrap(Input::wrap))
++        ResultInputSet(self.0.wrap())
 +    }
 +
 +    /// Freeze the set, as a PSBT's inputs are once they are no longer
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +}
 +
 +impl ResultInputSet {
++    /// 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::InputMembership(evidence),
++            SetConflict::Entry { key, conflict } => PsbtConflict::Input {
++                outpoint: key,
++                conflict,
++            },
++        })
++    }
++
 +    /// Return the number of inputs, or the conflicting sizes of the frozen
 +    /// sets and the inputs if they disagree.
 +    pub fn len(&self) -> JoinResult<usize> {
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +    }
 +}
 +
++impl Lift for InputSet {
++    type Result = ResultInputSet;
++
++    fn wrap(self) -> Self::Result {
++        Self::wrap(self)
++    }
++}
++
++impl ResultWrapped for ResultInputSet {
++    type Clean = InputSet;
++
++    fn is_ok(&self) -> bool {
++        Self::is_ok(self)
++    }
++
++    fn try_unwrap(self) -> Result<Self::Clean, Self> {
++        Self::try_unwrap(self)
++    }
++}
++
++impl Conflicts for ResultInputSet {
++    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 {
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +}
 
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
-@@
+@@ crates/concurrent-psbt/src/psbt/mod.rs: mod conflict_macro;
  mod joinable_struct_macro;
- pub(crate) mod global;
+ pub mod global;
  pub mod input;
 +mod input_set;
  #[cfg_attr(

@github-actions

Copy link
Copy Markdown
range-diff for force push 35910fca22 → 154a985bb1 November 16, 2026 03:38 UTC: 1 unchanged; 1 commit; base a09dc87596 → 103b805377 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff a09dc87..35910fc 103b805..154a985

1:  35910fca22 +315 -1 3f = 1:  154a985bb1 +315 -1 3f Introduce InputSet, keyed by outpoint

@github-actions

Copy link
Copy Markdown
range-diff for force push 154a985bb1 → 0bb6eb55fd November 16, 2026 03:47 UTC: 1 modified; 1 commit; base 103b805377 → 9442a7d917 (diverged, 5 ahead and 5 behind)

reproduce: git range-diff 103b805..154a985 9442a7d..0bb6eb5

1:  154a985bb1 +315 -1 3f ! 1:  0bb6eb55fd +446 -1 4f Introduce InputSet, keyed by outpoint
1: 154a985bb1 ! 1: 0bb6eb55fd Introduce InputSet, keyed by outpoint
@@ crates/concurrent-psbt/src/psbt/input_set.rs (new)
 +}
 
  ## crates/concurrent-psbt/src/psbt/mod.rs ##
-@@ crates/concurrent-psbt/src/psbt/mod.rs: mod conflict_macro;
+@@
  mod joinable_struct_macro;
  pub mod global;
  pub mod input;
@@ crates/concurrent-psbt/src/psbt/mod.rs: mod conflict_macro;
  #[cfg_attr(
      not(test),
      expect(
+
+ ## crates/concurrent-psbt/tests/input_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::hashes::Hash;
++    use bitcoin::{OutPoint, Sequence, Txid};
++    use concurrent_psbt::conflicts::{ConflictPath, PsbtConflict};
++    use concurrent_psbt::input::{Input, InputConflict, InputField, InputSet};
++    use concurrent_psbt::{Conflicts, Join, Lift, ResultWrapped};
++
++    fn input(outpoint: &OutPoint, sequence: u32) -> Input {
++        let mut input = Input::new(outpoint);
++        input.set_sequence(Some(Sequence(sequence)));
++        input
++    }
++
++    // Exercise clean joins, field conflicts, membership conflicts, and both
++    // together. Each case also runs through the public generic trait surface.
++    fn check_input_set_contract(tag: u8, sequence: u32, outer_key: u8) {
++        let common = OutPoint {
++            txid: Txid::from_byte_array([tag; 32]),
++            vout: 0,
++        };
++        let extra = OutPoint { vout: 1, ..common };
++        for frozen in [false, true] {
++            for field_conflict in [false, true] {
++                let other_sequence = if field_conflict {
++                    sequence.wrapping_add(1)
++                } else {
++                    sequence
++                };
++                let left = InputSet::try_from_inputs([input(&common, sequence)]).unwrap();
++                let left = if frozen { left.freeze() } else { left };
++                let right = InputSet::try_from_inputs([
++                    input(&common, other_sequence),
++                    input(&extra, sequence),
++                ])
++                .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::InputMembership(evidence) => {
++                            membership_count += 1;
++                            assert_eq!(path, ConflictPath::InputMembership);
++                            assert_eq!(evidence.unexpected, &extra);
++                            assert_eq!(evidence.frozen, &HashSet::from([common]));
++                        }
++                        PsbtConflict::Input {
++                            outpoint,
++                            conflict: InputConflict::Sequence { values },
++                        } => {
++                            field_count += 1;
++                            assert_eq!(outpoint, &common);
++                            assert_eq!(
++                                path,
++                                ConflictPath::Input {
++                                    outpoint: &common,
++                                    field: InputField::Sequence,
++                                }
++                            );
++                            assert_eq!(
++                                values.into_iter().copied().collect::<Vec<_>>(),
++                                [Sequence(sequence), Sequence(other_sequence)]
++                            );
++                        }
++                        other => panic!("unexpected input-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 input_set_traits_preserve_membership_and_field_conflicts() {
++        check_input_set_contract(7, 42, 9);
++    }
++
++    #[cfg(feature = "prop-tests")]
++    mod properties {
++        use super::*;
++        use proptest::prelude::*;
++
++        proptest! {
++            #[test]
++            fn input_set_traits_preserve_every_conflict(
++                tag in any::<u8>(), sequence in any::<u32>(), outer_key in any::<u8>(),
++            ) {
++                check_input_set_contract(tag, sequence, outer_key);
++            }
++        }
++    }
++}

@github-actions

Copy link
Copy Markdown
range-diff for force push 0bb6eb55fd → d01e05f2fe November 16, 2026 03:56 UTC: 1 modified; 1 commit; base 9442a7d917 → 15e3bcc2f7 (diverged, 2 ahead and 2 behind)

reproduce: git range-diff 9442a7d..0bb6eb5 15e3bcc..d01e05f

1:  0bb6eb55fd +446 -1 4f ! 1:  d01e05f2fe +585 -2 5f Introduce InputSet, keyed by outpoint
1: 0bb6eb55fd ! 1: d01e05f2fe Introduce InputSet, keyed by outpoint
@@ Commit message
     disjoint field values associated with the same input.
 
  ## 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.
+ 
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
      }
  }
@@ crates/concurrent-psbt/tests/input_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 d01e05f2fe → 34d3b4a033 November 16, 2026 04:05 UTC: 1 unchanged; 1 commit; base 15e3bcc2f7 → 52a877bd3e (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 15e3bcc..d01e05f 52a877b..34d3b4a

1:  d01e05f2fe +585 -2 5f = 1:  34d3b4a033 +585 -2 5f Introduce InputSet, keyed by outpoint

@github-actions

Copy link
Copy Markdown
range-diff for force push 34d3b4a033 → aab9d782cd November 16, 2026 04:09 UTC: 1 modified; 1 commit; base 52a877bd3e → fd8eb7e9dc (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 52a877b..34d3b4a fd8eb7e..aab9d78

1:  34d3b4a033 +585 -2 5f ! 1:  aab9d782cd +447 -2 4f Introduce InputSet, keyed by outpoint
1: 34d3b4a033 ! 1: aab9d782cd Introduce InputSet, keyed by outpoint
@@ crates/concurrent-psbt/tests/input_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 aab9d782cd → a587eaa8de November 16, 2026 04:25 UTC: 1 unchanged; 1 commit; base fd8eb7e9dc → bbeaafa8bf (diverged, 5 ahead and 5 behind)

reproduce: git range-diff fd8eb7e..aab9d78 bbeaafa..a587eaa

1:  aab9d782cd +447 -2 4f = 1:  a587eaa8de +447 -2 4f Introduce InputSet, keyed by outpoint

@github-actions

Copy link
Copy Markdown
range-diff for force push a587eaa8de → b97cb9cfc6 November 16, 2026 05:37 UTC: 1 unchanged; 1 commit; base bbeaafa8bf → 1aa57fc30c (diverged, 5 ahead and 5 behind)

reproduce: git range-diff bbeaafa..a587eaa 1aa57fc..b97cb9c

1:  a587eaa8de +447 -2 4f = 1:  b97cb9cfc6 +447 -2 4f Introduce InputSet, keyed by outpoint

Abstractly this is an unordered set of Input structs. Concretely, it is a
hashmap keyed by the spent coin's outpoint, so that recursive merging merges
disjoint field values associated with the same input.
@github-actions

Copy link
Copy Markdown
range-diff for force push b97cb9cfc6 → 834fd2a838 November 16, 2026 18:08 UTC: 1 unchanged; 1 commit; base 1aa57fc30c → 2e33c8cdd8 (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 1aa57fc..b97cb9c 2e33c8c..834fd2a

1:  b97cb9cfc6 +447 -2 4f = 1:  834fd2a838 +447 -2 4f Introduce InputSet, keyed by outpoint

@github-actions

Copy link
Copy Markdown
range-diff for force push 834fd2a838 → f52fcffb5d November 16, 2026 18:16 UTC: 1 unchanged; 1 commit; base 2e33c8cdd8 → 621eee135d (diverged, 1 ahead and 1 behind)

reproduce: git range-diff 2e33c8c..834fd2a 621eee1..f52fcff

1:  834fd2a838 +447 -2 4f = 1:  f52fcffb5d +447 -2 4f Introduce InputSet, keyed by outpoint

@github-actions

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

reproduce: git range-diff 621eee1..f52fcff 8393653..213e6e2

1:  f52fcffb5d +447 -2 4f ! 1:  213e6e2f9a +451 -4 4f Introduce InputSet, keyed by outpoint
1: f52fcffb5d ! 1: 213e6e2f9a Introduce InputSet, keyed by outpoint
@@ Commit message
 
  ## crates/concurrent-psbt/src/psbt/input.rs ##
 @@
- //! Per-input field type and input set merging.
+ #![allow(clippy::result_large_err)]
+ 
+-//! PSBT input fields.
++//! 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
+-//! [`ResultInput`] joins fields independently, retaining incompatible values
+-//! as conflicts.
++//! [`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.
++//! 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;
  
 @@ crates/concurrent-psbt/src/psbt/input.rs: pub(crate) fn out_point(input: &Input) -> OutPoint {
      }

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

3 participants