diff --git a/src/Application.cpp b/src/Application.cpp index 1a67e0b74d..ef00d19fdf 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -88,15 +88,17 @@ void Application::run() boost::thread t6(boost::bind(&InitDB, &mNetNodeDB, "netnode.db", NetNodeDBInit, NetNodeDBCount)); t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); t6.join(); - if(theConfig.START_UP==Config::FRESH) + if (theConfig.START_UP == Config::FRESH) { Log(lsINFO) << "Starting new Ledger"; startNewLedger(); - }else if(theConfig.START_UP==Config::LOAD) + } + else if (theConfig.START_UP == Config::LOAD) { Log(lsINFO) << "Loading Old Ledger"; loadOldLedger(); - }else + } + else { // TODO: This should really not validate a ledger until it gets the current one from our peers // but I'll let david make this change since a lot of code assumes we have a ledger // for now just do what we always were doing @@ -173,6 +175,7 @@ Application::~Application() delete mHashNodeDB; delete mNetNodeDB; } + void Application::startNewLedger() { // New stuff. @@ -203,14 +206,17 @@ void Application::startNewLedger() void Application::loadOldLedger() { - Ledger::pointer lastLedger = Ledger::getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;",true); + Ledger::pointer lastLedger = Ledger::getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;"); - if(!lastLedger) + if (!lastLedger) { std::cout << "No Ledger found?" << std::endl; exit(-1); } - mMasterLedger.pushLedger(lastLedger); + + lastLedger->setClosed(); + Ledger::pointer openLedger = boost::make_shared(false, boost::ref(*lastLedger)); + mMasterLedger.switchLedgers(lastLedger, openLedger); mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC()); } // vim:ts=4 diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 25a94db5ca..f52e1f1e71 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -391,7 +391,7 @@ void Ledger::saveAcceptedLedger(Ledger::ref ledger) theApp->getOPs().pubLedger(ledger); } -Ledger::pointer Ledger::getSQL(const std::string& sql,bool isMutable) +Ledger::pointer Ledger::getSQL(const std::string& sql) { uint256 ledgerHash, prevHash, accountHash, transHash; uint64 totCoins; @@ -424,8 +424,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql,bool isMutable) db->endIterRows(); } - Ledger::pointer ret =Ledger::pointer(new Ledger(prevHash, transHash, accountHash, totCoins, closingTime, prevClosingTime, - closeFlags, closeResolution, ledgerSeq,isMutable)); + Ledger::pointer ret = Ledger::pointer(new Ledger(prevHash, transHash, accountHash, totCoins, + closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq, true)); if (ret->getHash() != ledgerHash) { if (sLog(lsERROR)) diff --git a/src/Ledger.h b/src/Ledger.h index 71a1bbb2a9..41e30d2dbf 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -93,7 +93,7 @@ public: Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash, uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution, - uint32 ledgerSeq,bool immutable); // used for database ledgers + uint32 ledgerSeq, bool immutable); // used for database ledgers Ledger(const std::vector& rawLedger); @@ -103,7 +103,7 @@ public: Ledger(Ledger& target, bool isMutable); // snapshot - static Ledger::pointer getSQL(const std::string& sqlStatement,bool immutable=false); + static Ledger::pointer getSQL(const std::string& sqlStatement); void updateHash(); void setClosed() { mClosed = true; } @@ -116,10 +116,6 @@ public: void armDirty() { mTransactionMap->armDirty(); mAccountStateMap->armDirty(); } void disarmDirty() { mTransactionMap->disarmDirty(); mAccountStateMap->disarmDirty(); } - // This ledger has closed, will never be accepted, and is accepting - // new transactions to be re-reprocessed when do accept a new last-closed ledger - void bumpSeq() { mClosed = true; mLedgerSeq++; } - // ledger signature operations void addRaw(Serializer &s) const; void setRaw(const Serializer& s);