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

[5/? ] - lnwallet: add taproot funding support to the internal wallet flow (reservations) #7344

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Jan 20, 2023

Change Description

This depends on #7340.

In this PR, we build on all the prior commits and integrate the new taproot channels into the existing internal funding flow. Along the way, we do some refactoring to unify things like signing and verifying incoming commitment transaction signatures.

For our local nonce, we use the existing functional option type to derive the nonce based on the initial shachain pre-image we'll use as our revocation.

We also hook up the new funding flow to the existing internal wallet integration tests:

⛰   go test -v -run=TestLightningWallet/btcwallet/btcd:single_funding_workflow_musig2
=== RUN   TestLightningWallet
=== PAUSE TestLightningWallet
=== CONT  TestLightningWallet
=== RUN   TestLightningWallet/btcwallet/btcd:single_funding_workflow_musig2
--- PASS: TestLightningWallet (7.94s)
    --- PASS: TestLightningWallet/btcwallet/btcd:single_funding_workflow_musig2 (0.46s)
PASS
ok  	github.com/lightningnetwork/lnd/lnwallet/test/btcd	8.225s

The last ~14 commits are new. Along the way some rebase issues were found and fixed in commits marked as [temp].

The next PR in this series will modify the channel state machine to understand the new commitment dance.

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.

@Roasbeef Roasbeef changed the title [5/? ] - lnwallet: [5/? ] - lnwallet: add taproot funding support to the internal wallet flow (reservations) Jan 20, 2023
@saubyk saubyk added this to the v0.16.0 milestone Jan 20, 2023
@saubyk saubyk requested a review from yyforyongyu January 25, 2023 20:06
lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/wallet.go Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
@saubyk saubyk requested a review from Crypt-iQ January 31, 2023 18:07
@saubyk saubyk modified the milestones: v0.16.0, v0.16.1 Feb 14, 2023
lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/wallet.go Show resolved Hide resolved
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

very nice!

channeldb/channel.go Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
lnwallet/wallet.go Outdated Show resolved Hide resolved
lnwallet/wallet.go Outdated Show resolved Hide resolved
lnwallet/wallet.go Outdated Show resolved Hide resolved
lnwallet/test/test_interface.go Outdated Show resolved Hide resolved
@saubyk saubyk modified the milestones: v0.16.1, v0.17.0 Mar 13, 2023
@Roasbeef Roasbeef changed the base branch from master to simple-taproot-chans-staging April 26, 2023 23:48
@Roasbeef Roasbeef changed the base branch from simple-taproot-chans-staging to simple-taproot-funding April 27, 2023 00:02
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch from be2c89c to 58e6bef Compare April 27, 2023 00:05
@Roasbeef Roasbeef force-pushed the simple-taproot-funding branch from 8b3a3d6 to 6fc2387 Compare May 12, 2023 20:37
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch from 58e6bef to ce6879c Compare May 12, 2023 20:44
@lightninglabs-deploy
Copy link

@Crypt-iQ: review reminder
@Roasbeef, remember to re-request review from reviewers when ready

@Roasbeef Roasbeef force-pushed the simple-taproot-funding branch from 6fc2387 to 947096b Compare June 6, 2023 02:04
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch 2 times, most recently from f8bc68e to e895d9d Compare June 6, 2023 03:10
@Roasbeef
Copy link
Member Author

Roasbeef commented Jun 6, 2023

Initial round of comments addressed, PTAL!

lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/channel.go Outdated Show resolved Hide resolved
contractcourt/chain_watcher.go Show resolved Hide resolved
// local commitment transaction. If we need to force close, then this
// is also what'll be used to sign that transaction.
if reservation.partialState.ChanType.IsTaproot() {
firstNoncePreimage, err := taprootNonceProducer.AtIndex(0)
Copy link
Member

Choose a reason for hiding this comment

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

So this is the nonce that's sent in open_channel by the funder and can be used to generate the final sig when receiving funding_signed.nonce from the fundee right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, this is where we use the counter based method to generate nonces we can always arrive at again.

In part 4, I started to also bind the nonce creation with the tx hash of the tx we're about to sign. However at this point, we need to send a nonce, and don't yet know the tx hash so we can't do so.

We'll still do that each time we go to sign a new commitment, as the tx hash then is already known.

channeldb/channel.go Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/commitment.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef force-pushed the simple-taproot-funding branch 2 times, most recently from 691ecd9 to d22a0f9 Compare June 8, 2023 00:07
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch 2 times, most recently from d76ae7a to bfaefbe Compare June 8, 2023 00:32
@Roasbeef
Copy link
Member Author

Roasbeef commented Jun 8, 2023

Latest round of comments addressed, PTAL!

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Verrry close🤙🤙🤙 Need to fix the itest compile error, plus the linter error.

@@ -79,6 +92,8 @@ func (c CommitmentType) String() string {
return "anchors-zero-fee-second-level"
case CommitmentTypeScriptEnforcedLease:
return "script-enforced-lease"
case CommitmentTypeSimpleTaproot:
return "simple-taproot"
Copy link
Member

Choose a reason for hiding this comment

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

just occurs to me, why is this named simple taproot🤓?

Copy link
Member Author

Choose a reason for hiding this comment

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

So initial AJ had a much more feature complete and ambitious proposal to basically do everything (taproot, PTLCs, new commitment type, scriptless scripts) all in one. I thought it was a bit too much to bite off at once, so two spec meetings around I proposed a staged roll out proposal: musig2 output first, then PTLC+scriptless script, then commitment format changes). Thus was born "simple taproot".

lnwallet/commitment.go Show resolved Hide resolved
contractcourt/chain_watcher.go Show resolved Hide resolved
lnwallet/revocation_producer.go Outdated Show resolved Hide resolved
lnwallet/revocation_producer.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef force-pushed the simple-taproot-funding branch from d22a0f9 to 7c85f02 Compare June 9, 2023 00:20
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch from bfaefbe to 4cab0ce Compare June 9, 2023 00:40
@Roasbeef Roasbeef requested a review from yyforyongyu June 9, 2023 00:41
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

LGTM 🔥 🥕⚡

A couple of linter errors to catch - most of them are lll ones

)

return &ScriptInfo{
PkScript: toLocalPkScript,
Copy link
Collaborator

Choose a reason for hiding this comment

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

non blocking
am assuming we will calculate the witness script then for taproot chans at the time of spending since we would need to know which which branch we are spending in any case to build the control block at spend time. Other option would be to add a isLocalCommit bool to the CommitScriptToSelf method and then pre-compute and return the witness script & control block. That way we also dont have to derive the tree twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

See later in the series, this is modified further to include the full script tree information.

Copy link
Member

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Let's fix the linter errors and we can⛵️


// Add anchor for local commitment tx, if any.
revocation, err := lc.channelState.RevocationProducer.AtIndex(
lc.currentHeight,
Copy link
Member

Choose a reason for hiding this comment

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

Leaving some notes for other reviewers, was wondering if lc.currentHeight is always updated to date here since NewAnchorResolutions makes a separate call to db and creates a new LightningWallet. This is fine as we'd only call it when StateCommitmentBroadcasted, which means the db has the latest view of the local commit, and no other goroutines can update it anymore because it's closed.

lnwallet/wallet.go Show resolved Hide resolved
lnwallet/commitment.go Show resolved Hide resolved
lnwallet/reservation.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch from 4cab0ce to 781a70f Compare June 14, 2023 03:29
Roasbeef added 9 commits June 13, 2023 22:51
In this commit, we add a new wallet level channel type, along with the
new fields we'll need to accept from both parties within the
contribution messages. In this case, we now have a local nonce, along
with the internal musig session.
We also update some of the resolutions (even though they aren't hooked
up yet), as they need to be able to properly re-create the set of
scripts.
In this commit, we build on all the prior commits and integrate the new
taproot channels into the existing internal funding flow. Along the way,
we do some refactoring to unify things like signing and verifying
incoming commitment transaction signatures.

For our local nonce, we use the existing functional option type to
derive the nonce based on the initial shachain pre-image we'll use as
our revocation.
In this commit, we modify the starting logic to note attempt to add a
tower client for taproot channels. Instead, we'll just log that this
isn't available yet.
@Roasbeef Roasbeef force-pushed the simple-taproot-funding-reservation branch from 781a70f to 2d4df80 Compare June 14, 2023 03:54
@Roasbeef Roasbeef changed the base branch from simple-taproot-funding to simple-taproot-chans-staging June 14, 2023 03:54
@Roasbeef Roasbeef merged commit d91ae68 into lightningnetwork:simple-taproot-chans-staging Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: High Priority
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants