@@ -32,16 +32,18 @@ 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 ;
37+ use crate :: sign:: PeerStorageKey ;
3638use crate :: events:: { self , Event , EventHandler , ReplayEvent } ;
3739use crate :: util:: logger:: { Logger , WithContext } ;
3840use crate :: util:: errors:: APIError ;
3941use crate :: util:: persist:: MonitorName ;
4042use crate :: util:: wakers:: { Future , Notifier } ;
4143use crate :: ln:: channel_state:: ChannelDetails ;
42-
4344use crate :: prelude:: * ;
4445use crate :: sync:: { RwLock , RwLockReadGuard , Mutex , MutexGuard } ;
46+ use crate :: types:: features:: { InitFeatures , NodeFeatures } ;
4547use core:: ops:: Deref ;
4648use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
4749use bitcoin:: secp256k1:: PublicKey ;
@@ -253,6 +255,7 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
253255 /// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for
254256 /// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
255257 event_notifier : Notifier ,
258+ pending_send_only_events : Mutex < Vec < MessageSendEvent > > ,
256259}
257260
258261impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > ChainMonitor < ChannelSigner , C , T , F , L , P >
@@ -386,7 +389,15 @@ where C::Target: chain::Filter,
386389 /// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
387390 /// always need to fetch full blocks absent another means for determining which blocks contain
388391 /// transactions relevant to the watched channels.
389- pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P ) -> Self {
392+ ///
393+ /// # Note
394+ /// `our_peerstorage_encryption_key` must be obtained from [`crate::sign::NodeSigner::get_peer_storage_key()`].
395+ /// This key is used to encrypt peer storage backups.
396+ ///
397+ /// **Important**: This key should not be set arbitrarily or changed after initialization. The same key
398+ /// is obtained by the `ChannelManager` through `KeyMananger` to decrypt peer backups.
399+ /// Using an inconsistent or incorrect key will result in the inability to decrypt previously encrypted backups.
400+ pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P , our_peerstorage_encryption_key : PeerStorageKey ) -> Self {
390401 Self {
391402 monitors : RwLock :: new ( new_hash_map ( ) ) ,
392403 chain_source,
@@ -397,6 +408,7 @@ where C::Target: chain::Filter,
397408 pending_monitor_events : Mutex :: new ( Vec :: new ( ) ) ,
398409 highest_chain_height : AtomicUsize :: new ( 0 ) ,
399410 event_notifier : Notifier :: new ( ) ,
411+ pending_send_only_events : Mutex :: new ( Vec :: new ( ) ) ,
400412 }
401413 }
402414
@@ -665,6 +677,47 @@ where C::Target: chain::Filter,
665677 } ) ;
666678 }
667679 }
680+
681+ /// Retrieves all node IDs associated with the monitors.
682+ ///
683+ /// This function collects the counterparty node IDs from all monitors into a `HashSet`,
684+ /// ensuring unique IDs are returned.
685+ fn all_counterparty_node_ids ( & self ) -> HashSet < PublicKey > {
686+ let mon = self . monitors . read ( ) . unwrap ( ) ;
687+ mon
688+ . values ( )
689+ . map ( |monitor| monitor. monitor . get_counterparty_node_id ( ) )
690+ . collect ( )
691+ }
692+
693+ fn send_peer_storage ( & self , their_node_id : PublicKey ) {
694+ // TODO: Serialize `ChannelMonitor`s inside `our_peer_storage` and update [`OurPeerStorage::block_height`] accordingly.
695+ }
696+ }
697+
698+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > BaseMessageHandler for ChainMonitor < ChannelSigner , C , T , F , L , P >
699+ where C :: Target : chain:: Filter ,
700+ T :: Target : BroadcasterInterface ,
701+ F :: Target : FeeEstimator ,
702+ L :: Target : Logger ,
703+ P :: Target : Persist < ChannelSigner > ,
704+ {
705+ fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
706+ let mut pending_events = self . pending_send_only_events . lock ( ) . unwrap ( ) ;
707+ core:: mem:: take ( & mut * pending_events)
708+ }
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