|
xrpld
|
Maintains current and recent ledger validations. More...
#include <Validations.h>

Classes | |
| struct | KeepRange |
Public Member Functions | |
| template<class... Ts> | |
| Validations (ValidationParms const &p, beast::AbstractClock< std::chrono::steady_clock > &c, Ts &&... ts) | |
| Constructor. | |
| Adaptor const & | adaptor () const |
| Return the adaptor instance. | |
| ValidationParms const & | parms () const |
| Return the validation timing parameters. | |
| bool | canValidateSeq (Seq const s) |
| Return whether the local node can issue a validation for the given sequence number. | |
| ValStatus | add (NodeID const &nodeID, Validation const &val) |
| Add a new validation. | |
| void | setSeqToKeep (Seq const &low, Seq const &high) |
| Set the range [low, high) of validations to keep from expire. | |
| void | expire (beast::Journal const &j) |
| Expire old validation sets. | |
| void | trustChanged (HashSet< NodeID > const &added, HashSet< NodeID > const &removed) |
| Update trust status of validations. | |
| json::Value | getJsonTrie () const |
| std::optional< std::pair< Seq, ID > > | getPreferred (Ledger const &curr) |
| Return the sequence number and ID of the preferred working ledger. | |
| ID | getPreferred (Ledger const &curr, Seq minValidSeq) |
| Get the ID of the preferred working ledger that exceeds a minimum valid ledger sequence number. | |
| ID | getPreferredLCL (Ledger const &lcl, Seq minSeq, HashMap< ID, std::uint32_t > const &peerCounts) |
| Determine the preferred last closed ledger for the next consensus round. | |
| std::size_t | getNodesAfter (Ledger const &ledger, ID const &ledgerID) |
| Count the number of current trusted validators working on a ledger after the specified one. | |
| std::vector< WrappedValidationType > | currentTrusted () |
| Get the currently trusted full validations. | |
| auto | getCurrentNodeIDs () -> HashSet< NodeID > |
| Get the set of node ids associated with current validations. | |
| std::size_t | numTrustedForLedger (ID const &ledgerID) |
| Count the number of trusted full validations for the given ledger. | |
| std::vector< WrappedValidationType > | getTrustedForLedger (ID const &ledgerID, Seq const &seq) |
| Get trusted full validations for a specific ledger. | |
| std::vector< std::uint32_t > | fees (ID const &ledgerID, std::uint32_t baseFee) |
| Returns fees reported by trusted full validators in the given ledger. | |
| void | flush () |
| Flush all current validations. | |
| std::size_t | laggards (Seq const seq, HashSet< NodeKey > &trustedKeys) |
| Return quantity of lagging proposers, and remove online proposers for purposes of evaluating whether to pause. | |
| std::size_t | sizeOfCurrentCache () const |
| std::size_t | sizeOfSeqEnforcersCache () const |
| std::size_t | sizeOfByLedgerCache () const |
| std::size_t | sizeOfBySequenceCache () const |
Private Types | |
| using | Mutex = Adaptor::Mutex |
| using | Validation = Adaptor::Validation |
| using | Ledger = Adaptor::Ledger |
| using | ID = Ledger::ID |
| using | Seq = Ledger::Seq |
| using | NodeID = Validation::NodeID |
| using | NodeKey = Validation::NodeKey |
| using | WrappedValidationType |
Private Member Functions | |
| void | removeTrie (std::scoped_lock< Mutex > const &, NodeID const &nodeID, Validation const &val) |
| void | checkAcquired (std::scoped_lock< Mutex > const &lock) |
| void | updateTrie (std::scoped_lock< Mutex > const &, NodeID const &nodeID, Ledger ledger) |
| void | updateTrie (std::scoped_lock< Mutex > const &lock, NodeID const &nodeID, Validation const &val, std::optional< std::pair< Seq, ID > > prior) |
| Process a new validation. | |
| template<class F> | |
| auto | withTrie (std::scoped_lock< Mutex > const &lock, F &&f) |
| Use the trie for a calculation. | |
| template<class Pre, class F> | |
| void | byLedger (std::scoped_lock< Mutex > const &, ID const &ledgerID, Pre &&pre, F &&f) |
| Iterate current validations. | |
Private Attributes | |
| Mutex | mutex_ |
| HashMap< NodeID, Validation > | current_ |
| SeqEnforcer< Seq > | localSeqEnforcer_ |
| HashMap< NodeID, SeqEnforcer< Seq > > | seqEnforcers_ |
| beast::AgedUnorderedMap< ID, HashMap< NodeID, Validation >, std::chrono::steady_clock, beast::Uhash<> > | byLedger_ |
| Validations from listed nodes, indexed by ledger id (partial and full). | |
| beast::AgedUnorderedMap< Seq, HashMap< NodeID, Validation >, std::chrono::steady_clock, beast::Uhash<> > | bySequence_ |
| std::optional< KeepRange > | toKeep_ |
| LedgerTrie< Ledger > | trie_ |
| HashMap< NodeID, Ledger > | lastLedger_ |
| HashMap< std::pair< Seq, ID >, HashSet< NodeID > > | acquiring_ |
| ValidationParms const | parms_ |
| Adaptor | adaptor_ |
Maintains current and recent ledger validations.
Manages storage and queries related to validations received on the network. Stores the most current validation from nodes and sets of recent validations grouped by ledger identifier.
Stored validations are not necessarily from trusted nodes, so clients and implementations should take care to use trusted member functions or check the validation's trusted status.
This class uses a generic interface to allow adapting Validations for specific applications. The Adaptor template implements a set of helper functions and type definitions. The code stubs below outline the interface and type requirements.
| Adaptor | Provides type definitions and callbacks |
Definition at line 298 of file Validations.h.
|
private |
Definition at line 300 of file Validations.h.
|
private |
Definition at line 301 of file Validations.h.
|
private |
Definition at line 302 of file Validations.h.
|
private |
Definition at line 303 of file Validations.h.
|
private |
Definition at line 304 of file Validations.h.
|
private |
Definition at line 305 of file Validations.h.
|
private |
Definition at line 306 of file Validations.h.
|
private |
Definition at line 308 of file Validations.h.
| xrpl::Validations< Adaptor >::Validations | ( | ValidationParms const & | p, |
| beast::AbstractClock< std::chrono::steady_clock > & | c, | ||
| Ts &&... | ts ) |
Constructor.
| p | ValidationParms to control staleness/expiration of validations |
| c | Clock to use for expiring validations stored by ledger |
| ts | Parameters for constructing Adaptor instance |
Definition at line 577 of file Validations.h.
|
private |
Definition at line 366 of file Validations.h.
|
private |
Definition at line 389 of file Validations.h.
|
private |
Definition at line 409 of file Validations.h.
|
private |
Process a new validation.
Process a new trusted validation from a validator. This will be reflected only after the validated ledger is successfully acquired by the local node. In the interim, the prior validated ledger from this node remains.
| lock | Existing lock of mutex_ |
| nodeID | The node identifier of the validating node |
| val | The trusted validation issued by the node |
| prior | If not none, the last current validated ledger Seq,ID of key |
Definition at line 435 of file Validations.h.
|
private |
Use the trie for a calculation.
Accessing the trie through this helper ensures acquiring validations are checked and any stale validations are flushed from the trie.
| lock | Existing lock of mutex_ |
| f | Invocable with signature (LedgerTrie<Ledger> &) |
Definition at line 490 of file Validations.h.
|
private |
Iterate current validations.
Iterate current validations, flushing any which are stale.
| lock | Existing lock of mutex_ |
| pre | Invocable with signature (std::size_t) called prior to looping. |
| f | Invocable with signature (NodeID const &, Validations const &) for each current validation. |
template <class Pre, class F> void current(std::scoped_lock<Mutex> const& lock, Pre&& pre, F&& f) { NetClock::time_point const t = adaptor_.now(); pre(current_.size()); auto it = current_.begin(); while (it != current_.end()) { Check for staleness if (!isCurrent(parms_, t, it->second.signTime(), it->second.seenTime())) { removeTrie(lock, it->first, it->second); it = current_.erase(it); } else { auto cit = typename decltype(current_)::const_iterator{it}; contains a live record f(cit->first, cit->second); ++it; } } }
/** Iterate the set of validations associated with a given ledger id
| lock | Existing lock on mutex_ |
| ledgerID | The identifier of the ledger |
| pre | Invocable with signature(std::size_t) |
| f | Invocable with signature (NodeID const &, Validation const &) |
Definition at line 555 of file Validations.h.
| Adaptor const & xrpl::Validations< Adaptor >::adaptor | ( | ) | const |
Return the adaptor instance.
Definition at line 589 of file Validations.h.
| ValidationParms const & xrpl::Validations< Adaptor >::parms | ( | ) | const |
Return the validation timing parameters.
Definition at line 598 of file Validations.h.
| bool xrpl::Validations< Adaptor >::canValidateSeq | ( | Seq const | s | ) |
Return whether the local node can issue a validation for the given sequence number.
| s | The sequence number of the ledger the node wants to validate |
Definition at line 612 of file Validations.h.
| ValStatus xrpl::Validations< Adaptor >::add | ( | NodeID const & | nodeID, |
| Validation const & | val ) |
Add a new validation.
Attempt to add a new validation.
| nodeID | The identity of the node issuing this validation |
| val | The validation to store |
Definition at line 628 of file Validations.h.
| void xrpl::Validations< Adaptor >::setSeqToKeep | ( | Seq const & | low, |
| Seq const & | high ) |
Set the range [low, high) of validations to keep from expire.
| low | the lower sequence number |
| high | the higher sequence number |
Definition at line 720 of file Validations.h.
| void xrpl::Validations< Adaptor >::expire | ( | beast::Journal const & | j | ) |
Expire old validation sets.
Remove validation sets that were accessed more than validationSET_EXPIRES ago and were not asked to keep.
Definition at line 734 of file Validations.h.
| void xrpl::Validations< Adaptor >::trustChanged | ( | HashSet< NodeID > const & | added, |
| HashSet< NodeID > const & | removed ) |
Update trust status of validations.
Updates the trusted status of known validations to account for nodes that have been added or removed from the UNL. This also updates the trie to ensure only currently trusted nodes' validations are used.
| added | Identifiers of nodes that are now trusted |
| removed | Identifiers of nodes that are no longer trusted |
Definition at line 794 of file Validations.h.
| json::Value xrpl::Validations< Adaptor >::getJsonTrie | ( | ) | const |
Definition at line 830 of file Validations.h.
| std::optional< std::pair< Seq, ID > > xrpl::Validations< Adaptor >::getPreferred | ( | Ledger const & | curr | ) |
Return the sequence number and ID of the preferred working ledger.
A ledger is preferred if it has more support amongst trusted validators and is not an ancestor of the current working ledger; otherwise it remains the current working ledger.
| curr | The local node's current working ledger |
Definition at line 850 of file Validations.h.
| ID xrpl::Validations< Adaptor >::getPreferred | ( | Ledger const & | curr, |
| Seq | minValidSeq ) |
Get the ID of the preferred working ledger that exceeds a minimum valid ledger sequence number.
| curr | Current working ledger |
| minValidSeq | Minimum allowed sequence number |
Definition at line 904 of file Validations.h.
| ID xrpl::Validations< Adaptor >::getPreferredLCL | ( | Ledger const & | lcl, |
| Seq | minSeq, | ||
| HashMap< ID, std::uint32_t > const & | peerCounts ) |
Determine the preferred last closed ledger for the next consensus round.
Called before starting the next round of ledger consensus to determine the preferred working ledger. Uses the dominant peerCount ledger if no trusted validations are available.
| lcl | Last closed ledger by this node |
| minSeq | Minimum allowed sequence number of the trusted preferred ledger |
| peerCounts | Map from ledger ids to count of peers with that as the last closed ledger |
Definition at line 930 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::getNodesAfter | ( | Ledger const & | ledger, |
| ID const & | ledgerID ) |
Count the number of current trusted validators working on a ledger after the specified one.
| ledger | The working ledger |
| ledgerID | The preferred ledger |
Definition at line 964 of file Validations.h.
| std::vector< WrappedValidationType > xrpl::Validations< Adaptor >::currentTrusted | ( | ) |
Get the currently trusted full validations.
Definition at line 989 of file Validations.h.
| auto xrpl::Validations< Adaptor >::getCurrentNodeIDs | ( | ) | -> HashSet< NodeID > |
Get the set of node ids associated with current validations.
Definition at line 1009 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::numTrustedForLedger | ( | ID const & | ledgerID | ) |
Count the number of trusted full validations for the given ledger.
| ledgerID | The identifier of ledger of interest |
Definition at line 1028 of file Validations.h.
| std::vector< WrappedValidationType > xrpl::Validations< Adaptor >::getTrustedForLedger | ( | ID const & | ledgerID, |
| Seq const & | seq ) |
Get trusted full validations for a specific ledger.
| ledgerID | The identifier of ledger of interest |
| seq | The sequence number of ledger of interest |
Definition at line 1051 of file Validations.h.
| std::vector< std::uint32_t > xrpl::Validations< Adaptor >::fees | ( | ID const & | ledgerID, |
| std::uint32_t | baseFee ) |
Returns fees reported by trusted full validators in the given ledger.
| ledgerID | The identifier of ledger of interest |
| baseFee | The fee to report if not present in the validation |
Definition at line 1075 of file Validations.h.
| void xrpl::Validations< Adaptor >::flush | ( | ) |
Flush all current validations.
Definition at line 1104 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::laggards | ( | Seq const | seq, |
| HashSet< NodeKey > & | trustedKeys ) |
Return quantity of lagging proposers, and remove online proposers for purposes of evaluating whether to pause.
Laggards are the trusted proposers whose sequence number is lower than the sequence number from which our current pending proposal is based. Proposers from whom we have not received a validation for awhile are considered offline.
Note: the trusted flag is not used in this evaluation because it's made redundant by checking the list of proposers.
| seq | Our current sequence number. |
| trustedKeys | Public keys of trusted proposers. |
Definition at line 1127 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::sizeOfCurrentCache | ( | ) | const |
Definition at line 1148 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::sizeOfSeqEnforcersCache | ( | ) | const |
Definition at line 1155 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::sizeOfByLedgerCache | ( | ) | const |
Definition at line 1162 of file Validations.h.
| std::size_t xrpl::Validations< Adaptor >::sizeOfBySequenceCache | ( | ) | const |
Definition at line 1169 of file Validations.h.
|
mutableprivate |
Definition at line 312 of file Validations.h.
|
private |
Definition at line 315 of file Validations.h.
|
private |
Definition at line 318 of file Validations.h.
|
private |
Definition at line 321 of file Validations.h.
|
private |
Validations from listed nodes, indexed by ledger id (partial and full).
Definition at line 328 of file Validations.h.
|
private |
Definition at line 336 of file Validations.h.
|
private |
Definition at line 344 of file Validations.h.
|
private |
Definition at line 347 of file Validations.h.
|
private |
Definition at line 351 of file Validations.h.
|
private |
Definition at line 354 of file Validations.h.
|
private |
Definition at line 357 of file Validations.h.
|
private |
Definition at line 361 of file Validations.h.