Skip to content

lncli: base_fee_msat and fee_rate_ppm for openchannel#6753

Merged
guggero merged 7 commits intolightningnetwork:masterfrom
hieblmi:openchannel-fee-rates
Sep 29, 2022
Merged

lncli: base_fee_msat and fee_rate_ppm for openchannel#6753
guggero merged 7 commits intolightningnetwork:masterfrom
hieblmi:openchannel-fee-rates

Conversation

@hieblmi
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi commented Jul 18, 2022

Motivation

Node operators often see their newly confirmed channels' local balance leaking to the remote side especially when connecting to capacity sinks while having configured low default fee rates in lnd.conf, e.g.

The issue is also mentioned here #6610.

This PR introduces two parameters base_fee_msat and fee_rate for lncli openchannel in order to default to the so specified fees in the channel announcement phase. This way immediate channel leakage can be avoided.

Implementation

  1. Four fields are introduced to OpenChannelRequest, baseFee, feeRate, useBaseFee and useFeeRate. The use* fields are added to distinguish between the scenarios where the user provides fee values base_fee 0 / fee_rate 0 on lncli openchannel and where the user omits one of the fee values and when the default config parameters for fees should be used in the channel announcement.
  2. The rpcserver.go parses the fields into initFundingMsg
  3. Within funding/manager.go these new fields are added to a channel reservation context.
  4. When the FundingSigned stage is reached the reservation context is deleted so before that we store the fields per channel id in a new database bucket. Once the channel announcement stage is reached we read the channel fees from the database into the channel announcement structure and delete the fees from the database.
  5. In newChanAnnouncement we check if we find a fee entry in the database for a completed channel id. If so we apply the fees provided and delete the entry from the bucket.

Steps to Test

  1. See attached testOpenChannelUpdateFeePolicy and funding/manager_test.go
  2. Tested differrent scenarios on testnet while having default fees configured in lnd.conf.
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40000
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40001 --base_fee_msat 9999
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40002 --fee_rate_ppm 9999
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40003 --base_fee_msat 9999 --fee_rate_ppm 9999
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40004 --base_fee_msat 0 --fee_rate_ppm 9999
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40004 --base_fee_msat 9999 --fee_rate_ppm 0
lnclit openchannel --node_key 030425d8babe3ab6dfc065e69dd8b10ce6738c86ea7d634324c913e21620fa5eaf --local_amt 40004 --base_fee_msat 0 --fee_rate_ppm 0

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@hieblmi hieblmi force-pushed the openchannel-fee-rates branch 2 times, most recently from d7776b7 to cc21c9d Compare July 18, 2022 22:27
@hieblmi hieblmi changed the title #6706: BaseFee and FeeRate for OpenChannelRequest lncli: BaseFee and FeeRate for OpenChannelRequest Jul 18, 2022
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from cc21c9d to 895b1b9 Compare July 19, 2022 02:04
@hieblmi hieblmi changed the title lncli: BaseFee and FeeRate for OpenChannelRequest lncli: base_fee_msat and fee_rate for openchannel Jul 19, 2022
@hieblmi hieblmi closed this Jul 19, 2022
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from 895b1b9 to f7b7442 Compare July 19, 2022 02:39
@hieblmi hieblmi reopened this Jul 19, 2022
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from 265d99e to a1abd60 Compare July 19, 2022 14:26
@positiveblue positiveblue self-requested a review July 19, 2022 14:59
Copy link
Copy Markdown
Contributor

@positiveblue positiveblue left a comment

Choose a reason for hiding this comment

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

Nice work @hieblmi this looks pretty good!

I left some comments/nits.

The most pressing thing would be to ensure that this data is persisted + loaded when lnd starts again so we don't lose it during restarts.

Something useful could also be break the PR in smaller commits so they are easier to review:

  • Add fields to support custom fees in funding
  • Add rpc fields
  • Update rpc server to use the new fields
  • Add new fields to cmd
  • Add Notes

@Roasbeef Roasbeef added this to the v0.16.0 milestone Jul 19, 2022
@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour funding Related to the opening of new channels with funding transactions on the blockchain labels Jul 19, 2022
@hieblmi hieblmi changed the title lncli: base_fee_msat and fee_rate for openchannel lncli: base_fee_msat and fee_rate_ppm for openchannel Jul 19, 2022
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from a1abd60 to a9c708a Compare July 21, 2022 03:01
Copy link
Copy Markdown

@SachinMeier SachinMeier left a comment

Choose a reason for hiding this comment

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

This is a great change! Excited to see it merged.

@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from a9c708a to a13c691 Compare July 25, 2022 19:35
@hieblmi hieblmi requested review from guggero and positiveblue July 25, 2022 19:49
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from a13c691 to 62e23a3 Compare July 25, 2022 21:10
@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from f39f054 to 33dbf59 Compare September 27, 2022 12:33
@hieblmi hieblmi requested a review from guggero September 27, 2022 12:40
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented Sep 27, 2022

@guggero addressed the nits in latest change set.

@guggero
Copy link
Copy Markdown
Collaborator

guggero commented Sep 27, 2022

Thanks for addressing the nits in all commits, not just the ones I pointed out. Though the formatting is off, please see https://github.com/lightningnetwork/lnd/blob/master/docs/code_formatting_rules.md (part of the checklist in the PR template).

@hieblmi hieblmi force-pushed the openchannel-fee-rates branch 2 times, most recently from 925b537 to 8978aee Compare September 27, 2022 14:28
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented Sep 27, 2022

@guggero I think I caught all formatting issues and will keep them in mind.

Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Last set of nits, then we're good to go 🚀

@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from 8978aee to ba400cf Compare September 28, 2022 13:31
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented Sep 28, 2022

@guggero addressed latest nits.

@hieblmi hieblmi requested a review from guggero September 28, 2022 21:41
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I thought I already added this comment in my last review, but it looks like I forgot. But those struct fields all need an individual Godoc comment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The question about the TODO is still open. Is this something that actually needs to be decided or can we remove the TODO instead?
Also, the lines following after the comment are now duplicated between this case and the default case. If we set the values when we initialize chanUpdateAnn and only overwrite what we can actually configure this switch statement becomes easier to read and understand IMO.

@hieblmi hieblmi force-pushed the openchannel-fee-rates branch from ba400cf to 5083cc5 Compare September 29, 2022 12:32
@hieblmi hieblmi requested a review from guggero September 29, 2022 12:52
Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@guggero guggero merged commit 4b2edc4 into lightningnetwork:master Sep 29, 2022
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented Sep 29, 2022

Unreal 🍾🎉. Thanks yalls for reviewing and teaching this flow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvements to existing features / behaviour funding Related to the opening of new channels with funding transactions on the blockchain

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Allow setting channel parameters manually when opening channel

8 participants