Skip to content

Commit

Permalink
Remove STAmountSO::soTime and soTime2:
Browse files Browse the repository at this point in the history
STAmount::soTime and soTime2 were time based "amendment like"
switches to control small changes in behavior for STAmount.
soTime2, which was the most recent, was dated Feb 27, 2016.
That's over 3 years ago.

The main reason to retain these soTimes would be to replay
old transactions.  The likelihood of needing to replay a
transaction from over three years ago is pretty low.  So it
makes sense to remove these soTime values.

In Flow_test the testZeroOutputStep() test is removed.  That
test started to fail when the STAmount::soTimes were removed.
I checked with the original author of the test.  He said
that the code being tested by that unit test has been removed,
so it makes sense to remove the test.  That test is removed.
  • Loading branch information
scottschurr authored and manojsdoshi committed Jan 30, 2020
1 parent f7fffee commit fc0a082
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 199 deletions.
16 changes: 1 addition & 15 deletions src/ripple/app/misc/impl/TxQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ TxQ::MaybeTx::MaybeTx(
std::pair<TER, bool>
TxQ::MaybeTx::apply(Application& app, OpenView& view, beast::Journal j)
{
boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);
// If the rules or flags change, preflight again
assert(pfresult);
if (pfresult->rules != view.rules() ||
Expand Down Expand Up @@ -539,13 +536,7 @@ TxQ::tryClearAccountQueue(Application& app, OpenView& view,
}
// Apply the current tx. Because the state of the view has been changed
// by the queued txs, we also need to preclaim again.
auto txResult = [&]{
boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);
auto const pcresult = preclaim(pfresult, app, view);
return doApply(pcresult, app, view);
}();
auto const txResult = doApply (preclaim (pfresult, app, view), app, view);

if (txResult.second)
{
Expand Down Expand Up @@ -630,11 +621,6 @@ TxQ::apply(Application& app, OpenView& view,
auto const account = (*tx)[sfAccount];
auto const transactionID = tx->getTransactionID();
auto const tSeq = tx->getSequence();

boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);

// See if the transaction is valid, properly formed,
// etc. before doing potentially expensive queue
// replace and multi-transaction operations.
Expand Down
8 changes: 0 additions & 8 deletions src/ripple/app/paths/cursor/DeliverNodeReverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,6 @@ TER PathCursor::deliverNodeReverseImpl (
// Compute portion of input needed to cover actual output.
auto outputFee = mulRound (
saOutPassAct, node().saOfrRate, node().saTakerPays.issue (), true);
if (*stAmountCalcSwitchover == false && ! outputFee)
{
JLOG (j_.fatal())
<< "underflow computing outputFee "
<< "saOutPassAct: " << saOutPassAct
<< " saOfrRate: " << node ().saOfrRate;
return telFAILED_PROCESSING;
}
STAmount saInPassReq = std::min (node().saTakerPays, outputFee);
STAmount saInPassAct;

Expand Down
1 change: 0 additions & 1 deletion src/ripple/app/tx/impl/apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ apply (Application& app, OpenView& view,
STTx const& tx, ApplyFlags flags,
beast::Journal j)
{
STAmountSO saved(view.info().parentCloseTime);
auto pfresult = preflight(app, view.rules(), tx, flags, j);
auto pcresult = preclaim(pfresult, app, view);
return doApply(pcresult, app, view);
Expand Down
35 changes: 0 additions & 35 deletions src/ripple/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
#ifndef RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED
#define RIPPLE_PROTOCOL_STAMOUNT_H_INCLUDED

#include <ripple/basics/chrono.h>
#include <ripple/basics/IOUAmount.h>
#include <ripple/basics/LocalValue.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/protocol/SField.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/STBase.h>
#include <ripple/protocol/Issue.h>
#include <memory>

namespace ripple {

Expand Down Expand Up @@ -406,38 +403,6 @@ inline bool isXRP(STAmount const& amount)
return isXRP (amount.issue().currency);
}

extern LocalValue<bool> stAmountCalcSwitchover;
extern LocalValue<bool> stAmountCalcSwitchover2;

/** RAII class to set and restore the STAmount calc switchover.*/
class STAmountSO
{
public:
explicit STAmountSO(NetClock::time_point const closeTime)
: saved_(*stAmountCalcSwitchover)
, saved2_(*stAmountCalcSwitchover2)
{
*stAmountCalcSwitchover = closeTime > soTime;
*stAmountCalcSwitchover2 = closeTime > soTime2;
}

~STAmountSO()
{
*stAmountCalcSwitchover = saved_;
*stAmountCalcSwitchover2 = saved2_;
}

// Mon Dec 28, 2015 18:00:00 UTC
static NetClock::time_point const soTime;

// Sat Feb 27, 2016 05:00:00 UTC
static NetClock::time_point const soTime2;

private:
bool saved_;
bool saved2_;
};

} // ripple

#endif
21 changes: 4 additions & 17 deletions src/ripple/protocol/impl/STAmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@

namespace ripple {

LocalValue<bool> stAmountCalcSwitchover(true);
LocalValue<bool> stAmountCalcSwitchover2(true);

using namespace std::chrono_literals;

// Mon Dec 28, 2015 18:00:00 UTC
const NetClock::time_point STAmountSO::soTime{504640800s};

// Sat Feb 27, 2016 05:00:00 UTC
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;
Expand Down Expand Up @@ -1246,10 +1235,9 @@ mulRound (STAmount const& v1, STAmount const& v2, Issue const& issue,
canonicalizeRound (xrp, amount, offset);
STAmount result (issue, amount, offset, resultNegative);

// Control when bugfixes that require switchover dates are enabled
if (roundUp && !resultNegative && !result && *stAmountCalcSwitchover)
if (roundUp && !resultNegative && !result)
{
if (xrp && *stAmountCalcSwitchover2)
if (xrp)
{
// return the smallest value above zero
amount = 1;
Expand Down Expand Up @@ -1318,10 +1306,9 @@ divRound (STAmount const& num, STAmount const& den,
canonicalizeRound (isXRP (issue), amount, offset);

STAmount result (issue, amount, offset, resultNegative);
// Control when bugfixes that require switchover dates are enabled
if (roundUp && !resultNegative && !result && *stAmountCalcSwitchover)
if (roundUp && !resultNegative && !result)
{
if (isXRP(issue) && *stAmountCalcSwitchover2)
if (isXRP(issue))
{
// return the smallest value above zero
amount = 1;
Expand Down
40 changes: 0 additions & 40 deletions src/test/app/Flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,6 @@ struct Flow_test : public beast::unit_test::suite
// pass. This test checks that the payment produces 1 EUR, as expected.

Env env (*this, features);

auto const closeTime = STAmountSO::soTime2 +
100 * env.closed ()->info ().closeTimeResolution;
env.close (closeTime);

env.fund (XRP (10000), alice, bob, carol, gw);
env.trust (USD (1000), alice, bob, carol);
env.trust (EUR (1000), alice, bob, carol);
Expand Down Expand Up @@ -1249,40 +1244,6 @@ struct Flow_test : public beast::unit_test::suite
ter(temBAD_PATH));
}

void
testZeroOutputStep()
{
testcase("Zero Output Step");

using namespace jtx;
auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const gw = Account("gw");
auto const USD = gw["USD"];
auto const EUR = gw["EUR"];

auto const features = supported_amendments();
Env env(*this, features);
env.fund(XRP(10000), alice, bob, carol, gw);
env.trust(USD(1000), alice, bob, carol);
env.trust(EUR(1000), alice, bob, carol);
env(pay(gw, alice, USD(100)));
env(pay(gw, bob, USD(100)));
env(pay(gw, bob, EUR(100)));
env.close();

env(offer(bob, USD(100), EUR(100)));
env(offer(bob, EUR(100), XRP(0.000001)));
env.close();

env(pay(alice, carol, XRP(1)),
path(~EUR, ~XRP),
sendmax(USD(1)),
txflags(tfPartialPayment),
ter(tecPATH_DRY));
}

void testWithFeats(FeatureBitset features)
{
using namespace jtx;
Expand Down Expand Up @@ -1311,7 +1272,6 @@ struct Flow_test : public beast::unit_test::suite
void run() override
{
testLimitQuality();
testZeroOutputStep();
testRIPD1443(true);
testRIPD1443(false);
testRIPD1449(true);
Expand Down
120 changes: 37 additions & 83 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,7 @@ class Offer_test : public beast::unit_test::suite
for (int i=0;i<101;++i)
env (offer (carol, USD (1), EUR (2)));

auto hasFeature = [](Env& e, uint256 const& f)
{
return (e.app().config().features.find(f) !=
e.app().config().features.end());
};

for (auto d : {-1, 1})
{
auto const closeTime = STAmountSO::soTime +
d * env.closed()->info().closeTimeResolution;
env.close (closeTime);
*stAmountCalcSwitchover = closeTime > STAmountSO::soTime ||
!hasFeature(env, fix1513);
// Will fail without the underflow fix
TER const expectedResult = *stAmountCalcSwitchover ?
TER {tesSUCCESS} : TER {tecPATH_PARTIAL};
env (pay (alice, bob, EUR (epsilon)), path (~EUR),
sendmax (USD (100)), ter (expectedResult));
}
env (pay (alice, bob, EUR (epsilon)), path (~EUR), sendmax (USD (100)));
}

void testXRPTinyPayment (FeatureBitset features)
Expand Down Expand Up @@ -324,74 +306,46 @@ class Offer_test : public beast::unit_test::suite
auto const gw = Account {"gw"};

auto const USD = gw["USD"];
Env env {*this, features};

for (auto withFix : {false, true})
{
if (!withFix)
continue;

Env env {*this, features};
env.fund (XRP (10000), alice, bob, carol, dan, erin, gw);
env.trust (USD (1000), alice, bob, carol, dan, erin);
env (pay (gw, carol, USD (0.99999)));
env (pay (gw, dan, USD (1)));
env (pay (gw, erin, USD (1)));

// Carol doesn't quite have enough funds for this offer
// The amount left after this offer is taken will cause
// STAmount to incorrectly round to zero when the next offer
// (at a good quality) is considered. (when the
// stAmountCalcSwitchover2 patch is inactive)
env (offer (carol, drops (1), USD (1)));
// Offer at a quality poor enough so when the input xrp is
// calculated in the reverse pass, the amount is not zero.
env (offer (dan, XRP (100), USD (1)));

auto closeTime = [&]
{
auto const delta =
100 * env.closed ()->info ().closeTimeResolution;
if (withFix)
return STAmountSO::soTime2 + delta;
else
return STAmountSO::soTime2 - delta;
}();

env.fund (XRP (10000), alice, bob, carol, dan, erin, gw);
env.trust (USD (1000), alice, bob, carol, dan, erin);
env (pay (gw, carol, USD (0.99999)));
env (pay (gw, dan, USD (1)));
env (pay (gw, erin, USD (1)));

// Carol doesn't quite have enough funds for this offer
// The amount left after this offer is taken will cause
// STAmount to incorrectly round to zero when the next offer
// (at a good quality) is considered. (when the
// stAmountCalcSwitchover2 patch is inactive)
env (offer (carol, drops (1), USD (1)));
// Offer at a quality poor enough so when the input xrp is
// calculated in the reverse pass, the amount is not zero.
env (offer (dan, XRP (100), USD (1)));
env.close ();
// This is the funded offer that will be incorrectly removed.
// It is considered after the offer from carol, which leaves a
// tiny amount left to pay. When calculating the amount of xrp
// needed for this offer, it will incorrectly compute zero in both
// the forward and reverse passes (when the stAmountCalcSwitchover2
// is inactive.)
env (offer (erin, drops (1), USD (1)));

env (pay (alice, bob, USD (1)), path (~USD),
sendmax (XRP (102)),
txflags (tfNoRippleDirect | tfPartialPayment));

env.close (closeTime);
// This is the funded offer that will be incorrectly removed.
// It is considered after the offer from carol, which leaves a
// tiny amount left to pay. When calculating the amount of xrp
// needed for this offer, it will incorrectly compute zero in both
// the forward and reverse passes (when the stAmountCalcSwitchover2
// is inactive.)
env (offer (erin, drops (1), USD (1)));
env.require (
offers (carol, 0),
offers (dan, 1));

{
env (pay (alice, bob, USD (1)), path (~USD),
sendmax (XRP (102)),
txflags (tfNoRippleDirect | tfPartialPayment));

env.require (
offers (carol, 0),
offers (dan, 1));
if (!withFix)
{
// funded offer was removed
env.require (
balance (erin, USD (1)),
offers (erin, 0));
}
else
{
// offer was correctly consumed. There is still some
// liquidity left on that offer.
env.require (
balance (erin, USD (0.99999)),
offers (erin, 1));
}
}
}
// offer was correctly consumed. There is still some
// liquidity left on that offer.
env.require (
balance (erin, USD (0.99999)),
offers (erin, 1));
}

void testEnforceNoRipple (FeatureBitset features)
Expand Down

0 comments on commit fc0a082

Please sign in to comment.