@@ -35,7 +35,7 @@ use crate::ln::types::ChannelId;
3535use crate :: ln:: msgs:: { self , BaseMessageHandler , Init , MessageSendEvent } ;
3636use crate :: ln:: our_peer_storage:: OurPeerStorage ;
3737use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
38- use crate :: sign:: PeerStorageKey ;
38+ use crate :: sign:: { EntropySource , PeerStorageKey } ;
3939use crate :: events:: { self , Event , EventHandler , ReplayEvent } ;
4040use crate :: util:: logger:: { Logger , WithContext } ;
4141use crate :: util:: errors:: APIError ;
@@ -234,19 +234,21 @@ impl<ChannelSigner: EcdsaChannelSigner> Deref for LockedChannelMonitor<'_, Chann
234234/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
235235/// [module-level documentation]: crate::chain::chainmonitor
236236/// [`rebroadcast_pending_claims`]: Self::rebroadcast_pending_claims
237- pub struct ChainMonitor < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
237+ pub struct ChainMonitor < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref >
238238 where C :: Target : chain:: Filter ,
239239 T :: Target : BroadcasterInterface ,
240240 F :: Target : FeeEstimator ,
241241 L :: Target : Logger ,
242242 P :: Target : Persist < ChannelSigner > ,
243+ ES :: Target : EntropySource ,
243244{
244245 monitors : RwLock < HashMap < ChannelId , MonitorHolder < ChannelSigner > > > ,
245246 chain_source : Option < C > ,
246247 broadcaster : T ,
247248 logger : L ,
248249 fee_estimator : F ,
249250 persister : P ,
251+ entropy_source : ES ,
250252 /// "User-provided" (ie persistence-completion/-failed) [`MonitorEvent`]s. These came directly
251253 /// from the user and not from a [`ChannelMonitor`].
252254 pending_monitor_events : Mutex < Vec < ( OutPoint , ChannelId , Vec < MonitorEvent > , PublicKey ) > > ,
@@ -261,12 +263,13 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
261263 our_peerstorage_encryption_key : PeerStorageKey ,
262264}
263265
264- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > ChainMonitor < ChannelSigner , C , T , F , L , P >
266+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref > ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
265267where C :: Target : chain:: Filter ,
266268 T :: Target : BroadcasterInterface ,
267269 F :: Target : FeeEstimator ,
268270 L :: Target : Logger ,
269271 P :: Target : Persist < ChannelSigner > ,
272+ ES :: Target : EntropySource ,
270273{
271274 /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
272275 /// of a channel and reacting accordingly based on transactions in the given chain data. See
@@ -400,14 +403,15 @@ where C::Target: chain::Filter,
400403 /// **Important**: This key should not be set arbitrarily or changed after initialization. The same key
401404 /// is obtained by the `ChannelManager` through `KeyMananger` to decrypt peer backups.
402405 /// Using an inconsistent or incorrect key will result in the inability to decrypt previously encrypted backups.
403- pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P , our_peerstorage_encryption_key : PeerStorageKey ) -> Self {
406+ pub fn new ( chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P , entropy_source : ES , our_peerstorage_encryption_key : PeerStorageKey ) -> Self {
404407 Self {
405408 monitors : RwLock :: new ( new_hash_map ( ) ) ,
406409 chain_source,
407410 broadcaster,
408411 logger,
409412 fee_estimator : feeest,
410413 persister,
414+ entropy_source,
411415 pending_monitor_events : Mutex :: new ( Vec :: new ( ) ) ,
412416 highest_chain_height : AtomicUsize :: new ( 0 ) ,
413417 event_notifier : Notifier :: new ( ) ,
@@ -697,19 +701,20 @@ where C::Target: chain::Filter,
697701 fn send_peer_storage ( & self , their_node_id : PublicKey ) {
698702 // TODO: Serialize `ChannelMonitor`s inside `our_peer_storage`.
699703
700- let our_peer_storage = OurPeerStorage :: create_from_data ( self . our_peerstorage_encryption_key . clone ( ) , Vec :: new ( ) ) ;
704+ let our_peer_storage = OurPeerStorage :: create_from_data ( self . our_peerstorage_encryption_key . clone ( ) , Vec :: new ( ) , self . entropy_source . get_secure_random_bytes ( ) ) ;
701705 log_debug ! ( self . logger, "Sending Peer Storage from chainmonitor" ) ;
702706 self . pending_send_only_events . lock ( ) . unwrap ( ) . push ( MessageSendEvent :: SendPeerStorage { node_id : their_node_id,
703707 msg : msgs:: PeerStorage { data : our_peer_storage. encrypted_data ( ) } } )
704708 }
705709}
706710
707- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > BaseMessageHandler for ChainMonitor < ChannelSigner , C , T , F , L , P >
711+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref > BaseMessageHandler for ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
708712where C :: Target : chain:: Filter ,
709713 T :: Target : BroadcasterInterface ,
710714 F :: Target : FeeEstimator ,
711715 L :: Target : Logger ,
712716 P :: Target : Persist < ChannelSigner > ,
717+ ES :: Target : EntropySource ,
713718{
714719 fn get_and_clear_pending_msg_events ( & self ) -> Vec < MessageSendEvent > {
715720 let mut pending_events = self . pending_send_only_events . lock ( ) . unwrap ( ) ;
@@ -729,14 +734,15 @@ where C::Target: chain::Filter,
729734 fn peer_connected ( & self , _their_node_id : PublicKey , _msg : & Init , _inbound : bool ) -> Result < ( ) , ( ) > { Ok ( ( ) ) }
730735}
731736
732- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
733- chain:: Listen for ChainMonitor < ChannelSigner , C , T , F , L , P >
737+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref >
738+ chain:: Listen for ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
734739where
735740 C :: Target : chain:: Filter ,
736741 T :: Target : BroadcasterInterface ,
737742 F :: Target : FeeEstimator ,
738743 L :: Target : Logger ,
739744 P :: Target : Persist < ChannelSigner > ,
745+ ES :: Target : EntropySource ,
740746{
741747 fn filtered_block_connected ( & self , header : & Header , txdata : & TransactionData , height : u32 ) {
742748 log_debug ! ( self . logger, "New best block {} at height {} provided via block_connected" , header. block_hash( ) , height) ;
@@ -764,14 +770,15 @@ where
764770 }
765771}
766772
767- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
768- chain:: Confirm for ChainMonitor < ChannelSigner , C , T , F , L , P >
773+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref >
774+ chain:: Confirm for ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
769775where
770776 C :: Target : chain:: Filter ,
771777 T :: Target : BroadcasterInterface ,
772778 F :: Target : FeeEstimator ,
773779 L :: Target : Logger ,
774780 P :: Target : Persist < ChannelSigner > ,
781+ ES :: Target : EntropySource ,
775782{
776783 fn transactions_confirmed ( & self , header : & Header , txdata : & TransactionData , height : u32 ) {
777784 log_debug ! ( self . logger, "{} provided transactions confirmed at height {} in block {}" , txdata. len( ) , height, header. block_hash( ) ) ;
@@ -824,13 +831,14 @@ where
824831 }
825832}
826833
827- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref >
828- chain:: Watch < ChannelSigner > for ChainMonitor < ChannelSigner , C , T , F , L , P >
834+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref >
835+ chain:: Watch < ChannelSigner > for ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
829836where C :: Target : chain:: Filter ,
830837 T :: Target : BroadcasterInterface ,
831838 F :: Target : FeeEstimator ,
832839 L :: Target : Logger ,
833840 P :: Target : Persist < ChannelSigner > ,
841+ ES :: Target : EntropySource ,
834842{
835843 fn watch_channel ( & self , channel_id : ChannelId , monitor : ChannelMonitor < ChannelSigner > ) -> Result < ChannelMonitorUpdateStatus , ( ) > {
836844 let logger = WithChannelMonitor :: from ( & self . logger , & monitor, None ) ;
@@ -963,12 +971,13 @@ where C::Target: chain::Filter,
963971 }
964972}
965973
966- impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref > events:: EventsProvider for ChainMonitor < ChannelSigner , C , T , F , L , P >
974+ impl < ChannelSigner : EcdsaChannelSigner , C : Deref , T : Deref , F : Deref , L : Deref , P : Deref , ES : Deref > events:: EventsProvider for ChainMonitor < ChannelSigner , C , T , F , L , P , ES >
967975 where C :: Target : chain:: Filter ,
968976 T :: Target : BroadcasterInterface ,
969977 F :: Target : FeeEstimator ,
970978 L :: Target : Logger ,
971979 P :: Target : Persist < ChannelSigner > ,
980+ ES :: Target : EntropySource ,
972981{
973982 /// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
974983 ///
0 commit comments