Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ interface Node {
sequence<PaymentDetails> list_payments();
sequence<PeerDetails> list_peers();
sequence<ChannelDetails> list_channels();
sequence<ChannelMonitorSizeInfo> list_channel_monitor_sizes();
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
Expand Down Expand Up @@ -618,6 +619,11 @@ dictionary PeerDetails {
boolean is_connected;
};

dictionary ChannelMonitorSizeInfo {
ChannelId channel_id;
u64 size_bytes;
};

[Enum]
interface LightningBalance {
ClaimableOnChannelClose (
Expand Down
29 changes: 27 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ChannelMonitorSizeInfo> {
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.
Expand Down
11 changes: 11 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading