20 #include <ripple/app/ledger/LedgerCleaner.h>
21 #include <ripple/app/ledger/InboundLedgers.h>
22 #include <ripple/app/ledger/LedgerMaster.h>
23 #include <ripple/app/misc/LoadFeeTrack.h>
24 #include <ripple/protocol/jss.h>
25 #include <ripple/beast/core/CurrentThreadName.h>
92 LogicError (
"LedgerCleanerImp::onStop not called.");
112 JLOG (
j_.
info()) <<
"Stopping";
132 map[
"status"] =
"idle";
135 map[
"status"] =
"running";
138 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
139 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
205 if (params.
isMember(jss::max_ledger))
208 if (params.
isMember(jss::min_ledger))
217 if (params.
isMember(jss::check_nodes))
239 JLOG (
j_.
debug()) <<
"Initializing";
245 JLOG (
j_.
debug()) <<
"Started";
275 boost::optional<LedgerHash> hash;
283 "Ledger #" << ledger->info().seq <<
": " << mn.
what();
285 ledger->info().hash, ledger->info().seq,
288 return hash ? *hash : beast::zero;
308 JLOG (
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
317 (dbLedger->info().hash != ledgerHash) ||
318 (dbLedger->info().parentHash != nodeLedger->info().parentHash))
322 "Ledger " << ledgerIndex <<
" mismatches SQL DB";
328 JLOG (
j_.
debug()) <<
"ledger " << ledgerIndex
329 <<
" had wrong entry in history";
333 if (doNodes && !nodeLedger->walkLedger(
app_.
journal (
"Ledger")))
335 JLOG (
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
344 JLOG (
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
362 if (!referenceLedger || (referenceLedger->info().seq < ledgerIndex))
365 if (!referenceLedger)
367 JLOG (
j_.
warn()) <<
"No validated ledger";
372 if (referenceLedger->info().seq >= ledgerIndex)
384 bool const nonzero (refHash.
isNonZero ());
395 referenceLedger, ledgerIndex);
400 JLOG (
j_.
warn()) <<
"Validated ledger is prior to target ledger";
408 auto shouldExit = [
this]()
416 while (! shouldExit())
425 JLOG (
j_.
debug()) <<
"Waiting for load to subside";
445 ledgerHash =
getHash(ledgerIndex, goodLedger);
450 JLOG (
j_.
info()) <<
"Unable to get hash for ledger "
454 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
456 JLOG (
j_.
info()) <<
"Failed to process ledger " << ledgerIndex;
491 ,
beast::PropertyStream::Source (
"ledgercleaner")
501 return std::make_unique<LedgerCleanerImp>(app, parent, journal);
LedgerCleaner(Stoppable &parent)
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
void doClean(Json::Value const ¶ms) override
Start a long running task to clean the ledger.
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
std::condition_variable wakeup_
void onStop() override
Override called when the stop notification is issued.
virtual InboundLedgers & getInboundLedgers()=0
virtual LoadFeeTrack & getFeeTrack()=0
void onWrite(beast::PropertyStream::Map &map) override
Subclass override.
bool isLoadedLocal() const
Provides an interface for starting and stopping.
std::unique_ptr< LedgerCleaner > make_LedgerCleaner(Application &app, Stoppable &parent, beast::Journal journal)
~LedgerCleanerImp() override
Check the ledger/transaction databases to make sure they have continuity.
virtual LedgerMaster & getLedgerMaster()=0
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
LedgerHash getHash(LedgerIndex const &ledgerIndex, std::shared_ptr< ReadView const > &referenceLedger)
Returns the hash of the specified ledger.
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
LedgerHash getLedgerHash(std::shared_ptr< ReadView const > &ledger, LedgerIndex index)
std::shared_ptr< Ledger const > getValidatedLedger()
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
virtual ~LedgerCleaner()=0
Destroy the object.
void onStart() override
Override called during start.
boost::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
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
bool doLedger(LedgerIndex const &ledgerIndex, LedgerHash const &ledgerHash, bool doNodes, bool doTxns)
Process a single ledger.
void clearLedger(std::uint32_t seq)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
void doLedgerCleaner()
Run the ledger cleaner.
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
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.
LedgerCleanerImp(Application &app, Stoppable &stoppable, beast::Journal journal)
void onPrepare() override
Override called during preparation.