Skip to content

Commit 0e02969

Browse files
authored
Merge pull request #303 from tnull/2024-05-bump-max-inflight-for-outbound-private-channels
2 parents 3a328d4 + dc5d00e commit 0e02969

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-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;
@@ -229,3 +230,18 @@ impl Default for AnchorChannelsConfig {
229230
pub fn default_config() -> Config {
230231
Config::default()
231232
}
233+
234+
pub(crate) fn default_user_config(config: &Config) -> UserConfig {
235+
// Initialize the default config values.
236+
//
237+
// Note that methods such as Node::connect_open_channel might override some of the values set
238+
// here, e.g. the ChannelHandshakeConfig, meaning these default values will mostly be relevant
239+
// for inbound channels.
240+
let mut user_config = UserConfig::default();
241+
user_config.channel_handshake_limits.force_announced_channel_preference = false;
242+
user_config.manually_accept_inbound_channels = true;
243+
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
244+
config.anchor_channels_config.is_some();
245+
246+
user_config
247+
}

src/lib.rs

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

125125
use config::{
126-
NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL,
126+
default_user_config, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL,
127127
RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL, RGS_SYNC_INTERVAL,
128128
WALLET_SYNC_INTERVAL_MINIMUM_SECS,
129129
};
@@ -148,7 +148,6 @@ use lightning::events::bump_transaction::Wallet as LdkWallet;
148148
use lightning::ln::channelmanager::{ChannelShutdownState, PaymentId};
149149
use lightning::ln::msgs::SocketAddress;
150150

151-
use lightning::util::config::{ChannelHandshakeConfig, UserConfig};
152151
pub use lightning::util::logger::Level as LogLevel;
153152

154153
use lightning_background_processor::process_events_async;
@@ -1087,17 +1086,17 @@ impl Node {
10871086
return Err(Error::InsufficientFunds);
10881087
}
10891088

1090-
let channel_config = (*(channel_config.unwrap_or_default())).clone().into();
1091-
let user_config = UserConfig {
1092-
channel_handshake_limits: Default::default(),
1093-
channel_handshake_config: ChannelHandshakeConfig {
1094-
announced_channel: announce_channel,
1095-
negotiate_anchors_zero_fee_htlc_tx: self.config.anchor_channels_config.is_some(),
1096-
..Default::default()
1097-
},
1098-
channel_config,
1099-
..Default::default()
1100-
};
1089+
let mut user_config = default_user_config(&self.config);
1090+
user_config.channel_handshake_config.announced_channel = announce_channel;
1091+
user_config.channel_config = (*(channel_config.unwrap_or_default())).clone().into();
1092+
// We set the max inflight to 100% for private channels.
1093+
// FIXME: LDK will default to this behavior soon, too, at which point we should drop this
1094+
// manual override.
1095+
if !announce_channel {
1096+
user_config
1097+
.channel_handshake_config
1098+
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
1099+
}
11011100

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

0 commit comments

Comments
 (0)