0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

wallet: Rescan mempool for transactions as well

This commit is contained in:
Fabian Jahr 2022-05-01 14:28:14 +02:00
parent 37633d2f61
commit 236239bd40
No known key found for this signature in database
GPG key ID: F13D1E9D890798CD
3 changed files with 13 additions and 6 deletions

View file

@ -55,9 +55,6 @@ static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
auto database = MakeWalletDatabase("", options, status, error); auto database = MakeWalletDatabase("", options, status, error);
auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings); auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
NotifyWalletLoaded(context, wallet); NotifyWalletLoaded(context, wallet);
if (context.chain) {
wallet->postInitProcess();
}
return wallet; return wallet;
} }
@ -765,6 +762,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
// being blocked // being blocked
wallet = TestLoadWallet(context); wallet = TestLoadWallet(context);
BOOST_CHECK(rescan_completed); BOOST_CHECK(rescan_completed);
// AddToWallet events for block_tx and mempool_tx
BOOST_CHECK_EQUAL(addtx_count, 2); BOOST_CHECK_EQUAL(addtx_count, 2);
{ {
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
@ -777,6 +775,8 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
// transactionAddedToMempool events are processed // transactionAddedToMempool events are processed
promise.set_value(); promise.set_value();
SyncWithValidationInterfaceQueue(); SyncWithValidationInterfaceQueue();
// AddToWallet events for block_tx and mempool_tx events are counted a
// second time as the notificaiton queue is processed
BOOST_CHECK_EQUAL(addtx_count, 4); BOOST_CHECK_EQUAL(addtx_count, 4);
@ -800,7 +800,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
SyncWithValidationInterfaceQueue(); SyncWithValidationInterfaceQueue();
}); });
wallet = TestLoadWallet(context); wallet = TestLoadWallet(context);
BOOST_CHECK_EQUAL(addtx_count, 4); BOOST_CHECK_EQUAL(addtx_count, 2);
{ {
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U); BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U);

View file

@ -1687,7 +1687,8 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
/** /**
* Scan the block chain (starting in start_block) for transactions * Scan the block chain (starting in start_block) for transactions
* from or to us. If fUpdate is true, found transactions that already * from or to us. If fUpdate is true, found transactions that already
* exist in the wallet will be updated. * exist in the wallet will be updated. If max_height is not set, the
* mempool will be scanned as well.
* *
* @param[in] start_block Scan starting block. If block is not on the active * @param[in] start_block Scan starting block. If block is not on the active
* chain, the scan will return SUCCESS immediately. * chain, the scan will return SUCCESS immediately.
@ -1797,6 +1798,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
} }
} }
} }
if (!max_height) {
WalletLogPrintf("Scanning current mempool transactions.\n");
WITH_LOCK(cs_wallet, chain().requestMempoolTransactions(*this));
}
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 100); // hide progress dialog in GUI ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 100); // hide progress dialog in GUI
if (block_height && fAbortRescan) { if (block_height && fAbortRescan) {
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current); WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current);

View file

@ -480,7 +480,9 @@ class ImportDescriptorsTest(BitcoinTestFramework):
addr = wmulti_pub.getnewaddress('', 'bech32') addr = wmulti_pub.getnewaddress('', 'bech32')
assert_equal(addr, 'bcrt1qp8s25ckjl7gr6x2q3dx3tn2pytwp05upkjztk6ey857tt50r5aeqn6mvr9') # Derived at m/84'/0'/0'/1 assert_equal(addr, 'bcrt1qp8s25ckjl7gr6x2q3dx3tn2pytwp05upkjztk6ey857tt50r5aeqn6mvr9') # Derived at m/84'/0'/0'/1
change_addr = wmulti_pub.getrawchangeaddress('bech32') change_addr = wmulti_pub.getrawchangeaddress('bech32')
assert_equal(change_addr, 'bcrt1qt9uhe3a9hnq7vajl7a094z4s3crm9ttf8zw3f5v9gr2nyd7e3lnsy44n8e') assert_equal(change_addr, 'bcrt1qzxl0qz2t88kljdnkzg4n4gapr6kte26390gttrg79x66nt4p04fssj53nl')
assert(send_txid in self.nodes[0].getrawmempool(True))
assert(send_txid in (x['txid'] for x in wmulti_pub.listunspent(0)))
assert_equal(wmulti_pub.getwalletinfo()['keypoolsize'], 999) assert_equal(wmulti_pub.getwalletinfo()['keypoolsize'], 999)
# generate some utxos for next tests # generate some utxos for next tests