Skip to content

Commit 62223fc

Browse files
committed
fix Change result error to AbortReason
1 parent 1229034 commit 62223fc

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::ln::types::ChannelId;
3030
use crate::types::payment::{PaymentPreimage, PaymentHash};
3131
use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3232
use crate::ln::interactivetxs::{
33-
calculate_change_output_value, get_output_weight, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
33+
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteValue, HandleTxCompleteResult, InteractiveTxConstructor,
3434
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
3535
OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
3636
};
@@ -2229,7 +2229,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22292229
&mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
22302230
change_destination_opt: Option<ScriptBuf>,
22312231
prev_funding_input: Option<(TxIn, TransactionU16LenLimited)>,
2232-
) -> Result<Option<InteractiveTxMessageSend>, ChannelError>
2232+
) -> Result<Option<InteractiveTxMessageSend>, AbortReason>
22332233
where ES::Target: EntropySource
22342234
{
22352235
debug_assert!(self.interactive_tx_constructor.is_none());
@@ -2273,19 +2273,14 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22732273
script
22742274
} else {
22752275
signer_provider.get_destination_script(self.context.channel_keys_id)
2276-
.map_err(|err| ChannelError::Warn(format!(
2277-
"Failed to get change script as new destination script, {:?}", err,
2278-
)))?
2276+
.map_err(|_err| AbortReason::InternalErrorGettingDestinationScript)?
22792277
};
22802278
let change_value_opt = calculate_change_output_value(
22812279
self.funding.is_outbound(), self.dual_funding_context.our_funding_satoshis,
22822280
&funding_inputs_prev_outputs, &funding_outputs,
22832281
self.dual_funding_context.funding_feerate_sat_per_1000_weight,
22842282
change_script.minimal_non_dust().to_sat(),
2285-
).map_err(|err| ChannelError::Warn(format!(
2286-
"Insufficient inputs, cannot cover intended contribution of {} and fees; {}",
2287-
self.dual_funding_context.our_funding_satoshis, err
2288-
)))?;
2283+
)?;
22892284
if let Some(change_value) = change_value_opt {
22902285
let mut change_output = TxOut {
22912286
value: Amount::from_sat(change_value),
@@ -2313,8 +2308,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23132308
outputs_to_contribute: funding_outputs,
23142309
expected_remote_shared_funding_output,
23152310
};
2316-
let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)
2317-
.map_err(|_| ChannelError::Warn("Incorrect shared output provided".into()))?;
2311+
let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)?;
23182312
let msg = tx_constructor.take_initiator_first_message();
23192313

23202314
self.interactive_tx_constructor = Some(tx_constructor);
@@ -4999,23 +4993,18 @@ impl DualFundingChannelContext {
49994993
/// Obtain prev outputs for each supplied input and matching transaction.
50004994
/// Will error when a prev tx does not have an output for the specified vout.
50014995
/// Also checks for matching of transaction IDs.
5002-
fn txouts_from_input_prev_txs(inputs: &Vec<(TxIn, TransactionU16LenLimited)>) -> Result<Vec<&TxOut>, ChannelError> {
4996+
fn txouts_from_input_prev_txs(inputs: &Vec<(TxIn, TransactionU16LenLimited)>) -> Result<Vec<&TxOut>, AbortReason> {
50034997
let mut prev_outputs: Vec<&TxOut> = Vec::with_capacity(inputs.len());
50044998
// Check that vouts exist for each TxIn in provided transactions.
5005-
for (idx, (txin, tx)) in inputs.iter().enumerate() {
4999+
for (_idx, (txin, tx)) in inputs.iter().enumerate() {
50065000
let txid = tx.as_transaction().compute_txid();
50075001
if txin.previous_output.txid != txid {
5008-
return Err(ChannelError::Warn(
5009-
format!("Transaction input txid mismatch, {} vs. {}, at index {}", txin.previous_output.txid, txid, idx)
5010-
));
5002+
return Err(AbortReason::ProvidedInputsAndPrevtxsTxIdMismatch);
50115003
}
50125004
if let Some(output) = tx.as_transaction().output.get(txin.previous_output.vout as usize) {
50135005
prev_outputs.push(output);
50145006
} else {
5015-
return Err(ChannelError::Warn(
5016-
format!("Transaction with txid {} does not have an output with vout of {} corresponding to TxIn, at index {}",
5017-
txid, txin.previous_output.vout, idx)
5018-
));
5007+
return Err(AbortReason::ProvidedInputsAndPrevtxsVoutNotFound);
50195008
}
50205009
}
50215010
Ok(prev_outputs)

lightning/src/ln/interactivetxs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ pub(crate) enum AbortReason {
108108
/// if funding output is provided by the peer this is an interop error,
109109
/// if provided by the same node than internal input consistency error.
110110
InvalidLowFundingOutputValue,
111+
/// TxId mismatch in the provided inputs and previous transactions
112+
ProvidedInputsAndPrevtxsTxIdMismatch,
113+
/// A vout provided in an input is not found in the matching previous transaction
114+
ProvidedInputsAndPrevtxsVoutNotFound,
115+
/// Internal error, error while getting destination script
116+
InternalErrorGettingDestinationScript,
111117
}
112118

113119
impl AbortReason {
@@ -147,6 +153,12 @@ impl Display for AbortReason {
147153
AbortReason::InvalidLowFundingOutputValue => {
148154
"Local part of funding output value is greater than the funding output value"
149155
},
156+
AbortReason::ProvidedInputsAndPrevtxsTxIdMismatch =>
157+
"TxId mismatch in the provided inputs and previous transactions",
158+
AbortReason::ProvidedInputsAndPrevtxsVoutNotFound =>
159+
"Vout provided in an input is not found in the previous transaction",
160+
AbortReason::InternalErrorGettingDestinationScript =>
161+
"Internal error getting destination script",
150162
})
151163
}
152164
}

0 commit comments

Comments
 (0)