|
|
@ -1680,6 +1680,7 @@ static int64_t nTimeTotal = 0; |
|
|
|
|
|
|
|
|
|
|
|
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) |
|
|
|
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const CChainParams& chainparams = Params(); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
// Check it again in case a previous version let a bad block in
|
|
|
|
// Check it again in case a previous version let a bad block in
|
|
|
|
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck)) |
|
|
|
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck)) |
|
|
@ -1691,7 +1692,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin |
|
|
|
|
|
|
|
|
|
|
|
// Special case for the genesis block, skipping connection of its transactions
|
|
|
|
// Special case for the genesis block, skipping connection of its transactions
|
|
|
|
// (its coinbase is unspendable)
|
|
|
|
// (its coinbase is unspendable)
|
|
|
|
if (block.GetHash() == Params().HashGenesisBlock()) { |
|
|
|
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) { |
|
|
|
if (!fJustCheck) |
|
|
|
if (!fJustCheck) |
|
|
|
view.SetBestBlock(pindex->GetBlockHash()); |
|
|
|
view.SetBestBlock(pindex->GetBlockHash()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -2541,8 +2542,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo |
|
|
|
|
|
|
|
|
|
|
|
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev) |
|
|
|
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex * const pindexPrev) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
if (hash == Params().HashGenesisBlock()) |
|
|
|
if (hash == consensusParams.hashGenesisBlock) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
assert(pindexPrev); |
|
|
|
assert(pindexPrev); |
|
|
@ -2612,6 +2614,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn |
|
|
|
|
|
|
|
|
|
|
|
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) |
|
|
|
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const CChainParams& chainparams = Params(); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
// Check for duplicate
|
|
|
|
// Check for duplicate
|
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
@ -2632,7 +2635,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc |
|
|
|
|
|
|
|
|
|
|
|
// Get prev block index
|
|
|
|
// Get prev block index
|
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
CBlockIndex* pindexPrev = NULL; |
|
|
|
if (hash != Params().HashGenesisBlock()) { |
|
|
|
if (hash != chainparams.GetConsensus().hashGenesisBlock) { |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
if (mi == mapBlockIndex.end()) |
|
|
|
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); |
|
|
|
return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); |
|
|
@ -3119,6 +3122,7 @@ bool InitBlockIndex() { |
|
|
|
|
|
|
|
|
|
|
|
bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const CChainParams& chainparams = Params(); |
|
|
|
// Map of disk positions for blocks with unknown parent (only used for reindex)
|
|
|
|
// Map of disk positions for blocks with unknown parent (only used for reindex)
|
|
|
|
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent; |
|
|
|
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent; |
|
|
|
int64_t nStart = GetTimeMillis(); |
|
|
|
int64_t nStart = GetTimeMillis(); |
|
|
@ -3164,7 +3168,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
|
|
|
|
|
|
|
|
// detect out of order blocks, and store them for later
|
|
|
|
// detect out of order blocks, and store them for later
|
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
uint256 hash = block.GetHash(); |
|
|
|
if (hash != Params().HashGenesisBlock() && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) { |
|
|
|
if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) { |
|
|
|
LogPrint("reindex", "%s: Out of order block %s, parent %s not known\n", __func__, hash.ToString(), |
|
|
|
LogPrint("reindex", "%s: Out of order block %s, parent %s not known\n", __func__, hash.ToString(), |
|
|
|
block.hashPrevBlock.ToString()); |
|
|
|
block.hashPrevBlock.ToString()); |
|
|
|
if (dbp) |
|
|
|
if (dbp) |
|
|
@ -3179,7 +3183,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
nLoaded++; |
|
|
|
nLoaded++; |
|
|
|
if (state.IsError()) |
|
|
|
if (state.IsError()) |
|
|
|
break; |
|
|
|
break; |
|
|
|
} else if (hash != Params().HashGenesisBlock() && mapBlockIndex[hash]->nHeight % 1000 == 0) { |
|
|
|
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) { |
|
|
|
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight); |
|
|
|
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3221,6 +3225,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
|
|
|
|
|
|
|
|
void static CheckBlockIndex() |
|
|
|
void static CheckBlockIndex() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
const Consensus::Params& consensusParams = Params().GetConsensus(); |
|
|
|
if (!fCheckBlockIndex) { |
|
|
|
if (!fCheckBlockIndex) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -3263,7 +3268,7 @@ void static CheckBlockIndex() |
|
|
|
// Begin: actual consistency checks.
|
|
|
|
// Begin: actual consistency checks.
|
|
|
|
if (pindex->pprev == NULL) { |
|
|
|
if (pindex->pprev == NULL) { |
|
|
|
// Genesis block checks.
|
|
|
|
// Genesis block checks.
|
|
|
|
assert(pindex->GetBlockHash() == Params().HashGenesisBlock()); // Genesis block's hash must match.
|
|
|
|
assert(pindex->GetBlockHash() == consensusParams.hashGenesisBlock); // Genesis block's hash must match.
|
|
|
|
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
|
|
|
|
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
|
|
|
|
} |
|
|
|
} |
|
|
|
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)
|
|
|
|
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)
|
|
|
|