Skip to content

Commit

Permalink
Checkpoint / LLD Build Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VidereLicet committed Dec 20, 2016
1 parent d13239a commit 2622a3f
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE

#add build support for the LLD vs Berklee DB
ifdef USE_LLD
DEFS += -LLD
DEFS += -DUSE_LLD
endif

DEBUGFLAGS=-g
Expand Down
2 changes: 1 addition & 1 deletion makefile.osx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ endif

#add build support for the LLD vs Berklee DB
ifdef USE_LLD
DEFS += -LLD
DEFS += -DUSE_LLD
endif

all: nexus
Expand Down
2 changes: 1 addition & 1 deletion makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CXXFLAGS=-O2

#add build support for the LLD vs Berklee DB
ifdef USE_LLD
DEFS += -LLD
DEFS+=-DUSE_LLD
endif

xCXXFLAGS=-pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
Expand Down
29 changes: 15 additions & 14 deletions src/LLD/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace LLD
return pindexNew;
}

#ifdef LLD
#ifdef USE_LLD
bool CIndexDB::LoadBlockIndex()
{
Core::hashBestChain;
Expand All @@ -139,6 +139,7 @@ namespace LLD
break;
}

printf("Read Block %s Height %u\n", hashBlock.ToString().substr(0, 20).c_str(), diskindex.nHeight);
Core::CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
pindexNew->pnext = InsertBlockIndex(diskindex.hashNext);
Expand Down Expand Up @@ -166,9 +167,14 @@ namespace LLD
pindexNew->nNonce = diskindex.nNonce;
pindexNew->nTime = diskindex.nTime;

printf("-- Read Block %s Height %u\n", hashBlock.ToString().substr(0, 20).c_str(), diskindex.nHeight);

/** Detect the Genesis Block on Loading. */
if(hashBlock == Core::hashGenesisBlock)
Core::pindexGenesisBlock = pindexNew;

/** Add the Pending Checkpoint into the Blockchain. **/
Core::HardenCheckpoint(pindexNew, true);
if(!pindexNew->pprev || Core::IsNewTimespan(pindexNew))
if(!pindexNew->pprev || Core::HardenCheckpoint(pindexNew, true))
pindexNew->PendingCheckpoint = make_pair(pindexNew->nHeight, pindexNew->GetBlockHash());
else
pindexNew->PendingCheckpoint = pindexNew->pprev->PendingCheckpoint;
Expand All @@ -182,9 +188,6 @@ namespace LLD
if(!Core::cTrustPool.Accept(block, true))
return error("CIndexDB::LoadBlockIndex() : Failed To Accept Trust Key Block.");
}

if(hashBlock == Core::hashGenesisBlock)
Core::pindexGenesisBlock = pindexNew;

Core::pindexBest = pindexNew;
hashBlock = diskindex.hashNext;
Expand Down Expand Up @@ -529,11 +532,10 @@ namespace LLD


/** Add the Pending Checkpoint into the Blockchain. **/
Core::HardenCheckpoint(pindex, true);
if(!pindex->pprev || Core::IsNewTimespan(pindex))
pindex->PendingCheckpoint = make_pair(pindex->nHeight, pindex->GetBlockHash());
if(!pindexNew->pprev || Core::HardenCheckpoint(pindexNew, true))
pindexNew->PendingCheckpoint = make_pair(pindexNew->nHeight, pindexNew->GetBlockHash());
else
pindex->PendingCheckpoint = pindex->pprev->PendingCheckpoint;
pindexNew->PendingCheckpoint = pindexNew->pprev->PendingCheckpoint;

/** Exit the Loop on the Best Block. **/
if(pindex->GetBlockHash() == Core::hashBestChain)
Expand All @@ -548,10 +550,9 @@ namespace LLD

/** Verify the Blocks in the Best Chain To Last Checkpoint. **/
int nCheckLevel = GetArg("-checklevel", 1);

int nCheckDepth = GetArg( "-checkblocks", 100);
//if (nCheckDepth == 0)
// nCheckDepth = 1000000000;
int nCheckDepth = GetArg( "-checkblocks", 1);
if (nCheckDepth == 0)
nCheckDepth = 1000000000;

if (nCheckDepth > Core::nBestHeight)
nCheckDepth = Core::nBestHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/LLD/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** Lower Level Database Name Space. **/
namespace LLD
{
#ifdef LLD
#ifdef USE_LLD
class CIndexDB : public SectorDatabase
{
public:
Expand Down
6 changes: 3 additions & 3 deletions src/LLD/sector.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ namespace LLD
/** Start a New Database Transaction.
This will put all the database changes into pending state.
If any of the database updates fail in procewss it will roll the database back to its previous state. **/
void TransactionStart()
void TxnBegin()
{
/** Delete a previous database transaction pointer if applicable. **/
if(pTransaction)
Expand All @@ -366,7 +366,7 @@ namespace LLD
}

/** Abort the current transaction that is pending in the transaction chain. **/
void TransactionAbort()
void TxnAbort()
{
/** Delete the previous transaction pointer if applicable. **/
if(pTransaction)
Expand All @@ -392,7 +392,7 @@ namespace LLD
Make it temporary and named after the unique identity of the sector database.
Fingerprint is SK64 hash of unified time and the sector database name along with some other data
To be determined... **/
bool TransactionCommit()
bool TxnCommit()
{
MUTEX_LOCK(SECTOR_MUTEX);

Expand Down
6 changes: 3 additions & 3 deletions src/core/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ namespace Core
}

/** Add the Pending Checkpoint into the Blockchain. **/
if(!pindexNew->pprev || IsNewTimespan(pindexNew))
if(!pindexNew->pprev || HardenCheckpoint(pindexNew))
{
pindexNew->PendingCheckpoint = make_pair(pindexNew->nHeight, pindexNew->GetBlockHash());

Expand All @@ -511,7 +511,7 @@ namespace Core

if(GetArg("-verbose", 0) >= 2)
printg("===== Pending Checkpoint Age = %u Hash = %s Height = %u\n", nAge, pindexNew->PendingCheckpoint.second.ToString().substr(0, 15).c_str(), pindexNew->PendingCheckpoint.first);
}
}

/** Add to the MapBlockIndex **/
map<uint1024, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ namespace Core

/** Initialize Block Index Database. **/
LLD::CIndexDB indexdb("cr");
if (!indexdb.LoadBlockIndex())
if (!indexdb.LoadBlockIndex() || mapBlockIndex.empty())
{
if (!fAllowNew)
return false;
Expand Down
8 changes: 5 additions & 3 deletions src/core/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ namespace Core

/** Hardens the Pending Checkpoint on the Blockchain, determined by a new block creating a new Timespan.
The blockchain from genesis to new hardened checkpoint will then be fixed into place. **/
void HardenCheckpoint(CBlockIndex* pcheckpoint, bool fInit)
bool HardenCheckpoint(CBlockIndex* pcheckpoint, bool fInit)
{

/** Only Harden New Checkpoint if it Fits new Timestamp. **/
if(!IsNewTimespan(pcheckpoint->pprev))
return;
return false;


/** Only Harden a New Checkpoint if it isn't already hardened. **/
if(mapCheckpoints.count(pcheckpoint->pprev->PendingCheckpoint.first))
return;
return true;


/** Update the Checkpoints into Memory. **/
Expand All @@ -87,5 +87,7 @@ namespace Core
printg("===== Hardened Checkpoint %s Height = %u\n",
pcheckpoint->pprev->PendingCheckpoint.second.ToString().substr(0, 20).c_str(),
pcheckpoint->pprev->PendingCheckpoint.first);

return true;
}
}
2 changes: 1 addition & 1 deletion src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace Core
uint1024 GetLastCheckpoint();
bool IsNewTimespan(CBlockIndex* pindex);
bool IsDescendant(CBlockIndex* pindex);
void HardenCheckpoint(CBlockIndex* pcheckpoint, bool fInit = false);
bool HardenCheckpoint(CBlockIndex* pcheckpoint, bool fInit = false);


/** DIFFICULTY.CPP **/
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ bool AppInit2(int argc, char* argv[])
printf("Nexus version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());

#ifdef LLD
#ifdef USE_LLD
InitMessage(_("Initializing LLD Keychains..."));
LLD::RegisterKeychain("blkindex", "blkindex");
#endif
Expand Down

0 comments on commit 2622a3f

Please sign in to comment.