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

[1/?]: multi: add ability to fund+use musig2 channels that commit to a tapscript root #8683

Merged
merged 9 commits into from
Apr 30, 2024

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Apr 24, 2024

Replaces #8546 (with correct base branch and upstream feature branch).

In this PR, we add the initial plumbing that'll allow users to create and use musig2 channels that also commit to a tapscript root. Along the way, we start to store a new optional tapscript root in the channeldb.OpenChannel struct within the existing TLV stream appended to the older hard coded byte stream. The musig2 session itself will now conditionally pass in a tapscript root to the key aggregation and signing operations. We've also hooked up the lower half of the funding flow (lnwallet reservations) as well to ensure the new field gets propagated all the way down the relevant call stacks.

Link to all PRs in the saga:

Copy link

Pull reviewers stats

Stats of the last 30 days for lnd:

User Total reviews Time to review Total comments
guggero
🥇
21
▀▀▀
12h 42m
25
Roasbeef
🥈
14
▀▀
7d 9h 40m
77
▀▀▀
ellemouton
🥉
7
5h 10m
7
bhandras
6
13h 56m
1
ziggie1984
6
8d 18h 41m
45
▀▀
morehouse
4
7d 11h 12m
19
ProofOfKeags
3
7d 8h 56m
40
▀▀
yyforyongyu
2
12h 24m
1
Crypt-iQ
2
7d 5h 38m
8
saubyk
2
3d 17h 37m
0
ffranr
1
3d 16h 49m
5
dstadulis
1
14d 35m
▀▀
1
bitromortac
1
14d 3h 18m
▀▀
3
Chinwendu20
1
23h 27m
1

Copy link
Contributor

coderabbitai bot commented Apr 24, 2024

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.

@guggero
Copy link
Collaborator Author

guggero commented Apr 25, 2024

I can't approve the PR because I re-opened it. But I reviewed it and worked my feedback directly into the commits.
So I'm approving it with this comment: LGTM 🎉

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 🔧

Copy link
Collaborator

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

LGTM 🥕 ⚡
solid changes

lnwallet/chanfunding/interface.go Show resolved Hide resolved
In this commit, we rename the files as assembler.go houses the primary
interfaces/abstractions of the package. In the rest of the codebase,
this file is near uniformly called interface.go, so we rename the file
to make the repo more digestible at a scan.
// to the existing hard-coded fields in the channel's root bucket.
type chanAuxData struct {
// revokeKeyLoc is the key locator for the revocation key.
revokeKeyLoc tlv.RecordT[tlv.TlvType0, keyLocRecord]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should have started at 0 originally, but I think now this should start at 1 because of records already in the database?

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, I think in @Roasbeef's original commit it did start at 1 and I thought that was an oversight. But if there's a reason for it, then I'll change it back as I missed that. Thanks!

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 looked at this again and I'm not sure what "records already in the database" you mean? The aux data is only written in putChanInfo() and read in fetchChanInfo() where we first have static entries with ReadElements/WriteElements and then at the end a TLV stream (using the fact that EOF is a valid error when reading a TLV stream).
So there are no existing TLV streams in the chan-info-key sub bucket that things could collide with. Or what am I missing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For an existing channel already in the database, revokeKeyLoc will be stored with the tlv type of 1, but chanAuxData will attempt to read it as though the type is 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, of course... Was looking at it from a completely wrong angle, sorry. Totally makes sense, will fix/revert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch, not sure what I was thinking when changing it in the first place...

In this commit, we consolidate the root bucket TLVs into a new struct.
This makes it easier to see all the new TLV fields at a glance. We also
convert TLV usage to use the new type param based APis.
This'll allow us to create a funding output that uses musig2, but uses a tapscript tweak rather than a normal BIP 86 tweak.
In most cases, we won't yet be passing a root. The option usage helps us keep the control flow mostly unchanged.
This isn't hooked up yet to the funding manager, but with this commit, we can now start to write internal unit tests that handle musig2 channels with a tapscript root.
With this commit, the channel is now aware of if it's a musig2 channel, that also has a tapscript root. We'll need to always pass in the tapscript root each time we: make the funding output, sign a new state, and also verify a new state.
@guggero guggero merged commit bb44793 into 0-19-staging Apr 30, 2024
23 of 27 checks passed
@guggero guggero deleted the funding-tapcript branch April 30, 2024 16:12
@guggero guggero restored the funding-tapcript branch May 1, 2024 08:30
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