Skip to content

introduce output.UniqueId - #91

Merged
yuval-block merged 1 commit into
mainfrom
output-unique-id
Nov 13, 2026
Merged

yuval-block merged 1 commit into
mainfrom
output-unique-id

Conversation

@yuval-block

Copy link
Copy Markdown
Collaborator

Introduce the PSBT_OUT_UNIQUE_ID field (currently proprietary field) which serves as a stable key for outputs in unordered PSBTS.

Reopens #77, which was merged into `struct-macro` before #68 landed. Same commit, now stacked on #90.

🤖 Generated with Claude Code

@yuval-block
yuval-block added this pull request to stack #92 November 12, 2026 18:49
@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main bf9b058 output-unique-id a021cf6 +/-
100% 100% 0%
View coverage of the 1 most impacted file.
File main bf9b058 output-unique-id a021cf6 +/-
crates/concurre.../psbt/output.rs 0% 100% +100%

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


Updated November 13, 2026 15:19 UTC

@arminsabouri arminsabouri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

re-ACK

Same comments as #77

@github-actions

Copy link
Copy Markdown
range-diff for force push f747b4c060 → 673aa58c3b November 12, 2026 20:16 UTC: 1 unchanged; 1 commit; base e35e224dba → 549c733b12 (diverged, 4 ahead and 1 behind)

reproduce: git range-diff e35e224..f747b4c 549c733..673aa58

1:  f747b4c060 +152 -1 4f = 1:  673aa58c3b +152 -1 4f introduce output.UniqueId

@github-actions

Copy link
Copy Markdown
range-diff for force push f747b4c060 → 673aa58c3b November 12, 2026 20:16 UTC: 1 unchanged; 1 commit; base e35e224dba → 549c733b12 (diverged, 4 ahead and 1 behind)

reproduce: git range-diff e35e224..f747b4c 549c733..673aa58

1:  f747b4c060 +152 -1 4f = 1:  673aa58c3b +152 -1 4f introduce output.UniqueId

Comment thread nix/checks/coverage/default.nix Resolved
@github-actions

Copy link
Copy Markdown
range-diff for force push 673aa58c3b → f987bb2e1e November 13, 2026 00:07 UTC: 1 modified; 1 commit; same base 549c733b12

reproduce: git range-diff 549c733..673aa58 549c733..f987bb2

1:  673aa58c3b +152 -1 4f ! 1:  f987bb2e1e +148 -4 4f introduce output.UniqueId
1: 673aa58c3b ! 1: f987bb2e1e introduce output.UniqueId
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +        use super::*;
 +        use proptest::prelude::*;
 +
-+        fn output_with_uid(uid: &[u8]) -> Output {
-+            let mut output = Output::default();
-+            let key = psbt_v2::raw::ProprietaryKey {
-+                prefix: b"concurrent-psbt".to_vec(),
-+                subtype: PSBT_OUT_UNIQUE_ID_SUBTYPE,
-+                key: vec![],
-+            };
-+            output.proprietaries.insert(key, uid.to_vec());
-+            output
-+        }
-+
 +        proptest! {
 +            #[test]
 +            fn unique_id_roundtrip(uid in proptest::collection::vec(0u8..=255, 1..=32)) {
-+                let output = output_with_uid(&uid);
++                let id = UniqueId::new(uid.clone());
++                prop_assert_eq!(id.as_bytes(), uid.as_slice());
++
++                let mut output = Output::default();
++                prop_assert!(!output.has_unique_id());
++                output.set_unique_id(id);
 +                prop_assert!(output.has_unique_id());
 +                prop_assert_eq!(output.unique_id().unwrap().into_bytes(), uid);
 +            }
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 
  ## nix/checks/coverage/default.nix ##
 @@
-       # deliberately, from measured coverage, never to make a failing change
-       # pass.
+               ${report}/coverage.lcov
+           '';
+ 
+-      # Line coverage each suite must reach on its own, independently of the
+-      # other. They only catch a collapse of one category of test; lower them
+-      # deliberately, from measured coverage, never to make a failing change
+-      # pass.
++      # Line coverage each suite must reach on its own. These only catch a
++      # collapse of one category of test; lower one when reaching it would
++      # need contrived tests in that suite.
        coverageThresholds = {
--        prop-only = 95;
-+        prop-only = 90;
+         prop-only = 95;
          unit-only = 95;
-       };
- 

@bc1cindy bc1cindy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK f987bb2

@arminsabouri arminsabouri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

re-ACK

@github-actions

Copy link
Copy Markdown
range-diff for force push f987bb2e1e → 5bda2659b5 November 13, 2026 14:42 UTC: 1 modified, 2 added; 1 → 3 commits; base 549c733b12 → 227c7b51ba (ancestor, 1 commit behind)

reproduce: git range-diff 549c733..f987bb2 227c7b5..5bda265

-:  ----------             > 1:  1c5a69d312 +287 -28 5f Introduce joinable Input struct type
-:  ----------             > 2:  930cf29805 +172  -0 3f Introduce joinable Output struct type
1:  f987bb2e1e +148  -4 4f ! 3:  5bda2659b5 +190  -4 4f introduce output.UniqueId
1: f987bb2e1e ! 3: 5bda2659b5 introduce output.UniqueId
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
 +/// 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.
++///
++/// Built with [`TryFrom`], a unique ID is at most [`UniqueId::MAX_LEN`]
++/// bytes long. One read from an output is not checked.
 +#[derive(Debug, Clone, PartialEq, Eq, Hash)]
 +pub struct UniqueId(Vec<u8>);
 +
 +impl UniqueId {
-+    /// Create a `UniqueId` from raw bytes.
-+    pub fn new(bytes: Vec<u8>) -> Self {
++    /// The maximum length of a unique ID in bytes.
++    pub const MAX_LEN: usize = 32;
++
++    /// Create a `UniqueId` from raw bytes without checking their length.
++    #[cfg(test)]
++    pub(crate) fn new(bytes: Vec<u8>) -> Self {
 +        Self(bytes)
 +    }
 +
@@ crates/concurrent-psbt/src/psbt/output.rs: joinable_struct! {
 +
 +impl crate::values::IdempotentValue for UniqueId {}
 +
++/// The bytes are too long for a [`UniqueId`]; they are returned unchanged.
++#[derive(Debug, Clone, PartialEq, Eq)]
++pub struct InvalidUniqueId(pub Vec<u8>);
++
++impl TryFrom<Vec<u8>> for UniqueId {
++    type Error = InvalidUniqueId;
++
++    fn try_from(bytes: Vec<u8>) -> Result<Self, InvalidUniqueId> {
++        if bytes.len() > Self::MAX_LEN {
++            return Err(InvalidUniqueId(bytes));
++        }
++        Ok(Self(bytes))
++    }
++}
++
++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 {}",
++            self.0.len(),
++            UniqueId::MAX_LEN
++        )
++    }
++}
++
++impl std::error::Error for InvalidUniqueId {}
++
 +pub const PSBT_OUT_UNIQUE_ID_SUBTYPE: u8 = 0x01;
 +
 +/// Extension trait on [`psbt_v2::v2::Output`] for accessing the unique-ID proprietary field.
@@ crates/concurrent-psbt/src/psbt/output.rs: mod tests {
 +
 +        proptest! {
 +            #[test]
-+            fn unique_id_roundtrip(uid in proptest::collection::vec(0u8..=255, 1..=32)) {
-+                let id = UniqueId::new(uid.clone());
++            fn unique_id_roundtrip(uid in proptest::collection::vec(0u8..=255, 1..=40)) {
++                let Ok(id) = UniqueId::try_from(uid.clone()) else {
++                    prop_assert!(uid.len() > UniqueId::MAX_LEN);
++                    let error = InvalidUniqueId(uid.clone());
++                    prop_assert!(error.to_string().contains("more than 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());
 +
 +                let mut output = Output::default();

Introduce the PSBT_OUT_UNIQUE_ID field (currently proprietary field)
which serves as a stable key for outputs in unordered PSBTS.
@github-actions

Copy link
Copy Markdown
range-diff for force push 5bda2659b5 → a021cf6b11 November 13, 2026 15:06 UTC: 1 unchanged; 1 commit; base 930cf29805 → bf9b05843d (descendant, 1 commit ahead)

reproduce: git range-diff 930cf29..5bda265 bf9b058..a021cf6

1:  5bda2659b5 +190 -4 4f = 1:  a021cf6b11 +190 -4 4f introduce output.UniqueId

@yuval-block
yuval-block enabled stacked auto-merge November 13, 2026 15:11
@yuval-block
yuval-block added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 933eca8 Nov 13, 2026
6 checks passed
@yuval-block
yuval-block deleted the output-unique-id branch November 13, 2026 15:34
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.

4 participants