Skip to content

Commit

Permalink
Merge pull request #47 from getAlby/feat/split-esplora-clients
Browse files Browse the repository at this point in the history
feat: split esplora clients
  • Loading branch information
rolznz committed Aug 14, 2024
2 parents 02074c7 + 69e75d9 commit df42713
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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.
Expand All @@ -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),
Expand Down

0 comments on commit df42713

Please sign in to comment.