Pathfinding performance improvements.

This commit is contained in:
JoelKatz
2013-04-09 19:42:57 -07:00
parent ab751ffb27
commit fd296b4411
11 changed files with 56 additions and 47 deletions

View File

@@ -169,7 +169,11 @@ void Application::setup()
{
cLog(lsINFO) << "Loading specified Ledger";
loadOldLedger(theConfig.START_LEDGER);
if (!loadOldLedger(theConfig.START_LEDGER))
{
theApp->stop();
exit(-1);
}
}
else if (theConfig.START_UP == Config::NETWORK)
{ // This should probably become the default once we have a stable network
@@ -389,7 +393,7 @@ void Application::startNewLedger()
}
}
void Application::loadOldLedger(const std::string& l)
bool Application::loadOldLedger(const std::string& l)
{
try
{
@@ -408,7 +412,7 @@ void Application::loadOldLedger(const std::string& l)
if (!loadLedger)
{
cLog(lsFATAL) << "No Ledger found?" << std::endl;
exit(-1);
return false;
}
loadLedger->setClosed();
@@ -418,19 +422,19 @@ void Application::loadOldLedger(const std::string& l)
{
cLog(lsFATAL) << "Ledger is empty.";
assert(false);
exit(-1);
return false;
}
if (!loadLedger->walkLedger())
{
cLog(lsFATAL) << "Ledger is missing nodes.";
exit(-1);
return false;
}
if (!loadLedger->assertSane())
{
cLog(lsFATAL) << "Ledger is not sane.";
exit(-1);
return false;
}
mLedgerMaster.setLedgerRangePresent(loadLedger->getLedgerSeq(), loadLedger->getLedgerSeq());
@@ -441,13 +445,14 @@ void Application::loadOldLedger(const std::string& l)
catch (SHAMapMissingNode&)
{
cLog(lsFATAL) << "Data is missing for selected ledger";
exit(-1);
return false;
}
catch (boost::bad_lexical_cast&)
{
cLog(lsFATAL) << "Ledger specified '" << l << "' is not valid";
exit(-1);
return false;
}
return true;
}
// vim:ts=4

View File

@@ -92,7 +92,7 @@ class Application
void updateTables();
void startNewLedger();
void loadOldLedger(const std::string&);
bool loadOldLedger(const std::string&);
public:
Application();

View File

@@ -184,17 +184,16 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
#ifndef NO_SQLITE3_PREPARE
{
std::string sql = "SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = '";
sql.append(hash.GetHex());
sql.append("';");
ScopedLock sl(theApp->getHashNodeDB()->getDBLock());
static SqliteStatement pSt(theApp->getHashNodeDB()->getDB()->getSqliteDB(),
"SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = ?;");
LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK, "HOS::retrieve"));
SqliteStatement pSt(theApp->getHashNodeDB()->getDB()->getSqliteDB(), sql.c_str());
pSt.bind(1, hash.GetHex());
int ret = pSt.step();
if (pSt.isDone(ret))
{
pSt.reset();
mNegativeCache.add(hash);
cLog(lsTRACE) << "HOS: " << hash <<" fetch: not in db";
return obj;
@@ -203,6 +202,7 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
type = pSt.peekString(0);
index = pSt.getUInt32(1);
pSt.getBlob(2).swap(data);
pSt.reset();
}
#else

View File

@@ -3,33 +3,34 @@
AccountItem::pointer RippleState::makeItem(const uint160& accountID, SerializedLedgerEntry::ref ledgerEntry)
{
if (!ledgerEntry || ledgerEntry->getType() != ltRIPPLE_STATE) return(AccountItem::pointer());
if (!ledgerEntry || ledgerEntry->getType() != ltRIPPLE_STATE)
return AccountItem::pointer();
RippleState* rs = new RippleState(ledgerEntry);
rs->setViewAccount(accountID);
return(AccountItem::pointer(rs));
return AccountItem::pointer(rs);
}
RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(ledgerEntry),
mValid(false),
mViewLowest(true)
mViewLowest(true),
mLowLimit(ledgerEntry->getFieldAmount(sfLowLimit)),
mHighLimit(ledgerEntry->getFieldAmount(sfHighLimit)),
mLowID(mLowLimit.getIssuer()),
mHighID(mHighLimit.getIssuer()),
mBalance(ledgerEntry->getFieldAmount(sfBalance))
{
mFlags = mLedgerEntry->getFieldU32(sfFlags);
mLowLimit = mLedgerEntry->getFieldAmount(sfLowLimit);
mHighLimit = mLedgerEntry->getFieldAmount(sfHighLimit);
mLowID = mLowLimit.getIssuer();
mHighID = mHighLimit.getIssuer();
mLowQualityIn = mLedgerEntry->getFieldU32(sfLowQualityIn);
mLowQualityOut = mLedgerEntry->getFieldU32(sfLowQualityOut);
mHighQualityIn = mLedgerEntry->getFieldU32(sfHighQualityIn);
mHighQualityOut = mLedgerEntry->getFieldU32(sfHighQualityOut);
mBalance = mLedgerEntry->getFieldAmount(sfBalance);
mValid = true;
}

View File

@@ -17,14 +17,17 @@ public:
typedef boost::shared_ptr<RippleState> pointer;
private:
uint32 mFlags;
bool mValid;
bool mViewLowest;
uint160 mLowID;
uint160 mHighID;
uint32 mFlags;
STAmount mLowLimit;
STAmount mHighLimit;
uint160 mLowID;
uint160 mHighID;
uint64 mLowQualityIn;
uint64 mLowQualityOut;
uint64 mHighQualityIn;
@@ -32,9 +35,6 @@ private:
STAmount mBalance;
bool mValid;
bool mViewLowest;
RippleState(SerializedLedgerEntry::ref ledgerEntry); // For accounts in a ledger
public:

View File

@@ -124,8 +124,8 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) const
int SHAMapNode::selectBranch(const uint256& hash) const
{ // Which branch would contain the specified hash
#ifdef DEBUG
if (mDepth == 64)
#ifdef PARANOID
if (mDepth >= 64)
{
assert(false);
return -1;

View File

@@ -639,14 +639,18 @@ std::vector<unsigned char> STObject::getFieldVL(SField::ref field) const
return cf->getValue();
}
STAmount STObject::getFieldAmount(SField::ref field) const
static const STAmount defaultAmount;
const STAmount& STObject::getFieldAmount(SField::ref field) const
{
const SerializedType* rf = peekAtPField(field);
if (!rf) throw std::runtime_error("Field not found");
if (!rf)
throw std::runtime_error("Field not found");
SerializedTypeID id = rf->getSType();
if (id == STI_NOTPRESENT) return STAmount(); // optional field not present
if (id == STI_NOTPRESENT)
return defaultAmount; // optional field not present
const STAmount *cf = dynamic_cast<const STAmount *>(rf);
if (!cf) throw std::runtime_error("Wrong field type");
if (!cf)
throw std::runtime_error("Wrong field type");
return *cf;
}

View File

@@ -130,7 +130,7 @@ public:
RippleAddress getFieldAccount(SField::ref field) const;
uint160 getFieldAccount160(SField::ref field) const;
std::vector<unsigned char> getFieldVL(SField::ref field) const;
STAmount getFieldAmount(SField::ref field) const;
const STAmount& getFieldAmount(SField::ref field) const;
STPathSet getFieldPathSet(SField::ref field) const;
STVector256 getFieldV256(SField::ref field) const;

View File

@@ -14,10 +14,9 @@
#include "TransactionErr.h"
SETUP_LOG();
DECLARE_INSTANCE(SerializedValue);
STAmount saZero(CURRENCY_ONE, ACCOUNT_ONE, 0);
STAmount saOne(CURRENCY_ONE, ACCOUNT_ONE, 1);
const STAmount saZero(CURRENCY_ONE, ACCOUNT_ONE, 0);
const STAmount saOne(CURRENCY_ONE, ACCOUNT_ONE, 1);
SerializedType& SerializedType::operator=(const SerializedType& t)
{

View File

@@ -44,9 +44,7 @@ static inline const uint160& get_u160_one() { return u160_one; }
#define ACCOUNT_XRP get_u160_zero()
#define ACCOUNT_ONE get_u160_one() // Used as a place holder.
DEFINE_INSTANCE(SerializedValue);
class SerializedType : private IS_INSTANCE(SerializedValue)
class SerializedType
{
protected:
SField::ptr fName;
@@ -475,8 +473,8 @@ public:
void roundSelf();
};
extern STAmount saZero;
extern STAmount saOne;
extern const STAmount saZero;
extern const STAmount saOne;
class STHash128 : public SerializedType
{

View File

@@ -221,6 +221,7 @@ int main(int argc, char* argv[])
{
unit_test_main(init_unit_test, argc, argv);
InstanceType::shutdown();
return 0;
}
@@ -279,6 +280,7 @@ int main(int argc, char* argv[])
if (1 == iResult && !vm.count("quiet"))
printHelp(desc);
InstanceType::shutdown();
return iResult;
}
// vim:ts=4