Skip to content

Commit 9e03d2b

Browse files
author
Antoine Riard
committed
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.
1 parent 4abfd51 commit 9e03d2b

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

lightning/src/ln/channel.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
433433
cmp::max(at_open_background_feerate * B_OUTPUT_PLUS_SPENDING_INPUT_WEIGHT / 1000, 546) //TODO
434434
}
435435

436-
fn derive_our_htlc_minimum_msat(_at_open_channel_feerate_per_kw: u64) -> u64 {
437-
1000 // TODO
438-
}
439-
440436
// Constructors:
441437
pub fn new_outbound<K: Deref, F: Deref>(fee_estimator: &F, keys_provider: &K, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64, logger: Arc<Logger>, config: &UserConfig) -> Result<Channel<ChanSigner>, APIError>
442438
where K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
@@ -519,7 +515,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
519515
their_max_htlc_value_in_flight_msat: 0,
520516
their_channel_reserve_satoshis: 0,
521517
their_htlc_minimum_msat: 0,
522-
our_htlc_minimum_msat: Channel::<ChanSigner>::derive_our_htlc_minimum_msat(feerate),
518+
our_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat },
523519
their_to_self_delay: 0,
524520
our_to_self_delay: config.own_channel_config.our_to_self_delay,
525521
their_max_accepted_htlcs: 0,
@@ -744,7 +740,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
744740
their_max_htlc_value_in_flight_msat: cmp::min(msg.max_htlc_value_in_flight_msat, msg.funding_satoshis * 1000),
745741
their_channel_reserve_satoshis: msg.channel_reserve_satoshis,
746742
their_htlc_minimum_msat: msg.htlc_minimum_msat,
747-
our_htlc_minimum_msat: Channel::<ChanSigner>::derive_our_htlc_minimum_msat(msg.feerate_per_kw as u64),
743+
our_htlc_minimum_msat: if config.own_channel_config.our_htlc_minimum_msat == 0 { 1 } else { config.own_channel_config.our_htlc_minimum_msat },
748744
their_to_self_delay: msg.to_self_delay,
749745
our_to_self_delay: config.own_channel_config.our_to_self_delay,
750746
their_max_accepted_htlcs: msg.max_accepted_htlcs,

lightning/src/ln/functional_test_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ pub fn create_node_chanmgrs<'a, 'b>(node_count: usize, cfgs: &'a Vec<NodeCfg<'b>
10051005
let mut default_config = UserConfig::default();
10061006
default_config.channel_options.announced_channel = true;
10071007
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
1008+
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
10081009
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();
10091010
chanmgrs.push(node);
10101011
}

lightning/src/util/config.rs

+9
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,22 @@ pub struct ChannelHandshakeConfig {
5151
/// Default value: BREAKDOWN_TIMEOUT (currently 144), we enforce it as a minimum at channel
5252
/// opening so you can tweak config to ask for more security, not less.
5353
pub our_to_self_delay: u16,
54+
/// Set to the smallest value HTLC we will accept to process.
55+
///
56+
/// This value is sent to our counterparty on channel-open and we close the channel any time
57+
/// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
58+
///
59+
/// Default value: 1. If the value is less than 1, it is ignored and set to 1, as is required
60+
/// by the protocol.
61+
pub our_htlc_minimum_msat: u64,
5462
}
5563

5664
impl Default for ChannelHandshakeConfig {
5765
fn default() -> ChannelHandshakeConfig {
5866
ChannelHandshakeConfig {
5967
minimum_depth: 6,
6068
our_to_self_delay: BREAKDOWN_TIMEOUT,
69+
our_htlc_minimum_msat: 1,
6170
}
6271
}
6372
}

0 commit comments

Comments
 (0)