Skip to content

Commit f916700

Browse files
committed
Merge #8445: Move CWallet::setKeyPool to private section of CWallet.
8680d3a Move wallet initialization logic from AppInit2 to CWallet::InitLoadWallet (Patrick Strateman) e86eb71 Move CWallet::setKeyPool to private section of CWallet (Patrick Strateman)
2 parents 9358893 + 8680d3a commit f916700

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

src/init.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14941494
//// debug print
14951495
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
14961496
LogPrintf("nBestHeight = %d\n", chainActive.Height());
1497-
#ifdef ENABLE_WALLET
1498-
LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0);
1499-
LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
1500-
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
1501-
#endif
1502-
15031497
if (GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
15041498
StartTorControl(threadGroup, scheduler);
15051499

@@ -1512,9 +1506,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
15121506

15131507
#ifdef ENABLE_WALLET
15141508
if (pwalletMain) {
1515-
// Add wallet transactions that aren't already in a block to mapTransactions
1516-
pwalletMain->ReacceptWalletTransactions();
1517-
15181509
// Run a thread to flush wallet periodically
15191510
threadGroup.create_thread(boost::bind(&ThreadFlushWalletDB, boost::ref(pwalletMain->strWalletFile)));
15201511
}

src/wallet/wallet.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,7 +3416,17 @@ bool CWallet::InitLoadWallet()
34163416
}
34173417
walletInstance->SetBroadcastTransactions(GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
34183418

3419+
{
3420+
LOCK(walletInstance->cs_wallet);
3421+
LogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());
3422+
LogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size());
3423+
LogPrintf("mapAddressBook.size() = %u\n", walletInstance->mapAddressBook.size());
3424+
}
3425+
// Add wallet transactions that aren't already in a block to mapTransactions
3426+
walletInstance->ReacceptWalletTransactions();
3427+
34193428
pwalletMain = walletInstance;
3429+
34203430
return true;
34213431
}
34223432

src/wallet/wallet.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
582582
CHDChain hdChain;
583583

584584
bool fFileBacked;
585+
586+
std::set<int64_t> setKeyPool;
585587
public:
586588
/*
587589
* Main wallet lock.
@@ -594,7 +596,18 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
594596

595597
std::string strWalletFile;
596598

597-
std::set<int64_t> setKeyPool;
599+
void LoadKeyPool(int nIndex, const CKeyPool &keypool)
600+
{
601+
setKeyPool.insert(nIndex);
602+
603+
// If no metadata exists yet, create a default with the pool key's
604+
// creation time. Note that this may be overwritten by actually
605+
// stored metadata for that key later, which is fine.
606+
CKeyID keyid = keypool.vchPubKey.GetID();
607+
if (mapKeyMetadata.count(keyid) == 0)
608+
mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
609+
}
610+
598611
std::map<CKeyID, CKeyMetadata> mapKeyMetadata;
599612

600613
typedef std::map<unsigned int, CMasterKey> MasterKeyMap;

src/wallet/walletdb.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
556556
ssKey >> nIndex;
557557
CKeyPool keypool;
558558
ssValue >> keypool;
559-
pwallet->setKeyPool.insert(nIndex);
560-
561-
// If no metadata exists yet, create a default with the pool key's
562-
// creation time. Note that this may be overwritten by actually
563-
// stored metadata for that key later, which is fine.
564-
CKeyID keyid = keypool.vchPubKey.GetID();
565-
if (pwallet->mapKeyMetadata.count(keyid) == 0)
566-
pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime);
559+
560+
pwallet->LoadKeyPool(nIndex, keypool);
567561
}
568562
else if (strType == "version")
569563
{

0 commit comments

Comments
 (0)