Compare commits

...

12 Commits

Author SHA1 Message Date
Mayukha Vadari
b366a1b521 fix clang-tidy 2026-03-24 14:58:37 -07:00
Mayukha Vadari
0621a12c61 fix merge issue 2026-03-24 12:12:03 -07:00
Mayukha Vadari
40363ce525 Merge branch 'develop' into mvadari/payment-fixes 2026-03-24 11:00:30 -07:00
Mayukha Vadari
e78ab82996 Fix syntax error in Payment.cpp 2026-03-19 14:37:33 -04:00
Mayukha Vadari
253918c168 explicitly initialize sfBalance in Payment.cpp 2026-03-19 14:27:27 -04:00
Mayukha Vadari
a43de47f13 whoops 2026-03-18 18:25:09 -04:00
Mayukha Vadari
c78a68f218 Merge branch 'develop' into mvadari/payment-fixes 2026-03-18 17:56:51 -04:00
Mayukha Vadari
1dcbc503d8 add assertion to validate transfer fee does not exceed maximum allowed value 2026-03-18 17:50:04 -04:00
Mayukha Vadari
346fbbd3ac fix incorrect emplace result check logic 2026-03-18 17:44:20 -04:00
Mayukha Vadari
a2a66f68ad remove dead code 2026-03-18 17:41:14 -04:00
Mayukha Vadari
04c141cba5 fix reversed naming of variables 2026-03-18 17:35:58 -04:00
Mayukha Vadari
4cdc8561cd Refactor ledger open check in OfferCreate.cpp 2026-03-18 17:30:24 -04:00
6 changed files with 25 additions and 38 deletions

View File

@@ -58,8 +58,8 @@ private:
{
explicit Value() = default;
STAmount lowAcctCredits;
STAmount highAcctCredits;
STAmount lowAcctDebits;
STAmount highAcctDebits;
STAmount lowAcctOrigBalance;
};

View File

@@ -503,14 +503,6 @@ public:
{
return cur_.size();
}
void
removeIndex(std::size_t i)
{
if (i >= next_.size())
return;
next_.erase(next_.begin() + i);
}
};
/// @endcond
@@ -635,11 +627,6 @@ flow(
std::optional<BestStrand> best;
if (flowDebugInfo)
flowDebugInfo->newLiquidityPass();
// Index of strand to mark as inactive (remove from the active list) if
// the liquidity is used. This is used for strands that consume too many
// offers Constructed as `false,0` to workaround a gcc warning about
// uninitialized variables
std::optional<std::size_t> markInactiveOnUse;
for (size_t strandIndex = 0, sie = activeStrands.size(); strandIndex != sie; ++strandIndex)
{
Strand const* strand = activeStrands.get(strandIndex);
@@ -703,11 +690,6 @@ flow(
if (best)
{
if (markInactiveOnUse)
{
activeStrands.removeIndex(*markInactiveOnUse);
markInactiveOnUse.reset();
}
savedIns.insert(best->in);
savedOuts.insert(best->out);
remainingOut = outReq - sum(savedOuts);

View File

@@ -37,14 +37,14 @@ DeferredCredits::credit(
if (sender < receiver)
{
v.highAcctCredits = amount;
v.lowAcctCredits = amount.zeroed();
v.lowAcctDebits = amount;
v.highAcctDebits = amount.zeroed();
v.lowAcctOrigBalance = preCreditSenderBalance;
}
else
{
v.highAcctCredits = amount.zeroed();
v.lowAcctCredits = amount;
v.lowAcctDebits = amount.zeroed();
v.highAcctDebits = amount;
v.lowAcctOrigBalance = -preCreditSenderBalance;
}
@@ -56,11 +56,11 @@ DeferredCredits::credit(
auto& v = i->second;
if (sender < receiver)
{
v.highAcctCredits += amount;
v.lowAcctDebits += amount;
}
else
{
v.lowAcctCredits += amount;
v.highAcctDebits += amount;
}
}
}
@@ -104,11 +104,11 @@ DeferredCredits::adjustments(
if (main < other)
{
result.emplace(v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
result.emplace(v.lowAcctDebits, v.highAcctDebits, v.lowAcctOrigBalance);
return result;
}
result.emplace(v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
result.emplace(v.highAcctDebits, v.lowAcctDebits, -v.lowAcctOrigBalance);
return result;
}
@@ -122,8 +122,8 @@ DeferredCredits::apply(DeferredCredits& to)
{
auto& toVal = r.first->second;
auto const& fromVal = i.second;
toVal.lowAcctCredits += fromVal.lowAcctCredits;
toVal.highAcctCredits += fromVal.highAcctCredits;
toVal.lowAcctDebits += fromVal.lowAcctDebits;
toVal.highAcctDebits += fromVal.highAcctDebits;
// Do not update the orig balance, it's already correct
}
}
@@ -349,14 +349,14 @@ PaymentSandbox::balanceChanges(ReadView const& view) const
auto const cur = newBalance.getCurrency();
result[std::make_tuple(lowID, highID, cur)] = delta;
auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta);
if (r.second)
if (!r.second)
{
r.first->second += delta;
}
delta.negate();
r = result.emplace(std::make_tuple(highID, highID, cur), delta);
if (r.second)
if (!r.second)
{
r.first->second += delta;
}

View File

@@ -83,7 +83,11 @@ transferRate(ReadView const& view, MPTID const& issuanceID)
// which represents 50% of 1,000,000,000
if (auto const sle = view.read(keylet::mptIssuance(issuanceID));
sle && sle->isFieldPresent(sfTransferFee))
return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)};
{
auto const fee = sle->getFieldU16(sfTransferFee);
XRPL_ASSERT(fee <= maxTransferFee, "xrpl::transferRate : fee is too large");
return Rate{1'000'000'000u + (10'000 * fee)};
}
return parityRate;
}
@@ -149,7 +153,7 @@ authorizeMPToken(
// When a holder wants to unauthorize/delete a MPT, the ledger must
// - delete mptokenKey from owner directory
// - delete the MPToken
if (flags & tfMPTUnauthorize)
if ((flags & tfMPTUnauthorize) != 0u)
{
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
auto const sleMpt = view.peek(mptokenKey);
@@ -229,7 +233,7 @@ authorizeMPToken(
// Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on
// their MPToken
if (flags & tfMPTUnauthorize)
if ((flags & tfMPTUnauthorize) != 0u)
{
flagsOut &= ~lsfMPTAuthorized;
}
@@ -490,7 +494,7 @@ canTransfer(
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;
if (!(sleIssuance->getFieldU32(sfFlags) & lsfMPTCanTransfer))
if ((sleIssuance->getFieldU32(sfFlags) & lsfMPTCanTransfer) == 0u)
{
if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer])
return TER{tecNO_AUTH};

View File

@@ -564,7 +564,6 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel)
return {tecEXPIRED, true};
}
bool const bOpenLedger = sb.open();
bool crossed = false;
if (isTesSuccess(result))
@@ -650,7 +649,8 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel)
stream << " out: " << format_amount(place_offer.out);
}
if (result == tecFAILED_PROCESSING && bOpenLedger)
bool const isLedgerOpen = sb.open();
if (result == tecFAILED_PROCESSING && isLedgerOpen)
result = telFAILED_PROCESSING;
if (!isTesSuccess(result))

View File

@@ -389,6 +389,7 @@ Payment::doApply()
sleDst = std::make_shared<SLE>(k);
sleDst->setAccountID(sfAccount, dstAccountID);
sleDst->setFieldU32(sfSequence, view().seq());
sleDst->setFieldAmount(sfBalance, XRPAmount(beast::zero));
view().insert(sleDst);
}