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 committed 2023-08-22 16:31:07 -07:00
1 parent 9e8b00241f
commit 67ecefaac3
6 files changed
+315 -108

No files matched your search

+21 -8
View File
@@ -12,14 +12,15 @@ import (
// revocation root by applying ECDH to a new key from our revocation root family
// and the multisig key we use for the channel.
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
}
// Within our itests, we want to make sure we can still restore channel
@@ -34,17 +35,23 @@ func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
if res.pendingChanID == itestLegacyFormatChanID {
revocationRoot, err := l.DerivePrivKey(nextRevocationKeyDesc)
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.
revRoot, err := chainhash.NewHash(revocationRoot.Serialize())
if err != nil {
return nil, err
return nil, nil, err
}
shaChainRoot := shachain.NewRevocationProducer(*revRoot)
taprootShaChainRoot, err := deriveMusig2Shachain(*revRoot)
if err != nil {
return nil, nil, err
}
return shachain.NewRevocationProducer(*revRoot), nil
return shaChainRoot, taprootShaChainRoot, nil
}
// If the DeriveNextKey call returns the first key with Index 0, we need
@@ -55,7 +62,7 @@ func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
keychain.KeyFamilyRevocationRoot,
)
if err != nil {
return nil, err
return nil, nil, err
}
}
@@ -68,10 +75,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
}