-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rm some offers where the quality is reduced #3827
Changes from 2 commits
e1bf2c9
8ad2fd5
9b8c050
d77ad06
a06ca4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
#include <ripple/app/tx/impl/OfferStream.h> | ||
#include <ripple/basics/Log.h> | ||
#include <ripple/protocol/Feature.h> | ||
|
||
namespace ripple { | ||
|
||
|
@@ -132,6 +133,74 @@ accountFundsHelper( | |
view, id, issue.currency, issue.account, freezeHandling, j)); | ||
} | ||
|
||
template <class TIn, class TOut> | ||
template <class TTakerPays, class TTakerGets> | ||
bool | ||
TOfferStreamBase<TIn, TOut>::shouldRmSmallIncreasedQOffer() const | ||
{ | ||
static_assert( | ||
std::is_same_v<TTakerPays, IOUAmount> || | ||
std::is_same_v<TTakerPays, XRPAmount>, | ||
""); | ||
|
||
static_assert( | ||
std::is_same_v<TTakerGets, IOUAmount> || | ||
std::is_same_v<TTakerGets, XRPAmount>, | ||
""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
|
||
static_assert( | ||
!std::is_same_v<TTakerPays, XRPAmount> || | ||
!std::is_same_v<TTakerGets, XRPAmount>, | ||
"Cannot have XRP/XRP offers"); | ||
|
||
if (!view_.rules().enabled(fixRmSmallIncreasedQOffers)) | ||
return false; | ||
|
||
// Consider removing the offer if `TakerPays` is XRP or `TakerPays` and | ||
// `TakerGets` are both IOU and `TakerPays` < `TakerGets` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took quite a while for me to make sense out the comment regarding IOUs. Everything here is correct, but the consequences did not jump out at me. Consider rewriting the comment something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
constexpr bool const inIsXRP = std::is_same_v<TTakerPays, XRPAmount>; | ||
constexpr bool const outIsXRP = std::is_same_v<TTakerGets, XRPAmount>; | ||
|
||
if (outIsXRP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
{ | ||
// If `TakerGets` is XRP, worse this offer's quality can change is to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly, "worse" -> "the worst"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
// about 10^-81 `TakerPays` and 1 drop `TakerGets`. This will be | ||
// remarkably good quality for any realistic asset, so these offers | ||
// don't need this extra check. | ||
return false; | ||
} | ||
|
||
TAmounts<TTakerPays, TTakerGets> const ofrAmts{ | ||
toAmount<TTakerPays>(offer_.amount().in), | ||
toAmount<TTakerGets>(offer_.amount().out)}; | ||
|
||
if constexpr (!inIsXRP && !outIsXRP) | ||
{ | ||
if (ofrAmts.in >= ofrAmts.out) | ||
return false; | ||
} | ||
|
||
TTakerGets const ownerFunds = toAmount<TTakerGets>(*ownerFunds_); | ||
|
||
auto const effectiveAmounts = [&] { | ||
if (offer_.owner() != offer_.issueOut().account && | ||
ownerFunds < ofrAmts.out) | ||
{ | ||
// adjust the amounts by owner funds | ||
return offer_.quality().ceil_out(ofrAmts, ownerFunds); | ||
} | ||
return ofrAmts; | ||
}(); | ||
|
||
TTakerPays const thresh = TTakerPays::minPositiveAmount(); | ||
|
||
if (effectiveAmounts.in > thresh) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At your option, micronit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
return false; | ||
|
||
Quality const effectiveQuality{effectiveAmounts}; | ||
return effectiveQuality < offer_.quality(); | ||
} | ||
|
||
template <class TIn, class TOut> | ||
bool | ||
TOfferStreamBase<TIn, TOut>::step() | ||
|
@@ -222,6 +291,66 @@ TOfferStreamBase<TIn, TOut>::step() | |
<< "Removing became unfunded offer " << entry->key(); | ||
} | ||
offer_ = TOffer<TIn, TOut>{}; | ||
// See comment at top of loop for why the offer is removed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the comments in the block describe why we're removing the offer, what's not quite clear at this point is how. The comment at the top of the loop makes that clear. Consider changing this comment to "... for how the ...". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
continue; | ||
} | ||
|
||
bool const rmSmallIncreasedQOffer = [&] { | ||
bool const inIsXRP = isXRP(offer_.issueIn()); | ||
bool const outIsXRP = isXRP(offer_.issueOut()); | ||
if (inIsXRP && !outIsXRP) | ||
{ | ||
// Without the `if constexpr`, the | ||
// `shouldRmSmallIncreasedQOffer` template will be instantiated | ||
// even if it is never used. This can cause compiler errors in | ||
// some cases, hense the `if constexpr` guard. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great comment! Thanks! BTW, perhaps change "hense" to "hence'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
if constexpr (!(std::is_same_v<TIn, IOUAmount> || | ||
std::is_same_v<TOut, XRPAmount>)) | ||
return shouldRmSmallIncreasedQOffer<XRPAmount, IOUAmount>(); | ||
Comment on lines
+308
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here just confuses me. First, is there a reason we don't use Second, and maybe it's the fact that it's almost midnight, but I'm confused why the conditional is even necessary? Under what circumstances do we enter this codepath where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are three questions:
I added some minor clarifying comments, but kept the code essentially the same. I can revisit if you still think this is confusing. |
||
} | ||
if (!inIsXRP && outIsXRP) | ||
{ | ||
// See comment above for `if constexpr` rational | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in |
||
if constexpr (!(std::is_same_v<TIn, XRPAmount> || | ||
std::is_same_v<TOut, IOUAmount>)) | ||
return shouldRmSmallIncreasedQOffer<IOUAmount, XRPAmount>(); | ||
} | ||
if (!inIsXRP && !outIsXRP) | ||
{ | ||
// See comment above for `if constexpr` rational | ||
if constexpr (!(std::is_same_v<TIn, XRPAmount> || | ||
std::is_same_v<TOut, XRPAmount>)) | ||
return shouldRmSmallIncreasedQOffer<IOUAmount, IOUAmount>(); | ||
} | ||
assert(0); // xrp/xrp offer!?! should never happen | ||
return false; | ||
}(); | ||
|
||
if (rmSmallIncreasedQOffer) | ||
{ | ||
auto const original_funds = accountFundsHelper( | ||
cancelView_, | ||
offer_.owner(), | ||
amount.out, | ||
offer_.issueOut(), | ||
fhZERO_IF_FROZEN, | ||
j_); | ||
|
||
if (original_funds == *ownerFunds_) | ||
{ | ||
permRmOffer(entry->key()); | ||
JLOG(j_.trace()) | ||
<< "Removing tiny offer due to reduced quality " | ||
<< entry->key(); | ||
} | ||
else | ||
{ | ||
JLOG(j_.trace()) << "Removing became tiny offer due to " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Removing became" is gramatically incorrect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It mirrors the "became unfunded" terminology we use for offers. Having said that, I don't mind rewording it. Changed to "removing tiny offer that became tiny due to..." Fixed in |
||
"reduced quality " | ||
<< entry->key(); | ||
} | ||
offer_ = TOffer<TIn, TOut>{}; | ||
// See comment at top of loop for why the offer is removed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to earlier comment. Consider "... for how the ...". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in |
||
continue; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,9 @@ class IOUAmount : private boost::totally_ordered<IOUAmount>, | |
{ | ||
return mantissa_; | ||
} | ||
|
||
static IOUAmount | ||
minPositiveAmount(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long term, this could be made There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it were easy I'd do it, but this is going to be a rarely called function; making this |
||
}; | ||
|
||
std::string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,36 @@ toAmount<XRPAmount>(STAmount const& amt) | |
return XRPAmount(sMant); | ||
} | ||
|
||
template <class T> | ||
T | ||
toAmount(IOUAmount const& amt) | ||
{ | ||
static_assert(sizeof(T) == -1, "Must use specialized function"); | ||
return T(0); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never think of using Fixed in |
||
|
||
template <> | ||
inline IOUAmount | ||
toAmount<IOUAmount>(IOUAmount const& amt) | ||
{ | ||
return amt; | ||
} | ||
|
||
template <class T> | ||
T | ||
toAmount(XRPAmount const& amt) | ||
{ | ||
static_assert(sizeof(T) == -1, "Must use specialized function"); | ||
return T(0); | ||
} | ||
|
||
template <> | ||
inline XRPAmount | ||
toAmount<XRPAmount>(XRPAmount const& amt) | ||
{ | ||
return amt; | ||
} | ||
|
||
} // namespace ripple | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than leave the quotes empty, I might be inclined to say
"STAmount is not supported"
, since that's the most likely alternative. But your call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in
9b8c050cb3 [fold] Minor cleanups