@@ -32,16 +32,17 @@ use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
3232use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , Balance , MonitorEvent , TransactionOutputs , WithChannelMonitor } ;
3333use crate :: chain:: transaction:: { OutPoint , TransactionData } ;
3434use crate :: ln:: types:: ChannelId ;
35+ use crate :: ln:: msgs:: { self , BaseMessageHandler , Init , MessageSendEvent } ;
3536use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
3637use crate :: events:: { self , Event , EventHandler , ReplayEvent } ;
3738use crate :: util:: logger:: { Logger , WithContext } ;
3839use crate :: util:: errors:: APIError ;
3940use crate :: util:: persist:: MonitorName ;
4041use crate :: util:: wakers:: { Future , Notifier } ;
4142use crate :: ln:: channel_state:: ChannelDetails ;
42-
4343use crate :: prelude:: * ;
4444use crate :: sync:: { RwLock , RwLockReadGuard , Mutex , MutexGuard } ;
45+ use crate :: types:: features:: { InitFeatures , NodeFeatures } ;
4546use core:: ops:: Deref ;
4647use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
4748use bitcoin:: secp256k1:: PublicKey ;
@@ -253,6 +254,7 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
253254 /// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for
254255 /// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
255256 event_notifier : Notifier ,
257+ pending_send_only_events : Mutex < Vec < MessageSendEvent > > ,
256258}
257259
258260impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > ChainMonitor < ChannelSigner , C , T , F , L , P >
@@ -386,7 +388,15 @@ where C::Target: chain::Filter,
386388 /// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
387389 /// always need to fetch full blocks absent another means for determining which blocks contain
388390 /// transactions relevant to the watched channels.
389- pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P ) -> Self {
391+ ///
392+ /// # Note
393+ /// `our_peerstorage_encryption_key` must be obtained from [`crate::sign::NodeSigner::get_peer_storage_key()`].
394+ /// This key is used to encrypt peer storage backups.
395+ ///
396+ /// **Important**: This key should not be set arbitrarily or changed after initialization. The same key
397+ /// is obtained by the `ChannelManager` through `KeyMananger` to decrypt peer backups.
398+ /// Using an inconsistent or incorrect key will result in the inability to decrypt previously encrypted backups.
399+ pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P , our_peerstorage_encryption_key : [ u8 ; 32 ] ) -> Self {
390400 Self {
391401 monitors : RwLock :: new ( new_hash_map ( ) ) ,
392402 chain_source,
@@ -397,6 +407,7 @@ where C::Target: chain::Filter,
397407 pending_monitor_events : Mutex :: new ( Vec :: new ( ) ) ,
398408 highest_chain_height : AtomicUsize :: new ( 0 ) ,
399409 event_notifier : Notifier :: new ( ) ,
410+ pending_send_only_events : Mutex :: new ( Vec :: new ( ) ) ,
400411 }
401412 }
402413
@@ -665,6 +676,48 @@ where C::Target: chain::Filter,
665676 } ) ;
666677 }
667678 }
679+
680+ /// Retrieves all node IDs associated with the monitors.
681+ ///
682+ /// This function collects the counterparty node IDs from all monitors into a `HashSet`,
683+ /// ensuring unique IDs are returned.
684+ fn get_peer_node_ids ( & self ) -> HashSet < PublicKey > {
685+ let mon = self . monitors . read ( ) . unwrap ( ) ;
686+ mon
687+ . values ( )
688+ . map ( |monitor| monitor. monitor . get_counterparty_node_id ( ) )
689+ . collect ( )
690+ }
691+
692+ fn send_peer_storage ( & self , their_node_id : PublicKey ) {
693+ // TODO: Serialize `ChannelMonitor`s inside `our_peer_storage` and update [`OurPeerStorage::block_height`] accordingly.
694+ }
695+ }
696+
697+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > BaseMessageHandler for ChainMonitor < ChannelSigner , C , T , F , L , P >
698+ where C :: Target : chain:: Filter ,
699+ T :: Target : BroadcasterInterface ,
700+ F :: Target : FeeEstimator ,
701+ L :: Target : Logger ,
702+ P :: Target : Persist < ChannelSigner > ,
703+ {
704+ fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
705+ let mut pending_events = self . pending_send_only_events . lock ( ) . unwrap ( ) ;
706+ let mut ret = Vec :: new ( ) ;
707+ core:: mem:: swap ( & mut ret, & mut * pending_events) ;
708+ ret }
709+
710+ fn peer_disconnected ( & self , _their_node_id : PublicKey ) { }
711+
712+ fn provided_node_features ( & self ) -> NodeFeatures {
713+ NodeFeatures :: empty ( )
714+ }
715+
716+ fn provided_init_features ( & self , _their_node_id : PublicKey ) -> InitFeatures {
717+ InitFeatures :: empty ( )
718+ }
719+
720+ fn peer_connected ( & self , _their_node_id : PublicKey , _msg : & Init , _inbound : bool ) -> Result < ( ) , ( ) > { Ok ( ( ) ) }
668721}
669722
670723impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
0 commit comments