From e9ed80026ec2f7d5fd23fbc9f1f69399a59199eb Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Fri, 7 Feb 2025 21:25:47 +0000 Subject: [PATCH] Optimise isFrozen check for pair of accounts --- src/xrpld/app/tx/detail/Payment.cpp | 3 +- src/xrpld/ledger/View.h | 43 +++++++++++++++++++++++++++++ src/xrpld/ledger/detail/View.cpp | 13 +++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index 1ed3bacbbd..f8d016ec65 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -486,8 +486,7 @@ Payment::doApply() // - can't send between holders // - holder can send back to issuer // - issuer can send to holder - if (isFrozen(view(), account_, mptIssue) || - isFrozen(view(), dstAccountID, mptIssue)) + if (isAnyFrozen(view(), account_, dstAccountID, mptIssue)) return tecLOCKED; // Get the rate for a payment between the holders. diff --git a/src/xrpld/ledger/View.h b/src/xrpld/ledger/View.h index 74bcf5f24d..49ca44b935 100644 --- a/src/xrpld/ledger/View.h +++ b/src/xrpld/ledger/View.h @@ -154,6 +154,49 @@ isFrozen(ReadView const& view, AccountID const& account, Asset const& asset) asset.value()); } +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + AccountID const& account1, + AccountID const& account2, + MPTIssue const& mptIssue); + +/* +We do not have use a case for these (yet ?) + +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + AccountID const& account1, + AccountID const& account2, + Currency const& currency, + AccountID const& issuer); + +[[nodiscard]] inline bool +isAnyFrozen( + ReadView const& view, + AccountID const& account1, + AccountID const& account2, + Issue const& issue) +{ + return isAnyFrozen(view, account1, account2, issue.currency, issue.account); +} + +[[nodiscard]] inline bool +isAnyFrozen( + ReadView const& view, + AccountID const& account1, + AccountID const& account2, + Asset const& asset) +{ + return std::visit( + [&](auto const& issue) { + return isAnyFrozen(view, account1, account2, issue); + }, + asset.value()); +} +*/ + [[nodiscard]] bool isDeepFrozen( ReadView const& view, diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index e1b67f75bb..65ab4c0ca7 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -280,6 +280,19 @@ isFrozen( isVaultPseudoAccountFrozen(view, mptIssue); } +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + AccountID const& account1, + AccountID const& account2, + MPTIssue const& mptIssue) +{ + return isGlobalFrozen(view, mptIssue) || + isIndividualFrozen(view, account1, mptIssue) || + isIndividualFrozen(view, account2, mptIssue) || + isVaultPseudoAccountFrozen(view, mptIssue); +} + bool isVaultPseudoAccountFrozen(ReadView const& view, MPTIssue const& mptShare) {