Limit the number of offers that can be consumed during crossing

This commit is contained in:
Nik Bougalis
2015-09-07 08:59:16 -07:00
parent 502d5689bf
commit 91eee1a42d
2 changed files with 29 additions and 0 deletions

View File

@@ -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<TER, Amounts>
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);

View File

@@ -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.
//