Skip to content

Commit c91ca0a

Browse files
committed
Merge #9827: Improve ScanForWalletTransactions return value
30abce7 Improve ScanForWalletTransactions return value (Russell Yanofsky) Tree-SHA512: 195028553b103052a842b6a37e67410118a20c32475b80f7fd22d6d8622f92eca1c2d84f291d1092bef2161d3187d91052799b533e1e265b7613d51955490b8d
2 parents e96486c + 30abce7 commit c91ca0a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
424424
BOOST_CHECK_EQUAL(response.write(), strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Failed to rescan before time %d, transactions may be missing.\"}},{\"success\":true}]", newTip->GetBlockTimeMax()));
425425
::pwalletMain = backup;
426426
}
427+
428+
// Verify ScanForWalletTransactions does not return null when the scan is
429+
// elided due to the nTimeFirstKey optimization.
430+
{
431+
CWallet wallet;
432+
{
433+
LOCK(wallet.cs_wallet);
434+
wallet.UpdateTimeFirstKey(newTip->GetBlockTime() + 7200 + 1);
435+
}
436+
BOOST_CHECK_EQUAL(newTip, wallet.ScanForWalletTransactions(newTip));
437+
}
427438
}
428439

429440
// Check that GetImmatureCredit() returns a newly calculated value instead of

src/wallet/wallet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,16 +1515,17 @@ void CWalletTx::GetAccountAmounts(const std::string& strAccount, CAmount& nRecei
15151515
* exist in the wallet will be updated.
15161516
*
15171517
* Returns pointer to the first block in the last contiguous range that was
1518-
* successfully scanned.
1519-
*
1518+
* successfully scanned or elided (elided if pIndexStart points at a block
1519+
* before CWallet::nTimeFirstKey). Returns null if there is no such range, or
1520+
* the range doesn't include chainActive.Tip().
15201521
*/
15211522
CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
15221523
{
1523-
CBlockIndex* ret = nullptr;
15241524
int64_t nNow = GetTime();
15251525
const CChainParams& chainParams = Params();
15261526

15271527
CBlockIndex* pindex = pindexStart;
1528+
CBlockIndex* ret = pindexStart;
15281529
{
15291530
LOCK2(cs_main, cs_wallet);
15301531
fAbortRescan = false;

0 commit comments

Comments
 (0)