mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 23:15:52 +00:00
Optimize the startup code so we don't have long periods of slowness on startup.
This commit is contained in:
@@ -529,6 +529,53 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 Ledger::getHashByIndex(uint32 ledgerIndex)
|
||||||
|
{
|
||||||
|
uint256 ret;
|
||||||
|
|
||||||
|
std::string sql="SELECT LedgerHash FROM Ledgers WHERE LedgerSeq='";
|
||||||
|
sql.append(boost::lexical_cast<std::string>(ledgerIndex));
|
||||||
|
sql.append("';");
|
||||||
|
|
||||||
|
std::string hash;
|
||||||
|
{
|
||||||
|
Database *db = theApp->getLedgerDB()->getDB();
|
||||||
|
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||||
|
if (!db->executeSQL(sql) || !db->startIterRows())
|
||||||
|
return ret;
|
||||||
|
db->getStr("LedgerHash", hash);
|
||||||
|
db->endIterRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.SetHex(hash);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ledger::getHashesByIndex(uint32 ledgerIndex, uint256& ledgerHash, uint256& parentHash)
|
||||||
|
{
|
||||||
|
std::string sql="SELECT LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq='";
|
||||||
|
sql.append(boost::lexical_cast<std::string>(ledgerIndex));
|
||||||
|
sql.append("';");
|
||||||
|
|
||||||
|
std::string hash, prevHash;
|
||||||
|
{
|
||||||
|
Database *db = theApp->getLedgerDB()->getDB();
|
||||||
|
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||||
|
if (!db->executeSQL(sql) || !db->startIterRows())
|
||||||
|
return false;
|
||||||
|
db->getStr("LedgerHash", hash);
|
||||||
|
db->getStr("PrevHash", prevHash);
|
||||||
|
db->endIterRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
ledgerHash.SetHex(hash);
|
||||||
|
parentHash.SetHex(prevHash);
|
||||||
|
|
||||||
|
assert(ledgerHash.isNonZero() && ((ledgerIndex == 0) || parentHash.isNonZero()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Ledger::pointer Ledger::loadByIndex(uint32 ledgerIndex)
|
Ledger::pointer Ledger::loadByIndex(uint32 ledgerIndex)
|
||||||
{ // This is a low-level function with no caching
|
{ // This is a low-level function with no caching
|
||||||
std::string sql="SELECT * from Ledgers WHERE LedgerSeq='";
|
std::string sql="SELECT * from Ledgers WHERE LedgerSeq='";
|
||||||
|
|||||||
@@ -178,9 +178,11 @@ public:
|
|||||||
SLE::pointer getAccountRoot(const RippleAddress& naAccountID);
|
SLE::pointer getAccountRoot(const RippleAddress& naAccountID);
|
||||||
void updateSkipList();
|
void updateSkipList();
|
||||||
|
|
||||||
// database functions
|
// database functions (low-level)
|
||||||
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
static Ledger::pointer loadByIndex(uint32 ledgerIndex);
|
||||||
static Ledger::pointer loadByHash(const uint256& ledgerHash);
|
static Ledger::pointer loadByHash(const uint256& ledgerHash);
|
||||||
|
static uint256 getHashByIndex(uint32 index);
|
||||||
|
static bool getHashesByIndex(uint32 index, uint256& ledgerHash, uint256& parentHash);
|
||||||
void pendSave(bool fromConsensus);
|
void pendSave(bool fromConsensus);
|
||||||
|
|
||||||
// next/prev function
|
// next/prev function
|
||||||
|
|||||||
@@ -134,19 +134,25 @@ bool LedgerMaster::haveLedgerRange(uint32 from, uint32 to)
|
|||||||
|
|
||||||
void LedgerMaster::asyncAccept(Ledger::pointer ledger)
|
void LedgerMaster::asyncAccept(Ledger::pointer ledger)
|
||||||
{
|
{
|
||||||
do
|
uint32 seq = ledger->getLedgerSeq();
|
||||||
|
uint256 prevHash = ledger->getParentHash();
|
||||||
|
|
||||||
|
while (seq > 0)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||||
mCompleteLedgers.setValue(ledger->getLedgerSeq());
|
mCompleteLedgers.setValue(seq);
|
||||||
if ((ledger->getLedgerSeq() == 0) || mCompleteLedgers.hasValue(ledger->getLedgerSeq() - 1))
|
--seq;
|
||||||
|
if (mCompleteLedgers.hasValue(seq))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ledger::pointer prevLedger = mLedgerHistory.getLedgerBySeq(ledger->getLedgerSeq() - 1); // FIXME
|
|
||||||
if (!prevLedger || (prevLedger->getHash() != ledger->getParentHash()))
|
uint256 tHash, pHash;
|
||||||
|
if (!Ledger::getHashesByIndex(seq, tHash, pHash) || (tHash != prevHash))
|
||||||
break;
|
break;
|
||||||
ledger = prevLedger;
|
prevHash = pHash;
|
||||||
} while(1);
|
}
|
||||||
|
|
||||||
resumeAcquiring();
|
resumeAcquiring();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +162,7 @@ bool LedgerMaster::acquireMissingLedger(const uint256& ledgerHash, uint32 ledger
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
Ledger::pointer ledger = mLedgerHistory.getLedgerBySeq(ledgerSeq);
|
Ledger::pointer ledger = mLedgerHistory.getLedgerBySeq(ledgerSeq);
|
||||||
if (ledger && (ledger->getHash() == ledgerHash))
|
if (Ledger::getHashByIndex(ledgerSeq) == ledgerHash)
|
||||||
{
|
{
|
||||||
cLog(lsDEBUG) << "Ledger hash found in database";
|
cLog(lsDEBUG) << "Ledger hash found in database";
|
||||||
mTooFast = true;
|
mTooFast = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user