Skip to content

Commit 0f5cd35

Browse files
committed
Expose HTLCStats in ChannelDetails
1 parent d78dd48 commit 0f5cd35

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

fuzz/src/router.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 13 deletions
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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,39 @@ pub struct ChannelCounterparty {
12721272
pub outbound_htlc_maximum_msat: Option<u64>,
12731273
}
12741274

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

14481489
impl ChannelDetails {
@@ -1514,6 +1555,8 @@ impl ChannelDetails {
15141555
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
15151556
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
15161557
config: Some(channel.config()),
1558+
incoming_htlc_stats: Some(channel.get_inbound_pending_htlc_stats(None)),
1559+
outgoing_htlc_stats: Some(channel.get_outbound_pending_htlc_stats(None)),
15171560
}
15181561
}
15191562
}
@@ -7156,6 +7199,8 @@ impl Writeable for ChannelDetails {
71567199
(35, self.inbound_htlc_maximum_msat, option),
71577200
(37, user_channel_id_high_opt, option),
71587201
(39, self.feerate_sat_per_1000_weight, option),
7202+
(41, self.incoming_htlc_stats, option),
7203+
(43, self.outgoing_htlc_stats, option),
71597204
});
71607205
Ok(())
71617206
}
@@ -7193,6 +7238,8 @@ impl Readable for ChannelDetails {
71937238
(35, inbound_htlc_maximum_msat, option),
71947239
(37, user_channel_id_high_opt, option),
71957240
(39, feerate_sat_per_1000_weight, option),
7241+
(40, incoming_htlc_stats, option),
7242+
(41, outgoing_htlc_stats, option),
71967243
});
71977244

71987245
// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -7228,6 +7275,8 @@ impl Readable for ChannelDetails {
72287275
inbound_htlc_minimum_msat,
72297276
inbound_htlc_maximum_msat,
72307277
feerate_sat_per_1000_weight,
7278+
incoming_htlc_stats,
7279+
outgoing_htlc_stats,
72317280
})
72327281
}
72337282
}

lightning/src/routing/router.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,9 @@ mod tests {
25122512
inbound_htlc_minimum_msat: None,
25132513
inbound_htlc_maximum_msat: None,
25142514
config: None,
2515-
feerate_sat_per_1000_weight: None
2515+
feerate_sat_per_1000_weight: None,
2516+
incoming_htlc_stats: None,
2517+
outgoing_htlc_stats: None,
25162518
}
25172519
}
25182520

@@ -6299,6 +6301,8 @@ pub(crate) mod bench_utils {
62996301
inbound_htlc_maximum_msat: None,
63006302
config: None,
63016303
feerate_sat_per_1000_weight: None,
6304+
incoming_htlc_stats: None,
6305+
outgoing_htlc_stats: None,
63026306
}
63036307
}
63046308

0 commit comments

Comments
 (0)