From 91eee1a42d1de4ed2b08d800003d15ece0cbbd7f Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Mon, 7 Sep 2015 08:59:16 -0700 Subject: [PATCH] Limit the number of offers that can be consumed during crossing --- src/ripple/app/tx/impl/CreateOffer.cpp | 24 ++++++++++++++++++++++++ src/ripple/app/tx/impl/CreateOffer.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index b13eb0fbe3..469a21bef1 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -224,6 +224,18 @@ CreateOffer::select_path ( return std::make_pair (false, bridged_quality); } +bool +CreateOffer::reachedOfferCrossingLimit (Taker const& taker) const +{ + auto const crossings = + taker.get_direct_crossings () + + (2 * taker.get_bridge_crossings ()); + + // The crossing limit is part of the Ripple protocol and + // changing it is a transaction-processing change. + return crossings >= 850; +} + std::pair CreateOffer::bridged_cross ( Taker& taker, @@ -358,6 +370,12 @@ CreateOffer::bridged_cross ( break; } + if (reachedOfferCrossingLimit (taker)) + { + j_.debug << "The offer crossing limit has been exceeded!"; + break; + } + // Postcondition: If we aren't done, then we *must* have consumed at // least one offer fully. assert (direct_consumed || leg1_consumed || leg2_consumed); @@ -432,6 +450,12 @@ CreateOffer::direct_cross ( break; } + if (reachedOfferCrossingLimit (taker)) + { + j_.debug << "The offer crossing limit has been exceeded!"; + break; + } + // Postcondition: If we aren't done, then we *must* have consumed the // offer on the books fully! assert (direct_consumed); diff --git a/src/ripple/app/tx/impl/CreateOffer.h b/src/ripple/app/tx/impl/CreateOffer.h index 5e4a3a96e2..45b8c82492 100644 --- a/src/ripple/app/tx/impl/CreateOffer.h +++ b/src/ripple/app/tx/impl/CreateOffer.h @@ -97,6 +97,11 @@ private: bool step_account (OfferStream& stream, Taker const& taker); + // True if the number of offers that have been crossed + // exceeds the limit. + bool + reachedOfferCrossingLimit (Taker const& taker) const; + // Fill offer as much as possible by consuming offers already on the books, // and adjusting account balances accordingly. //