mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-12 05:31:14 +00:00
Fixed Initial Block Download issue with RandomKeva.
This commit is contained in:
parent
e2415c2c17
commit
e55c1ef81e
@ -33,6 +33,12 @@ static const int CONTINUE_EXECUTION=-1;
|
||||
|
||||
// To fix the chainActive not defined error.
|
||||
CChain chainActive;
|
||||
struct BlockHasher
|
||||
{
|
||||
size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
|
||||
};
|
||||
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||
BlockMap mapBlockIndex;
|
||||
|
||||
//
|
||||
// This function returns either one of EXIT_ codes when it's expected to stop the process or
|
||||
|
@ -43,6 +43,24 @@ unsigned get_max_concurrency()
|
||||
static uint256 cn_get_block_hash_by_height(uint64_t seed_height, char cnHash[32])
|
||||
{
|
||||
CBlockIndex* pblockindex = chainActive[seed_height];
|
||||
if (pblockindex == NULL) {
|
||||
// This will only happens during initial block download.
|
||||
static std::map<uint64_t, CBlockIndex*> mapBlockHeight;
|
||||
std::map<uint64_t, CBlockIndex*>::iterator iter = mapBlockHeight.find(seed_height);
|
||||
if (iter != mapBlockHeight.end()) {
|
||||
pblockindex = iter->second;
|
||||
} else {
|
||||
for (const std::pair<uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
CBlockIndex* pindex = item.second;
|
||||
if (pindex->nNonce == seed_height) {
|
||||
pblockindex = pindex;
|
||||
mapBlockHeight.insert(std::make_pair(seed_height, pindex));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uint256 blockHash = pblockindex->GetBlockHash();
|
||||
const unsigned char* pHash = blockHash.begin();
|
||||
for (int j = 31; j >= 0; j--) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user