Skip to content

WIP: Configure holder max htlc value in flight function of channel value #868

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

Conversation

jfroche
Copy link

@jfroche jfroche commented Apr 7, 2021

refs #850

jfroche added 2 commits April 7, 2021 16:59
As `get_holder_max_htlc_value_in_flight_msat` is a thents of
`self.channel_value_satoshis`, there is no need to compute the minimum.
@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #868 (73089c5) into main (e23c270) will decrease coverage by 0.00%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #868      +/-   ##
==========================================
- Coverage   90.60%   90.60%   -0.01%     
==========================================
  Files          51       51              
  Lines       27295    27298       +3     
==========================================
+ Hits        24730    24732       +2     
- Misses       2565     2566       +1     
Impacted Files Coverage Δ
lightning/src/util/config.rs 46.51% <0.00%> (-1.11%) ⬇️
lightning/src/ln/channel.rs 87.33% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e23c270...73089c5. Read the comment docs.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, could use some sanity checking and the docs could be more clear.

fn get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
channel_value_satoshis * 1000 / 10 //TODO
fn get_holder_max_htlc_value_in_flight_msat(&self) -> u64 {
self.channel_value_satoshis * 1000 * self.holder_max_htlc_value_percentage / 100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bound by min(max(setting, 1), 90) (and update documentation to match)?

Copy link

@gotcha gotcha Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

In #850 @TheBlueMatt mentioned sthing regarding an absolute value which we did not understand:

some kind of "min htlc_max_in_flight as a percentage of channel value" and "min htlc_max_in_filght absolute value" knobs

Do we need to dig further or can we forget it ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its fine to skip it, I was just generally trying to say "maybe just a % isn't a sufficiently flexible knob, so we may need more options", but in hindsight, I'm not sure it matters, I think just the way it is is fine.

@@ -47,6 +47,8 @@ pub struct ChannelHandshakeConfig {
/// 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,
/// Set to percentage of channel value used to control the channel maximum htlc value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a bit more specific and should include some guidance on how to set it. Something like "The maximum amount we will accept for any single incoming HTLC on our channels, expressed as a percentage of the value of the channel. Payments to or routed through us above this value will be rejected before even reaching us. If this value is too large and we are a routing node, a malicious third-party could tie up our entire channel balance in a single HTLC which they refuse to resolve quickly." This should also mention the current default value.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I don't think this comment is accurate on the last part. IIRC, "htlc_max_value_in_flight_msat" is the global inbound HTLC balance, not a single HTLC. Setting a low-percentage doesn't prevent to tie up the entire channel balance in a single HTLC. Also I think it should say inbound liquidity instead of channel balance, our channel balance is the outbound liquidity ?

W.r.t to the default value, I would be more generous like 15% or 20%. Let say you want to preserve liquidity equilibrium in both direction. If you reach 35/75 in one direction, you trigger a rebalancing action like a circular loop to another one of your channel. A max_htlc_value of 15% means even at 35, you still have 20% of inbound liquidity buffer to keep the channel operational, assuming the in-flight 15% settled before the rebalance operation succeed.

Or what's your thinking on how a user should selection this value ? Otherwise, if you want to limit security risk, just open a smaller channel to avoid wasting almost-never used liquidity.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! You're totally right. As to guidance, that's a much tougher question if I read the variable name correctly :).

I'm not sure its right to focus on DoS here, its more about the our_to_self_delay vs cltv_expiry_delta distinction in my mind - in my mind, the biggest thing users should know is this is the max % of their channel who's security is controlled by cltv_expiry_delta, the rest being secured under the our_to_self_delay-block-limit. Its true re-balancing is a concern, but isn't it equally a concern with multiple payments? Maybe we should put rebalancing notes in htlc_maximum_msat (which I believe we currently don't expose, but should)?

Copy link

@ariard ariard Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my mind, the biggest thing users should know is this is the max % of their channel who's security is controlled by cltv_expiry_delta, the rest being secured under the our_to_self_delay-block-limit.

Yep, csv_delay vs cltv expiry delta sounds a good rational for guidance.

Its true re-balancing is a concern, but isn't it equally a concern with multiple payments?

I think unbalancing can be provoked as well due to multiple payments than a single one and "htlc_max_value_in_flight_msat" scope either but i would say such rebalancing concern should be noted there as we indirectly set hltc_maximum_msat in function of htlc_max_value_in_flight_msat (see get_announced_htlc_max_msat) ?

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution :) Overall sounds good to me

@@ -47,6 +47,8 @@ pub struct ChannelHandshakeConfig {
/// 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,
/// Set to percentage of channel value used to control the channel maximum htlc value
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I don't think this comment is accurate on the last part. IIRC, "htlc_max_value_in_flight_msat" is the global inbound HTLC balance, not a single HTLC. Setting a low-percentage doesn't prevent to tie up the entire channel balance in a single HTLC. Also I think it should say inbound liquidity instead of channel balance, our channel balance is the outbound liquidity ?

W.r.t to the default value, I would be more generous like 15% or 20%. Let say you want to preserve liquidity equilibrium in both direction. If you reach 35/75 in one direction, you trigger a rebalancing action like a circular loop to another one of your channel. A max_htlc_value of 15% means even at 35, you still have 20% of inbound liquidity buffer to keep the channel operational, assuming the in-flight 15% settled before the rebalance operation succeed.

Or what's your thinking on how a user should selection this value ? Otherwise, if you want to limit security risk, just open a smaller channel to avoid wasting almost-never used liquidity.


Channel::<Signer>::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis)
);
self.get_holder_max_htlc_value_in_flight_msat()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deprecate this method and instead make get_holder_max_htlc_value_in_flight_msat a pub fn ?

@@ -483,8 +483,8 @@ macro_rules! secp_check {

impl<Signer: Sign> Channel<Signer> {
// Convert constants + channel value to limits:
fn get_holder_max_htlc_value_in_flight_msat(channel_value_satoshis: u64) -> u64 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about this method "Returns a max in-flight inbound htlc value the remote can't overbid, required by us" ?

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Mar 26, 2022

Are you still interested in working on this @jfroche

@TheBlueMatt
Copy link
Collaborator

Going ahead and closing this. If you are interested in continuing work on this, just leave and comment and we'll get it reopened!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants