mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
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:
@@ -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_)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user