Skip to content

Commit 46c1454

Browse files
committed
lnwallet/chanvalidate: update ValidateChannel to recognize taproot chans
1 parent fdbe171 commit 46c1454

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
@@ -2373,27 +2373,44 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
23732373
if err != nil {
23742374
return err
23752375
}
2376-
signedCommitTx, err := channel.getSignedCommitTx()
2377-
if err != nil {
2378-
return err
2379-
}
2376+
2377+
localKey := channelState.LocalChanCfg.MultiSigKey.PubKey
2378+
remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey
23802379

23812380
// We'll also need the multi-sig witness script itself so the
23822381
// chanvalidate package can check it for correctness against the
23832382
// funding transaction, and also commitment validity.
2384-
localKey := channelState.LocalChanCfg.MultiSigKey.PubKey
2385-
remoteKey := channelState.RemoteChanCfg.MultiSigKey.PubKey
2386-
witnessScript, err := input.GenMultiSigScript(
2387-
localKey.SerializeCompressed(),
2388-
remoteKey.SerializeCompressed(),
2389-
)
2390-
if err != nil {
2391-
return err
2383+
var fundingScript []byte
2384+
if channelState.ChanType.IsTaproot() {
2385+
fundingScript, _, err = input.GenTaprootFundingScript(
2386+
localKey, remoteKey, int64(channel.Capacity),
2387+
)
2388+
if err != nil {
2389+
return err
2390+
}
2391+
2392+
} else {
2393+
witnessScript, err := input.GenMultiSigScript(
2394+
localKey.SerializeCompressed(),
2395+
remoteKey.SerializeCompressed(),
2396+
)
2397+
if err != nil {
2398+
return err
2399+
}
2400+
fundingScript, err = input.WitnessScriptHash(witnessScript)
2401+
if err != nil {
2402+
return err
2403+
}
23922404
}
2393-
pkScript, err := input.WitnessScriptHash(witnessScript)
2405+
2406+
signedCommitTx, err := channel.getSignedCommitTx()
23942407
if err != nil {
23952408
return err
23962409
}
2410+
commitCtx := &chanvalidate.CommitmentContext{
2411+
Value: channel.Capacity,
2412+
FullySignedCommitTx: signedCommitTx,
2413+
}
23972414

23982415
// Finally, we'll pass in all the necessary context needed to fully
23992416
// validate that this channel is indeed what we expect, and can be
@@ -2402,12 +2419,9 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
24022419
Locator: &chanvalidate.OutPointChanLocator{
24032420
ChanPoint: channelState.FundingOutpoint,
24042421
},
2405-
MultiSigPkScript: pkScript,
2422+
MultiSigPkScript: fundingScript,
24062423
FundingTx: fundingTx,
2407-
CommitCtx: &chanvalidate.CommitmentContext{
2408-
Value: channel.Capacity,
2409-
FullySignedCommitTx: signedCommitTx,
2410-
},
2424+
CommitCtx: commitCtx,
24112425
})
24122426
if err != nil {
24132427
return err

0 commit comments

Comments
 (0)