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>
86 LogicError(
"LedgerCleanerImp::onStop not called.");
104 JLOG(
j_.
info()) <<
"Stopping";
125 map[
"status"] =
"idle";
128 map[
"status"] =
"running";
131 map[
"check_nodes"] =
checkNodes_ ?
"true" :
"false";
132 map[
"fix_txns"] =
fixTxns_ ?
"true" :
"false";
199 if (params.
isMember(jss::max_ledger))
202 if (params.
isMember(jss::min_ledger))
211 if (params.
isMember(jss::check_nodes))
234 JLOG(
j_.
debug()) <<
"Initializing";
267 boost::optional<LedgerHash> hash;
275 <<
"Ledger #" << ledger->info().seq <<
": " << mn.
what();
281 return hash ? *hash : beast::zero;
302 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" not available";
310 if (!dbLedger || (dbLedger->info().hash != ledgerHash) ||
311 (dbLedger->info().parentHash != nodeLedger->info().parentHash))
315 <<
"Ledger " << ledgerIndex <<
" mismatches SQL DB";
322 <<
"ledger " << ledgerIndex <<
" had wrong entry in history";
326 if (doNodes && !nodeLedger->walkLedger(
app_.
journal(
"Ledger")))
328 JLOG(
j_.
debug()) <<
"Ledger " << ledgerIndex <<
" is missing nodes";
337 JLOG(
j_.
debug()) <<
"Failed to save ledger " << ledgerIndex;
356 if (!referenceLedger || (referenceLedger->info().seq < ledgerIndex))
359 if (!referenceLedger)
361 JLOG(
j_.
warn()) <<
"No validated ledger";
366 if (referenceLedger->info().seq >= ledgerIndex)
393 JLOG(
j_.
warn()) <<
"Validated ledger is prior to target ledger";
402 auto shouldExit = [
this]() {
409 while (!shouldExit())
418 JLOG(
j_.
debug()) <<
"Waiting for load to subside";
438 ledgerHash =
getHash(ledgerIndex, goodLedger);
444 <<
"Unable to get hash for ledger " << ledgerIndex;
447 else if (!
doLedger(ledgerIndex, ledgerHash, doNodes, doTxns))
449 JLOG(
j_.
info()) <<
"Failed to process ledger " << ledgerIndex;
483 ,
beast::PropertyStream::Source(
"ledgercleaner")
492 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)
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.
std::shared_ptr< Ledger const > getValidatedLedger()
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)