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;
|
CBlockIndex* pindex = (*mi).second;
|
||||||
CBlock block;
|
CBlock block;
|
||||||
block.ReadFromDisk(pindex);
|
ReadBlockFromDisk(block, pindex);
|
||||||
block.BuildMerkleTree();
|
block.BuildMerkleTree();
|
||||||
block.print();
|
block.print();
|
||||||
printf("\n");
|
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)) {
|
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)
|
||||||
|
54
src/main.h
54
src/main.h
@ -682,33 +682,6 @@ public:
|
|||||||
return hash;
|
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
|
void print() const
|
||||||
{
|
{
|
||||||
printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
|
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
|
// 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);
|
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
|
// Add this block to the block index, and if necessary, switch the active block chain to this
|
||||||
bool AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos);
|
bool AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos);
|
||||||
|
|
||||||
@ -756,7 +726,31 @@ public:
|
|||||||
|
|
||||||
/** Functions for disk access for blocks */
|
/** Functions for disk access for blocks */
|
||||||
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos);
|
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
|
class CBlockFileInfo
|
||||||
|
@ -163,7 +163,7 @@ Value getblock(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
CBlock block;
|
CBlock block;
|
||||||
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||||
block.ReadFromDisk(pblockindex);
|
ReadBlockFromDisk(block, pblockindex);
|
||||||
|
|
||||||
if (!fVerbose)
|
if (!fVerbose)
|
||||||
{
|
{
|
||||||
|
@ -804,7 +804,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CBlock block;
|
CBlock block;
|
||||||
block.ReadFromDisk(pindex);
|
ReadBlockFromDisk(block, pindex);
|
||||||
BOOST_FOREACH(CTransaction& tx, block.vtx)
|
BOOST_FOREACH(CTransaction& tx, block.vtx)
|
||||||
{
|
{
|
||||||
if (AddToWalletIfInvolvingMe(tx.GetHash(), tx, &block, fUpdate))
|
if (AddToWalletIfInvolvingMe(tx.GetHash(), tx, &block, fUpdate))
|
||||||
|
Loading…
Reference in New Issue
Block a user