From aef0a84e07752d8f15fa58cddc1c8e96dda5644d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 11:48:13 -0700 Subject: [PATCH] Don't use getAccountState as a quick way to check if an account exists in a ledger. It's much heavier than needed. --- src/cpp/ripple/Ledger.cpp | 5 +++++ src/cpp/ripple/Ledger.h | 1 + src/cpp/ripple/RPCHandler.cpp | 8 ++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 14c943001..c2ea6aa91 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -190,6 +190,11 @@ void Ledger::setAccepted() setImmutable(); } +bool Ledger::hasAccount(const RippleAddress& accountID) +{ + return mAccountStateMap->hasItem(Ledger::getAccountRootIndex(accountID)); +} + AccountState::pointer Ledger::getAccountState(const RippleAddress& accountID) { #ifdef DEBUG diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 3c8256a6e..1c7e09c08 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -183,6 +183,7 @@ public: TransactionMetaSet::pointer& txMeta); // high-level functions + bool hasAccount(const RippleAddress& acctID); AccountState::pointer getAccountState(const RippleAddress& acctID); LedgerStateParms writeBack(LedgerStateParms parms, SLE::ref); SLE::pointer getAccountRoot(const uint160& accountID); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 398a702a5..e0ec6417d 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1062,9 +1062,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL return jvResult; } - AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount); - - if (as) + if (lpLedger->hasAccount(raAccount)) { jvResult["account"] = raAccount.humanAccountID(); @@ -1140,9 +1138,7 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped if (bIndex) jvResult["account_index"] = iIndex; - AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount); - - if (as) + if (lpLedger->hasAccount(raAccount)) { Json::Value& jsonLines = (jvResult["offers"] = Json::arrayValue);