Skip to content

Commit ad683d8

Browse files
committed
f fix logic + add an s
1 parent ed06722 commit ad683d8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lightning/src/ln/channel.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct ChannelValueStat {
6262
pub counterparty_dust_limit_msat: u64,
6363
}
6464

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

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

2352-
let mut balance_msat = self.value_to_self_msat - outbound_stats.pending_htlcs_value_msat;
2352+
let mut balance_msat = self.value_to_self_msat;
23532353
for ref htlc in self.pending_inbound_htlcs.iter() {
23542354
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
23552355
balance_msat += htlc.amount_msat;
23562356
}
23572357
}
2358+
balance_msat -= outbound_stats.pending_htlcs_value_msat;
23582359

23592360
let outbound_capacity_msat = cmp::max(self.value_to_self_msat as i64
23602361
- outbound_stats.pending_htlcs_value_msat as i64
23612362
- self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) as i64 * 1000,
23622363
0) as u64;
2363-
AvailableBalance {
2364+
AvailableBalances {
23642365
inbound_capacity_msat: cmp::max(self.channel_value_satoshis as i64 * 1000
23652366
- self.value_to_self_msat as i64
23662367
- self.get_inbound_pending_htlc_stats(None).pending_htlcs_value_msat as i64

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
16771677
let channel_state = self.channel_state.lock().unwrap();
16781678
res.reserve(channel_state.by_id.len());
16791679
for (channel_id, channel) in channel_state.by_id.iter().filter(f) {
1680-
let balance = channel.get_available_balance_msat();
1680+
let balance = channel.get_available_balances();
16811681
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
16821682
channel.get_holder_counterparty_selected_channel_reserve_satoshis();
16831683
res.push(ChannelDetails {

0 commit comments

Comments
 (0)