mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
lnrpc+itest: fix panic with missing UTXO info
Fixes #6396. This commit fixes a panic that occurred when trying to sign for a Taproot output without specifying the full UTXO information for each input. Instead of panicking an error is now returned.
This commit is contained in:
parent
2a069b8b4e
commit
1e72d6737d
@ -376,6 +376,24 @@ func (s *Server) SignOutputRaw(_ context.Context, in *SignReq) (*SignResp,
|
|||||||
InputIndex: int(signDesc.InputIndex),
|
InputIndex: int(signDesc.InputIndex),
|
||||||
PrevOutputFetcher: prevOutputFetcher,
|
PrevOutputFetcher: prevOutputFetcher,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Are we trying to sign for a Taproot output? Then we need all
|
||||||
|
// previous outputs being declared, otherwise we'd run into a
|
||||||
|
// panic later on.
|
||||||
|
if txscript.IsPayToTaproot(signDesc.Output.PkScript) {
|
||||||
|
for idx, txIn := range txToSign.TxIn {
|
||||||
|
utxo := prevOutputFetcher.FetchPrevOutput(
|
||||||
|
txIn.PreviousOutPoint,
|
||||||
|
)
|
||||||
|
if utxo == nil {
|
||||||
|
return nil, fmt.Errorf("error signing "+
|
||||||
|
"taproot output, transaction "+
|
||||||
|
"input %d is missing its "+
|
||||||
|
"previous outpoint information",
|
||||||
|
idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we've mapped all the proper sign descriptors, we can
|
// Now that we've mapped all the proper sign descriptors, we can
|
||||||
|
@ -232,6 +232,29 @@ func testTaprootScriptSpend(ctxt context.Context, t *harnessTest,
|
|||||||
PkScript: p2trPkScript,
|
PkScript: p2trPkScript,
|
||||||
Value: 800_000,
|
Value: 800_000,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
// Before we actually sign, we want to make sure that we get an error
|
||||||
|
// when we try to sign for a Taproot output without specifying all UTXO
|
||||||
|
// information.
|
||||||
|
_, err = net.Alice.SignerClient.SignOutputRaw(
|
||||||
|
ctxt, &signrpc.SignReq{
|
||||||
|
RawTxBytes: buf.Bytes(),
|
||||||
|
SignDescs: []*signrpc.SignDescriptor{{
|
||||||
|
Output: utxoInfo[0],
|
||||||
|
InputIndex: 0,
|
||||||
|
KeyDesc: keyDesc,
|
||||||
|
Sighash: uint32(txscript.SigHashDefault),
|
||||||
|
WitnessScript: leaf2.Script,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
require.Error(t.t, err)
|
||||||
|
require.Contains(
|
||||||
|
t.t, err.Error(), "error signing taproot output, transaction "+
|
||||||
|
"input 0 is missing its previous outpoint information",
|
||||||
|
)
|
||||||
|
|
||||||
|
// Do the actual signing now.
|
||||||
signResp, err := net.Alice.SignerClient.SignOutputRaw(
|
signResp, err := net.Alice.SignerClient.SignOutputRaw(
|
||||||
ctxt, &signrpc.SignReq{
|
ctxt, &signrpc.SignReq{
|
||||||
RawTxBytes: buf.Bytes(),
|
RawTxBytes: buf.Bytes(),
|
||||||
|
Loading…
Reference in New Issue
Block a user