Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
pending_inbound_htlcs: Vec::new(),
pending_outbound_htlcs: Vec::new(),
current_dust_exposure_msat: None,
});
}
Some(&$first_hops_vec[..])
Expand Down
8 changes: 8 additions & 0 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ pub struct AvailableBalances {
pub next_outbound_htlc_limit_msat: u64,
/// The minimum value we can assign to the next outbound HTLC
pub next_outbound_htlc_minimum_msat: u64,
/// The current total dust exposure on this channel, in millisatoshis.
///
/// This is the maximum of the dust exposure on the holder and counterparty commitment
/// transactions, and includes both the value of all pending HTLCs that are below the dust
/// threshold as well as any excess commitment transaction fees that contribute to dust
/// exposure.
pub dust_exposure_msat: u64,
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -12559,6 +12566,7 @@ where
next_outbound_htlc_minimum_msat: acc
.next_outbound_htlc_minimum_msat
.max(e.next_outbound_htlc_minimum_msat),
dust_exposure_msat: acc.dust_exposure_msat.max(e.dust_exposure_msat),
})
})
}
Expand Down
19 changes: 19 additions & 0 deletions lightning/src/ln/channel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,21 @@ pub struct ChannelDetails {
///
/// This field will be `None` for objects serialized with LDK versions prior to 0.2.0.
pub funding_redeem_script: Option<bitcoin::ScriptBuf>,
/// The current total dust exposure on this channel, in millisatoshis.
///
/// This is the maximum of the dust exposure on the holder and counterparty commitment
/// transactions, and includes both the value of all pending HTLCs that are below the dust
/// threshold as well as the portion of commitment transaction fees that contribute to dust
/// exposure.
///
/// The dust exposure is compared against
/// [`ChannelConfig::max_dust_htlc_exposure`] to determine whether new HTLCs can be
/// accepted or offered on this channel.
///
/// This field will be `None` for objects serialized with LDK versions prior to 0.2.1.
///
/// [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure
pub current_dust_exposure_msat: Option<u64>,
}

impl ChannelDetails {
Expand Down Expand Up @@ -533,6 +548,7 @@ impl ChannelDetails {
outbound_capacity_msat: 0,
next_outbound_htlc_limit_msat: 0,
next_outbound_htlc_minimum_msat: u64::MAX,
dust_exposure_msat: 0,
}
});
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
Expand Down Expand Up @@ -596,6 +612,7 @@ impl ChannelDetails {
channel_shutdown_state: Some(context.shutdown_state()),
pending_inbound_htlcs: context.get_pending_inbound_htlc_details(funding),
pending_outbound_htlcs: context.get_pending_outbound_htlc_details(funding),
current_dust_exposure_msat: Some(balance.dust_exposure_msat),
}
}
}
Expand Down Expand Up @@ -636,6 +653,7 @@ impl_writeable_tlv_based!(ChannelDetails, {
(43, pending_inbound_htlcs, optional_vec),
(45, pending_outbound_htlcs, optional_vec),
(47, funding_redeem_script, option),
(49, current_dust_exposure_msat, option),
(_unused, user_channel_id, (static_value,
_user_channel_id_low.unwrap_or(0) as u128 | ((_user_channel_id_high.unwrap_or(0) as u128) << 64)
)),
Expand Down Expand Up @@ -756,6 +774,7 @@ mod tests {
skimmed_fee_msat: Some(42),
is_dust: false,
}],
current_dust_exposure_msat: Some(150_000),
};
let mut buffer = Vec::new();
channel_details.write(&mut buffer).unwrap();
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7929,6 +7929,7 @@ impl<
outbound_capacity_msat: 0,
next_outbound_htlc_limit_msat: 0,
next_outbound_htlc_minimum_msat: u64::MAX,
dust_exposure_msat: 0,
}
});
let is_in_range = (balances.next_outbound_htlc_minimum_msat
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,7 @@ mod tests {
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
pending_inbound_htlcs: Vec::new(),
pending_outbound_htlcs: Vec::new(),
current_dust_exposure_msat: None,
}
}

Expand Down Expand Up @@ -9665,6 +9666,7 @@ pub(crate) mod bench_utils {
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
pending_inbound_htlcs: Vec::new(),
pending_outbound_htlcs: Vec::new(),
current_dust_exposure_msat: None,
}
}

Expand Down
3 changes: 3 additions & 0 deletions lightning/src/sign/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,16 @@ fn get_available_balances(
available_capacity_msat = 0;
}

let dust_exposure_msat = cmp::max(local_dust_exposure_msat, remote_dust_exposure_msat);

#[allow(deprecated)] // TODO: Remove once balance_msat is removed
crate::ln::channel::AvailableBalances {
inbound_capacity_msat: remote_balance_before_fee_msat
.saturating_sub(channel_constraints.holder_selected_channel_reserve_satoshis * 1000),
outbound_capacity_msat,
next_outbound_htlc_limit_msat: available_capacity_msat,
next_outbound_htlc_minimum_msat,
dust_exposure_msat,
}
}

Expand Down
Loading