mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 05:55:51 +00:00
Speed up path finding by about 35%.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user