Skip to content

Commit 7e0ea47

Browse files
committed
lnwallet/chanvalidate: update ValidateChannel to recognize taproot chans
1 parent 0e4dcbe commit 7e0ea47

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

lnwallet/chanvalidate/validate.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ func Validate(ctx *Context) (*wire.OutPoint, error) {
186186
// If we reach this point, then all other checks have succeeded, so
187187
// we'll now attempt a full Script VM execution to ensure that we're
188188
// able to close the channel using this initial state.
189+
prevFetcher := txscript.NewCannedPrevOutputFetcher(
190+
ctx.MultiSigPkScript, fundingValue,
191+
)
192+
commitTx := ctx.CommitCtx.FullySignedCommitTx
193+
hashCache := txscript.NewTxSigHashes(commitTx, prevFetcher)
189194
vm, err := txscript.NewEngine(
190-
ctx.MultiSigPkScript, ctx.CommitCtx.FullySignedCommitTx,
191-
0, txscript.StandardVerifyFlags, nil, nil, fundingValue,
192-
txscript.NewCannedPrevOutputFetcher(ctx.MultiSigPkScript, 0),
195+
ctx.MultiSigPkScript, commitTx, 0, txscript.StandardVerifyFlags,
196+
nil, hashCache, fundingValue, prevFetcher,
193197
)
194198
if err != nil {
195199
return nil, err

lnwallet/wallet.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,27 +2362,44 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
23622362
if err != nil {
23632363
return err
23642364
}
2365-
signedCommitTx, err := channel.getSignedCommitTx()
2366-
if err != nil {
2367-
return err
2368-
}
2365+
2366+
localKey := channelState.LocalChanCfg.MultiSigKey.PubKey
2367+
remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey
23692368

23702369
// We'll also need the multi-sig witness script itself so the
23712370
// chanvalidate package can check it for correctness against the
23722371
// funding transaction, and also commitment validity.
2373-
localKey := channelState.LocalChanCfg.MultiSigKey.PubKey
2374-
remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey
2375-
witnessScript, err := input.GenMultiSigScript(
2376-
localKey.SerializeCompressed(),
2377-
remoteKey.SerializeCompressed(),
2378-
)
2379-
if err != nil {
2380-
return err
2372+
var fundingScript []byte
2373+
if channelState.ChanType.IsTaproot() {
2374+
fundingScript, _, err = input.GenTaprootFundingScript(
2375+
localKey, remoteKey, int64(channel.Capacity),
2376+
)
2377+
if err != nil {
2378+
return err
2379+
}
2380+
2381+
} else {
2382+
witnessScript, err := input.GenMultiSigScript(
2383+
localKey.SerializeCompressed(),
2384+
remoteKey.SerializeCompressed(),
2385+
)
2386+
if err != nil {
2387+
return err
2388+
}
2389+
fundingScript, err = input.WitnessScriptHash(witnessScript)
2390+
if err != nil {
2391+
return err
2392+
}
23812393
}
2382-
pkScript, err := input.WitnessScriptHash(witnessScript)
2394+
2395+
signedCommitTx, err := channel.getSignedCommitTx()
23832396
if err != nil {
23842397
return err
23852398
}
2399+
commitCtx := &chanvalidate.CommitmentContext{
2400+
Value: channel.Capacity,
2401+
FullySignedCommitTx: signedCommitTx,
2402+
}
23862403

23872404
// Finally, we'll pass in all the necessary context needed to fully
23882405
// validate that this channel is indeed what we expect, and can be
@@ -2391,12 +2408,9 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
23912408
Locator: &chanvalidate.OutPointChanLocator{
23922409
ChanPoint: channelState.FundingOutpoint,
23932410
},
2394-
MultiSigPkScript: pkScript,
2411+
MultiSigPkScript: fundingScript,
23952412
FundingTx: fundingTx,
2396-
CommitCtx: &chanvalidate.CommitmentContext{
2397-
Value: channel.Capacity,
2398-
FullySignedCommitTx: signedCommitTx,
2399-
},
2413+
CommitCtx: commitCtx,
24002414
})
24012415
if err != nil {
24022416
return err

0 commit comments

Comments
 (0)