Skip to content

Commit 890caa2

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 bbfa15e commit 890caa2

File tree

5 files changed

+38
-71
lines changed

5 files changed

+38
-71
lines changed

fuzz/src/router.rs

Lines changed: 0 additions & 1 deletion
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_public: 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

Lines changed: 0 additions & 12 deletions
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.
@@ -3077,14 +3074,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30773074
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator);
30783075
let htlc_stats = context.get_pending_htlc_stats(None, dust_exposure_limiting_feerate);
30793076

3080-
let mut balance_msat = context.value_to_self_msat;
3081-
for ref htlc in context.pending_inbound_htlcs.iter() {
3082-
if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state {
3083-
balance_msat += htlc.amount_msat;
3084-
}
3085-
}
3086-
balance_msat -= htlc_stats.pending_outbound_htlcs_value_msat;
3087-
30883077
let outbound_capacity_msat = context.value_to_self_msat
30893078
.saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat)
30903079
.saturating_sub(
@@ -3226,7 +3215,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32263215
outbound_capacity_msat,
32273216
next_outbound_htlc_limit_msat: available_capacity_msat,
32283217
next_outbound_htlc_minimum_msat,
3229-
balance_msat,
32303218
}
32313219
}
32323220

lightning/src/ln/channel_state.rs

Lines changed: 37 additions & 56 deletions
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,
@@ -569,41 +554,38 @@ impl Writeable for ChannelDetails {
569554
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
570555
let user_channel_id_low = self.user_channel_id as u64;
571556
let user_channel_id_high_opt = Some((self.user_channel_id >> 64) as u64);
572-
#[allow(deprecated)] // TODO: Remove once balance_msat is removed.
573-
{
574-
write_tlv_fields!(writer, {
575-
(1, self.inbound_scid_alias, option),
576-
(2, self.channel_id, required),
577-
(3, self.channel_type, option),
578-
(4, self.counterparty, required),
579-
(5, self.outbound_scid_alias, option),
580-
(6, self.funding_txo, option),
581-
(7, self.config, option),
582-
(8, self.short_channel_id, option),
583-
(9, self.confirmations, option),
584-
(10, self.channel_value_satoshis, required),
585-
(12, self.unspendable_punishment_reserve, option),
586-
(14, user_channel_id_low, required),
587-
(16, self.balance_msat, required),
588-
(18, self.outbound_capacity_msat, required),
589-
(19, self.next_outbound_htlc_limit_msat, required),
590-
(20, self.inbound_capacity_msat, required),
591-
(21, self.next_outbound_htlc_minimum_msat, required),
592-
(22, self.confirmations_required, option),
593-
(24, self.force_close_spend_delay, option),
594-
(26, self.is_outbound, required),
595-
(28, self.is_channel_ready, required),
596-
(30, self.is_usable, required),
597-
(32, self.is_public, required),
598-
(33, self.inbound_htlc_minimum_msat, option),
599-
(35, self.inbound_htlc_maximum_msat, option),
600-
(37, user_channel_id_high_opt, option),
601-
(39, self.feerate_sat_per_1000_weight, option),
602-
(41, self.channel_shutdown_state, option),
603-
(43, self.pending_inbound_htlcs, optional_vec),
604-
(45, self.pending_outbound_htlcs, optional_vec),
605-
});
606-
}
557+
write_tlv_fields!(writer, {
558+
(1, self.inbound_scid_alias, option),
559+
(2, self.channel_id, required),
560+
(3, self.channel_type, option),
561+
(4, self.counterparty, required),
562+
(5, self.outbound_scid_alias, option),
563+
(6, self.funding_txo, option),
564+
(7, self.config, option),
565+
(8, self.short_channel_id, option),
566+
(9, self.confirmations, option),
567+
(10, self.channel_value_satoshis, required),
568+
(12, self.unspendable_punishment_reserve, option),
569+
(14, user_channel_id_low, required),
570+
(16, self.next_outbound_htlc_limit_msat, required), // Forwards compatibility for removed balance_msat field.
571+
(18, self.outbound_capacity_msat, required),
572+
(19, self.next_outbound_htlc_limit_msat, required),
573+
(20, self.inbound_capacity_msat, required),
574+
(21, self.next_outbound_htlc_minimum_msat, required),
575+
(22, self.confirmations_required, option),
576+
(24, self.force_close_spend_delay, option),
577+
(26, self.is_outbound, required),
578+
(28, self.is_channel_ready, required),
579+
(30, self.is_usable, required),
580+
(32, self.is_public, required),
581+
(33, self.inbound_htlc_minimum_msat, option),
582+
(35, self.inbound_htlc_maximum_msat, option),
583+
(37, user_channel_id_high_opt, option),
584+
(39, self.feerate_sat_per_1000_weight, option),
585+
(41, self.channel_shutdown_state, option),
586+
(43, self.pending_inbound_htlcs, optional_vec),
587+
(45, self.pending_outbound_htlcs, optional_vec),
588+
});
607589
Ok(())
608590
}
609591
}
@@ -623,7 +605,7 @@ impl Readable for ChannelDetails {
623605
(10, channel_value_satoshis, required),
624606
(12, unspendable_punishment_reserve, option),
625607
(14, user_channel_id_low, required),
626-
(16, balance_msat, required),
608+
(16, _balance_msat, option), // Backwards compatibility for removed balance_msat field.
627609
(18, outbound_capacity_msat, required),
628610
// Note that by the time we get past the required read above, outbound_capacity_msat will be
629611
// filled in, so we can safely unwrap it here.
@@ -651,7 +633,8 @@ impl Readable for ChannelDetails {
651633
let user_channel_id = user_channel_id_low as u128
652634
+ ((user_channel_id_high_opt.unwrap_or(0 as u64) as u128) << 64);
653635

654-
#[allow(deprecated)] // TODO: Remove once balance_msat is removed.
636+
let _balance_msat: Option<u64> = _balance_msat;
637+
655638
Ok(Self {
656639
inbound_scid_alias,
657640
channel_id: channel_id.0.unwrap(),
@@ -664,7 +647,6 @@ impl Readable for ChannelDetails {
664647
channel_value_satoshis: channel_value_satoshis.0.unwrap(),
665648
unspendable_punishment_reserve,
666649
user_channel_id,
667-
balance_msat: balance_msat.0.unwrap(),
668650
outbound_capacity_msat: outbound_capacity_msat.0.unwrap(),
669651
next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat.0.unwrap(),
670652
next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat.0.unwrap(),
@@ -762,7 +744,6 @@ mod tests {
762744
inbound_scid_alias: None,
763745
channel_value_satoshis: 50_100,
764746
user_channel_id: (u64::MAX as u128) + 1, // Gets us into the high bytes
765-
balance_msat: 23_100,
766747
outbound_capacity_msat: 24_300,
767748
next_outbound_htlc_limit_msat: 20_000,
768749
next_outbound_htlc_minimum_msat: 132,

lightning/src/routing/router.rs

Lines changed: 0 additions & 2 deletions
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,
@@ -8797,7 +8796,6 @@ pub(crate) mod bench_utils {
87978796
outbound_scid_alias: None,
87988797
channel_value_satoshis: 10_000_000_000,
87998798
user_channel_id: 0,
8800-
balance_msat: 10_000_000_000,
88018799
outbound_capacity_msat: 10_000_000_000,
88028800
next_outbound_htlc_minimum_msat: 0,
88038801
next_outbound_htlc_limit_msat: 10_000_000_000,
Lines changed: 1 addition & 0 deletions
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)