diff options
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index 352e2a776e..03a699a69c 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -8,6 +8,7 @@ #include "base58.h" #include "coincontrol.h" #include "net.h" +#include "checkpoints.h" #include <boost/algorithm/string/replace.hpp> #include <openssl/rand.h> @@ -589,7 +590,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet) bool CWallet::AddToWalletIfInvolvingMe(const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate) { { - LOCK(cs_wallet); + AssertLockHeld(cs_wallet); bool fExisted = mapWallet.count(hash); if (fExisted && !fUpdate) return false; if (fExisted || IsMine(tx) || IsFromMe(tx)) @@ -606,9 +607,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const uint256 &hash, const CTransaction& void CWallet::SyncTransaction(const uint256 &hash, const CTransaction& tx, const CBlock* pblock) { - AddToWalletIfInvolvingMe(hash, tx, pblock, true); - - if (mapWallet.count(hash) == 0) + LOCK(cs_wallet); + if (!AddToWalletIfInvolvingMe(hash, tx, pblock, true)) return; // Not one of ours // If a transaction changes 'conflicted' state, that changes the balance @@ -831,18 +831,24 @@ bool CWalletTx::WriteToDisk() int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) { int ret = 0; + int64_t nNow = GetTime(); CBlockIndex* pindex = pindexStart; { LOCK(cs_wallet); + + // no need to read and scan block, if block was created before + // our wallet birthday (as adjusted for block time variability) + while (pindex && nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200))) + pindex = chainActive.Next(pindex); + + ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup + double dProgressStart = Checkpoints::GuessVerificationProgress(pindex, false); + double dProgressTip = Checkpoints::GuessVerificationProgress(chainActive.Tip(), false); while (pindex) { - // no need to read and scan block, if block was created before - // our wallet birthday (as adjusted for block time variability) - if (nTimeFirstKey && (pindex->nTime < (nTimeFirstKey - 7200))) { - pindex = chainActive.Next(pindex); - continue; - } + if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) + ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); CBlock block; ReadBlockFromDisk(block, pindex); @@ -852,7 +858,12 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ret++; } pindex = chainActive.Next(pindex); + if (GetTime() >= nNow + 60) { + nNow = GetTime(); + LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, Checkpoints::GuessVerificationProgress(pindex)); + } } + ShowProgress(_("Rescanning..."), 100); // hide progress dialog in GUI } return ret; } @@ -1488,6 +1499,8 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) return nLoadWalletRet; fFirstRunRet = !vchDefaultKey.IsValid(); + uiInterface.LoadWallet(this); + return DB_LOAD_OK; } |