lnwallet/chanvalidate: update ValidateChannel to recognize taproot chans

This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:31:36 -07:00
1 parent b38f9000d5
commit c9fc508083
2 files changed
+33 -15

No files matched your search

+7 -3
View File
@@ -186,10 +186,14 @@ func Validate(ctx *Context) (*wire.OutPoint, error) {
// If we reach this point, then all other checks have succeeded, so // If we reach this point, then all other checks have succeeded, so
// we'll now attempt a full Script VM execution to ensure that we're // we'll now attempt a full Script VM execution to ensure that we're
// able to close the channel using this initial state. // able to close the channel using this initial state.
prevFetcher := txscript.NewCannedPrevOutputFetcher(
ctx.MultiSigPkScript, fundingValue,
)
commitTx := ctx.CommitCtx.FullySignedCommitTx
hashCache := txscript.NewTxSigHashes(commitTx, prevFetcher)
vm, err := txscript.NewEngine( vm, err := txscript.NewEngine(
ctx.MultiSigPkScript, ctx.CommitCtx.FullySignedCommitTx, ctx.MultiSigPkScript, commitTx, 0, txscript.StandardVerifyFlags,
0, txscript.StandardVerifyFlags, nil, nil, fundingValue, nil, hashCache, fundingValue, prevFetcher,
txscript.NewCannedPrevOutputFetcher(ctx.MultiSigPkScript, 0),
) )
if err != nil { if err != nil {
return nil, err return nil, err
+26 -12
View File
@@ -2433,16 +2433,23 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
if err != nil { if err != nil {
return err return err
} }
signedCommitTx, err := channel.getSignedCommitTx()
if err != nil { localKey := channelState.LocalChanCfg.MultiSigKey.PubKey
return err remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey
}
// We'll also need the multi-sig witness script itself so the // We'll also need the multi-sig witness script itself so the
// chanvalidate package can check it for correctness against the // chanvalidate package can check it for correctness against the
// funding transaction, and also commitment validity. // funding transaction, and also commitment validity.
localKey := channelState.LocalChanCfg.MultiSigKey.PubKey var fundingScript []byte
remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey if channelState.ChanType.IsTaproot() {
fundingScript, _, err = input.GenTaprootFundingScript(
localKey, remoteKey, int64(channel.Capacity),
)
if err != nil {
return err
}
} else {
witnessScript, err := input.GenMultiSigScript( witnessScript, err := input.GenMultiSigScript(
localKey.SerializeCompressed(), localKey.SerializeCompressed(),
remoteKey.SerializeCompressed(), remoteKey.SerializeCompressed(),
@@ -2450,10 +2457,20 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
if err != nil { if err != nil {
return err return err
} }
pkScript, err := input.WitnessScriptHash(witnessScript) fundingScript, err = input.WitnessScriptHash(witnessScript)
if err != nil { if err != nil {
return err return err
} }
}
signedCommitTx, err := channel.getSignedCommitTx()
if err != nil {
return err
}
commitCtx := &chanvalidate.CommitmentContext{
Value: channel.Capacity,
FullySignedCommitTx: signedCommitTx,
}
// Finally, we'll pass in all the necessary context needed to fully // Finally, we'll pass in all the necessary context needed to fully
// validate that this channel is indeed what we expect, and can be // validate that this channel is indeed what we expect, and can be
@@ -2462,12 +2479,9 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
Locator: &chanvalidate.OutPointChanLocator{ Locator: &chanvalidate.OutPointChanLocator{
ChanPoint: channelState.FundingOutpoint, ChanPoint: channelState.FundingOutpoint,
}, },
MultiSigPkScript: pkScript, MultiSigPkScript: fundingScript,
FundingTx: fundingTx, FundingTx: fundingTx,
CommitCtx: &chanvalidate.CommitmentContext{ CommitCtx: commitCtx,
Value: channel.Capacity,
FullySignedCommitTx: signedCommitTx,
},
}) })
if err != nil { if err != nil {
return err return err