Make it possible to start from a specific chosen ledger.

This commit is contained in:
JoelKatz
2013-01-07 23:47:39 -08:00
parent 7a2f098ac4
commit cc2588aba2
4 changed files with 35 additions and 15 deletions

View File

@@ -129,7 +129,7 @@ void Application::run()
{ {
cLog(lsINFO) << "Loading Old Ledger"; cLog(lsINFO) << "Loading Old Ledger";
loadOldLedger(); loadOldLedger(theConfig.START_LEDGER);
} }
else if (theConfig.START_UP == Config::NETWORK) else if (theConfig.START_UP == Config::NETWORK)
{ // This should probably become the default once we have a stable 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 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<uint32>(l));
if (!lastLedger) if (!loadLedger)
{ {
cLog(lsFATAL) << "No Ledger found?" << std::endl; cLog(lsFATAL) << "No Ledger found?" << std::endl;
exit(-1); 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."; cLog(lsFATAL) << "Ledger is empty.";
assert(false); assert(false);
exit(-1); exit(-1);
} }
if (!lastLedger->walkLedger()) if (!loadLedger->walkLedger())
{ {
cLog(lsFATAL) << "Ledger is missing nodes."; cLog(lsFATAL) << "Ledger is missing nodes.";
exit(-1); exit(-1);
} }
if (!lastLedger->assertSane()) if (!loadLedger->assertSane())
{ {
cLog(lsFATAL) << "Ledger is not sane."; cLog(lsFATAL) << "Ledger is not sane.";
exit(-1); exit(-1);
} }
mLedgerMaster.setLedgerRangePresent(0, lastLedger->getLedgerSeq()); mLedgerMaster.setLedgerRangePresent(loadLedger->getLedgerSeq(), loadLedger->getLedgerSeq());
Ledger::pointer openLedger = boost::make_shared<Ledger>(false, boost::ref(*lastLedger)); Ledger::pointer openLedger = boost::make_shared<Ledger>(false, boost::ref(*loadLedger));
mLedgerMaster.switchLedgers(lastLedger, openLedger); mLedgerMaster.switchLedgers(loadLedger, openLedger);
mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC()); mNetOps.setLastCloseTime(loadLedger->getCloseTimeNC());
} }
catch (SHAMapMissingNode& mn) catch (SHAMapMissingNode& mn)
{ {

View File

@@ -84,7 +84,7 @@ class Application
boost::recursive_mutex mPeerMapLock; boost::recursive_mutex mPeerMapLock;
void startNewLedger(); void startNewLedger();
void loadOldLedger(); void loadOldLedger(const std::string&);
public: public:
Application(); Application();

View File

@@ -65,6 +65,7 @@ public:
enum StartUpType { FRESH, NORMAL, LOAD, NETWORK }; enum StartUpType { FRESH, NORMAL, LOAD, NETWORK };
StartUpType START_UP; StartUpType START_UP;
std::string START_LEDGER;
// Database // Database
std::string DATABASE_PATH; std::string DATABASE_PATH;

View File

@@ -102,6 +102,7 @@ int main(int argc, char* argv[])
("quiet,q", "Reduce diagnotics.") ("quiet,q", "Reduce diagnotics.")
("verbose,v", "Verbose logging.") ("verbose,v", "Verbose logging.")
("load", "Load the current ledger from the local DB.") ("load", "Load the current ledger from the local DB.")
("ledger", po::value<std::string>(), "Load the specified ledger and start from .")
("start", "Start from a fresh Ledger.") ("start", "Start from a fresh Ledger.")
("net", "Get the initial ledger from the network.") ("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; 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<std::string>();
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; else if (vm.count("net")) theConfig.START_UP = Config::NETWORK;
if (iResult) if (iResult)