@@ -24,10 +24,7 @@ use lightning::util::ser::Writeable;
2424use lightning_transaction_sync:: ElectrumSyncClient ;
2525
2626use super :: WalletSyncStatus ;
27- use crate :: config:: {
28- Config , ElectrumSyncConfig , BDK_CLIENT_STOP_GAP , BDK_WALLET_SYNC_TIMEOUT_SECS ,
29- FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS , LDK_WALLET_SYNC_TIMEOUT_SECS , TX_BROADCAST_TIMEOUT_SECS ,
30- } ;
27+ use crate :: config:: { Config , ElectrumSyncConfig , BDK_CLIENT_STOP_GAP } ;
3128use crate :: error:: Error ;
3229use crate :: fee_estimator:: {
3330 apply_post_estimation_adjustments, get_all_conf_targets, get_num_block_defaults_for_target,
@@ -41,7 +38,6 @@ use crate::NodeMetrics;
4138
4239const BDK_ELECTRUM_CLIENT_BATCH_SIZE : usize = 5 ;
4340const ELECTRUM_CLIENT_NUM_RETRIES : u8 = 3 ;
44- const ELECTRUM_CLIENT_TIMEOUT_SECS : u8 = 10 ;
4541
4642pub ( super ) struct ElectrumChainSource {
4743 server_url : String ,
@@ -82,6 +78,7 @@ impl ElectrumChainSource {
8278 pub ( super ) fn start ( & self , runtime : Arc < Runtime > ) -> Result < ( ) , Error > {
8379 self . electrum_runtime_status . write ( ) . unwrap ( ) . start (
8480 self . server_url . clone ( ) ,
81+ self . sync_config . clone ( ) ,
8582 Arc :: clone ( & runtime) ,
8683 Arc :: clone ( & self . config ) ,
8784 Arc :: clone ( & self . logger ) ,
@@ -318,13 +315,14 @@ impl ElectrumRuntimeStatus {
318315 }
319316
320317 pub ( super ) fn start (
321- & mut self , server_url : String , runtime : Arc < Runtime > , config : Arc < Config > ,
322- logger : Arc < Logger > ,
318+ & mut self , server_url : String , sync_config : ElectrumSyncConfig , runtime : Arc < Runtime > ,
319+ config : Arc < Config > , logger : Arc < Logger > ,
323320 ) -> Result < ( ) , Error > {
324321 match self {
325322 Self :: Stopped { pending_registered_txs, pending_registered_outputs } => {
326323 let client = Arc :: new ( ElectrumRuntimeClient :: new (
327- server_url. clone ( ) ,
324+ server_url,
325+ sync_config,
328326 runtime,
329327 config,
330328 logger,
@@ -380,6 +378,7 @@ impl ElectrumRuntimeStatus {
380378
381379struct ElectrumRuntimeClient {
382380 electrum_client : Arc < ElectrumClient > ,
381+ sync_config : ElectrumSyncConfig ,
383382 bdk_electrum_client : Arc < BdkElectrumClient < Arc < ElectrumClient > > > ,
384383 tx_sync : Arc < ElectrumSyncClient < Arc < Logger > > > ,
385384 runtime : Arc < Runtime > ,
@@ -389,11 +388,12 @@ struct ElectrumRuntimeClient {
389388
390389impl ElectrumRuntimeClient {
391390 fn new (
392- server_url : String , runtime : Arc < Runtime > , config : Arc < Config > , logger : Arc < Logger > ,
391+ server_url : String , sync_config : ElectrumSyncConfig , runtime : Arc < Runtime > ,
392+ config : Arc < Config > , logger : Arc < Logger > ,
393393 ) -> Result < Self , Error > {
394394 let electrum_config = ElectrumConfigBuilder :: new ( )
395395 . retry ( ELECTRUM_CLIENT_NUM_RETRIES )
396- . timeout ( Some ( ELECTRUM_CLIENT_TIMEOUT_SECS ) )
396+ . timeout ( Some ( sync_config . timeouts_config . per_request_timeout_secs ) )
397397 . build ( ) ;
398398
399399 let electrum_client = Arc :: new (
@@ -409,7 +409,15 @@ impl ElectrumRuntimeClient {
409409 Error :: ConnectionFailed
410410 } ) ?,
411411 ) ;
412- Ok ( Self { electrum_client, bdk_electrum_client, tx_sync, runtime, config, logger } )
412+ Ok ( Self {
413+ electrum_client,
414+ sync_config,
415+ bdk_electrum_client,
416+ tx_sync,
417+ runtime,
418+ config,
419+ logger,
420+ } )
413421 }
414422
415423 async fn sync_confirmables (
@@ -419,8 +427,12 @@ impl ElectrumRuntimeClient {
419427
420428 let tx_sync = Arc :: clone ( & self . tx_sync ) ;
421429 let spawn_fut = self . runtime . spawn_blocking ( move || tx_sync. sync ( confirmables) ) ;
422- let timeout_fut =
423- tokio:: time:: timeout ( Duration :: from_secs ( LDK_WALLET_SYNC_TIMEOUT_SECS ) , spawn_fut) ;
430+ let timeout_fut = tokio:: time:: timeout (
431+ Duration :: from_secs (
432+ self . sync_config . timeouts_config . lightning_wallet_sync_timeout_secs ,
433+ ) ,
434+ spawn_fut,
435+ ) ;
424436
425437 let res = timeout_fut
426438 . await
@@ -461,8 +473,10 @@ impl ElectrumRuntimeClient {
461473 true ,
462474 )
463475 } ) ;
464- let wallet_sync_timeout_fut =
465- tokio:: time:: timeout ( Duration :: from_secs ( BDK_WALLET_SYNC_TIMEOUT_SECS ) , spawn_fut) ;
476+ let wallet_sync_timeout_fut = tokio:: time:: timeout (
477+ Duration :: from_secs ( self . sync_config . timeouts_config . onchain_wallet_sync_timeout_secs ) ,
478+ spawn_fut,
479+ ) ;
466480
467481 wallet_sync_timeout_fut
468482 . await
@@ -490,8 +504,10 @@ impl ElectrumRuntimeClient {
490504 let spawn_fut = self . runtime . spawn_blocking ( move || {
491505 bdk_electrum_client. sync ( request, BDK_ELECTRUM_CLIENT_BATCH_SIZE , true )
492506 } ) ;
493- let wallet_sync_timeout_fut =
494- tokio:: time:: timeout ( Duration :: from_secs ( BDK_WALLET_SYNC_TIMEOUT_SECS ) , spawn_fut) ;
507+ let wallet_sync_timeout_fut = tokio:: time:: timeout (
508+ Duration :: from_secs ( self . sync_config . timeouts_config . onchain_wallet_sync_timeout_secs ) ,
509+ spawn_fut,
510+ ) ;
495511
496512 wallet_sync_timeout_fut
497513 . await
@@ -517,8 +533,10 @@ impl ElectrumRuntimeClient {
517533
518534 let spawn_fut =
519535 self . runtime . spawn_blocking ( move || electrum_client. transaction_broadcast ( & tx) ) ;
520- let timeout_fut =
521- tokio:: time:: timeout ( Duration :: from_secs ( TX_BROADCAST_TIMEOUT_SECS ) , spawn_fut) ;
536+ let timeout_fut = tokio:: time:: timeout (
537+ Duration :: from_secs ( self . sync_config . timeouts_config . tx_broadcast_timeout_secs ) ,
538+ spawn_fut,
539+ ) ;
522540
523541 match timeout_fut. await {
524542 Ok ( res) => match res {
@@ -565,7 +583,9 @@ impl ElectrumRuntimeClient {
565583 let spawn_fut = self . runtime . spawn_blocking ( move || electrum_client. batch_call ( & batch) ) ;
566584
567585 let timeout_fut = tokio:: time:: timeout (
568- Duration :: from_secs ( FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS ) ,
586+ Duration :: from_secs (
587+ self . sync_config . timeouts_config . fee_rate_cache_update_timeout_secs ,
588+ ) ,
569589 spawn_fut,
570590 ) ;
571591
0 commit comments