Skip to content

Commit deaf48b

Browse files
committed
Handle TIMESTAMP_WINDOW within CWallet::RescanFromTime
This way CWallet::RescanFromTime callers don't need to subtract TIMESTAMP_WINDOW themselves. This is pure refactoring, there is no change in behavior.
1 parent 5b2be2b commit deaf48b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/wallet/rpcdump.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ UniValue importwallet(const JSONRPCRequest& request)
537537
file.close();
538538
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
539539
pwallet->UpdateTimeFirstKey(nTimeBegin);
540-
pwallet->RescanFromTime(nTimeBegin - TIMESTAMP_WINDOW, false /* update */);
540+
pwallet->RescanFromTime(nTimeBegin, false /* update */);
541541
pwallet->MarkDirty();
542542

543543
if (!fGood)
@@ -1113,10 +1113,10 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
11131113
}
11141114

11151115
if (fRescan && fRunScan && requests.size()) {
1116-
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp - TIMESTAMP_WINDOW, true /* update */);
1116+
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp, true /* update */);
11171117
pwallet->ReacceptWalletTransactions();
11181118

1119-
if (scannedTime > nLowestTimestamp - TIMESTAMP_WINDOW) {
1119+
if (scannedTime > nLowestTimestamp) {
11201120
std::vector<UniValue> results = response.getValues();
11211121
response.clear();
11221122
response.setArray();
@@ -1126,7 +1126,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
11261126
// range, or if the import result already has an error set, let
11271127
// the result stand unmodified. Otherwise replace the result
11281128
// with an error message.
1129-
if (scannedTime <= GetImportTimestamp(request, now) - TIMESTAMP_WINDOW || results.at(i).exists("error")) {
1129+
if (scannedTime <= GetImportTimestamp(request, now) || results.at(i).exists("error")) {
11301130
response.push_back(results.at(i));
11311131
} else {
11321132
UniValue result = UniValue(UniValue::VOBJ);
@@ -1142,7 +1142,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
11421142
"caused by pruning or data corruption (see bitcoind log for details) and could "
11431143
"be dealt with by downloading and rescanning the relevant blocks (see -reindex "
11441144
"and -rescan options).",
1145-
GetImportTimestamp(request, now), scannedTime - 1, TIMESTAMP_WINDOW)));
1145+
GetImportTimestamp(request, now), scannedTime - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)));
11461146
response.push_back(std::move(result));
11471147
}
11481148
++i;

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
14651465
/**
14661466
* Scan active chain for relevant transactions after importing keys. This should
14671467
* be called whenever new keys are added to the wallet, with the oldest key
1468-
* creation time minus TIMESTAMP_WINDOW.
1468+
* creation time.
14691469
*
14701470
* @return Earliest timestamp that could be successfully scanned from. Timestamp
14711471
* returned will be higher than startTime if relevant blocks could not be read.
@@ -1478,13 +1478,13 @@ int64_t CWallet::RescanFromTime(int64_t startTime, bool update)
14781478
// Find starting block. May be null if nCreateTime is greater than the
14791479
// highest blockchain timestamp, in which case there is nothing that needs
14801480
// to be scanned.
1481-
CBlockIndex* const startBlock = chainActive.FindEarliestAtLeast(startTime);
1481+
CBlockIndex* const startBlock = chainActive.FindEarliestAtLeast(startTime - TIMESTAMP_WINDOW);
14821482
LogPrintf("%s: Rescanning last %i blocks\n", __func__, startBlock ? chainActive.Height() - startBlock->nHeight + 1 : 0);
14831483

14841484
if (startBlock) {
14851485
const CBlockIndex* const failedBlock = ScanForWalletTransactions(startBlock, update);
14861486
if (failedBlock) {
1487-
return failedBlock->GetBlockTimeMax() + 1;
1487+
return failedBlock->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1;
14881488
}
14891489
}
14901490
return startTime;

0 commit comments

Comments
 (0)