@@ -36,7 +36,7 @@ use lightning_transaction_sync::EsploraSyncClient;
3636use lightning_block_sync:: gossip:: UtxoSource ;
3737use lightning_block_sync:: init:: { synchronize_listeners, validate_best_block_header} ;
3838use lightning_block_sync:: poll:: { ChainPoller , ChainTip , ValidatedBlockHeader } ;
39- use lightning_block_sync:: SpvClient ;
39+ use lightning_block_sync:: { BlockSourceErrorKind , SpvClient } ;
4040
4141use bdk_esplora:: EsploraAsyncExt ;
4242use bdk_wallet:: Update as BdkUpdate ;
@@ -425,6 +425,8 @@ impl ChainSource {
425425 "Starting initial synchronization of chain listeners. This might take a while.." ,
426426 ) ;
427427
428+ let mut backoff_delay_multiplier = 0 ;
429+
428430 loop {
429431 let channel_manager_best_block_hash =
430432 channel_manager. current_best_block ( ) . block_hash ;
@@ -504,8 +506,23 @@ impl ChainSource {
504506
505507 Err ( e) => {
506508 log_error ! ( logger, "Failed to synchronize chain listeners: {:?}" , e) ;
507- tokio:: time:: sleep ( Duration :: from_secs ( CHAIN_POLLING_INTERVAL_SECS ) )
508- . await ;
509+ backoff_delay_multiplier += 1 ;
510+ let backoff_delay =
511+ CHAIN_POLLING_INTERVAL_SECS * backoff_delay_multiplier;
512+ if e. kind ( ) == BlockSourceErrorKind :: Transient {
513+ log_info ! (
514+ logger,
515+ "Transient error. Retrying sync in {} seconds (backoff multiplier: {})." ,
516+ backoff_delay,
517+ backoff_delay_multiplier
518+ ) ;
519+ tokio:: time:: sleep ( Duration :: from_secs ( backoff_delay) ) . await ;
520+ } else {
521+ log_error ! (
522+ logger,
523+ "Failed to synchronize chain listeners: {:?}, e"
524+ ) ;
525+ }
509526 } ,
510527 }
511528 }
0 commit comments