aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db.h12
-rw-r--r--init.cpp13
-rw-r--r--main.cpp9
3 files changed, 33 insertions, 1 deletions
diff --git a/db.h b/db.h
index c9c40d58c6..290981c06a 100644
--- a/db.h
+++ b/db.h
@@ -13,6 +13,7 @@ class CAddress;
class CWalletTx;
class CAccount;
class CAccountingEntry;
+class CBlockLocator;
extern map<string, string> mapAddressBook;
extern CCriticalSection cs_mapAddressBook;
@@ -405,6 +406,17 @@ public:
return Write(make_pair(string("key"), vchPubKey), vchPrivKey, false);
}
+ bool WriteBestBlock(const CBlockLocator& locator)
+ {
+ nWalletDBUpdated++;
+ return Write(string("bestblock"), locator);
+ }
+
+ bool ReadBestBlock(CBlockLocator& locator)
+ {
+ return Read(string("bestblock"), locator);
+ }
+
bool ReadDefaultKey(vector<unsigned char>& vchPubKey)
{
vchPubKey.clear();
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);
}
diff --git a/main.cpp b/main.cpp
index 67db0bce88..1b15d7e07e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1611,6 +1611,15 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
}
}
+ // Update best block in wallet (so we can detect restored wallets)
+ if (!IsInitialBlockDownload())
+ {
+ CWalletDB walletdb;
+ const CBlockLocator locator(pindexNew);
+ if (!walletdb.WriteBestBlock(locator))
+ return error("SetBestChain() : WriteWalletBest failed");
+ }
+
// New best block
hashBestChain = hash;
pindexBest = pindexNew;