@@ -371,6 +371,9 @@ pub struct ChainMonitor<
371371
372372 #[ cfg( peer_storage) ]
373373 our_peerstorage_encryption_key : PeerStorageKey ,
374+
375+ /// If false, claim info persistence events are swallowed.
376+ offload_claim_info : bool ,
374377}
375378
376379impl <
@@ -397,7 +400,7 @@ where
397400 pub fn new_async_beta (
398401 chain_source : Option < C > , broadcaster : T , logger : L , feeest : F ,
399402 persister : MonitorUpdatingPersisterAsync < K , S , L , ES , SP , T , F > , _entropy_source : ES ,
400- _our_peerstorage_encryption_key : PeerStorageKey ,
403+ _our_peerstorage_encryption_key : PeerStorageKey , offload_claim_info : bool ,
401404 ) -> Self {
402405 let event_notifier = Arc :: new ( Notifier :: new ( ) ) ;
403406 Self {
@@ -414,6 +417,7 @@ where
414417 pending_send_only_events : Mutex :: new ( Vec :: new ( ) ) ,
415418 #[ cfg( peer_storage) ]
416419 our_peerstorage_encryption_key : _our_peerstorage_encryption_key,
420+ offload_claim_info,
417421 }
418422 }
419423}
@@ -590,6 +594,15 @@ where
590594 /// always need to fetch full blocks absent another means for determining which blocks contain
591595 /// transactions relevant to the watched channels.
592596 ///
597+ /// If `offload_claim_info` is set to `true`, [`Event::PersistClaimInfo`] events will be
598+ /// surfaced, allowing callers to offload claim information from [`ChannelMonitor`]s to reduce
599+ /// their size. If set to `false`, these events will be silently ignored and the claim
600+ /// information will remain in-memory and in each [`ChannelMonitor`] on disk.
601+ ///
602+ /// Note that no matter the value of `offload_claim_info`, [`Event::ClaimInfoRequest`]s will be
603+ /// surfaced if needed. If [`Event::PersistClaimInfo`]s have never been surfaced/handled for a
604+ /// node, no [`Event::ClaimInfoRequest`] will be generated.
605+ ///
593606 /// # Note
594607 /// `our_peerstorage_encryption_key` must be obtained from [`NodeSigner::get_peer_storage_key`].
595608 /// This key is used to encrypt peer storage backups.
@@ -601,9 +614,12 @@ where
601614 /// [`NodeSigner`]: crate::sign::NodeSigner
602615 /// [`NodeSigner::get_peer_storage_key`]: crate::sign::NodeSigner::get_peer_storage_key
603616 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
617+ /// [`Event::PersistClaimInfo`]: crate::events::Event::PersistClaimInfo
618+ /// [`Event::ClaimInfoRequest`]: crate::events::Event::ClaimInfoRequest
604619 pub fn new (
605620 chain_source : Option < C > , broadcaster : T , logger : L , feeest : F , persister : P ,
606621 _entropy_source : ES , _our_peerstorage_encryption_key : PeerStorageKey ,
622+ offload_claim_info : bool ,
607623 ) -> Self {
608624 Self {
609625 monitors : RwLock :: new ( new_hash_map ( ) ) ,
@@ -619,6 +635,7 @@ where
619635 pending_send_only_events : Mutex :: new ( Vec :: new ( ) ) ,
620636 #[ cfg( peer_storage) ]
621637 our_peerstorage_encryption_key : _our_peerstorage_encryption_key,
638+ offload_claim_info,
622639 }
623640 }
624641
@@ -880,7 +897,17 @@ where
880897 self . monitors. read( ) . unwrap( ) . get( & channel_id) . map( |m| & m. monitor) ,
881898 self . logger,
882899 ev,
883- handler( ev) . await
900+ {
901+ if !self . offload_claim_info {
902+ if let Event :: PersistClaimInfo { .. } = & ev {
903+ Ok ( ( ) )
904+ } else {
905+ handler( ev) . await
906+ }
907+ } else {
908+ handler( ev) . await
909+ }
910+ }
884911 ) {
885912 Ok ( ( ) ) => { } ,
886913 Err ( ReplayEvent ( ) ) => {
@@ -1539,8 +1566,16 @@ where
15391566 where
15401567 H :: Target : EventHandler ,
15411568 {
1569+ let filtering_handler = |event : events:: Event | {
1570+ if !self . offload_claim_info {
1571+ if let events:: Event :: PersistClaimInfo { .. } = & event {
1572+ return Ok ( ( ) ) ;
1573+ }
1574+ }
1575+ handler. handle_event ( event)
1576+ } ;
15421577 for monitor_state in self . monitors . read ( ) . unwrap ( ) . values ( ) {
1543- match monitor_state. monitor . process_pending_events ( & handler , & self . logger ) {
1578+ match monitor_state. monitor . process_pending_events ( & & filtering_handler , & self . logger ) {
15441579 Ok ( ( ) ) => { } ,
15451580 Err ( ReplayEvent ( ) ) => {
15461581 self . event_notifier . notify ( ) ;
0 commit comments