aboutsummaryrefslogtreecommitdiff
path: root/init.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-04-13 16:16:30 +0200
committerGavin Andresen <gavinandresen@gmail.com>2011-04-18 17:37:47 -0400
commit6a76c60e6c4c21c6355c5580f9f770fcc9f978ef (patch)
treeba3522df13633aeedf795b1bf967aa4f627ab584 /init.cpp
parent657cfe721b21934349c26ce00aa18661404d46c5 (diff)
downloadbitcoin-6a76c60e6c4c21c6355c5580f9f770fcc9f978ef.tar.xz
Automatically rescan after restoring wallet.dat
Information about the best known chain is added to wallet.dat. If this information does not match the data in blkindex.dat, a rescan is automatically performed, starting from the the last known block. When upgrading from a wallet which does not have this information, no rescan is done automatically.
Diffstat (limited to 'init.cpp')
-rw-r--r--init.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/init.cpp b/init.cpp
index 68ed11f6b8..8f72181225 100644
--- a/init.cpp
+++ b/init.cpp
@@ -372,10 +372,21 @@ bool AppInit2(int argc, char* argv[])
strErrors += _("Error loading wallet.dat \n");
printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
+ CBlockIndex *pindexRescan = pindexBest;
if (GetBoolArg("-rescan"))
+ pindexRescan = pindexGenesisBlock;
+ else
+ {
+ CWalletDB walletdb;
+ CBlockLocator locator;
+ if (walletdb.ReadBestBlock(locator))
+ pindexRescan = locator.GetBlockIndex();
+ }
+ if (pindexBest != pindexRescan)
{
+ printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis();
- ScanForWalletTransactions(pindexGenesisBlock);
+ ScanForWalletTransactions(pindexRescan);
printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
}