Skip to content

Commit a2a7fb7

Browse files
committed
feat: conf rest sync & add ChainSource::BitcoindRest variant
- Adds set_chain_source_bitcoind_rest to configure REST synchronization. - Adds ChainSource::BitcoindRest variant (unimplemented) - Akin to the BitcoindRpcClient, adds BitcoindRestClient, initially duplicating logic and structure, and utilizing the RestClient where possible. Note: Duplicated logic will be addressed in a following commit.
1 parent 5221ce1 commit a2a7fb7

9 files changed

Lines changed: 1018 additions & 154 deletions

File tree

bindings/ldk_node.udl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ dictionary ElectrumSyncConfig {
3434
BackgroundSyncConfig? background_sync_config;
3535
};
3636

37-
[Enum]
38-
interface BitcoindSyncClientConfig {
39-
Rpc();
40-
Rest(string rest_host, u16 rest_port);
41-
};
42-
4337
dictionary LSPS2ServiceConfig {
4438
string? require_token;
4539
boolean advertise_service;
@@ -83,7 +77,8 @@ interface Builder {
8377
void set_entropy_bip39_mnemonic(Mnemonic mnemonic, string? passphrase);
8478
void set_chain_source_esplora(string server_url, EsploraSyncConfig? config);
8579
void set_chain_source_electrum(string server_url, ElectrumSyncConfig? config);
86-
void set_chain_source_bitcoind(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password, BitcoindSyncClientConfig? sync_client_config);
80+
void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
81+
void set_chain_source_bitcoind_rest(string rest_host, u16 rest_port, string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
8782
void set_gossip_source_p2p();
8883
void set_gossip_source_rgs(string rgs_server_url);
8984
void set_liquidity_source_lsps1(PublicKey node_id, SocketAddress address, string? token);

src/builder.rs

Lines changed: 99 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use crate::chain::{ChainSource, DEFAULT_ESPLORA_SERVER_URL};
99
use crate::config::{
10-
default_user_config, may_announce_channel, AnnounceError, BitcoindSyncClientConfig, Config,
10+
default_user_config, may_announce_channel, AnnounceError, BitcoindRestClientConfig, Config,
1111
ElectrumSyncConfig, EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL,
1212
WALLET_KEYS_SEED_LEN,
1313
};
@@ -96,7 +96,7 @@ enum ChainDataSourceConfig {
9696
rpc_port: u16,
9797
rpc_user: String,
9898
rpc_password: String,
99-
sync_client_config: BitcoindSyncClientConfig,
99+
rest_client_config: Option<BitcoindRestClientConfig>,
100100
},
101101
}
102102

@@ -310,29 +310,51 @@ impl NodeBuilder {
310310
self
311311
}
312312

313-
/// Configures the [`Node`] instance to synchronize its chain data from the given Bitcoin Core RPC
314-
/// endpoint.
313+
/// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC.
315314
///
316-
/// This method configures an RPC connection for essential operations, with options for
317-
/// synchronization via either RPC (default) or REST.
315+
/// This method establishes an RPC connection that enables all essential chain operations including
316+
/// transaction broadcasting and chain data synchronization.
318317
///
319-
/// # Parameters:
320-
/// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC connection
321-
/// * `sync_client_config` - Optional synchronization client configuration; defaults to using RPC for sync
322-
pub fn set_chain_source_bitcoind(
318+
/// ## Parameters:
319+
/// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
320+
/// connection.
321+
pub fn set_chain_source_bitcoind_rpc(
323322
&mut self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
324-
sync_client_config: Option<BitcoindSyncClientConfig>,
325323
) -> &mut Self {
326324
self.chain_data_source_config = Some(ChainDataSourceConfig::Bitcoind {
327325
rpc_host,
328326
rpc_port,
329327
rpc_user,
330328
rpc_password,
331-
sync_client_config: sync_client_config.unwrap_or(BitcoindSyncClientConfig::Rpc),
329+
rest_client_config: None,
332330
});
333331
self
334332
}
335333

334+
/// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint.
335+
///
336+
/// This method enables chain data synchronization via Bitcoin Core's REST interface. We pass
337+
/// additional RPC configuration to non-REST-supported API calls like transaction broadcasting.
338+
///
339+
/// ## Parameters:
340+
/// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
341+
/// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
342+
/// connection
343+
pub fn set_chain_source_bitcoind_rest(
344+
&mut self, rest_host: String, rest_port: u16, rpc_host: String, rpc_port: u16,
345+
rpc_user: String, rpc_password: String,
346+
) -> &mut Self {
347+
self.chain_data_source_config = Some(ChainDataSourceConfig::Bitcoind {
348+
rpc_host,
349+
rpc_port,
350+
rpc_user,
351+
rpc_password,
352+
rest_client_config: Some(BitcoindRestClientConfig { rest_host, rest_port }),
353+
});
354+
355+
self
356+
}
357+
336358
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
337359
/// network.
338360
pub fn set_gossip_source_p2p(&mut self) -> &mut Self {
@@ -740,18 +762,46 @@ impl ArcedNodeBuilder {
740762
self.inner.write().unwrap().set_chain_source_electrum(server_url, sync_config);
741763
}
742764

743-
/// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
744-
/// endpoint.
745-
pub fn set_chain_source_bitcoind(
765+
/// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC.
766+
///
767+
/// This method establishes an RPC connection that enables all essential chain operations including
768+
/// transaction broadcasting and chain data synchronization. RPC is the minimum required configuration
769+
/// for Bitcoin Core chain interactions and must be set up before any other Bitcoin Core connection options.
770+
///
771+
/// ## Parameters:
772+
/// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
773+
/// connection.
774+
pub fn set_chain_source_bitcoind_rpc(
746775
&self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
747-
sync_client_config: Option<BitcoindSyncClientConfig>,
748776
) {
749-
self.inner.write().unwrap().set_chain_source_bitcoind(
777+
self.inner.write().unwrap().set_chain_source_bitcoind_rpc(
778+
rpc_host,
779+
rpc_port,
780+
rpc_user,
781+
rpc_password,
782+
);
783+
}
784+
785+
/// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint.
786+
///
787+
/// This method enables chain data synchronization via Bitcoin Core's REST interface.
788+
/// It must be called after [`set_chain_source_bitcoind_rpc`] because REST is used only for chain
789+
/// synchronization, while RPC is still required for other essential operations like transaction
790+
/// broadcasting.
791+
///
792+
/// ## Parameters:
793+
/// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
794+
pub fn set_chain_source_bitcoind_rest(
795+
&self, rest_host: String, rest_port: u16, rpc_host: String, rpc_port: u16,
796+
rpc_user: String, rpc_password: String,
797+
) {
798+
self.inner.write().unwrap().set_chain_source_bitcoind_rest(
799+
rest_host,
800+
rest_port,
750801
rpc_host,
751802
rpc_port,
752803
rpc_user,
753804
rpc_password,
754-
sync_client_config,
755805
);
756806
}
757807

@@ -1094,21 +1144,37 @@ fn build_with_store_internal(
10941144
rpc_port,
10951145
rpc_user,
10961146
rpc_password,
1097-
sync_client_config,
1098-
}) => Arc::new(ChainSource::new_bitcoind(
1099-
rpc_host.clone(),
1100-
*rpc_port,
1101-
rpc_user.clone(),
1102-
rpc_password.clone(),
1103-
Arc::clone(&wallet),
1104-
Arc::clone(&fee_estimator),
1105-
Arc::clone(&tx_broadcaster),
1106-
Arc::clone(&kv_store),
1107-
Arc::clone(&config),
1108-
sync_client_config.clone(),
1109-
Arc::clone(&logger),
1110-
Arc::clone(&node_metrics),
1111-
)),
1147+
rest_client_config,
1148+
}) => match rest_client_config {
1149+
Some(rest_client_config) => Arc::new(ChainSource::new_bitcoind_rest(
1150+
rpc_host.clone(),
1151+
*rpc_port,
1152+
rpc_user.clone(),
1153+
rpc_password.clone(),
1154+
Arc::clone(&wallet),
1155+
Arc::clone(&fee_estimator),
1156+
Arc::clone(&tx_broadcaster),
1157+
Arc::clone(&kv_store),
1158+
Arc::clone(&config),
1159+
rest_client_config.clone(),
1160+
Arc::clone(&logger),
1161+
Arc::clone(&node_metrics),
1162+
)),
1163+
None => Arc::new(ChainSource::new_bitcoind_rpc(
1164+
rpc_host.clone(),
1165+
*rpc_port,
1166+
rpc_user.clone(),
1167+
rpc_password.clone(),
1168+
Arc::clone(&wallet),
1169+
Arc::clone(&fee_estimator),
1170+
Arc::clone(&tx_broadcaster),
1171+
Arc::clone(&kv_store),
1172+
Arc::clone(&config),
1173+
Arc::clone(&logger),
1174+
Arc::clone(&node_metrics),
1175+
)),
1176+
},
1177+
11121178
None => {
11131179
// Default to Esplora client.
11141180
let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();

0 commit comments

Comments
 (0)