Skip to content

Commit 1229034

Browse files
committed
Use output-specific dust limit for change check
1 parent c7e9cc5 commit 1229034

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lightning/src/ln/channel.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2269,24 +2269,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22692269
};
22702270

22712271
// Optionally add change output
2272+
let change_script = if let Some(script) = change_destination_opt {
2273+
script
2274+
} else {
2275+
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+
)))?
2279+
};
22722280
let change_value_opt = calculate_change_output_value(
22732281
self.funding.is_outbound(), self.dual_funding_context.our_funding_satoshis,
22742282
&funding_inputs_prev_outputs, &funding_outputs,
22752283
self.dual_funding_context.funding_feerate_sat_per_1000_weight,
2276-
self.context.holder_dust_limit_satoshis,
2284+
change_script.minimal_non_dust().to_sat(),
22772285
).map_err(|err| ChannelError::Warn(format!(
22782286
"Insufficient inputs, cannot cover intended contribution of {} and fees; {}",
22792287
self.dual_funding_context.our_funding_satoshis, err
22802288
)))?;
22812289
if let Some(change_value) = change_value_opt {
2282-
let change_script = if let Some(script) = change_destination_opt {
2283-
script
2284-
} else {
2285-
signer_provider.get_destination_script(self.context.channel_keys_id)
2286-
.map_err(|err| ChannelError::Warn(format!(
2287-
"Failed to get change script as new destination script, {:?}", err,
2288-
)))?
2289-
};
22902290
let mut change_output = TxOut {
22912291
value: Amount::from_sat(change_value),
22922292
script_pubkey: change_script,

lightning/src/ln/interactivetxs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ impl InteractiveTxConstructor {
16771677
pub(super) fn calculate_change_output_value(
16781678
is_initiator: bool, our_contribution: u64, funding_inputs_prev_outputs: &Vec<&TxOut>,
16791679
funding_outputs: &Vec<OutputOwned>, funding_feerate_sat_per_1000_weight: u32,
1680-
holder_dust_limit_satoshis: u64,
1680+
change_output_dust_limit: u64,
16811681
) -> Result<Option<u64>, AbortReason> {
16821682
let our_funding_inputs_weight =
16831683
funding_inputs_prev_outputs.iter().fold(0u64, |weight, prev_output| {
@@ -1705,7 +1705,7 @@ pub(super) fn calculate_change_output_value(
17051705
return Err(AbortReason::InsufficientFees);
17061706
}
17071707
let remaining_value = total_inputs_less_fees.saturating_sub(our_contribution);
1708-
if remaining_value < holder_dust_limit_satoshis {
1708+
if remaining_value < change_output_dust_limit {
17091709
// Enough to cover contribution plus fees, but leftover is below dust limit; no change
17101710
Ok(None)
17111711
} else {

0 commit comments

Comments
 (0)