Skip to content

Commit 236239b

Browse files
committed
wallet: Rescan mempool for transactions as well
1 parent 37633d2 commit 236239b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
5555
auto database = MakeWalletDatabase("", options, status, error);
5656
auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
5757
NotifyWalletLoaded(context, wallet);
58-
if (context.chain) {
59-
wallet->postInitProcess();
60-
}
6158
return wallet;
6259
}
6360

@@ -765,6 +762,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
765762
// being blocked
766763
wallet = TestLoadWallet(context);
767764
BOOST_CHECK(rescan_completed);
765+
// AddToWallet events for block_tx and mempool_tx
768766
BOOST_CHECK_EQUAL(addtx_count, 2);
769767
{
770768
LOCK(wallet->cs_wallet);
@@ -777,6 +775,8 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
777775
// transactionAddedToMempool events are processed
778776
promise.set_value();
779777
SyncWithValidationInterfaceQueue();
778+
// AddToWallet events for block_tx and mempool_tx events are counted a
779+
// second time as the notificaiton queue is processed
780780
BOOST_CHECK_EQUAL(addtx_count, 4);
781781

782782

@@ -800,7 +800,7 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
800800
SyncWithValidationInterfaceQueue();
801801
});
802802
wallet = TestLoadWallet(context);
803-
BOOST_CHECK_EQUAL(addtx_count, 4);
803+
BOOST_CHECK_EQUAL(addtx_count, 2);
804804
{
805805
LOCK(wallet->cs_wallet);
806806
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U);

src/wallet/wallet.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,8 @@ int64_t CWallet::RescanFromTime(int64_t startTime, const WalletRescanReserver& r
16871687
/**
16881688
* Scan the block chain (starting in start_block) for transactions
16891689
* from or to us. If fUpdate is true, found transactions that already
1690-
* exist in the wallet will be updated.
1690+
* exist in the wallet will be updated. If max_height is not set, the
1691+
* mempool will be scanned as well.
16911692
*
16921693
* @param[in] start_block Scan starting block. If block is not on the active
16931694
* chain, the scan will return SUCCESS immediately.
@@ -1797,6 +1798,10 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
17971798
}
17981799
}
17991800
}
1801+
if (!max_height) {
1802+
WalletLogPrintf("Scanning current mempool transactions.\n");
1803+
WITH_LOCK(cs_wallet, chain().requestMempoolTransactions(*this));
1804+
}
18001805
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 100); // hide progress dialog in GUI
18011806
if (block_height && fAbortRescan) {
18021807
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current);

test/functional/wallet_importdescriptors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ def run_test(self):
480480
addr = wmulti_pub.getnewaddress('', 'bech32')
481481
assert_equal(addr, 'bcrt1qp8s25ckjl7gr6x2q3dx3tn2pytwp05upkjztk6ey857tt50r5aeqn6mvr9') # Derived at m/84'/0'/0'/1
482482
change_addr = wmulti_pub.getrawchangeaddress('bech32')
483-
assert_equal(change_addr, 'bcrt1qt9uhe3a9hnq7vajl7a094z4s3crm9ttf8zw3f5v9gr2nyd7e3lnsy44n8e')
483+
assert_equal(change_addr, 'bcrt1qzxl0qz2t88kljdnkzg4n4gapr6kte26390gttrg79x66nt4p04fssj53nl')
484+
assert(send_txid in self.nodes[0].getrawmempool(True))
485+
assert(send_txid in (x['txid'] for x in wmulti_pub.listunspent(0)))
484486
assert_equal(wmulti_pub.getwalletinfo()['keypoolsize'], 999)
485487

486488
# generate some utxos for next tests

0 commit comments

Comments
 (0)