[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow - #7346

Merged
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr
Jul 27, 2023
Merged

[7/?] - funding: update funding manager w/ new musig2+taproot funding flow #7346
Roasbeef merged 11 commits into
lightningnetwork:simple-taproot-chans-stagingfrom
Roasbeef:simple-taproot-chans-funding-mgr

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Change Description

Depends on #7345.

Only the last 6 commits are new.

In this PR, we build on the prior PR that updated the channel state machine to update the funding manager to be aware of the new funding flow.

This flow is identical to the existing flow, but both sides need to exchange local nonces up front, and then signatures sent are now partial signatures instead of regular signatures.

The funding manager also gains some new state of the local nonces it needs to generate in order to send the funding locked message, and also process the funding locked message from the remote party.

In order to allow the funding manger to generate the nonces that need to be applied to each channel, then AddNewChannel method has been modified to accept a set of options that the peer will then use to bind the nonces to a new channel.

We also update the link+peer interaction to know how to initialize the new channel, as well as the extra information that needs to be sent in funding locked and the channel reest message.

As a stop gap before Gossip 1.5, we need to set a new feature bit in the channel announcement itself. Otherwise, the router won't know how to validate the funding script of the newly created channel.

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.

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you expect the same feature bit to be used eventually for public channels?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, this is a temp hack so we're able to signal to the gossiper exactly what type of channel this is. When things get to the router, we'll still verify the channel on-chain (compared the output to the expected script), so we need this in order to signal that this is a different type of channel.

@joostjagerjoostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shallow-reviewed all the PRs in the series and overall the addition of simple taproot channels does not look too involved at all! Of course relative to the expectation, because obviously it is still a large diff.

General comments:

  • Perhaps it is good to make the changes so that taproot channels follow the default flow instead of being the exception. So if !taproot { ... } rather than if taproot { ...}
  • Related to the first point: would it be feasible to take a more object-oriented approach for adding taproot channels? More grouping of taproot-channel-specific code in a single location and fewer selects on chan type could possibly improve code quality.
  • For public channels, gossip needs to change. Is there already anything concrete in terms of spec for that? Would be helpful to complete the mental model, even if not implemented.
  • To reduce complexity, it would be great if all non-taproot channels would just go away 😬

@saubyksaubyk modified the milestones: v0.16.0, v0.16.1Feb 14, 2023
@saubyksaubyk modified the milestones: v0.16.1, v0.17.0Mar 13, 2023
@Roasbeef
Roasbeef changed the base branch from master to simple-taproot-chans-channel-statemachineApril 27, 2023 00:10
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from ff09526 to 3ccb4e1CompareApril 27, 2023 00:12

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did first pass - looks good! Sooo cool how the funding manager could be made taproot-chan-ready with such a slim diff 🔥

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
if !ok {
// If there's no pending nonce for this channel ID,
// then we'll generate one now.
verNonce, err := lnwallet.NewMusigVerificationNonce(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can use channel.GenMusigNonces() as is done for createFundingLocked

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agree

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So can't use it here as we don't yet have the full channel state machine created. So instead we need to call the function manually. Also spotted a bug here (will be covered by the eventual itests): it uses the current commitment height, but should actually use the next commitment height. I think @ellemouton ran into this in the past.

Comment threadfunding/manager.go
Comment threadfeature/deps.go Outdated
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it gets confusing because they may send a channel_ready and channel_reestablish

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goa here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Goal here is to have the "last" one override the nonce that we'll store for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this modify the feature bit dependency mapping to use "INC+" instead of "IN"?

Comment threadrouting/router.go
Comment threadhtlcswitch/link.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadhtlcswitch/link.go
Comment threadhtlcswitch/link.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 717c9a3 to 4a43a07CompareMay 12, 2023 20:52
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 7b91e27 to a9dd0f4CompareMay 12, 2023 20:57

@positivebluepositiveblue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass done.

The code looks good and the changes are pretty straight forward 🎉

There are some issues to resolve before merging (like make it panic proof). I also did not see any tests in the commits, are they added later in the PR chain?

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch from 4a43a07 to 763d774CompareJuly 3, 2023 01:25
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 138c6c5 to c8e9287CompareJuly 3, 2023 02:18
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-channel-statemachine branch 4 times, most recently from b3a68b0 to 07d8f36CompareJuly 14, 2023 02:22
@litbot-9000

Copy link
Copy Markdown
Collaborator

@Roasbeef, remember to re-request review from reviewers when ready

@levmi
levmi requested a review from positiveblueJuly 17, 2023 11:11

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this might be an outdated branch because there are three panics?

  • msg.LocalNonce in handleFundingOpen
  • msg.LocalNonce in handleFundingAccept
  • sig.Nonce in VerifyCommitSig

Comment threadfunding/manager.go
Comment threadfunding/manager.go Outdated
}

// TODO(roasbeef): call sendFundingLocked here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

think we need to include nonces here. Also think the spec needs to clarify what to do when we receive another FundingLocked that rotates the alias, do we ignore the nonces?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes as is we'll ignore the second one (existing logic). We'll use the same nonce each time until the channel state has moved forward one.

Comment threadfunding/manager.go
Comment threadpeer/brontide.go
}

// TODO(roasbeef): don't also need to apply
// nonces here? get from chan reest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that means that the channel_ready will override the nonces previously set in channel_reestablish? IMO if channel_reestablish has been exchanged, we should ignore nonces in channel_ready and then we never need to worry about overriding nonces with scid alias rotation

Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go Outdated
Comment threadhtlcswitch/link.go
Comment threadcontractcourt/chain_watcher.go
Comment threadcontractcourt/chain_watcher.go
@Roasbeef
Roasbeef changed the base branch from simple-taproot-chans-channel-statemachine to simple-taproot-chans-stagingJuly 23, 2023 16:11
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from c8e9287 to 171e993CompareJuly 23, 2023 16:13
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/transactions.go Outdated
Comment threadlnwallet/channel.go Outdated
Comment threadlnwallet/channel.go
Comment threadlnwallet/channel.go Outdated
Comment threadfeature/default_sets.go
Comment threadfunding/commitment_type_negotiation.go
Comment threadfunding/manager.go Outdated
Comment threadrouting/router.go Outdated
Comment threadhtlcswitch/link.go Outdated
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from af2fe2b to e47ccedCompareJuly 24, 2023 19:25

@ellemoutonellemouton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending resolution on @Crypt-iQ's comment re RegisterSpendNtfn & CI fixes.
Left one comment re allowing unsetting of the new feature bit.

Comment threadfeature/deps.go
Comment threadfunding/commitment_type_negotiation.go Outdated
Comment threadfunding/manager.go
Comment threadfunding/manager.go
@Crypt-iQ

Crypt-iQ commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator

sig.Nonce in VerifyCommitSig

sig.Nonce isn't a pointer here.

if sig is nil then it will be nil-ptr-dereference

@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch 2 times, most recently from 8cfdf30 to a1b6a0dCompareJuly 26, 2023 00:54

@yyforyongyuyyforyongyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think it's very close. Got one question - should we update the commit weight and fee here when calling NewChannelReservation?

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: would put this check after L1968 to align with other checks such as if !resCtx.reservation.IsZeroConf() && msg.MinAcceptDepth == 0 { .

Comment threadfunding/manager.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably a bug, not introduced from this PR tho. At L2320 we already called f.deleteReservationCtx which removes the channel from f.activeReservations. Hence when we call failFundingFlow here, it will error out because f.cancelReservationCtx won't find the reservation.

Comment threadfunding/manager.go Outdated
Comment threadfunding/manager.go Outdated
@ellemouton

Copy link
Copy Markdown
Collaborator

should we update the commit weight and fee here when calling NewChannelReservation?

I think we can just change that to use the lnwallet.CommitWeight method instead which is updated with a taproot case here

@Crypt-iQCrypt-iQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM pending two comments:

Roasbeef added 10 commits July 26, 2023 15:46
In this commit, we add support for the new musig2 channel funding flow.
This flow is identical to the existing flow, but not both sides need to
exchange local nonces up front, and then signatures sent are now partial
signatures instead of regular signatures.
The funding manager also gains some new state of the local nonces it
needs to generate in order to send the funding locked message, and also
process the funding locked message from the remote party.
In order to allow the funding manger to generate the nonces that need to
be applied to each channel, then AddNewChannel method has been modified
to accept a set of options that the peer will then use to bind the
nonces to a new channel.
… channels
In this commit, we start to set _internally_ a new feature bit in the
channel announcements we generate. As these taproot channels can only be
unadvertised, this will never actually leak to the public network. The
funding manager will then set this field to allow the router to properly
validate these channels.
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
This ensures that when loading the channel again after a normal chan
reest, we generate the local nonces, which ensures we can then process
nonces the remote party sends us in their chan reest message.
This ensures that we end up playing the target output on chain for
taproot channels.
@Roasbeef
Roasbeefforce-pushed the simple-taproot-chans-funding-mgr branch from a1b6a0d to ea25054CompareJuly 27, 2023 00:04
@Roasbeef

Copy link
Copy Markdown
MemberAuthor

Pushed up a final set of commits adding unit test coverage for the new funding manager flows, cc @positiveblue

@Roasbeef
Roasbeef merged commit dd8820d into lightningnetwork:simple-taproot-chans-stagingJul 27, 2023
@Crypt-iQ

Copy link
Copy Markdown
Collaborator

@ellemouton comment was that channelFeatures.OnlyContains can be called with ZeroConfRequired and ScidAliasRequired, but then hasFeatures doesn't contain ScidAliasOptional. I think that the ZeroConfRequired+ScidAliasRequired case is missing from this PR

@saubyksaubyk moved this from High Priority to Merged in PR Review PriorityMay 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

9 participants

@Roasbeef@litbot-9000@Crypt-iQ@ellemouton@positiveblue@joostjager@yyforyongyu@sputn1ck@saubyk