Use u16 for ConstructedTransaction::shared_input_index
What changed, and why it matters
This commit narrows a numeric field used to track a shared transaction input from a 32-bit integer to a 16-bit integer. The change is safe because the protocol already caps the number of inputs at 4,096, which fits comfortably in a 16-bit value. It is a small cleanup or consistency fix, not a security patch.
No action required; treat as a minor refactor. Reviewers may verify that 4096 remains the hard input limit and that downstream consumers of `shared_input_index()` tolerate `Option<u16>`.
Security signals we found
No security-relevant signals in commit message or diff
Type narrowing with documented domain bound (4096 inputs)
No input validation, bounds, or memory-safety changes
Evidence from the diff
The patch changes ConstructedTransaction::shared_input_index from Option<u32> to Option<u16> and updates the two conversion/cast sites and the getter return type accordingly. The interactive-tx construction session limits inputs to 4096, so a u16 is sufficient. This aligns the field with the existing shared_output_index: u16.
Changed components
lightning/src/ln/interactivetxs.rsConstructedTransaction::shared_input_index field and getterInspect captured patch +3 / −3
diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs
index ebb6a89..ea9994d 100644
--- a/lightning/src/ln/interactivetxs.rs
+++ b/lightning/src/ln/interactivetxs.rs
@@ -199,7 +199,7 @@ pub(crate) struct ConstructedTransaction {
input_metadata: Vec<TxInMetadata>,
output_metadata: Vec<TxOutMetadata>,
tx: Transaction,
- shared_input_index: Option<u32>,
+ shared_input_index: Option<u16>,
shared_output_index: u16,
}
@@ -279,7 +279,7 @@ impl ConstructedTransaction {
.position(|txin| {
txin.previous_output == shared_funding_input.input.previous_output
})
- .map(|position| position as u32)
+ .map(|position| position as u16)
});
let shared_output_index = output
@@ -455,7 +455,7 @@ impl ConstructedTransaction {
self.holder_is_initiator
}
- pub fn shared_input_index(&self) -> Option<u32> {
+ pub fn shared_input_index(&self) -> Option<u16> {
self.shared_input_index
}
}
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.