From f80dea0446105f5d02636db70b9f226c6bfa046a Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 6 Jan 2026 15:00:57 +0700 Subject: [PATCH 1/2] feat: add method to list channel monitor sizes --- bindings/ldk_node.udl | 6 ++++++ src/lib.rs | 29 +++++++++++++++++++++++++++-- src/types.rs | 11 +++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index d3c788463..b67cf4ae2 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -174,6 +174,7 @@ interface Node { sequence list_payments(); sequence list_peers(); sequence list_channels(); + sequence list_channel_sizes(); NetworkGraph network_graph(); string sign_message([ByRef]sequence msg); boolean verify_signature([ByRef]sequence msg, [ByRef]string sig, [ByRef]PublicKey pkey); @@ -618,6 +619,11 @@ dictionary PeerDetails { boolean is_connected; }; +dictionary ChannelMonitorSizeInfo { + ChannelId channel_id; + u64 size_bytes; +}; + [Enum] interface LightningBalance { ClaimableOnChannelClose ( diff --git a/src/lib.rs b/src/lib.rs index 9051e5f31..856d7640e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,8 +161,8 @@ use types::{ OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, Wallet, }; pub use types::{ - ChannelDetails, CustomTlvRecord, DynStore, PeerDetails, SyncAndAsyncKVStore, UserChannelId, - WordCount, + ChannelDetails, ChannelMonitorSizeInfo, CustomTlvRecord, DynStore, PeerDetails, + SyncAndAsyncKVStore, UserChannelId, WordCount, }; pub use { bip39, bitcoin, lightning, lightning_invoice, lightning_liquidity, lightning_types, tokio, @@ -1051,6 +1051,31 @@ impl Node { self.channel_manager.list_channels().into_iter().map(|c| c.into()).collect() } + /// Alby: Retrieve a list of channel monitor sizes (how big each channel monitor is when serialized) + /// we use this to be able to notify users when their channel monitors are getting too large + /// (a risk that reading/writing to VSS could start taking too long) + pub fn list_channel_sizes(&self) -> Vec { + use lightning::util::ser::Writeable; + use std::ops::Deref; + + let mut channel_sizes = Vec::new(); + + for channel_id in self.chain_monitor.list_monitors() { + if let Ok(monitor) = self.chain_monitor.get_monitor(channel_id) { + // Serialize the monitor to count bytes + let mut size_counter = Vec::new(); + if monitor.deref().write(&mut size_counter).is_ok() { + channel_sizes.push(ChannelMonitorSizeInfo { + channel_id, + size_bytes: size_counter.len() as u64, + }); + } + } + } + + channel_sizes + } + /// Connect to a node on the peer-to-peer network. /// /// If `persist` is set to `true`, we'll remember the peer and reconnect to it on restart. diff --git a/src/types.rs b/src/types.rs index c0ae1f466..92d42d8fd 100644 --- a/src/types.rs +++ b/src/types.rs @@ -452,6 +452,17 @@ pub struct PeerDetails { pub is_connected: bool, } +/// Information about the size of a channel monitor. +/// +/// This includes the channel ID and the serialized size in bytes. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ChannelMonitorSizeInfo { + /// The channel ID. + pub channel_id: ChannelId, + /// The size of the channel monitor in bytes when serialized. + pub size_bytes: u64, +} + /// Custom TLV entry. (Alby version) #[derive(Debug, Clone, PartialEq, Eq)] pub struct TlvEntry { From e8b1c372dd7ca0cea24142bb1422ed2235d00fb0 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 6 Jan 2026 15:04:23 +0700 Subject: [PATCH 2/2] chore: rename method --- bindings/ldk_node.udl | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index b67cf4ae2..c205c35cf 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -174,7 +174,7 @@ interface Node { sequence list_payments(); sequence list_peers(); sequence list_channels(); - sequence list_channel_sizes(); + sequence list_channel_monitor_sizes(); NetworkGraph network_graph(); string sign_message([ByRef]sequence msg); boolean verify_signature([ByRef]sequence msg, [ByRef]string sig, [ByRef]PublicKey pkey); diff --git a/src/lib.rs b/src/lib.rs index 856d7640e..995f1318f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1054,7 +1054,7 @@ impl Node { /// Alby: Retrieve a list of channel monitor sizes (how big each channel monitor is when serialized) /// we use this to be able to notify users when their channel monitors are getting too large /// (a risk that reading/writing to VSS could start taking too long) - pub fn list_channel_sizes(&self) -> Vec { + pub fn list_channel_monitor_sizes(&self) -> Vec { use lightning::util::ser::Writeable; use std::ops::Deref;