diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-19 10:58:22 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-19 10:58:25 +0200 |
commit | 1b285b7807076b9b9c2863c27776c5f1354c1f5b (patch) | |
tree | fceeca5e14a04597810ffba38889f1f59653b254 | |
parent | 8c9ea8a556fd2f8859558eba1f75d320d40732dc (diff) | |
parent | d2ed97656bba050051cfc677f1fa7eb3fc633f7d (diff) | |
download | bitcoin-1b285b7807076b9b9c2863c27776c5f1354c1f5b.tar.xz |
Merge bitcoin/bitcoin#25590: wallet: Precompute Txdata after setting PSBT inputs' UTXOs
d2ed97656bba050051cfc677f1fa7eb3fc633f7d 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 https://github.com/bitcoin/bitcoin/pull/25590/commits/d2ed97656bba050051cfc677f1fa7eb3fc633f7d
Sjors:
ACK d2ed97656bba050051cfc677f1fa7eb3fc633f7d
aureleoules:
ACK d2ed97656bba050051cfc677f1fa7eb3fc633f7d.
Tree-SHA512: 71beb6c7946096e82cfca83f36277302aa9e69d27b4f6d73d7d8f2f9f0ea1c0d653e846fa6aebee5e4763f56f950b4481240e953f6a2412caa84908d519171e1
-rw-r--r-- | src/wallet/wallet.cpp | 3 | ||||
-rwxr-xr-x | test/functional/rpc_psbt.py | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 890e171913..9af68000aa 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1984,7 +1984,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp if (n_signed) { *n_signed = 0; } - const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); LOCK(cs_wallet); // Get all of the previous transactions for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) { @@ -2008,6 +2007,8 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp } } + const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); + // Fill in information from ScriptPubKeyMans for (ScriptPubKeyMan* spk_man : GetAllScriptPubKeyMans()) { int n_signed_this_spkm = 0; diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 264b2ac32d..93b8d81959 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -22,6 +22,7 @@ from test_framework.util import ( assert_greater_than, assert_raises_rpc_error, find_output, + find_vout_for_address, ) from test_framework.wallet_util import bytes_to_wif @@ -764,5 +765,15 @@ class PSBTTest(BitcoinTestFramework): psbt = self.nodes[0].walletprocesspsbt(psbt)["psbt"] self.nodes[0].sendrawtransaction(self.nodes[0].finalizepsbt(psbt)["hex"]) + self.log.info("Test that walletprocesspsbt both updates and signs a non-updated psbt containing Taproot inputs") + addr = self.nodes[0].getnewaddress("", "bech32m") + txid = self.nodes[0].sendtoaddress(addr, 1) + vout = find_vout_for_address(self.nodes[0], txid, addr) + psbt = self.nodes[0].createpsbt([{"txid": txid, "vout": vout}], [{self.nodes[0].getnewaddress(): 0.9999}]) + signed = self.nodes[0].walletprocesspsbt(psbt) + rawtx = self.nodes[0].finalizepsbt(signed["psbt"])["hex"] + self.nodes[0].sendrawtransaction(rawtx) + self.generate(self.nodes[0], 1) + if __name__ == '__main__': PSBTTest().main() |