diff --git a/src/xrpld/app/paths/detail/AMMOffer.cpp b/src/xrpld/app/paths/detail/AMMOffer.cpp index f86293946f2..6b89c453d8b 100644 --- a/src/xrpld/app/paths/detail/AMMOffer.cpp +++ b/src/xrpld/app/paths/detail/AMMOffer.cpp @@ -141,9 +141,6 @@ AMMOffer::checkInvariant( TAmounts const& consumed, beast::Journal j) const { - if (isFeatureEnabled(fixAMMv1_3)) - return true; - if (consumed.in > amounts_.in || consumed.out > amounts_.out) { JLOG(j.error()) << "AMMOffer::checkInvariant failed: consumed " @@ -155,6 +152,10 @@ AMMOffer::checkInvariant( return false; } + // The invariant check below is moved to InvariantCheck + if (isFeatureEnabled(fixAMMv1_3)) + return true; + Number const product = balances_.in * balances_.out; auto const newBalances = TAmounts{ balances_.in + consumed.in, balances_.out - consumed.out}; diff --git a/src/xrpld/app/tx/detail/Offer.h b/src/xrpld/app/tx/detail/Offer.h index a6f707ba561..8f091335d2a 100644 --- a/src/xrpld/app/tx/detail/Offer.h +++ b/src/xrpld/app/tx/detail/Offer.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_BOOK_OFFER_H_INCLUDED #include +#include #include #include #include @@ -169,8 +170,24 @@ class TOffer : private TOfferBase * always returns true. */ bool - checkInvariant(TAmounts const&, beast::Journal j) const + checkInvariant(TAmounts const& consumed, beast::Journal j) const { + if (!isFeatureEnabled(fixAMMv1_3)) + return true; + + if (consumed.in > m_amounts.in || consumed.out > m_amounts.out) + { + // LCOV_EXCL_START + JLOG(j.error()) + << "AMMOffer::checkInvariant failed: consumed " + << to_string(consumed.in) << " " << to_string(consumed.out) + << " amounts " << to_string(m_amounts.in) << " " + << to_string(m_amounts.out); + + return false; + // LCOV_EXCL_STOP + } + return true; } };