mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Moved CBlock::ReadFromDisk out of CBlock to functions ReadBlockFromDisk in main.h
This commit is contained in:
parent
226f821942
commit
7db120d531
@ -820,7 +820,7 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||
{
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
CBlock block;
|
||||
block.ReadFromDisk(pindex);
|
||||
ReadBlockFromDisk(block, pindex);
|
||||
block.BuildMerkleTree();
|
||||
block.print();
|
||||
printf("\n");
|
||||
|
28
src/main.cpp
28
src/main.cpp
@ -627,7 +627,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
|
||||
if (pcoinsTip->GetCoins(GetHash(), coins)) {
|
||||
CBlockIndex *pindex = FindBlockByHeight(coins.nHeight);
|
||||
if (pindex) {
|
||||
if (!blockTmp.ReadFromDisk(pindex))
|
||||
if (!ReadBlockFromDisk(blockTmp, pindex))
|
||||
return 0;
|
||||
pblock = &blockTmp;
|
||||
}
|
||||
@ -1114,7 +1114,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
|
||||
|
||||
if (pindexSlow) {
|
||||
CBlock block;
|
||||
if (block.ReadFromDisk(pindexSlow)) {
|
||||
if (ReadBlockFromDisk(block, pindexSlow)) {
|
||||
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
|
||||
if (tx.GetHash() == hash) {
|
||||
txOut = tx;
|
||||
@ -1172,12 +1172,12 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
|
||||
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;
|
||||
if (GetHash() != pindex->GetBlockHash())
|
||||
return error("CBlock::ReadFromDisk() : GetHash() doesn't match index");
|
||||
if (block.GetHash() != pindex->GetBlockHash())
|
||||
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*) : GetHash() doesn't match index");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1886,7 +1886,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
|
||||
vector<CTransaction> vResurrect;
|
||||
BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) {
|
||||
CBlock block;
|
||||
if (!block.ReadFromDisk(pindex))
|
||||
if (!ReadBlockFromDisk(block, pindex))
|
||||
return state.Abort(_("Failed to read block"));
|
||||
int64 nStart = GetTimeMicros();
|
||||
if (!block.DisconnectBlock(state, pindex, view))
|
||||
@ -1906,7 +1906,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
|
||||
vector<CTransaction> vDelete;
|
||||
BOOST_FOREACH(CBlockIndex *pindex, vConnect) {
|
||||
CBlock block;
|
||||
if (!block.ReadFromDisk(pindex))
|
||||
if (!ReadBlockFromDisk(block, pindex))
|
||||
return state.Abort(_("Failed to read block"));
|
||||
int64 nStart = GetTimeMicros();
|
||||
if (!block.ConnectBlock(state, pindex, view)) {
|
||||
@ -2736,8 +2736,8 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth)
|
||||
break;
|
||||
CBlock block;
|
||||
// check level 0: read from disk
|
||||
if (!block.ReadFromDisk(pindex))
|
||||
return error("VerifyDB() : *** block.ReadFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
|
||||
if (!ReadBlockFromDisk(block, pindex))
|
||||
return error("VerifyDB() : *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
|
||||
// check level 1: verify block validity
|
||||
if (nCheckLevel >= 1 && !block.CheckBlock(state))
|
||||
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();
|
||||
pindex = pindex->GetNextInMainChain();
|
||||
CBlock block;
|
||||
if (!block.ReadFromDisk(pindex))
|
||||
return error("VerifyDB() : *** block.ReadFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
|
||||
if (!ReadBlockFromDisk(block, pindex))
|
||||
return error("VerifyDB() : *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
|
||||
if (!block.ConnectBlock(state, pindex, coins))
|
||||
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
|
||||
CBlock block;
|
||||
block.ReadFromDisk(pindex);
|
||||
ReadBlockFromDisk(block, pindex);
|
||||
printf("%d (blk%05u.dat:0x%x) %s tx %"PRIszu"",
|
||||
pindex->nHeight,
|
||||
pindex->GetBlockPos().nFile, pindex->GetBlockPos().nPos,
|
||||
@ -3108,7 +3108,7 @@ void static ProcessGetData(CNode* pfrom)
|
||||
if (mi != mapBlockIndex.end())
|
||||
{
|
||||
CBlock block;
|
||||
block.ReadFromDisk((*mi).second);
|
||||
ReadBlockFromDisk(block, (*mi).second);
|
||||
if (inv.type == MSG_BLOCK)
|
||||
pfrom->PushMessage("block", block);
|
||||
else // MSG_FILTERED_BLOCK)
|
||||
|
54
src/main.h
54
src/main.h
@ -682,33 +682,6 @@ public:
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
bool ReadFromDisk(const CDiskBlockPos &pos)
|
||||
{
|
||||
SetNull();
|
||||
|
||||
// Open history file to read
|
||||
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
|
||||
if (!filein)
|
||||
return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
|
||||
|
||||
// Read block
|
||||
try {
|
||||
filein >> *this;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
// Check the header
|
||||
if (!CheckProofOfWork(GetHash(), nBits))
|
||||
return error("CBlock::ReadFromDisk() : errors in block header");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print() const
|
||||
{
|
||||
printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
|
||||
@ -739,9 +712,6 @@ public:
|
||||
// Apply the effects of this block (with given index) on the UTXO set represented by coins
|
||||
bool ConnectBlock(CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false);
|
||||
|
||||
// Read a block from disk
|
||||
bool ReadFromDisk(const CBlockIndex* pindex);
|
||||
|
||||
// Add this block to the block index, and if necessary, switch the active block chain to this
|
||||
bool AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos);
|
||||
|
||||
@ -756,7 +726,31 @@ public:
|
||||
|
||||
/** Functions for disk access for blocks */
|
||||
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos);
|
||||
inline bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
|
||||
{
|
||||
block.SetNull();
|
||||
|
||||
// Open history file to read
|
||||
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
|
||||
if (!filein)
|
||||
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : OpenBlockFile failed");
|
||||
|
||||
// Read block
|
||||
try {
|
||||
filein >> block;
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
// Check the header
|
||||
if (!CheckProofOfWork(block.GetHash(), block.nBits))
|
||||
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : errors in block header");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
|
||||
|
||||
|
||||
class CBlockFileInfo
|
||||
|
@ -163,7 +163,7 @@ Value getblock(const Array& params, bool fHelp)
|
||||
|
||||
CBlock block;
|
||||
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||
block.ReadFromDisk(pblockindex);
|
||||
ReadBlockFromDisk(block, pblockindex);
|
||||
|
||||
if (!fVerbose)
|
||||
{
|
||||
|
@ -804,7 +804,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||
}
|
||||
|
||||
CBlock block;
|
||||
block.ReadFromDisk(pindex);
|
||||
ReadBlockFromDisk(block, pindex);
|
||||
BOOST_FOREACH(CTransaction& tx, block.vtx)
|
||||
{
|
||||
if (AddToWalletIfInvolvingMe(tx.GetHash(), tx, &block, fUpdate))
|
||||
|
Loading…
Reference in New Issue
Block a user