@@ -33,6 +33,7 @@ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance
3333use crate :: chain:: transaction:: { OutPoint , TransactionData } ;
3434use crate :: ln:: types:: ChannelId ;
3535use crate :: ln:: msgs:: { self , BaseMessageHandler , Init , MessageSendEvent } ;
36+ use crate :: ln:: our_peer_storage:: OurPeerStorage ;
3637use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
3738use crate :: sign:: PeerStorageKey ;
3839use crate :: events:: { self , Event , EventHandler , ReplayEvent } ;
@@ -256,6 +257,8 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
256257 /// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
257258 event_notifier : Notifier ,
258259 pending_send_only_events : Mutex < Vec < MessageSendEvent > > ,
260+
261+ our_peerstorage_encryption_key : PeerStorageKey ,
259262}
260263
261264impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > ChainMonitor < ChannelSigner , C , T , F , L , P >
@@ -409,6 +412,7 @@ where C::Target: chain::Filter,
409412 highest_chain_height : AtomicUsize :: new ( 0 ) ,
410413 event_notifier : Notifier :: new ( ) ,
411414 pending_send_only_events : Mutex :: new ( Vec :: new ( ) ) ,
415+ our_peerstorage_encryption_key
412416 }
413417 }
414418
@@ -691,7 +695,12 @@ where C::Target: chain::Filter,
691695 }
692696
693697 fn send_peer_storage ( & self , their_node_id : PublicKey ) {
694- // TODO: Serialize `ChannelMonitor`s inside `our_peer_storage` and update [`OurPeerStorage::block_height`] accordingly.
698+ // TODO: Serialize `ChannelMonitor`s inside `our_peer_storage`.
699+
700+ let our_peer_storage = OurPeerStorage :: create_from_data ( self . our_peerstorage_encryption_key . clone ( ) , Vec :: new ( ) ) ;
701+ log_debug ! ( self . logger, "Sending Peer Storage from chainmonitor" ) ;
702+ self . pending_send_only_events . lock ( ) . unwrap ( ) . push ( MessageSendEvent :: SendPeerStorage { node_id : their_node_id,
703+ msg : msgs:: PeerStorage { data : our_peer_storage. encrypted_data ( ) } } )
695704 }
696705}
697706
@@ -735,6 +744,12 @@ where
735744 monitor. block_connected (
736745 header, txdata, height, & * self . broadcaster , & * self . fee_estimator , & self . logger )
737746 } ) ;
747+
748+ // Send peer storage everytime a new block arrives.
749+ for node_id in self . all_counterparty_node_ids ( ) {
750+ self . send_peer_storage ( node_id) ;
751+ }
752+
738753 // Assume we may have some new events and wake the event processor
739754 self . event_notifier . notify ( ) ;
740755 }
@@ -786,6 +801,12 @@ where
786801 header, height, & * self . broadcaster , & * self . fee_estimator , & self . logger
787802 )
788803 } ) ;
804+
805+ // Send peer storage everytime a new block arrives.
806+ for node_id in self . all_counterparty_node_ids ( ) {
807+ self . send_peer_storage ( node_id) ;
808+ }
809+
789810 // Assume we may have some new events and wake the event processor
790811 self . event_notifier . notify ( ) ;
791812 }
0 commit comments