Inject journals:

Calls to WriteLog are replaced with injected journals
This commit is contained in:
seelabs
2015-09-19 11:06:12 -07:00
committed by Vinnie Falco
parent df6ac8f7f5
commit 92b2ca70b7
131 changed files with 1336 additions and 1076 deletions

View File

@@ -164,7 +164,8 @@ Pathfinder::Pathfinder (
STAmount(mDstAmount.issue(), STAmount::cMaxValue, STAmount::cMaxOffset)),
mLedger (cache->getLedger ()),
mRLCache (cache),
app_ (app)
app_ (app),
j_ (app.journal ("Pathfinder"))
{
assert (! uSrcIssuer || isXRP(uSrcCurrency) == isXRP(uSrcIssuer.get()));
}
@@ -178,7 +179,7 @@ bool Pathfinder::findPaths (int searchLevel)
if (mDstAmount == zero)
{
// No need to send zero money.
WriteLog (lsDEBUG, Pathfinder) << "Destination amount was zero.";
JLOG (j_.debug) << "Destination amount was zero.";
mLedger.reset ();
return false;
@@ -191,7 +192,7 @@ bool Pathfinder::findPaths (int searchLevel)
mSrcCurrency == mDstAmount.getCurrency ())
{
// No need to send to same account with same currency.
WriteLog (lsDEBUG, Pathfinder) << "Tried to send to same issuer";
JLOG (j_.debug) << "Tried to send to same issuer";
mLedger.reset ();
return false;
}
@@ -214,7 +215,7 @@ bool Pathfinder::findPaths (int searchLevel)
mSource = STPathElement (account, mSrcCurrency, issuer);
auto issuerString = mSrcIssuer
? to_string (*mSrcIssuer) : std::string ("none");
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< "findPaths>"
<< " mSrcAccount=" << mSrcAccount
<< " mDstAccount=" << mDstAccount
@@ -224,7 +225,7 @@ bool Pathfinder::findPaths (int searchLevel)
if (!mLedger)
{
WriteLog (lsDEBUG, Pathfinder) << "findPaths< no ledger";
JLOG (j_.debug) << "findPaths< no ledger";
return false;
}
@@ -234,14 +235,14 @@ bool Pathfinder::findPaths (int searchLevel)
if (! mLedger->exists (keylet::account(mSrcAccount)))
{
// We can't even start without a source account.
WriteLog (lsDEBUG, Pathfinder) << "invalid source account";
JLOG (j_.debug) << "invalid source account";
return false;
}
if ((mEffectiveDst != mDstAccount) &&
! mLedger->exists (keylet::account(mEffectiveDst)))
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "Non-existent gateway";
return false;
}
@@ -252,7 +253,7 @@ bool Pathfinder::findPaths (int searchLevel)
// account.
if (!bDstXrp)
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "New account not being funded in XRP ";
return false;
}
@@ -260,7 +261,7 @@ bool Pathfinder::findPaths (int searchLevel)
auto const reserve = STAmount (mLedger->fees().accountReserve (0));
if (mDstAmount < reserve)
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "New account not getting enough funding: "
<< mDstAmount << " < " << reserve;
return false;
@@ -273,31 +274,31 @@ bool Pathfinder::findPaths (int searchLevel)
if (bSrcXrp && bDstXrp)
{
// XRP -> XRP
WriteLog (lsDEBUG, Pathfinder) << "XRP to XRP payment";
JLOG (j_.debug) << "XRP to XRP payment";
paymentType = pt_XRP_to_XRP;
}
else if (bSrcXrp)
{
// XRP -> non-XRP
WriteLog (lsDEBUG, Pathfinder) << "XRP to non-XRP payment";
JLOG (j_.debug) << "XRP to non-XRP payment";
paymentType = pt_XRP_to_nonXRP;
}
else if (bDstXrp)
{
// non-XRP -> XRP
WriteLog (lsDEBUG, Pathfinder) << "non-XRP to XRP payment";
JLOG (j_.debug) << "non-XRP to XRP payment";
paymentType = pt_nonXRP_to_XRP;
}
else if (mSrcCurrency == mDstAmount.getCurrency ())
{
// non-XRP -> non-XRP - Same currency
WriteLog (lsDEBUG, Pathfinder) << "non-XRP to non-XRP - same currency";
JLOG (j_.debug) << "non-XRP to non-XRP - same currency";
paymentType = pt_nonXRP_to_same;
}
else
{
// non-XRP to non-XRP - Different currency
WriteLog (lsDEBUG, Pathfinder) << "non-XRP to non-XRP - cross currency";
JLOG (j_.debug) << "non-XRP to non-XRP - cross currency";
paymentType = pt_nonXRP_to_nonXRP;
}
@@ -316,7 +317,7 @@ bool Pathfinder::findPaths (int searchLevel)
}
}
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< mCompletePaths.size () << " complete paths found";
// Even if we find no paths, default paths may work, and we don't check them
@@ -352,6 +353,7 @@ TER Pathfinder::getPathLiquidity (
mDstAccount,
mSrcAccount,
pathSet,
app_.logs(),
&rcInput);
// If we can't get even the minimum liquidity requested, we're done.
if (rc.result () != tesSUCCESS)
@@ -371,6 +373,7 @@ TER Pathfinder::getPathLiquidity (
mDstAccount,
mSrcAccount,
pathSet,
app_.logs (),
&rcInput);
// If we found further liquidity, add it into the result.
@@ -382,7 +385,7 @@ TER Pathfinder::getPathLiquidity (
}
catch (std::exception const& e)
{
WriteLog (lsINFO, Pathfinder) <<
JLOG (j_.info) <<
"checkpath: exception (" << e.what() << ") " <<
path.getJson (0);
return tefEXCEPTION;
@@ -421,23 +424,24 @@ void Pathfinder::computePathRanks (int maxPaths)
mDstAccount,
mSrcAccount,
STPathSet(),
app_.logs (),
&rcInput);
if (rc.result () == tesSUCCESS)
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "Default path contributes: " << rc.actualAmountIn;
mRemainingAmount -= rc.actualAmountOut;
}
else
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "Default path fails: " << transToken (rc.result ());
}
}
catch (...)
{
WriteLog (lsDEBUG, Pathfinder) << "Default path causes exception";
JLOG (j_.debug) << "Default path causes exception";
}
rankPaths (maxPaths, mCompletePaths, mPathRanks);
@@ -509,14 +513,14 @@ void Pathfinder::rankPaths (
currentPath, saMinDstAmount, liquidity, uQuality);
if (resultCode != tesSUCCESS)
{
WriteLog (lsDEBUG, Pathfinder) <<
JLOG (j_.debug) <<
"findPaths: dropping : " <<
transToken (resultCode) <<
": " << currentPath.getJson (0);
}
else
{
WriteLog (lsDEBUG, Pathfinder) <<
JLOG (j_.debug) <<
"findPaths: quality: " << uQuality <<
": " << currentPath.getJson (0);
@@ -558,7 +562,7 @@ Pathfinder::getBestPaths (
STPathSet const& extraPaths,
AccountID const& srcIssuer)
{
WriteLog (lsDEBUG, Pathfinder) << "findPaths: " <<
JLOG (j_.debug) << "findPaths: " <<
mCompletePaths.size() << " paths and " <<
extraPaths.size () << " extras";
@@ -655,12 +659,12 @@ Pathfinder::getBestPaths (
{
// We found an extra path that can move the whole amount.
fullLiquidityPath = (startsWithIssuer ? removeIssuer (path) : path);
WriteLog (lsDEBUG, Pathfinder) <<
JLOG (j_.debug) <<
"Found extra full path: " << fullLiquidityPath.getJson (0);
}
else
{
WriteLog (lsDEBUG, Pathfinder) <<
JLOG (j_.debug) <<
"Skipping a non-filling path: " << path.getJson (0);
}
}
@@ -668,12 +672,12 @@ Pathfinder::getBestPaths (
if (remaining > zero)
{
assert (fullLiquidityPath.empty ());
WriteLog (lsINFO, Pathfinder) <<
JLOG (j_.info) <<
"Paths could not send " << remaining << " of " << mDstAmount;
}
else
{
WriteLog (lsDEBUG, Pathfinder) <<
JLOG (j_.debug) <<
"findPaths: RESULTS: " << bestPaths.getJson (0);
}
return bestPaths;
@@ -760,7 +764,7 @@ void Pathfinder::addLinks (
STPathSet& incompletePaths, // The set of partial paths we add to
int addFlags)
{
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "addLink< on " << currentPaths.size ()
<< " source(s), flags=" << addFlags;
for (auto const& path: currentPaths)
@@ -786,7 +790,7 @@ STPathSet& Pathfinder::addPathsForType (PathType const& pathType)
STPathSet const& parentPaths = addPathsForType (parentPathType);
STPathSet& pathsOut = mPaths[pathType];
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "getPaths< adding onto '"
<< pathTypeToString (parentPathType) << "' to get '"
<< pathTypeToString (pathType) << "'";
@@ -830,7 +834,7 @@ STPathSet& Pathfinder::addPathsForType (PathType const& pathType)
CondLog (mCompletePaths.size () != initialSize, lsDEBUG, Pathfinder)
<< (mCompletePaths.size () - initialSize)
<< " complete paths added";
WriteLog (lsDEBUG, Pathfinder)
JLOG (j_.debug)
<< "getPaths> " << pathsOut.size () << " partial paths found";
return pathsOut;
}
@@ -900,9 +904,9 @@ void Pathfinder::addLink (
// rather than the ultimate destination?
bool const hasEffectiveDestination = mEffectiveDst != mDstAccount;
WriteLog (lsTRACE, Pathfinder) << "addLink< flags="
JLOG (j_.trace) << "addLink< flags="
<< addFlags << " onXRP=" << bOnXRP;
WriteLog (lsTRACE, Pathfinder) << currentPath.getJson (0);
JLOG (j_.trace) << currentPath.getJson (0);
if (addFlags & afADD_ACCOUNTS)
{
@@ -911,7 +915,7 @@ void Pathfinder::addLink (
{
if (mDstAmount.native () && !currentPath.empty ())
{ // non-default path to XRP destination
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< "complete path found ax: " << currentPath.getJson(0);
addUniquePath (mCompletePaths, currentPath);
}
@@ -942,7 +946,7 @@ void Pathfinder::addLink (
auto* rs = dynamic_cast<RippleState const *> (item.get ());
if (!rs)
{
WriteLog (lsERROR, Pathfinder)
JLOG (j_.error)
<< "Couldn't decipher RippleState";
continue;
}
@@ -984,7 +988,7 @@ void Pathfinder::addLink (
// this is a complete path
if (!currentPath.empty ())
{
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< "complete path found ae: "
<< currentPath.getJson (0);
addUniquePath
@@ -1048,7 +1052,7 @@ void Pathfinder::addLink (
}
else
{
WriteLog (lsWARNING, Pathfinder)
JLOG (j_.warning)
<< "Path ends on non-existent issuer";
}
}
@@ -1075,7 +1079,7 @@ void Pathfinder::addLink (
bool bDestOnly = (addFlags & afOB_LAST) != 0;
auto books = app_.getOrderBookDB ().getBooksByTakerPays(
{uEndCurrency, uEndIssuer});
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< books.size () << " books found from this currency/issuer";
for (auto const& book : books)
@@ -1104,7 +1108,7 @@ void Pathfinder::addLink (
{
// destination is XRP, add account and path is
// complete
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< "complete path found bx: "
<< currentPath.getJson(0);
addUniquePath (mCompletePaths, newPath);
@@ -1147,7 +1151,7 @@ void Pathfinder::addLink (
else if (book->getIssuerOut() == mEffectiveDst &&
book->getCurrencyOut() == mDstAmount.getCurrency())
{ // with the destination account, this path is complete
WriteLog (lsTRACE, Pathfinder)
JLOG (j_.trace)
<< "complete path found ba: "
<< currentPath.getJson(0);
addUniquePath (mCompletePaths, newPath);