lnd icon indicating copy to clipboard operation
lnd copied to clipboard

rpc+htlcswitch: add htlc transformation capabilities to the interceptor

Open ffranr opened this issue 10 months ago • 9 comments

Change Description

Closes https://github.com/lightningnetwork/lnd/issues/8619

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • [ ] Your PR passes all CI checks.
  • [ ] Tests covering the positive and negative (error paths) are included.
  • [ ] Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

ffranr avatar Apr 09 '24 16:04 ffranr

[!IMPORTANT]

Auto Review Skipped

Auto reviews are disabled on this repository.

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.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 09 '24 16:04 coderabbitai[bot]

There are two things left to do here:

  1. Add support for modifying (via HTLC interception) p2p message lnwire.UpdateFulfillHTLC.
  2. Write received UpdateAddHTLC to log so that the itest can ensure that Carol's node receives the correctly modified message.

I would be keen on feedback on what I have so far to check that I'm still on the right track.

Note that I couldn't include the record.CustomSet type as a field in UpdateAddHTLC because of an import cycle. Therefore, the code is currently serializing record.CustomSet into a blob before attaching it to UpdateAddHTLC.

It seems to me that much of package record should be merged into lnwire, is that a good idea?

ffranr avatar Apr 13 '24 12:04 ffranr

There are two things left to do here:

1. Add support for modifying (via HTLC interception) p2p message `lnwire.UpdateFulfillHTLC`.

2. Write received `UpdateAddHTLC` to log so that the itest can ensure that Carol's node receives the correctly modified message.

I would be keen on feedback on what I have so far to check that I'm still on the right track.

Note that I couldn't include the record.CustomSet type as a field in UpdateAddHTLC because of an import cycle. Therefore, the code is currently serializing record.CustomSet into a blob before attaching it to UpdateAddHTLC.

It seems to me that much of package record should be merged into lnwire, is that a good idea?

  1. I'm not sure if we need to modify lnwire.UpdateFulfillHTLC also. We can leave that for a separate PR.

  2. This is complete. We're checking Carol's log in the itest.

ffranr avatar Apr 15 '24 11:04 ffranr

New message encode/decode changes are in place.

Still need to modify lnwire.UpdateFulfillHTLC, but a review at this point would be useful to ensure correct encode/decode.

ffranr avatar Apr 29 '24 10:04 ffranr

Latest on this PR:

  1. I've modified the custom records field encode/decode procedure. It's now serialized "flat" in the ExtraData field.

Things to consider:

Similar modifications are (probably) necessary for lnwire.UpdateFulfillHTLC. Will do that now that the overall pattern has been approved.

ffranr avatar Apr 30 '24 18:04 ffranr

The latest on this PR:

  1. I've added a custom record field to UpdateFulfillHtlc. The HTLC interceptor can now modify the custom records field on update_fulfill_htlc and update_add_htlc messages.

  2. I've removed a side effect from the UpdateAddHtlc.Encode method. Previously, when using this method, the blind point and custom records fields were added into the ExtraData field in the UpdateAddHtlc instance. Now they are encoded/decode as part of the message extra data field only. Effectively, UpdateAddHtlc.ExtraData now only contains TLV types which do not have corresponding fields in UpdateAddHtlc and are not within the custom records range.

  3. The ExtraOpaqueData.PackRecords method has been made more robust with respect to canonical TLV record ordering.

TODO:

  1. Add encoding/decoding unit tests for UpdateFulfillHtlc. (Corresponding unit tests already exist for UpdateAddHtlc.)

ffranr avatar May 03 '24 17:05 ffranr

I've just add encoding/decoding unit tests for UpdateFulfillHtlc.

PR should be ready for merge, IMO.

ffranr avatar May 03 '24 18:05 ffranr

I've included changes which were found necessary from the proof-of-concept investigation.

ffranr avatar May 09 '24 18:05 ffranr

I made some additional changes to the custom records here: https://github.com/lightningnetwork/lnd/commit/8a4531fc9680f85040fdebce93e1fef3541482c2#diff-dcf3ed2a4ce04d1e140efd7a8d84967d7b7d04e69be69fdeb3a95c0350ac3b58 Would be nice to get those in as well.

guggero avatar May 10 '24 12:05 guggero

I made some additional changes to the custom records here: 8a4531f#diff-dcf3ed2a4ce04d1e140efd7a8d84967d7b7d04e69be69fdeb3a95c0350ac3b58 Would be nice to get those in as well.

Latest commits should include the custom record changes found above.

ffranr avatar May 14 '24 10:05 ffranr