From: Antoine Riard Date: Tue, 10 Mar 2020 17:03:10 +0000 (-0400) Subject: Make htlc_minimum_msat configurable X-Git-Tag: v0.0.12~105^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=9e03d2bc7a5d45c56722b40348b143403167142c;p=rust-lightning Make htlc_minimum_msat configurable Enforce a minimum htlc_minimum_msat of 1. Instead of computing dynamically htlc_minimum_msat based on feerate, relies on user-provided configuration value. This let user compute an economical-driven channel parameter according to network dynamics. --- diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 5771f772e..860746275 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -433,10 +433,6 @@ impl Channel { cmp::max(at_open_background_feerate * B_OUTPUT_PLUS_SPENDING_INPUT_WEIGHT / 1000, 546) //TODO } - fn derive_our_htlc_minimum_msat(_at_open_channel_feerate_per_kw: u64) -> u64 { - 1000 // TODO - } - // Constructors: pub fn new_outbound(fee_estimator: &F, keys_provider: &K, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64, logger: Arc, config: &UserConfig) -> Result, APIError> where K::Target: KeysInterface, @@ -519,7 +515,7 @@ impl Channel { their_max_htlc_value_in_flight_msat: 0, their_channel_reserve_satoshis: 0, their_htlc_minimum_msat: 0, - our_htlc_minimum_msat: Channel::::derive_our_htlc_minimum_msat(feerate), + our_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, their_to_self_delay: 0, our_to_self_delay: config.own_channel_config.our_to_self_delay, their_max_accepted_htlcs: 0, @@ -744,7 +740,7 @@ impl Channel { their_max_htlc_value_in_flight_msat: cmp::min(msg.max_htlc_value_in_flight_msat, msg.funding_satoshis * 1000), their_channel_reserve_satoshis: msg.channel_reserve_satoshis, their_htlc_minimum_msat: msg.htlc_minimum_msat, - our_htlc_minimum_msat: Channel::::derive_our_htlc_minimum_msat(msg.feerate_per_kw as u64), + our_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat }, their_to_self_delay: msg.to_self_delay, our_to_self_delay: config.own_channel_config.our_to_self_delay, their_max_accepted_htlcs: msg.max_accepted_htlcs, diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 27908ca54..ba918f82e 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -1005,6 +1005,7 @@ pub fn create_node_chanmgrs<'a, 'b>(node_count: usize, cfgs: &'a Vec let mut default_config = UserConfig::default(); default_config.channel_options.announced_channel = true; default_config.peer_channel_config_limits.force_announced_channel_preference = false; + default_config.own_channel_config.our_htlc_minimum_msat = 1000; // sanitization being done by the sender, to exerce receiver logic we need to lift of limit let node = ChannelManager::new(Network::Testnet, cfgs[i].fee_estimator, &cfgs[i].chan_monitor, cfgs[i].tx_broadcaster, cfgs[i].logger.clone(), &cfgs[i].keys_manager, if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }, 0).unwrap(); chanmgrs.push(node); } diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index 3c4ab77c1..c76747cbb 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -51,6 +51,14 @@ pub struct ChannelHandshakeConfig { /// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel /// opening so you can tweak config to ask for more security, not less. pub our_to_self_delay: u16, + /// Set to the smallest value HTLC we will accept to process. + /// + /// This value is sent to our counterparty on channel-open and we close the channel any time + /// our counterparty misbehaves by sending us an HTLC with a value smaller than this. + /// + /// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required + /// by the protocol. + pub our_htlc_minimum_msat: u64, } impl Default for ChannelHandshakeConfig { @@ -58,6 +66,7 @@ impl Default for ChannelHandshakeConfig { ChannelHandshakeConfig { minimum_depth: 6, our_to_self_delay: BREAKDOWN_TIMEOUT, + our_htlc_minimum_msat: 1, } } }