lnwallet: integrate new taproot channels into internal funding flow

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

For our local nonce, we use the existing functional option type to
derive the nonce based on the initial shachain pre-image we'll use as
our revocation.
This commit is contained in:
Olaoluwa Osuntokun
2023-01-19 17:15:12 -08:00
parent 9e8b00241f
commit 67ecefaac3
6 changed files with 315 additions and 108 deletions

View File

@@ -8,17 +8,19 @@ import (
)
// nextRevocationProducer creates a new revocation producer, deriving the
// revocation root by applying ECDH to a new key from our revocation root family
// and the multisig key we use for the channel.
// revocation root by applying ECDH to a new key from our revocation root
// family and the multisig key we use for the channel. For taproot channels a
// related shachain revocation root is also returned.
func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
keyRing keychain.KeyRing) (shachain.Producer, error) {
keyRing keychain.KeyRing,
) (shachain.Producer, shachain.Producer, error) {
// Derive the next key in the revocation root family.
nextRevocationKeyDesc, err := keyRing.DeriveNextKey(
keychain.KeyFamilyRevocationRoot,
)
if err != nil {
return nil, err
return nil, nil, err
}
// If the DeriveNextKey call returns the first key with Index 0, we need
@@ -29,7 +31,7 @@ func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
keychain.KeyFamilyRevocationRoot,
)
if err != nil {
return nil, err
return nil, nil, err
}
}
@@ -42,10 +44,16 @@ func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
nextRevocationKeyDesc, res.ourContribution.MultiSigKey.PubKey,
)
if err != nil {
return nil, err
return nil, nil, err
}
// Once we have the root, we can then generate our shachain producer
// and from that generate the per-commitment point.
return shachain.NewRevocationProducer(revRoot), nil
shaChainRoot := shachain.NewRevocationProducer(revRoot)
taprootShaChainRoot, err := deriveMusig2Shachain(revRoot)
if err != nil {
return nil, nil, err
}
return shaChainRoot, taprootShaChainRoot, nil
}