Browse Source

Populated mapBlockSeedHeight on startup.

keva-gui
Just Wonder 4 years ago
parent
commit
4eb132ad4d
  1. 6
      src/txdb.cpp
  2. 2
      src/txdb.h
  3. 15
      src/validation.cpp

6
src/txdb.cpp

@ -353,7 +353,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
return true; return true;
} }
bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex) bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&, int)> insertBlockIndex)
{ {
std::unique_ptr<CDBIterator> pcursor(NewIterator()); std::unique_ptr<CDBIterator> pcursor(NewIterator());
@ -367,8 +367,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
CDiskBlockIndex diskindex; CDiskBlockIndex diskindex;
if (pcursor->GetValue(diskindex)) { if (pcursor->GetValue(diskindex)) {
// Construct block index object // Construct block index object
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash()); CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash(), diskindex.nHeight);
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev); pindexNew->pprev = insertBlockIndex(diskindex.hashPrev, diskindex.nHeight - 1);
pindexNew->nHeight = diskindex.nHeight; pindexNew->nHeight = diskindex.nHeight;
pindexNew->nFile = diskindex.nFile; pindexNew->nFile = diskindex.nFile;
pindexNew->nDataPos = diskindex.nDataPos; pindexNew->nDataPos = diskindex.nDataPos;

2
src/txdb.h

@ -128,7 +128,7 @@ public:
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &vect); bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &vect);
bool WriteFlag(const std::string &name, bool fValue); bool WriteFlag(const std::string &name, bool fValue);
bool ReadFlag(const std::string &name, bool &fValue); bool ReadFlag(const std::string &name, bool &fValue);
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex); bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&, int)> insertBlockIndex);
}; };
#endif // BITCOIN_TXDB_H #endif // BITCOIN_TXDB_H

15
src/validation.cpp

@ -191,7 +191,7 @@ private:
CBlockIndex* AddToBlockIndex(const CBlockHeader& block); CBlockIndex* AddToBlockIndex(const CBlockHeader& block);
/** Create a new block index entry for a given block hash */ /** Create a new block index entry for a given block hash */
CBlockIndex * InsertBlockIndex(const uint256& hash); CBlockIndex * InsertBlockIndex(const uint256& hash, int nHeight);
void CheckBlockIndex(const Consensus::Params& consensusParams); void CheckBlockIndex(const Consensus::Params& consensusParams);
void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state); void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state);
@ -3759,7 +3759,7 @@ fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile); return GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile);
} }
CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash) CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash, int nHeight)
{ {
if (hash.IsNull()) if (hash.IsNull())
return nullptr; return nullptr;
@ -3771,6 +3771,13 @@ CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
// Create new // Create new
CBlockIndex* pindexNew = new CBlockIndex(); CBlockIndex* pindexNew = new CBlockIndex();
if (nHeight < 0) {
nHeight = 0;
}
pindexNew->nNonce = nHeight;
if (crypto::is_a_seed_height(nHeight)) {
mapBlockSeedHeight.insert(std::make_pair(nHeight, pindexNew));
}
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first; mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
pindexNew->phashBlock = &((*mi).first); pindexNew->phashBlock = &((*mi).first);
@ -3779,7 +3786,7 @@ CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree) bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlockTreeDB& blocktree)
{ {
if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash){ return this->InsertBlockIndex(hash); })) if (!blocktree.LoadBlockIndexGuts(consensus_params, [this](const uint256& hash, int nHeight){ return this->InsertBlockIndex(hash, nHeight); }))
return false; return false;
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
@ -4243,6 +4250,7 @@ void UnloadBlockIndex()
delete entry.second; delete entry.second;
} }
mapBlockIndex.clear(); mapBlockIndex.clear();
mapBlockSeedHeight.clear();
fHavePruned = false; fHavePruned = false;
g_chainstate.UnloadBlockIndex(); g_chainstate.UnloadBlockIndex();
@ -4791,5 +4799,6 @@ public:
for (; it1 != mapBlockIndex.end(); it1++) for (; it1 != mapBlockIndex.end(); it1++)
delete (*it1).second; delete (*it1).second;
mapBlockIndex.clear(); mapBlockIndex.clear();
mapBlockSeedHeight.clear();
} }
} instance_of_cmaincleanup; } instance_of_cmaincleanup;

Loading…
Cancel
Save