From 69e75d9d61134884b6909a67f1cfc1053e2a6cdb Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Thu, 15 Aug 2024 00:47:49 +0700 Subject: [PATCH] feat: split esplora clients --- src/builder.rs | 16 ++++++++++------ src/config.rs | 2 +- src/lib.rs | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 1ab3c7b4d..56f3f3730 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -558,21 +558,25 @@ fn build_with_store_internal( let (blockchain, tx_sync, tx_broadcaster, fee_estimator) = match chain_data_source_config { Some(ChainDataSourceConfig::Esplora(server_url)) => { + log_info!(logger, "Using custom esplora server: {}", server_url); let mut client_builder = esplora_client::Builder::new(&server_url.clone()); client_builder = client_builder.timeout(DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS); - let esplora_client = client_builder.build_async().unwrap(); + let tx_sync = Arc::new(EsploraSyncClient::from_client( - esplora_client.clone(), + client_builder.clone().build_async().unwrap(), Arc::clone(&logger), )); - let blockchain = EsploraBlockchain::from_client(esplora_client, BDK_CLIENT_STOP_GAP) - .with_concurrency(BDK_CLIENT_CONCURRENCY); + let blockchain = EsploraBlockchain::from_client( + client_builder.clone().build_async().unwrap(), + BDK_CLIENT_STOP_GAP, + ) + .with_concurrency(BDK_CLIENT_CONCURRENCY); let tx_broadcaster = Arc::new(TransactionBroadcaster::new( - tx_sync.client().clone(), + client_builder.clone().build_async().unwrap(), Arc::clone(&logger), )); let fee_estimator = Arc::new(OnchainFeeEstimator::new( - tx_sync.client().clone(), + client_builder.clone().build_async().unwrap(), Arc::clone(&config), Arc::clone(&logger), )); diff --git a/src/config.rs b/src/config.rs index 9fdefccf5..fcf6ee7d9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,7 +32,7 @@ pub(crate) const BDK_CLIENT_CONCURRENCY: u8 = 4; pub(crate) const DEFAULT_ESPLORA_SERVER_URL: &str = "https://blockstream.info/api"; // The default Esplora client timeout we're using. -pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 100; // Alby - higher than the sync timeout to avoid deadlocks // 10; +pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 10; // The timeout after which we abandon retrying failed payments. pub(crate) const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(50); // (10); diff --git a/src/lib.rs b/src/lib.rs index 33b3c8b4a..030b31cff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1338,6 +1338,7 @@ impl Node { let now = Instant::now(); // We don't add an additional timeout here, as `Wallet::sync` already returns // after a timeout. + log_info!(sync_logger, "Starting wallet sync"); match wallet.sync().await { Ok(()) => { log_info!( @@ -1357,6 +1358,7 @@ impl Node { }, }; + log_info!(sync_logger, "Starting fee estimates sync"); let now = Instant::now(); // We don't add an additional timeout here, as // `FeeEstimator::update_fee_estimates` already returns after a timeout. @@ -1379,6 +1381,7 @@ impl Node { }, } + log_info!(sync_logger, "Starting LDK wallet sync"); let now = Instant::now(); let tx_sync_timeout_fut = tokio::time::timeout( Duration::from_secs(LDK_WALLET_SYNC_TIMEOUT_SECS),