@@ -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" )
@@ -623,19 +633,16 @@ impl NegotiationContext {
623
633
624
634
// Extract info from msg, check if shared
625
635
let ( input, prev_outpoint) = if let Some ( shared_txid) = & msg. shared_input_txid {
626
- // This is a shared input
627
636
if self . holder_is_initiator {
628
637
return Err ( AbortReason :: DuplicateFundingInput ) ;
629
638
}
630
639
if let Some ( shared_funding_input) = & self . shared_funding_input {
631
- // There can only be one shared output.
632
640
if self . inputs . values ( ) . any ( |input| matches ! ( input. input, InputOwned :: Shared ( _) ) ) {
633
641
return Err ( AbortReason :: DuplicateFundingInput ) ;
634
642
}
635
643
// Check if receied shared input matches the expected
636
644
if shared_funding_input. 0 . txid != * shared_txid {
637
- // Shared input TXID differs from expected
638
- return Err ( AbortReason :: MissingFundingInput ) ;
645
+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
639
646
} else {
640
647
let previous_output = OutPoint { txid : * shared_txid, vout : msg. prevtx_out } ;
641
648
let txin = TxIn {
@@ -652,11 +659,9 @@ impl NegotiationContext {
652
659
( InputOwned :: Shared ( shared_input) , previous_output)
653
660
}
654
661
} else {
655
- // Unexpected shared input received
656
- return Err ( AbortReason :: MissingFundingInput ) ;
662
+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
657
663
}
658
664
} else {
659
- // Non-shared input
660
665
if let Some ( prevtx) = & msg. prevtx {
661
666
let transaction = prevtx. as_transaction ( ) ;
662
667
let txid = transaction. compute_txid ( ) ;
@@ -690,7 +695,7 @@ impl NegotiationContext {
690
695
return Err ( AbortReason :: PrevTxOutInvalid ) ;
691
696
}
692
697
} else {
693
- return Err ( AbortReason :: MissingFundingInput ) ;
698
+ return Err ( AbortReason :: MissingPrevTx ) ;
694
699
}
695
700
} ;
696
701
@@ -714,7 +719,6 @@ impl NegotiationContext {
714
719
// (and not removed) input's
715
720
return Err ( AbortReason :: PrevTxOutInvalid ) ;
716
721
}
717
- self . prevtx_outpoints . insert ( prev_outpoint) ;
718
722
719
723
Ok ( ( ) )
720
724
} ,
@@ -794,11 +798,9 @@ impl NegotiationContext {
794
798
795
799
let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
796
800
let output = if txout == self . shared_funding_output . 0 {
797
- // This is a shared output
798
801
if self . holder_is_initiator {
799
802
return Err ( AbortReason :: DuplicateFundingOutput ) ;
800
803
}
801
- // There can only be one shared output.
802
804
if self . outputs . values ( ) . any ( |output| matches ! ( output. output, OutputOwned :: Shared ( _) ) ) {
803
805
return Err ( AbortReason :: DuplicateFundingOutput ) ;
804
806
}
@@ -840,7 +842,6 @@ impl NegotiationContext {
840
842
fn sent_tx_add_input ( & mut self , msg : & msgs:: TxAddInput ) -> Result < ( ) , AbortReason > {
841
843
let vout = msg. prevtx_out as usize ;
842
844
let ( prev_outpoint, input) = if let Some ( shared_input_txid) = msg. shared_input_txid {
843
- // This is the shared input
844
845
let prev_outpoint = OutPoint { txid : shared_input_txid, vout : msg. prevtx_out } ;
845
846
let txin = TxIn {
846
847
previous_output : prev_outpoint,
@@ -863,10 +864,9 @@ impl NegotiationContext {
863
864
InputOwned :: Shared ( SharedOwnedInput :: new ( txin, prev_output, local_owned) ) ,
864
865
)
865
866
} else {
866
- return Err ( AbortReason :: MissingFundingInput ) ;
867
+ return Err ( AbortReason :: UnexpectedFundingInput ) ;
867
868
}
868
869
} else {
869
- // Non-shared input
870
870
if let Some ( prevtx) = & msg. prevtx {
871
871
let prev_txid = prevtx. as_transaction ( ) . compute_txid ( ) ;
872
872
let prev_outpoint = OutPoint { txid : prev_txid, vout : msg. prevtx_out } ;
@@ -901,7 +901,6 @@ impl NegotiationContext {
901
901
fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
902
902
let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
903
903
let output = if txout == self . shared_funding_output . 0 {
904
- // this is the shared output
905
904
OutputOwned :: Shared ( SharedOwnedOutput :: new ( txout, self . shared_funding_output . 1 ) )
906
905
} else {
907
906
OutputOwned :: Single ( txout)
@@ -2949,7 +2948,7 @@ mod tests {
2949
2948
b_shared_input : None ,
2950
2949
shared_output_b : generate_funding_txout ( 108_000 , 0 ) ,
2951
2950
outputs_b : vec ! [ ] ,
2952
- expect_error : Some ( ( AbortReason :: MissingFundingInput , ErrorCulprit :: NodeA ) ) ,
2951
+ expect_error : Some ( ( AbortReason :: UnexpectedFundingInput , ErrorCulprit :: NodeA ) ) ,
2953
2952
} ) ;
2954
2953
}
2955
2954
0 commit comments