Better numerical stability for deferred credits:

Before this change, the deferred credits algorithm took the current
balance and subtracted the recorded credits. Conceptually, this is the
same as taking the original balance, adding all the credits,
subtracting all the debits, and subtracting all the credits. The new
algorithm records the original balance and subtracts the debits. This
prevents errors that occur when the original balance and the recorded
credits have large differences in magnitude.

Additionally, XRP credits were recorded incorrectly in the deferred
credits table (the line was between the sender and receiver, rather than
the root account).
This commit is contained in:
seelabs
2016-03-31 11:06:13 -04:00
committed by Nik Bougalis
parent 4124850481
commit 4b8d227922
16 changed files with 349 additions and 139 deletions

View File

@@ -102,6 +102,12 @@ public:
return EitherAmount (cache_->out);
}
boost::optional<Book>
bookStepBook () const override
{
return book_;
}
std::pair<TIn, TOut>
revImp (
PaymentSandbox& sb,
@@ -258,7 +264,7 @@ forEachOffer (
break;
}
return {offers.toRemove (), counter.count()};
return {offers.permToRemove (), counter.count()};
}
template <class TIn, class TOut>
@@ -546,11 +552,16 @@ BookStep<TIn, TOut>::check(StrandContext const& ctx) const
JLOG (j_.debug()) << "Book: currency is inconsistent with issuer." << *this;
return temBAD_PATH;
}
if (!ctx.seenBooks.insert (book_).second)
// Do not allow two books to output the same issue. This may cause offers on
// one step to unfund offers in another step.
if (!ctx.seenBookOuts.insert (book_.out).second ||
ctx.seenDirectIssues[0].count (book_.out))
{
JLOG (j_.debug()) << "BookStep: loop detected: " << *this;
return temBAD_PATH_LOOP;
}
return tesSUCCESS;
}