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/ledger/LedgerPersistence.h>
5#include <xrpld/app/main/Application.h>
7#include <xrpl/beast/core/CurrentThreadName.h>
8#include <xrpl/protocol/jss.h>
9#include <xrpl/server/LoadFeeTrack.h>
65 LogicError(
"LedgerCleanerImp::stop not called.");
77 JLOG(
j_.
info()) <<
"Stopping";
99 map[
"status"] =
"idle";
103 map[
"status"] =
"running";
106 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
107 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
174 if (params.
isMember(jss::max_ledger))
177 if (params.
isMember(jss::min_ledger))
186 if (params.
isMember(jss::check_nodes))
234 JLOG(
j_.
warn()) <<
"Ledger #" << ledger->header().seq <<
": " << mn.
what();
238 return hash ? *hash : beast::zero;
259 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
269 if (!dbLedger || (dbLedger->header().hash != ledgerHash) ||
270 (dbLedger->header().parentHash != nodeLedger->header().parentHash))
273 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" mismatches SQL DB";
279 JLOG(
j_.
debug()) <<
"ledger " << ledgerIndex <<
" had wrong entry in history";
283 if (doNodes && !nodeLedger->walkLedger(
app_.
getJournal(
"Ledger")))
285 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
294 JLOG(
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
311 if (!referenceLedger || (referenceLedger->header().seq < ledgerIndex))
314 if (!referenceLedger)
316 JLOG(
j_.
warn()) <<
"No validated ledger";
321 if (referenceLedger->header().seq >= ledgerIndex)
334 XRPL_ASSERT(nonzero,
"xrpl::LedgerCleanerImp::getHash : nonzero hash");
347 JLOG(
j_.
warn()) <<
"Validated ledger is prior to target ledger";
356 auto shouldExit = [
this] {
363 while (!shouldExit())
367 bool doNodes =
false;
372 JLOG(
j_.
debug()) <<
"Waiting for load to subside";
389 ledgerHash =
getHash(ledgerIndex, goodLedger);
394 JLOG(
j_.
info()) <<
"Unable to get hash for ledger " << ledgerIndex;
397 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
399 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 Config & config()=0
std::unordered_set< uint256, beast::uhash<> > features
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
Rules controlling protocol behavior.
virtual beast::Journal getJournal(std::string const &name)=0
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.
bool pendSaveValidated(ServiceRegistry ®istry, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger.
std::unique_ptr< LedgerCleaner > make_LedgerCleaner(Application &app, beast::Journal journal)
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Rules const &rules, Fees const &fees, ServiceRegistry ®istry, bool acquire)
Load a ledger by its sequence number.
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Fees toFees() const
Convert to a Fees object for use with Ledger construction.
Reflects the fee settings for a particular ledger.