Skip to content

Commit 374cec2

Browse files
committed
Expose HTLCStats in ChannelDetails
1 parent b6787a4 commit 374cec2

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

fuzz/src/router.rs

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
270270
inbound_htlc_maximum_msat: None,
271271
config: None,
272272
feerate_sat_per_1000_weight: None,
273+
incoming_htlc_stats: None,
274+
outgoing_htlc_stats: None,
273275
});
274276
}
275277
Some(&first_hops_vec[..])

lightning/src/ln/channel.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,34 @@ enum HTLCInitiator {
348348
}
349349

350350
/// An enum gathering stats on pending HTLCs, either inbound or outbound side.
351-
struct HTLCStats {
352-
pending_htlcs: u32,
353-
pending_htlcs_value_msat: u64,
354-
on_counterparty_tx_dust_exposure_msat: u64,
355-
on_holder_tx_dust_exposure_msat: u64,
356-
holding_cell_msat: u64,
357-
on_holder_tx_holding_cell_htlcs_count: u32, // dust HTLCs *non*-included
351+
#[derive(Debug, Clone, Copy, PartialEq)]
352+
pub struct HTLCStats {
353+
/// The number of pending HTLC's.
354+
pub pending_htlcs: u32,
355+
/// The total value of pending HTLC's.
356+
pub pending_htlcs_value_msat: u64,
357+
/// The total dust exposure for the counterparty.
358+
pub on_counterparty_tx_dust_exposure_msat: u64,
359+
/// The total dust exposure for the local node.
360+
pub on_holder_tx_dust_exposure_msat: u64,
361+
/// The total value of pending, outgoing HTLC's being added that are awaiting remote revocation.
362+
/// See `ChannelState::AwaitingRemoteRevoke`.
363+
pub holding_cell_msat: u64,
364+
/// The number of pending, outgoing HTLC's being added that are awaiting remote revocation,
365+
/// dust HTLCS not included.
366+
/// See `ChannelState::AwaitingRemoteRevoke`.
367+
pub on_holder_tx_holding_cell_htlcs_count: u32,
358368
}
359369

370+
impl_writeable_tlv_based!(HTLCStats, {
371+
(0, pending_htlcs, required),
372+
(1, pending_htlcs_value_msat, required),
373+
(2, on_counterparty_tx_dust_exposure_msat, required),
374+
(3, on_holder_tx_dust_exposure_msat, required),
375+
(4, holding_cell_msat, required),
376+
(5, on_holder_tx_holding_cell_htlcs_count, required),
377+
});
378+
360379
/// An enum gathering stats on commitment transaction, either local or remote.
361380
struct CommitmentStats<'a> {
362381
tx: CommitmentTransaction, // the transaction info
@@ -2621,7 +2640,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
26212640
}
26222641

26232642
/// Returns a HTLCStats about inbound pending htlcs
2624-
fn get_inbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
2643+
pub(super) fn get_inbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
26252644
let mut stats = HTLCStats {
26262645
pending_htlcs: self.pending_inbound_htlcs.len() as u32,
26272646
pending_htlcs_value_msat: 0,
@@ -2653,7 +2672,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
26532672
}
26542673

26552674
/// Returns a HTLCStats about pending outbound htlcs, *including* pending adds in our holding cell.
2656-
fn get_outbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
2675+
pub(super) fn get_outbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
26572676
let mut stats = HTLCStats {
26582677
pending_htlcs: self.pending_outbound_htlcs.len() as u32,
26592678
pending_htlcs_value_msat: 0,

lightning/src/ln/channelmanager.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4040
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4141
// construct one themselves.
4242
use crate::ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret};
43-
use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch};
43+
use crate::ln::channel::{Channel, ChannelError, ChannelUpdateStatus, HTLCStats, ShutdownResult, UpdateFulfillCommitFetch};
4444
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4545
#[cfg(any(feature = "_test_utils", test))]
4646
use crate::ln::features::InvoiceFeatures;
@@ -1441,6 +1441,14 @@ pub struct ChannelDetails {
14411441
///
14421442
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
14431443
pub config: Option<ChannelConfig>,
1444+
/// Statistics on pending incoming HTLCs.
1445+
///
1446+
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.116.
1447+
pub incoming_htlc_stats: Option<HTLCStats>,
1448+
/// Statistics on pending outgoing HTLCs.
1449+
///
1450+
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.116.
1451+
pub outgoing_htlc_stats: Option<HTLCStats>,
14441452
}
14451453

14461454
impl ChannelDetails {
@@ -1512,6 +1520,8 @@ impl ChannelDetails {
15121520
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
15131521
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
15141522
config: Some(channel.config()),
1523+
incoming_htlc_stats: Some(channel.get_inbound_pending_htlc_stats(None)),
1524+
outgoing_htlc_stats: Some(channel.get_outbound_pending_htlc_stats(None)),
15151525
}
15161526
}
15171527
}
@@ -7190,6 +7200,8 @@ impl Writeable for ChannelDetails {
71907200
(35, self.inbound_htlc_maximum_msat, option),
71917201
(37, user_channel_id_high_opt, option),
71927202
(39, self.feerate_sat_per_1000_weight, option),
7203+
(40, self.incoming_htlc_stats, option),
7204+
(41, self.outgoing_htlc_stats, option),
71937205
});
71947206
Ok(())
71957207
}
@@ -7227,6 +7239,8 @@ impl Readable for ChannelDetails {
72277239
(35, inbound_htlc_maximum_msat, option),
72287240
(37, user_channel_id_high_opt, option),
72297241
(39, feerate_sat_per_1000_weight, option),
7242+
(40, incoming_htlc_stats, option),
7243+
(41, outgoing_htlc_stats, option),
72307244
});
72317245

72327246
// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -7262,6 +7276,8 @@ impl Readable for ChannelDetails {
72627276
inbound_htlc_minimum_msat,
72637277
inbound_htlc_maximum_msat,
72647278
feerate_sat_per_1000_weight,
7279+
incoming_htlc_stats,
7280+
outgoing_htlc_stats,
72657281
})
72667282
}
72677283
}

lightning/src/routing/router.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,9 @@ mod tests {
25032503
inbound_htlc_minimum_msat: None,
25042504
inbound_htlc_maximum_msat: None,
25052505
config: None,
2506-
feerate_sat_per_1000_weight: None
2506+
feerate_sat_per_1000_weight: None,
2507+
incoming_htlc_stats: None,
2508+
outgoing_htlc_stats: None,
25072509
}
25082510
}
25092511

@@ -6290,6 +6292,8 @@ pub(crate) mod bench_utils {
62906292
inbound_htlc_maximum_msat: None,
62916293
config: None,
62926294
feerate_sat_per_1000_weight: None,
6295+
incoming_htlc_stats: None,
6296+
outgoing_htlc_stats: None,
62936297
}
62946298
}
62956299

0 commit comments

Comments
 (0)