Skip to content

Bump max inflight HTLC value for outbound private channels #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions src/builder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
}
25 changes: 12 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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;
Expand Down Expand Up @@ -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::<u128>();
Expand Down
Loading