20 #ifndef RIPPLE_APP_LEDGER_LEDGERMASTER_H_INCLUDED
21 #define RIPPLE_APP_LEDGER_LEDGERMASTER_H_INCLUDED
23 #include <ripple/app/ledger/AbstractFetchPackContainer.h>
24 #include <ripple/app/ledger/InboundLedgers.h>
25 #include <ripple/app/ledger/Ledger.h>
26 #include <ripple/app/ledger/LedgerHistory.h>
27 #include <ripple/app/ledger/LedgerHolder.h>
28 #include <ripple/app/ledger/LedgerReplay.h>
29 #include <ripple/app/main/Application.h>
30 #include <ripple/app/misc/CanonicalTXSet.h>
31 #include <ripple/basics/RangeSet.h>
32 #include <ripple/basics/StringUtilities.h>
33 #include <ripple/basics/UptimeClock.h>
34 #include <ripple/basics/chrono.h>
35 #include <ripple/beast/insight/Collector.h>
36 #include <ripple/protocol/Protocol.h>
37 #include <ripple/protocol/RippleLedgerHash.h>
38 #include <ripple/protocol/STValidation.h>
39 #include <ripple/protocol/messages.h>
61 "Reporting mode has no open or closed ledger. Proxy this "
102 Throw<ReportingShouldProxy>();
414 template <
class Handler>
416 Handler
const& handler,
418 :
hook(collector->make_hook(handler))
420 collector->make_gauge(
"LedgerMaster",
"Validated_Ledger_Age"))
422 collector->make_gauge(
"LedgerMaster",
"Published_Ledger_Age"))
bool getValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
std::shared_ptr< Ledger const > mPubLedger
LedgerHolder mClosedLedger
std::shared_ptr< ReadView const > getPublishedLedger()
TaggedCache< uint256, Blob > fetch_packs_
void makeFetchPack(std::weak_ptr< Peer > const &wPeer, std::shared_ptr< protocol::TMGetObjectByHash > const &request, uint256 haveLedgerHash, UptimeClock::time_point uptime)
void clearLedgerCachePrior(LedgerIndex seq)
std::atomic< LedgerIndex > mBuildingLedgerSeq
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector)
LedgerHistory mLedgerHistory
CanonicalTXSet mHeldTransactions
LedgerIndex getValidLedgerIndex()
std::shared_ptr< Ledger const > mHistLedger
beast::insight::Hook hook
std::chrono::seconds getPublishedLedgerAge()
TimeKeeper::time_point upgradeWarningPrevTime_
std::unique_ptr< LedgerReplay > releaseReplay()
Rules getValidatedRules()
std::recursive_mutex mCompleteLock
void applyHeldTransactions()
Apply held transactions to the open ledger This is normally called as we close the ledger.
void switchLCL(std::shared_ptr< Ledger const > const &lastClosed)
bool newPFWork(const char *name, std::unique_lock< std::recursive_mutex > &)
A thread needs to be dispatched to handle pathfinding work of some kind.
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
Stopwatch & stopwatch()
Returns an instance of a wall clock.
std::uint32_t getEarliestFetch()
Retains historical ledgers.
std::optional< LedgerHash > walkHashBySeq(std::uint32_t index, InboundLedger::Reason reason)
Walk to a ledger's hash using the skip list.
void setFullLedger(std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
void fixMismatch(ReadView const &ledger)
const std::uint32_t fetch_depth_
Holds transactions which were deferred to the next pass of consensus.
std::string getCompleteLedgers()
const std::uint32_t ledger_fetch_size_
beast::insight::Gauge validatedLedgerAge
std::recursive_mutex & peekMutex()
std::atomic_flag mGotFetchPackThread
RangeSet< std::uint32_t > mCompleteLedgers
std::unique_ptr< LedgerReplay > replayData
void gotFetchPack(bool progress, std::uint32_t seq)
void fetchForHistory(std::uint32_t missing, bool &progress, InboundLedger::Reason reason, std::unique_lock< std::recursive_mutex > &)
std::optional< Blob > getFetchPack(uint256 const &hash) override
Retrieves partial ledger data of the coresponding hash from peers.
void failedSave(std::uint32_t seq, uint256 const &hash)
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
virtual Config & config()=0
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
bool canBeCurrent(std::shared_ptr< Ledger const > const &ledger)
Check the sequence number and parent close time of a ledger against our clock and last validated ledg...
An interface facilitating retrieval of fetch packs without an application or ledgermaster object.
bool haveLedger(std::uint32_t seq)
Provide a light-weight way to check active() before string formatting.
bool isCompatible(ReadView const &, beast::Journal::Stream, char const *reason)
std::optional< LedgerIndex > minSqlSeq()
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
A generic endpoint for log messages.
void addHeldTransaction(std::shared_ptr< Transaction > const &trans)
void setValidLedger(std::shared_ptr< Ledger const > const &l)
std::shared_ptr< Ledger const > get()
std::shared_ptr< ReadView const > getCurrentLedger()
std::size_t getNeededValidations()
Determines how many validations are needed to fully validate a ledger.
void checkAccept(std::shared_ptr< Ledger const > const &ledger)
A metric for measuring an integral value.
const LedgerIndex max_ledger_difference_
std::size_t getFetchPackCacheSize() const
std::shared_ptr< Ledger const > mPathLedger
bool haveValidated()
Whether we have ever fully validated a ledger.
std::chrono::seconds getValidatedLedgerAge()
std::shared_ptr< Ledger const > getClosedLedger()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
beast::insight::Gauge publishedLedgerAge
std::atomic< std::uint32_t > mPubLedgerClose
const std::uint32_t ledger_history_
std::atomic< LedgerIndex > mPubLedgerSeq
virtual ~LedgerMaster()=default
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > data)
void clearLedger(std::uint32_t seq)
std::optional< LedgerHash > getLedgerHashForHistory(LedgerIndex index, InboundLedger::Reason reason)
std::atomic< LedgerIndex > mValidLedgerSeq
LedgerIndex getCurrentLedgerIndex()
Hold a ledger in a thread-safe way.
void takeReplay(std::unique_ptr< LedgerReplay > replay)
std::shared_ptr< Ledger const > getValidatedLedger()
std::pair< uint256, LedgerIndex > mLastValidLedger
Rules controlling protocol behavior.
std::shared_ptr< Ledger const > mShardLedger
bool storeLedger(std::shared_ptr< Ledger const > ledger)
boost::icl::interval_set< T, std::less, ClosedInterval< T > > RangeSet
A set of closed intervals over the domain T.
void setLedgerRangePresent(std::uint32_t minV, std::uint32_t maxV)
void consensusBuilt(std::shared_ptr< Ledger const > const &ledger, uint256 const &consensusHash, Json::Value consensus)
Report that the consensus process built a particular ledger.
void tryFill(std::shared_ptr< Ledger const > ledger)
LedgerHolder mValidLedger
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
std::vector< std::shared_ptr< Ledger const > > findNewLedgersToPublish(std::unique_lock< std::recursive_mutex > &)
bool isCaughtUp(std::string &reason)
std::optional< NetClock::time_point > getCloseTimeByHash(LedgerHash const &ledgerHash, LedgerIndex ledgerIndex)
std::atomic< std::uint32_t > mValidLedgerSign
void setBuildingLedger(LedgerIndex index)
void doAdvance(std::unique_lock< std::recursive_mutex > &)
void clearPriorLedgers(LedgerIndex seq)
void setPubLedger(std::shared_ptr< Ledger const > const &l)
typename NetClock ::time_point time_point
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Get the next transaction held for a particular account if any.
A reference to a handler for performing polled collection.
LedgerMaster(Application &app, Stopwatch &stopwatch, beast::insight::Collector::ptr const &collector, beast::Journal journal)
void set(value_type value) const
Set the value on the gauge.
std::recursive_mutex m_mutex