This PR picks up the work from #18964 and closes #18954.
It should incorporate all the unaddressed feedback from the PR:
- Mempool rescan now expanded to all relevant import* RPCs
- Added documentation in the help of each RPC
- More tests
ACK abdaa251610569a346af55a1121c8ab385efb655
1599 | @@ -1592,7 +1600,7 @@ RPCHelpMan importdescriptors() 1600 | " Use the string \"now\" to substitute the current synced blockchain time.\n" 1601 | " \"now\" can be specified to bypass scanning, for outputs which are known to never have been used, and\n" 1602 | " 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest timestamp\n" 1603 | - " of all descriptors being imported will be scanned.", 1604 | + " of all descriptors being imported will be scanned as well as the mempool.",
"of all descriptors being imported will be scanned as well as the mempool.",
nit: The whitespace isn't needed and can be removed while touching this line. (If you need to retouch later)
done
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
No conflicts as of last run.
764 | @@ -765,7 +765,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup) 765 | // being blocked 766 | wallet = TestLoadWallet(context); 767 | BOOST_CHECK(rescan_completed); 768 | - BOOST_CHECK_EQUAL(addtx_count, 2); 769 | + BOOST_CHECK_EQUAL(addtx_count, 3);
a43ee48e8e904764fc12f58f40e569c7f2208876: maybe add a comment to explain what those 3 transactions are: 2 m_coinbase_txns entries and mempool_tx?
I'm confused why it's 3 here and 5 below.
https://github.com/bitcoin/bitcoin/commit/a43ee48e8e904764fc12f58f40e569c7f2208876: maybe add a comment to explain what those 3 transactions are: 2 m_coinbase_txns entries and mempool_tx? I'm confused why it's 3 here and 5 below.
Agreed.
Yeah, I see what you mean. The TestLoadWallet() helper function had a call to postInitProcess() which meant that the mempool was checked twice. Removing that led to the numbers in the CreateWallet test being much more sensible and there seem to be no other negative effects from that change. At least the test isn't failing and I also didn't see any other reason to keep it. I added some comments as well.
IMO bumping the numbers was better. :/
IMO bumping the numbers was better. :/
Could you say why you like it better? When the numbers are bumped I feel they don't match what the test is doing and I would need to add more comments to explain why this is the case. Hence it seemed like the better choice to me. Also curious to hear your feedback here @w0xlt and @Sjors :)
Seems like it would be undefined behaviour (between modules) to skip postInitProcess.
Counting AddToWallet calls might be too low-level to be a good test, but that seems out of scope here IMO.
I have no strong feelings about this, as long as it's clear from the code documentation where the transactions are coming from.
I'm unable to get this to work with descriptor wallets; still seeing the issue I reported in #25453.
Step 1: create a regular descriptor wallet, put some coins in it (I used a Taproot address for this)
Step 2: get ~one of its~ the matching receive descriptor ~s~ via listdescriptors
Step 3: create a watch-only wallet
Step 4: send coins to self, and before it confirms do:
Step 5: call importdescriptors on the watch-only wallet, using the above descriptor and some recent timestamp.
It will not add the mempool transaction until you either restart or it confirms.
rescanblockchain also doesn't add the transaction, but I suppose that's out of scope here.
Update: Note that you DO see the confirmed deposit transaction, but you don't see the outgoing mempool transaction.
1797 | @@ -1797,6 +1798,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc 1798 | } 1799 | } 1800 | } 1801 | + if (!max_height) { 1802 | + WalletLogPrintf("Scanning current mempool transactions.\n");
I don't see this notice in the log either.
Strange, that may be a hint that the build didn't have this change? But I will go through your steps as well as an additional check.
Indeed it turns out I was running the wrong build (again). Let me try again. At least I know for sure the bug exists on master 506d9b25a3f8ef8a4ce63f989083803d8d4ae6df :-)
249 | + variant.initial_amount = get_rand_amount() 250 | + variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount) 251 | + variant.confirmation_height = 0 252 | + variant.timestamp = timestamp 253 | + 254 | + assert_equal(len(self.nodes[0].getrawmempool()), 54)
nit: this makes it explicit that it is one transaction per variant
assert_equal(len(self.nodes[0].getrawmempool()), len(mempool_variants))
done
479 | @@ -480,7 +480,7 @@ def run_test(self): 480 | addr = wmulti_pub.getnewaddress('', 'bech32') 481 | assert_equal(addr, 'bcrt1qp8s25ckjl7gr6x2q3dx3tn2pytwp05upkjztk6ey857tt50r5aeqn6mvr9') # Derived at m/84'/0'/0'/1 482 | change_addr = wmulti_pub.getrawchangeaddress('bech32') 483 | - assert_equal(change_addr, 'bcrt1qt9uhe3a9hnq7vajl7a094z4s3crm9ttf8zw3f5v9gr2nyd7e3lnsy44n8e') 484 | + assert_equal(change_addr, 'bcrt1qzxl0qz2t88kljdnkzg4n4gapr6kte26390gttrg79x66nt4p04fssj53nl')
Perhaps the assertions below can be added.
They test that importdescriptors retrieved the mempool transaction.
Not related to this PR, but transaction send_txid is confirmed in line 457, isn't it ?
Why is it still in the mempool in line 463 and 470?
assert_equal(change_addr, 'bcrt1qzxl0qz2t88kljdnkzg4n4gapr6kte26390gttrg79x66nt4p04fssj53nl')
assert(any([x == send_txid for x in self.nodes[0].getrawmempool(True)]))
assert(any([x['txid'] == send_txid for x in wmulti_pub.listunspent(0)]))
Added
Not related to this PR, but transaction
send_txidis confirmed in line 457, isn't it ? Why is it still in the mempool in line 463 and 470?
Hm, you are right that this shouldn't really work but it still does due to a race between the two nodes involved. I am kind of surprised that this doesn't lead flakiness in the CI but I couldn't find any related issue. I addressed this in #25476.
479 | @@ -480,7 +480,9 @@ def run_test(self): 480 | addr = wmulti_pub.getnewaddress('', 'bech32') 481 | assert_equal(addr, 'bcrt1qp8s25ckjl7gr6x2q3dx3tn2pytwp05upkjztk6ey857tt50r5aeqn6mvr9') # Derived at m/84'/0'/0'/1 482 | change_addr = wmulti_pub.getrawchangeaddress('bech32') 483 | - assert_equal(change_addr, 'bcrt1qt9uhe3a9hnq7vajl7a094z4s3crm9ttf8zw3f5v9gr2nyd7e3lnsy44n8e') 484 | + assert_equal(change_addr, 'bcrt1qzxl0qz2t88kljdnkzg4n4gapr6kte26390gttrg79x66nt4p04fssj53nl') 485 | + assert(any([x == send_txid for x in self.nodes[0].getrawmempool(True)])) 486 | + assert(any([x['txid'] == send_txid for x in wmulti_pub.listunspent(0)]))
assert(any(x == send_txid for x in self.nodes[0].getrawmempool(True)))
assert(any(x['txid'] == send_txid for x in wmulti_pub.listunspent(0)))
No benefit to making it a list - just causes every element to be compared (using the generator directly stops comparing as soon as it finds a match)
Or even better and clearer...
assert(send_txid in self.nodes[0].getrawmempool(True))
assert(send_txid in (x['txid'] for x in wmulti_pub.listunspent(0)))
done
I redid the experiment and clarified the procedure a bit. ~It might be taproot-specific.~
Oops, I managed to run an earlier build of QT, because I reconfigred using --without-gui at some point. Will retry. Update: works!
tACK 8f59d58549ab8a9e7ecf8eb3ed2fb6d18b812a6d
(though I only manually tested with a taproot descriptor)
co-authored-by: Fabian Jahr <fjahr@protonmail.com>
co-authored-by: Fabian Jahr <fjahr@protonmail.com>
re-utACK 1be796418934ae7370cb0ed501877db59e738106 (only a test change)
ACK 1be796418934ae7370cb0ed501877db59e738106
Milestone
24.0