Skip to content

Commit d2ed976

Browse files
committed
wallet: Precompute Txdata after setting PSBT inputs' UTXOs
If we are given a PSBT that is missing one or more input UTXOs, our PrecomputedTransactionData will be incorrect and missing information that it should otherwise have, and therefore we may not produce a signature when we should. To avoid this problem, we can do the precomputation after we have set the UTXOs the wallet is able to set for the PSBT. Also adds a test for this behavior.
1 parent 0817cc3 commit d2ed976

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
19691969
if (n_signed) {
19701970
*n_signed = 0;
19711971
}
1972-
const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
19731972
LOCK(cs_wallet);
19741973
// Get all of the previous transactions
19751974
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
@@ -1993,6 +1992,8 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
19931992
}
19941993
}
19951994

1995+
const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
1996+
19961997
// Fill in information from ScriptPubKeyMans
19971998
for (ScriptPubKeyMan* spk_man : GetAllScriptPubKeyMans()) {
19981999
int n_signed_this_spkm = 0;

test/functional/rpc_psbt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
assert_greater_than,
2222
assert_raises_rpc_error,
2323
find_output,
24+
find_vout_for_address,
2425
)
2526
from test_framework.wallet_util import bytes_to_wif
2627

@@ -764,5 +765,15 @@ def test_psbt_input_keys(psbt_input, keys):
764765
psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"]
765766
self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"])
766767

768+
self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs")
769+
addr = self.nodes[0].getnewaddress("", "bech32m")
770+
txid = self.nodes[0].sendtoaddress(addr, 1)
771+
vout = find_vout_for_address(self.nodes[0], txid, addr)
772+
psbt = self.nodes[0].createpsbt([{"txid": txid, "vout": vout}], [{self.nodes[0].getnewaddress(): 0.9999}])
773+
signed = self.nodes[0].walletprocesspsbt(psbt)
774+
rawtx = self.nodes[0].finalizepsbt(signed["psbt"])["hex"]
775+
self.nodes[0].sendrawtransaction(rawtx)
776+
self.generate(self.nodes[0], 1)
777+
767778
if __name__ == '__main__':
768779
PSBTTest().main()

0 commit comments

Comments
 (0)