5
5
// Distributed under the MIT/X11 software license, see the accompanying
6
6
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
7
7
8
+
8
9
#include < map>
9
10
10
11
#include < boost/version.hpp>
11
12
#include < boost/filesystem.hpp>
12
13
#include < boost/filesystem/fstream.hpp>
13
14
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
-
20
15
#include " kernel.h"
21
16
#include " checkpoints.h"
22
17
#include " txdb.h"
25
20
#include " main.h"
26
21
#include " chainparams.h"
27
22
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
+
28
29
using namespace std ;
29
30
using namespace boost ;
30
31
@@ -40,27 +41,27 @@ static leveldb::Options GetOptions() {
40
41
41
42
void init_blockindex (leveldb::Options& options, bool fRemoveOld = false ) {
42
43
// First time init.
43
- boost:: filesystem::path directory = GetDataDir () / " txleveldb" ;
44
+ filesystem::path directory = GetDataDir () / " txleveldb" ;
44
45
45
46
if (fRemoveOld ) {
46
- boost:: filesystem::remove_all (directory); // remove directory
47
+ filesystem::remove_all (directory); // remove directory
47
48
unsigned int nFile = 1 ;
48
49
49
50
while (true )
50
51
{
51
- boost:: filesystem::path strBlockFile = GetDataDir () / strprintf (" blk%04u.dat" , nFile);
52
+ filesystem::path strBlockFile = GetDataDir () / strprintf (" blk%04u.dat" , nFile);
52
53
53
54
// Break if no such file
54
- if ( !boost:: filesystem::exists ( strBlockFile ) )
55
+ if ( !filesystem::exists ( strBlockFile ) )
55
56
break ;
56
57
57
- boost:: filesystem::remove (strBlockFile);
58
+ filesystem::remove (strBlockFile);
58
59
59
60
nFile++;
60
61
}
61
62
}
62
63
63
- boost:: filesystem::create_directory (directory);
64
+ filesystem::create_directory (directory);
64
65
LogPrintf (" Opening LevelDB in %s\n " , directory.string ());
65
66
leveldb::Status status = leveldb::DB::Open (options, directory.string (), &txdb);
66
67
if (!status.ok ()) {
@@ -385,7 +386,7 @@ bool CTxDB::LoadBlockIndex()
385
386
return error (" LoadBlockIndex() : CheckIndex failed at %d" , pindexNew->nHeight );
386
387
}
387
388
388
- // LiteDogecoin : build setStakeSeen
389
+ // NovaCoin : build setStakeSeen
389
390
if (pindexNew->IsProofOfStake ())
390
391
setStakeSeen.insert (make_pair (pindexNew->prevoutStake , pindexNew->nStakeTime ));
391
392
@@ -408,6 +409,10 @@ bool CTxDB::LoadBlockIndex()
408
409
{
409
410
CBlockIndex* pindex = item.second ;
410
411
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 );
411
416
}
412
417
413
418
// Load hashBestChain pointer to end of best chain
@@ -427,7 +432,7 @@ bool CTxDB::LoadBlockIndex()
427
432
hashBestChain.ToString (), nBestHeight, CBigNum (nBestChainTrust).ToString (),
428
433
DateTimeStrFormat (" %x %H:%M:%S" , pindexBest->GetBlockTime ()));
429
434
430
- // LiteDogecoin : load hashSyncCheckpoint
435
+ // NovaCoin : load hashSyncCheckpoint
431
436
if (!ReadSyncCheckpoint (Checkpoints::hashSyncCheckpoint))
432
437
return error (" CTxDB::LoadBlockIndex() : hashSyncCheckpoint not loaded" );
433
438
LogPrintf (" LoadBlockIndex(): synchronized checkpoint %s\n " , Checkpoints::hashSyncCheckpoint.ToString ());
@@ -439,7 +444,7 @@ bool CTxDB::LoadBlockIndex()
439
444
440
445
// Verify blocks in the best chain
441
446
int nCheckLevel = GetArg (" -checklevel" , 1 );
442
- int nCheckDepth = GetArg ( " -checkblocks" , 500 );
447
+ int nCheckDepth = GetArg ( " -checkblocks" , 2500 );
443
448
if (nCheckDepth == 0 )
444
449
nCheckDepth = 1000000000 ; // suffices until the year 19000
445
450
if (nCheckDepth > nBestHeight)
@@ -450,7 +455,7 @@ bool CTxDB::LoadBlockIndex()
450
455
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev ; pindex = pindex->pprev )
451
456
{
452
457
boost::this_thread::interruption_point ();
453
- if (pindex->nHeight < nBestHeight-nCheckDepth)
458
+ if (fRequestShutdown || pindex->nHeight < nBestHeight-nCheckDepth)
454
459
break ;
455
460
CBlock block;
456
461
if (!block.ReadFromDisk (pindex))
@@ -459,7 +464,7 @@ bool CTxDB::LoadBlockIndex()
459
464
// check level 7: verify block signature too
460
465
if (nCheckLevel>0 && !block.CheckBlock (true , true , (nCheckLevel>6 )))
461
466
{
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 () );
463
468
pindexFork = pindex->pprev ;
464
469
}
465
470
// check level 2: verify transaction index validity
@@ -480,13 +485,13 @@ bool CTxDB::LoadBlockIndex()
480
485
CTransaction txFound;
481
486
if (!txFound.ReadFromDisk (txindex.pos ))
482
487
{
483
- LogPrintf (" LoadBlockIndex() : *** cannot read mislocated transaction %s\n " , hashTx.ToString ());
488
+ LogPrintf (" LoadBlockIndex() : *** cannot read mislocated transaction %s\n " , hashTx.ToString (). c_str () );
484
489
pindexFork = pindex->pprev ;
485
490
}
486
491
else
487
492
if (txFound.GetHash () != hashTx) // not a duplicate tx
488
493
{
489
- LogPrintf (" LoadBlockIndex(): *** invalid tx position for %s\n " , hashTx.ToString ());
494
+ LogPrintf (" LoadBlockIndex(): *** invalid tx position for %s\n " , hashTx.ToString (). c_str () );
490
495
pindexFork = pindex->pprev ;
491
496
}
492
497
}
@@ -501,7 +506,7 @@ bool CTxDB::LoadBlockIndex()
501
506
pair<unsigned int , unsigned int > posFind = make_pair (txpos.nFile , txpos.nBlockPos );
502
507
if (!mapBlockPos.count (posFind))
503
508
{
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 ());
505
510
pindexFork = pindex->pprev ;
506
511
}
507
512
// check level 6: check whether spent txouts were spent by a valid transaction that consume them
@@ -510,12 +515,12 @@ bool CTxDB::LoadBlockIndex()
510
515
CTransaction txSpend;
511
516
if (!txSpend.ReadFromDisk (txpos))
512
517
{
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);
514
519
pindexFork = pindex->pprev ;
515
520
}
516
521
else if (!txSpend.CheckTransaction ())
517
522
{
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);
519
524
pindexFork = pindex->pprev ;
520
525
}
521
526
else
@@ -526,7 +531,7 @@ bool CTxDB::LoadBlockIndex()
526
531
fFound = true ;
527
532
if (!fFound )
528
533
{
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);
530
535
pindexFork = pindex->pprev ;
531
536
}
532
537
}
@@ -545,15 +550,15 @@ bool CTxDB::LoadBlockIndex()
545
550
if (ReadTxIndex (txin.prevout .hash , txindex))
546
551
if (txindex.vSpent .size ()-1 < txin.prevout .n || txindex.vSpent [txin.prevout .n ].IsNull ())
547
552
{
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 ());
549
554
pindexFork = pindex->pprev ;
550
555
}
551
556
}
552
557
}
553
558
}
554
559
}
555
560
}
556
- if (pindexFork)
561
+ if (pindexFork && ! fRequestShutdown )
557
562
{
558
563
boost::this_thread::interruption_point ();
559
564
// Reorg back to the fork
0 commit comments