@@ -108,6 +108,10 @@ pub(crate) enum AbortReason {
108108 InvalidTx ,
109109 /// No funding (shared) input found.
110110 MissingFundingInput ,
111+ /// A funding (shared) input was seen, but we don't expect one
112+ UnexpectedFundingInput ,
113+ /// In tx_add_input, the prev_tx field must be filled in case of non-shared input
114+ MissingPrevTx ,
111115 /// No funding (shared) output found.
112116 MissingFundingOutput ,
113117 /// More than one funding (shared) output found.
@@ -165,6 +169,12 @@ impl Display for AbortReason {
165169 } ,
166170 AbortReason :: InvalidTx => f. write_str ( "The transaction is invalid" ) ,
167171 AbortReason :: MissingFundingInput => f. write_str ( "No shared funding input found" ) ,
172+ AbortReason :: UnexpectedFundingInput => {
173+ f. write_str ( "A funding (shared) input was seen, but we don't expect one" )
174+ } ,
175+ AbortReason :: MissingPrevTx => f. write_str (
176+ "In tx_add_input, the prev_tx field must be filled in case of non-shared input" ,
177+ ) ,
168178 AbortReason :: MissingFundingOutput => f. write_str ( "No shared funding output found" ) ,
169179 AbortReason :: DuplicateFundingOutput => {
170180 f. write_str ( "More than one funding output found" )
@@ -482,10 +492,10 @@ struct NegotiationContext {
482492 /// - For the initiator:
483493 /// The intended previous funding input. This will be added alongside to the
484494 /// provided inputs.
485- /// The values are the output value and the the holder's part of the shared input.
495+ /// The values are the output value and the holder's part of the shared input.
486496 /// - For the acceptor:
487497 /// The expected previous funding input. It should be added by the initiator node.
488- /// The values are the output value and the the holder's part of the shared input.
498+ /// The values are the output value and the holder's part of the shared input.
489499 shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
490500 /// The intended/extended funding output, potentially co-owned by both peers (shared).
491501 /// - For the initiator:
@@ -620,19 +630,16 @@ impl NegotiationContext {
620630
621631 // Extract info from msg, check if shared
622632 let ( input, prev_outpoint) = if let Some ( shared_txid) = & msg. shared_input_txid {
623- // This is a shared input
624633 if self . holder_is_initiator {
625634 return Err ( AbortReason :: DuplicateFundingInput ) ;
626635 }
627636 if let Some ( shared_funding_input) = & self . shared_funding_input {
628- // There can only be one shared output.
629637 if self . inputs . values ( ) . any ( |input| matches ! ( input. input, InputOwned :: Shared ( _) ) ) {
630638 return Err ( AbortReason :: DuplicateFundingInput ) ;
631639 }
632- // Check if receied shared input matches the expected
640+ // Check if received shared input matches the expected
633641 if shared_funding_input. 0 . txid != * shared_txid {
634- // Shared input TXID differs from expected
635- return Err ( AbortReason :: MissingFundingInput ) ;
642+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
636643 } else {
637644 let previous_output = OutPoint { txid : * shared_txid, vout : msg. prevtx_out } ;
638645 let txin = TxIn {
@@ -649,11 +656,9 @@ impl NegotiationContext {
649656 ( InputOwned :: Shared ( shared_input) , previous_output)
650657 }
651658 } else {
652- // Unexpected shared input received
653- return Err ( AbortReason :: MissingFundingInput ) ;
659+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
654660 }
655661 } else {
656- // Non-shared input
657662 if let Some ( prevtx) = & msg. prevtx {
658663 let transaction = prevtx. as_transaction ( ) ;
659664 let txid = transaction. compute_txid ( ) ;
@@ -687,7 +692,7 @@ impl NegotiationContext {
687692 return Err ( AbortReason :: PrevTxOutInvalid ) ;
688693 }
689694 } else {
690- return Err ( AbortReason :: MissingFundingInput ) ;
695+ return Err ( AbortReason :: MissingPrevTx ) ;
691696 }
692697 } ;
693698
@@ -711,7 +716,6 @@ impl NegotiationContext {
711716 // (and not removed) input's
712717 return Err ( AbortReason :: PrevTxOutInvalid ) ;
713718 }
714- self . prevtx_outpoints . insert ( prev_outpoint) ;
715719
716720 Ok ( ( ) )
717721 } ,
@@ -791,11 +795,9 @@ impl NegotiationContext {
791795
792796 let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
793797 let output = if txout == self . shared_funding_output . tx_out {
794- // This is a shared output
795798 if self . holder_is_initiator {
796799 return Err ( AbortReason :: DuplicateFundingOutput ) ;
797800 }
798- // There can only be one shared output.
799801 if self . outputs . values ( ) . any ( |output| matches ! ( output. output, OutputOwned :: Shared ( _) ) ) {
800802 return Err ( AbortReason :: DuplicateFundingOutput ) ;
801803 }
@@ -837,7 +839,6 @@ impl NegotiationContext {
837839 fn sent_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) -> Result < ( ) , AbortReason > {
838840 let vout = msg. prevtx_out as usize ;
839841 let ( prev_outpoint, input) = if let Some ( shared_input_txid) = msg. shared_input_txid {
840- // This is the shared input
841842 let prev_outpoint = OutPoint { txid : shared_input_txid, vout : msg. prevtx_out } ;
842843 let txin = TxIn {
843844 previous_output : prev_outpoint,
@@ -860,10 +861,9 @@ impl NegotiationContext {
860861 InputOwned :: Shared ( SharedOwnedInput :: new ( txin, prev_output, local_owned) ) ,
861862 )
862863 } else {
863- return Err ( AbortReason :: MissingFundingInput ) ;
864+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
864865 }
865866 } else {
866- // Non-shared input
867867 if let Some ( prevtx) = & msg. prevtx {
868868 let prev_txid = prevtx. as_transaction ( ) . compute_txid ( ) ;
869869 let prev_outpoint = OutPoint { txid : prev_txid, vout : msg. prevtx_out } ;
@@ -898,7 +898,6 @@ impl NegotiationContext {
898898 fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
899899 let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
900900 let output = if txout == self . shared_funding_output . tx_out {
901- // this is the shared output
902901 OutputOwned :: Shared ( self . shared_funding_output . clone ( ) )
903902 } else {
904903 OutputOwned :: Single ( txout)
@@ -2956,7 +2955,7 @@ mod tests {
29562955 b_shared_input : None ,
29572956 shared_output_b : generate_funding_txout ( 108_000 , 0 ) ,
29582957 outputs_b : vec ! [ ] ,
2959- expect_error : Some ( ( AbortReason :: MissingFundingInput , ErrorCulprit :: NodeA ) ) ,
2958+ expect_error : Some ( ( AbortReason :: UnexpectedFundingInput , ErrorCulprit :: NodeA ) ) ,
29602959 } ) ;
29612960 }
29622961
0 commit comments