@@ -14,7 +14,6 @@ use crate::config::{
14
14
Config , EsploraSyncConfig , BDK_CLIENT_CONCURRENCY , BDK_CLIENT_STOP_GAP ,
15
15
BDK_WALLET_SYNC_TIMEOUT_SECS , FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS , LDK_WALLET_SYNC_TIMEOUT_SECS ,
16
16
RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL , TX_BROADCAST_TIMEOUT_SECS ,
17
- WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
18
17
} ;
19
18
use crate :: fee_estimator:: {
20
19
apply_post_estimation_adjustments, get_all_conf_targets, get_num_block_defaults_for_target,
@@ -208,31 +207,73 @@ impl ChainSource {
208
207
match self {
209
208
Self :: Esplora { sync_config, logger, .. } => {
210
209
// Setup syncing intervals
211
- let onchain_wallet_sync_interval_secs = sync_config
212
- . onchain_wallet_sync_interval_secs
213
- . max ( WALLET_SYNC_INTERVAL_MINIMUM_SECS ) ;
214
- let mut onchain_wallet_sync_interval =
215
- tokio:: time:: interval ( Duration :: from_secs ( onchain_wallet_sync_interval_secs) ) ;
216
- onchain_wallet_sync_interval
217
- . set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
210
+ let mut onchain_wallet_sync_interval = match sync_config
211
+ . onchain_wallet_sync_interval_secs ( )
212
+ {
213
+ Some ( secs) => {
214
+ log_info ! (
215
+ logger,
216
+ "Onchain wallet background syncing enabled with interval of {} seconds" ,
217
+ secs
218
+ ) ;
219
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( secs) ) ;
220
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
221
+ Some ( interval)
222
+ } ,
223
+ None => {
224
+ log_info ! (
225
+ logger,
226
+ "Onchain wallet background syncing disabled. Manual syncing required." ,
227
+ ) ;
228
+ None
229
+ } ,
230
+ } ;
218
231
219
- let fee_rate_cache_update_interval_secs = sync_config
220
- . fee_rate_cache_update_interval_secs
221
- . max ( WALLET_SYNC_INTERVAL_MINIMUM_SECS ) ;
222
- let mut fee_rate_update_interval =
223
- tokio:: time:: interval ( Duration :: from_secs ( fee_rate_cache_update_interval_secs) ) ;
224
- // When starting up, we just blocked on updating, so skip the first tick.
225
- fee_rate_update_interval. reset ( ) ;
226
- fee_rate_update_interval
227
- . set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
232
+ let mut fee_rate_update_interval = match sync_config
233
+ . fee_rate_cache_update_interval_secs ( )
234
+ {
235
+ Some ( secs) => {
236
+ log_info ! (
237
+ logger,
238
+ "Fee rate cache background updating enabled with interval of {} seconds" ,
239
+ secs
240
+ ) ;
241
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( secs) ) ;
242
+ // When starting up, we just blocked on updating, so skip the first tick.
243
+ interval. reset ( ) ;
244
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
245
+ Some ( interval)
246
+ } ,
247
+ None => {
248
+ log_info ! (
249
+ logger,
250
+ "Fee rate cache background updating disabled. Manual updates required." ,
251
+ ) ;
252
+ None
253
+ } ,
254
+ } ;
228
255
229
- let lightning_wallet_sync_interval_secs = sync_config
230
- . lightning_wallet_sync_interval_secs
231
- . max ( WALLET_SYNC_INTERVAL_MINIMUM_SECS ) ;
232
- let mut lightning_wallet_sync_interval =
233
- tokio:: time:: interval ( Duration :: from_secs ( lightning_wallet_sync_interval_secs) ) ;
234
- lightning_wallet_sync_interval
235
- . set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
256
+ let mut lightning_wallet_sync_interval = match sync_config
257
+ . lightning_wallet_sync_interval_secs ( )
258
+ {
259
+ Some ( secs) => {
260
+ log_info ! (
261
+ logger,
262
+ "Lightning wallet background syncing enabled with interval of {} seconds" ,
263
+ secs
264
+ ) ;
265
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( secs) ) ;
266
+ interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Skip ) ;
267
+ Some ( interval)
268
+ } ,
269
+ None => {
270
+ log_info ! (
271
+ logger,
272
+ "Lightning wallet background syncing disabled. Manual syncing required." ,
273
+ ) ;
274
+ None
275
+ } ,
276
+ } ;
236
277
237
278
// Start the syncing loop.
238
279
loop {
@@ -244,13 +285,34 @@ impl ChainSource {
244
285
) ;
245
286
return ;
246
287
}
247
- _ = onchain_wallet_sync_interval. tick( ) => {
288
+
289
+ _ = async {
290
+ if let Some ( ref mut interval) = onchain_wallet_sync_interval {
291
+ interval. tick( ) . await
292
+ } else {
293
+ std:: future:: pending:: <tokio:: time:: Instant >( ) . await
294
+ }
295
+ } , if onchain_wallet_sync_interval. is_some( ) => {
248
296
let _ = self . sync_onchain_wallet( ) . await ;
249
297
}
250
- _ = fee_rate_update_interval. tick( ) => {
298
+
299
+ _ = async {
300
+ if let Some ( ref mut interval) = fee_rate_update_interval {
301
+ interval. tick( ) . await
302
+ } else {
303
+ std:: future:: pending:: <tokio:: time:: Instant >( ) . await
304
+ }
305
+ } , if fee_rate_update_interval. is_some( ) => {
251
306
let _ = self . update_fee_rate_estimates( ) . await ;
252
307
}
253
- _ = lightning_wallet_sync_interval. tick( ) => {
308
+
309
+ _ = async {
310
+ if let Some ( ref mut interval) = lightning_wallet_sync_interval {
311
+ interval. tick( ) . await
312
+ } else {
313
+ std:: future:: pending:: <tokio:: time:: Instant >( ) . await
314
+ }
315
+ } , if lightning_wallet_sync_interval. is_some( ) => {
254
316
let _ = self . sync_lightning_wallet(
255
317
Arc :: clone( & channel_manager) ,
256
318
Arc :: clone( & chain_monitor) ,
0 commit comments