From 11c4ca00d59141fdc82a86ff01f395179326494b Mon Sep 17 00:00:00 2001 From: seelabs Date: Mon, 6 Jun 2016 09:24:06 -0400 Subject: [PATCH] Put flowV2 on an amendment only --- src/ripple/app/paths/RippleCalc.cpp | 3 +- src/ripple/app/paths/cursor/AdvanceNode.cpp | 2 +- .../app/paths/cursor/DeliverNodeReverse.cpp | 2 +- src/ripple/app/tests/Flow_test.cpp | 41 +++++++++---------- src/ripple/ledger/View.h | 8 ++-- src/ripple/ledger/impl/PaymentSandbox.cpp | 2 +- src/ripple/ledger/impl/View.cpp | 25 +++-------- .../ledger/tests/PaymentSandbox_test.cpp | 6 +-- 8 files changed, 36 insertions(+), 53 deletions(-) diff --git a/src/ripple/app/paths/RippleCalc.cpp b/src/ripple/app/paths/RippleCalc.cpp index 7d6a6fda21..8e5b26cade 100644 --- a/src/ripple/app/paths/RippleCalc.cpp +++ b/src/ripple/app/paths/RippleCalc.cpp @@ -76,7 +76,6 @@ RippleCalc::Output RippleCalc::rippleCalculate ( view.rules ().enabled (featureCompareFlowV1V2, config.features); bool const useFlowV1Output = - !flowV2Switchover (view.info ().parentCloseTime) && !view.rules ().enabled (featureFlowV2, config.features); bool const callFlowV1 = useFlowV1Output || compareFlowV1V2; bool const callFlowV2 = !useFlowV1Output || compareFlowV1V2; @@ -331,7 +330,7 @@ TER RippleCalc::rippleCalculate (detail::FlowDebugInfo* flowDebugInfo) boost::container::flat_set unfundedOffersFromBestPaths; int iPass = 0; - auto const dcSwitch = dcSwitchover(view.info().parentCloseTime); + auto const dcSwitch = amendmentRIPD1141(view.info().parentCloseTime); while (resultCode == temUNCERTAIN) { diff --git a/src/ripple/app/paths/cursor/AdvanceNode.cpp b/src/ripple/app/paths/cursor/AdvanceNode.cpp index c6f904f9b9..c37d7dc750 100644 --- a/src/ripple/app/paths/cursor/AdvanceNode.cpp +++ b/src/ripple/app/paths/cursor/AdvanceNode.cpp @@ -27,7 +27,7 @@ namespace path { TER PathCursor::advanceNode (STAmount const& amount, bool reverse, bool callerHasLiquidity) const { - bool const multi = dcSwitchover (view ().info ().parentCloseTime) + bool const multi = amendmentRIPD1141 (view ().info ().parentCloseTime) ? (multiQuality_ || (!callerHasLiquidity && amount == zero)) : (multiQuality_ || amount == zero); diff --git a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp index e59aef6bef..4420db9f8a 100644 --- a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp +++ b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp @@ -255,7 +255,7 @@ TER PathCursor::deliverNodeReverseImpl ( saInPassAct, saOutAct > zero); - if (dcSwitchover(view().info().parentCloseTime)) + if (amendmentRIPD1141(view().info().parentCloseTime)) { // The recursive call is dry this time, but we have liquidity // from previous calls diff --git a/src/ripple/app/tests/Flow_test.cpp b/src/ripple/app/tests/Flow_test.cpp index 72f32034af..7cf83d3bf0 100644 --- a/src/ripple/app/tests/Flow_test.cpp +++ b/src/ripple/app/tests/Flow_test.cpp @@ -913,7 +913,7 @@ struct Flow_test : public beast::unit_test::suite Account const bob ("bob"); Account const carol ("carol"); - auto const closeTime = dcSoTime() + + auto const closeTime = amendmentRIPD1141SoTime() + 100 * env.closed ()->info ().closeTimeResolution; env.close (closeTime); @@ -977,30 +977,27 @@ struct Flow_test : public beast::unit_test::suite auto const timeDelta = Env{*this}.closed ()->info ().closeTimeResolution; - for(auto const& t :{dcSoTime(), flowV2SoTime()}){ - for(auto const& d: {-timeDelta*100, +timeDelta*100}){ - auto const closeTime = t+d; - Env env (*this); - env.close (closeTime); + for(auto const& d: {-timeDelta*100, +timeDelta*100}){ + auto const closeTime = amendmentRIPD1141SoTime () + d; + Env env (*this); + env.close (closeTime); - env.fund (XRP(10000), alice, bob, carol, gw); + env.fund (XRP(10000), alice, bob, carol, gw); - env.trust (USD(100), alice, bob, carol); - env (pay (gw, bob, USD (100))); - env (offer (bob, XRP (50), USD (50))); - env (offer (bob, XRP (100), USD (50))); + env.trust (USD(100), alice, bob, carol); + env (pay (gw, bob, USD (100))); + env (offer (bob, XRP (50), USD (50))); + env (offer (bob, XRP (100), USD (50))); - auto expectedResult = - closeTime < dcSoTime () ? tecPATH_DRY : tesSUCCESS; - env (pay (alice, carol, USD (100)), path (~USD), sendmax (XRP (100)), - txflags (tfNoRippleDirect | tfPartialPayment | tfLimitQuality), - ter (expectedResult)); + auto expectedResult = + closeTime < amendmentRIPD1141SoTime () ? tecPATH_DRY : tesSUCCESS; + env (pay (alice, carol, USD (100)), path (~USD), sendmax (XRP (100)), + txflags (tfNoRippleDirect | tfPartialPayment | tfLimitQuality), + ter (expectedResult)); - if (expectedResult == tesSUCCESS) - env.require (balance (carol, USD (50))); - } + if (expectedResult == tesSUCCESS) + env.require (balance (carol, USD (50))); } - } // Helper function that returns the reserve on an account based on @@ -1045,7 +1042,7 @@ struct Flow_test : public beast::unit_test::suite Env env (*this, features (featureFlowV2)); auto const closeTime = - flowV2SoTime () + 100 * env.closed ()->info ().closeTimeResolution; + amendmentRIPD1141SoTime () + 100 * env.closed ()->info ().closeTimeResolution; env.close (closeTime); env.fund (XRP (1000000), gw1, gw2); @@ -1119,7 +1116,7 @@ struct Flow_test : public beast::unit_test::suite Env env (*this, features (featureFlowV2)); auto const closeTime = - flowV2SoTime () + 100 * env.closed ()->info ().closeTimeResolution; + amendmentRIPD1141SoTime () + 100 * env.closed ()->info ().closeTimeResolution; env.close (closeTime); env.fund (XRP (1000000), gw1, gw2); diff --git a/src/ripple/ledger/View.h b/src/ripple/ledger/View.h index 23b49a5432..78f02c1b96 100644 --- a/src/ripple/ledger/View.h +++ b/src/ripple/ledger/View.h @@ -340,11 +340,11 @@ transferXRP (ApplyView& view, STAmount const& amount, beast::Journal j); -NetClock::time_point const& flowV2SoTime (); -bool flowV2Switchover (NetClock::time_point const closeTime); +NetClock::time_point const& amendmentRIPD1141SoTime (); +bool amendmentRIPD1141 (NetClock::time_point const closeTime); -NetClock::time_point const& dcSoTime (); -bool dcSwitchover (NetClock::time_point const closeTime); +NetClock::time_point const& amendmentRIPD1141SoTime (); +bool amendmentRIPD1141 (NetClock::time_point const closeTime); } // ripple diff --git a/src/ripple/ledger/impl/PaymentSandbox.cpp b/src/ripple/ledger/impl/PaymentSandbox.cpp index 0bf61018ce..0aae98d7e9 100644 --- a/src/ripple/ledger/impl/PaymentSandbox.cpp +++ b/src/ripple/ledger/impl/PaymentSandbox.cpp @@ -179,7 +179,7 @@ PaymentSandbox::balanceHook (AccountID const& account, */ auto const currency = amount.getCurrency (); - auto const switchover = flowV2Switchover (info ().parentCloseTime); + auto const switchover = amendmentRIPD1141 (info ().parentCloseTime); auto adjustedAmt = amount; if (switchover) diff --git a/src/ripple/ledger/impl/View.cpp b/src/ripple/ledger/impl/View.cpp index 78cda24dfb..1ed1e4f51e 100644 --- a/src/ripple/ledger/impl/View.cpp +++ b/src/ripple/ledger/impl/View.cpp @@ -31,7 +31,7 @@ namespace ripple { -NetClock::time_point const& flowV2SoTime () +NetClock::time_point const& amendmentRIPD1141SoTime () { using namespace std::chrono_literals; // Wed May 26, 2016 07:00:00am PDT @@ -39,22 +39,9 @@ NetClock::time_point const& flowV2SoTime () return soTime; } -bool flowV2Switchover (NetClock::time_point const closeTime) +bool amendmentRIPD1141 (NetClock::time_point const closeTime) { - return closeTime > flowV2SoTime(); -} - -NetClock::time_point const& dcSoTime () -{ - using namespace std::chrono_literals; - // Mon May 23, 2016 10:00:00am PDT - static NetClock::time_point const soTime{517338000s}; - return soTime; -} - -bool dcSwitchover (NetClock::time_point const closeTime) -{ - return closeTime > dcSoTime(); + return closeTime > amendmentRIPD1141SoTime(); } // VFALCO NOTE A copy of the other one for now @@ -134,7 +121,7 @@ accountHolds (ReadView const& view, if (isXRP(currency)) { // XRP: return balance minus reserve - if (dcSwitchover (view.info ().parentCloseTime)) + if (amendmentRIPD1141 (view.info ().parentCloseTime)) { auto const sle = view.read( keylet::account(account)); @@ -1429,7 +1416,7 @@ rippleSend (ApplyView& view, // Calculate the amount to transfer accounting // for any transfer fees: - if (!flowV2Switchover (view.info ().parentCloseTime)) + if (!amendmentRIPD1141 (view.info ().parentCloseTime)) { STAmount const saTransitFee = rippleTransferFee ( view, uSenderID, uReceiverID, issuer, saAmount, j); @@ -1485,7 +1472,7 @@ accountSend (ApplyView& view, return rippleSend (view, uSenderID, uReceiverID, saAmount, saActual, j); } - auto const fv2Switch = flowV2Switchover (view.info ().parentCloseTime); + auto const fv2Switch = amendmentRIPD1141 (view.info ().parentCloseTime); if (!fv2Switch) { auto const dummyBalance = saAmount.zeroed(); diff --git a/src/ripple/ledger/tests/PaymentSandbox_test.cpp b/src/ripple/ledger/tests/PaymentSandbox_test.cpp index abbbf4ceb5..0ece1350e9 100644 --- a/src/ripple/ledger/tests/PaymentSandbox_test.cpp +++ b/src/ripple/ledger/tests/PaymentSandbox_test.cpp @@ -280,12 +280,12 @@ class PaymentSandbox_test : public beast::unit_test::suite for (auto timeDelta : {-env.closed ()->info ().closeTimeResolution, env.closed ()->info ().closeTimeResolution}) { - auto const closeTime = flowV2SoTime () + timeDelta; + auto const closeTime = amendmentRIPD1141SoTime () + timeDelta; env.close (closeTime); ApplyViewImpl av (&*env.current (), tapNONE); PaymentSandbox pv (&av); pv.creditHook (gw, alice, hugeAmt, -tinyAmt); - if (closeTime > flowV2SoTime ()) + if (closeTime > amendmentRIPD1141SoTime ()) expect (pv.balanceHook (alice, gw, hugeAmt) == tinyAmt); else expect (pv.balanceHook (alice, gw, hugeAmt) != tinyAmt); @@ -315,7 +315,7 @@ class PaymentSandbox_test : public beast::unit_test::suite Account const alice ("alice"); env.fund (reserve(env, 1), alice); - auto const closeTime = dcSoTime () + + auto const closeTime = amendmentRIPD1141SoTime () + 100 * env.closed ()->info ().closeTimeResolution; env.close (closeTime); ApplyViewImpl av (&*env.current (), tapNONE);