Skip to content

Commit 12d18e9

Browse files
committed
Consolidate setting UserConfig defaults
.. now only via `Config::default_user_config`
1 parent caf0aca commit 12d18e9

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

src/builder.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::config::{
2-
Config, BDK_CLIENT_CONCURRENCY, BDK_CLIENT_STOP_GAP, DEFAULT_ESPLORA_SERVER_URL,
3-
WALLET_KEYS_SEED_LEN,
2+
default_user_config, Config, BDK_CLIENT_CONCURRENCY, BDK_CLIENT_STOP_GAP,
3+
DEFAULT_ESPLORA_SERVER_URL, WALLET_KEYS_SEED_LEN,
44
};
55
use crate::connection::ConnectionManager;
66
use crate::event::EventQueue;
@@ -31,7 +31,6 @@ use lightning::routing::scoring::{
3131
};
3232
use lightning::sign::EntropySource;
3333

34-
use lightning::util::config::UserConfig;
3534
use lightning::util::persist::{
3635
read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY,
3736
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -686,19 +685,7 @@ fn build_with_store_internal(
686685
},
687686
};
688687

689-
// Initialize the default config values.
690-
//
691-
// Note that methods such as Node::connect_open_channel might override some of the values set
692-
// here, e.g. the ChannelHandshakeConfig, meaning these default values will mostly be relevant
693-
// for inbound channels.
694-
let mut user_config = UserConfig::default();
695-
user_config.channel_handshake_limits.force_announced_channel_preference = false;
696-
user_config.manually_accept_inbound_channels = true;
697-
// Note the channel_handshake_config will be overwritten in `connect_open_channel`, but we
698-
// still set a default here.
699-
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
700-
config.anchor_channels_config.is_some();
701-
688+
let mut user_config = default_user_config(&config);
702689
if liquidity_source_config.and_then(|lsc| lsc.lsps2_service.as_ref()).is_some() {
703690
// Generally allow claiming underpaying HTLCs as the LSP will skim off some fee. We'll
704691
// check that they don't take too much before claiming.

src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use lightning::ln::msgs::SocketAddress;
4+
use lightning::util::config::UserConfig;
45
use lightning::util::logger::Level as LogLevel;
56

67
use bitcoin::secp256k1::PublicKey;
@@ -225,3 +226,18 @@ impl Default for AnchorChannelsConfig {
225226
pub fn default_config() -> Config {
226227
Config::default()
227228
}
229+
230+
pub(crate) fn default_user_config(config: &Config) -> UserConfig {
231+
// Initialize the default config values.
232+
//
233+
// Note that methods such as Node::connect_open_channel might override some of the values set
234+
// here, e.g. the ChannelHandshakeConfig, meaning these default values will mostly be relevant
235+
// for inbound channels.
236+
let mut user_config = UserConfig::default();
237+
user_config.channel_handshake_limits.force_announced_channel_preference = false;
238+
user_config.manually_accept_inbound_channels = true;
239+
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
240+
config.anchor_channels_config.is_some();
241+
242+
user_config
243+
}

src/lib.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub use builder::BuildError;
122122
pub use builder::NodeBuilder as Builder;
123123

124124
use config::{
125-
NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
125+
default_user_config, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
126126
WALLET_SYNC_INTERVAL_MINIMUM_SECS,
127127
};
128128
use connection::ConnectionManager;
@@ -145,7 +145,6 @@ use lightning::events::bump_transaction::Wallet as LdkWallet;
145145
use lightning::ln::channelmanager::{ChannelShutdownState, PaymentId};
146146
use lightning::ln::msgs::SocketAddress;
147147

148-
use lightning::util::config::{ChannelHandshakeConfig, UserConfig};
149148
pub use lightning::util::logger::Level as LogLevel;
150149

151150
use lightning_background_processor::process_events_async;
@@ -1074,17 +1073,9 @@ impl Node {
10741073
return Err(Error::InsufficientFunds);
10751074
}
10761075

1077-
let channel_config = (*(channel_config.unwrap_or_default())).clone().into();
1078-
let user_config = UserConfig {
1079-
channel_handshake_limits: Default::default(),
1080-
channel_handshake_config: ChannelHandshakeConfig {
1081-
announced_channel: announce_channel,
1082-
negotiate_anchors_zero_fee_htlc_tx: self.config.anchor_channels_config.is_some(),
1083-
..Default::default()
1084-
},
1085-
channel_config,
1086-
..Default::default()
1087-
};
1076+
let mut user_config = default_user_config(&self.config);
1077+
user_config.channel_handshake_config.announced_channel = announce_channel;
1078+
user_config.channel_config = (*(channel_config.unwrap_or_default())).clone().into();
10881079

10891080
let push_msat = push_to_counterparty_msat.unwrap_or(0);
10901081
let user_channel_id: u128 = rand::thread_rng().gen::<u128>();

0 commit comments

Comments
 (0)