Skip to content

Commit 1469533

Browse files
authored
Update txdb-leveldb.cpp
update, redo, and fixes
1 parent 19061a8 commit 1469533

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

src/txdb-leveldb.cpp

+30-25
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
// Distributed under the MIT/X11 software license, see the accompanying
66
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
77

8+
89
#include <map>
910

1011
#include <boost/version.hpp>
1112
#include <boost/filesystem.hpp>
1213
#include <boost/filesystem/fstream.hpp>
1314

14-
#include <leveldb/include/leveldb/env.h>
15-
#include <leveldb/include/leveldb/cache.h>
16-
#include <leveldb/include/leveldb/slice.h>
17-
#include <leveldb/include/leveldb/filter_policy.h>
18-
#include <leveldb/helpers/memenv/memenv.h>
19-
2015
#include "kernel.h"
2116
#include "checkpoints.h"
2217
#include "txdb.h"
@@ -25,6 +20,12 @@
2520
#include "main.h"
2621
#include "chainparams.h"
2722

23+
#include <leveldb/include/leveldb/env.h>
24+
#include <leveldb/include/leveldb/cache.h>
25+
#include <leveldb/include/leveldb/slice.h>
26+
#include <leveldb/include/leveldb/filter_policy.h>
27+
#include <memenv/memenv.h>
28+
2829
using namespace std;
2930
using namespace boost;
3031

@@ -40,27 +41,27 @@ static leveldb::Options GetOptions() {
4041

4142
void init_blockindex(leveldb::Options& options, bool fRemoveOld = false) {
4243
// First time init.
43-
boost::filesystem::path directory = GetDataDir() / "txleveldb";
44+
filesystem::path directory = GetDataDir() / "txleveldb";
4445

4546
if (fRemoveOld) {
46-
boost::filesystem::remove_all(directory); // remove directory
47+
filesystem::remove_all(directory); // remove directory
4748
unsigned int nFile = 1;
4849

4950
while (true)
5051
{
51-
boost::filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile);
52+
filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile);
5253

5354
// Break if no such file
54-
if( !boost::filesystem::exists( strBlockFile ) )
55+
if( !filesystem::exists( strBlockFile ) )
5556
break;
5657

57-
boost::filesystem::remove(strBlockFile);
58+
filesystem::remove(strBlockFile);
5859

5960
nFile++;
6061
}
6162
}
6263

63-
boost::filesystem::create_directory(directory);
64+
filesystem::create_directory(directory);
6465
LogPrintf("Opening LevelDB in %s\n", directory.string());
6566
leveldb::Status status = leveldb::DB::Open(options, directory.string(), &txdb);
6667
if (!status.ok()) {
@@ -385,7 +386,7 @@ bool CTxDB::LoadBlockIndex()
385386
return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight);
386387
}
387388

388-
// LiteDogecoin: build setStakeSeen
389+
// NovaCoin: build setStakeSeen
389390
if (pindexNew->IsProofOfStake())
390391
setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));
391392

@@ -408,6 +409,10 @@ bool CTxDB::LoadBlockIndex()
408409
{
409410
CBlockIndex* pindex = item.second;
410411
pindex->nChainTrust = (pindex->pprev ? pindex->pprev->nChainTrust : 0) + pindex->GetBlockTrust();
412+
// NovaCoin: calculate stake modifier checksum
413+
pindex->nStakeModifierChecksum = GetStakeModifierChecksum(pindex);
414+
if (!CheckStakeModifierCheckpoints(pindex->nHeight, pindex->nStakeModifierChecksum))
415+
return error("CTxDB::LoadBlockIndex() : Failed stake modifier checkpoint height=%d, modifier=0x%016" PRIx64, pindex->nHeight, pindex->nStakeModifier);
411416
}
412417

413418
// Load hashBestChain pointer to end of best chain
@@ -427,7 +432,7 @@ bool CTxDB::LoadBlockIndex()
427432
hashBestChain.ToString(), nBestHeight, CBigNum(nBestChainTrust).ToString(),
428433
DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime()));
429434

430-
// LiteDogecoin: load hashSyncCheckpoint
435+
// NovaCoin: load hashSyncCheckpoint
431436
if (!ReadSyncCheckpoint(Checkpoints::hashSyncCheckpoint))
432437
return error("CTxDB::LoadBlockIndex() : hashSyncCheckpoint not loaded");
433438
LogPrintf("LoadBlockIndex(): synchronized checkpoint %s\n", Checkpoints::hashSyncCheckpoint.ToString());
@@ -439,7 +444,7 @@ bool CTxDB::LoadBlockIndex()
439444

440445
// Verify blocks in the best chain
441446
int nCheckLevel = GetArg("-checklevel", 1);
442-
int nCheckDepth = GetArg( "-checkblocks", 500);
447+
int nCheckDepth = GetArg( "-checkblocks", 2500);
443448
if (nCheckDepth == 0)
444449
nCheckDepth = 1000000000; // suffices until the year 19000
445450
if (nCheckDepth > nBestHeight)
@@ -450,7 +455,7 @@ bool CTxDB::LoadBlockIndex()
450455
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
451456
{
452457
boost::this_thread::interruption_point();
453-
if (pindex->nHeight < nBestHeight-nCheckDepth)
458+
if (fRequestShutdown || pindex->nHeight < nBestHeight-nCheckDepth)
454459
break;
455460
CBlock block;
456461
if (!block.ReadFromDisk(pindex))
@@ -459,7 +464,7 @@ bool CTxDB::LoadBlockIndex()
459464
// check level 7: verify block signature too
460465
if (nCheckLevel>0 && !block.CheckBlock(true, true, (nCheckLevel>6)))
461466
{
462-
LogPrintf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
467+
LogPrintf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
463468
pindexFork = pindex->pprev;
464469
}
465470
// check level 2: verify transaction index validity
@@ -480,13 +485,13 @@ bool CTxDB::LoadBlockIndex()
480485
CTransaction txFound;
481486
if (!txFound.ReadFromDisk(txindex.pos))
482487
{
483-
LogPrintf("LoadBlockIndex() : *** cannot read mislocated transaction %s\n", hashTx.ToString());
488+
LogPrintf("LoadBlockIndex() : *** cannot read mislocated transaction %s\n", hashTx.ToString().c_str());
484489
pindexFork = pindex->pprev;
485490
}
486491
else
487492
if (txFound.GetHash() != hashTx) // not a duplicate tx
488493
{
489-
LogPrintf("LoadBlockIndex(): *** invalid tx position for %s\n", hashTx.ToString());
494+
LogPrintf("LoadBlockIndex(): *** invalid tx position for %s\n", hashTx.ToString().c_str());
490495
pindexFork = pindex->pprev;
491496
}
492497
}
@@ -501,7 +506,7 @@ bool CTxDB::LoadBlockIndex()
501506
pair<unsigned int, unsigned int> posFind = make_pair(txpos.nFile, txpos.nBlockPos);
502507
if (!mapBlockPos.count(posFind))
503508
{
504-
LogPrintf("LoadBlockIndex(): *** found bad spend at %d, hashBlock=%s, hashTx=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString(), hashTx.ToString());
509+
LogPrintf("LoadBlockIndex(): *** found bad spend at %d, hashBlock=%s, hashTx=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str(), hashTx.ToString().c_str());
505510
pindexFork = pindex->pprev;
506511
}
507512
// check level 6: check whether spent txouts were spent by a valid transaction that consume them
@@ -510,12 +515,12 @@ bool CTxDB::LoadBlockIndex()
510515
CTransaction txSpend;
511516
if (!txSpend.ReadFromDisk(txpos))
512517
{
513-
LogPrintf("LoadBlockIndex(): *** cannot read spending transaction of %s:%i from disk\n", hashTx.ToString(), nOutput);
518+
LogPrintf("LoadBlockIndex(): *** cannot read spending transaction of %s:%i from disk\n", hashTx.ToString().c_str(), nOutput);
514519
pindexFork = pindex->pprev;
515520
}
516521
else if (!txSpend.CheckTransaction())
517522
{
518-
LogPrintf("LoadBlockIndex(): *** spending transaction of %s:%i is invalid\n", hashTx.ToString(), nOutput);
523+
LogPrintf("LoadBlockIndex(): *** spending transaction of %s:%i is invalid\n", hashTx.ToString().c_str(), nOutput);
519524
pindexFork = pindex->pprev;
520525
}
521526
else
@@ -526,7 +531,7 @@ bool CTxDB::LoadBlockIndex()
526531
fFound = true;
527532
if (!fFound)
528533
{
529-
LogPrintf("LoadBlockIndex(): *** spending transaction of %s:%i does not spend it\n", hashTx.ToString(), nOutput);
534+
LogPrintf("LoadBlockIndex(): *** spending transaction of %s:%i does not spend it\n", hashTx.ToString().c_str(), nOutput);
530535
pindexFork = pindex->pprev;
531536
}
532537
}
@@ -545,15 +550,15 @@ bool CTxDB::LoadBlockIndex()
545550
if (ReadTxIndex(txin.prevout.hash, txindex))
546551
if (txindex.vSpent.size()-1 < txin.prevout.n || txindex.vSpent[txin.prevout.n].IsNull())
547552
{
548-
LogPrintf("LoadBlockIndex(): *** found unspent prevout %s:%i in %s\n", txin.prevout.hash.ToString(), txin.prevout.n, hashTx.ToString());
553+
LogPrintf("LoadBlockIndex(): *** found unspent prevout %s:%i in %s\n", txin.prevout.hash.ToString().c_str(), txin.prevout.n, hashTx.ToString().c_str());
549554
pindexFork = pindex->pprev;
550555
}
551556
}
552557
}
553558
}
554559
}
555560
}
556-
if (pindexFork)
561+
if (pindexFork && !fRequestShutdown)
557562
{
558563
boost::this_thread::interruption_point();
559564
// Reorg back to the fork

0 commit comments

Comments
 (0)