Speed up path finding by about 35%.

This commit is contained in:
JoelKatz
2013-03-04 18:57:44 -08:00
parent b8fdb3b659
commit ce401dffb6
7 changed files with 22 additions and 13 deletions

View File

@@ -35,6 +35,7 @@ class AccountItems
void fillItems(const uint160& accountID, Ledger::ref ledger);
public:
typedef boost::shared_ptr<AccountItems> pointer;
AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType);

View File

@@ -205,6 +205,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
}
LedgerEntrySet lesActive(mLedger);
boost::unordered_map<uint160, AccountItems::pointer> aiMap;
SLE::pointer sleSrc = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(mSrcAccountID));
if (!sleSrc)
@@ -285,7 +286,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
continue;
}
if (tLog(lsTRACE)
if (sLog(lsTRACE))
{
cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID);
cLog(lsTRACE) << "findPaths: finish? currency: " << (speEnd.mCurrencyID == mDstAmount.getCurrency());
@@ -387,7 +388,13 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
// Last element is for non-XRP, continue by adding ripple lines and order books.
// Create new paths for each outbound account not already in the path.
AccountItems rippleLines(speEnd.mAccountID, mLedger, AccountItem::pointer(new RippleState()));
boost::unordered_map<uint160, AccountItems::pointer>::iterator it = aiMap.find(speEnd.mAccountID);
if (it == aiMap.end())
it = aiMap.insert(std::make_pair(speEnd.mAccountID,
boost::make_shared<AccountItems>(
boost::cref(speEnd.mAccountID), boost::cref(mLedger), AccountItem::pointer(new RippleState())))).first;
AccountItems& rippleLines = *it->second;
SLE::pointer sleEnd = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(speEnd.mAccountID));
tLog(!sleEnd, lsDEBUG)
@@ -403,7 +410,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
{
RippleState* rspEntry = (RippleState*) item.get();
const uint160 uPeerID = rspEntry->getAccountIDPeer().getAccountID();
const uint160 uPeerID = rspEntry->getAccountIDPeer();
if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID))
{

View File

@@ -929,7 +929,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
Json::Value jPeer = Json::Value(Json::objectValue);
jPeer["account"] = line->getAccountIDPeer().humanAccountID();
jPeer["account"] = RippleAddress::createHumanAccountID(line->getAccountIDPeer());
// Amount reported is positive if current account holds other account's IOUs.
// Amount reported is negative if other account holds current account's IOUs.
jPeer["balance"] = saBalance.getText();

View File

@@ -2521,7 +2521,7 @@ cLog(lsDEBUG) << boost::str(boost::format("rippleCalc: Build direct: status: %s"
}
}
cLog(lsINFO) << "rippleCalc: Paths in set: " << spsPaths.size();
cLog(lsTRACE) << "rippleCalc: Paths in set: " << spsPaths.size();
int iIndex = 0;
BOOST_FOREACH(const STPath& spPath, spsPaths)

View File

@@ -19,8 +19,8 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l
mLowLimit = mLedgerEntry->getFieldAmount(sfLowLimit);
mHighLimit = mLedgerEntry->getFieldAmount(sfHighLimit);
mLowID = RippleAddress::createAccountID(mLowLimit.getIssuer());
mHighID = RippleAddress::createAccountID(mHighLimit.getIssuer());
mLowID = mLowLimit.getIssuer();
mHighID = mHighLimit.getIssuer();
mLowQualityIn = mLedgerEntry->getFieldU32(sfLowQualityIn);
mLowQualityOut = mLedgerEntry->getFieldU32(sfLowQualityOut);
@@ -35,7 +35,7 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l
void RippleState::setViewAccount(const uint160& accountID)
{
bool bViewLowestNew = mLowID.getAccountID() == accountID;
bool bViewLowestNew = mLowID == accountID;
if (bViewLowestNew != mViewLowest)
{

View File

@@ -19,8 +19,8 @@ public:
private:
uint32 mFlags;
RippleAddress mLowID;
RippleAddress mHighID;
uint160 mLowID;
uint160 mHighID;
STAmount mLowLimit;
STAmount mHighLimit;
@@ -44,8 +44,8 @@ public:
void setViewAccount(const uint160& accountID);
const RippleAddress getAccountID() const { return mViewLowest ? mLowID : mHighID; }
const RippleAddress getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; }
const uint160& getAccountID() const { return mViewLowest ? mLowID : mHighID; }
const uint160& getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; }
bool getAuth() const { return isSetBit(mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth); }
bool getAuthPeer() const { return isSetBit(mFlags, !mViewLowest ? lsfLowAuth : lsfHighAuth); }

View File

@@ -194,7 +194,8 @@ SHAMapTreeNode* SHAMap::walkToPointer(const uint256& id)
{
int branch = inNode->selectBranch(id);
const uint256& nextHash = inNode->getChildHash(branch);
if (nextHash.isZero()) return NULL;
if (nextHash.isZero())
return NULL;
inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash);
assert(inNode);
}