|
xrpld
|
Tracks the current ledger and any ledgers in the process of closing. More...
#include <LedgerMaster.h>


Classes | |
| struct | Stats |
| Ledger-age gauges reported to the insight collector. More... | |
Public Member Functions | |
| LedgerMaster (Application &app, Stopwatch &stopwatch, beast::insight::Collector::Ptr const &collector, beast::Journal journal) | |
| Constructs the tracker; reads history and fetch limits from the config. | |
| ~LedgerMaster () override=default | |
| Destroys the tracker. | |
| LedgerIndex | getCurrentLedgerIndex () |
| LedgerIndex | getValidLedgerIndex () |
| bool | isCompatible (ReadView const &, beast::Journal::Stream, char const *reason) |
| Tests whether a view can belong to the same chain as what we validated. | |
| std::recursive_mutex & | peekMutex () |
| Exposes mutex_. | |
| std::shared_ptr< ReadView const > | getCurrentLedger () |
| The current ledger is the ledger we believe new transactions should go in. | |
| std::shared_ptr< Ledger const > | getClosedLedger () |
| The finalized ledger is the last closed/accepted ledger. | |
| std::shared_ptr< Ledger const > | getValidatedLedger () |
| The validated ledger is the last fully validated ledger. | |
| Rules | getValidatedRules () |
| The Rules are in the last fully validated ledger if there is one. | |
| std::shared_ptr< ReadView const > | getPublishedLedger () |
| This is the last ledger we published to clients and can lag the validated ledger. | |
| std::chrono::seconds | getPublishedLedgerAge () |
| std::chrono::seconds | getValidatedLedgerAge () |
| bool | isCaughtUp (std::string &reason) |
| Decides whether the node is close enough to the network to serve clients. | |
| std::uint32_t | getEarliestFetch () |
| Get the earliest ledger we will let peers fetch. | |
| bool | storeLedger (std::shared_ptr< Ledger const > ledger) |
| Adds a ledger to the history cache. | |
| void | setFullLedger (std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent) |
| A new ledger has been accepted as part of the trusted chain: mark it validated and full, record it as resident, persist it, and repair the chain behind it if the parent turns out to disagree. | |
| 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 ledger to see if it can be the network's current ledger. | |
| void | switchLCL (std::shared_ptr< Ledger const > const &lastClosed) |
| Adopts a ledger as the last closed ledger, then either accepts it directly (standalone) or tests it for validation (networked). | |
| void | failedSave (std::uint32_t seq, UInt256 const &hash) |
| Marks a ledger no longer resident after its save failed, and starts fetching it again. | |
| std::string | getCompleteLedgers () const |
| std::size_t | missingFromCompleteLedgerRange (LedgerIndex first, LedgerIndex last) const |
| Counts gaps in a closed sequence interval. | |
| void | applyHeldTransactions () |
| Apply held transactions to the open ledger This is normally called as we close the ledger. | |
| std::shared_ptr< STTx const > | popAcctTransaction (std::shared_ptr< STTx const > const &tx) |
| Get the next transaction held for a particular account if any. | |
| UInt256 | getHashBySeq (std::uint32_t index) |
| Get a ledger's hash by sequence number using the cache. | |
| std::optional< LedgerHash > | walkHashBySeq (std::uint32_t index, InboundLedger::Reason reason) |
| Walk to a ledger's hash using the skip list. | |
| std::optional< LedgerHash > | walkHashBySeq (std::uint32_t index, std::shared_ptr< ReadView const > const &referenceLedger, InboundLedger::Reason reason) |
| Walk the chain of ledger hashes to determine the hash of the ledger with the specified index. | |
| std::shared_ptr< Ledger const > | getLedgerBySeq (std::uint32_t index) |
| Finds a ledger by sequence, preferring the validated chain. | |
| std::shared_ptr< Ledger const > | getLedgerByHash (UInt256 const &hash) |
| void | setLedgerRangePresent (std::uint32_t minV, std::uint32_t maxV) |
| Records a closed range of sequences as resident. | |
| std::optional< NetClock::time_point > | getCloseTimeBySeq (LedgerIndex ledgerIndex) |
| std::optional< NetClock::time_point > | getCloseTimeByHash (LedgerHash const &ledgerHash, LedgerIndex ledgerIndex) |
| Reads a close time straight out of the serialized header in the node store. | |
| void | addHeldTransaction (std::shared_ptr< Transaction > const &trans) |
| Defers a transaction to the next open ledger. | |
| void | fixMismatch (ReadView const &ledger) |
| Walks back from a ledger, dropping every resident ledger it cannot confirm against that ledger's skip list: a mismatch, one it cannot load, or one too far back to look up. | |
| bool | haveLedger (std::uint32_t seq) const |
| void | clearLedger (std::uint32_t seq) |
| Marks a ledger no longer resident. | |
| bool | isValidated (ReadView const &ledger) |
| Tests whether a ledger is on the validated chain, using the skip list when the ledger does not already say so. | |
| bool | getValidatedRange (std::uint32_t &minVal, std::uint32_t &maxVal) |
| Returns Ledgers we have all the nodes for and are indexed: a contiguous part of getFullValidatedRange() with no ledger still being saved. | |
| bool | getFullValidatedRange (std::uint32_t &minVal, std::uint32_t &maxVal) |
| Returns Ledgers we have all the nodes for: the contiguous resident range ending at the published ledger. | |
| void | sweep () |
| Expires stale entries from the ledger history and fetch-pack caches. | |
| float | getCacheHitRate () |
| void | checkAccept (std::shared_ptr< Ledger const > const &ledger) |
| If the ledger passes canBeCurrent(), is newer than the validated ledger and has a quorum, makes it the last fully validated ledger. | |
| void | checkAccept (UInt256 const &hash, std::uint32_t seq) |
| Check if the specified ledger can become the new last fully-validated ledger, fetching it if it is not resident. | |
| 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 | setBuildingLedger (LedgerIndex index) |
| Records which ledger consensus is currently building, so validations for it are not chased separately. | |
| void | tryAdvance () |
| Signals that the ledger stream may be able to make progress. | |
| bool | newPathRequest () |
| Notes a new pathfinding request and dispatches a worker if one is due. | |
| bool | isNewPathRequest () |
| bool | newOrderBookDB () |
| If the order book is radically updated, we need to reprocess all pathfinding requests. | |
| bool | fixIndex (LedgerIndex ledgerIndex, LedgerHash const &ledgerHash) |
| Corrects the cached sequence-to-hash mapping for one ledger. | |
| void | clearPriorLedgers (LedgerIndex seq) |
| Forgets that we hold any ledger below a sequence, without touching the cached ledgers themselves. | |
| void | clearLedgerCachePrior (LedgerIndex seq) |
| Drops cached ledgers below a sequence. | |
| void | takeReplay (std::unique_ptr< LedgerReplay > replay) |
| Stores a transaction set to replay when the next ledger closes. | |
| std::unique_ptr< LedgerReplay > | releaseReplay () |
| void | gotFetchPack (bool progress, std::uint32_t seq) |
| Signals that fetch-pack data arrived, so waiting acquires can use it. | |
| void | addFetchPack (UInt256 const &hash, std::shared_ptr< Blob > data) |
| Caches one fetch-pack node received from a peer. | |
| std::optional< Blob > | getFetchPack (UInt256 const &hash) override |
| Consumes one cached fetch-pack node. | |
| void | makeFetchPack (std::weak_ptr< Peer > const &wPeer, std::shared_ptr< protocol::TMGetObjectByHash > const &request, UInt256 haveLedgerHash, UptimeClock::time_point uptime) |
| Builds a fetch pack of the ledgers preceding the one a peer says it has, and sends it. | |
| std::size_t | getFetchPackCacheSize () const |
| bool | haveValidated () |
| Whether we have ever fully validated a ledger. | |
| std::optional< LedgerIndex > | minSqlSeq () |
| Returns the minimum ledger sequence in SQL database, if any. | |
| std::optional< UInt256 > | txnIdFromIndex (uint32_t ledgerSeq, uint32_t txnIndex) |
| Iff a txn exists at the specified ledger and offset then return its txnid. | |
Private Member Functions | |
| void | setValidLedger (std::shared_ptr< Ledger const > const &l) |
| Adopts a ledger as the last validated one and tells the rest of the server, including the amendment-support checks that can block the node. | |
| void | setPubLedger (std::shared_ptr< Ledger const > const &l) |
| Records how far publication has reached. | |
| void | tryFill (std::shared_ptr< Ledger const > ledger) |
| Walks back from a ledger through the SQL index, marking each ancestor resident until the chain breaks or a known ledger is reached. | |
| void | getFetchPack (LedgerIndex missing, InboundLedger::Reason reason) |
| Request a fetch pack to get to the specified ledger. | |
| std::optional< LedgerHash > | getLedgerHashForHistory (LedgerIndex index, InboundLedger::Reason reason) |
| Finds the hash of a ledger the history back-fill wants, preferring the last back-filled ledger as the reference to walk from. | |
| std::size_t | getNeededValidations () |
| Determines how many validations are needed to fully validate a ledger. | |
| void | fetchForHistory (std::uint32_t missing, bool &progress, InboundLedger::Reason reason, std::unique_lock< std::recursive_mutex > &) |
| Starts acquiring one missing historical ledger. | |
| void | doAdvance (std::unique_lock< std::recursive_mutex > &) |
| Try to publish ledgers, acquire missing ledgers. | |
| std::vector< std::shared_ptr< Ledger const > > | findNewLedgersToPublish (std::unique_lock< std::recursive_mutex > &) |
| Collects the next run of validated ledgers to publish, acquiring or replaying the ones that are missing. | |
| void | updatePaths () |
| Runs one pathfinding pass per new validated ledger or new request, and exits when neither is new, even if requests are still pending. | |
| bool | newPFWork (char const *name, std::unique_lock< std::recursive_mutex > &) |
| A thread needs to be dispatched to handle pathfinding work of some kind. | |
| void | collectMetrics () |
| Samples both ledger ages into the gauges. | |
Private Attributes | |
| Application & | app_ |
| Owning application, the route to every other subsystem. | |
| beast::Journal | journal_ |
| Log sink for this component. | |
| std::recursive_mutex | mutex_ |
| Guards pubLedger_, pathLedger_, lastValidLedger_, the held transactions and the job flags other than the atomic gotFetchPackThread_. | |
| LedgerHolder | closedLedger_ |
| The ledger that most recently closed. | |
| LedgerHolder | validLedger_ |
| The highest-sequence ledger we have fully accepted. | |
| std::shared_ptr< Ledger const > | pubLedger_ |
| The last ledger we have published. | |
| std::shared_ptr< Ledger const > | pathLedger_ |
| The last ledger we did pathfinding against. | |
| std::shared_ptr< Ledger const > | histLedger_ |
| The last ledger we handled fetching history. | |
| std::pair< UInt256, LedgerIndex > | lastValidLedger_ {UInt256(), 0} |
| Fully validated ledger, whether or not we have the ledger resident. | |
| LedgerHistory | ledgerHistory_ |
| Cache of ledgers by hash and of validated sequence-to-hash mappings. | |
| CanonicalTXSet | heldTransactions_ {UInt256()} |
| Transactions deferred to the next open ledger, in canonical order. | |
| std::unique_ptr< LedgerReplay > | replayData_ |
| A set of transactions to replay during the next close. | |
| std::recursive_mutex | completeLock_ |
| Guards completeLedgers_ only. | |
| RangeSet< std::uint32_t > | completeLedgers_ |
| Sequences of the ledgers this node believes it holds in full. | |
| bool | advanceThread_ {false} |
| An AdvanceLedger job is queued or running. | |
| bool | advanceWork_ {false} |
| Publish thread has work to do. | |
| int | fillInProgress_ {0} |
| Sequence a tryFill() job is currently walking back from, or 0 when no fill is running. | |
| int | pathFindThread_ {0} |
| Pathfinding jobs queued or running. | |
| bool | pathFindNewRequest_ {false} |
| A pathfinding request arrived and has not been picked up yet. | |
| std::atomic_flag | gotFetchPackThread_ = ATOMIC_FLAG_INIT |
| Set while a GotFetchPack job is outstanding, so only one ever is. | |
| std::atomic< std::uint32_t > | pubLedgerClose_ {0} |
| Close time of pubLedger_, in seconds since the network epoch; 0 if none. | |
| std::atomic< LedgerIndex > | pubLedgerSeq_ {0} |
| Sequence of pubLedger_; 0 if nothing has been published. | |
| std::atomic< std::uint32_t > | validLedgerSign_ {0} |
| Sign time of validLedger_, in seconds since the network epoch: the median of its trusted validations, or its close time when those were too few. | |
| std::atomic< LedgerIndex > | validLedgerSeq_ {0} |
| Sequence of validLedger_; 0 if nothing is validated. | |
| std::atomic< LedgerIndex > | buildingLedgerSeq_ {0} |
| Sequence consensus is building; 0 once it is built. | |
| bool const | standalone_ |
| The server is in standalone mode. | |
| std::uint32_t const | fetchDepth_ |
| How many ledgers before the closed ledger do we allow peers to request? | |
| std::uint32_t const | ledgerHistorySize_ |
| How much history do we want to keep. | |
| std::uint32_t const | ledgerFetchSize_ |
| Cap on ledgers acquired in one publication or prefetch pass. | |
| TaggedCache< UInt256, Blob > | fetchPacks_ |
| Fetch-pack nodes keyed by node hash. | |
| std::uint32_t | fetchSeq_ {0} |
| Sequence of the last fetch-pack attempt, so the same one is not tried twice in a row. | |
| LedgerIndex const | maxLedgerDifference_ {1000000} |
| Try to keep a validator from switching from test to live network without first wiping the database. | |
| TimeKeeper::time_point | upgradeWarningPrevTime_ |
| Time that the previous upgrade warning was issued. | |
| Stats | stats_ |
| The gauges and the collector hook that samples them. | |
Tracks the current ledger and any ledgers in the process of closing.
Tracks ledger history. Tracks held transactions.
Four ledgers are tracked, and they can all differ:
Advancing the stream is a state machine run on a JobQueue thread. Callers only ever poke it with tryAdvance(); the loop decides what to do next:
Definition at line 121 of file LedgerMaster.h.
|
explicit |
Constructs the tracker; reads history and fetch limits from the config.
| app | Owning application, used to reach every other subsystem. |
| stopwatch | Clock driving expiry of the fetch-pack cache. |
| collector | Sink for the ledger-age gauges and the history cache's mismatch counter. |
| journal | Log sink. |
Definition at line 147 of file LedgerMaster.cpp.
|
overridedefault |
Destroys the tracker.
Outstanding JobQueue work must already have been drained, since those jobs capture this.
| LedgerIndex xrpl::LedgerMaster::getCurrentLedgerIndex | ( | ) |
Definition at line 170 of file LedgerMaster.cpp.
| LedgerIndex xrpl::LedgerMaster::getValidLedgerIndex | ( | ) |
Definition at line 176 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::isCompatible | ( | ReadView const & | view, |
| beast::Journal::Stream | s, | ||
| char const * | reason ) |
Tests whether a view can belong to the same chain as what we validated.
| view | Ledger view to test. |
| s | Stream the reason for a mismatch is logged to. |
| reason | Caller-supplied label for that log line. |
Definition at line 182 of file LedgerMaster.cpp.
| std::recursive_mutex & xrpl::LedgerMaster::peekMutex | ( | ) |
Exposes mutex_.
Holding it across several calls keeps the closed, validated and published ledgers from changing; the open ledger is not covered.
Definition at line 1587 of file LedgerMaster.cpp.
| std::shared_ptr< ReadView const > xrpl::LedgerMaster::getCurrentLedger | ( | ) |
The current ledger is the ledger we believe new transactions should go in.
Definition at line 1594 of file LedgerMaster.cpp.
| std::shared_ptr< Ledger const > xrpl::LedgerMaster::getClosedLedger | ( | ) |
The finalized ledger is the last closed/accepted ledger.
Definition at line 193 of file LedgerMaster.h.
| std::shared_ptr< Ledger const > xrpl::LedgerMaster::getValidatedLedger | ( | ) |
The validated ledger is the last fully validated ledger.
Definition at line 1600 of file LedgerMaster.cpp.
| Rules xrpl::LedgerMaster::getValidatedRules | ( | ) |
The Rules are in the last fully validated ledger if there is one.
Definition at line 1606 of file LedgerMaster.cpp.
| std::shared_ptr< ReadView const > xrpl::LedgerMaster::getPublishedLedger | ( | ) |
This is the last ledger we published to clients and can lag the validated ledger.
Definition at line 1621 of file LedgerMaster.cpp.
| std::chrono::seconds xrpl::LedgerMaster::getPublishedLedgerAge | ( | ) |
Definition at line 205 of file LedgerMaster.cpp.
| std::chrono::seconds xrpl::LedgerMaster::getValidatedLedgerAge | ( | ) |
Definition at line 229 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::isCaughtUp | ( | std::string & | reason | ) |
Decides whether the node is close enough to the network to serve clients.
| reason | Set to a human-readable explanation when the answer is false. |
Definition at line 254 of file LedgerMaster.cpp.
| std::uint32_t xrpl::LedgerMaster::getEarliestFetch | ( | ) |
Get the earliest ledger we will let peers fetch.
Definition at line 653 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::storeLedger | ( | std::shared_ptr< Ledger const > | ledger | ) |
Adds a ledger to the history cache.
Does not itself validate the ledger, but honours the flag the ledger already carries: a ledger marked validated is also indexed by sequence.
| ledger | Immutable ledger to cache. |
Definition at line 476 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::setFullLedger | ( | std::shared_ptr< Ledger const > const & | ledger, |
| bool | isSynchronous, | ||
| bool | isCurrent ) |
A new ledger has been accepted as part of the trusted chain: mark it validated and full, record it as resident, persist it, and repair the chain behind it if the parent turns out to disagree.
It also becomes the validated ledger if newer, and the published one if none is set.
| ledger | Ledger to accept. |
| isSynchronous | true to write it to the database before returning. |
| isCurrent | true adds the ledger to the in-memory sequence index and saves it as a current ledger, at the higher job priority. Only the publish path passes true; standalone, startup and back-fill pass false. |
Definition at line 844 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::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 ledger to see if it can be the network's current ledger.
| ledger | Candidate ledger; must not be null. |
Definition at line 379 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::switchLCL | ( | std::shared_ptr< Ledger const > const & | lastClosed | ) |
Adopts a ledger as the last closed ledger, then either accepts it directly (standalone) or tests it for validation (networked).
| lastClosed | Closed, immutable ledger. Passing an open or mutable ledger is a logic error and terminates the process. |
Definition at line 444 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::failedSave | ( | std::uint32_t | seq, |
| UInt256 const & | hash ) |
Marks a ledger no longer resident after its save failed, and starts fetching it again.
| seq | Sequence of the ledger that failed to save. |
| hash | Hash of that ledger, used to re-acquire it. |
Definition at line 905 of file LedgerMaster.cpp.
| std::string xrpl::LedgerMaster::getCompleteLedgers | ( | ) | const |
Definition at line 1628 of file LedgerMaster.cpp.
| std::size_t xrpl::LedgerMaster::missingFromCompleteLedgerRange | ( | LedgerIndex | first, |
| LedgerIndex | last ) const |
Counts gaps in a closed sequence interval.
| first | Lowest sequence to test; must not exceed last. |
| last | Highest sequence to test. |
Definition at line 1635 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::applyHeldTransactions | ( | ) |
Apply held transactions to the open ledger This is normally called as we close the ledger.
The open ledger remains open to handle new transactions until a new open ledger is built.
Definition at line 490 of file LedgerMaster.cpp.
| std::shared_ptr< STTx const > xrpl::LedgerMaster::popAcctTransaction | ( | std::shared_ptr< STTx const > const & | tx | ) |
Get the next transaction held for a particular account if any.
This is normally called when a transaction for that account is successfully applied to the open ledger so the next transaction can be resubmitted without waiting for ledger close.
| tx | Transaction that was just applied; its account and sequence select the successor. |
Definition at line 506 of file LedgerMaster.cpp.
| UInt256 xrpl::LedgerMaster::getHashBySeq | ( | std::uint32_t | index | ) |
Get a ledger's hash by sequence number using the cache.
| index | Ledger sequence to look up. |
Definition at line 1685 of file LedgerMaster.cpp.
| std::optional< LedgerHash > xrpl::LedgerMaster::walkHashBySeq | ( | std::uint32_t | index, |
| InboundLedger::Reason | reason ) |
Walk to a ledger's hash using the skip list.
| index | Ledger sequence wanted. |
| reason | Why the ledger is needed, for any acquire this triggers. |
Definition at line 1696 of file LedgerMaster.cpp.
| std::optional< LedgerHash > xrpl::LedgerMaster::walkHashBySeq | ( | std::uint32_t | index, |
| std::shared_ptr< ReadView const > const & | referenceLedger, | ||
| InboundLedger::Reason | reason ) |
Walk the chain of ledger hashes to determine the hash of the ledger with the specified index.
The referenceLedger is used as the base of the chain and should be fully validated and must not precede the target index. This function may throw if nodes from the reference ledger or any prior ledger are not present in the node store.
| index | Ledger sequence wanted. |
| referenceLedger | Ledger to walk back from. |
| reason | Why the ledger is needed, for any acquire this triggers. |
Definition at line 1707 of file LedgerMaster.cpp.
| std::shared_ptr< Ledger const > xrpl::LedgerMaster::getLedgerBySeq | ( | std::uint32_t | index | ) |
Finds a ledger by sequence, preferring the validated chain.
The history cache loads it from the database on a miss.
| index | Ledger sequence wanted. |
Definition at line 1762 of file LedgerMaster.cpp.
| std::shared_ptr< Ledger const > xrpl::LedgerMaster::getLedgerByHash | ( | UInt256 const & | hash | ) |
| hash | Ledger hash wanted. |
Definition at line 1798 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::setLedgerRangePresent | ( | std::uint32_t | minV, |
| std::uint32_t | maxV ) |
Records a closed range of sequences as resident.
| minV | Lowest sequence now present. |
| maxV | Highest sequence now present. |
Definition at line 1811 of file LedgerMaster.cpp.
| std::optional< NetClock::time_point > xrpl::LedgerMaster::getCloseTimeBySeq | ( | LedgerIndex | ledgerIndex | ) |
| ledgerIndex | Ledger sequence wanted. |
Definition at line 1659 of file LedgerMaster.cpp.
| std::optional< NetClock::time_point > xrpl::LedgerMaster::getCloseTimeByHash | ( | LedgerHash const & | ledgerHash, |
| LedgerIndex | ledgerIndex ) |
Reads a close time straight out of the serialized header in the node store.
| ledgerHash | Hash of the ledger wanted. |
| ledgerIndex | Its sequence, used as the node-store lookup hint. |
Definition at line 1666 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::addHeldTransaction | ( | std::shared_ptr< Transaction > const & | trans | ) |
Defers a transaction to the next open ledger.
| trans | Transaction to hold. |
Definition at line 369 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::fixMismatch | ( | ReadView const & | ledger | ) |
Walks back from a ledger, dropping every resident ledger it cannot confirm against that ledger's skip list: a mismatch, one it cannot load, or one too far back to look up.
Stops at the first confirmed match or read error.
| ledger | Ledger whose chain is taken as correct. |
Definition at line 792 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::haveLedger | ( | std::uint32_t | seq | ) | const |
| seq | Ledger sequence to test. |
Definition at line 520 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::clearLedger | ( | std::uint32_t | seq | ) |
Marks a ledger no longer resident.
| seq | Ledger sequence to drop. |
Definition at line 527 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::isValidated | ( | ReadView const & | ledger | ) |
Tests whether a ledger is on the validated chain, using the skip list when the ledger does not already say so.
| ledger | Ledger to test; open ledgers are never validated. |
Definition at line 534 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::getValidatedRange | ( | std::uint32_t & | minVal, |
| std::uint32_t & | maxVal ) |
Returns Ledgers we have all the nodes for and are indexed: a contiguous part of getFullValidatedRange() with no ledger still being saved.
Pending saves at either end are trimmed first. Each remaining one then drops the part between it and the nearer end, so this is a best effort and not always the largest such part.
| minVal | Set to the lowest usable sequence, or 0 if none remains. Unchanged when the call returns false. |
| maxVal | Set to the highest usable sequence, or 0 if none remains or the call returns false. |
Definition at line 608 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::getFullValidatedRange | ( | std::uint32_t & | minVal, |
| std::uint32_t & | maxVal ) |
Returns Ledgers we have all the nodes for: the contiguous resident range ending at the published ledger.
The published ledger itself is assumed present, not checked.
| minVal | Set to the lowest sequence of that range. |
| maxVal | Set to the published sequence. |
Definition at line 579 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::sweep | ( | ) |
Expires stale entries from the ledger history and fetch-pack caches.
Definition at line 1818 of file LedgerMaster.cpp.
| float xrpl::LedgerMaster::getCacheHitRate | ( | ) |
Definition at line 1825 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::checkAccept | ( | std::shared_ptr< Ledger const > const & | ledger | ) |
If the ledger passes canBeCurrent(), is newer than the validated ledger and has a quorum, makes it the last fully validated ledger.
Then sets the remote fee to the median load fee of trusted full validations of this ledger and its parent (a missing load fee counts as the base fee; no validations give the base fee), and pokes the stream.
| ledger | Candidate ledger. |
Definition at line 974 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::checkAccept | ( | UInt256 const & | hash, |
| std::uint32_t | seq ) |
Check if the specified ledger can become the new last fully-validated ledger, fetching it if it is not resident.
| hash | Hash of the candidate ledger. |
| seq | Its sequence. Zero means the sequence is unknown, which skips the staleness checks. |
Definition at line 914 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::consensusBuilt | ( | std::shared_ptr< Ledger const > const & | ledger, |
| UInt256 const & | consensusHash, | ||
| json::Value | consensus ) |
Report that the consensus process built a particular ledger.
In standalone this only clears the building sequence. Otherwise it records the built ledger and tries to accept it. If that does not advance the validated ledger, it checks the highest newer ledger with more than a quorum of current trusted validations, which may not be this one.
| ledger | Ledger consensus just built. |
| consensusHash | Hash of the consensus transaction set. |
| consensus | Consensus metadata for this round, kept only so a built-versus-validated mismatch can be logged. |
Definition at line 1115 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::setBuildingLedger | ( | LedgerIndex | index | ) |
Records which ledger consensus is currently building, so validations for it are not chased separately.
| index | Sequence being built; 0 when none is. |
Definition at line 514 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::tryAdvance | ( | ) |
Signals that the ledger stream may be able to make progress.
Starts the advance job if it is not already running and a validated ledger exists; otherwise it only records the request. Cheap to call often.
Definition at line 1400 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::newPathRequest | ( | ) |
Notes a new pathfinding request and dispatches a worker if one is due.
Definition at line 1540 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::isNewPathRequest | ( | ) |
Definition at line 1548 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::newOrderBookDB | ( | ) |
If the order book is radically updated, we need to reprocess all pathfinding requests.
Definition at line 1559 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::fixIndex | ( | LedgerIndex | ledgerIndex, |
| LedgerHash const & | ledgerHash ) |
Corrects the cached sequence-to-hash mapping for one ledger.
| ledgerIndex | Sequence to correct. |
| ledgerHash | Hash that sequence really has. |
Definition at line 470 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::clearPriorLedgers | ( | LedgerIndex | seq | ) |
Forgets that we hold any ledger below a sequence, without touching the cached ledgers themselves.
| seq | First sequence to keep. |
Definition at line 1831 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::clearLedgerCachePrior | ( | LedgerIndex | seq | ) |
Drops cached ledgers below a sequence.
| seq | First sequence to keep. |
Definition at line 1839 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::takeReplay | ( | std::unique_ptr< LedgerReplay > | replay | ) |
Stores a transaction set to replay when the next ledger closes.
| replay | Set to replay; replaces any set already held. |
Definition at line 1845 of file LedgerMaster.cpp.
| std::unique_ptr< LedgerReplay > xrpl::LedgerMaster::releaseReplay | ( | ) |
Definition at line 1851 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::gotFetchPack | ( | bool | progress, |
| std::uint32_t | seq ) |
Signals that fetch-pack data arrived, so waiting acquires can use it.
At most one handler job is queued at a time.
| progress | Unused by the current implementation. |
| seq | Unused by the current implementation. |
Definition at line 2066 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::addFetchPack | ( | UInt256 const & | hash, |
| std::shared_ptr< Blob > | data ) |
Caches one fetch-pack node received from a peer.
| hash | Hash of the node, which is its key. |
| data | Serialized node. |
Definition at line 2047 of file LedgerMaster.cpp.
|
override |
Consumes one cached fetch-pack node.
| hash | Hash of the node wanted. |
Definition at line 2053 of file LedgerMaster.cpp.
| void xrpl::LedgerMaster::makeFetchPack | ( | std::weak_ptr< Peer > const & | wPeer, |
| std::shared_ptr< protocol::TMGetObjectByHash > const & | request, | ||
| UInt256 | haveLedgerHash, | ||
| UptimeClock::time_point | uptime ) |
Builds a fetch pack of the ledgers preceding the one a peer says it has, and sends it.
Silently declines when the node is too loaded, too far behind, or the request is over a second old.
| wPeer | Peer to reply to; nothing is sent if it has gone away. |
| request | Originating request, whose ledger hash is echoed back. |
| haveLedgerHash | Newest ledger the peer claims to have. Its parent is the first one packed. |
| uptime | Time the request was received, used as the deadline base. |
Definition at line 2135 of file LedgerMaster.cpp.
| std::size_t xrpl::LedgerMaster::getFetchPackCacheSize | ( | ) | const |
Definition at line 2256 of file LedgerMaster.cpp.
| bool xrpl::LedgerMaster::haveValidated | ( | ) |
Whether we have ever fully validated a ledger.
Definition at line 725 of file LedgerMaster.h.
| std::optional< LedgerIndex > xrpl::LedgerMaster::minSqlSeq | ( | ) |
Returns the minimum ledger sequence in SQL database, if any.
Definition at line 2263 of file LedgerMaster.cpp.
| std::optional< UInt256 > xrpl::LedgerMaster::txnIdFromIndex | ( | uint32_t | ledgerSeq, |
| uint32_t | txnIndex ) |
Iff a txn exists at the specified ledger and offset then return its txnid.
| ledgerSeq | Ledger to search. Not a precondition: a sequence above the validated range yields nullopt rather than an error. |
| txnIndex | Position of the transaction within that ledger. |
Definition at line 2269 of file LedgerMaster.cpp.
|
private |
Adopts a ledger as the last validated one and tells the rest of the server, including the amendment-support checks that can block the node.
| l | Ledger to adopt. Its recorded sign time is the median of the trusted validations, or its own close time when there are too few. |
Definition at line 279 of file LedgerMaster.cpp.
|
private |
Records how far publication has reached.
The first ledger recorded is a starting point and is not sent to clients.
| l | Ledger just published. |
Definition at line 361 of file LedgerMaster.cpp.
|
private |
Walks back from a ledger through the SQL index, marking each ancestor resident until the chain breaks or a known ledger is reached.
Runs as a job, and clears fillInProgress_ when it finishes, unless the server is stopping.
| ledger | Ledger to walk back from. |
Definition at line 671 of file LedgerMaster.cpp.
|
private |
Request a fetch pack to get to the specified ledger.
| missing | Sequence we lack; the request is keyed on its successor. |
| reason | Why the ledger is needed, for any hash walk this triggers. |
Definition at line 743 of file LedgerMaster.cpp.
|
private |
Finds the hash of a ledger the history back-fill wants, preferring the last back-filled ledger as the reference to walk from.
| index | Ledger sequence wanted. |
| reason | Why the ledger is needed, for any acquire this triggers. |
Definition at line 1239 of file LedgerMaster.cpp.
|
private |
Determines how many validations are needed to fully validate a ledger.
Definition at line 968 of file LedgerMaster.cpp.
|
private |
Starts acquiring one missing historical ledger.
If it is not local yet, also asks a peer for a fetch pack and prefetches up to ledgerFetchSize_ ledgers from missing downward.
| missing | Sequence to acquire. |
| progress | Set to true when the ledger was stored, or when no hash was found; in that case missing + 1 is dropped from the resident set. true makes the caller run another pass at once. |
| reason | Why the ledger is needed, passed to the acquire. |
| sl | Lock on mutex_, released for the whole call. |
Definition at line 1857 of file LedgerMaster.cpp.
|
private |
Try to publish ledgers, acquire missing ledgers.
Always called with mutex_ locked. The passed lock is a reminder to callers.
Publishing takes priority; history is only back-filled when the node is caught up, unloaded and idle. Loops while it makes progress or tryAdvance() posts new work.
| sl | Lock on mutex_, released around publication and network work. |
Definition at line 1958 of file LedgerMaster.cpp.
|
private |
Collects the next run of validated ledgers to publish, acquiring or replaying the ones that are missing.
| sl | Lock on mutex_, released while ledgers are fetched. |
Definition at line 1259 of file LedgerMaster.cpp.
|
private |
Runs one pathfinding pass per new validated ledger or new request, and exits when neither is new, even if requests are still pending.
Runs as a job, and decrements pathFindThread_ on each of its early returns, but not when a job-queue shutdown ends the loop, which leaves the count high for the rest of the process.
Definition at line 1434 of file LedgerMaster.cpp.
|
private |
A thread needs to be dispatched to handle pathfinding work of some kind.
Always called with mutex_ locked. The passed lock is a reminder to callers.
| name | Job name, for the perf log. |
Definition at line 1571 of file LedgerMaster.cpp.
|
private |
Samples both ledger ages into the gauges.
Called on the collector's thread.
Definition at line 1107 of file LedgerMaster.h.
|
private |
Owning application, the route to every other subsystem.
Definition at line 879 of file LedgerMaster.h.
|
private |
Log sink for this component.
Definition at line 884 of file LedgerMaster.h.
|
mutableprivate |
Guards pubLedger_, pathLedger_, lastValidLedger_, the held transactions and the job flags other than the atomic gotFetchPackThread_.
closedLedger_ and validLedger_ lock themselves for reads and are changed only under this lock. histLedger_ and fetchSeq_ belong to the advance job, which runs one at a time. Recursive because holders re-enter it: checkAccept() and tryFill() call tryAdvance() while holding it. Taken before completeLock_.
Definition at line 895 of file LedgerMaster.h.
|
private |
The ledger that most recently closed.
Definition at line 900 of file LedgerMaster.h.
|
private |
The highest-sequence ledger we have fully accepted.
Definition at line 905 of file LedgerMaster.h.
|
private |
The last ledger we have published.
Definition at line 910 of file LedgerMaster.h.
|
private |
The last ledger we did pathfinding against.
Definition at line 915 of file LedgerMaster.h.
|
private |
The last ledger we handled fetching history.
Definition at line 920 of file LedgerMaster.h.
|
private |
Fully validated ledger, whether or not we have the ledger resident.
Definition at line 925 of file LedgerMaster.h.
|
private |
Cache of ledgers by hash and of validated sequence-to-hash mappings.
Definition at line 930 of file LedgerMaster.h.
|
private |
Transactions deferred to the next open ledger, in canonical order.
One can leave earlier, when the account's previous transaction applies.
Definition at line 936 of file LedgerMaster.h.
|
private |
A set of transactions to replay during the next close.
Definition at line 941 of file LedgerMaster.h.
|
mutableprivate |
Guards completeLedgers_ only.
Usually taken alone; when both are held, mutex_ is taken first.
Definition at line 947 of file LedgerMaster.h.
|
private |
Sequences of the ledgers this node believes it holds in full.
An entry is dropped when a lookup finds the ledger missing.
Definition at line 953 of file LedgerMaster.h.
|
private |
An AdvanceLedger job is queued or running.
Definition at line 958 of file LedgerMaster.h.
|
private |
Publish thread has work to do.
Definition at line 963 of file LedgerMaster.h.
|
private |
Sequence a tryFill() job is currently walking back from, or 0 when no fill is running.
Keeps back-fill from competing with itself.
Definition at line 969 of file LedgerMaster.h.
|
private |
Pathfinding jobs queued or running.
Never allowed above two, so pathfinding cannot starve other jobs.
Definition at line 975 of file LedgerMaster.h.
|
private |
A pathfinding request arrived and has not been picked up yet.
Definition at line 980 of file LedgerMaster.h.
|
private |
Set while a GotFetchPack job is outstanding, so only one ever is.
Definition at line 985 of file LedgerMaster.h.
|
private |
Close time of pubLedger_, in seconds since the network epoch; 0 if none.
Definition at line 990 of file LedgerMaster.h.
|
private |
Sequence of pubLedger_; 0 if nothing has been published.
Definition at line 995 of file LedgerMaster.h.
|
private |
Sign time of validLedger_, in seconds since the network epoch: the median of its trusted validations, or its close time when those were too few.
Definition at line 1001 of file LedgerMaster.h.
|
private |
Sequence of validLedger_; 0 if nothing is validated.
Definition at line 1006 of file LedgerMaster.h.
|
private |
Sequence consensus is building; 0 once it is built.
Can stay set if a round ends without building it.
Definition at line 1012 of file LedgerMaster.h.
|
private |
The server is in standalone mode.
Definition at line 1017 of file LedgerMaster.h.
|
private |
How many ledgers before the closed ledger do we allow peers to request?
Definition at line 1022 of file LedgerMaster.h.
|
private |
How much history do we want to keep.
Definition at line 1027 of file LedgerMaster.h.
|
private |
Cap on ledgers acquired in one publication or prefetch pass.
Definition at line 1032 of file LedgerMaster.h.
|
private |
Fetch-pack nodes keyed by node hash.
A node is removed once read; unread nodes expire about 45 seconds after arrival, sooner when over 65536 are held.
Definition at line 1039 of file LedgerMaster.h.
|
private |
Sequence of the last fetch-pack attempt, so the same one is not tried twice in a row.
Definition at line 1045 of file LedgerMaster.h.
|
private |
Try to keep a validator from switching from test to live network without first wiping the database.
Definition at line 1051 of file LedgerMaster.h.
|
private |
Time that the previous upgrade warning was issued.
Definition at line 1056 of file LedgerMaster.h.
|
private |
The gauges and the collector hook that samples them.
Definition at line 1099 of file LedgerMaster.h.