|
|
@ -627,7 +627,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock) |
|
|
|
if (pcoinsTip->GetCoins(GetHash(), coins)) { |
|
|
|
if (pcoinsTip->GetCoins(GetHash(), coins)) { |
|
|
|
CBlockIndex *pindex = FindBlockByHeight(coins.nHeight); |
|
|
|
CBlockIndex *pindex = FindBlockByHeight(coins.nHeight); |
|
|
|
if (pindex) { |
|
|
|
if (pindex) { |
|
|
|
if (!blockTmp.ReadFromDisk(pindex)) |
|
|
|
if (!ReadBlockFromDisk(blockTmp, pindex)) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
pblock = &blockTmp; |
|
|
|
pblock = &blockTmp; |
|
|
|
} |
|
|
|
} |
|
|
@ -1114,7 +1114,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock |
|
|
|
|
|
|
|
|
|
|
|
if (pindexSlow) { |
|
|
|
if (pindexSlow) { |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
if (block.ReadFromDisk(pindexSlow)) { |
|
|
|
if (ReadBlockFromDisk(block, pindexSlow)) { |
|
|
|
BOOST_FOREACH(const CTransaction &tx, block.vtx) { |
|
|
|
BOOST_FOREACH(const CTransaction &tx, block.vtx) { |
|
|
|
if (tx.GetHash() == hash) { |
|
|
|
if (tx.GetHash() == hash) { |
|
|
|
txOut = tx; |
|
|
|
txOut = tx; |
|
|
@ -1172,12 +1172,12 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CBlock::ReadFromDisk(const CBlockIndex* pindex) |
|
|
|
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!ReadFromDisk(pindex->GetBlockPos())) |
|
|
|
if (!ReadBlockFromDisk(block, pindex->GetBlockPos())) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
if (GetHash() != pindex->GetBlockHash()) |
|
|
|
if (block.GetHash() != pindex->GetBlockHash()) |
|
|
|
return error("CBlock::ReadFromDisk() : GetHash() doesn't match index"); |
|
|
|
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*) : GetHash() doesn't match index"); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1886,7 +1886,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) |
|
|
|
vector<CTransaction> vResurrect; |
|
|
|
vector<CTransaction> vResurrect; |
|
|
|
BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) { |
|
|
|
BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) { |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
if (!block.ReadFromDisk(pindex)) |
|
|
|
if (!ReadBlockFromDisk(block, pindex)) |
|
|
|
return state.Abort(_("Failed to read block")); |
|
|
|
return state.Abort(_("Failed to read block")); |
|
|
|
int64 nStart = GetTimeMicros(); |
|
|
|
int64 nStart = GetTimeMicros(); |
|
|
|
if (!block.DisconnectBlock(state, pindex, view)) |
|
|
|
if (!block.DisconnectBlock(state, pindex, view)) |
|
|
@ -1906,7 +1906,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) |
|
|
|
vector<CTransaction> vDelete; |
|
|
|
vector<CTransaction> vDelete; |
|
|
|
BOOST_FOREACH(CBlockIndex *pindex, vConnect) { |
|
|
|
BOOST_FOREACH(CBlockIndex *pindex, vConnect) { |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
if (!block.ReadFromDisk(pindex)) |
|
|
|
if (!ReadBlockFromDisk(block, pindex)) |
|
|
|
return state.Abort(_("Failed to read block")); |
|
|
|
return state.Abort(_("Failed to read block")); |
|
|
|
int64 nStart = GetTimeMicros(); |
|
|
|
int64 nStart = GetTimeMicros(); |
|
|
|
if (!block.ConnectBlock(state, pindex, view)) { |
|
|
|
if (!block.ConnectBlock(state, pindex, view)) { |
|
|
@ -2736,8 +2736,8 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) |
|
|
|
break; |
|
|
|
break; |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
// check level 0: read from disk
|
|
|
|
// check level 0: read from disk
|
|
|
|
if (!block.ReadFromDisk(pindex)) |
|
|
|
if (!ReadBlockFromDisk(block, pindex)) |
|
|
|
return error("VerifyDB() : *** block.ReadFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
return error("VerifyDB() : *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
// check level 1: verify block validity
|
|
|
|
// check level 1: verify block validity
|
|
|
|
if (nCheckLevel >= 1 && !block.CheckBlock(state)) |
|
|
|
if (nCheckLevel >= 1 && !block.CheckBlock(state)) |
|
|
|
return error("VerifyDB() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
return error("VerifyDB() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
@ -2773,8 +2773,8 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
pindex = pindex->GetNextInMainChain(); |
|
|
|
pindex = pindex->GetNextInMainChain(); |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
if (!block.ReadFromDisk(pindex)) |
|
|
|
if (!ReadBlockFromDisk(block, pindex)) |
|
|
|
return error("VerifyDB() : *** block.ReadFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
return error("VerifyDB() : *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
if (!block.ConnectBlock(state, pindex, coins)) |
|
|
|
if (!block.ConnectBlock(state, pindex, coins)) |
|
|
|
return error("VerifyDB() : *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
return error("VerifyDB() : *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
|
|
|
} |
|
|
|
} |
|
|
@ -2884,7 +2884,7 @@ void PrintBlockTree() |
|
|
|
|
|
|
|
|
|
|
|
// print item
|
|
|
|
// print item
|
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
block.ReadFromDisk(pindex); |
|
|
|
ReadBlockFromDisk(block, pindex); |
|
|
|
printf("%d (blk%05u.dat:0x%x) %s tx %"PRIszu"", |
|
|
|
printf("%d (blk%05u.dat:0x%x) %s tx %"PRIszu"", |
|
|
|
pindex->nHeight, |
|
|
|
pindex->nHeight, |
|
|
|
pindex->GetBlockPos().nFile, pindex->GetBlockPos().nPos, |
|
|
|
pindex->GetBlockPos().nFile, pindex->GetBlockPos().nPos, |
|
|
@ -3108,7 +3108,7 @@ void static ProcessGetData(CNode* pfrom) |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
if (mi != mapBlockIndex.end()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CBlock block; |
|
|
|
CBlock block; |
|
|
|
block.ReadFromDisk((*mi).second); |
|
|
|
ReadBlockFromDisk(block, (*mi).second); |
|
|
|
if (inv.type == MSG_BLOCK) |
|
|
|
if (inv.type == MSG_BLOCK) |
|
|
|
pfrom->PushMessage("block", block); |
|
|
|
pfrom->PushMessage("block", block); |
|
|
|
else // MSG_FILTERED_BLOCK)
|
|
|
|
else // MSG_FILTERED_BLOCK)
|
|
|
|