mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-02 00:45:58 +00:00
allow you to load old ledger
This commit is contained in:
@@ -118,6 +118,12 @@
|
||||
[rpc_allow_remote]
|
||||
1
|
||||
|
||||
[websocket_ip]
|
||||
0.0.0.0
|
||||
|
||||
[websocket_port]
|
||||
5006
|
||||
|
||||
[debug_logfile]
|
||||
log/debug.log
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ void Application::run()
|
||||
boost::thread auxThread(boost::bind(&boost::asio::io_service::run, &mAuxService));
|
||||
auxThread.detach();
|
||||
|
||||
|
||||
if (!theConfig.RUN_STANDALONE)
|
||||
mSNTPClient.init(theConfig.SNTP_SERVERS);
|
||||
|
||||
@@ -87,9 +88,24 @@ 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)
|
||||
{
|
||||
Log(lsINFO) << "Starting new Ledger";
|
||||
startNewLedger();
|
||||
}else if(theConfig.START_UP==Config::LOAD)
|
||||
{
|
||||
Log(lsINFO) << "Loading Old Ledger";
|
||||
loadOldLedger();
|
||||
}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
|
||||
startNewLedger();
|
||||
}
|
||||
|
||||
//
|
||||
// Begin validation and ip maintenance.
|
||||
// - Wallet maintains local information: including identity and network connection persistency information.
|
||||
// - Wallet maintains local information: including identity and network connection persistence information.
|
||||
//
|
||||
mWallet.start();
|
||||
|
||||
@@ -132,32 +148,8 @@ void Application::run()
|
||||
if (!theConfig.RUN_STANDALONE)
|
||||
mConnectionPool.start();
|
||||
|
||||
// New stuff.
|
||||
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
|
||||
NewcoinAddress rootGeneratorMaster = NewcoinAddress::createGeneratorPublic(rootSeedMaster);
|
||||
NewcoinAddress rootAddress = NewcoinAddress::createAccountPublic(rootGeneratorMaster, 0);
|
||||
|
||||
// Print enough information to be able to claim root account.
|
||||
Log(lsINFO) << "Root master seed: " << rootSeedMaster.humanSeed();
|
||||
Log(lsINFO) << "Root account: " << rootAddress.humanAccountID();
|
||||
|
||||
{
|
||||
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, SYSTEM_CURRENCY_START);
|
||||
assert(!!firstLedger->getAccountState(rootAddress));
|
||||
firstLedger->updateHash();
|
||||
firstLedger->setClosed();
|
||||
firstLedger->setAccepted();
|
||||
mMasterLedger.pushLedger(firstLedger);
|
||||
|
||||
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
|
||||
secondLedger->setClosed();
|
||||
secondLedger->setAccepted();
|
||||
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)));
|
||||
assert(!!secondLedger->getAccountState(rootAddress));
|
||||
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (theConfig.RUN_STANDALONE)
|
||||
{
|
||||
Log(lsWARNING) << "Running in standalone mode";
|
||||
@@ -182,4 +174,44 @@ Application::~Application()
|
||||
delete mHashNodeDB;
|
||||
delete mNetNodeDB;
|
||||
}
|
||||
void Application::startNewLedger()
|
||||
{
|
||||
// New stuff.
|
||||
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
|
||||
NewcoinAddress rootGeneratorMaster = NewcoinAddress::createGeneratorPublic(rootSeedMaster);
|
||||
NewcoinAddress rootAddress = NewcoinAddress::createAccountPublic(rootGeneratorMaster, 0);
|
||||
|
||||
// Print enough information to be able to claim root account.
|
||||
Log(lsINFO) << "Root master seed: " << rootSeedMaster.humanSeed();
|
||||
Log(lsINFO) << "Root account: " << rootAddress.humanAccountID();
|
||||
|
||||
{
|
||||
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, SYSTEM_CURRENCY_START);
|
||||
assert(!!firstLedger->getAccountState(rootAddress));
|
||||
firstLedger->updateHash();
|
||||
firstLedger->setClosed();
|
||||
firstLedger->setAccepted();
|
||||
mMasterLedger.pushLedger(firstLedger);
|
||||
|
||||
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
|
||||
secondLedger->setClosed();
|
||||
secondLedger->setAccepted();
|
||||
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)));
|
||||
assert(!!secondLedger->getAccountState(rootAddress));
|
||||
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
|
||||
}
|
||||
}
|
||||
|
||||
void Application::loadOldLedger()
|
||||
{
|
||||
Ledger::pointer lastLedger = Ledger::getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;",true);
|
||||
|
||||
if(!lastLedger)
|
||||
{
|
||||
std::cout << "No Ledger found?" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
mMasterLedger.pushLedger(lastLedger);
|
||||
mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC());
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -67,6 +67,9 @@ class Application
|
||||
std::map<std::string, Peer::pointer> mPeerMap;
|
||||
boost::recursive_mutex mPeerMapLock;
|
||||
|
||||
void startNewLedger();
|
||||
void loadOldLedger();
|
||||
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
|
||||
@@ -155,6 +155,7 @@ void Config::setup(const std::string& strConf)
|
||||
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE;
|
||||
|
||||
RUN_STANDALONE = false;
|
||||
START_UP = NORMAL;
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ public:
|
||||
std::vector<std::string> IPS; // Peer IPs from newcoind.cfg.
|
||||
std::vector<std::string> SNTP_SERVERS; // SNTP servers from newcoind.cfg.
|
||||
|
||||
enum StartUpType {FRESH,NORMAL,LOAD};
|
||||
StartUpType START_UP;
|
||||
|
||||
// Network parameters
|
||||
int NETWORK_START_TIME; // The Unix time we start ledger 0.
|
||||
int TRANSACTION_FEE_BASE;
|
||||
|
||||
@@ -37,11 +37,11 @@ Ledger::Ledger(const NewcoinAddress& masterID, uint64 startAmount) : mTotCoins(s
|
||||
}
|
||||
|
||||
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||
uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution, uint32 ledgerSeq)
|
||||
uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution, uint32 ledgerSeq,bool isMutable)
|
||||
: mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash), mTotCoins(totCoins),
|
||||
mLedgerSeq(ledgerSeq), mCloseTime(closeTime), mParentCloseTime(parentCloseTime),
|
||||
mCloseResolution(closeResolution), mCloseFlags(closeFlags),
|
||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
|
||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(isMutable)
|
||||
{
|
||||
updateHash();
|
||||
}
|
||||
@@ -390,7 +390,7 @@ void Ledger::saveAcceptedLedger(Ledger::ref ledger)
|
||||
theApp->getOPs().pubLedger(ledger);
|
||||
}
|
||||
|
||||
Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
Ledger::pointer Ledger::getSQL(const std::string& sql,bool isMutable)
|
||||
{
|
||||
uint256 ledgerHash, prevHash, accountHash, transHash;
|
||||
uint64 totCoins;
|
||||
@@ -423,9 +423,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
db->endIterRows();
|
||||
}
|
||||
|
||||
Ledger::pointer ret =
|
||||
boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins, closingTime, prevClosingTime,
|
||||
closeFlags, closeResolution, ledgerSeq);
|
||||
Ledger::pointer ret =Ledger::pointer(new Ledger(prevHash, transHash, accountHash, totCoins, closingTime, prevClosingTime,
|
||||
closeFlags, closeResolution, ledgerSeq,isMutable));
|
||||
if (ret->getHash() != ledgerHash)
|
||||
{
|
||||
Json::StyledStreamWriter ssw;
|
||||
|
||||
@@ -84,7 +84,7 @@ private:
|
||||
protected:
|
||||
|
||||
|
||||
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
||||
|
||||
|
||||
SLE::pointer getASNode(LedgerStateParms& parms, const uint256& nodeID, LedgerEntryType let);
|
||||
|
||||
@@ -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); // used for database ledgers
|
||||
uint32 ledgerSeq,bool immutable); // used for database ledgers
|
||||
|
||||
Ledger(const std::vector<unsigned char>& rawLedger);
|
||||
|
||||
@@ -103,6 +103,8 @@ public:
|
||||
|
||||
Ledger(Ledger& target, bool isMutable); // snapshot
|
||||
|
||||
static Ledger::pointer getSQL(const std::string& sqlStatement,bool immutable=false);
|
||||
|
||||
void updateHash();
|
||||
void setClosed() { mClosed = true; }
|
||||
void setAccepted(uint32 closeTime, int closeResolution, bool correctCloseTime);
|
||||
|
||||
@@ -21,7 +21,7 @@ bool LedgerMaster::addHeldTransaction(const Transaction::pointer& transaction)
|
||||
void LedgerMaster::pushLedger(Ledger::ref newLedger)
|
||||
{
|
||||
// Caller should already have properly assembled this ledger into "ready-to-close" form --
|
||||
// all candidate transactions must already be appled
|
||||
// all candidate transactions must already be applied
|
||||
Log(lsINFO) << "PushLedger: " << newLedger->getHash();
|
||||
ScopedLock sl(mLock);
|
||||
if (!!mFinalizedLedger)
|
||||
@@ -70,6 +70,8 @@ void LedgerMaster::storeLedger(Ledger::ref ledger)
|
||||
mLedgerHistory.addLedger(ledger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ledger::pointer LedgerMaster::closeLedger()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -424,7 +424,7 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
// If full or tracking, check only at wobble time!
|
||||
uint256 networkClosed;
|
||||
bool ledgerChange = checkLastClosedLedger(peerList, networkClosed);
|
||||
assert(networkClosed.isNonZero());
|
||||
if(networkClosed.isZero())return;
|
||||
|
||||
// WRITEME: Unless we are in omFULL and in the process of doing a consensus,
|
||||
// we must count how many nodes share our LCL, how many nodes disagree with our LCL,
|
||||
@@ -438,7 +438,7 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
setMode(omTRACKING);
|
||||
}
|
||||
|
||||
if ((mMode == omTRACKING) && !ledgerChange)
|
||||
if ((mMode == omTRACKING) && !ledgerChange )
|
||||
{
|
||||
// check if the ledger is good enough to go to omFULL
|
||||
// Note: Do not go to omFULL if we don't have the previous ledger
|
||||
@@ -470,6 +470,8 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
Log(lsTRACE) << "NetworkOPs::checkLastClosedLedger";
|
||||
|
||||
Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger();
|
||||
if(!ourClosed) return(false);
|
||||
|
||||
uint256 closedLedger = ourClosed->getHash();
|
||||
uint256 prevClosedLedger = ourClosed->getParentHash();
|
||||
|
||||
|
||||
@@ -98,6 +98,8 @@ int main(int argc, char* argv[])
|
||||
("test,t", "Perform unit tests.")
|
||||
("parameters", po::value< vector<string> >(), "Specify comma separated parameters.")
|
||||
("verbose,v", "Increase log level.")
|
||||
("load","Load the current ledger from the local DB.")
|
||||
("start","Start from a fresh Ledger.")
|
||||
;
|
||||
|
||||
// Interpret positional arguments as --parameters.
|
||||
@@ -154,6 +156,9 @@ 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 (iResult)
|
||||
{
|
||||
nothing();
|
||||
|
||||
Reference in New Issue
Block a user