Skip to content

Commit 09db8bd

Browse files
committed
Make minimum channel opening confirmations configurable
and change default from 12 to 6 (c-lightning compat)
1 parent 8b4cb9f commit 09db8bd

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

fuzz/fuzz_targets/chanmon_fail_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn do_test(data: &[u8]) {
148148
let mut config = UserConfig::new();
149149
config.channel_options.fee_proportional_millionths = 0;
150150
config.channel_options.announced_channel = true;
151-
config.channel_limits.min_dust_limit_satoshis = 0;
151+
config.peer_channel_limits.min_dust_limit_satoshis = 0;
152152
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap(),
153153
monitor)
154154
} }

src/ln/channel.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,6 @@ impl Channel {
410410
1000 // TODO
411411
}
412412

413-
fn derive_minimum_depth(_channel_value_satoshis_msat: u64, _value_to_self_msat: u64) -> u32 {
414-
// Note that in order to comply with BOLT 7 announcement_signatures requirements this must
415-
// be at least 6.
416-
const CONF_TARGET: u32 = 12; //TODO: Should be much higher
417-
CONF_TARGET
418-
}
419-
420413
// Constructors:
421414
pub fn new_outbound(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface>, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64, logger: Arc<Logger>, config: &UserConfig) -> Result<Channel, APIError> {
422415
let chan_keys = keys_provider.get_channel_keys(false);
@@ -565,32 +558,32 @@ impl Channel {
565558
}
566559

567560
// Now check against optional parameters as set by config...
568-
if msg.funding_satoshis < config.channel_limits.min_funding_satoshis {
561+
if msg.funding_satoshis < config.peer_channel_limits.min_funding_satoshis {
569562
return Err(ChannelError::Close("funding satoshis is less than the user specified limit"));
570563
}
571-
if msg.htlc_minimum_msat > config.channel_limits.max_htlc_minimum_msat {
564+
if msg.htlc_minimum_msat > config.peer_channel_limits.max_htlc_minimum_msat {
572565
return Err(ChannelError::Close("htlc minimum msat is higher than the user specified limit"));
573566
}
574-
if msg.max_htlc_value_in_flight_msat < config.channel_limits.min_max_htlc_value_in_flight_msat {
567+
if msg.max_htlc_value_in_flight_msat < config.peer_channel_limits.min_max_htlc_value_in_flight_msat {
575568
return Err(ChannelError::Close("max htlc value in flight msat is less than the user specified limit"));
576569
}
577-
if msg.channel_reserve_satoshis > config.channel_limits.max_channel_reserve_satoshis {
570+
if msg.channel_reserve_satoshis > config.peer_channel_limits.max_channel_reserve_satoshis {
578571
return Err(ChannelError::Close("channel reserve satoshis is higher than the user specified limit"));
579572
}
580-
if msg.max_accepted_htlcs < config.channel_limits.min_max_accepted_htlcs {
573+
if msg.max_accepted_htlcs < config.peer_channel_limits.min_max_accepted_htlcs {
581574
return Err(ChannelError::Close("max accepted htlcs is less than the user specified limit"));
582575
}
583-
if msg.dust_limit_satoshis < config.channel_limits.min_dust_limit_satoshis {
576+
if msg.dust_limit_satoshis < config.peer_channel_limits.min_dust_limit_satoshis {
584577
return Err(ChannelError::Close("dust limit satoshis is less than the user specified limit"));
585578
}
586-
if msg.dust_limit_satoshis > config.channel_limits.max_dust_limit_satoshis {
579+
if msg.dust_limit_satoshis > config.peer_channel_limits.max_dust_limit_satoshis {
587580
return Err(ChannelError::Close("dust limit satoshis is greater than the user specified limit"));
588581
}
589582

590583
// Convert things into internal flags and prep our state:
591584

592585
let their_announce = if (msg.channel_flags & 1) == 1 { true } else { false };
593-
if config.channel_limits.force_announced_channel_preference {
586+
if config.peer_channel_limits.force_announced_channel_preference {
594587
if local_config.announced_channel != their_announce {
595588
return Err(ChannelError::Close("Peer tried to open channel but their announcement preference is different from ours"));
596589
}
@@ -687,7 +680,7 @@ impl Channel {
687680
our_htlc_minimum_msat: Channel::derive_our_htlc_minimum_msat(msg.feerate_per_kw as u64),
688681
their_to_self_delay: msg.to_self_delay,
689682
their_max_accepted_htlcs: msg.max_accepted_htlcs,
690-
minimum_depth: Channel::derive_minimum_depth(msg.funding_satoshis*1000, msg.push_msat),
683+
minimum_depth: config.own_channel_config.minimum_depth,
691684

692685
their_funding_pubkey: Some(msg.funding_pubkey),
693686
their_revocation_basepoint: Some(msg.revocation_basepoint),
@@ -1371,25 +1364,25 @@ impl Channel {
13711364
}
13721365

13731366
// Now check against optional parameters as set by config...
1374-
if msg.htlc_minimum_msat > config.channel_limits.max_htlc_minimum_msat {
1367+
if msg.htlc_minimum_msat > config.peer_channel_limits.max_htlc_minimum_msat {
13751368
return Err(ChannelError::Close("htlc minimum msat is higher than the user specified limit"));
13761369
}
1377-
if msg.max_htlc_value_in_flight_msat < config.channel_limits.min_max_htlc_value_in_flight_msat {
1370+
if msg.max_htlc_value_in_flight_msat < config.peer_channel_limits.min_max_htlc_value_in_flight_msat {
13781371
return Err(ChannelError::Close("max htlc value in flight msat is less than the user specified limit"));
13791372
}
1380-
if msg.channel_reserve_satoshis > config.channel_limits.max_channel_reserve_satoshis {
1373+
if msg.channel_reserve_satoshis > config.peer_channel_limits.max_channel_reserve_satoshis {
13811374
return Err(ChannelError::Close("channel reserve satoshis is higher than the user specified limit"));
13821375
}
1383-
if msg.max_accepted_htlcs < config.channel_limits.min_max_accepted_htlcs {
1376+
if msg.max_accepted_htlcs < config.peer_channel_limits.min_max_accepted_htlcs {
13841377
return Err(ChannelError::Close("max accepted htlcs is less than the user specified limit"));
13851378
}
1386-
if msg.dust_limit_satoshis < config.channel_limits.min_dust_limit_satoshis {
1379+
if msg.dust_limit_satoshis < config.peer_channel_limits.min_dust_limit_satoshis {
13871380
return Err(ChannelError::Close("dust limit satoshis is less than the user specified limit"));
13881381
}
1389-
if msg.dust_limit_satoshis > config.channel_limits.max_dust_limit_satoshis {
1382+
if msg.dust_limit_satoshis > config.peer_channel_limits.max_dust_limit_satoshis {
13901383
return Err(ChannelError::Close("dust limit satoshis is greater than the user specified limit"));
13911384
}
1392-
if msg.minimum_depth > config.channel_limits.max_minimum_depth {
1385+
if msg.minimum_depth > config.peer_channel_limits.max_minimum_depth {
13931386
return Err(ChannelError::Close("We consider the minimum depth to be unreasonably large"));
13941387
}
13951388

src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ pub fn create_network(node_count: usize) -> Vec<Node> {
824824
let chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(chain_monitor.clone(), tx_broadcaster.clone(), logger.clone()));
825825
let mut config = UserConfig::new();
826826
config.channel_options.announced_channel = true;
827-
config.channel_limits.force_announced_channel_preference = false;
827+
config.peer_channel_limits.force_announced_channel_preference = false;
828828
let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap();
829829
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger));
830830
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed: seed,

src/util/config.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
/// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
55
#[derive(Clone, Debug)]
66
pub struct UserConfig {
7+
/// Channel config that we propose on channel opening
8+
pub own_channel_config: ChannelHandshakeConfig,
79
/// Limits applied during channel creation.
8-
pub channel_limits: ChannelHandshakeLimits,
10+
pub peer_channel_limits: ChannelHandshakeLimits,
911
/// Channel config which affects behavior during channel lifetime.
1012
pub channel_options: ChannelConfig,
1113
}
@@ -14,12 +16,29 @@ impl UserConfig {
1416
/// Provides sane defaults for most configurations (but with 0 relay fees!)
1517
pub fn new() -> Self{
1618
UserConfig {
17-
channel_limits: ChannelHandshakeLimits::new(),
19+
own_channel_config: ChannelHandshakeConfig::new(),
20+
peer_channel_limits: ChannelHandshakeLimits::new(),
1821
channel_options: ChannelConfig::new(),
1922
}
2023
}
2124
}
2225

26+
/// Configuration we want to opening channels
27+
#[derive(Clone, Debug)]
28+
pub struct ChannelHandshakeConfig {
29+
/// Confirmations we will wait for before considering the channel locked in
30+
pub minimum_depth: u32,
31+
}
32+
33+
impl ChannelHandshakeConfig {
34+
/// Provides sane defaults for `ChannelHandshakeConfig`
35+
pub fn new() -> ChannelHandshakeConfig {
36+
ChannelHandshakeConfig {
37+
minimum_depth: 6,
38+
}
39+
}
40+
}
41+
2342
/// Optional channel limits which are applied during channel creation.
2443
///
2544
/// These limits are only applied to our counterparty's limits, not our own.

0 commit comments

Comments
 (0)