Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> peers, CbfSyncConfig? sync_config);
void set_chain_source_cbf(sequence<string> 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();
Expand Down Expand Up @@ -357,6 +357,8 @@ enum Currency {

typedef enum AsyncPaymentsRole;

typedef enum FeeSourceConfig;

[Custom]
typedef string Txid;

Expand Down
7 changes: 7 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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."),
}
}
}
Expand Down Expand Up @@ -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 => {
Expand Down
11 changes: 7 additions & 4 deletions src/chain/cbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ impl CbfChainSource {
peers: Vec<String>, sync_config: CbfSyncConfig, fee_source_config: Option<FeeSourceConfig>,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
) -> Self {
) -> Result<Self, Error> {
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 },
Expand All @@ -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,
Expand All @@ -174,7 +177,7 @@ impl CbfChainSource {
config,
logger,
node_metrics,
}
})
}

/// Start the bip157 node and spawn background tasks for event processing.
Expand Down
7 changes: 4 additions & 3 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -205,7 +206,7 @@ impl ChainSource {
fee_estimator: Arc<OnchainFeeEstimator>, tx_broadcaster: Arc<Broadcaster>,
kv_store: Arc<DynStore>, config: Arc<Config>, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
) -> (Self, Option<BestBlock>) {
) -> Result<(Self, Option<BestBlock>), Error> {
let cbf_chain_source = CbfChainSource::new(
peers,
sync_config,
Expand All @@ -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<Runtime>) -> Result<(), Error> {
Expand Down
2 changes: 2 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading