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