Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,8 @@ impl Node {
total_anchor_channels_reserve_sats(&self.channel_manager, &self.config);
let new_channel_reserve =
self.new_channel_anchor_reserve_sats(&peer_info.node_id)?;
let total_anchor_reserve_sats = cur_anchor_reserve_sats + new_channel_reserve;
let total_anchor_reserve_sats =
cur_anchor_reserve_sats.saturating_add(new_channel_reserve);

let fee_rate = fee_rate.unwrap_or_else(|| {
self.fee_estimator.estimate_fee_rate(ConfirmationTarget::ChannelFunding)
Expand Down Expand Up @@ -1529,7 +1530,7 @@ impl Node {

if for_new_channel {
let required_funds_sats =
amount_sats + self.new_channel_anchor_reserve_sats(peer_node_id)?;
amount_sats.saturating_add(self.new_channel_anchor_reserve_sats(peer_node_id)?);

if spendable_amount_sats < required_funds_sats {
log_error!(self.logger,
Expand Down Expand Up @@ -2717,7 +2718,7 @@ impl_writeable_tlv_based!(NodeMetrics, {
pub(crate) fn total_anchor_channels_reserve_sats(
channel_manager: &ChannelManager, config: &Config,
) -> u64 {
channel_manager
let num_reserved_channels = channel_manager
.list_channels()
.into_iter()
.filter(|c| {
Expand All @@ -2729,8 +2730,8 @@ pub(crate) fn total_anchor_channels_reserve_sats(
.map_or(true, |s| s != ChannelShutdownState::ShutdownComplete)
&& c.channel_type.as_ref().map_or(true, requires_anchor_channel_type)
})
.count() as u64
* config.anchor_channels_config.per_channel_reserve_sats
.count() as u64;
num_reserved_channels.saturating_mul(config.anchor_channels_config.per_channel_reserve_sats)
}

pub(crate) fn new_channel_anchor_reserve_sats(
Expand Down
2 changes: 1 addition & 1 deletion src/liquidity/client/lsps1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
})?;

let lsp_limits = self.lsps1_request_opening_params(node_id).await?.supported_options;
let channel_size_sat = lsp_balance_sat + client_balance_sat;
let channel_size_sat = lsp_balance_sat.saturating_add(client_balance_sat);

if channel_size_sat < lsp_limits.min_channel_balance_sat
|| channel_size_sat > lsp_limits.max_channel_balance_sat
Expand Down
10 changes: 6 additions & 4 deletions src/liquidity/service/lsps2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ where
};

// Fail if we have insufficient onchain funds available.
let over_provisioning_msat = (amt_to_forward_msat
* service_config.channel_over_provisioning_ppm as u64)
let over_provisioning_msat = amt_to_forward_msat
.saturating_mul(service_config.channel_over_provisioning_ppm as u64)
/ 1_000_000;
let channel_amount_sats = (amt_to_forward_msat + over_provisioning_msat) / 1000;
let channel_amount_sats =
amt_to_forward_msat.saturating_add(over_provisioning_msat) / 1000;
let cur_anchor_reserve_sats =
total_anchor_channels_reserve_sats(&self.channel_manager, &self.config);
let spendable_amount_sats =
Expand All @@ -460,7 +461,8 @@ where
&their_network_key,
anchor_channel,
);
let required_funds_sats = channel_amount_sats + additional_reserve_required;
let required_funds_sats =
channel_amount_sats.saturating_add(additional_reserve_required);
if spendable_amount_sats < required_funds_sats {
log_error!(self.logger,
"Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats",
Expand Down
Loading