Merge branch 'ximinez/lending-refactoring-3' into ximinez/lending-refactoring-4

This commit is contained in:
Ed Hennis
2025-09-10 20:36:43 -04:00
committed by GitHub
3 changed files with 27 additions and 6 deletions

View File

@@ -83,6 +83,9 @@ public:
std::optional<TxType>
getGranularTxType(GranularPermissionType const& gpType) const;
std::optional<std::reference_wrapper<uint256 const>> const
getTxFeature(TxType txType) const;
bool
isDelegatable(std::uint32_t const& permissionValue, Rules const& rules)
const;

View File

@@ -131,6 +131,19 @@ Permission::getGranularTxType(GranularPermissionType const& gpType) const
return std::nullopt;
}
std::optional<std::reference_wrapper<uint256 const>> const
Permission::getTxFeature(TxType txType) const
{
auto const txFeaturesIt = txFeatureMap_.find(txType);
XRPL_ASSERT(
txFeaturesIt != txFeatureMap_.end(),
"ripple::Permissions::isDelegatable : tx exists in txFeatureMap_");
if (txFeaturesIt->second == uint256{})
return std::nullopt;
return txFeaturesIt->second;
}
bool
Permission::isDelegatable(
std::uint32_t const& permissionValue,
@@ -150,16 +163,12 @@ Permission::isDelegatable(
if (it == delegatableTx_.end())
return false;
auto const txFeaturesIt = txFeatureMap_.find(txType);
XRPL_ASSERT(
txFeaturesIt != txFeatureMap_.end(),
"ripple::Permissions::isDelegatable : tx exists in txFeatureMap_");
auto const feature = getTxFeature(txType);
// fixDelegateV1_1: Delegation is only allowed if the required amendment
// for the transaction is enabled. For transactions that do not require
// an amendment, delegation is always allowed.
if (txFeaturesIt->second != uint256{} &&
!rules.enabled(txFeaturesIt->second))
if (feature && !rules.enabled(*feature))
return false;
}

View File

@@ -395,6 +395,15 @@ Transactor::invokePreflight(PreflightContext const& ctx)
// TODO: If #5650 is merged, use its transaction -> amendment lookup here to
// do a first-pass check. Rewrite or remove any `isEnabled` overloads that
// check those default amendments.
// Using this lookup does NOT require checking the fixDelegateV1_1. The data
// exists regardless of whether it is enabled.
auto const feature =
Permission::getInstance().getTxFeature(ctx.tx.getTxnType());
if (feature && !ctx.rules.enabled(*feature))
return temDISABLED;
if (!T::isEnabled(ctx))
return temDISABLED;