@@ -161,8 +161,8 @@ use types::{
161161 OnionMessenger , PaymentStore , PeerManager , Router , Scorer , Sweeper , Wallet ,
162162} ;
163163pub use types:: {
164- ChannelDetails , CustomTlvRecord , DynStore , PeerDetails , SyncAndAsyncKVStore , UserChannelId ,
165- WordCount ,
164+ ChannelDetails , ChannelMonitorSizeInfo , CustomTlvRecord , DynStore , PeerDetails ,
165+ SyncAndAsyncKVStore , UserChannelId , WordCount ,
166166} ;
167167pub 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.
0 commit comments