@@ -129,37 +129,6 @@ impl ElectrumChainSource {
129129 let incremental_sync =
130130 self . node_metrics . read ( ) . expect ( "lock" ) . latest_onchain_wallet_sync_timestamp . is_some ( ) ;
131131
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) ,
157- } ,
158- Err ( e) => Err ( e) ,
159- }
160- } ;
161- }
162-
163132 let cached_txs = onchain_wallet. get_cached_txs ( ) ;
164133
165134 let res = if incremental_sync {
@@ -169,19 +138,61 @@ impl ElectrumChainSource {
169138
170139 let now = Instant :: now ( ) ;
171140 let update_res: Result < BdkUpdate , Error > = incremental_sync_fut. await . map ( |u| u. into ( ) ) ;
172- apply_wallet_update ! ( update_res, now)
141+ self . apply_onchain_wallet_update (
142+ onchain_wallet. as_ref ( ) ,
143+ incremental_sync,
144+ update_res,
145+ now,
146+ )
147+ . await
173148 } else {
174149 let full_scan_request = onchain_wallet. get_full_scan_request ( ) ;
175150 let full_scan_fut =
176151 electrum_client. get_full_scan_wallet_update ( full_scan_request, cached_txs) ;
177152 let now = Instant :: now ( ) ;
178153 let update_res: Result < BdkUpdate , Error > = full_scan_fut. await . map ( |u| u. into ( ) ) ;
179- apply_wallet_update ! ( update_res, now)
154+ self . apply_onchain_wallet_update (
155+ onchain_wallet. as_ref ( ) ,
156+ incremental_sync,
157+ update_res,
158+ now,
159+ )
160+ . await
180161 } ;
181162
182163 res
183164 }
184165
166+ async fn apply_onchain_wallet_update (
167+ & self , onchain_wallet : & Wallet , incremental_sync : bool ,
168+ update_res : Result < BdkUpdate , Error > , now : Instant ,
169+ ) -> Result < ( ) , Error > {
170+ match update_res {
171+ Ok ( update) => match onchain_wallet. apply_update ( update) {
172+ Ok ( ( ) ) => {
173+ log_debug ! (
174+ self . logger,
175+ "{} of on-chain wallet finished in {}ms." ,
176+ if incremental_sync { "Incremental sync" } else { "Sync" } ,
177+ now. elapsed( ) . as_millis( )
178+ ) ;
179+ let unix_time_secs_opt =
180+ SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . ok ( ) . map ( |d| d. as_secs ( ) ) ;
181+ update_and_persist_node_metrics (
182+ & self . node_metrics ,
183+ & * self . kv_store ,
184+ & * self . logger ,
185+ |m| m. latest_onchain_wallet_sync_timestamp = unix_time_secs_opt,
186+ )
187+ . await ?;
188+ Ok ( ( ) )
189+ } ,
190+ Err ( e) => Err ( e) ,
191+ } ,
192+ Err ( e) => Err ( e) ,
193+ }
194+ }
195+
185196 pub ( crate ) async fn sync_lightning_wallet (
186197 & self , channel_manager : Arc < ChannelManager > , chain_monitor : Arc < ChainMonitor > ,
187198 output_sweeper : Arc < Sweeper > ,
0 commit comments