Skip to content

Commit

Permalink
f fix logic + add an s
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Apr 27, 2022
1 parent ed06722 commit 68a08f7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lightning/src/ln/channel.rs
Expand Up @@ -62,7 +62,7 @@ pub struct ChannelValueStat {
pub counterparty_dust_limit_msat: u64,
}

pub struct AvailableBalance {
pub struct AvailableBalances {
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
pub balance_msat: u64,
/// Total amount available for our counterparty to send to us, ignoring HTLCs.
Expand Down Expand Up @@ -2341,26 +2341,27 @@ impl<Signer: Sign> Channel<Signer> {
stats
}

/// Get the available balances, see [`AvailableBalance`]'s fields for more info.
/// Get the available balances, see [`AvailableBalances`]'s fields for more info.
/// Doesn't bother handling the
/// if-we-removed-it-already-but-haven't-fully-resolved-they-can-still-send-an-inbound-HTLC
/// corner case properly.
pub fn get_available_balance_msat(&self) -> AvailableBalance {
pub fn get_available_balance_msat(&self) -> AvailableBalances {
// Note that we have to handle overflow due to the above case.
let outbound_stats = self.get_outbound_pending_htlc_stats(None);

let mut balance_msat = self.value_to_self_msat - outbound_stats.pending_htlcs_value_msat;
let mut balance_msat = self.value_to_self_msat;
for ref htlc in self.pending_inbound_htlcs.iter() {
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
balance_msat += htlc.amount_msat;
}
}
balance_msat -= outbound_stats.pending_htlcs_value_msat;

let outbound_capacity_msat = cmp::max(self.value_to_self_msat as i64
- outbound_stats.pending_htlcs_value_msat as i64
- self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) as i64 * 1000,
0) as u64;
AvailableBalance {
AvailableBalances {
inbound_capacity_msat: cmp::max(self.channel_value_satoshis as i64 * 1000
- self.value_to_self_msat as i64
- self.get_inbound_pending_htlc_stats(None).pending_htlcs_value_msat as i64
Expand Down

0 comments on commit 68a08f7

Please sign in to comment.