mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 22:15:52 +00:00
Fix underflow issue for XRP:
In some cases multiplying or dividing STAmounts gave incorrect results. This happens when: 1) The result should be rounded up 2) The STAmount represents a native value (XRP) 3) The rounded up value was less than one drop In this case, the result was zero, instead of one drop. This could cause funded offers to be removed as unfunded.
This commit is contained in:
@@ -36,9 +36,14 @@
|
||||
namespace ripple {
|
||||
|
||||
LocalValue<bool> stAmountCalcSwitchover(true);
|
||||
LocalValue<bool> stAmountCalcSwitchover2(true);
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
const NetClock::time_point STAmountSO::soTime{504640800s};
|
||||
|
||||
// Fri Feb 26, 2016 9:00:00pm PST
|
||||
const NetClock::time_point STAmountSO::soTime2{509864400s};
|
||||
|
||||
static const std::uint64_t tenTo14 = 100000000000000ull;
|
||||
static const std::uint64_t tenTo14m1 = tenTo14 - 1;
|
||||
static const std::uint64_t tenTo17 = tenTo14 * 1000;
|
||||
@@ -1199,9 +1204,18 @@ mulRound (STAmount const& v1, STAmount const& v2, Issue const& issue,
|
||||
// Control when bugfixes that require switchover dates are enabled
|
||||
if (roundUp && !resultNegative && !result && *stAmountCalcSwitchover)
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = STAmount::cMinValue;
|
||||
offset = STAmount::cMinOffset;
|
||||
if (isXRP(issue) && *stAmountCalcSwitchover2)
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = 1;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = STAmount::cMinValue;
|
||||
offset = STAmount::cMinOffset;
|
||||
}
|
||||
return STAmount(issue, amount, offset, resultNegative);
|
||||
}
|
||||
return result;
|
||||
@@ -1259,10 +1273,19 @@ divRound (STAmount const& num, STAmount const& den,
|
||||
// Control when bugfixes that require switchover dates are enabled
|
||||
if (roundUp && !resultNegative && !result && *stAmountCalcSwitchover)
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = STAmount::cMinValue;
|
||||
offset = STAmount::cMinOffset;
|
||||
return STAmount (issue, amount, offset, resultNegative);
|
||||
if (isXRP(issue) && *stAmountCalcSwitchover2)
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = 1;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = STAmount::cMinValue;
|
||||
offset = STAmount::cMinOffset;
|
||||
}
|
||||
return STAmount(issue, amount, offset, resultNegative);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user