Skip to content

Commit dc672f1

Browse files
committed
Store shared output index in ConstructedTransaction
Currently, only the shared input index is stored in ConstructedTransaction. This will be used later to filter out the shared input when constructing an error during interactive tx negotiation. Store the shared output index as well so that the shared output can be filtered out as well.
1 parent 8ca05a8 commit dc672f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ pub(crate) struct ConstructedTransaction {
200200
output_metadata: Vec<TxOutMetadata>,
201201
tx: Transaction,
202202
shared_input_index: Option<u32>,
203+
shared_output_index: u16,
203204
}
204205

205206
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -244,6 +245,7 @@ impl_writeable_tlv_based!(ConstructedTransaction, {
244245
(5, output_metadata, required),
245246
(7, tx, required),
246247
(9, shared_input_index, option),
248+
(11, shared_output_index, required),
247249
});
248250

249251
impl ConstructedTransaction {
@@ -280,12 +282,19 @@ impl ConstructedTransaction {
280282
.map(|position| position as u32)
281283
});
282284

285+
let shared_output_index = output
286+
.iter()
287+
.position(|txout| *txout == context.shared_funding_output.tx_out)
288+
.map(|position| position as u16)
289+
.unwrap_or(u16::MAX);
290+
283291
let tx = ConstructedTransaction {
284292
holder_is_initiator: context.holder_is_initiator,
285293
input_metadata,
286294
output_metadata,
287295
tx: Transaction { version: Version::TWO, lock_time, input, output },
288296
shared_input_index,
297+
shared_output_index,
289298
};
290299

291300
// The receiving node:
@@ -315,7 +324,7 @@ impl ConstructedTransaction {
315324
return Err(AbortReason::MissingFundingInput);
316325
}
317326

318-
if !tx.tx.output.iter().any(|txout| *txout == context.shared_funding_output.tx_out) {
327+
if tx.shared_output_index == u16::MAX {
319328
return Err(AbortReason::MissingFundingOutput);
320329
}
321330

@@ -3329,6 +3338,7 @@ mod tests {
33293338
output_metadata: vec![], // N/A for test
33303339
tx: transaction.clone(),
33313340
shared_input_index: None,
3341+
shared_output_index: 0,
33323342
};
33333343

33343344
let secp_ctx = Secp256k1::new();

0 commit comments

Comments
 (0)