Skip to content
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
37148b6
lnwire: add new Musig2Nonce type for signing+verification musig nonces
Roasbeef Aug 31, 2022
8fd7459
lnwire: add musig2 nonces to open_channel msg
Roasbeef Aug 31, 2022
f61db68
lnwire: add musig2 nonces to accept_channel msg
Roasbeef Aug 31, 2022
4c15c28
lnwire: add musig2 nonces to funding_locked msg
Roasbeef Aug 31, 2022
4ffadd3
lnwire: add musig2 nonces to chan_reest msg
Roasbeef Aug 31, 2022
82bb765
lnwire: add musig2 nonces to closing_signed
Roasbeef Aug 31, 2022
fbf4a8e
lnwire: add musig2 nonces to commit_sig
Roasbeef Aug 31, 2022
0ccaaa0
lnwire: add musig2 nonces to revoke_and_ack
Roasbeef Aug 31, 2022
cbe0a9c
lnwire: add musig2 nonces to shutdown
Roasbeef Aug 31, 2022
090cf52
lnwire: add feature bits for simple-taproot-chans
Roasbeef Aug 31, 2022
4ffec3c
lnwire: always sort records in ExtractRecords
Roasbeef Aug 31, 2022
15552f7
feature: define default set and deps for simple taproot chans
Roasbeef Aug 31, 2022
c45f666
channeldb: add SimpleTaprootFeatureBit chan type
Roasbeef Aug 31, 2022
4fa2372
funding: define accepted feature bit combos for taproot chans
Roasbeef Aug 31, 2022
a318d4d
input: thread through musig2.SessionOptions for create session
Roasbeef Aug 31, 2022
75f4a14
input: add GenTaprootFundingScript for musig2 chans
Roasbeef Aug 31, 2022
5d40959
input: add TaprootCommitScriptToSelf for local self balance
Roasbeef Aug 31, 2022
b459a81
input: add TaprootCommitScriptToRemote for remote taproot outputs
Roasbeef Aug 31, 2022
9717efd
input: add TaprootOutputKeyAnchor for taproot anchor outputs
Roasbeef Aug 31, 2022
cc2fa3c
input: create new PayToTaprootScript utility func
Roasbeef Aug 31, 2022
a2cd14b
lnwallet/btcwallet: update musig2 signer to pass in session opts
Roasbeef Aug 31, 2022
f0360c9
lnwallet: add new taproot commitment type enum value
Roasbeef Aug 31, 2022
ae613fb
lnwallet: add signing+verification musig2 nonces to ChannelContribution
Roasbeef Aug 31, 2022
c68e84d
lnwallet: add MusigPartialSig wrapper over musig2.PartialSignature
Roasbeef Aug 31, 2022
fd58579
lnwallet: add MusigSession struct to encapsulate taproot commit updat…
Roasbeef Aug 31, 2022
05a8469
lnwallet: add MusigPairSession to handle asymmetric commitment states
Roasbeef Aug 31, 2022
b9a8400
lnwallet/chanfunding: update the funding assemblers to make musig2 fu…
Roasbeef Aug 31, 2022
e831860
lnwallet: add the pre-tweak CombinedFundingKey to CommitmentKeyRing
Roasbeef Aug 31, 2022
92b3a43
lnwallet: update CommitScriptToSelf to conditionally make P2TR outputs
Roasbeef Aug 31, 2022
d51facd
lnwallet: update CommitScriptToRemote to conditionally make P2TR outputs
Roasbeef Aug 31, 2022
d6eeda2
lnwallet: update CommitScriptAnchors to conditionally make P2TR outputs
Roasbeef Aug 31, 2022
a8554f4
lnwallet: create signing+verification nonces for taproot channel funding
Roasbeef Aug 31, 2022
1b121a3
funding: send signing+verification nonces in open/accept channel for …
Roasbeef Aug 31, 2022
ac82dd8
lnwallet: pass thru musig2 context for chan funder requests
Roasbeef Aug 31, 2022
505c190
lnwallet: add internal funding support for signing+verifying musig2 c…
Roasbeef Aug 31, 2022
1c9efdd
lnwallet: add new test case for musig2 single funder workflows
Roasbeef Aug 31, 2022
710e76a
lnwallet: add initial awareness for musig2 sessions to channel state …
Roasbeef Aug 31, 2022
7fe9929
lnwallet: update RemoteNextRevocation to return nil if no nonces know…
Roasbeef Aug 31, 2022
d3cb968
lnwallet: add initial support for musig2 handling for commitment dance
Roasbeef Sep 1, 2022
33f3b44
input: fix taproot local/remote scripts
Roasbeef Nov 17, 2022
bb085b0
lnwallet: use tweaked keys for taproot anchor outputs
Roasbeef Nov 17, 2022
2b93228
lnwallet: introduce new CommitSigs struct for sign/recv commit
Roasbeef Nov 17, 2022
ffe0b5c
input: add tapleaf+control block logic for sender HTLC scripts
Roasbeef Dec 31, 2022
b285a58
input: add tapleaf+ctrlblock logic for receiver HTLC scripts
Roasbeef Dec 31, 2022
6b22b0f
input: add new taproot second level HTLC scripts+txns
Roasbeef Dec 31, 2022
c884b4e
build: update to musig2 1.0
Roasbeef Dec 31, 2022
a7dca6b
lnwallet+input: move mock signer into lnwallet pkg, use new musig ses…
Roasbeef Dec 31, 2022
1797ace
multi: morph existing lnwire.SIg into new struct to support schnorr+e…
Roasbeef Dec 31, 2022
10e27ac
lnwallet: update funding nonce gen to pass in priv key
Roasbeef Dec 31, 2022
cc18427
lnwallet: parse incoming schnorr signature as "schnorr shell"
Roasbeef Dec 31, 2022
514254d
lnwallet: update ValidateChannel to recognize musig2+taproot chans
Roasbeef Dec 31, 2022
038954b
lnwallet: update CreateHtlcTimeoutTx+CreateHtlcSuccessTx for musig2+t…
Roasbeef Dec 31, 2022
8466ae0
lnwallet/btcwallet/signer: fix SignOutputRaw bug w/ non-default sighash
Roasbeef Dec 31, 2022
13fea73
lnwallet: properly pass in remoteCommit into NewMusigSession
Roasbeef Dec 31, 2022
950b83e
lnwallet: add temp methods for going to/from musig2 schnorr shell sigs
Roasbeef Dec 31, 2022
d28fe84
lnwallet: pass in pubkey for nonce gen in musig2.SignCommit
Roasbeef Dec 31, 2022
d443039
lnwallet: modify MusigSession.Refresh to return new instance instead …
Roasbeef Dec 31, 2022
391c176
lnwallet; update musig2.VerifyCommitSig to pubkey nonce and set prope…
Roasbeef Dec 31, 2022
d1eb662
lnwallet: add MusigSession.CombineSigs method
Roasbeef Dec 31, 2022
0689779
lnwallet: use input.Signature rather than raw sig pointers
Roasbeef Dec 31, 2022
9c4ff67
contractcourt: update the chainWatcher to recognize taproot+musig2 fu…
Roasbeef Dec 31, 2022
ef8ca2d
funding: send nonces along side open+accept channel
Roasbeef Dec 31, 2022
76e49f5
funding: update makeFundingScript for musig2 chans
Roasbeef Dec 31, 2022
c9d0f42
funding: send musig2 nonces w/ funding_locked, add recv processing logic
Roasbeef Dec 31, 2022
49bd2a4
funding: reject funding attempts for public taproot channels
Roasbeef Dec 31, 2022
9463eea
funding: add the taproot feature bit for funding announcements
Roasbeef Dec 31, 2022
67e0535
routing: update chan validate logic to recognize musig2 channels
Roasbeef Dec 31, 2022
b4b8157
lnwallet: add IsTaproot method to ChannelReservation
Roasbeef Dec 31, 2022
8aa81f8
lnwallet: update CommitScriptToRemote to properly set taproot script
Roasbeef Dec 31, 2022
1646d7c
lnwallet: update genHtlcScript to dispense taproot HTLC scripts
Roasbeef Dec 31, 2022
afd9e5c
lnwallet: update NewLightningChannel with new musig2 opts
Roasbeef Dec 31, 2022
3b27533
lnwallet: update sig pool to support signing+verifying 2nd level tapr…
Roasbeef Dec 31, 2022
15f0565
lnwallet: update channel state machine dance to support new musig2 flow
Roasbeef Dec 31, 2022
90194af
lnwallet: add new public NewMusigChannelNonces method, use pubkey for…
Roasbeef Dec 31, 2022
f9da9a4
lnwallet: add new co-op close opts for providing musig2 session for t…
Roasbeef Dec 31, 2022
464e009
lnwallet: add taproot case to testAddSettleWorkflow
Roasbeef Dec 31, 2022
ab91106
peer+lnpeer: add new wrapper struct to allow passing opaque opts to c…
Roasbeef Dec 31, 2022
7643be5
htlcswitch: pass along new musig2 nonce information to link
Roasbeef Dec 31, 2022
a370180
htlcswitch: send new nonces in chan reest message, add recv logic
Roasbeef Dec 31, 2022
f585b9c
lnwallet/chancloser: add support for musig2 co-op closes w/ auto accept
Roasbeef Dec 31, 2022
5e68ba8
rpc: add support for parsing musig2 openchannel requests
Roasbeef Dec 31, 2022
0a18d3e
cmd/lncli: add taproot chan parsing support for openchannel
Roasbeef Dec 31, 2022
5ba9ed5
multi: switch to using new partial_sig TLV type for musig sigs
Roasbeef Jan 12, 2023
dedd31d
multi: use distinct types for sig + nonce used in co-op close flow
Roasbeef Jan 13, 2023
e68221c
multi: use counter based (shachain) nonces for all local nonces
Roasbeef Jan 13, 2023
e69ffe8
lnwire: fix bug with PartialSigWithNonce.Decode/Encode
Roasbeef Jan 17, 2023
ded917b
multi: add initial support for force closing
Roasbeef Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ const (
// ScidAliasFeatureBit indicates that the scid-alias feature bit was
// negotiated during the lifetime of this channel.
ScidAliasFeatureBit ChannelType = 1 << 9

// SimpleTaprootFeatureBit indicates that the simple-taproot-channels
// feature bit was negotiated during the lifetime of the channel.
SimpleTaprootFeatureBit ChannelType = 1 << 10
)

// IsSingleFunder returns true if the channel type if one of the known single
Expand Down Expand Up @@ -343,6 +347,11 @@ func (c ChannelType) HasScidAliasFeature() bool {
return c&ScidAliasFeatureBit == ScidAliasFeatureBit
}

// IsTaproot returns true if the channel is using taproot features.
func (c ChannelType) IsTaproot() bool {
return c&SimpleTaprootFeatureBit == SimpleTaprootFeatureBit
}

// ChannelConstraints represents a set of constraints meant to allow a node to
// limit their exposure, enact flow control and ensure that all HTLCs are
// economically relevant. This struct will be mirrored for both sides of the
Expand Down Expand Up @@ -1315,11 +1324,11 @@ func (c *OpenChannel) SecondCommitmentPoint() (*btcec.PublicKey, error) {
// commitment chains in the case of a last or only partially processed message.
// When the remote party receives this message one of three things may happen:
//
// 1. We're fully synced and no messages need to be sent.
// 2. We didn't get the last CommitSig message they sent, so they'll re-send
// it.
// 3. We didn't get the last RevokeAndAck message they sent, so they'll
// re-send it.
// 1. We're fully synced and no messages need to be sent.
// 2. We didn't get the last CommitSig message they sent, so they'll re-send
// it.
// 3. We didn't get the last RevokeAndAck message they sent, so they'll
// re-send it.
//
// If this is a restored channel, having status ChanStatusRestored, then we'll
// modify our typical chan sync message to ensure they force close even if
Expand Down
4 changes: 4 additions & 0 deletions feature/default_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ var defaultSetDesc = setDesc{
SetInit: {}, // I
SetNodeAnn: {}, // N
},
lnwire.SimpleTaprootChannelsOptional: {
SetInit: {}, // I
SetNodeAnn: {}, // N
},
}
3 changes: 3 additions & 0 deletions feature/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ var deps = depDesc{
lnwire.ZeroConfOptional: {
lnwire.ScidAliasOptional: {},
},
lnwire.SimpleTaprootChannelsOptional: {
lnwire.ExplicitChannelTypeOptional: {},
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.

should anchors be a dependency?

},
}

// ValidateDeps asserts that a feature vector sets all features and their
Expand Down
45 changes: 45 additions & 0 deletions funding/commitment_type_negotiation.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,51 @@ func explicitNegotiateCommitmentType(channelType lnwire.ChannelType, local,
}
return lnwallet.CommitmentTypeTweakless, nil

// Simple taproot channels only.
case channelFeatures.OnlyContains(lnwire.SimpleTaprootChannelsRequired):

if !hasFeatures(
local, remote, lnwire.SimpleTaprootChannelsOptional,
) {
return 0, errUnsupportedChannelType
}

return lnwallet.CommitmentTypeSimpleTaproot, nil

// Simple taproot channels with scid only.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootChannelsRequired,
lnwire.ScidAliasRequired,
):

if !hasFeatures(
local, remote,
lnwire.SimpleTaprootChannelsOptional,
lnwire.ScidAliasOptional,
) {
return 0, errUnsupportedChannelType
}

return lnwallet.CommitmentTypeSimpleTaproot, nil

// Simple taproot channels with zero conf only.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootChannelsRequired,
lnwire.ScidAliasRequired,
lnwire.ZeroConfRequired,
):

if !hasFeatures(
local, remote,
lnwire.SimpleTaprootChannelsOptional,
lnwire.ScidAliasOptional,
lnwire.ZeroConfOptional,
) {
return 0, errUnsupportedChannelType
}

return lnwallet.CommitmentTypeSimpleTaproot, nil

// No features, use legacy commitment type.
case channelFeatures.IsEmpty():
return lnwallet.CommitmentTypeLegacy, nil
Expand Down
32 changes: 32 additions & 0 deletions funding/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,21 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
log.Debugf("Remote party accepted commitment constraints: %v",
spew.Sdump(remoteContribution.ChannelConfig.ChannelConstraints))

ourContribution := reservation.OurContribution()

var (
localNonce *lnwire.LocalMusig2Nonce
remoteNonce *lnwire.RemoteMusig2Nonce
)
if commitType == lnwallet.CommitmentTypeSimpleTaproot {
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.

can use IsTaproot()

localNonce = &lnwire.LocalMusig2Nonce{
Musig2Nonce: ourContribution.LocalNonce.PubNonce,
}
remoteNonce = &lnwire.RemoteMusig2Nonce{
Musig2Nonce: ourContribution.RemoteNonce.PubNonce,
}
}

// With the initiator's contribution recorded, respond with our
// contribution in the next message of the workflow.
ourContribution := reservation.OurContribution()
Expand All @@ -1680,6 +1695,8 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
UpfrontShutdownScript: ourContribution.UpfrontShutdown,
ChannelType: chanTypeFeatureBits,
LeaseExpiry: msg.LeaseExpiry,
LocalNonce: localNonce,
RemoteNonce: remoteNonce,
}

if err := peer.SendMessage(true, &fundingAccept); err != nil {
Expand Down Expand Up @@ -4037,6 +4054,19 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
log.Infof("Starting funding workflow with %v for pending_id(%x), "+
"committype=%v", msg.Peer.Address(), chanID, commitType)

var (
localNonce *lnwire.LocalMusig2Nonce
remoteNonce *lnwire.RemoteMusig2Nonce
)
if commitType == lnwallet.CommitmentTypeSimpleTaproot {
localNonce = &lnwire.LocalMusig2Nonce{
Musig2Nonce: ourContribution.LocalNonce.PubNonce,
}
remoteNonce = &lnwire.RemoteMusig2Nonce{
Musig2Nonce: ourContribution.RemoteNonce.PubNonce,
}
}

fundingOpen := lnwire.OpenChannel{
ChainHash: *f.cfg.Wallet.Cfg.NetParams.GenesisHash,
PendingChannelID: chanID,
Expand All @@ -4059,6 +4089,8 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
UpfrontShutdownScript: shutdown,
ChannelType: chanType,
LeaseExpiry: leaseExpiry,
LocalNonce: localNonce,
RemoteNonce: remoteNonce,
}
if err := msg.Peer.SendMessage(true, &fundingOpen); err != nil {
e := fmt.Errorf("unable to send funding request message: %v",
Expand Down
13 changes: 11 additions & 2 deletions input/musig2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ type MuSig2Signer interface {
// public key of the local signing key. If nonces of other parties are
// already known, they can be submitted as well to reduce the number of
// method calls necessary later on.
//
// The set of sessionOpts are _optional_ and allow a caller to modify the
// generated sessions. As an example the local nonce might already be generated
// ahead of time.
MuSig2CreateSession(keychain.KeyLocator, []*btcec.PublicKey,
*MuSig2Tweaks, [][musig2.PubNonceSize]byte) (*MuSig2SessionInfo,
error)
*MuSig2Tweaks, [][musig2.PubNonceSize]byte,
...musig2.SessionOption) (*MuSig2SessionInfo, error)

// TODO(roasbeef): need to make the sparse one here?
// * don't have any info but want a session

// MuSig2RegisterNonces registers one or more public nonces of other
// signing participants for a session identified by its ID. This method
Expand Down Expand Up @@ -76,6 +83,8 @@ type MuSig2SessionInfo struct {
// CombinedKey is the combined public key with all tweaks applied to it.
CombinedKey *btcec.PublicKey

// TODO(roasbeef): also add combined nonce

// TaprootTweak indicates whether a taproot tweak (BIP-0086 or script
// path) was used. The TaprootInternalKey will only be set if this is
// set to true.
Expand Down
Loading