contractcourt: update chain watcher to understand the taproot pkscript

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 commit is contained in:
Olaoluwa Osuntokun 2023-01-19 20:31:31 -08:00
parent e8b6e0ca45
commit 9ce817511d
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -287,17 +287,32 @@ func (c *chainWatcher) Start() error {
}
}
localKey := chanState.LocalChanCfg.MultiSigKey.PubKey.SerializeCompressed()
remoteKey := chanState.RemoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
multiSigScript, err := input.GenMultiSigScript(
localKey, remoteKey,
localKey := chanState.LocalChanCfg.MultiSigKey.PubKey
remoteKey := chanState.RemoteChanCfg.MultiSigKey.PubKey
var (
pkScript []byte
err error
)
if err != nil {
return err
}
pkScript, err := input.WitnessScriptHash(multiSigScript)
if err != nil {
return err
if chanState.ChanType.IsTaproot() {
pkScript, _, err = input.GenTaprootFundingScript(
localKey, remoteKey, 0,
)
if err != nil {
return err
}
} else {
multiSigScript, err := input.GenMultiSigScript(
localKey.SerializeCompressed(),
remoteKey.SerializeCompressed(),
)
if err != nil {
return err
}
pkScript, err = input.WitnessScriptHash(multiSigScript)
if err != nil {
return err
}
}
spendNtfn, err := c.cfg.notifier.RegisterSpendNtfn(
@ -833,6 +848,9 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail,
}
// Create an AnchorResolution for the breached state.
//
// TODO(roasbeef): make keyring for taproot chans to pass in instead of
// nil
anchorRes, err := lnwallet.NewAnchorResolution(
c.cfg.chanState, commitSpend.SpendingTx, nil,
)