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>
64 LogicError(
"LedgerCleanerImp::stop not called.");
76 JLOG(
j_.
info()) <<
"Stopping";
97 map[
"status"] =
"idle";
100 map[
"status"] =
"running";
103 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
104 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
171 if (params.
isMember(jss::max_ledger))
174 if (params.
isMember(jss::min_ledger))
183 if (params.
isMember(jss::check_nodes))
218 "xrpl::LedgerCleanerImp::run : is cleaning");
236 <<
"Ledger #" << ledger->header().seq <<
": " << mn.
what();
238 ledger->header().hash,
239 ledger->header().seq,
242 return hash ? *hash : beast::zero;
263 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
271 if (!dbLedger || (dbLedger->header().hash != ledgerHash) ||
272 (dbLedger->header().parentHash != nodeLedger->header().parentHash))
276 <<
"Ledger " << ledgerIndex <<
" mismatches SQL DB";
283 <<
"ledger " << ledgerIndex <<
" had wrong entry in history";
287 if (doNodes && !nodeLedger->walkLedger(
app_.
journal(
"Ledger")))
289 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
298 JLOG(
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
317 if (!referenceLedger || (referenceLedger->header().seq < ledgerIndex))
320 if (!referenceLedger)
322 JLOG(
j_.
warn()) <<
"No validated ledger";
327 if (referenceLedger->header().seq >= ledgerIndex)
341 nonzero,
"xrpl::LedgerCleanerImp::getHash : nonzero hash");
355 JLOG(
j_.
warn()) <<
"Validated ledger is prior to target ledger";
364 auto shouldExit = [
this] {
371 while (!shouldExit())
380 JLOG(
j_.
debug()) <<
"Waiting for load to subside";
398 ledgerHash =
getHash(ledgerIndex, goodLedger);
404 <<
"Unable to get hash for ledger " << ledgerIndex;
407 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
409 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 InboundLedgers & getInboundLedgers()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual LedgerMaster & getLedgerMaster()=0
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
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.