mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 22:15:52 +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);
|
void fillItems(const uint160& accountID, Ledger::ref ledger);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef boost::shared_ptr<AccountItems> pointer;
|
||||||
|
|
||||||
AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType);
|
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);
|
LedgerEntrySet lesActive(mLedger);
|
||||||
|
boost::unordered_map<uint160, AccountItems::pointer> aiMap;
|
||||||
|
|
||||||
SLE::pointer sleSrc = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(mSrcAccountID));
|
SLE::pointer sleSrc = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(mSrcAccountID));
|
||||||
if (!sleSrc)
|
if (!sleSrc)
|
||||||
@@ -285,7 +286,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tLog(lsTRACE)
|
if (sLog(lsTRACE))
|
||||||
{
|
{
|
||||||
cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID);
|
cLog(lsTRACE) << "findPaths: finish? account: " << (speEnd.mAccountID == mDstAccountID);
|
||||||
cLog(lsTRACE) << "findPaths: finish? currency: " << (speEnd.mCurrencyID == mDstAmount.getCurrency());
|
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.
|
// 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.
|
// 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));
|
SLE::pointer sleEnd = lesActive.entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(speEnd.mAccountID));
|
||||||
|
|
||||||
tLog(!sleEnd, lsDEBUG)
|
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())
|
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
|
||||||
{
|
{
|
||||||
RippleState* rspEntry = (RippleState*) item.get();
|
RippleState* rspEntry = (RippleState*) item.get();
|
||||||
const uint160 uPeerID = rspEntry->getAccountIDPeer().getAccountID();
|
const uint160 uPeerID = rspEntry->getAccountIDPeer();
|
||||||
|
|
||||||
if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID))
|
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);
|
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 positive if current account holds other account's IOUs.
|
||||||
// Amount reported is negative if other account holds current account's IOUs.
|
// Amount reported is negative if other account holds current account's IOUs.
|
||||||
jPeer["balance"] = saBalance.getText();
|
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;
|
int iIndex = 0;
|
||||||
BOOST_FOREACH(const STPath& spPath, spsPaths)
|
BOOST_FOREACH(const STPath& spPath, spsPaths)
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l
|
|||||||
mLowLimit = mLedgerEntry->getFieldAmount(sfLowLimit);
|
mLowLimit = mLedgerEntry->getFieldAmount(sfLowLimit);
|
||||||
mHighLimit = mLedgerEntry->getFieldAmount(sfHighLimit);
|
mHighLimit = mLedgerEntry->getFieldAmount(sfHighLimit);
|
||||||
|
|
||||||
mLowID = RippleAddress::createAccountID(mLowLimit.getIssuer());
|
mLowID = mLowLimit.getIssuer();
|
||||||
mHighID = RippleAddress::createAccountID(mHighLimit.getIssuer());
|
mHighID = mHighLimit.getIssuer();
|
||||||
|
|
||||||
mLowQualityIn = mLedgerEntry->getFieldU32(sfLowQualityIn);
|
mLowQualityIn = mLedgerEntry->getFieldU32(sfLowQualityIn);
|
||||||
mLowQualityOut = mLedgerEntry->getFieldU32(sfLowQualityOut);
|
mLowQualityOut = mLedgerEntry->getFieldU32(sfLowQualityOut);
|
||||||
@@ -35,7 +35,7 @@ RippleState::RippleState(SerializedLedgerEntry::ref ledgerEntry) : AccountItem(l
|
|||||||
|
|
||||||
void RippleState::setViewAccount(const uint160& accountID)
|
void RippleState::setViewAccount(const uint160& accountID)
|
||||||
{
|
{
|
||||||
bool bViewLowestNew = mLowID.getAccountID() == accountID;
|
bool bViewLowestNew = mLowID == accountID;
|
||||||
|
|
||||||
if (bViewLowestNew != mViewLowest)
|
if (bViewLowestNew != mViewLowest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
uint32 mFlags;
|
uint32 mFlags;
|
||||||
|
|
||||||
RippleAddress mLowID;
|
uint160 mLowID;
|
||||||
RippleAddress mHighID;
|
uint160 mHighID;
|
||||||
|
|
||||||
STAmount mLowLimit;
|
STAmount mLowLimit;
|
||||||
STAmount mHighLimit;
|
STAmount mHighLimit;
|
||||||
@@ -44,8 +44,8 @@ public:
|
|||||||
|
|
||||||
void setViewAccount(const uint160& accountID);
|
void setViewAccount(const uint160& accountID);
|
||||||
|
|
||||||
const RippleAddress getAccountID() const { return mViewLowest ? mLowID : mHighID; }
|
const uint160& getAccountID() const { return mViewLowest ? mLowID : mHighID; }
|
||||||
const RippleAddress getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; }
|
const uint160& getAccountIDPeer() const { return !mViewLowest ? mLowID : mHighID; }
|
||||||
|
|
||||||
bool getAuth() const { return isSetBit(mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth); }
|
bool getAuth() const { return isSetBit(mFlags, mViewLowest ? lsfLowAuth : lsfHighAuth); }
|
||||||
bool getAuthPeer() 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);
|
int branch = inNode->selectBranch(id);
|
||||||
const uint256& nextHash = inNode->getChildHash(branch);
|
const uint256& nextHash = inNode->getChildHash(branch);
|
||||||
if (nextHash.isZero()) return NULL;
|
if (nextHash.isZero())
|
||||||
|
return NULL;
|
||||||
inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash);
|
inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash);
|
||||||
assert(inNode);
|
assert(inNode);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user