Skip to content

Commit 1b285b7

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25590: wallet: Precompute Txdata after setting PSBT inputs' UTXOs
d2ed976 wallet: Precompute Txdata after setting PSBT inputs' UTXOs (Andrew Chow) Pull request description: 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. ACKs for top commit: instagibbs: reACK bitcoin/bitcoin@d2ed976 Sjors: ACK d2ed976 aureleoules: ACK d2ed976. Tree-SHA512: 71beb6c7946096e82cfca83f36277302aa9e69d27b4f6d73d7d8f2f9f0ea1c0d653e846fa6aebee5e4763f56f950b4481240e953f6a2412caa84908d519171e1
2 parents 8c9ea8a + d2ed976 commit 1b285b7

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
@@ -1984,7 +1984,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
19841984
if (n_signed) {
19851985
*n_signed = 0;
19861986
}
1987-
const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
19881987
LOCK(cs_wallet);
19891988
// Get all of the previous transactions
19901989
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
@@ -2008,6 +2007,8 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
20082007
}
20092008
}
20102009

2010+
const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
2011+
20112012
// Fill in information from ScriptPubKeyMans
20122013
for (ScriptPubKeyMan* spk_man : GetAllScriptPubKeyMans()) {
20132014
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
@@ -22,6 +22,7 @@
2222
assert_greater_than,
2323
assert_raises_rpc_error,
2424
find_output,
25+
find_vout_for_address,
2526
)
2627
from test_framework.wallet_util import bytes_to_wif
2728

@@ -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)