mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Merge bitcoin/bitcoin#30357: Fix cases of calls to FillPSBT
errantly returning complete=true
7e36dca657
test: add test for modififed walletprocesspsbt calls (willcl-ark)39cea21ec5
wallet: fix FillPSBT errantly showing as complete (willcl-ark) Pull request description: Fixes: #30077 Fix cases of calls to `FillPSBT` returning `complete=true` when it's not the case. This can happen when some inputs have been signed but the transaction is subsequently modified, e.g. in the context of PayJoins. Also fixes a related bug where a finalized hex string is attempted to be added during `walletprocesspsbt` but a CHECK_NONFATAL causes an abort. ACKs for top commit: achow101: ACK7e36dca657
ismaelsadeeq: Tested ACK7e36dca657
pinheadmz: re-ACK7e36dca657
Tree-SHA512: e35d19789899c543866d86d513506494d672e4bed9aa36a995dbec4e72f0a8ec5536b57c4a940a18002ae4a8efd0b007c77ba64e57cd52af98e4ac0e7bf650d6
This commit is contained in:
commit
6f9db1ebca
2 changed files with 25 additions and 2 deletions
|
@ -2225,8 +2225,8 @@ std::optional<PSBTError> CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bo
|
|||
|
||||
// Complete if every input is now signed
|
||||
complete = true;
|
||||
for (const auto& input : psbtx.inputs) {
|
||||
complete &= PSBTInputSigned(input);
|
||||
for (size_t i = 0; i < psbtx.inputs.size(); ++i) {
|
||||
complete &= PSBTInputSignedAndVerified(psbtx, i, &txdata);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -68,6 +68,28 @@ class PSBTTest(BitcoinTestFramework):
|
|||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def test_psbt_incomplete_after_invalid_modification(self):
|
||||
self.log.info("Check that PSBT is correctly marked as incomplete after invalid modification")
|
||||
node = self.nodes[2]
|
||||
wallet = node.get_wallet_rpc(self.default_wallet_name)
|
||||
address = wallet.getnewaddress()
|
||||
wallet.sendtoaddress(address=address, amount=1.0)
|
||||
self.generate(node, nblocks=1, sync_fun=lambda: self.sync_all(self.nodes[:2]))
|
||||
|
||||
utxos = wallet.listunspent(addresses=[address])
|
||||
psbt = wallet.createpsbt([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{wallet.getnewaddress(): 0.9999}])
|
||||
signed_psbt = wallet.walletprocesspsbt(psbt)["psbt"]
|
||||
|
||||
# Modify the raw transaction by changing the output address, so the signature is no longer valid
|
||||
signed_psbt_obj = PSBT.from_base64(signed_psbt)
|
||||
substitute_addr = wallet.getnewaddress()
|
||||
raw = wallet.createrawtransaction([{"txid": utxos[0]["txid"], "vout": utxos[0]["vout"]}], [{substitute_addr: 0.9999}])
|
||||
signed_psbt_obj.g.map[PSBT_GLOBAL_UNSIGNED_TX] = bytes.fromhex(raw)
|
||||
|
||||
# Check that the walletprocesspsbt call succeeds but also recognizes that the transaction is not complete
|
||||
signed_psbt_incomplete = wallet.walletprocesspsbt(signed_psbt_obj.to_base64(), finalize=False)
|
||||
assert signed_psbt_incomplete["complete"] is False
|
||||
|
||||
def test_utxo_conversion(self):
|
||||
self.log.info("Check that non-witness UTXOs are removed for segwit v1+ inputs")
|
||||
mining_node = self.nodes[2]
|
||||
|
@ -589,6 +611,7 @@ class PSBTTest(BitcoinTestFramework):
|
|||
|
||||
if self.options.descriptors:
|
||||
self.test_utxo_conversion()
|
||||
self.test_psbt_incomplete_after_invalid_modification()
|
||||
|
||||
self.test_input_confs_control()
|
||||
|
||||
|
|
Loading…
Reference in a new issue