Merge branch 'develop' into bthomee/node_depth

This commit is contained in:
Bart
2026-04-24 09:26:37 -04:00
21 changed files with 59 additions and 224 deletions

View File

@@ -21,9 +21,8 @@ private:
struct ValueIOU
{
explicit ValueIOU() = default;
STAmount lowAcctCredits;
STAmount highAcctCredits;
STAmount lowAcctDebits;
STAmount highAcctDebits;
STAmount lowAcctOrigBalance;
};
@@ -230,13 +229,6 @@ public:
apply(PaymentSandbox& to);
/** @} */
// Return a map of balance changes on trust lines. The low account is the
// first account in the key. If the two accounts are equal, the map contains
// the total changes in currency regardless of issuer. This is useful to get
// the total change in XRP balances.
std::map<std::tuple<AccountID, AccountID, Currency>, STAmount>
balanceChanges(ReadView const& view) const;
XRPAmount
xrpDestroyed() const;

View File

@@ -1,15 +1,14 @@
#pragma once
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/st.h>
namespace xrpl {
struct PreflightContext;
// Lending protocol has dependencies, so capture them here.
bool
checkLendingProtocolDependencies(PreflightContext const& ctx);
checkLendingProtocolDependencies(Rules const& rules, STTx const& tx);
static constexpr std::uint32_t secondsInYear = 365 * 24 * 60 * 60;

View File

@@ -327,27 +327,4 @@ writeDiffs(std::ostringstream& ostr, Iter begin, Iter end)
ostr << ']';
};
using BalanceDiffs =
std::pair<std::map<std::tuple<AccountID, AccountID, Currency>, STAmount>, XRPAmount>;
inline BalanceDiffs
balanceDiffs(PaymentSandbox const& sb, ReadView const& rv)
{
return {sb.balanceChanges(rv), sb.xrpDestroyed()};
}
inline std::string
balanceDiffsToString(std::optional<BalanceDiffs> const& bd)
{
if (!bd)
return std::string{};
auto const& diffs = bd->first;
auto const& xrpDestroyed = bd->second;
std::ostringstream ostr;
ostr << ", xrpDestroyed: " << to_string(xrpDestroyed);
ostr << ", balanceDiffs: ";
writeDiffs(ostr, diffs.begin(), diffs.end());
return ostr.str();
};
} // namespace xrpl::path::detail

View File

@@ -527,14 +527,6 @@ public:
{
return cur_.size();
}
void
removeIndex(std::size_t i)
{
if (i >= next_.size())
return;
next_.erase(next_.begin() + i);
}
};
/// @endcond
@@ -661,11 +653,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);
@@ -729,11 +716,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

@@ -1,7 +1,7 @@
#pragma once
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
namespace xrpl {

View File

@@ -4,20 +4,16 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/RawView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Issue.h>
#include <xrpl/protocol/LedgerFormats.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/UintTypes.h>
#include <xrpl/protocol/XRPAmount.h>
#include <algorithm>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <tuple>
#include <utility>
@@ -58,14 +54,14 @@ DeferredCredits::creditIOU(
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;
}
@@ -77,11 +73,11 @@ DeferredCredits::creditIOU(
auto& v = i->second;
if (sender < receiver)
{
v.highAcctCredits += amount;
v.lowAcctDebits += amount;
}
else
{
v.lowAcctCredits += amount;
v.highAcctDebits += amount;
}
}
}
@@ -212,11 +208,11 @@ DeferredCredits::adjustmentsIOU(
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;
}
@@ -239,8 +235,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
}
}
@@ -467,131 +463,6 @@ PaymentSandbox::apply(PaymentSandbox& to)
tab_.apply(to.tab_);
}
std::map<std::tuple<AccountID, AccountID, Currency>, STAmount>
PaymentSandbox::balanceChanges(ReadView const& view) const
{
using key_t = std::tuple<AccountID, AccountID, Currency>;
// Map of delta trust lines. As a special case, when both ends of the trust
// line are the same currency, then it's delta currency for that issuer. To
// get the change in XRP balance, Account == root, issuer == root, currency
// == XRP
std::map<key_t, STAmount> result;
// populate a dictionary with low/high/currency/delta. This can be
// compared with the other versions payment code.
auto each = [&result](
uint256 const& key,
bool isDelete,
std::shared_ptr<SLE const> const& before,
std::shared_ptr<SLE const> const& after) {
STAmount oldBalance;
STAmount newBalance;
AccountID lowID;
AccountID highID;
// before is read from prev view
if (isDelete)
{
if (!before)
return;
auto const bt = before->getType();
switch (bt)
{
case ltACCOUNT_ROOT:
lowID = xrpAccount();
highID = (*before)[sfAccount];
oldBalance = (*before)[sfBalance];
newBalance = oldBalance.zeroed();
break;
case ltRIPPLE_STATE:
lowID = (*before)[sfLowLimit].getIssuer();
highID = (*before)[sfHighLimit].getIssuer();
oldBalance = (*before)[sfBalance];
newBalance = oldBalance.zeroed();
break;
case ltOFFER:
// TBD
break;
default:
break;
}
}
else if (!before)
{
// insert
auto const at = after->getType();
switch (at)
{
case ltACCOUNT_ROOT:
lowID = xrpAccount();
highID = (*after)[sfAccount];
newBalance = (*after)[sfBalance];
oldBalance = newBalance.zeroed();
break;
case ltRIPPLE_STATE:
lowID = (*after)[sfLowLimit].getIssuer();
highID = (*after)[sfHighLimit].getIssuer();
newBalance = (*after)[sfBalance];
oldBalance = newBalance.zeroed();
break;
case ltOFFER:
// TBD
break;
default:
break;
}
}
else
{
// modify
auto const at = after->getType();
XRPL_ASSERT(
at == before->getType(),
"xrpl::PaymentSandbox::balanceChanges : after and before "
"types matching");
switch (at)
{
case ltACCOUNT_ROOT:
lowID = xrpAccount();
highID = (*after)[sfAccount];
oldBalance = (*before)[sfBalance];
newBalance = (*after)[sfBalance];
break;
case ltRIPPLE_STATE:
lowID = (*after)[sfLowLimit].getIssuer();
highID = (*after)[sfHighLimit].getIssuer();
oldBalance = (*before)[sfBalance];
newBalance = (*after)[sfBalance];
break;
case ltOFFER:
// TBD
break;
default:
break;
}
}
// The following are now set, put them in the map
auto delta = newBalance - oldBalance;
auto const cur = newBalance.get<Issue>().currency;
result[std::make_tuple(lowID, highID, cur)] = delta;
auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta);
if (r.second)
{
r.first->second += delta;
}
delta.negate();
r = result.emplace(std::make_tuple(highID, highID, cur), delta);
if (r.second)
{
r.first->second += delta;
}
};
items_.visit(view, each);
return result;
}
XRPAmount
PaymentSandbox::xrpDestroyed() const
{

View File

@@ -1,4 +1,4 @@
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Log.h>
@@ -7,18 +7,19 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/LedgerFormats.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/STTx.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/Units.h>
#include <xrpl/tx/transactors/vault/VaultCreate.h>
#include <algorithm>
#include <cstddef>
@@ -28,9 +29,18 @@
namespace xrpl {
bool
checkLendingProtocolDependencies(PreflightContext const& ctx)
checkLendingProtocolDependencies(Rules const& rules, STTx const& tx)
{
return ctx.rules.enabled(featureSingleAssetVault) && VaultCreate::checkExtraFeatures(ctx);
if (!rules.enabled(featureSingleAssetVault))
return false;
if (!rules.enabled(featureMPTokensV1))
return false;
if (tx.isFieldPresent(sfDomainID) && !rules.enabled(featurePermissionedDomains))
return false;
return true;
}
LoanPaymentParts&

View File

@@ -94,7 +94,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;
}
@@ -160,7 +164,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) != 0)
if ((flags & tfMPTUnauthorize) != 0u)
{
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
auto const sleMpt = view.peek(mptokenKey);
@@ -242,7 +246,7 @@ authorizeMPToken(
// Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on
// their MPToken
if ((flags & tfMPTUnauthorize) != 0)
if ((flags & tfMPTUnauthorize) != 0u)
{
flagsOut &= ~lsfMPTAuthorized;
}

View File

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

View File

@@ -7,6 +7,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
@@ -25,7 +26,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
#include <optional>
@@ -36,7 +36,7 @@ namespace xrpl {
bool
LoanBrokerCoverClawback::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -2,6 +2,7 @@
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/SField.h>
@@ -12,7 +13,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -21,7 +21,7 @@ namespace xrpl {
bool
LoanBrokerCoverDeposit::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -5,6 +5,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/Protocol.h>
@@ -17,7 +18,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -26,7 +26,7 @@ namespace xrpl {
bool
LoanBrokerCoverWithdraw::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -4,6 +4,7 @@
#include <xrpl/basics/Number.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Indexes.h>
@@ -15,7 +16,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -24,7 +24,7 @@ namespace xrpl {
bool
LoanBrokerDelete::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -6,6 +6,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Indexes.h>
@@ -18,7 +19,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
#include <vector>
@@ -28,7 +28,7 @@ namespace xrpl {
bool
LoanBrokerSet::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -5,6 +5,7 @@
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STAmount.h> // IWYU pragma: keep
@@ -14,7 +15,6 @@
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <memory>
@@ -23,7 +23,7 @@ namespace xrpl {
bool
LoanDelete::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
NotTEC

View File

@@ -6,6 +6,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
@@ -22,7 +23,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <algorithm>
#include <cstdint>
@@ -33,7 +33,7 @@ namespace xrpl {
bool
LoanManage::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -8,6 +8,7 @@
#include <xrpl/json/to_string.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
@@ -23,7 +24,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/tx/transactors/lending/LoanManage.h>
#include <algorithm>
@@ -36,7 +36,7 @@ namespace xrpl {
bool
LoanPay::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -7,6 +7,7 @@
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
@@ -25,7 +26,6 @@
#include <xrpl/protocol/Units.h>
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/tx/Transactor.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <cstddef>
#include <cstdint>
@@ -40,7 +40,7 @@ namespace xrpl {
bool
LoanSet::checkExtraFeatures(PreflightContext const& ctx)
{
return checkLendingProtocolDependencies(ctx);
return checkLendingProtocolDependencies(ctx.rules, ctx.tx);
}
std::uint32_t

View File

@@ -431,6 +431,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);
}

View File

@@ -6,8 +6,8 @@
#include <xrpl/basics/Number.h>
#include <xrpl/basics/chrono.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Units.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <cstdint>
#include <string>

View File

@@ -34,6 +34,7 @@
#include <xrpl/beast/xor_shift_engine.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/to_string.h>
#include <xrpl/ledger/helpers/LendingHelpers.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/HashPrefix.h>
@@ -55,7 +56,6 @@
#include <xrpl/protocol/XRPAmount.h>
#include <xrpl/protocol/jss.h>
#include <xrpl/server/LoadFeeTrack.h>
#include <xrpl/tx/transactors/lending/LendingHelpers.h>
#include <xrpl/tx/transactors/lending/LoanSet.h>
#include <xrpl/tx/transactors/system/Batch.h>