Fix underflow issue for XRP:

When specifying that a result should be rounded up,
the code rounded up to a value suitable for a non-xrp
amount. When called with an xrp amount, if that rounded-up
value was less than one drop, the code rounded down to zero.

This could cause funded offers to be removed as unfunded.
This commit is contained in:
seelabs
2016-02-25 10:07:32 -05:00
committed by Nik Bougalis
parent 7837eed21b
commit 675cbb72a6
3 changed files with 51 additions and 11 deletions

View File

@@ -1207,10 +1207,20 @@ mulRound (STAmount const& v1, STAmount const& v2,
STAmount result (issue, amount, offset, resultNegative);
if (switchovers.enableUnderflowFix () && roundUp && !resultNegative && !result)
{
// return the smallest value above zero
amount = STAmount::cMinValue;
offset = STAmount::cMinOffset;
return STAmount (issue, amount, offset, resultNegative);
if (isXRP(issue) && switchovers.enableUnderflowFix2 ())
{
// return the smallest value above zero
amount = 1;
offset = 0;
return STAmount(issue, amount, offset, resultNegative);
}
else
{
// return the smallest value above zero
amount = STAmount::cMinValue;
offset = STAmount::cMinOffset;
return STAmount(issue, amount, offset, resultNegative);
}
}
return result;
}
@@ -1267,10 +1277,20 @@ divRound (STAmount const& num, STAmount const& den,
STAmount result (issue, amount, offset, resultNegative);
if (switchovers.enableUnderflowFix () && roundUp && !resultNegative && !result)
{
// return the smallest value above zero
amount = STAmount::cMinValue;
offset = STAmount::cMinOffset;
return STAmount (issue, amount, offset, resultNegative);
if (isXRP(issue) && switchovers.enableUnderflowFix2 ())
{
// return the smallest value above zero
amount = 1;
offset = 0;
return STAmount(issue, amount, offset, resultNegative);
}
else
{
// return the smallest value above zero
amount = STAmount::cMinValue;
offset = STAmount::cMinOffset;
return STAmount(issue, amount, offset, resultNegative);
}
}
return result;
}
@@ -1283,9 +1303,18 @@ STAmountCalcSwitchovers::enableUnderflowFixCloseTime ()
return NetClock::time_point{504640800s};
}
NetClock::time_point
STAmountCalcSwitchovers::enableUnderflowFixCloseTime2 ()
{
using namespace std::chrono_literals;
// Fri Feb 26, 2016 9:00:00pm PST
return NetClock::time_point{509864400s};
}
STAmountCalcSwitchovers::STAmountCalcSwitchovers (NetClock::time_point parentCloseTime)
{
enableUnderflowFix_ = parentCloseTime > enableUnderflowFixCloseTime();
enableUnderflowFix2_ = parentCloseTime > enableUnderflowFixCloseTime2();
}
@@ -1294,4 +1323,9 @@ bool STAmountCalcSwitchovers::enableUnderflowFix () const
return enableUnderflowFix_;
}
bool STAmountCalcSwitchovers::enableUnderflowFix2 () const
{
return enableUnderflowFix2_;
}
} // ripple