From cc2588aba276eef3e4a8ec0e5a8c06cd97433338 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 7 Jan 2013 23:47:39 -0800 Subject: [PATCH] Make it possible to start from a specific chosen ledger. --- src/cpp/ripple/Application.cpp | 36 ++++++++++++++++++++++------------ src/cpp/ripple/Application.h | 2 +- src/cpp/ripple/Config.h | 1 + src/cpp/ripple/main.cpp | 11 ++++++++++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 4fce41e78b..60255b55d8 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -129,7 +129,7 @@ void Application::run() { cLog(lsINFO) << "Loading Old Ledger"; - loadOldLedger(); + loadOldLedger(theConfig.START_LEDGER); } else if (theConfig.START_UP == Config::NETWORK) { // This should probably become the default once we have a stable network @@ -317,44 +317,54 @@ void Application::startNewLedger() } } -void Application::loadOldLedger() +void Application::loadOldLedger(const std::string& l) { try { - Ledger::pointer lastLedger = Ledger::getLastFullLedger(); + Ledger::pointer loadLedger; + if (l.empty() || (l == "latest")) + loadLedger = Ledger::getLastFullLedger(); + if (l.length() == 64) + { + uint256 hash; + hash.SetHex(l); + loadLedger = Ledger::loadByHash(hash); + } + else + loadLedger = Ledger::loadByIndex(boost::lexical_cast(l)); - if (!lastLedger) + if (!loadLedger) { cLog(lsFATAL) << "No Ledger found?" << std::endl; exit(-1); } - lastLedger->setClosed(); + loadLedger->setClosed(); - cLog(lsINFO) << "Loading ledger " << lastLedger->getHash() << " seq:" << lastLedger->getLedgerSeq(); + cLog(lsINFO) << "Loading ledger " << loadLedger->getHash() << " seq:" << loadLedger->getLedgerSeq(); - if (lastLedger->getAccountHash().isZero()) + if (loadLedger->getAccountHash().isZero()) { cLog(lsFATAL) << "Ledger is empty."; assert(false); exit(-1); } - if (!lastLedger->walkLedger()) + if (!loadLedger->walkLedger()) { cLog(lsFATAL) << "Ledger is missing nodes."; exit(-1); } - if (!lastLedger->assertSane()) + if (!loadLedger->assertSane()) { cLog(lsFATAL) << "Ledger is not sane."; exit(-1); } - mLedgerMaster.setLedgerRangePresent(0, lastLedger->getLedgerSeq()); + mLedgerMaster.setLedgerRangePresent(loadLedger->getLedgerSeq(), loadLedger->getLedgerSeq()); - Ledger::pointer openLedger = boost::make_shared(false, boost::ref(*lastLedger)); - mLedgerMaster.switchLedgers(lastLedger, openLedger); - mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC()); + Ledger::pointer openLedger = boost::make_shared(false, boost::ref(*loadLedger)); + mLedgerMaster.switchLedgers(loadLedger, openLedger); + mNetOps.setLastCloseTime(loadLedger->getCloseTimeNC()); } catch (SHAMapMissingNode& mn) { diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 31772c30ac..ca1561379c 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -84,7 +84,7 @@ class Application boost::recursive_mutex mPeerMapLock; void startNewLedger(); - void loadOldLedger(); + void loadOldLedger(const std::string&); public: Application(); diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index c97f5495d0..04544dd2ae 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -65,6 +65,7 @@ public: enum StartUpType { FRESH, NORMAL, LOAD, NETWORK }; StartUpType START_UP; + std::string START_LEDGER; // Database std::string DATABASE_PATH; diff --git a/src/cpp/ripple/main.cpp b/src/cpp/ripple/main.cpp index 6f11ae8080..0373dccad8 100644 --- a/src/cpp/ripple/main.cpp +++ b/src/cpp/ripple/main.cpp @@ -102,6 +102,7 @@ int main(int argc, char* argv[]) ("quiet,q", "Reduce diagnotics.") ("verbose,v", "Verbose logging.") ("load", "Load the current ledger from the local DB.") + ("ledger", po::value(), "Load the specified ledger and start from .") ("start", "Start from a fresh Ledger.") ("net", "Get the initial ledger from the network.") ; @@ -171,7 +172,15 @@ int main(int argc, char* argv[]) } if (vm.count("start")) theConfig.START_UP = Config::FRESH; - else if (vm.count("load")) theConfig.START_UP = Config::LOAD; + if (vm.count("ledger")) + { + theConfig.START_LEDGER = vm["ledger"].as(); + theConfig.START_UP = Config::LOAD; + } + else if (vm.count("load")) + { + theConfig.START_UP = Config::LOAD; + } else if (vm.count("net")) theConfig.START_UP = Config::NETWORK; if (iResult)