From 482c3933ad8f3c27398f0c3ba3f175246bd190b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Oct 2016 13:17:40 -0300 Subject: [PATCH] test --- src/komodo.h | 6 +----- src/main.cpp | 22 +++++++++++----------- src/main.h | 4 ++-- src/rest.cpp | 2 +- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- src/wallet/wallet.cpp | 6 +++--- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f40bb3d0b..123c5eea6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -30,12 +30,8 @@ int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp) CBlock block; int32_t height; char *coinbasestr; if ( pindex == 0 ) return(0); - block.SetNull(); - CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); - if ( filein.IsNull() ) + if ( ReadBlockFromDisk(block,pindex,1) == 0 ) return(0); - try { filein >> block; } - catch (const std::exception& e) { return(0); } if ( block.vtx.size() > 0 ) { height = pindex->nHeight; diff --git a/src/main.cpp b/src/main.cpp index 6c4035009..31e161e28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1323,9 +1323,9 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M return true; } -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos) +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,int32_t skipkomodo) { - int32_t retval; uint32_t nBits; + int32_t retval=0; uint32_t nBits; block.SetNull(); // Open history file to read @@ -1343,7 +1343,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos) // Check the header nBits = block.nBits; - if ( (retval= komodo_blockcheck(block,&nBits)) == 0 ) + if ( skipkomodo != 0 || (retval= komodo_blockcheck(block,&nBits)) == 0 ) { if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(block.GetHash(), nBits, Params().GetConsensus()))) return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); @@ -1353,9 +1353,9 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos) return true; } -bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) +bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,int32_t skipkomodo) { - if (!ReadBlockFromDisk(block, pindex->GetBlockPos())) + if (!ReadBlockFromDisk(block, pindex->GetBlockPos(),skipkomodo)) return false; if (block.GetHash() != pindex->GetBlockHash()) return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", @@ -2392,7 +2392,7 @@ bool static DisconnectTip(CValidationState &state) { mempool.check(pcoinsTip); // Read block from disk. CBlock block; - if (!ReadBlockFromDisk(block, pindexDelete)) + if (!ReadBlockFromDisk(block, pindexDelete,0)) return AbortNode(state, "Failed to read block"); // Apply the block atomically to the chain state. uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor(); @@ -2455,7 +2455,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * int64_t nTime1 = GetTimeMicros(); CBlock block; if (!pblock) { - if (!ReadBlockFromDisk(block, pindexNew)) + if (!ReadBlockFromDisk(block, pindexNew,0)) return AbortNode(state, "Failed to read block"); pblock = █ } @@ -3594,7 +3594,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth break; CBlock block; // check level 0: read from disk - if (!ReadBlockFromDisk(block, pindex)) + if (!ReadBlockFromDisk(block, pindex,0)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity if (nCheckLevel >= 1 && !CheckBlock(block, state)) @@ -3634,7 +3634,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50)))); pindex = chainActive.Next(pindex); CBlock block; - if (!ReadBlockFromDisk(block, pindex)) + if (!ReadBlockFromDisk(block, pindex,0)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); if (!ConnectBlock(block, state, pindex, coins)) return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); @@ -3807,7 +3807,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) std::pair::iterator, std::multimap::iterator> range = mapBlocksUnknownParent.equal_range(head); while (range.first != range.second) { std::multimap::iterator it = range.first; - if (ReadBlockFromDisk(block, it->second)) + if (ReadBlockFromDisk(block, it->second,0)) { LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(), head.ToString()); @@ -4166,7 +4166,7 @@ void static ProcessGetData(CNode* pfrom) { // Send block from disk CBlock block; - if (!ReadBlockFromDisk(block, (*mi).second)) + if (!ReadBlockFromDisk(block, (*mi).second,0)) assert(!"cannot load block from disk"); if (inv.type == MSG_BLOCK) pfrom->PushMessage("block", block); diff --git a/src/main.h b/src/main.h index aec92435c..0b8d71db0 100644 --- a/src/main.h +++ b/src/main.h @@ -393,8 +393,8 @@ public: /** Functions for disk access for blocks */ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart); -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos); -bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,int32_t skipkomodo); +bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,int32_t skipkomodo); /** Functions for validating blocks and updating the block tree */ diff --git a/src/rest.cpp b/src/rest.cpp index 7c238d506..c21b48484 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -200,7 +200,7 @@ static bool rest_block(AcceptedConnection* conn, if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) throw RESTERR(HTTP_NOT_FOUND, hashStr + " not available (pruned data)"); - if (!ReadBlockFromDisk(block, pblockindex)) + if (!ReadBlockFromDisk(block, pblockindex,0)) throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found"); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4c92979b2..7f7d21b78 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -326,7 +326,7 @@ Value getblock(const Array& params, bool fHelp) if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); - if(!ReadBlockFromDisk(block, pblockindex)) + if(!ReadBlockFromDisk(block, pblockindex,0)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); if (!fVerbose) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 5cca9df9d..2a767616d 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -303,7 +303,7 @@ Value gettxoutproof(const Array& params, bool fHelp) } CBlock block; - if(!ReadBlockFromDisk(block, pblockindex)) + if(!ReadBlockFromDisk(block, pblockindex,0)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); unsigned int ntxFound = 0; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1a865a966..239b8976c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -668,7 +668,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, const CBlock* pblock {pblockIn}; CBlock block; if (!pblock) { - ReadBlockFromDisk(block, pindex); + ReadBlockFromDisk(block, pindex,0); pblock = █ } @@ -1651,7 +1651,7 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, while (pindex) { CBlock block; - ReadBlockFromDisk(block, pindex); + ReadBlockFromDisk(block, pindex,0); BOOST_FOREACH(const CTransaction& tx, block.vtx) { @@ -1727,7 +1727,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100)))); CBlock block; - ReadBlockFromDisk(block, pindex); + ReadBlockFromDisk(block, pindex,0); BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))