Skip to content

Commit 9f53d5c

Browse files
authored
Merge pull request #335 from TheBlueMatt/2019-04-330-nits
Make channel open confs configurable (and change from 12 to 6)
2 parents 5bd8837 + 80aa4f2 commit 9f53d5c

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
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_config_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
} }

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
350350
let mut config = UserConfig::new();
351351
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
352352
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
353-
config.channel_limits.min_dust_limit_satoshis = 0;
353+
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
354354
let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap();
355355
let router = Arc::new(Router::new(PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger)));
356356

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_config_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_config_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_config_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_config_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_config_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_config_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_config_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_config_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),
@@ -1383,25 +1376,25 @@ impl Channel {
13831376
}
13841377

13851378
// Now check against optional parameters as set by config...
1386-
if msg.htlc_minimum_msat > config.channel_limits.max_htlc_minimum_msat {
1379+
if msg.htlc_minimum_msat > config.peer_channel_config_limits.max_htlc_minimum_msat {
13871380
return Err(ChannelError::Close("htlc minimum msat is higher than the user specified limit"));
13881381
}
1389-
if msg.max_htlc_value_in_flight_msat < config.channel_limits.min_max_htlc_value_in_flight_msat {
1382+
if msg.max_htlc_value_in_flight_msat < config.peer_channel_config_limits.min_max_htlc_value_in_flight_msat {
13901383
return Err(ChannelError::Close("max htlc value in flight msat is less than the user specified limit"));
13911384
}
1392-
if msg.channel_reserve_satoshis > config.channel_limits.max_channel_reserve_satoshis {
1385+
if msg.channel_reserve_satoshis > config.peer_channel_config_limits.max_channel_reserve_satoshis {
13931386
return Err(ChannelError::Close("channel reserve satoshis is higher than the user specified limit"));
13941387
}
1395-
if msg.max_accepted_htlcs < config.channel_limits.min_max_accepted_htlcs {
1388+
if msg.max_accepted_htlcs < config.peer_channel_config_limits.min_max_accepted_htlcs {
13961389
return Err(ChannelError::Close("max accepted htlcs is less than the user specified limit"));
13971390
}
1398-
if msg.dust_limit_satoshis < config.channel_limits.min_dust_limit_satoshis {
1391+
if msg.dust_limit_satoshis < config.peer_channel_config_limits.min_dust_limit_satoshis {
13991392
return Err(ChannelError::Close("dust limit satoshis is less than the user specified limit"));
14001393
}
1401-
if msg.dust_limit_satoshis > config.channel_limits.max_dust_limit_satoshis {
1394+
if msg.dust_limit_satoshis > config.peer_channel_config_limits.max_dust_limit_satoshis {
14021395
return Err(ChannelError::Close("dust limit satoshis is greater than the user specified limit"));
14031396
}
1404-
if msg.minimum_depth > config.channel_limits.max_minimum_depth {
1397+
if msg.minimum_depth > config.peer_channel_config_limits.max_minimum_depth {
14051398
return Err(ChannelError::Close("We consider the minimum depth to be unreasonably large"));
14061399
}
14071400

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_config_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: 24 additions & 3 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-
/// Limits applied during channel creation.
8-
pub channel_limits: ChannelHandshakeLimits,
7+
/// Channel config that we propose to our counterparty.
8+
pub own_channel_config: ChannelHandshakeConfig,
9+
/// Limits applied to our counterparty's proposed channel config settings.
10+
pub peer_channel_config_limits: ChannelHandshakeLimits,
911
/// Channel config which affects behavior during channel lifetime.
1012
pub channel_options: ChannelConfig,
1113
}
@@ -14,12 +16,31 @@ 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_config_limits: ChannelHandshakeLimits::new(),
1821
channel_options: ChannelConfig::new(),
1922
}
2023
}
2124
}
2225

26+
/// Configuration we set when applicable.
27+
#[derive(Clone, Debug)]
28+
pub struct ChannelHandshakeConfig {
29+
/// Confirmations we will wait for before considering the channel locked in.
30+
/// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
31+
/// equivalent limit applied to outbound channels).
32+
pub minimum_depth: u32,
33+
}
34+
35+
impl ChannelHandshakeConfig {
36+
/// Provides sane defaults for `ChannelHandshakeConfig`
37+
pub fn new() -> ChannelHandshakeConfig {
38+
ChannelHandshakeConfig {
39+
minimum_depth: 6,
40+
}
41+
}
42+
}
43+
2344
/// Optional channel limits which are applied during channel creation.
2445
///
2546
/// These limits are only applied to our counterparty's limits, not our own.

0 commit comments

Comments
 (0)