From a51194b9fad41c5e1279543ebf7bc3c6ef5850d0 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 15 Feb 2021 16:04:51 +1100 Subject: [PATCH] Instantiate electrum client with custom config with 2 retries The default number of retries is 1. Unfortunately, the way this config value is interpreted doesn't actually lead to a retry. We have to set it to 2 to actually make it retry. See https://github.com/bitcoindevkit/rust-electrum-client/issues/47. --- swap/src/bitcoin/wallet.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 9615d180..fc7448d1 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -12,7 +12,7 @@ use async_trait::async_trait; use backoff::{backoff::Constant as ConstantBackoff, tokio::retry}; use bdk::{ blockchain::{noop_progress, Blockchain, ElectrumBlockchain}, - electrum_client::{Client, ElectrumApi}, + electrum_client::{self, Client, ElectrumApi}, keys::GeneratableDefaultOptions, FeeRate, }; @@ -45,7 +45,10 @@ impl Wallet { network: bitcoin::Network, waller_dir: &Path, ) -> Result { - let client = Client::new(electrum_rpc_url.as_str()) + // Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47. + let config = electrum_client::ConfigBuilder::default().retry(2).build(); + + let client = Client::from_config(electrum_rpc_url.as_str(), config) .map_err(|e| anyhow!("Failed to init electrum rpc client: {:?}", e))?; let db = bdk::sled::open(waller_dir)?.open_tree(SLED_TREE_NAME)?;