Skip to content

Commit a6e3cf3

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 7a5f40b commit a6e3cf3

File tree

9 files changed

+1018
-154
lines changed

9 files changed

+1018
-154
lines changed

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
};
@@ -98,7 +98,7 @@ enum ChainDataSourceConfig {
9898
rpc_port: u16,
9999
rpc_user: String,
100100
rpc_password: String,
101-
sync_client_config: BitcoindSyncClientConfig,
101+
rest_client_config: Option<BitcoindRestClientConfig>,
102102
},
103103
}
104104

@@ -312,29 +312,51 @@ impl NodeBuilder {
312312
self
313313
}
314314

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

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

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

@@ -1101,21 +1151,37 @@ fn build_with_store_internal(
11011151
rpc_port,
11021152
rpc_user,
11031153
rpc_password,
1104-
sync_client_config,
1105-
}) => Arc::new(ChainSource::new_bitcoind(
1106-
rpc_host.clone(),
1107-
*rpc_port,
1108-
rpc_user.clone(),
1109-
rpc_password.clone(),
1110-
Arc::clone(&wallet),
1111-
Arc::clone(&fee_estimator),
1112-
Arc::clone(&tx_broadcaster),
1113-
Arc::clone(&kv_store),
1114-
Arc::clone(&config),
1115-
sync_client_config.clone(),
1116-
Arc::clone(&logger),
1117-
Arc::clone(&node_metrics),
1118-
)),
1154+
rest_client_config,
1155+
}) => match rest_client_config {
1156+
Some(rest_client_config) => Arc::new(ChainSource::new_bitcoind_rest(
1157+
rpc_host.clone(),
1158+
*rpc_port,
1159+
rpc_user.clone(),
1160+
rpc_password.clone(),
1161+
Arc::clone(&wallet),
1162+
Arc::clone(&fee_estimator),
1163+
Arc::clone(&tx_broadcaster),
1164+
Arc::clone(&kv_store),
1165+
Arc::clone(&config),
1166+
rest_client_config.clone(),
1167+
Arc::clone(&logger),
1168+
Arc::clone(&node_metrics),
1169+
)),
1170+
None => Arc::new(ChainSource::new_bitcoind_rpc(
1171+
rpc_host.clone(),
1172+
*rpc_port,
1173+
rpc_user.clone(),
1174+
rpc_password.clone(),
1175+
Arc::clone(&wallet),
1176+
Arc::clone(&fee_estimator),
1177+
Arc::clone(&tx_broadcaster),
1178+
Arc::clone(&kv_store),
1179+
Arc::clone(&config),
1180+
Arc::clone(&logger),
1181+
Arc::clone(&node_metrics),
1182+
)),
1183+
},
1184+
11191185
None => {
11201186
// Default to Esplora client.
11211187
let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();

0 commit comments

Comments
 (0)