Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 162
feat: chain source rest sync#526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tnull
merged 3 commits into
lightningdevkit:main
from
enigbe:2025-04-bitcoind-rest-sync-v2Jul 1, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,8 +7,9 @@ | ||
| use crate::chain::{ChainSource, DEFAULT_ESPLORA_SERVER_URL}; | ||
| use crate::config::{ | ||
| default_user_config, may_announce_channel, AnnounceError, Config, ElectrumSyncConfig, | ||
| EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, WALLET_KEYS_SEED_LEN, | ||
| default_user_config, may_announce_channel, AnnounceError, BitcoindRestClientConfig, Config, | ||
| ElectrumSyncConfig, EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, | ||
| WALLET_KEYS_SEED_LEN, | ||
| }; | ||
| use crate::connection::ConnectionManager; | ||
| @@ -84,9 +85,21 @@ const LSPS_HARDENED_CHILD_INDEX: u32 = 577; | ||
| #[derive(Debug, Clone)] | ||
| enum ChainDataSourceConfig { | ||
| Esplora { server_url: String, sync_config: Option<EsploraSyncConfig> }, | ||
| Electrum { server_url: String, sync_config: Option<ElectrumSyncConfig> }, | ||
| BitcoindRpc { rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String }, | ||
| Esplora { | ||
| server_url: String, | ||
| sync_config: Option<EsploraSyncConfig>, | ||
| }, | ||
| Electrum { | ||
| server_url: String, | ||
| sync_config: Option<ElectrumSyncConfig>, | ||
| }, | ||
| Bitcoind { | ||
| rpc_host: String, | ||
| rpc_port: u16, | ||
| rpc_user: String, | ||
| rpc_password: String, | ||
| rest_client_config: Option<BitcoindRestClientConfig>, | ||
| }, | ||
| } | ||
| #[derive(Debug, Clone)] | ||
| @@ -299,13 +312,48 @@ impl NodeBuilder { | ||
| self | ||
| } | ||
| /// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC | ||
| /// endpoint. | ||
| /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC. | ||
| /// | ||
| /// This method establishes an RPC connection that enables all essential chain operations including | ||
| /// transaction broadcasting and chain data synchronization. | ||
| /// | ||
| /// ## Parameters: | ||
| /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC | ||
| /// connection. | ||
| pub fn set_chain_source_bitcoind_rpc( | ||
| &mut self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String, | ||
| ) -> &mut Self { | ||
| self.chain_data_source_config = | ||
| Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password }); | ||
| self.chain_data_source_config = Some(ChainDataSourceConfig::Bitcoind { | ||
| rpc_host, | ||
| rpc_port, | ||
| rpc_user, | ||
| rpc_password, | ||
| rest_client_config: None, | ||
| }); | ||
| self | ||
| } | ||
| /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint. | ||
| /// | ||
| /// This method enables chain data synchronization via Bitcoin Core's REST interface. We pass | ||
| /// additional RPC configuration to non-REST-supported API calls like transaction broadcasting. | ||
| /// | ||
| /// ## Parameters: | ||
| /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection. | ||
| /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC | ||
| /// connection | ||
| pub fn set_chain_source_bitcoind_rest( | ||
| &mut self, rest_host: String, rest_port: u16, rpc_host: String, rpc_port: u16, | ||
| rpc_user: String, rpc_password: String, | ||
| ) -> &mut Self { | ||
| self.chain_data_source_config = Some(ChainDataSourceConfig::Bitcoind { | ||
| rpc_host, | ||
| rpc_port, | ||
| rpc_user, | ||
| rpc_password, | ||
| rest_client_config: Some(BitcoindRestClientConfig { rest_host, rest_port }), | ||
| }); | ||
| self | ||
| } | ||
| @@ -716,8 +764,14 @@ impl ArcedNodeBuilder { | ||
| self.inner.write().unwrap().set_chain_source_electrum(server_url, sync_config); | ||
| } | ||
| /// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC | ||
| /// endpoint. | ||
| /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC. | ||
| /// | ||
| /// This method establishes an RPC connection that enables all essential chain operations including | ||
enigbe marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /// transaction broadcasting and chain data synchronization. | ||
| /// | ||
| /// ## Parameters: | ||
| /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC | ||
| /// connection. | ||
| pub fn set_chain_source_bitcoind_rpc( | ||
| &self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String, | ||
| ) { | ||
| @@ -729,6 +783,29 @@ impl ArcedNodeBuilder { | ||
| ); | ||
| } | ||
| /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint. | ||
| /// | ||
| /// This method enables chain data synchronization via Bitcoin Core's REST interface. We pass | ||
| /// additional RPC configuration to non-REST-supported API calls like transaction broadcasting. | ||
| /// | ||
| /// ## Parameters: | ||
| /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection. | ||
| /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC | ||
| /// connection | ||
| pub fn set_chain_source_bitcoind_rest( | ||
| &self, rest_host: String, rest_port: u16, rpc_host: String, rpc_port: u16, | ||
| rpc_user: String, rpc_password: String, | ||
| ) { | ||
| self.inner.write().unwrap().set_chain_source_bitcoind_rest( | ||
| rest_host, | ||
| rest_port, | ||
| rpc_host, | ||
| rpc_port, | ||
| rpc_user, | ||
| rpc_password, | ||
| ); | ||
| } | ||
| /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer | ||
| /// network. | ||
| pub fn set_gossip_source_p2p(&self) { | ||
| @@ -1068,8 +1145,14 @@ fn build_with_store_internal( | ||
| Arc::clone(&node_metrics), | ||
| )) | ||
| }, | ||
| Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password }) => { | ||
| Arc::new(ChainSource::new_bitcoind_rpc( | ||
| Some(ChainDataSourceConfig::Bitcoind { | ||
| rpc_host, | ||
| rpc_port, | ||
| rpc_user, | ||
| rpc_password, | ||
| rest_client_config, | ||
| }) => match rest_client_config { | ||
| Some(rest_client_config) => Arc::new(ChainSource::new_bitcoind_rest( | ||
| rpc_host.clone(), | ||
| *rpc_port, | ||
| rpc_user.clone(), | ||
| @@ -1079,10 +1162,25 @@ fn build_with_store_internal( | ||
| Arc::clone(&tx_broadcaster), | ||
| Arc::clone(&kv_store), | ||
| Arc::clone(&config), | ||
| rest_client_config.clone(), | ||
| Arc::clone(&logger), | ||
| Arc::clone(&node_metrics), | ||
| )) | ||
| )), | ||
| None => Arc::new(ChainSource::new_bitcoind_rpc( | ||
| rpc_host.clone(), | ||
| *rpc_port, | ||
| rpc_user.clone(), | ||
| rpc_password.clone(), | ||
| Arc::clone(&wallet), | ||
| Arc::clone(&fee_estimator), | ||
| Arc::clone(&tx_broadcaster), | ||
| Arc::clone(&kv_store), | ||
| Arc::clone(&config), | ||
| Arc::clone(&logger), | ||
| Arc::clone(&node_metrics), | ||
| )), | ||
| }, | ||
| None => { | ||
| // Default to Esplora client. | ||
| let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string(); | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.