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

[custom channels 3/5]: Extract PART3 from mega staging branch #9072

Merged
merged 21 commits into from
Sep 19, 2024

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Sep 9, 2024

Extracts part 3 from #8960.

@guggero guggero added this to the v0.18.4 milestone Sep 9, 2024
@guggero guggero self-assigned this Sep 9, 2024
Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Labels to auto review (1)
  • llm-review

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>, please review it.
    -- 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 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.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link

github-actions bot commented Sep 9, 2024

Pull reviewers stats

Stats of the last 30 days for lnd:

User Total reviews Time to review Total comments
guggero
🥇
19
▀▀▀
12h 47m
34
▀▀
yyforyongyu
🥈
14
▀▀
15h
33
Roasbeef
🥉
8
5d 2h 26m
18
ellemouton
5
6h 51m
13
Crypt-iQ
4
13h 28m
7
bitromortac
4
6d 20h 16m
50
▀▀
ziggie1984
4
5d 13h 36m
17
ProofOfKeags
3
5d 6h 54m
38
▀▀
bhandras
2
5h 58m
0
hieblmi
2
1h 31m
2
alexbosworth
1
3d 21h 20m
1
aakselrod
1
4d 2h 7m
2
dstadulis
1
5d 7h 41m
1
morehouse
1
1h 5m
1
GeorgeTsagk
1
11d 15h 22m
▀▀
3
carlaKC
1
17h 11m
0
MPins
1
5d 8h 9m
2

@guggero
Copy link
Collaborator Author

guggero commented Sep 12, 2024

Requires a spicy rebase now that #8981 is in...

funding/manager.go Outdated Show resolved Hide resolved
@@ -4043,6 +4059,21 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, //nolint:funlen
PubNonce: remoteNonce,
}),
)

err = fn.MapOptionZ(
Copy link
Collaborator

Choose a reason for hiding this comment

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

These both call AuxFundingController.ChannelReady but are two slightly different states:

  • handleChannelReady means we've received channel_ready, we still need to send ours potentially
  • handleChannelReadyReceived means we've sent + received channel_ready
    Not sure if that matters at all for the way the funding controller is using these notifications.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well spotted! But fortunately it doesn't really matter for the current use case. Added a comment to make it more clear.

lnwire/commit_sig.go Show resolved Hide resolved
@guggero guggero force-pushed the extract-part3-from-staging-branch branch 2 times, most recently from 2199ea9 to 49a8371 Compare September 13, 2024 15:57
Roasbeef and others added 12 commits September 18, 2024 10:25
This struct will house all the information we'll need to do a class of custom channels that relies primarily on adding additional items to the tapscript root of the HTLC/commitment/funding outputs.
With this commit, we'll now populate all the custom channel information within the OpenChannel and ChannelCommitment structs.
In this commit, we make a new `AuxFundingController` interface capable of processing messages off the wire. In addition, we can use it to abstract away details w.r.t how we obtain a `AuxFundingDesc` for a given channel.

We'll now use this whenever we get a channel funding request, to make sure we pass along the custom state that a channel may require.
If this is a taproot channel, then we'll return the internal key which'll be useful to callers.
We also add a new assertion to the itests to ensure the field is being properly set.
In this commit, we modify the aux funding work flow slightly. We won't
be able to generate the full AuxFundingDesc until both sides has
sent+received funding params. So we'll now only attempt to bind the
tapscript root as soon as we send+recv the open_channel message.

We'll now also make sure that we pass the tapscript root all the way
down into the musig2 session creation.
For the initiator, once we get the signal that the PSBT has been
finalized, we'll call into the aux funder to get the funding desc. For
the responder, once we receive the funding_created message, we'll do the
same.

We now also have local+remote aux leaves for the commitment transaction.

Some old TODO comments that in retrospect aren't required anymore are
removed as well.
In this commit, we add a new aux signer interface that's meant to mirror the SigPool. If present, this'll be used to (maybe) obtain signatures for second level HTLCs for certain classes of custom channels.
Due to a recent refactor, the HTLCs are no longer an exported type.
Custom channels need access to those updates, so we provide them in a
read-only manner.
@guggero guggero force-pushed the extract-part3-from-staging-branch branch 2 times, most recently from 3dc1947 to 8cb20e7 Compare September 18, 2024 10:03
// We need to limit the size of the custom records to prevent the whole
// commitment_signed message to not exceed the maximum message size of
// 65k. If we assume a maximum number of HTLCs on the commitment of 483,
// and each signature being 64 bytes, we already use up 30k of the
Copy link
Collaborator

Choose a reason for hiding this comment

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

The maximum number is 966, 483 is the one-way limit. Not sure how limiting that is for the custom channels use-case. If we want more space, we'd need to fragment the message across multiple brontide packets

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, right... I'm not sure we can split the sigs over multiple messages. Or it would be a big refactor.

I changed the code to calculate the remaining number of bytes left for custom records. If we exceed that, we'll just fail the HTLC (I think). So for custom channels the real number of potential in-flight HTLCs will be quite a bit lower than the theoretical total of 966. But I think that's fine for now.
What do you think?

cc @Roasbeef

Copy link
Collaborator

@Crypt-iQ Crypt-iQ Sep 18, 2024

Choose a reason for hiding this comment

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

I don't know if we can calculate the space dynamically here. We have to avoid a situation where createCommitDiff fails as it can cause the link to fail with ErrInternalError which causes us to send an Error to our peer and make them force close on us. This is made worse if a 3rd party can route HTLCs through us, causing both sides to hit the max_accepted_htlcs limit and then potentially triggering channel failure due to the custom records size. One solution may be to limit max_accepted_htlcs during funding and ensuring that if dynamic commitments are ever used, that this value isn't updated.

@guggero guggero force-pushed the extract-part3-from-staging-branch branch 3 times, most recently from 6a0d859 to f093d3d Compare September 18, 2024 16:06
Roasbeef and others added 6 commits September 18, 2024 19:04
In this commit, we start to use the new AuxSigner to obtain+verify aux sigs for all second level HTLCs. This is similar to the existing SigPool, but we'll only attempt to do this if the AuxSigner is present (won't be for most channels).
To make sure we attempt to read the results of the sig batches in the
same order they're processed, we sort them _before_ submitting them to
the batch processor.
Otherwise it might happen that we try to read on a result channel that
was never sent on because we aborted due to an error.
We also use slices.SortFunc now which doesn't use reflection and might
be slightly faster.
This commit adds an optional data parser that can inspect and in-place
format custom data of certain RPC messages.
We don't add an implementation of the interface itself, as that will be
provided by external components when packaging up lnd as a bundle with
other software.
@guggero guggero force-pushed the extract-part3-from-staging-branch branch from f093d3d to 52e50d8 Compare September 18, 2024 17:08
Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

LGTM and size change to come when custom channels no longer experimental

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 🪕


// AuxHtlcDescriptor is a struct that contains the information needed to sign or
// verify an HTLC for custom channels.
type AuxHtlcDescriptor struct {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, with this change then we aren't as blocked on some proposed refactors as we've separated concerns by using a new minimal struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. The whole rebase on top of the first of these refactors just boiled down to making this struct. So not really that big of a deal, luckily.

return err
}

// Extract TLV records from the extra data field.
Copy link
Member

Choose a reason for hiding this comment

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

Was this commit pulled into an earlier version: 78f31da ?

Or was it just re-worked from scratch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had it reworked from scratch... So we kind of did the same thing twice unfortunately.

lnwallet/channel.go Show resolved Hide resolved
@@ -4544,6 +4544,7 @@ func (lc *LightningChannel) computeView(view *HtlcView,
// need this to determine which HTLCs are dust, and also the final fee
// rate.
view.FeePerKw = commitChain.tip().feePerKw
view.NextHeight = nextHeight
Copy link
Member

Choose a reason for hiding this comment

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

Set, but not added in this commit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we added it earlier in part 2. But looks like I forgot to squash this commit with an earlier one, so this remained.

@guggero guggero merged commit cdad5d9 into master Sep 19, 2024
26 of 34 checks passed
@guggero guggero deleted the extract-part3-from-staging-branch branch September 19, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants