Skip to content

Commit 039c38d

Browse files
committed
Expose HTLCStats in ChannelDetails
1 parent b6787a4 commit 039c38d

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
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

+3-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::ln::features::{ChannelTypeFeatures, InitFeatures};
2727
use crate::ln::msgs;
2828
use crate::ln::msgs::DecodeError;
2929
use crate::ln::script::{self, ShutdownScript};
30-
use crate::ln::channelmanager::{self, CounterpartyForwardingInfo, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
30+
use crate::ln::channelmanager::{self, CounterpartyForwardingInfo, PendingHTLCStatus, HTLCSource, HTLCStats, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
3131
use crate::ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight, htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS, get_commitment_transaction_number_obscure_factor, ClosingTransaction};
3232
use crate::ln::chan_utils;
3333
use crate::ln::onion_utils::HTLCFailReason;
@@ -347,16 +347,6 @@ enum HTLCInitiator {
347347
RemoteOffered,
348348
}
349349

350-
/// 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
358-
}
359-
360350
/// An enum gathering stats on commitment transaction, either local or remote.
361351
struct CommitmentStats<'a> {
362352
tx: CommitmentTransaction, // the transaction info
@@ -2621,7 +2611,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
26212611
}
26222612

26232613
/// Returns a HTLCStats about inbound pending htlcs
2624-
fn get_inbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
2614+
pub(super) fn get_inbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
26252615
let mut stats = HTLCStats {
26262616
pending_htlcs: self.pending_inbound_htlcs.len() as u32,
26272617
pending_htlcs_value_msat: 0,
@@ -2653,7 +2643,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
26532643
}
26542644

26552645
/// 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 {
2646+
pub(super) fn get_outbound_pending_htlc_stats(&self, outbound_feerate_update: Option<u32>) -> HTLCStats {
26572647
let mut stats = HTLCStats {
26582648
pending_htlcs: self.pending_outbound_htlcs.len() as u32,
26592649
pending_htlcs_value_msat: 0,

lightning/src/ln/channelmanager.rs

+49
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,39 @@ pub struct ChannelCounterparty {
12701270
pub outbound_htlc_maximum_msat: Option<u64>,
12711271
}
12721272

1273+
/// An enum gathering stats on pending HTLCs, either inbound or outbound side.
1274+
#[derive(Debug, Clone, Copy, PartialEq)]
1275+
pub struct HTLCStats {
1276+
/// The number of pending HTLCs.
1277+
pub pending_htlcs: u32,
1278+
/// The total value of pending HTLCs.
1279+
pub pending_htlcs_value_msat: u64,
1280+
/// The total dust exposure for the counterparty.
1281+
pub on_counterparty_tx_dust_exposure_msat: u64,
1282+
/// The total dust exposure for the local node.
1283+
pub on_holder_tx_dust_exposure_msat: u64,
1284+
/// The total value of pending, outgoing HTLCs being held.
1285+
///
1286+
/// These HTLCs are being held temporarily after sending commitment_signed to discern them
1287+
/// from HTLCs implicitly included in the counterparty's revoke_and_ack.
1288+
pub holding_cell_msat: u64,
1289+
/// The number of pending, outgoing HTLCs being added that are being held,
1290+
/// dust HTLCS not included.
1291+
///
1292+
/// These HTLCs are being held temporarily after sending commitment_signed to discern them
1293+
/// from HTLCs implicitly included in the counterparty's revoke_and_ack.
1294+
pub on_holder_tx_holding_cell_htlcs_count: u32,
1295+
}
1296+
1297+
impl_writeable_tlv_based!(HTLCStats, {
1298+
(0, pending_htlcs, required),
1299+
(2, pending_htlcs_value_msat, required),
1300+
(4, on_counterparty_tx_dust_exposure_msat, required),
1301+
(6, on_holder_tx_dust_exposure_msat, required),
1302+
(8, holding_cell_msat, required),
1303+
(10, on_holder_tx_holding_cell_htlcs_count, required),
1304+
});
1305+
12731306
/// Details of a channel, as returned by [`ChannelManager::list_channels`] and [`ChannelManager::list_usable_channels`]
12741307
#[derive(Clone, Debug, PartialEq)]
12751308
pub struct ChannelDetails {
@@ -1441,6 +1474,14 @@ pub struct ChannelDetails {
14411474
///
14421475
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
14431476
pub config: Option<ChannelConfig>,
1477+
/// Statistics on pending incoming HTLCs.
1478+
///
1479+
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.116.
1480+
pub incoming_htlc_stats: Option<HTLCStats>,
1481+
/// Statistics on pending outgoing HTLCs.
1482+
///
1483+
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.116.
1484+
pub outgoing_htlc_stats: Option<HTLCStats>,
14441485
}
14451486

14461487
impl ChannelDetails {
@@ -1512,6 +1553,8 @@ impl ChannelDetails {
15121553
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
15131554
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
15141555
config: Some(channel.config()),
1556+
incoming_htlc_stats: Some(channel.get_inbound_pending_htlc_stats(None)),
1557+
outgoing_htlc_stats: Some(channel.get_outbound_pending_htlc_stats(None)),
15151558
}
15161559
}
15171560
}
@@ -7190,6 +7233,8 @@ impl Writeable for ChannelDetails {
71907233
(35, self.inbound_htlc_maximum_msat, option),
71917234
(37, user_channel_id_high_opt, option),
71927235
(39, self.feerate_sat_per_1000_weight, option),
7236+
(41, self.incoming_htlc_stats, option),
7237+
(43, self.outgoing_htlc_stats, option),
71937238
});
71947239
Ok(())
71957240
}
@@ -7227,6 +7272,8 @@ impl Readable for ChannelDetails {
72277272
(35, inbound_htlc_maximum_msat, option),
72287273
(37, user_channel_id_high_opt, option),
72297274
(39, feerate_sat_per_1000_weight, option),
7275+
(40, incoming_htlc_stats, option),
7276+
(41, outgoing_htlc_stats, option),
72307277
});
72317278

72327279
// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -7262,6 +7309,8 @@ impl Readable for ChannelDetails {
72627309
inbound_htlc_minimum_msat,
72637310
inbound_htlc_maximum_msat,
72647311
feerate_sat_per_1000_weight,
7312+
incoming_htlc_stats,
7313+
outgoing_htlc_stats,
72657314
})
72667315
}
72677316
}

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)