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

@@ -226,14 +226,14 @@ toStrand (
*/
std::array<boost::container::flat_set<Issue>, 2> seenDirectIssues;
// A strand may not include the same offer book more than once
boost::container::flat_set<Book> seenBooks;
boost::container::flat_set<Issue> seenBookOuts;
seenDirectIssues[0].reserve (pes.size());
seenDirectIssues[1].reserve (pes.size());
seenBooks.reserve (pes.size());
seenBookOuts.reserve (pes.size());
auto ctx = [&](bool isLast = false)
{
return StrandContext{view, result, strandSrc, strandDst, isLast,
seenDirectIssues, seenBooks, j};
seenDirectIssues, seenBookOuts, j};
};
for (int i = 0; i < pes.size () - 1; ++i)
@@ -456,7 +456,7 @@ StrandContext::StrandContext (
AccountID strandDst_,
bool isLast_,
std::array<boost::container::flat_set<Issue>, 2>& seenDirectIssues_,
boost::container::flat_set<Book>& seenBooks_,
boost::container::flat_set<Issue>& seenBookOuts_,
beast::Journal j_)
: view (view_)
, strandSrc (strandSrc_)
@@ -467,7 +467,7 @@ StrandContext::StrandContext (
, prevStep (!strand_.empty () ? strand_.back ().get ()
: nullptr)
, seenDirectIssues(seenDirectIssues_)
, seenBooks(seenBooks_)
, seenBookOuts(seenBookOuts_)
, j (j_)
{
}