Fix unfunded offer not removed (RIPD-1298):

If the mantissas of two non-native amounts differ by less than 10, then
subtracting them leaves a result of zero. This can cause situations
where `a>b`, yet `a-b == 0`.

One consequence of this is unfunded offers were incorrectly left in
order books. The code would check if the offer would be
consumed (`amount in offer > amount needed`), assume it wouldn't be,
yet when `amount needed` was subtracted from `amount in offer` the
result was zero and the offer was unfunded. This unfunded offer
incorrectly remained on the order book.

This patch fixes this bug.
This commit is contained in:
seelabs
2016-09-16 11:19:51 -04:00
committed by Vinnie Falco
parent 3b639afac2
commit bb0b97f46b
4 changed files with 109 additions and 6 deletions

View File

@@ -412,7 +412,15 @@ BookStep<TIn, TOut>::revImp (
result.in = sum(savedIns);
result.out = out;
this->consumeOffer (sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
return false;
// When the mantissas of two iou amounts differ by less than ten, then
// subtracting them leaves a result of zero. This can cause the check for
// (stpAmt.out > remainingOut) to incorrectly think an offer will be funded
// after subtracting remainingIn.
if (amendmentRIPD1298(sb.parentCloseTime()))
return offer.fully_consumed();
else
return false;
}
};
@@ -561,6 +569,14 @@ BookStep<TIn, TOut>::fwdImp (
remainingIn = in - result.in;
this->consumeOffer (sb, offer, ofrAdjAmt, stpAdjAmt, ownerGivesAdj);
// When the mantissas of two iou amounts differ by less than ten, then
// subtracting them leaves a result of zero. This can cause the check for
// (stpAmt.in > remainingIn) to incorrectly think an offer will be funded
// after subtracting remainingIn.
if (amendmentRIPD1298(sb.parentCloseTime()))
processMore = processMore || offer.fully_consumed();
return processMore;
};