Skip to content
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

htlcswitch: add inbound routing fees receive support #6703

Merged
merged 4 commits into from
Mar 31, 2024

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented Jul 5, 2022

This PR implements "receive" support for inbound fees. In short this means that a routing node operator gets to set distinct fee schedules for the movement of funds on their incoming channels. This enables more fine-grained flow control, potentially leading to an increase in capital efficiency.

More discussion on this change can be found in the corresponding bolts issue lightning/bolts#835 and blip lightning/blips#18

Mailing list post that elaborates a bit on the upgrade scenario and how this can be a non-breaking change: https://lists.linuxfoundation.org/pipermail/lightning-dev/2022-July/003643.html

Note that no network-wide upgrade is required for the inbound fee schedule to propagate.

Changes:

  • Ability to set an inbound base and proportional fee as part of the channel policy.
  • Broadcasting of the inbound fee schedule to the wider network.
  • Update the forwarding logic to take into account inbound fees. This does not break older senders as long as the inbound fee is negative.

For send support, see #6934.

Implementation details

  • The channel_update extra opaque data is stored in the database without any validation. This means that readers of this data must handle the case where a tlv error is encountered during parsing of the stream.

    An alternative would be to do strict validation in ExtraOpaqueData.Decode when a message is received, but is more involved. It for example breaks the exisitng fuzz tests. Also, there may already be malformed tlv data in the database.

  • When a fee_insufficient failure happens on an intermediate node, still only the outgoing channel update is returned. The 256-byte failure message isn't able to accommodate both the incoming and outgoing channel policies until htlcswitch: relax failure message length check #6913 is widely deployed. For now, this means that senders can only receive updates to the inbound policy via gossip.

    For code that shows a future extended fee_insufficient, see htlcswitch: return inbound channel update #6967.

  • Forwards will be declined if the total of inbound and outbound fee is negative. Negative inbound fees can be set, but it must be made sure that it is sufficiently offset by a positive outbound fee.

  • Inbound fees can be set on private channels, but note must be taken that those fees cannot be communicated in bolt11 hop hints. For a hinted route that spans more than a single hop and where any hop except for the final hop has an inbound fee set, the inbound fee will be ignored by the sender. For a negative inbound fee this means the sender will miss out on the discount. For a positive inbound fee, the payment will fail.

Fixes #4225

@joostjager joostjager changed the title htlcswitch: add inbound fees htlcswitch: add inbound routing fees Jul 5, 2022
@joostjager
Copy link
Contributor Author

Added a scenario that underlines the advantage of inbound fees on the spec pr: lightning/bolts#835 (comment)

Lightning Labs, what is your view on this feature?

@joostjager
Copy link
Contributor Author

Created BLIP for the gossip change: lightning/blips#18

@joostjager joostjager mentioned this pull request Sep 1, 2022
3 tasks
@joostjager joostjager force-pushed the inbound-fees branch 9 times, most recently from 6a14f1e to 776391b Compare September 4, 2022 07:31
@joostjager
Copy link
Contributor Author

joostjager commented Sep 4, 2022

For the fee_insufficient failure message, I think we'd want to return not just the outgoing channel update, but also the incoming channel update. That way the sender has up to date fees for the pair of channels and the next attempt should work.

The problem though is the size limit of 256 bytes on the failure message. A fee_insufficient message with two channel updates attached is 274+ bytes.

Maybe a probabilistic fix is to randomly return either the incoming or the outgoing channel update? And perhaps there is an upside to disincentivizing high frequency channel updates too. See also #6883.

@joostjager joostjager force-pushed the inbound-fees branch 12 times, most recently from de3de69 to e0d6f3f Compare September 7, 2022 06:50
@joostjager
Copy link
Contributor Author

Rebased

Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@joostjager
Copy link
Contributor Author

Rebased

@joostjager joostjager force-pushed the inbound-fees branch 2 times, most recently from af237f8 to 3888b93 Compare January 30, 2024 15:16
@joostjager
Copy link
Contributor Author

Rebased

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM ☀️

)

// Fee represents a fee schedule.
type Fee struct {
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking given the age/lineage of this PR, but I think we should go ahead and add it to the existing ChannelUpdate struct using the new optional TLV records.

Copy link
Member

Choose a reason for hiding this comment

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

Will make a follow up issue to track this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

In this commit, the tlv extension of a channel update message is parsed.
If an inbound fee schedule is encountered, it is reported in the
graph rpc calls.
@joostjager joostjager force-pushed the inbound-fees branch 2 times, most recently from 5348160 to 9f80df8 Compare March 31, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inbound fee Changes related to inbound routing fee P1 MUST be fixed or reviewed routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set inbound and outbound fees