Skip to content

Commit f80dea0

Browse files
committed
feat: add method to list channel monitor sizes
1 parent 5ea6be6 commit f80dea0

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

bindings/ldk_node.udl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ interface Node {
174174
sequence<PaymentDetails> list_payments();
175175
sequence<PeerDetails> list_peers();
176176
sequence<ChannelDetails> list_channels();
177+
sequence<ChannelMonitorSizeInfo> list_channel_sizes();
177178
NetworkGraph network_graph();
178179
string sign_message([ByRef]sequence<u8> msg);
179180
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
@@ -618,6 +619,11 @@ dictionary PeerDetails {
618619
boolean is_connected;
619620
};
620621

622+
dictionary ChannelMonitorSizeInfo {
623+
ChannelId channel_id;
624+
u64 size_bytes;
625+
};
626+
621627
[Enum]
622628
interface LightningBalance {
623629
ClaimableOnChannelClose (

src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ use types::{
161161
OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, Wallet,
162162
};
163163
pub use types::{
164-
ChannelDetails, CustomTlvRecord, DynStore, PeerDetails, SyncAndAsyncKVStore, UserChannelId,
165-
WordCount,
164+
ChannelDetails, ChannelMonitorSizeInfo, CustomTlvRecord, DynStore, PeerDetails,
165+
SyncAndAsyncKVStore, UserChannelId, WordCount,
166166
};
167167
pub use {
168168
bip39, bitcoin, lightning, lightning_invoice, lightning_liquidity, lightning_types, tokio,
@@ -1051,6 +1051,31 @@ impl Node {
10511051
self.channel_manager.list_channels().into_iter().map(|c| c.into()).collect()
10521052
}
10531053

1054+
/// Alby: Retrieve a list of channel monitor sizes (how big each channel monitor is when serialized)
1055+
/// we use this to be able to notify users when their channel monitors are getting too large
1056+
/// (a risk that reading/writing to VSS could start taking too long)
1057+
pub fn list_channel_sizes(&self) -> Vec<ChannelMonitorSizeInfo> {
1058+
use lightning::util::ser::Writeable;
1059+
use std::ops::Deref;
1060+
1061+
let mut channel_sizes = Vec::new();
1062+
1063+
for channel_id in self.chain_monitor.list_monitors() {
1064+
if let Ok(monitor) = self.chain_monitor.get_monitor(channel_id) {
1065+
// Serialize the monitor to count bytes
1066+
let mut size_counter = Vec::new();
1067+
if monitor.deref().write(&mut size_counter).is_ok() {
1068+
channel_sizes.push(ChannelMonitorSizeInfo {
1069+
channel_id,
1070+
size_bytes: size_counter.len() as u64,
1071+
});
1072+
}
1073+
}
1074+
}
1075+
1076+
channel_sizes
1077+
}
1078+
10541079
/// Connect to a node on the peer-to-peer network.
10551080
///
10561081
/// If `persist` is set to `true`, we'll remember the peer and reconnect to it on restart.

src/types.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,17 @@ pub struct PeerDetails {
452452
pub is_connected: bool,
453453
}
454454

455+
/// Information about the size of a channel monitor.
456+
///
457+
/// This includes the channel ID and the serialized size in bytes.
458+
#[derive(Debug, Clone, PartialEq, Eq)]
459+
pub struct ChannelMonitorSizeInfo {
460+
/// The channel ID.
461+
pub channel_id: ChannelId,
462+
/// The size of the channel monitor in bytes when serialized.
463+
pub size_bytes: u64,
464+
}
465+
455466
/// Custom TLV entry. (Alby version)
456467
#[derive(Debug, Clone, PartialEq, Eq)]
457468
pub struct TlvEntry {

0 commit comments

Comments
 (0)