20 #include <ripple/app/ledger/InboundLedgers.h>
21 #include <ripple/app/ledger/LedgerCleaner.h>
22 #include <ripple/app/ledger/LedgerMaster.h>
23 #include <ripple/app/misc/LoadFeeTrack.h>
24 #include <ripple/beast/core/CurrentThreadName.h>
25 #include <ripple/protocol/jss.h>
82 LogicError(
"LedgerCleanerImp::stop not called.");
94 JLOG(
j_.
info()) <<
"Stopping";
115 map[
"status"] =
"idle";
118 map[
"status"] =
"running";
121 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
122 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
189 if (params.
isMember(jss::max_ledger))
192 if (params.
isMember(jss::min_ledger))
201 if (params.
isMember(jss::check_nodes))
252 <<
"Ledger #" << ledger->info().seq <<
": " << mn.
what();
258 return hash ? *hash : beast::zero;
279 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
287 if (!dbLedger || (dbLedger->info().hash != ledgerHash) ||
288 (dbLedger->info().parentHash != nodeLedger->info().parentHash))
292 <<
"Ledger " << ledgerIndex <<
" mismatches SQL DB";
299 <<
"ledger " << ledgerIndex <<
" had wrong entry in history";
303 if (doNodes && !nodeLedger->walkLedger(
app_.
journal(
"Ledger")))
305 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
314 JLOG(
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
333 if (!referenceLedger || (referenceLedger->info().seq < ledgerIndex))
336 if (!referenceLedger)
338 JLOG(
j_.
warn()) <<
"No validated ledger";
343 if (referenceLedger->info().seq >= ledgerIndex)
370 JLOG(
j_.
warn()) <<
"Validated ledger is prior to target ledger";
379 auto shouldExit = [
this] {
386 while (!shouldExit())
395 JLOG(
j_.
debug()) <<
"Waiting for load to subside";
413 ledgerHash =
getHash(ledgerIndex, goodLedger);
419 <<
"Unable to get hash for ledger " << ledgerIndex;
422 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
424 JLOG(
j_.
info()) <<
"Failed to process ledger " << ledgerIndex;
457 return std::make_unique<LedgerCleanerImp>(app, journal);
~LedgerCleanerImp() override
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
LedgerCleanerImp(Application &app, beast::Journal journal)
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.
std::unique_ptr< LedgerCleaner > make_LedgerCleaner(Application &app, beast::Journal journal)
void doLedgerCleaner()
Run the ledger cleaner.
LedgerHash getLedgerHash(std::shared_ptr< ReadView const > &ledger, LedgerIndex index)
virtual InboundLedgers & getInboundLedgers()=0
virtual LoadFeeTrack & getFeeTrack()=0
LedgerHash getHash(LedgerIndex const &ledgerIndex, std::shared_ptr< ReadView const > &referenceLedger)
Returns the hash of the specified ledger.
bool isLoadedLocal() const
std::condition_variable wakeup_
virtual LedgerMaster & getLedgerMaster()=0
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
void clean(Json::Value const ¶ms) override
Start a long running task to clean the ledger.
void setCurrentThreadName(std::string_view name)
Changes the name of the caller thread.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual beast::Journal journal(std::string const &name)=0
void clearLedger(std::uint32_t seq)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
std::shared_ptr< Ledger const > getValidatedLedger()
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Check the ledger/transaction databases to make sure they have continuity.
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.