1#include <xrpld/app/ledger/InboundLedgers.h>
2#include <xrpld/app/ledger/LedgerCleaner.h>
3#include <xrpld/app/ledger/LedgerMaster.h>
4#include <xrpld/app/misc/LoadFeeTrack.h>
6#include <xrpl/beast/core/CurrentThreadName.h>
7#include <xrpl/protocol/jss.h>
63 LogicError(
"LedgerCleanerImp::stop not called.");
75 JLOG(
j_.
info()) <<
"Stopping";
96 map[
"status"] =
"idle";
99 map[
"status"] =
"running";
102 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
103 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
170 if (params.
isMember(jss::max_ledger))
173 if (params.
isMember(jss::min_ledger))
182 if (params.
isMember(jss::check_nodes))
230 JLOG(
j_.
warn()) <<
"Ledger #" << ledger->header().seq <<
": " << mn.
what();
234 return hash ? *hash : beast::zero;
250 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
257 if (!dbLedger || (dbLedger->header().hash != ledgerHash) ||
258 (dbLedger->header().parentHash != nodeLedger->header().parentHash))
261 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" mismatches SQL DB";
267 JLOG(
j_.
debug()) <<
"ledger " << ledgerIndex <<
" had wrong entry in history";
271 if (doNodes && !nodeLedger->walkLedger(
app_.
journal(
"Ledger")))
273 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
281 JLOG(
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
298 if (!referenceLedger || (referenceLedger->header().seq < ledgerIndex))
301 if (!referenceLedger)
303 JLOG(
j_.
warn()) <<
"No validated ledger";
308 if (referenceLedger->header().seq >= ledgerIndex)
321 XRPL_ASSERT(nonzero,
"xrpl::LedgerCleanerImp::getHash : nonzero hash");
334 JLOG(
j_.
warn()) <<
"Validated ledger is prior to target ledger";
343 auto shouldExit = [
this] {
350 while (!shouldExit())
359 JLOG(
j_.
debug()) <<
"Waiting for load to subside";
376 ledgerHash =
getHash(ledgerIndex, goodLedger);
381 JLOG(
j_.
info()) <<
"Unable to get hash for ledger " << ledgerIndex;
384 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
386 JLOG(
j_.
info()) <<
"Failed to process ledger " << ledgerIndex;
bool isMember(char const *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
virtual beast::Journal journal(std::string const &name)=0
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
std::condition_variable wakeup_
LedgerHash getHash(LedgerIndex const &ledgerIndex, std::shared_ptr< ReadView const > &referenceLedger)
Returns the hash of the specified ledger.
~LedgerCleanerImp() override
void clean(Json::Value const ¶ms) override
Start a long running task to clean the ledger.
void doLedgerCleaner()
Run the ledger cleaner.
void onWrite(beast::PropertyStream::Map &map) override
Subclass override.
bool doLedger(LedgerIndex const &ledgerIndex, LedgerHash const &ledgerHash, bool doNodes, bool doTxns)
Process a single ledger.
LedgerCleanerImp(Application &app, beast::Journal journal)
LedgerHash getLedgerHash(std::shared_ptr< ReadView const > &ledger, LedgerIndex index)
Check the ledger/transaction databases to make sure they have continuity.
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
void clearLedger(std::uint32_t seq)
std::shared_ptr< Ledger const > getValidatedLedger()
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
bool isLoadedLocal() const
virtual LoadFeeTrack & getFeeTrack()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual LedgerMaster & getLedgerMaster()=0
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
std::unique_ptr< LedgerCleaner > make_LedgerCleaner(Application &app, beast::Journal journal)
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.