@@ -129,30 +129,36 @@ impl ElectrumChainSource {
129129 let incremental_sync =
130130 self . node_metrics . read ( ) . expect ( "lock" ) . latest_onchain_wallet_sync_timestamp . is_some ( ) ;
131131
132- let apply_wallet_update =
133- |update_res : Result < BdkUpdate , Error > , now : Instant | match update_res {
134- Ok ( update) => match onchain_wallet. apply_update ( update) {
135- Ok ( ( ) ) => {
136- log_debug ! (
137- self . logger,
138- "{} of on-chain wallet finished in {}ms." ,
139- if incremental_sync { "Incremental sync" } else { "Sync" } ,
140- now. elapsed( ) . as_millis( )
141- ) ;
142- let unix_time_secs_opt =
143- SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
144- update_and_persist_node_metrics (
145- & self . node_metrics ,
146- & * self . kv_store ,
147- & * self . logger ,
148- |m| m. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt,
149- ) ?;
150- Ok ( ( ) )
132+ macro_rules! apply_wallet_update {
133+ ( $update_res: expr, $now: expr) => {
134+ match $update_res {
135+ Ok ( update) => match onchain_wallet. apply_update( update) {
136+ Ok ( ( ) ) => {
137+ log_debug!(
138+ self . logger,
139+ "{} of on-chain wallet finished in {}ms." ,
140+ if incremental_sync { "Incremental sync" } else { "Sync" } ,
141+ $now. elapsed( ) . as_millis( )
142+ ) ;
143+ let unix_time_secs_opt = SystemTime :: now( )
144+ . duration_since( UNIX_EPOCH )
145+ . ok( )
146+ . map( |d| d. as_secs( ) ) ;
147+ update_and_persist_node_metrics(
148+ & self . node_metrics,
149+ & * self . kv_store,
150+ & * self . logger,
151+ |m| m. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt,
152+ )
153+ . await ?;
154+ Ok ( ( ) )
155+ } ,
156+ Err ( e) => Err ( e) ,
151157 } ,
152158 Err ( e) => Err ( e) ,
153- } ,
154- Err ( e) => Err ( e) ,
159+ }
155160 } ;
161+ }
156162
157163 let cached_txs = onchain_wallet. get_cached_txs ( ) ;
158164
@@ -162,15 +168,15 @@ impl ElectrumChainSource {
162168 . get_incremental_sync_wallet_update ( incremental_sync_request, cached_txs) ;
163169
164170 let now = Instant :: now ( ) ;
165- let update_res = incremental_sync_fut. await . map ( |u| u. into ( ) ) ;
166- apply_wallet_update ( update_res, now)
171+ let update_res: Result < BdkUpdate , Error > = incremental_sync_fut. await . map ( |u| u. into ( ) ) ;
172+ apply_wallet_update ! ( update_res, now)
167173 } else {
168174 let full_scan_request = onchain_wallet. get_full_scan_request ( ) ;
169175 let full_scan_fut =
170176 electrum_client. get_full_scan_wallet_update ( full_scan_request, cached_txs) ;
171177 let now = Instant :: now ( ) ;
172- let update_res = full_scan_fut. await . map ( |u| u. into ( ) ) ;
173- apply_wallet_update ( update_res, now)
178+ let update_res: Result < BdkUpdate , Error > = full_scan_fut. await . map ( |u| u. into ( ) ) ;
179+ apply_wallet_update ! ( update_res, now)
174180 } ;
175181
176182 res
@@ -239,7 +245,8 @@ impl ElectrumChainSource {
239245 & * self . kv_store ,
240246 & * self . logger ,
241247 |m| m. latest_lightning_wallet_sync_timestamp = unix_time_secs_opt,
242- ) ?;
248+ )
249+ . await ?;
243250 }
244251
245252 res
@@ -270,7 +277,8 @@ impl ElectrumChainSource {
270277 SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
271278 update_and_persist_node_metrics ( & self . node_metrics , & * self . kv_store , & * self . logger , |m| {
272279 m. latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
273- } ) ?;
280+ } )
281+ . await ?;
274282
275283 Ok ( ( ) )
276284 }
0 commit comments