Skip to content

Commit 5fb333d

Browse files
committed
fix Minor changes, error enum, comments
1 parent b2e0da8 commit 5fb333d

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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")
@@ -623,19 +633,16 @@ impl NegotiationContext {
623633

624634
// Extract info from msg, check if shared
625635
let (input, prev_outpoint) = if let Some(shared_txid) = &msg.shared_input_txid {
626-
// This is a shared input
627636
if self.holder_is_initiator {
628637
return Err(AbortReason::DuplicateFundingInput);
629638
}
630639
if let Some(shared_funding_input) = &self.shared_funding_input {
631-
// There can only be one shared output.
632640
if self.inputs.values().any(|input| matches!(input.input, InputOwned::Shared(_))) {
633641
return Err(AbortReason::DuplicateFundingInput);
634642
}
635643
// Check if receied shared input matches the expected
636644
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);
639646
} else {
640647
let previous_output = OutPoint { txid: *shared_txid, vout: msg.prevtx_out };
641648
let txin = TxIn {
@@ -652,11 +659,9 @@ impl NegotiationContext {
652659
(InputOwned::Shared(shared_input), previous_output)
653660
}
654661
} else {
655-
// Unexpected shared input received
656-
return Err(AbortReason::MissingFundingInput);
662+
return Err(AbortReason::UnexpectedFundingInput);
657663
}
658664
} else {
659-
// Non-shared input
660665
if let Some(prevtx) = &msg.prevtx {
661666
let transaction = prevtx.as_transaction();
662667
let txid = transaction.compute_txid();
@@ -690,7 +695,7 @@ impl NegotiationContext {
690695
return Err(AbortReason::PrevTxOutInvalid);
691696
}
692697
} else {
693-
return Err(AbortReason::MissingFundingInput);
698+
return Err(AbortReason::MissingPrevTx);
694699
}
695700
};
696701

@@ -714,7 +719,6 @@ impl NegotiationContext {
714719
// (and not removed) input's
715720
return Err(AbortReason::PrevTxOutInvalid);
716721
}
717-
self.prevtx_outpoints.insert(prev_outpoint);
718722

719723
Ok(())
720724
},
@@ -794,11 +798,9 @@ impl NegotiationContext {
794798

795799
let txout = TxOut { value: Amount::from_sat(msg.sats), script_pubkey: msg.script.clone() };
796800
let output = if txout == self.shared_funding_output.0 {
797-
// This is a shared output
798801
if self.holder_is_initiator {
799802
return Err(AbortReason::DuplicateFundingOutput);
800803
}
801-
// There can only be one shared output.
802804
if self.outputs.values().any(|output| matches!(output.output, OutputOwned::Shared(_))) {
803805
return Err(AbortReason::DuplicateFundingOutput);
804806
}
@@ -840,7 +842,6 @@ impl NegotiationContext {
840842
fn sent_tx_add_input(&mut self, msg: &msgs::TxAddInput) -> Result<(), AbortReason> {
841843
let vout = msg.prevtx_out as usize;
842844
let (prev_outpoint, input) = if let Some(shared_input_txid) = msg.shared_input_txid {
843-
// This is the shared input
844845
let prev_outpoint = OutPoint { txid: shared_input_txid, vout: msg.prevtx_out };
845846
let txin = TxIn {
846847
previous_output: prev_outpoint,
@@ -863,10 +864,9 @@ impl NegotiationContext {
863864
InputOwned::Shared(SharedOwnedInput::new(txin, prev_output, local_owned)),
864865
)
865866
} else {
866-
return Err(AbortReason::MissingFundingInput);
867+
return Err(AbortReason::UnexpectedFundingInput);
867868
}
868869
} else {
869-
// Non-shared input
870870
if let Some(prevtx) = &msg.prevtx {
871871
let prev_txid = prevtx.as_transaction().compute_txid();
872872
let prev_outpoint = OutPoint { txid: prev_txid, vout: msg.prevtx_out };
@@ -901,7 +901,6 @@ impl NegotiationContext {
901901
fn sent_tx_add_output(&mut self, msg: &msgs::TxAddOutput) -> Result<(), AbortReason> {
902902
let txout = TxOut { value: Amount::from_sat(msg.sats), script_pubkey: msg.script.clone() };
903903
let output = if txout == self.shared_funding_output.0 {
904-
// this is the shared output
905904
OutputOwned::Shared(SharedOwnedOutput::new(txout, self.shared_funding_output.1))
906905
} else {
907906
OutputOwned::Single(txout)
@@ -2949,7 +2948,7 @@ mod tests {
29492948
b_shared_input: None,
29502949
shared_output_b: generate_funding_txout(108_000, 0),
29512950
outputs_b: vec![],
2952-
expect_error: Some((AbortReason::MissingFundingInput, ErrorCulprit::NodeA)),
2951+
expect_error: Some((AbortReason::UnexpectedFundingInput, ErrorCulprit::NodeA)),
29532952
});
29542953
}
29552954

0 commit comments

Comments
 (0)