From 75016a176ca89e5269737fc1bc435755a1151bfb Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 3 Feb 2022 17:34:14 +0100 Subject: [PATCH] rpcwallet: disallow empty UTXO pk script [skip ci] If we're signing for an UTXO that isn't known to the wallet, then the UTXO's pk script _must_ be set in the sign descriptor. Otherwise we run into a generic PSBT serialization error when running in a remote signing setup. --- lnwallet/rpcwallet/rpcwallet.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lnwallet/rpcwallet/rpcwallet.go b/lnwallet/rpcwallet/rpcwallet.go index 01f9f5449..8c90dfc34 100644 --- a/lnwallet/rpcwallet/rpcwallet.go +++ b/lnwallet/rpcwallet/rpcwallet.go @@ -618,6 +618,16 @@ func (r *RPCKeyRing) remoteSign(tx *wire.MsgTx, signDesc *input.SignDescriptor, PubKey: signDesc.KeyDesc.PubKey.SerializeCompressed(), }} + // We need to specify a pk script in the witness UTXO, otherwise + // the field becomes invalid when serialized as a PSBT. To avoid + // running into a generic "Invalid PSBT serialization format" + // error later, we return a more descriptive error now. + if len(in.WitnessUtxo.PkScript) == 0 { + return nil, fmt.Errorf("error assembling UTXO " + + "information, output not known to wallet and " + + "no UTXO pk script provided in sign descriptor") + } + default: return nil, fmt.Errorf("error assembling UTXO information, "+ "wallet returned err='%v' and sign descriptor is "+