Fixes for ripple_path_find.

This commit is contained in:
Arthur Britto
2012-12-06 20:16:12 -08:00
parent 6a318f496c
commit 56e85db815
5 changed files with 13 additions and 15 deletions

View File

@@ -14,15 +14,9 @@ AccountItem::AccountItem(SerializedLedgerEntry::ref ledger) : mLedgerEntry(ledge
AccountItems::AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType)
{
mOfType=ofType;
fillItems(accountID, ledger);
}
mOfType = ofType;
// looks in the current ledger
AccountItems::AccountItems(const uint160& accountID, AccountItem::pointer ofType )
{
mOfType=ofType;
fillItems(accountID,theApp->getLedgerMaster().getClosedLedger());
fillItems(accountID, ledger);
}
void AccountItems::fillItems(const uint160& accountID, Ledger::ref ledger)

View File

@@ -37,7 +37,6 @@ class AccountItems
public:
AccountItems(const uint160& accountID, Ledger::ref ledger, AccountItem::pointer ofType);
AccountItems(const uint160& accountID, AccountItem::pointer ofType ); // looks in the current ledger
std::vector<AccountItem::pointer>& getItems() { return(mItems); }
};

View File

@@ -256,7 +256,7 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet
// 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(ele.mAccountID, AccountItem::pointer(new RippleState()));
AccountItems rippleLines(ele.mAccountID, mLedger, AccountItem::pointer(new RippleState()));
BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems())
{

View File

@@ -559,7 +559,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
// XXX This is wrong, we do access the current ledger and do need to worry about changes.
// We access a committed ledger and need not worry about changes.
AccountItems rippleLines(raAccount.getAccountID(), AccountItem::pointer(new RippleState()));
AccountItems rippleLines(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new RippleState()));
BOOST_FOREACH(AccountItem::pointer item, rippleLines.getItems())
{
@@ -629,7 +629,7 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
{
Json::Value jsonLines(Json::arrayValue);
AccountItems offers(raAccount.getAccountID(), AccountItem::pointer(new Offer()));
AccountItems offers(raAccount.getAccountID(), lpLedger, AccountItem::pointer(new Offer()));
BOOST_FOREACH(AccountItem::pointer item, offers.getItems())
{
Offer* offer=(Offer*)item.get();
@@ -827,7 +827,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
RippleCalc::setCanonical(spsCanonical, vpsExpanded);
jvEntry["source_amount"] = saMaxAmountAct.getJson(0);
// jvEntry["paths_expanded"] = spsExpanded.getJson(0);
// jvEntry["paths_expanded"] = vpsExpanded.getJson(0);
jvEntry["paths_canonical"] = spsCanonical.getJson(0);
jvArray.append(jvEntry);

View File

@@ -470,9 +470,10 @@ void PathState::setCanonical(
// saInAct
// - currency is always the same as vpnNodes[0].
if (uMaxIssuerID != uAccountID);
if (uNode != uEnd && uMaxIssuerID != uAccountID)
{
// saInAct issuer is not the sender. This forces an implied node.
// cLog(lsDEBUG) << boost::str(boost::format("setCanonical: in diff: uNode=%d uEnd=%d") % uNode % uEnd);
// skip node 1
@@ -483,6 +484,7 @@ void PathState::setCanonical(
if (uNode != uEnd && !!uOutCurrencyID && uOutIssuerID != uDstAccountID)
{
// cLog(lsDEBUG) << boost::str(boost::format("setCanonical: out diff: uNode=%d uEnd=%d") % uNode % uEnd);
// The next to last node is saOutAct if an issuer different from receiver is supplied.
// The next to last node can be implied.
@@ -495,19 +497,21 @@ void PathState::setCanonical(
&& !pnEnd.uAccountID && pnEnd.uCurrencyID == uOutCurrencyID && pnEnd.uIssuerID == uOutIssuerID)
{
// The current end node is an offer converting to saOutAct's currency and issuer and can be implied.
// cLog(lsDEBUG) << boost::str(boost::format("setCanonical: out offer: uNode=%d uEnd=%d") % uNode % uEnd);
--uEnd;
}
// Do not include uEnd.
for (; uNode != uEnd; ++uNode)
{
// cLog(lsDEBUG) << boost::str(boost::format("setCanonical: loop: uNode=%d uEnd=%d") % uNode % uEnd);
const PaymentNode& pnPrv = psExpanded.vpnNodes[uNode-1];
const PaymentNode& pnCur = psExpanded.vpnNodes[uNode];
const PaymentNode& pnNxt = psExpanded.vpnNodes[uNode+1];
const bool bPrvAccount = isSetBit(pnPrv.uFlags, STPathElement::typeAccount);
const bool bCurAccount = isSetBit(pnCur.uFlags, STPathElement::typeAccount);
const bool bNxtAccount = isSetBit(pnNxt.uFlags, STPathElement::typeAccount);
bool bSkip = false;
@@ -525,6 +529,7 @@ void PathState::setCanonical(
else
{
// Currently at an offer.
const bool bNxtAccount = isSetBit(pnNxt.uFlags, STPathElement::typeAccount);
if (bPrvAccount && bNxtAccount // Offer surrounded by accounts.
&& pnPrv.uCurrencyID != pnNxt.uCurrencyID)