Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AccountID string conversion caching #4181

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/ripple/app/ledger/AcceptedLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ AcceptedLedger::AcceptedLedger(
transactions_.reserve(256);

auto insertAll = [&](auto const& txns) {
auto const& idcache = app.accountIDCache();

for (auto const& item : txns)
transactions_.emplace_back(std::make_unique<AcceptedLedgerTx>(
ledger, item.first, item.second, idcache));
ledger, item.first, item.second));
};

if (app.config().reporting())
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/app/ledger/AcceptedLedgerTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace ripple {
AcceptedLedgerTx::AcceptedLedgerTx(
std::shared_ptr<ReadView const> const& ledger,
std::shared_ptr<STTx const> const& txn,
std::shared_ptr<STObject const> const& met,
AccountIDCache const& accountCache)
std::shared_ptr<STObject const> const& met)
: mTxn(txn)
, mMeta(txn->getTransactionID(), ledger->seq(), *met)
, mAffected(mMeta.getAffectedAccounts())
Expand All @@ -52,7 +51,7 @@ AcceptedLedgerTx::AcceptedLedgerTx(
{
Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
for (auto const& account : mAffected)
affected.append(accountCache.toBase58(account));
affected.append(toBase58(account));
}

if (mTxn->getTxnType() == ttOFFER_CREATE)
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/app/ledger/AcceptedLedgerTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class AcceptedLedgerTx : public CountedObject<AcceptedLedgerTx>
AcceptedLedgerTx(
std::shared_ptr<ReadView const> const& ledger,
std::shared_ptr<STTx const> const&,
std::shared_ptr<STObject const> const&,
AccountIDCache const&);
std::shared_ptr<STObject const> const&);

std::shared_ptr<STTx const> const&
getTxn() const
Expand Down
11 changes: 2 additions & 9 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ class ApplicationImp : public Application, public BasicApp
NodeStoreScheduler m_nodeStoreScheduler;
std::unique_ptr<SHAMapStore> m_shaMapStore;
PendingSaves pendingSaves_;
AccountIDCache accountIDCache_;
std::optional<OpenLedger> openLedger_;

NodeCache m_tempNodeCache;
Expand Down Expand Up @@ -327,8 +326,6 @@ class ApplicationImp : public Application, public BasicApp
m_nodeStoreScheduler,
logs_->journal("SHAMapStore")))

, accountIDCache_(128000)

, m_tempNodeCache(
"NodeCache",
16384,
Expand Down Expand Up @@ -485,6 +482,8 @@ class ApplicationImp : public Application, public BasicApp
config_->reporting() ? std::make_unique<ReportingETL>(*this)
: nullptr)
{
initAccountIdCache(config_->getValueFor(SizedItem::accountIdCacheSize));

add(m_resourceManager.get());

//
Expand Down Expand Up @@ -841,12 +840,6 @@ class ApplicationImp : public Application, public BasicApp
return pendingSaves_;
}

AccountIDCache const&
accountIDCache() const override
{
return accountIDCache_;
}

OpenLedger&
openLedger() override
{
Expand Down
3 changes: 0 additions & 3 deletions src/ripple/app/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class PathRequests;
class PendingSaves;
class PublicKey;
class SecretKey;
class AccountIDCache;
class STLedgerEntry;
class TimeKeeper;
class TransactionMaster;
Expand Down Expand Up @@ -245,8 +244,6 @@ class Application : public beast::PropertyStream::Source
getSHAMapStore() = 0;
virtual PendingSaves&
pendingSaves() = 0;
virtual AccountIDCache const&
accountIDCache() const = 0;
virtual OpenLedger&
openLedger() = 0;
virtual OpenLedger const&
Expand Down
19 changes: 12 additions & 7 deletions src/ripple/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,16 @@ PathRequest::findPaths(
continueCallback);
mContext[issue] = ps;

auto& sourceAccount = !isXRP(issue.account)
? issue.account
: isXRP(issue.currency) ? xrpAccount() : *raSrcAccount;
auto const& sourceAccount = [&] {
if (!isXRP(issue.account))
return issue.account;

if (isXRP(issue.currency))
return xrpAccount();

return *raSrcAccount;
}();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. I am not sure what the beauty of a lambda in this case.

STAmount saMaxAmount = saSendMax.value_or(
STAmount({issue.currency, sourceAccount}, 1u, 0, true));

Expand Down Expand Up @@ -675,10 +682,8 @@ PathRequest::doUpdate(
destCurrencies.append(to_string(c));
}

newStatus[jss::source_account] =
app_.accountIDCache().toBase58(*raSrcAccount);
newStatus[jss::destination_account] =
app_.accountIDCache().toBase58(*raDstAccount);
newStatus[jss::source_account] = toBase58(*raSrcAccount);
newStatus[jss::destination_account] = toBase58(*raDstAccount);
newStatus[jss::destination_amount] = saDstAmount.getJson(JsonOptions::none);
newStatus[jss::full_reply] = !fast;

Expand Down
4 changes: 0 additions & 4 deletions src/ripple/app/rdb/backend/detail/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ getNewestAccountTxsB(
* account which match given criteria starting from given marker
* and calls callback for each found transaction.
* @param session Session with database.
* @param idCache Account ID cache.
* @param onUnsavedLedger Callback function to call on each found unsaved
* ledger within given range.
* @param onTransaction Callback function to call on each found transaction.
Expand All @@ -408,7 +407,6 @@ getNewestAccountTxsB(
std::pair<std::optional<RelationalDatabase::AccountTxMarker>, int>
oldestAccountTxPage(
soci::session& session,
AccountIDCache const& idCache,
std::function<void(std::uint32_t)> const& onUnsavedLedger,
std::function<
void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
Expand All @@ -422,7 +420,6 @@ oldestAccountTxPage(
* account which match given criteria starting from given marker
* and calls callback for each found transaction.
* @param session Session with database.
* @param idCache Account ID cache.
* @param onUnsavedLedger Callback function to call on each found unsaved
* ledger within given range.
* @param onTransaction Callback function to call on each found transaction.
Expand All @@ -441,7 +438,6 @@ oldestAccountTxPage(
std::pair<std::optional<RelationalDatabase::AccountTxMarker>, int>
newestAccountTxPage(
soci::session& session,
AccountIDCache const& idCache,
std::function<void(std::uint32_t)> const& onUnsavedLedger,
std::function<
void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
Expand Down
21 changes: 7 additions & 14 deletions src/ripple/app/rdb/backend/detail/impl/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ saveValidatedLedger(

sql += txnId;
sql += "','";
sql += app.accountIDCache().toBase58(account);
sql += toBase58(account);
sql += "',";
sql += ledgerSeq;
sql += ",";
Expand Down Expand Up @@ -760,8 +760,7 @@ transactionsSQL(
sql = boost::str(
boost::format("SELECT %s FROM AccountTransactions "
"WHERE Account = '%s' %s %s LIMIT %u, %u;") %
selection % app.accountIDCache().toBase58(options.account) %
maxClause % minClause %
selection % toBase58(options.account) % maxClause % minClause %
beast::lexicalCastThrow<std::string>(options.offset) %
beast::lexicalCastThrow<std::string>(numberOfResults));
else
Expand All @@ -774,9 +773,9 @@ transactionsSQL(
"ORDER BY AccountTransactions.LedgerSeq %s, "
"AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
"LIMIT %u, %u;") %
selection % app.accountIDCache().toBase58(options.account) %
maxClause % minClause % (descending ? "DESC" : "ASC") %
selection % toBase58(options.account) % maxClause % minClause %
(descending ? "DESC" : "ASC") % (descending ? "DESC" : "ASC") %
(descending ? "DESC" : "ASC") %
beast::lexicalCastThrow<std::string>(options.offset) %
beast::lexicalCastThrow<std::string>(numberOfResults));
JLOG(j.trace()) << "txSQL query: " << sql;
Expand Down Expand Up @@ -1049,7 +1048,6 @@ getNewestAccountTxsB(
* account that matches the given criteria starting from the provided
* marker and invokes the callback parameter for each found transaction.
* @param session Session with the database.
* @param idCache Account ID cache.
* @param onUnsavedLedger Callback function to call on each found unsaved
* ledger within the given range.
* @param onTransaction Callback function to call on each found transaction.
Expand All @@ -1069,7 +1067,6 @@ getNewestAccountTxsB(
static std::pair<std::optional<RelationalDatabase::AccountTxMarker>, int>
accountTxPage(
soci::session& session,
AccountIDCache const& idCache,
std::function<void(std::uint32_t)> const& onUnsavedLedger,
std::function<
void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
Expand Down Expand Up @@ -1135,8 +1132,8 @@ accountTxPage(
ORDER BY AccountTransactions.LedgerSeq %s,
AccountTransactions.TxnSeq %s
LIMIT %u;)")) %
idCache.toBase58(options.account) % options.minLedger %
options.maxLedger % order % order % queryLimit);
toBase58(options.account) % options.minLedger % options.maxLedger %
order % order % queryLimit);
}
else
{
Expand All @@ -1146,7 +1143,7 @@ accountTxPage(
const std::uint32_t maxLedger =
forward ? options.maxLedger : findLedger - 1;

auto b58acct = idCache.toBase58(options.account);
auto b58acct = toBase58(options.account);
sql = boost::str(
boost::format((
R"(SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,
Expand Down Expand Up @@ -1250,7 +1247,6 @@ accountTxPage(
std::pair<std::optional<RelationalDatabase::AccountTxMarker>, int>
oldestAccountTxPage(
soci::session& session,
AccountIDCache const& idCache,
std::function<void(std::uint32_t)> const& onUnsavedLedger,
std::function<
void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
Expand All @@ -1261,7 +1257,6 @@ oldestAccountTxPage(
{
return accountTxPage(
session,
idCache,
onUnsavedLedger,
onTransaction,
options,
Expand All @@ -1273,7 +1268,6 @@ oldestAccountTxPage(
std::pair<std::optional<RelationalDatabase::AccountTxMarker>, int>
newestAccountTxPage(
soci::session& session,
AccountIDCache const& idCache,
std::function<void(std::uint32_t)> const& onUnsavedLedger,
std::function<
void(std::uint32_t, std::string const&, Blob&&, Blob&&)> const&
Expand All @@ -1284,7 +1278,6 @@ newestAccountTxPage(
{
return accountTxPage(
session,
idCache,
onUnsavedLedger,
onTransaction,
options,
Expand Down
Loading