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

[3/5]: multi: add new AuxFundingController for custom external funding flows #8622

Merged
merged 15 commits into from
May 27, 2024

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Apr 5, 2024

Depends on #8684.

In this commit, we add the AuxFundingController interface that can be used to implement a class of custom funding channels that only requires some additional data to be inserted into the tapscript leaves for the funding/HTLC/commitment outputs. This controller also implements the MsgEndpoint interface (see #8520) as well. This allows the controller to intercept certain custom messages related to the funding process (think extra sigs for a channel factory), and even the existing funding messages.

We then create a new top level config entry for this interface. This allows an external program to instantiate a AuxFundingController, make a MsgRouter, register that, then pass both into the lnd top level config.

We also pick up where the prior PR in this series left of by using the new abstraction to map a pending chan ID (kinda like the FundingStateStep RPC) to the aux funding data. This data is then used to populate all the new custom blobs that we'll store for these new channel types, which impacts the way we construct the funding output, and also the commitment/HTLC outputs+scripts.

Link to all PRs in the saga:

@Roasbeef Roasbeef added funding Related to the opening of new channels with funding transactions on the blockchain custom chans labels Apr 5, 2024
Copy link

coderabbitai bot commented Apr 5, 2024

Important

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the 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 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.

Copy link

github-actions bot commented Apr 5, 2024

Pull reviewers stats

Stats of the last 30 days for lnd:

User Total reviews Time to review Total comments
guggero
🥇
25
▀▀▀
2d 21h 27m
57
▀▀▀
ellemouton
🥈
17
▀▀
4d 14h 51m
34
▀▀
bhandras
🥉
10
30m
0
Roasbeef
6
7h 40m
12
yyforyongyu
6
3h 18m
0
ProofOfKeags
4
7d 8h 54m
42
▀▀
GeorgeTsagk
4
2d 20h 31m
10
ziggie1984
4
3d 11h 1m
9
saubyk
3
3h 43m
0
Chinwendu20
3
18d 5h 35m
▀▀▀
10
hieblmi
2
21m
1
bitromortac
2
9h 44m
0
positiveblue
1
4d 21h 57m
0
Crypt-iQ
1
7d 14h 36m
4
dstadulis
1
1d 22h 10m
4
morehouse
1
2d 2h 39m
1
carlaKC
1
12h 2m
0
mohamedawnallah
1
1d 4h 44m
0

peer/msg_router.go Outdated Show resolved Hide resolved
peer/msg_router.go Outdated Show resolved Hide resolved
peer/msg_router.go Outdated Show resolved Hide resolved
peer/msg_router.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Did a first pass, looks good! Will probably have more questions once we start with the actual AuxFundingController implementation.

funding/aux_funding.go Outdated Show resolved Hide resolved
funding/manager.go Outdated Show resolved Hide resolved
@Roasbeef
Copy link
Member Author

Pushed a few new commits: we'll now include the taproot internal key in the PBST template we return for the PSBT funding flow.

@guggero guggero force-pushed the aux-leaf-fetcher branch 3 times, most recently from a8bfe36 to e04f50d Compare April 24, 2024 13:01
@guggero guggero changed the title multi: add new AuxFundingController for custom external funding flows [3/?]: multi: add new AuxFundingController for custom external funding flows Apr 24, 2024
@guggero guggero changed the title [3/?]: multi: add new AuxFundingController for custom external funding flows [3/5]: multi: add new AuxFundingController for custom external funding flows May 17, 2024
@guggero guggero force-pushed the aux-funding branch 2 times, most recently from d978f49 to d43b5f8 Compare May 21, 2024 07:27
@guggero
Copy link
Collaborator

guggero commented May 21, 2024

Updated this PR to depend on #8660 so we have everything we need in one continuous branch. @ffranr and @GeorgeTsagk please skip the first 6 commits when reviewing this PR!

In this commit, we add a new abstract message router. Over time, the
goal is that this message router replaces the logic we currently have in
the readHandler (the giant switch for each message).

With this new abstraction, can reduce the responsibilities of the
readHandler to *just* reading messages off the wire and handing them off
to the msg router. The readHandler no longer needs to know *where* the
messages should go, or how they should be dispatched.

This will be used in tandem with the new `protofsm` module in an
upcoming PR implementing the new rbf-coop close.
Over time with this, we should be able to significantly reduce the size
of the peer.Brontide struct as we only need all those deps as the peer
needs to recognize and handle each incoming wire message itself.
With this commit, we allow the `MsgRouter` to be available in the `ImplementationCfg`. With this, programs outside of lnd itself are able to now hook into the message processing flow to direct handle custom messages, and even normal wire messages.
This'll be useful for new interface definitions that use the contents of the package.
This lets us get rid of the mutex usage there. We also shift the algo slightly to increment by 1, then use that as the next value, which plays nicer with the atomics.
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.
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.

Slick ✨
Couple of nits

Wanted to see some test coverage where we simply validate that the aux leaf exists after funding, but maybe too early in the PR-pipeline for this given that we're headed for 0-19-staging

LGTM

@@ -98,7 +99,6 @@ const (
// you and limitless channel size (apart from 21 million cap).
MaxBtcFundingAmountWumbo = btcutil.Amount(1000000000)

// TODO(roasbeef): tune.
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo removed but value wasn't tuned

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume it turned out tuning isn't necessary anymore? @Roasbeef removed those TODOs, so I can just make the assumption they aren't required anymore? Updated the commit message though.

funding/manager.go Outdated Show resolved Hide resolved
funding/manager.go Outdated Show resolved Hide resolved
@@ -3409,6 +3481,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
errChan := f.cfg.SendAnnouncement(
ann.chanAnn, discovery.ChannelCapacity(completeChan.Capacity),
discovery.ChannelPoint(completeChan.FundingOutpoint),
discovery.TapscriptRoot(completeChan.TapscriptRoot),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this ends up being encoded in the ExtraOpaqueData right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have a way to gossip Simple Taproot channels to the wider network yet, so they currently don't land in any p2p message. We just set the field here so that the local gossip validation logic doesn't trip over it and fails to add the channel to the local graph.

lnwallet/wallet.go Show resolved Hide resolved
peer/brontide.go Show resolved Hide resolved
@@ -493,6 +499,10 @@ type Brontide struct {
// potentially holding lots of un-consumed events.
channelEventClient *subscribe.Client

// msgRouter is an instance of the MsgRouter which is used to send off
// new wire messages for handing.
msgRouter fn.Option[protofsm.MsgRouter]
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this really need to be wrapped as an option?

we're always setting it to be either a custom msgRouter or the default one

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think it minimizes the diff size, otherwise we might need to hook up more to get the unit tests to pass.

@@ -2513,6 +2523,9 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
cp := *nMsg.optionalMsgFields.channelPoint
edge.ChannelPoint = cp
}

// Optional tapscript root for custom channels.
edge.TapscriptRoot = nMsg.optionalMsgFields.tapscriptRoot
Copy link
Collaborator

Choose a reason for hiding this comment

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

for other nodes in the network what purpose does this field have?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For being able to verify the pkScript of the channel. Without the tapscript root the validation nodes would assume 2-of-2 MuSig2 with BIP-0086 tweak.

Copy link
Collaborator

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

Easy commits to review, thanks.
LGTM

log.Error(err)
f.failFundingFlow(peer, cid, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe just log all errors in failFundingFlow

Copy link
Collaborator

Choose a reason for hiding this comment

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

We already do, but just as a Debugf because there we don't always know if it qualifies as an actual error. So I think it's okay to do so here, we seem to be doing the same in other places too.

funding/aux_funding.go Outdated Show resolved Hide resolved
Comment on lines 4632 to 4703
err = fmt.Errorf("error deriving tapscript root: %w", err)
msg.Err <- err
Copy link
Collaborator

Choose a reason for hiding this comment

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

just msg.Err <- fmt.Errorf(...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I forgot to do the logging here, which I think we need. So I kept the separate variable.

lnwallet/chanfunding/psbt_assembler.go Outdated Show resolved Hide resolved
Roasbeef and others added 8 commits May 27, 2024 12:58
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.
@guggero guggero merged commit 652ff81 into 0-19-staging May 27, 2024
23 of 27 checks passed
@guggero guggero deleted the aux-funding branch May 27, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom chans funding Related to the opening of new channels with funding transactions on the blockchain
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants