@@ -108,6 +108,10 @@ pub(crate) enum AbortReason {
108
108
InvalidTx ,
109
109
/// No funding (shared) input found.
110
110
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 ,
111
115
/// No funding (shared) output found.
112
116
MissingFundingOutput ,
113
117
/// More than one funding (shared) output found.
@@ -165,6 +169,12 @@ impl Display for AbortReason {
165
169
} ,
166
170
AbortReason :: InvalidTx => f. write_str ( "The transaction is invalid" ) ,
167
171
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
+ ) ,
168
178
AbortReason :: MissingFundingOutput => f. write_str ( "No shared funding output found" ) ,
169
179
AbortReason :: DuplicateFundingOutput => {
170
180
f. write_str ( "More than one funding output found" )
@@ -482,10 +492,10 @@ struct NegotiationContext {
482
492
/// - For the initiator:
483
493
/// The intended previous funding input. This will be added alongside to the
484
494
/// 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.
486
496
/// - For the acceptor:
487
497
/// 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.
489
499
shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
490
500
/// The intended/extended funding output, potentially co-owned by both peers (shared).
491
501
/// - For the initiator:
@@ -620,19 +630,16 @@ impl NegotiationContext {
620
630
621
631
// Extract info from msg, check if shared
622
632
let ( input, prev_outpoint) = if let Some ( shared_txid) = & msg. shared_input_txid {
623
- // This is a shared input
624
633
if self . holder_is_initiator {
625
634
return Err ( AbortReason :: DuplicateFundingInput ) ;
626
635
}
627
636
if let Some ( shared_funding_input) = & self . shared_funding_input {
628
- // There can only be one shared output.
629
637
if self . inputs . values ( ) . any ( |input| matches ! ( input. input, InputOwned :: Shared ( _) ) ) {
630
638
return Err ( AbortReason :: DuplicateFundingInput ) ;
631
639
}
632
- // Check if receied shared input matches the expected
640
+ // Check if received shared input matches the expected
633
641
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 ) ;
636
643
} else {
637
644
let previous_output = OutPoint { txid : * shared_txid, vout : msg. prevtx_out } ;
638
645
let txin = TxIn {
@@ -649,11 +656,9 @@ impl NegotiationContext {
649
656
( InputOwned :: Shared ( shared_input) , previous_output)
650
657
}
651
658
} else {
652
- // Unexpected shared input received
653
- return Err ( AbortReason :: MissingFundingInput ) ;
659
+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
654
660
}
655
661
} else {
656
- // Non-shared input
657
662
if let Some ( prevtx) = & msg. prevtx {
658
663
let transaction = prevtx. as_transaction ( ) ;
659
664
let txid = transaction. compute_txid ( ) ;
@@ -687,7 +692,7 @@ impl NegotiationContext {
687
692
return Err ( AbortReason :: PrevTxOutInvalid ) ;
688
693
}
689
694
} else {
690
- return Err ( AbortReason :: MissingFundingInput ) ;
695
+ return Err ( AbortReason :: MissingPrevTx ) ;
691
696
}
692
697
} ;
693
698
@@ -711,7 +716,6 @@ impl NegotiationContext {
711
716
// (and not removed) input's
712
717
return Err ( AbortReason :: PrevTxOutInvalid ) ;
713
718
}
714
- self . prevtx_outpoints . insert ( prev_outpoint) ;
715
719
716
720
Ok ( ( ) )
717
721
} ,
@@ -791,11 +795,9 @@ impl NegotiationContext {
791
795
792
796
let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
793
797
let output = if txout == self . shared_funding_output . tx_out {
794
- // This is a shared output
795
798
if self . holder_is_initiator {
796
799
return Err ( AbortReason :: DuplicateFundingOutput ) ;
797
800
}
798
- // There can only be one shared output.
799
801
if self . outputs . values ( ) . any ( |output| matches ! ( output. output, OutputOwned :: Shared ( _) ) ) {
800
802
return Err ( AbortReason :: DuplicateFundingOutput ) ;
801
803
}
@@ -837,7 +839,6 @@ impl NegotiationContext {
837
839
fn sent_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) -> Result < ( ) , AbortReason > {
838
840
let vout = msg. prevtx_out as usize ;
839
841
let ( prev_outpoint, input) = if let Some ( shared_input_txid) = msg. shared_input_txid {
840
- // This is the shared input
841
842
let prev_outpoint = OutPoint { txid : shared_input_txid, vout : msg. prevtx_out } ;
842
843
let txin = TxIn {
843
844
previous_output : prev_outpoint,
@@ -860,10 +861,9 @@ impl NegotiationContext {
860
861
InputOwned :: Shared ( SharedOwnedInput :: new ( txin, prev_output, local_owned) ) ,
861
862
)
862
863
} else {
863
- return Err ( AbortReason :: MissingFundingInput ) ;
864
+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
864
865
}
865
866
} else {
866
- // Non-shared input
867
867
if let Some ( prevtx) = & msg. prevtx {
868
868
let prev_txid = prevtx. as_transaction ( ) . compute_txid ( ) ;
869
869
let prev_outpoint = OutPoint { txid : prev_txid, vout : msg. prevtx_out } ;
@@ -898,7 +898,6 @@ impl NegotiationContext {
898
898
fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
899
899
let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
900
900
let output = if txout == self . shared_funding_output . tx_out {
901
- // this is the shared output
902
901
OutputOwned :: Shared ( self . shared_funding_output . clone ( ) )
903
902
} else {
904
903
OutputOwned :: Single ( txout)
@@ -2956,7 +2955,7 @@ mod tests {
2956
2955
b_shared_input : None ,
2957
2956
shared_output_b : generate_funding_txout ( 108_000 , 0 ) ,
2958
2957
outputs_b : vec ! [ ] ,
2959
- expect_error : Some ( ( AbortReason :: MissingFundingInput , ErrorCulprit :: NodeA ) ) ,
2958
+ expect_error : Some ( ( AbortReason :: UnexpectedFundingInput , ErrorCulprit :: NodeA ) ) ,
2960
2959
} ) ;
2961
2960
}
2962
2961
0 commit comments