diff --git a/src/builder.rs b/src/builder.rs index 9b2e476df..fa6e573b7 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,6 +1,6 @@ use crate::config::{ - Config, BDK_CLIENT_CONCURRENCY, BDK_CLIENT_STOP_GAP, DEFAULT_ESPLORA_SERVER_URL, - WALLET_KEYS_SEED_LEN, + default_user_config, Config, BDK_CLIENT_CONCURRENCY, BDK_CLIENT_STOP_GAP, + DEFAULT_ESPLORA_SERVER_URL, WALLET_KEYS_SEED_LEN, }; use crate::connection::ConnectionManager; use crate::event::EventQueue; @@ -31,7 +31,6 @@ use lightning::routing::scoring::{ }; use lightning::sign::EntropySource; -use lightning::util::config::UserConfig; use lightning::util::persist::{ read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE, @@ -686,19 +685,7 @@ fn build_with_store_internal( }, }; - // Initialize the default config values. - // - // Note that methods such as Node::connect_open_channel might override some of the values set - // here, e.g. the ChannelHandshakeConfig, meaning these default values will mostly be relevant - // for inbound channels. - let mut user_config = UserConfig::default(); - user_config.channel_handshake_limits.force_announced_channel_preference = false; - user_config.manually_accept_inbound_channels = true; - // Note the channel_handshake_config will be overwritten in `connect_open_channel`, but we - // still set a default here. - user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = - config.anchor_channels_config.is_some(); - + let mut user_config = default_user_config(&config); if liquidity_source_config.and_then(|lsc| lsc.lsps2_service.as_ref()).is_some() { // Generally allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll // check that they don't take too much before claiming. diff --git a/src/config.rs b/src/config.rs index 37e37bd63..7adae2d4b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use std::time::Duration; use lightning::ln::msgs::SocketAddress; +use lightning::util::config::UserConfig; use lightning::util::logger::Level as LogLevel; use bitcoin::secp256k1::PublicKey; @@ -229,3 +230,18 @@ impl Default for AnchorChannelsConfig { pub fn default_config() -> Config { Config::default() } + +pub(crate) fn default_user_config(config: &Config) -> UserConfig { + // Initialize the default config values. + // + // Note that methods such as Node::connect_open_channel might override some of the values set + // here, e.g. the ChannelHandshakeConfig, meaning these default values will mostly be relevant + // for inbound channels. + let mut user_config = UserConfig::default(); + user_config.channel_handshake_limits.force_announced_channel_preference = false; + user_config.manually_accept_inbound_channels = true; + user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = + config.anchor_channels_config.is_some(); + + user_config +} diff --git a/src/lib.rs b/src/lib.rs index 938b7ad20..bb6492cb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,7 @@ pub use builder::BuildError; pub use builder::NodeBuilder as Builder; use config::{ - NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, + default_user_config, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL, RGS_SYNC_INTERVAL, WALLET_SYNC_INTERVAL_MINIMUM_SECS, }; @@ -148,7 +148,6 @@ use lightning::events::bump_transaction::Wallet as LdkWallet; use lightning::ln::channelmanager::{ChannelShutdownState, PaymentId}; use lightning::ln::msgs::SocketAddress; -use lightning::util::config::{ChannelHandshakeConfig, UserConfig}; pub use lightning::util::logger::Level as LogLevel; use lightning_background_processor::process_events_async; @@ -1087,17 +1086,17 @@ impl Node { return Err(Error::InsufficientFunds); } - let channel_config = (*(channel_config.unwrap_or_default())).clone().into(); - let user_config = UserConfig { - channel_handshake_limits: Default::default(), - channel_handshake_config: ChannelHandshakeConfig { - announced_channel: announce_channel, - negotiate_anchors_zero_fee_htlc_tx: self.config.anchor_channels_config.is_some(), - ..Default::default() - }, - channel_config, - ..Default::default() - }; + let mut user_config = default_user_config(&self.config); + user_config.channel_handshake_config.announced_channel = announce_channel; + user_config.channel_config = (*(channel_config.unwrap_or_default())).clone().into(); + // We set the max inflight to 100% for private channels. + // FIXME: LDK will default to this behavior soon, too, at which point we should drop this + // manual override. + if !announce_channel { + user_config + .channel_handshake_config + .max_inbound_htlc_value_in_flight_percent_of_channel = 100; + } let push_msat = push_to_counterparty_msat.unwrap_or(0); let user_channel_id: u128 = rand::thread_rng().gen::();