diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 9f3ee8551e..31d3d6a4cd 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -40,7 +40,7 @@ interface Builder { constructor(Config config); void set_chain_source_esplora(string server_url, EsploraSyncConfig? config); void set_chain_source_electrum(string server_url, ElectrumSyncConfig? config); - void set_chain_source_cbf(sequence peers, CbfSyncConfig? sync_config); + void set_chain_source_cbf(sequence peers, CbfSyncConfig? sync_config, FeeSourceConfig? fee_source_config); void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password); void set_chain_source_bitcoind_rest(string rest_host, u16 rest_port, string rpc_host, u16 rpc_port, string rpc_user, string rpc_password); void set_gossip_source_p2p(); @@ -357,6 +357,8 @@ enum Currency { typedef enum AsyncPaymentsRole; +typedef enum FeeSourceConfig; + [Custom] typedef string Txid; diff --git a/src/builder.rs b/src/builder.rs index 3b8003f903..5a388cd82b 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -198,6 +198,8 @@ pub enum BuildError { NetworkMismatch, /// The role of the node in an asynchronous payments context is not compatible with the current configuration. AsyncPaymentsConfigMismatch, + /// We failed to setup the chain source. + ChainSourceSetupFailed, } impl fmt::Display for BuildError { @@ -231,6 +233,7 @@ impl fmt::Display for BuildError { "The async payments role is not compatible with the current configuration." ) }, + Self::ChainSourceSetupFailed => write!(f, "Failed to setup chain source."), } } } @@ -1424,6 +1427,10 @@ fn build_with_store_internal( Arc::clone(&logger), Arc::clone(&node_metrics), ) + .map_err(|e| { + log_error!(logger, "Failed to initialize CBF chain source: {}", e); + BuildError::ChainSourceSetupFailed + })? }, None => { diff --git a/src/chain/cbf.rs b/src/chain/cbf.rs index 531d8896a4..494883b098 100644 --- a/src/chain/cbf.rs +++ b/src/chain/cbf.rs @@ -126,13 +126,16 @@ impl CbfChainSource { peers: Vec, sync_config: CbfSyncConfig, fee_source_config: Option, fee_estimator: Arc, kv_store: Arc, config: Arc, logger: Arc, node_metrics: Arc>, - ) -> Self { + ) -> Result { let fee_source = match fee_source_config { Some(FeeSourceConfig::Esplora(server_url)) => { let timeout = sync_config.timeouts_config.per_request_timeout_secs; let mut builder = esplora_client::Builder::new(&server_url); builder = builder.timeout(timeout as u64); - let client = builder.build_async().unwrap(); + let client = builder.build_async().map_err(|e| { + log_error!(logger, "Failed to build esplora client: {}", e); + Error::ConnectionFailed + })?; FeeSource::Esplora { client } }, Some(FeeSourceConfig::Electrum(server_url)) => FeeSource::Electrum { server_url }, @@ -152,7 +155,7 @@ impl CbfChainSource { let last_lightning_synced_height = Arc::new(Mutex::new(None)); let onchain_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed); let lightning_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed); - Self { + Ok(Self { peers, sync_config, fee_source, @@ -174,7 +177,7 @@ impl CbfChainSource { config, logger, node_metrics, - } + }) } /// Start the bip157 node and spawn background tasks for event processing. diff --git a/src/chain/mod.rs b/src/chain/mod.rs index 3440145430..b896ba6fbf 100644 --- a/src/chain/mod.rs +++ b/src/chain/mod.rs @@ -90,6 +90,7 @@ impl WalletSyncStatus { /// Setting an external source provides more accurate, per-target estimates /// from a mempool-aware server. #[derive(Debug, Clone)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] pub enum FeeSourceConfig { /// Use an Esplora HTTP server for fee rate estimation. Esplora(String), @@ -205,7 +206,7 @@ impl ChainSource { fee_estimator: Arc, tx_broadcaster: Arc, kv_store: Arc, config: Arc, logger: Arc, node_metrics: Arc>, - ) -> (Self, Option) { + ) -> Result<(Self, Option), Error> { let cbf_chain_source = CbfChainSource::new( peers, sync_config, @@ -215,10 +216,10 @@ impl ChainSource { config, Arc::clone(&logger), node_metrics, - ); + )?; let kind = ChainSourceKind::Cbf(cbf_chain_source); let registered_txids = Mutex::new(Vec::new()); - (Self { kind, registered_txids, tx_broadcaster, logger }, None) + Ok((Self { kind, registered_txids, tx_broadcaster, logger }, None)) } pub(crate) fn start(&self, runtime: Arc) -> Result<(), Error> { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index cca23a1526..45ac10f1ad 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -7,6 +7,8 @@ #![cfg(any(test, cln_test, lnd_test, vss_test))] #![allow(dead_code)] +#![allow(unused_imports)] +#![allow(unused_macros)] pub(crate) mod logging;