Skip to content

Commit 0e9caca

Browse files
committed
Also apply a general 10 second socket timeout for the Esplora client
1 parent cd41cdd commit 0e9caca

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/builder.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::config::{
22
default_user_config, Config, BDK_CLIENT_CONCURRENCY, BDK_CLIENT_STOP_GAP,
3-
DEFAULT_ESPLORA_SERVER_URL, WALLET_KEYS_SEED_LEN,
3+
DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS, DEFAULT_ESPLORA_SERVER_URL, WALLET_KEYS_SEED_LEN,
44
};
55
use crate::connection::ConnectionManager;
66
use crate::event::EventQueue;
@@ -558,10 +558,15 @@ fn build_with_store_internal(
558558

559559
let (blockchain, tx_sync, tx_broadcaster, fee_estimator) = match chain_data_source_config {
560560
Some(ChainDataSourceConfig::Esplora(server_url)) => {
561-
let tx_sync = Arc::new(EsploraSyncClient::new(server_url.clone(), Arc::clone(&logger)));
562-
let blockchain =
563-
EsploraBlockchain::from_client(tx_sync.client().clone(), BDK_CLIENT_STOP_GAP)
564-
.with_concurrency(BDK_CLIENT_CONCURRENCY);
561+
let mut client_builder = esplora_client::Builder::new(&server_url.clone());
562+
client_builder = client_builder.timeout(DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS);
563+
let esplora_client = client_builder.build_async().unwrap();
564+
let tx_sync = Arc::new(EsploraSyncClient::from_client(
565+
esplora_client.clone(),
566+
Arc::clone(&logger),
567+
));
568+
let blockchain = EsploraBlockchain::from_client(esplora_client, BDK_CLIENT_STOP_GAP)
569+
.with_concurrency(BDK_CLIENT_CONCURRENCY);
565570
let tx_broadcaster = Arc::new(TransactionBroadcaster::new(
566571
tx_sync.client().clone(),
567572
Arc::clone(&logger),

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub(crate) const BDK_CLIENT_CONCURRENCY: u8 = 4;
2828
// The default Esplora server we're using.
2929
pub(crate) const DEFAULT_ESPLORA_SERVER_URL: &str = "https://blockstream.info/api";
3030

31+
// The default Esplora client timeout we're using.
32+
pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 10;
33+
3134
// The timeout after which we abandon retrying failed payments.
3235
pub(crate) const LDK_PAYMENT_RETRY_TIMEOUT: Duration = Duration::from_secs(10);
3336

0 commit comments

Comments
 (0)