Skip to content

Commit 59f1689

Browse files
dunxenwvanlint
andcommitted
Remove AvailableBalances::balance_msat
The ChannelMonitor::get_claimable_balances and ChainMonitor::get_claimable_balances methods provide a more straightforward approach to the balance of a channel, which satisfies most use cases. The computation of AvailableBalances::balance_msat is complex and originally had a different purpose that is not applicable anymore. Co-authored-by: Willem Van Lint <[email protected]>
1 parent eba329c commit 59f1689

File tree

5 files changed

+7
-37
lines changed

5 files changed

+7
-37
lines changed

fuzz/src/router.rs

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
242242
is_channel_ready: true,
243243
is_usable: true,
244244
is_announced: true,
245-
balance_msat: 0,
246245
outbound_capacity_msat: capacity.saturating_mul(1000),
247246
next_outbound_htlc_limit_msat: capacity.saturating_mul(1000),
248247
next_outbound_htlc_minimum_msat: 0,

lightning/src/ln/channel.rs

-12
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ pub struct ChannelValueStat {
7979
}
8080

8181
pub struct AvailableBalances {
82-
/// The amount that would go to us if we close the channel, ignoring any on-chain fees.
83-
#[deprecated(since = "0.0.124", note = "use [`ChainMonitor::get_claimable_balances`] instead")]
84-
pub balance_msat: u64,
8582
/// Total amount available for our counterparty to send to us.
8683
pub inbound_capacity_msat: u64,
8784
/// Total amount available for us to send to our counterparty.
@@ -3089,14 +3086,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30893086
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
30903087
let htlc_stats = context.get_pending_htlc_stats(None, dust_exposure_limiting_feerate);
30913088

3092-
let mut balance_msat = context.value_to_self_msat;
3093-
for ref htlc in context.pending_inbound_htlcs.iter() {
3094-
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
3095-
balance_msat += htlc.amount_msat;
3096-
}
3097-
}
3098-
balance_msat -= htlc_stats.pending_outbound_htlcs_value_msat;
3099-
31003089
let outbound_capacity_msat = context.value_to_self_msat
31013090
.saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat)
31023091
.saturating_sub(
@@ -3238,7 +3227,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32383227
outbound_capacity_msat,
32393228
next_outbound_htlc_limit_msat: available_capacity_msat,
32403229
next_outbound_htlc_minimum_msat,
3241-
balance_msat,
32423230
}
32433231
}
32443232

lightning/src/ln/channel_state.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -359,25 +359,11 @@ pub struct ChannelDetails {
359359
///
360360
/// This value will be `None` for objects serialized with LDK versions prior to 0.0.115.
361361
pub feerate_sat_per_1000_weight: Option<u32>,
362-
/// Our total balance. This is the amount we would get if we close the channel.
363-
/// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
364-
/// amount is not likely to be recoverable on close.
365-
///
366-
/// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose
367-
/// balance is not available for inclusion in new outbound HTLCs). This further does not include
368-
/// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
369-
/// This does not consider any on-chain fees.
370-
///
371-
/// See also [`ChannelDetails::outbound_capacity_msat`]
372-
#[deprecated(since = "0.0.124", note = "use [`ChainMonitor::get_claimable_balances`] instead")]
373-
pub balance_msat: u64,
374362
/// The available outbound capacity for sending HTLCs to the remote peer. This does not include
375363
/// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not
376364
/// available for inclusion in new outbound HTLCs). This further does not include any pending
377365
/// outgoing HTLCs which are awaiting some other resolution to be sent.
378366
///
379-
/// See also [`ChannelDetails::balance_msat`]
380-
///
381367
/// This value is not exact. Due to various in-flight changes, feerate changes, and our
382368
/// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we
383369
/// should be able to spend nearly this amount.
@@ -387,8 +373,8 @@ pub struct ChannelDetails {
387373
/// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
388374
/// to use a limit as close as possible to the HTLC limit we can currently send.
389375
///
390-
/// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`],
391-
/// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`].
376+
/// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`] and
377+
/// [`ChannelDetails::outbound_capacity_msat`].
392378
pub next_outbound_htlc_limit_msat: u64,
393379
/// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of
394380
/// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than
@@ -540,7 +526,6 @@ impl ChannelDetails {
540526
channel_value_satoshis: context.get_value_satoshis(),
541527
feerate_sat_per_1000_weight: Some(context.get_feerate_sat_per_1000_weight()),
542528
unspendable_punishment_reserve: to_self_reserve_satoshis,
543-
balance_msat: balance.balance_msat,
544529
inbound_capacity_msat: balance.inbound_capacity_msat,
545530
outbound_capacity_msat: balance.outbound_capacity_msat,
546531
next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
@@ -584,7 +569,7 @@ impl Writeable for ChannelDetails {
584569
(10, self.channel_value_satoshis, required),
585570
(12, self.unspendable_punishment_reserve, option),
586571
(14, user_channel_id_low, required),
587-
(16, self.balance_msat, required),
572+
(16, self.next_outbound_htlc_limit_msat, required), // Forwards compatibility for removed balance_msat field.
588573
(18, self.outbound_capacity_msat, required),
589574
(19, self.next_outbound_htlc_limit_msat, required),
590575
(20, self.inbound_capacity_msat, required),
@@ -623,7 +608,7 @@ impl Readable for ChannelDetails {
623608
(10, channel_value_satoshis, required),
624609
(12, unspendable_punishment_reserve, option),
625610
(14, user_channel_id_low, required),
626-
(16, balance_msat, required),
611+
(16, _balance_msat, option), // Backwards compatibility for removed balance_msat field.
627612
(18, outbound_capacity_msat, required),
628613
// Note that by the time we get past the required read above, outbound_capacity_msat will be
629614
// filled in, so we can safely unwrap it here.
@@ -651,7 +636,8 @@ impl Readable for ChannelDetails {
651636
let user_channel_id = user_channel_id_low as u128
652637
+ ((user_channel_id_high_opt.unwrap_or(0 as u64) as u128) << 64);
653638

654-
#[allow(deprecated)] // TODO: Remove once balance_msat is removed.
639+
let _balance_msat: Option<u64> = _balance_msat;
640+
655641
Ok(Self {
656642
inbound_scid_alias,
657643
channel_id: channel_id.0.unwrap(),
@@ -664,7 +650,6 @@ impl Readable for ChannelDetails {
664650
channel_value_satoshis: channel_value_satoshis.0.unwrap(),
665651
unspendable_punishment_reserve,
666652
user_channel_id,
667-
balance_msat: balance_msat.0.unwrap(),
668653
outbound_capacity_msat: outbound_capacity_msat.0.unwrap(),
669654
next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat.0.unwrap(),
670655
next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat.0.unwrap(),
@@ -762,7 +747,6 @@ mod tests {
762747
inbound_scid_alias: None,
763748
channel_value_satoshis: 50_100,
764749
user_channel_id: (u64::MAX as u128) + 1, // Gets us into the high bytes
765-
balance_msat: 23_100,
766750
outbound_capacity_msat: 24_300,
767751
next_outbound_htlc_limit_msat: 20_000,
768752
next_outbound_htlc_minimum_msat: 132,

lightning/src/routing/router.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,6 @@ mod tests {
36093609
inbound_scid_alias: None,
36103610
channel_value_satoshis: 0,
36113611
user_channel_id: 0,
3612-
balance_msat: 0,
36133612
outbound_capacity_msat,
36143613
next_outbound_htlc_limit_msat: outbound_capacity_msat,
36153614
next_outbound_htlc_minimum_msat: 0,
@@ -8793,7 +8792,6 @@ pub(crate) mod bench_utils {
87938792
outbound_scid_alias: None,
87948793
channel_value_satoshis: 10_000_000_000,
87958794
user_channel_id: 0,
8796-
balance_msat: 10_000_000_000,
87978795
outbound_capacity_msat: 10_000_000_000,
87988796
next_outbound_htlc_minimum_msat: 0,
87998797
next_outbound_htlc_limit_msat: 10_000_000_000,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* The `AvailableBalances::balance_msat` field has been removed in favor of `ChainMonitor::get_claimable_balances`. `ChannelDetails` serialized with versions of LDK >= 0.0.125 will have their `balance_msat` field set to `next_outbound_htlc_limit_msat` when read by versions of LDK prior to 0.0.125 (#3243).

0 commit comments

Comments
 (0)