diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index d3c788463..c205c35cf 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_monitor_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..995f1318f 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_monitor_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 {