Browse Source

Fixed Initial Block Download issue with RandomKeva.

idb-fix
Just Wonder 5 years ago
parent
commit
e55c1ef81e
  1. 6
      src/bitcoin-tx.cpp
  2. 18
      src/primitives/block.cpp

6
src/bitcoin-tx.cpp

@ -33,6 +33,12 @@ static const int CONTINUE_EXECUTION=-1;
// To fix the chainActive not defined error. // To fix the chainActive not defined error.
CChain chainActive; 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 // This function returns either one of EXIT_ codes when it's expected to stop the process or

18
src/primitives/block.cpp

@ -43,6 +43,24 @@ unsigned get_max_concurrency()
static uint256 cn_get_block_hash_by_height(uint64_t seed_height, char cnHash[32]) static uint256 cn_get_block_hash_by_height(uint64_t seed_height, char cnHash[32])
{ {
CBlockIndex* pblockindex = chainActive[seed_height]; 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(); uint256 blockHash = pblockindex->GetBlockHash();
const unsigned char* pHash = blockHash.begin(); const unsigned char* pHash = blockHash.begin();
for (int j = 31; j >= 0; j--) { for (int j = 31; j >= 0; j--) {

Loading…
Cancel
Save