From 3869fb89b60091281b43a35921057ba3f43c18f0 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Mon, 10 Jun 2013 09:36:29 -0400 Subject: Wallet: store key creation time. Calculate whole-wallet birthday. This also encapsulate wallet-read state information into CWalletScanState. --- src/wallet.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/wallet.cpp') diff --git a/src/wallet.cpp b/src/wallet.cpp index 7041d49da..aa1371111 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -45,20 +45,33 @@ CPubKey CWallet::GenerateNewKey() return pubkey; } -bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey) +bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey, + int64 nCreateTime) { + if (!nCreateTime) + nCreateTime = GetTime(); + if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey)) + nTimeFirstKey = nCreateTime; if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) return false; if (!fFileBacked) return true; if (!IsCrypted()) { - return CWalletDB(strWalletFile).WriteKey(pubkey, secret.GetPrivKey()); + return CWalletDB(strWalletFile).WriteKey(pubkey, + secret.GetPrivKey(), + nCreateTime); } return true; } -bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector &vchCryptedSecret) +bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, + const vector &vchCryptedSecret, + int64 nCreateTime) { + if (!nCreateTime) + nCreateTime = GetTime(); + if (!nTimeFirstKey || (nCreateTime < nTimeFirstKey)) + nTimeFirstKey = nCreateTime; if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; if (!fFileBacked) @@ -66,9 +79,13 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vectorWriteCryptedKey(vchPubKey, vchCryptedSecret); + return pwalletdbEncryption->WriteCryptedKey(vchPubKey, + vchCryptedSecret, + nCreateTime); else - return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret); + return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, + vchCryptedSecret, + nCreateTime); } return false; } -- cgit v1.2.3 From 8da9dd0725ea90b1fd085d9551177fe62d7a9ba2 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Mon, 10 Jun 2013 09:38:13 -0400 Subject: Wallet: optimize rescan to skip blocks prior to birthday --- src/wallet.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/wallet.cpp') diff --git a/src/wallet.cpp b/src/wallet.cpp index aa1371111..9a4a92cd5 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -790,6 +790,13 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) LOCK(cs_wallet); 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 = pindex->GetNextInMainChain(); + continue; + } + CBlock block; block.ReadFromDisk(pindex); BOOST_FOREACH(CTransaction& tx, block.vtx) -- cgit v1.2.3