lnd
lnd copied to clipboard
rpc+htlcswitch: add htlc transformation capabilities to the interceptor
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
- [ ] The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
- [ ] Commits follow the Ideal Git Commit Structure.
- [ ] Any new logging statements use an appropriate subsystem and logging level.
- [ ] Any new lncli commands have appropriate tags in the comments for the rpc in the proto file.
- [ ] There is a change description in the release notes, or
[skip ci]in the commit message for small changes.
📝 Please see our Contribution Guidelines for further guidance.
[!IMPORTANT]
Auto Review Skipped
Auto reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein 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?
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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto 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.yamlfile 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.
There are two things left to do here:
- Add support for modifying (via HTLC interception) p2p message
lnwire.UpdateFulfillHTLC. - Write received
UpdateAddHTLCto 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?
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.CustomSettype as a field inUpdateAddHTLCbecause of an import cycle. Therefore, the code is currently serializingrecord.CustomSetinto a blob before attaching it toUpdateAddHTLC.It seems to me that much of package
recordshould be merged intolnwire, is that a good idea?
-
I'm not sure if we need to modify
lnwire.UpdateFulfillHTLCalso. We can leave that for a separate PR. -
This is complete. We're checking Carol's log in the itest.
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.
Latest on this PR:
- I've modified the custom records field encode/decode procedure. It's now serialized "flat" in the
ExtraDatafield.
Things to consider:
Similar modifications are (probably) necessary for lnwire.UpdateFulfillHTLC. Will do that now that the overall pattern has been approved.
The latest on this PR:
-
I've added a custom record field to
UpdateFulfillHtlc. The HTLC interceptor can now modify the custom records field onupdate_fulfill_htlcandupdate_add_htlcmessages. -
I've removed a side effect from the
UpdateAddHtlc.Encodemethod. Previously, when using this method, the blind point and custom records fields were added into theExtraDatafield in theUpdateAddHtlcinstance. Now they are encoded/decode as part of the message extra data field only. Effectively,UpdateAddHtlc.ExtraDatanow only contains TLV types which do not have corresponding fields inUpdateAddHtlcand are not within the custom records range. -
The
ExtraOpaqueData.PackRecordsmethod has been made more robust with respect to canonical TLV record ordering.
TODO:
- Add encoding/decoding unit tests for
UpdateFulfillHtlc. (Corresponding unit tests already exist forUpdateAddHtlc.)
I've just add encoding/decoding unit tests for UpdateFulfillHtlc.
PR should be ready for merge, IMO.
I've included changes which were found necessary from the proof-of-concept investigation.
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.
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.