Skip to content

Commit

Permalink
[FOLD] Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed Jun 4, 2024
1 parent 9ddf547 commit 186eda8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ripple/app/paths/impl/BookStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,12 @@ limitStepIn(
auto const inLmt =
mulRatio(stpAmt.in, QUALITY_ONE, transferRateIn, /*roundUp*/ false);
// It turns out we can prevent order book blocking by (strictly)
// rounding down the ceil_in() result. This adjustment changes
// transaction outcomes, so it must be made under an amendment.
// rounding down the ceil_in() result. By rounding down we guarantee
// that the quality of an offer left in the ledger is as good or
// better than the quality of the containing order book page.
//
// This adjustment changes transaction outcomes, so it must be made
// under an amendment.
ofrAmt = offer.limitIn(ofrAmt, inLmt, rules, /* roundUp */ false);
stpAmt.out = ofrAmt.out;
ownerGives = mulRatio(
Expand Down
23 changes: 23 additions & 0 deletions src/test/app/Flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ struct Flow_test : public beast::unit_test::suite
env(pay(gw, alice, USD(1000)));
env(pay(gw, bob, EUR(1000)));

Keylet const bobUsdOffer = keylet::offer(bob, env.seq(bob));
env(offer(bob, USD(1), drops(2)), txflags(tfPassive));
env(offer(bob, drops(1), EUR(1000)), txflags(tfPassive));

Expand All @@ -536,6 +537,28 @@ struct Flow_test : public beast::unit_test::suite
env.require(balance(carol, EUR(1)));
env.require(balance(bob, USD(0.4)));
env.require(balance(bob, EUR(999)));

// Show that bob's USD offer is now a blocker.
std::shared_ptr<SLE const> const usdOffer = env.le(bobUsdOffer);
if (BEAST_EXPECT(usdOffer))
{
std::uint64_t const bookRate = [&usdOffer]() {
// Extract the least significant 64 bits from the
// book page. That's where the quality is stored.
std::string bookDirStr =
to_string(usdOffer->at(sfBookDirectory));
bookDirStr.erase(0, 48);
return std::stoull(bookDirStr, nullptr, 16);
}();
std::uint64_t const actualRate = getRate(
usdOffer->at(sfTakerGets), usdOffer->at(sfTakerPays));

// We expect the actual rate of the offer to be worse
// (larger) than the rate of the book page holding the
// offer. This is a defect which is corrected by
// fixReducedOffersV2.
BEAST_EXPECT(actualRate > bookRate);
}
}
}
}
Expand Down

0 comments on commit 186eda8

Please sign in to comment.