Skip to content

Commit

Permalink
Simplify LedgerMaster:
Browse files Browse the repository at this point in the history
- Eliminate `tune` member function and allow `LedgerHistory`
  to fully initialize itself.
  • Loading branch information
nbougalis authored and manojsdoshi committed Mar 30, 2022
1 parent 6faaa91 commit c7e6803
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 47 deletions.
19 changes: 2 additions & 17 deletions src/ripple/app/ledger/LedgerHistory.cpp
Expand Up @@ -26,14 +26,6 @@

namespace ripple {

// VFALCO TODO replace macros

#ifndef CACHED_LEDGER_NUM
#define CACHED_LEDGER_NUM 96
#endif

std::chrono::seconds constexpr CachedLedgerAge = std::chrono::minutes{2};

// FIXME: Need to clean up ledgers by index at some point

LedgerHistory::LedgerHistory(
Expand All @@ -44,8 +36,8 @@ LedgerHistory::LedgerHistory(
, mismatch_counter_(collector->make_counter("ledger.history", "mismatch"))
, m_ledgers_by_hash(
"LedgerCache",
CACHED_LEDGER_NUM,
CachedLedgerAge,
app_.config().getValueFor(SizedItem::ledgerSize),
std::chrono::seconds{app_.config().getValueFor(SizedItem::ledgerAge)},
stopwatch(),
app_.journal("TaggedCache"))
, m_consensus_validated(
Expand Down Expand Up @@ -523,13 +515,6 @@ LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
return true;
}

void
LedgerHistory::tune(int size, std::chrono::seconds age)
{
m_ledgers_by_hash.setTargetSize(size);
m_ledgers_by_hash.setTargetAge(age);
}

void
LedgerHistory::clearLedgerCachePrior(LedgerIndex seq)
{
Expand Down
7 changes: 0 additions & 7 deletions src/ripple/app/ledger/LedgerHistory.h
Expand Up @@ -70,13 +70,6 @@ class LedgerHistory
LedgerHash
getLedgerHash(LedgerIndex ledgerIndex);

/** Set the history cache's parameters
@param size The target size of the cache
@param age The target age of the cache, in seconds
*/
void
tune(int size, std::chrono::seconds age);

/** Remove stale cache entries
*/
void
Expand Down
2 changes: 0 additions & 2 deletions src/ripple/app/ledger/LedgerMaster.h
Expand Up @@ -219,8 +219,6 @@ class LedgerMaster : public AbstractFetchPackContainer
bool
getFullValidatedRange(std::uint32_t& minVal, std::uint32_t& maxVal);

void
tune(int size, std::chrono::seconds age);
void
sweep();
float
Expand Down
11 changes: 3 additions & 8 deletions src/ripple/app/ledger/impl/LedgerMaster.cpp
Expand Up @@ -1624,7 +1624,8 @@ LedgerMaster::newPFWork(
const char* name,
std::unique_lock<std::recursive_mutex>&)
{
if (mPathFindThread < 2 && app_.getPathRequests().requestsPending())
if (!app_.isStopping() && mPathFindThread < 2 &&
app_.getPathRequests().requestsPending())
{
JLOG(m_journal.debug())
<< "newPFWork: Creating job. path find threads: "
Expand Down Expand Up @@ -1868,12 +1869,6 @@ LedgerMaster::setLedgerRangePresent(std::uint32_t minV, std::uint32_t maxV)
mCompleteLedgers.insert(range(minV, maxV));
}

void
LedgerMaster::tune(int size, std::chrono::seconds age)
{
mLedgerHistory.tune(size, age);
}

void
LedgerMaster::sweep()
{
Expand Down Expand Up @@ -2114,7 +2109,7 @@ LedgerMaster::doAdvance(std::unique_lock<std::recursive_mutex>& sl)
{
JLOG(m_journal.trace()) << "tryAdvance found " << pubLedgers.size()
<< " ledgers to publish";
for (auto ledger : pubLedgers)
for (auto const& ledger : pubLedgers)
{
{
ScopedUnlock sul{sl};
Expand Down
7 changes: 0 additions & 7 deletions src/ripple/app/main/Application.cpp
Expand Up @@ -962,13 +962,6 @@ class ApplicationImp : public Application, public BasicApp
<< "' took " << elapsed.count() << " seconds.";
}

// tune caches
using namespace std::chrono;

m_ledgerMaster->tune(
config_->getValueFor(SizedItem::ledgerSize),
seconds{config_->getValueFor(SizedItem::ledgerAge)});

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/core/impl/Config.cpp
Expand Up @@ -119,8 +119,8 @@ sizedItems
{SizedItem::sweepInterval, {{ 10, 30, 60, 90, 120 }}},
{SizedItem::treeCacheSize, {{ 262144, 524288, 2097152, 4194304, 8388608 }}},
{SizedItem::treeCacheAge, {{ 30, 60, 90, 120, 900 }}},
{SizedItem::ledgerSize, {{ 32, 128, 256, 384, 768 }}},
{SizedItem::ledgerAge, {{ 30, 90, 180, 240, 900 }}},
{SizedItem::ledgerSize, {{ 32, 32, 64, 256, 384 }}},
{SizedItem::ledgerAge, {{ 30, 60, 180, 300, 600 }}},
{SizedItem::ledgerFetch, {{ 2, 3, 4, 5, 8 }}},
{SizedItem::hashNodeDBCache, {{ 4, 12, 24, 64, 128 }}},
{SizedItem::txnDBCache, {{ 4, 12, 24, 64, 128 }}},
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/rpc/handlers/LedgerAccept.cpp
Expand Up @@ -34,7 +34,6 @@ namespace ripple {
Json::Value
doLedgerAccept(RPC::JsonContext& context)
{
std::unique_lock lock{context.app.getMasterMutex()};
Json::Value jvResult;

if (!context.app.config().standalone() || context.app.config().reporting())
Expand All @@ -43,8 +42,8 @@ doLedgerAccept(RPC::JsonContext& context)
}
else
{
std::unique_lock lock{context.app.getMasterMutex()};
context.netOps.acceptLedger();

jvResult[jss::ledger_current_index] =
context.ledgerMaster.getCurrentLedgerIndex();
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/rpc/LedgerRequestRPC_test.cpp
Expand Up @@ -318,9 +318,11 @@ class LedgerRequestRPC_test : public beast::unit_test::suite
{
using namespace test::jtx;
using namespace std::chrono_literals;
Env env{*this};
Env env{*this, envconfig([](std::unique_ptr<Config> cfg) {
cfg->NODE_SIZE = 0;
return cfg;
})};
Account const gw{"gateway"};
env.app().getLedgerMaster().tune(0, 1h);
auto const USD = gw["USD"];
env.fund(XRP(100000), gw);

Expand Down

0 comments on commit c7e6803

Please sign in to comment.