Skip to content

Commit af5d85a

Browse files
authored
Merge pull request #370 from tnull/2024-10-add-bitcoind-support
Add bitcoind RPC support
2 parents cffdf7e + 7c629f2 commit af5d85a

File tree

11 files changed

+1131
-45
lines changed

11 files changed

+1131
-45
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lightning-net-tokio = { version = "0.0.125" }
3434
lightning-persister = { version = "0.0.125" }
3535
lightning-background-processor = { version = "0.0.125", features = ["futures"] }
3636
lightning-rapid-gossip-sync = { version = "0.0.125" }
37+
lightning-block-sync = { version = "0.0.125", features = ["rpc-client", "tokio"] }
3738
lightning-transaction-sync = { version = "0.0.125", features = ["esplora-async-https", "time"] }
3839
lightning-liquidity = { version = "0.1.0-alpha.6", features = ["std"] }
3940

@@ -65,12 +66,15 @@ bitcoin = "0.32.2"
6566
bip39 = "2.0.0"
6667
bip21 = { version = "0.5", features = ["std"], default-features = false }
6768

69+
base64 = { version = "0.22.1", default-features = false, features = ["std"] }
6870
rand = "0.8.5"
6971
chrono = { version = "0.4", default-features = false, features = ["clock"] }
7072
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
7173
esplora-client = { version = "0.9", default-features = false }
7274
libc = "0.2"
7375
uniffi = { version = "0.26.0", features = ["build"], optional = true }
76+
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
77+
serde_json = { version = "1.0.128", default-features = false, features = ["std"] }
7478

7579
[target.'cfg(vss)'.dependencies]
7680
vss-client = "0.3"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn main() {
5555
LDK Node currently comes with a decidedly opinionated set of design choices:
5656

5757
- On-chain data is handled by the integrated [BDK][bdk] wallet.
58-
- Chain data may currently be sourced from an [Esplora][esplora] server, while support for Electrum and `bitcoind` RPC will follow soon.
58+
- Chain data may currently be sourced from the Bitcoin Core RPC interface or an [Esplora][esplora] server, while support for Electrum will follow soon.
5959
- Wallet and channel state may be persisted to an [SQLite][sqlite] database, to file system, or to a custom back-end to be implemented by the user.
6060
- Gossip data may be sourced via Lightning's peer-to-peer network or the [Rapid Gossip Sync](https://docs.rs/lightning-rapid-gossip-sync/*/lightning_rapid_gossip_sync/) protocol.
6161
- Entropy for the Lightning and on-chain wallets may be sourced from raw bytes or a [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonic. In addition, LDK Node offers the means to generate and persist the entropy bytes to disk.

bindings/ldk_node.udl

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface Builder {
3636
void set_entropy_seed_bytes(sequence<u8> seed_bytes);
3737
void set_entropy_bip39_mnemonic(Mnemonic mnemonic, string? passphrase);
3838
void set_chain_source_esplora(string server_url, EsploraSyncConfig? config);
39+
void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
3940
void set_gossip_source_p2p();
4041
void set_gossip_source_rgs(string rgs_server_url);
4142
void set_liquidity_source_lsps2(SocketAddress address, PublicKey node_id, string? token);

src/builder.rs

+39
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use std::time::SystemTime;
7878
#[derive(Debug, Clone)]
7979
enum ChainDataSourceConfig {
8080
Esplora { server_url: String, sync_config: Option<EsploraSyncConfig> },
81+
BitcoindRpc { rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String },
8182
}
8283

8384
#[derive(Debug, Clone)]
@@ -248,6 +249,16 @@ impl NodeBuilder {
248249
self
249250
}
250251

252+
/// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
253+
/// endpoint.
254+
pub fn set_chain_source_bitcoind_rpc(
255+
&mut self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
256+
) -> &mut Self {
257+
self.chain_data_source_config =
258+
Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password });
259+
self
260+
}
261+
251262
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
252263
/// network.
253264
pub fn set_gossip_source_p2p(&mut self) -> &mut Self {
@@ -479,6 +490,19 @@ impl ArcedNodeBuilder {
479490
self.inner.write().unwrap().set_chain_source_esplora(server_url, sync_config);
480491
}
481492

493+
/// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
494+
/// endpoint.
495+
pub fn set_chain_source_bitcoind_rpc(
496+
&self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
497+
) {
498+
self.inner.write().unwrap().set_chain_source_bitcoind_rpc(
499+
rpc_host,
500+
rpc_port,
501+
rpc_user,
502+
rpc_password,
503+
);
504+
}
505+
482506
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
483507
/// network.
484508
pub fn set_gossip_source_p2p(&self) {
@@ -633,6 +657,21 @@ fn build_with_store_internal(
633657
Arc::clone(&node_metrics),
634658
))
635659
},
660+
Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password }) => {
661+
Arc::new(ChainSource::new_bitcoind_rpc(
662+
rpc_host.clone(),
663+
*rpc_port,
664+
rpc_user.clone(),
665+
rpc_password.clone(),
666+
Arc::clone(&wallet),
667+
Arc::clone(&fee_estimator),
668+
Arc::clone(&tx_broadcaster),
669+
Arc::clone(&kv_store),
670+
Arc::clone(&config),
671+
Arc::clone(&logger),
672+
Arc::clone(&node_metrics),
673+
))
674+
},
636675
None => {
637676
// Default to Esplora client.
638677
let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();

0 commit comments

Comments
 (0)