7777
7878mod balance;
7979mod builder;
80+ mod config;
8081mod error;
8182mod event;
8283mod fee_estimator;
@@ -101,6 +102,7 @@ pub use lightning;
101102pub use lightning_invoice;
102103
103104pub use balance:: { BalanceDetails , LightningBalance , PendingSweepBalance } ;
105+ pub use config:: { default_config, Config } ;
104106pub use error:: Error as NodeError ;
105107use error:: Error ;
106108
@@ -118,6 +120,10 @@ pub use builder::BuildError;
118120#[ cfg( not( feature = "uniffi" ) ) ]
119121pub use builder:: NodeBuilder as Builder ;
120122
123+ use config:: {
124+ LDK_PAYMENT_RETRY_TIMEOUT , NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL ,
125+ RGS_SYNC_INTERVAL , WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
126+ } ;
121127use event:: { EventHandler , EventQueue } ;
122128use gossip:: GossipSource ;
123129use liquidity:: LiquiditySource ;
@@ -155,7 +161,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
155161use bitcoin:: hashes:: Hash ;
156162use bitcoin:: secp256k1:: PublicKey ;
157163
158- use bitcoin:: { Address , Network , Txid } ;
164+ use bitcoin:: { Address , Txid } ;
159165
160166use rand:: Rng ;
161167
@@ -167,133 +173,6 @@ use std::time::{Duration, Instant, SystemTime};
167173#[ cfg( feature = "uniffi" ) ]
168174uniffi:: include_scaffolding!( "ldk_node" ) ;
169175
170- // Config defaults
171- const DEFAULT_STORAGE_DIR_PATH : & str = "/tmp/ldk_node/" ;
172- const DEFAULT_NETWORK : Network = Network :: Bitcoin ;
173- const DEFAULT_CLTV_EXPIRY_DELTA : u32 = 144 ;
174- const DEFAULT_BDK_WALLET_SYNC_INTERVAL_SECS : u64 = 80 ;
175- const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS : u64 = 30 ;
176- const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS : u64 = 60 * 10 ;
177- const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER : u64 = 3 ;
178- const DEFAULT_LOG_LEVEL : LogLevel = LogLevel :: Debug ;
179-
180- // The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold
181- // number of derivation indexes after which BDK stops looking for new scripts belonging to the wallet.
182- const BDK_CLIENT_STOP_GAP : usize = 20 ;
183-
184- // The number of concurrent requests made against the API provider.
185- const BDK_CLIENT_CONCURRENCY : u8 = 4 ;
186-
187- // The default Esplora server we're using.
188- const DEFAULT_ESPLORA_SERVER_URL : & str = "https://blockstream.info/api" ;
189-
190- // The timeout after which we abandon retrying failed payments.
191- const LDK_PAYMENT_RETRY_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
192-
193- // The time in-between peer reconnection attempts.
194- const PEER_RECONNECTION_INTERVAL : Duration = Duration :: from_secs ( 10 ) ;
195-
196- // The time in-between RGS sync attempts.
197- const RGS_SYNC_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
198-
199- // The time in-between node announcement broadcast attempts.
200- const NODE_ANN_BCAST_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 ) ;
201-
202- // The lower limit which we apply to any configured wallet sync intervals.
203- const WALLET_SYNC_INTERVAL_MINIMUM_SECS : u64 = 10 ;
204-
205- // The length in bytes of our wallets' keys seed.
206- const WALLET_KEYS_SEED_LEN : usize = 64 ;
207-
208- #[ derive( Debug , Clone ) ]
209- /// Represents the configuration of an [`Node`] instance.
210- ///
211- /// ### Defaults
212- ///
213- /// | Parameter | Value |
214- /// |----------------------------------------|--------------------|
215- /// | `storage_dir_path` | /tmp/ldk_node/ |
216- /// | `log_dir_path` | None |
217- /// | `network` | Bitcoin |
218- /// | `listening_addresses` | None |
219- /// | `default_cltv_expiry_delta` | 144 |
220- /// | `onchain_wallet_sync_interval_secs` | 80 |
221- /// | `wallet_sync_interval_secs` | 30 |
222- /// | `fee_rate_cache_update_interval_secs` | 600 |
223- /// | `trusted_peers_0conf` | [] |
224- /// | `probing_liquidity_limit_multiplier` | 3 |
225- /// | `log_level` | Debug |
226- ///
227- pub struct Config {
228- /// The path where the underlying LDK and BDK persist their data.
229- pub storage_dir_path : String ,
230- /// The path where logs are stored.
231- ///
232- /// If set to `None`, logs can be found in the `logs` subdirectory in [`Config::storage_dir_path`].
233- pub log_dir_path : Option < String > ,
234- /// The used Bitcoin network.
235- pub network : Network ,
236- /// The addresses on which the node will listen for incoming connections.
237- pub listening_addresses : Option < Vec < SocketAddress > > ,
238- /// The default CLTV expiry delta to be used for payments.
239- pub default_cltv_expiry_delta : u32 ,
240- /// The time in-between background sync attempts of the onchain wallet, in seconds.
241- ///
242- /// **Note:** A minimum of 10 seconds is always enforced.
243- pub onchain_wallet_sync_interval_secs : u64 ,
244- /// The time in-between background sync attempts of the LDK wallet, in seconds.
245- ///
246- /// **Note:** A minimum of 10 seconds is always enforced.
247- pub wallet_sync_interval_secs : u64 ,
248- /// The time in-between background update attempts to our fee rate cache, in seconds.
249- ///
250- /// **Note:** A minimum of 10 seconds is always enforced.
251- pub fee_rate_cache_update_interval_secs : u64 ,
252- /// A list of peers that we allow to establish zero confirmation channels to us.
253- ///
254- /// **Note:** Allowing payments via zero-confirmation channels is potentially insecure if the
255- /// funding transaction ends up never being confirmed on-chain. Zero-confirmation channels
256- /// should therefore only be accepted from trusted peers.
257- pub trusted_peers_0conf : Vec < PublicKey > ,
258- /// The liquidity factor by which we filter the outgoing channels used for sending probes.
259- ///
260- /// Channels with available liquidity less than the required amount times this value won't be
261- /// used to send pre-flight probes.
262- pub probing_liquidity_limit_multiplier : u64 ,
263- /// The level at which we log messages.
264- ///
265- /// Any messages below this level will be excluded from the logs.
266- pub log_level : LogLevel ,
267- }
268-
269- impl Default for Config {
270- fn default ( ) -> Self {
271- Self {
272- storage_dir_path : DEFAULT_STORAGE_DIR_PATH . to_string ( ) ,
273- log_dir_path : None ,
274- network : DEFAULT_NETWORK ,
275- listening_addresses : None ,
276- default_cltv_expiry_delta : DEFAULT_CLTV_EXPIRY_DELTA ,
277- onchain_wallet_sync_interval_secs : DEFAULT_BDK_WALLET_SYNC_INTERVAL_SECS ,
278- wallet_sync_interval_secs : DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS ,
279- fee_rate_cache_update_interval_secs : DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS ,
280- trusted_peers_0conf : Vec :: new ( ) ,
281- probing_liquidity_limit_multiplier : DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER ,
282- log_level : DEFAULT_LOG_LEVEL ,
283- }
284- }
285- }
286-
287- /// Returns a [`Config`] object populated with default values.
288- ///
289- /// See the documentation of [`Config`] for more information on the used defaults.
290- ///
291- /// This is mostly meant for use in bindings, in Rust this is synonymous with
292- /// [`Config::default()`].
293- pub fn default_config ( ) -> Config {
294- Config :: default ( )
295- }
296-
297176/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
298177///
299178/// Needs to be initialized and instantiated through [`Builder::build`].
@@ -369,8 +248,10 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
369248 let wallet = Arc :: clone ( & self . wallet ) ;
370249 let sync_logger = Arc :: clone ( & self . logger ) ;
371250 let mut stop_sync = self . stop_receiver . clone ( ) ;
372- let onchain_wallet_sync_interval_secs =
373- self . config . onchain_wallet_sync_interval_secs . max ( WALLET_SYNC_INTERVAL_MINIMUM_SECS ) ;
251+ let onchain_wallet_sync_interval_secs = self
252+ . config
253+ . onchain_wallet_sync_interval_secs
254+ . max ( config:: WALLET_SYNC_INTERVAL_MINIMUM_SECS ) ;
374255 std:: thread:: spawn ( move || {
375256 tokio:: runtime:: Builder :: new_current_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) . block_on (
376257 async move {
0 commit comments