X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Ftxdb-leveldb.cpp;h=8f956fe16413c5c6f29a3414706fe2401265bf14;hb=HEAD;hp=494971c1a735b7b229d404be690f61bbbb802510;hpb=77a43545b4491b9703d803765da9059d2bdd5aaa;p=novacoin.git diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index 494971c..69a29b0 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -3,7 +3,10 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. -#include +#include "txdb-leveldb.h" +#include "kernel.h" +#include "checkpoints.h" +#include "main.h" #include #include @@ -14,20 +17,13 @@ #include #include -#include "kernel.h" -#include "checkpoints.h" -#include "txdb.h" -#include "util.h" -#include "main.h" - using namespace std; -using namespace boost; leveldb::DB *txdb; // global pointer for LevelDB object instance static leveldb::Options GetOptions() { leveldb::Options options; - int nCacheSizeMB = GetArg("-dbcache", 25); + int nCacheSizeMB = GetArgInt("-dbcache", 25); options.block_cache = leveldb::NewLRUCache(nCacheSizeMB * 1048576); options.filter_policy = leveldb::NewBloomFilterPolicy(10); return options; @@ -35,27 +31,27 @@ static leveldb::Options GetOptions() { void init_blockindex(leveldb::Options& options, bool fRemoveOld = false) { // First time init. - filesystem::path directory = GetDataDir() / "txleveldb"; + boost::filesystem::path directory = GetDataDir() / "txleveldb"; if (fRemoveOld) { - filesystem::remove_all(directory); // remove directory + boost::filesystem::remove_all(directory); // remove directory unsigned int nFile = 1; - while (true) + for ( ; ; ) { - filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile); + boost::filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile); // Break if no such file - if( !filesystem::exists( strBlockFile ) ) + if( !boost::filesystem::exists( strBlockFile ) ) break; - filesystem::remove(strBlockFile); + boost::filesystem::remove(strBlockFile); nFile++; } } - filesystem::create_directory(directory); + boost::filesystem::create_directory(directory); printf("Opening LevelDB in %s\n", directory.string().c_str()); leveldb::Status status = leveldb::DB::Open(options, directory.string(), &txdb); if (!status.ok()) { @@ -64,7 +60,7 @@ void init_blockindex(leveldb::Options& options, bool fRemoveOld = false) { } // CDB subclasses are created and destroyed VERY OFTEN. That's why -// we shouldn't treat this as a free operations. +// we shouldn't treat this as free operations. CTxDB::CTxDB(const char* pszMode) { assert(pszMode); @@ -95,10 +91,10 @@ CTxDB::CTxDB(const char* pszMode) printf("Required index version is %d, removing old database\n", DATABASE_VERSION); // Leveldb instance destruction - delete txdb; - txdb = pdb = NULL; delete activeBatch; activeBatch = NULL; + delete txdb; + txdb = pdb = NULL; init_blockindex(options, true); // Remove directory and create new database pdb = txdb; @@ -325,7 +321,7 @@ static CBlockIndex *InsertBlockIndex(uint256 hash) return (*mi).second; // Create new - CBlockIndex* pindexNew = new CBlockIndex(); + CBlockIndex* pindexNew = new(nothrow) CBlockIndex(); if (!pindexNew) throw runtime_error("LoadBlockIndex() : new CBlockIndex failed"); mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; @@ -410,13 +406,13 @@ bool CTxDB::LoadBlockIndex() // Calculate nChainTrust vector > vSortedByHeight; vSortedByHeight.reserve(mapBlockIndex.size()); - BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) + for (const auto& item : mapBlockIndex) { CBlockIndex* pindex = item.second; vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex)); } sort(vSortedByHeight.begin(), vSortedByHeight.end()); - BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight) + for (const auto& item : vSortedByHeight) { CBlockIndex* pindex = item.second; pindex->nChainTrust = (pindex->pprev ? pindex->pprev->nChainTrust : 0) + pindex->GetBlockTrust(); @@ -454,8 +450,8 @@ bool CTxDB::LoadBlockIndex() nBestInvalidTrust = bnBestInvalidTrust.getuint256(); // Verify blocks in the best chain - int nCheckLevel = GetArg("-checklevel", 1); - int nCheckDepth = GetArg( "-checkblocks", 2500); + int nCheckLevel = GetArgInt("-checklevel", 1); + int nCheckDepth = GetArgInt( "-checkblocks", 2500); if (nCheckDepth == 0) nCheckDepth = 1000000000; // suffices until the year 19000 if (nCheckDepth > nBestHeight) @@ -482,7 +478,7 @@ bool CTxDB::LoadBlockIndex() { pair pos = make_pair(pindex->nFile, pindex->nBlockPos); mapBlockPos[pos] = pindex; - BOOST_FOREACH(const CTransaction &tx, block.vtx) + for (const CTransaction &tx : block.vtx) { uint256 hashTx = tx.GetHash(); CTxIndex txindex; @@ -509,7 +505,7 @@ bool CTxDB::LoadBlockIndex() unsigned int nOutput = 0; if (nCheckLevel>3) { - BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent) + for (const CDiskTxPos &txpos : txindex.vSpent) { if (!txpos.IsNull()) { @@ -536,7 +532,7 @@ bool CTxDB::LoadBlockIndex() else { bool fFound = false; - BOOST_FOREACH(const CTxIn &txin, txSpend.vin) + for (const CTxIn &txin : txSpend.vin) if (txin.prevout.hash == hashTx && txin.prevout.n == nOutput) fFound = true; if (!fFound) @@ -554,7 +550,7 @@ bool CTxDB::LoadBlockIndex() // check level 5: check whether all prevouts are marked spent if (nCheckLevel>4) { - BOOST_FOREACH(const CTxIn &txin, tx.vin) + for (const CTxIn &txin : tx.vin) { CTxIndex txindex; if (ReadTxIndex(txin.prevout.hash, txindex))