From 7c2478480d90c3d843ba4aa24b329ad430913c2c Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Thu, 2 Jul 2015 15:10:11 -0700 Subject: [PATCH] DeliverMin enable switch and precheck greater than dest amount --- src/BeastConfig.h | 7 ---- src/ripple/app/tx/impl/Payment.cpp | 39 ++++++++++----------- src/ripple/app/tx/tests/DeliverMin.test.cpp | 15 ++------ src/ripple/test/jtx/Env.h | 16 ++++++--- 4 files changed, 33 insertions(+), 44 deletions(-) diff --git a/src/BeastConfig.h b/src/BeastConfig.h index 38ffdd008b..4bd22f61ad 100644 --- a/src/BeastConfig.h +++ b/src/BeastConfig.h @@ -192,13 +192,6 @@ #define RIPPLE_USE_OPENSSL 0 #endif -/** Config: RIPPLE_ENABLE_DELIVERMIN - Enables processing of delivermin in transactions -*/ -#ifndef RIPPLE_ENABLE_DELIVERMIN -#define RIPPLE_ENABLE_DELIVERMIN 0 -#endif - // Enables the experimental OpenLedger #ifndef RIPPLE_OPEN_LEDGER #define RIPPLE_OPEN_LEDGER 0 diff --git a/src/ripple/app/tx/impl/Payment.cpp b/src/ripple/app/tx/impl/Payment.cpp index 6adde54d50..cb6630519e 100644 --- a/src/ripple/app/tx/impl/Payment.cpp +++ b/src/ripple/app/tx/impl/Payment.cpp @@ -28,6 +28,16 @@ namespace ripple { // See https://ripple.com/wiki/Transaction_Format#Payment_.280.29 +// Mon Aug 3 11:00:00am PDT +static std::uint32_t const deliverMinTime = 491940000; + +bool +allowDeliverMin (ApplyView const& view) +{ + return view.info().parentCloseTime > deliverMinTime || + (view.flags() & tapENABLE_TESTING); +} + TER Payment::preCheck () { @@ -45,12 +55,6 @@ Payment::preCheck () bool const defaultPathsAllowed = !(uTxFlags & tfNoRippleDirect); bool const bPaths = mTxn.isFieldPresent (sfPaths); bool const bMax = mTxn.isFieldPresent (sfSendMax); - bool const deliverMin = -#if RIPPLE_ENABLE_DELIVERMIN -#else - (view().flags() & tapENABLE_TESTING) && -#endif - mTxn.isFieldPresent(sfDeliverMin); STAmount const saDstAmount (mTxn.getFieldAmount (sfAmount)); @@ -145,12 +149,11 @@ Payment::preCheck () "No ripple direct specified for XRP to XRP."; return temBAD_SEND_XRP_NO_DIRECT; } - if (deliverMin) + + if (mTxn.isFieldPresent(sfDeliverMin)) { - #if ! RIPPLE_ENABLE_DELIVERMIN - if (! (view().flags() & tapENABLE_TESTING)) + if (! allowDeliverMin(view())) return temMALFORMED; - #endif if (! partialPaymentAllowed) { @@ -160,7 +163,7 @@ Payment::preCheck () } auto const dMin = mTxn.getFieldAmount(sfDeliverMin); - if (!isLegalNet(dMin) || dMin <= zero) + if (! isLegalNet(dMin) || dMin <= zero) { j_.trace << "Malformed transaction: Invalid " << jss::DeliverMin.c_str() << " amount. " << @@ -174,11 +177,9 @@ Payment::preCheck () dMin.getFullText(); return temBAD_AMOUNT; } - if (bMax && - (dMin.getCurrency() == maxSourceAmount.getCurrency() && - dMin > maxSourceAmount)) + if (dMin > saDstAmount) { - j_.trace << "Malformed transaction: SendMax less than " << + j_.trace << "Malformed transaction: Dst amount less than " << jss::DeliverMin.c_str() << ". " << dMin.getFullText(); return temBAD_AMOUNT; @@ -198,12 +199,8 @@ Payment::doApply () bool const defaultPathsAllowed = !(uTxFlags & tfNoRippleDirect); bool const bPaths = mTxn.isFieldPresent (sfPaths); bool const bMax = mTxn.isFieldPresent (sfSendMax); - bool const deliverMin = -#if RIPPLE_ENABLE_DELIVERMIN -#else - (view().flags() & tapENABLE_TESTING) && -#endif - mTxn.isFieldPresent(sfDeliverMin); + bool const deliverMin = mTxn.isFieldPresent(sfDeliverMin) && + allowDeliverMin(view()); AccountID const uDstAccountID (mTxn.getAccountID (sfDestination)); STAmount const saDstAmount (mTxn.getFieldAmount (sfAmount)); diff --git a/src/ripple/app/tx/tests/DeliverMin.test.cpp b/src/ripple/app/tx/tests/DeliverMin.test.cpp index f4764a089c..6c585babaf 100644 --- a/src/ripple/app/tx/tests/DeliverMin.test.cpp +++ b/src/ripple/app/tx/tests/DeliverMin.test.cpp @@ -49,23 +49,14 @@ public: delivermin(Account("carol")["USD"](5)), txflags(tfPartialPayment), ter(temBAD_AMOUNT)); env(pay("alice", "bob", USD(10)), delivermin(USD(15)), - txflags(tfPartialPayment), ter(tecPATH_DRY)); - env(pay("alice", "bob", USD(10)), - delivermin(USD(10)), txflags(tfPartialPayment), - sendmax(USD(9)), ter(temBAD_AMOUNT)); + txflags(tfPartialPayment), ter(temBAD_AMOUNT)); env(pay(gw, "carol", USD(50))); env(offer("carol", XRP(5), USD(5))); env(pay("alice", "bob", USD(10)), paths(XRP), delivermin(USD(7)), txflags(tfPartialPayment), - sendmax(XRP(20)), ter(tecPATH_PARTIAL)); - env.require(balance("alice", XRP(9999.99998))); + sendmax(XRP(5)), ter(tecPATH_PARTIAL)); + env.require(balance("alice", XRP(9999.99999))); env.require(balance("bob", XRP(10000))); - - // DeliverMin greater than destination amount - env(pay("alice", "bob", USD(5)), paths(XRP), - delivermin(USD(50)), txflags(tfPartialPayment), - sendmax(XRP(5))); - env.require(balance("bob", USD(5))); } { diff --git a/src/ripple/test/jtx/Env.h b/src/ripple/test/jtx/Env.h index 893220f811..efaa633d72 100644 --- a/src/ripple/test/jtx/Env.h +++ b/src/ripple/test/jtx/Env.h @@ -162,7 +162,7 @@ public: open ledger at the moment of the call. Transactions applied after the call to open() will not be visible. - + */ std::shared_ptr open() const; @@ -220,18 +220,25 @@ public: With no arguments, trace all */ void - trace(int howMany = -1) + trace (int howMany = -1) { trace_ = howMany; } /** Turn off JSON tracing. */ void - notrace() + notrace () { trace_ = 0; } + /** Turn off testing. */ + void + disable_testing () + { + testing_ = false; + } + /** Associate AccountID with account. */ void memoize (Account const& account); @@ -305,7 +312,7 @@ public: } /** Check a set of requirements. - + The requirements are formed from condition functors. */ @@ -444,6 +451,7 @@ public: protected: int trace_ = 0; + bool testing_ = true; void autofill_sig (JTx& jt);