@@ -39,7 +39,7 @@ use crate::fee_estimator::{
3939 apply_post_estimation_adjustments, get_all_conf_targets, get_num_block_defaults_for_target,
4040 ConfirmationTarget , OnchainFeeEstimator ,
4141} ;
42- use crate :: io:: utils:: write_node_metrics ;
42+ use crate :: io:: utils:: update_and_persist_node_metrics ;
4343use crate :: logger:: { log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger , Logger } ;
4444use crate :: types:: { ChainMonitor , ChannelManager , DynStore , Sweeper , Wallet } ;
4545use crate :: { Error , NodeMetrics } ;
@@ -203,15 +203,18 @@ impl BitcoindChainSource {
203203 * self . latest_chain_tip . write ( ) . expect ( "lock" ) = Some ( chain_tip) ;
204204 let unix_time_secs_opt =
205205 SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
206- let mut locked_node_metrics = self . node_metrics . write ( ) . expect ( "lock" ) ;
207- locked_node_metrics. latest_lightning_wallet_sync_timestamp =
208- unix_time_secs_opt;
209- locked_node_metrics. latest_onchain_wallet_sync_timestamp =
210- unix_time_secs_opt;
211- write_node_metrics ( & * locked_node_metrics, & * self . kv_store , & * self . logger )
212- . unwrap_or_else ( |e| {
213- log_error ! ( self . logger, "Failed to persist node metrics: {}" , e) ;
214- } ) ;
206+ update_and_persist_node_metrics (
207+ & self . node_metrics ,
208+ & * self . kv_store ,
209+ & * self . logger ,
210+ |m| {
211+ m. latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
212+ m. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
213+ } ,
214+ )
215+ . unwrap_or_else ( |e| {
216+ log_error ! ( self . logger, "Failed to persist node metrics: {}" , e) ;
217+ } ) ;
215218 }
216219 break ;
217220 } ,
@@ -454,11 +457,10 @@ impl BitcoindChainSource {
454457
455458 let unix_time_secs_opt =
456459 SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
457- let mut locked_node_metrics = self . node_metrics . write ( ) . expect ( "lock" ) ;
458- locked_node_metrics. latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
459- locked_node_metrics. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
460-
461- write_node_metrics ( & * locked_node_metrics, & * self . kv_store , & * self . logger ) ?;
460+ update_and_persist_node_metrics ( & self . node_metrics , & * self . kv_store , & * self . logger , |m| {
461+ m. latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
462+ m. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
463+ } ) ?;
462464
463465 Ok ( ( ) )
464466 }
@@ -568,11 +570,9 @@ impl BitcoindChainSource {
568570
569571 let unix_time_secs_opt =
570572 SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
571- {
572- let mut locked_node_metrics = self . node_metrics . write ( ) . expect ( "lock" ) ;
573- locked_node_metrics. latest_fee_rate_cache_update_timestamp = unix_time_secs_opt;
574- write_node_metrics ( & * locked_node_metrics, & * self . kv_store , & * self . logger ) ?;
575- }
573+ update_and_persist_node_metrics ( & self . node_metrics , & * self . kv_store , & * self . logger , |m| {
574+ m. latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
575+ } ) ?;
576576
577577 Ok ( ( ) )
578578 }
0 commit comments