mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 20:45:51 +00:00
Convert STAmount switchovers to tls (RIPD-1068)
This commit is contained in:
committed by
Edward Hennis
parent
4fb6bf3e67
commit
14dde47173
@@ -35,6 +35,10 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
LocalValue<bool> stAmountCalcSwitchover(true);
|
||||
using namespace std::chrono_literals;
|
||||
const NetClock::time_point STAmountSO::soTime{504640800s};
|
||||
|
||||
static const std::uint64_t tenTo14 = 100000000000000ull;
|
||||
static const std::uint64_t tenTo14m1 = tenTo14 - 1;
|
||||
static const std::uint64_t tenTo17 = tenTo14 * 1000;
|
||||
@@ -1139,9 +1143,8 @@ canonicalizeRound (bool native, std::uint64_t& value, int& offset, bool roundUp)
|
||||
}
|
||||
|
||||
STAmount
|
||||
mulRound (STAmount const& v1, STAmount const& v2,
|
||||
Issue const& issue, bool roundUp,
|
||||
STAmountCalcSwitchovers const& switchovers)
|
||||
mulRound (STAmount const& v1, STAmount const& v2, Issue const& issue,
|
||||
bool roundUp)
|
||||
{
|
||||
if (v1 == zero || v2 == zero)
|
||||
return {issue};
|
||||
@@ -1205,20 +1208,20 @@ mulRound (STAmount const& v1, STAmount const& v2,
|
||||
canonicalizeRound (
|
||||
isXRP (issue), amount, offset, resultNegative != roundUp);
|
||||
STAmount result (issue, amount, offset, resultNegative);
|
||||
if (switchovers.enableUnderflowFix () && roundUp && !resultNegative && !result)
|
||||
// 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);
|
||||
return STAmount(issue, amount, offset, resultNegative);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
STAmount
|
||||
divRound (STAmount const& num, STAmount const& den,
|
||||
Issue const& issue, bool roundUp,
|
||||
STAmountCalcSwitchovers const& switchovers)
|
||||
Issue const& issue, bool roundUp)
|
||||
{
|
||||
if (den == zero)
|
||||
Throw<std::runtime_error> ("division by zero");
|
||||
@@ -1265,7 +1268,8 @@ divRound (STAmount const& num, STAmount const& den,
|
||||
canonicalizeRound (
|
||||
isXRP (issue), amount, offset, resultNegative != roundUp);
|
||||
STAmount result (issue, amount, offset, resultNegative);
|
||||
if (switchovers.enableUnderflowFix () && roundUp && !resultNegative && !result)
|
||||
// Control when bugfixes that require switchover dates are enabled
|
||||
if (roundUp && !resultNegative && !result && *stAmountCalcSwitchover)
|
||||
{
|
||||
// return the smallest value above zero
|
||||
amount = STAmount::cMinValue;
|
||||
@@ -1275,23 +1279,4 @@ divRound (STAmount const& num, STAmount const& den,
|
||||
return result;
|
||||
}
|
||||
|
||||
NetClock::time_point
|
||||
STAmountCalcSwitchovers::enableUnderflowFixCloseTime ()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
// Mon Dec 28, 2015 10:00:00am PST
|
||||
return NetClock::time_point{504640800s};
|
||||
}
|
||||
|
||||
STAmountCalcSwitchovers::STAmountCalcSwitchovers (NetClock::time_point parentCloseTime)
|
||||
{
|
||||
enableUnderflowFix_ = parentCloseTime > enableUnderflowFixCloseTime();
|
||||
}
|
||||
|
||||
|
||||
bool STAmountCalcSwitchovers::enableUnderflowFix () const
|
||||
{
|
||||
return enableUnderflowFix_;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user