-
Notifications
You must be signed in to change notification settings - Fork 143
Add probing service #815
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
base: main
Are you sure you want to change the base?
Add probing service #815
Changes from all commits
5633c9c
793a61d
dd91fbe
c9e5d22
bff5fa0
891868e
e8b2cb2
679fccc
8c50d14
76d62d4
7152553
73882a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ use crate::config::{ | |
| default_user_config, may_announce_channel, AnnounceError, AsyncPaymentsRole, | ||
| BitcoindRestClientConfig, Config, ElectrumSyncConfig, EsploraSyncConfig, HRNResolverConfig, | ||
| TorConfig, DEFAULT_ESPLORA_SERVER_URL, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, | ||
| DEFAULT_MAX_PROBE_AMOUNT_MSAT, DEFAULT_MIN_PROBE_AMOUNT_MSAT, | ||
| }; | ||
| use crate::connection::ConnectionManager; | ||
| use crate::entropy::NodeEntropy; | ||
|
|
@@ -76,6 +77,9 @@ use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger}; | |
| use crate::message_handler::NodeCustomMessageHandler; | ||
| use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox; | ||
| use crate::peer_store::PeerStore; | ||
| use crate::probing::{ | ||
| HighDegreeStrategy, Prober, ProbingConfig, ProbingStrategy, ProbingStrategyKind, RandomWalkStrategy, | ||
| }; | ||
| use crate::runtime::{Runtime, RuntimeSpawner}; | ||
| use crate::tx_broadcaster::TransactionBroadcaster; | ||
| use crate::types::{ | ||
|
|
@@ -292,6 +296,7 @@ pub struct NodeBuilder { | |
| runtime_handle: Option<tokio::runtime::Handle>, | ||
| pathfinding_scores_sync_config: Option<PathfindingScoresSyncConfig>, | ||
| recovery_mode: bool, | ||
| probing_config: Option<ProbingConfig>, | ||
| } | ||
|
|
||
| impl NodeBuilder { | ||
|
|
@@ -310,16 +315,19 @@ impl NodeBuilder { | |
| let runtime_handle = None; | ||
| let pathfinding_scores_sync_config = None; | ||
| let recovery_mode = false; | ||
| let async_payments_role = None; | ||
| let probing_config = None; | ||
| Self { | ||
| config, | ||
| chain_data_source_config, | ||
| gossip_source_config, | ||
| liquidity_source_config, | ||
| log_writer_config, | ||
| runtime_handle, | ||
| async_payments_role: None, | ||
| async_payments_role, | ||
| pathfinding_scores_sync_config, | ||
| recovery_mode, | ||
| probing_config, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -625,6 +633,31 @@ impl NodeBuilder { | |
| self | ||
| } | ||
|
|
||
| /// Configures background probing. | ||
| /// | ||
| /// Use [`ProbingConfigBuilder`] to build the configuration: | ||
| /// ```no_run | ||
| /// # #[cfg(not(feature = "uniffi"))] | ||
| /// # { | ||
| /// use std::time::Duration; | ||
| /// use ldk_node::Builder; | ||
| /// use ldk_node::probing::ProbingConfigBuilder; | ||
| /// | ||
| /// let mut builder = Builder::new(); | ||
| /// builder.set_probing_config( | ||
| /// ProbingConfigBuilder::high_degree(100) | ||
| /// .interval(Duration::from_secs(30)) | ||
| /// .build() | ||
| /// ); | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// [`ProbingConfigBuilder`]: crate::probing::ProbingConfigBuilder | ||
| pub fn set_probing_config(&mut self, config: ProbingConfig) -> &mut Self { | ||
| self.probing_config = Some(config); | ||
| self | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options | ||
| /// previously configured. | ||
| pub fn build(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> { | ||
|
|
@@ -809,6 +842,7 @@ impl NodeBuilder { | |
| self.gossip_source_config.as_ref(), | ||
| self.liquidity_source_config.as_ref(), | ||
| self.pathfinding_scores_sync_config.as_ref(), | ||
| self.probing_config.as_ref(), | ||
| self.async_payments_role, | ||
| self.recovery_mode, | ||
| seed_bytes, | ||
|
|
@@ -1109,6 +1143,15 @@ impl ArcedNodeBuilder { | |
| self.inner.write().expect("lock").set_wallet_recovery_mode(); | ||
| } | ||
|
|
||
| /// Configures background probing. | ||
| /// | ||
| /// Use [`ProbingConfigBuilder`] to build the configuration. | ||
| /// | ||
| /// [`ProbingConfigBuilder`]: crate::probing::ProbingConfigBuilder | ||
| pub fn set_probing_config(&self, config: Arc<ProbingConfig>) { | ||
| self.inner.write().expect("lock").set_probing_config((*config).clone()); | ||
| } | ||
|
|
||
| /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options | ||
| /// previously configured. | ||
| pub fn build(&self, node_entropy: Arc<NodeEntropy>) -> Result<Arc<Node>, BuildError> { | ||
|
|
@@ -1252,8 +1295,9 @@ fn build_with_store_internal( | |
| gossip_source_config: Option<&GossipSourceConfig>, | ||
| liquidity_source_config: Option<&LiquiditySourceConfig>, | ||
| pathfinding_scores_sync_config: Option<&PathfindingScoresSyncConfig>, | ||
| async_payments_role: Option<AsyncPaymentsRole>, recovery_mode: bool, seed_bytes: [u8; 64], | ||
| runtime: Arc<Runtime>, logger: Arc<Logger>, kv_store: Arc<DynStore>, | ||
| probing_config: Option<&ProbingConfig>, async_payments_role: Option<AsyncPaymentsRole>, | ||
| recovery_mode: bool, seed_bytes: [u8; 64], runtime: Arc<Runtime>, logger: Arc<Logger>, | ||
| kv_store: Arc<DynStore>, | ||
| ) -> Result<Node, BuildError> { | ||
| optionally_install_rustls_cryptoprovider(); | ||
|
|
||
|
|
@@ -1661,7 +1705,10 @@ fn build_with_store_internal( | |
| }, | ||
| } | ||
|
|
||
| let scoring_fee_params = ProbabilisticScoringFeeParameters::default(); | ||
| let mut scoring_fee_params = ProbabilisticScoringFeeParameters::default(); | ||
|
randomlogin marked this conversation as resolved.
|
||
| if let Some(penalty) = probing_config.and_then(|c| c.diversity_penalty_msat) { | ||
| scoring_fee_params.probing_diversity_penalty_msat = penalty; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this will install the This probably means that we can't use the default router for probing, but rather need to call https://docs.rs/lightning/latest/lightning/routing/router/fn.find_route.html manually (as it allows us to pass the score params directly per call) to create a route and then hand the pre-built route to https://docs.rs/lightning/latest/lightning/ln/channelmanager/struct.ChannelManager.html#method.send_payment_with_route |
||
| } | ||
| let router = Arc::new(DefaultRouter::new( | ||
| Arc::clone(&network_graph), | ||
| Arc::clone(&logger), | ||
|
|
@@ -2036,6 +2083,38 @@ fn build_with_store_internal( | |
| _leak_checker.0.push(Arc::downgrade(&wallet) as Weak<dyn Any + Send + Sync>); | ||
| } | ||
|
|
||
| let prober = probing_config.map(|probing_cfg| { | ||
| let strategy: Arc<dyn ProbingStrategy> = match &probing_cfg.kind { | ||
| ProbingStrategyKind::HighDegree { top_node_count } => { | ||
| Arc::new(HighDegreeStrategy::new( | ||
| Arc::clone(&network_graph), | ||
| Arc::clone(&channel_manager), | ||
| Arc::clone(&router), | ||
| *top_node_count, | ||
| DEFAULT_MIN_PROBE_AMOUNT_MSAT, | ||
| DEFAULT_MAX_PROBE_AMOUNT_MSAT, | ||
| probing_cfg.cooldown, | ||
| config.probing_liquidity_limit_multiplier, | ||
| )) | ||
| }, | ||
| ProbingStrategyKind::RandomWalk { max_hops } => Arc::new(RandomWalkStrategy::new( | ||
| Arc::clone(&network_graph), | ||
| Arc::clone(&channel_manager), | ||
| *max_hops, | ||
| DEFAULT_MIN_PROBE_AMOUNT_MSAT, | ||
| DEFAULT_MAX_PROBE_AMOUNT_MSAT, | ||
| )), | ||
| ProbingStrategyKind::Custom(s) => Arc::clone(s), | ||
| }; | ||
| Arc::new(Prober { | ||
| channel_manager: Arc::clone(&channel_manager), | ||
| logger: Arc::clone(&logger), | ||
| strategy, | ||
| interval: probing_cfg.interval, | ||
| max_locked_msat: probing_cfg.max_locked_msat, | ||
| }) | ||
| }); | ||
|
|
||
| Ok(Node { | ||
| runtime, | ||
| stop_sender, | ||
|
|
@@ -2069,6 +2148,7 @@ fn build_with_store_internal( | |
| om_mailbox, | ||
| async_payments_role, | ||
| hrn_resolver, | ||
| prober, | ||
| #[cfg(cycle_tests)] | ||
| _leak_checker, | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.