Skip to content

Commit 1e37df7

Browse files
committed
Fix CBF chain source build errors and UniFFI bindings (#5)
1 parent d0cfb9c commit 1e37df7

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface Builder {
4040
constructor(Config config);
4141
void set_chain_source_esplora(string server_url, EsploraSyncConfig? config);
4242
void set_chain_source_electrum(string server_url, ElectrumSyncConfig? config);
43-
void set_chain_source_cbf(sequence<string> peers, CbfSyncConfig? sync_config);
43+
void set_chain_source_cbf(sequence<string> peers, CbfSyncConfig? sync_config, FeeSourceConfig? fee_source_config);
4444
void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
4545
void set_chain_source_bitcoind_rest(string rest_host, u16 rest_port, string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
4646
void set_gossip_source_p2p();
@@ -357,6 +357,8 @@ enum Currency {
357357

358358
typedef enum AsyncPaymentsRole;
359359

360+
typedef enum FeeSourceConfig;
361+
360362
[Custom]
361363
typedef string Txid;
362364

src/builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ pub enum BuildError {
198198
NetworkMismatch,
199199
/// The role of the node in an asynchronous payments context is not compatible with the current configuration.
200200
AsyncPaymentsConfigMismatch,
201+
/// We failed to setup the chain source.
202+
ChainSourceSetupFailed,
201203
}
202204

203205
impl fmt::Display for BuildError {
@@ -231,6 +233,7 @@ impl fmt::Display for BuildError {
231233
"The async payments role is not compatible with the current configuration."
232234
)
233235
},
236+
Self::ChainSourceSetupFailed => write!(f, "Failed to setup chain source."),
234237
}
235238
}
236239
}
@@ -1424,6 +1427,10 @@ fn build_with_store_internal(
14241427
Arc::clone(&logger),
14251428
Arc::clone(&node_metrics),
14261429
)
1430+
.map_err(|e| {
1431+
log_error!(logger, "Failed to initialize CBF chain source: {}", e);
1432+
BuildError::ChainSourceSetupFailed
1433+
})?
14271434
},
14281435

14291436
None => {

src/chain/cbf.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ impl CbfChainSource {
123123
peers: Vec<String>, sync_config: CbfSyncConfig, fee_source_config: Option<FeeSourceConfig>,
124124
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
125125
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
126-
) -> Self {
126+
) -> Result<Self, Error> {
127127
let fee_source = match fee_source_config {
128128
Some(FeeSourceConfig::Esplora(server_url)) => {
129129
let timeout = sync_config.timeouts_config.per_request_timeout_secs;
130130
let mut builder = esplora_client::Builder::new(&server_url);
131131
builder = builder.timeout(timeout as u64);
132-
let client = builder.build_async().unwrap();
132+
let client = builder.build_async().map_err(|e| {
133+
log_error!(logger, "Failed to build esplora client: {}", e);
134+
Error::ConnectionFailed
135+
})?;
133136
FeeSource::Esplora { client }
134137
},
135138
Some(FeeSourceConfig::Electrum(server_url)) => FeeSource::Electrum { server_url },
@@ -149,7 +152,7 @@ impl CbfChainSource {
149152
let last_lightning_synced_height = Mutex::new(None);
150153
let onchain_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed);
151154
let lightning_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed);
152-
Self {
155+
Ok(Self {
153156
peers,
154157
sync_config,
155158
fee_source,
@@ -171,7 +174,7 @@ impl CbfChainSource {
171174
config,
172175
logger,
173176
node_metrics,
174-
}
177+
})
175178
}
176179

177180
/// Start the bip157 node and spawn background tasks for event processing.

src/chain/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl WalletSyncStatus {
9090
/// Setting an external source provides more accurate, per-target estimates
9191
/// from a mempool-aware server.
9292
#[derive(Debug, Clone)]
93+
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
9394
pub enum FeeSourceConfig {
9495
/// Use an Esplora HTTP server for fee rate estimation.
9596
Esplora(String),
@@ -205,7 +206,7 @@ impl ChainSource {
205206
fee_estimator: Arc<OnchainFeeEstimator>, tx_broadcaster: Arc<Broadcaster>,
206207
kv_store: Arc<DynStore>, config: Arc<Config>, logger: Arc<Logger>,
207208
node_metrics: Arc<RwLock<NodeMetrics>>,
208-
) -> (Self, Option<BestBlock>) {
209+
) -> Result<(Self, Option<BestBlock>), Error> {
209210
let cbf_chain_source = CbfChainSource::new(
210211
peers,
211212
sync_config,
@@ -215,10 +216,10 @@ impl ChainSource {
215216
config,
216217
Arc::clone(&logger),
217218
node_metrics,
218-
);
219+
)?;
219220
let kind = ChainSourceKind::Cbf(cbf_chain_source);
220221
let registered_txids = Mutex::new(Vec::new());
221-
(Self { kind, registered_txids, tx_broadcaster, logger }, None)
222+
Ok((Self { kind, registered_txids, tx_broadcaster, logger }, None))
222223
}
223224

224225
pub(crate) fn start(&self, runtime: Arc<Runtime>) -> Result<(), Error> {

tests/common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#![cfg(any(test, cln_test, lnd_test, vss_test))]
99
#![allow(dead_code)]
10+
#![allow(unused_imports)]
11+
#![allow(unused_macros)]
1012

1113
pub(crate) mod logging;
1214

0 commit comments

Comments
 (0)