Skip to content

Commit 0de6544

Browse files
committed
[Init] Load block hashes cache at startup
1 parent 2237a69 commit 0de6544

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/init.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,19 @@ static std::string ResolveErrMsg(const char * const optname, const std::string&
942942
return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);
943943
}
944944

945+
// Sets the last CACHED_BLOCK_HASHES hashes into masternode manager cache
946+
static void LoadBlockHashesCache(CMasternodeMan& man)
947+
{
948+
LOCK(cs_main);
949+
const CBlockIndex* pindex = chainActive.Tip();
950+
unsigned int inserted = 0;
951+
while (pindex && inserted < CACHED_BLOCK_HASHES) {
952+
man.CacheBlockHash(pindex);
953+
pindex = pindex->pprev;
954+
++inserted;
955+
}
956+
}
957+
945958
void InitLogging()
946959
{
947960
//g_logger->m_print_to_file = !IsArgNegated("-debuglogfile");
@@ -1740,6 +1753,7 @@ bool AppInit2()
17401753
uiInterface.InitMessage(_("Loading masternode cache..."));
17411754

17421755
mnodeman.SetBestHeight(nChainHeight);
1756+
LoadBlockHashesCache(mnodeman);
17431757
CMasternodeDB mndb;
17441758
CMasternodeDB::ReadResult readResult = mndb.Read(mnodeman);
17451759
if (readResult == CMasternodeDB::FileError)

0 commit comments

Comments
 (0)