From 62d4952348ecf70e3c4b8cd0400158a603b37708 Mon Sep 17 00:00:00 2001 From: Duncan Dean Date: Tue, 26 Mar 2024 12:15:37 +0200 Subject: [PATCH] Abort if we add a duplicate input --- lightning/src/ln/interactivetxs.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs index 33a8bfc2f..836258b58 100644 --- a/lightning/src/ln/interactivetxs.rs +++ b/lightning/src/ln/interactivetxs.rs @@ -308,7 +308,10 @@ impl NegotiationContext { }; let prev_output = tx.output.get(msg.prevtx_out as usize).ok_or(AbortReason::PrevTxOutInvalid)?.clone(); - self.prevtx_outpoints.insert(input.previous_output); + if !self.prevtx_outpoints.insert(input.previous_output) { + // We have added an input that already exists + return Err(AbortReason::PrevTxOutInvalid); + } self.inputs.insert(msg.serial_id, TxInputWithPrevOutput { input, prev_output }); Ok(()) } @@ -1253,7 +1256,7 @@ mod tests { outputs_a: generate_outputs(&[1_000_000]), inputs_b: vec![], outputs_b: vec![], - expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeA)), + expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeB)), }); // Non-initiator uses same prevout as initiator. let duplicate_input = TxIn { @@ -1266,7 +1269,7 @@ mod tests { outputs_a: generate_outputs(&[1_000_000]), inputs_b: vec![(duplicate_input.clone(), tx.clone())], outputs_b: vec![], - expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeB)), + expect_error: Some((AbortReason::PrevTxOutInvalid, ErrorCulprit::NodeA)), }); // Initiator sends too many TxAddInputs do_test_interactive_tx_constructor(TestSession { -- 2.39.5