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

Classes | |
| struct | KeepRange | 
Public Member Functions | |
| template<class... Ts> | |
| Validations (ValidationParms const &p, beast::abstract_clock< 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 &j) | 
| Expire old validation sets.   | |
| void | trustChanged (hash_set< NodeID > const &added, hash_set< 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, hash_map< 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 () -> hash_set< 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, hash_set< 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 = typename Adaptor::Mutex | 
| using | Validation = typename Adaptor::Validation | 
| using | Ledger = typename Adaptor::Ledger | 
| using | ID = typename Ledger::ID | 
| using | Seq = typename Ledger::Seq | 
| using | NodeID = typename Validation::NodeID | 
| using | NodeKey = typename Validation::NodeKey | 
| using | WrappedValidationType = std::decay_t< std::invoke_result_t< decltype(&Validation::unwrap), Validation > > | 
Private Member Functions | |
| void | removeTrie (std::lock_guard< Mutex > const &, NodeID const &nodeID, Validation const &val) | 
| void | checkAcquired (std::lock_guard< Mutex > const &lock) | 
| void | updateTrie (std::lock_guard< Mutex > const &, NodeID const &nodeID, Ledger ledger) | 
| void | updateTrie (std::lock_guard< 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::lock_guard< Mutex > const &lock, F &&f) | 
| Use the trie for a calculation.   | |
| template<class Pre , class F > | |
| void | current (std::lock_guard< Mutex > const &lock, Pre &&pre, F &&f) | 
| Iterate current validations.   | |
| template<class Pre , class F > | |
| void | byLedger (std::lock_guard< Mutex > const &, ID const &ledgerID, Pre &&pre, F &&f) | 
| Iterate the set of validations associated with a given ledger id.   | |
Private Attributes | |
| Mutex | mutex_ | 
| hash_map< NodeID, Validation > | current_ | 
| SeqEnforcer< Seq > | localSeqEnforcer_ | 
| hash_map< NodeID, SeqEnforcer< Seq > > | seqEnforcers_ | 
| beast::aged_unordered_map< ID, hash_map< NodeID, Validation >, std::chrono::steady_clock, beast::uhash<> > | byLedger_ | 
| Validations from listed nodes, indexed by ledger id (partial and full)   | |
| beast::aged_unordered_map< Seq, hash_map< NodeID, Validation >, std::chrono::steady_clock, beast::uhash<> > | bySequence_ | 
| std::optional< KeepRange > | toKeep_ | 
| LedgerTrie< Ledger > | trie_ | 
| hash_map< NodeID, Ledger > | lastLedger_ | 
| hash_map< std::pair< Seq, ID >, hash_set< 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 289 of file Validations.h.
      
  | 
  private | 
Definition at line 291 of file Validations.h.
      
  | 
  private | 
Definition at line 292 of file Validations.h.
      
  | 
  private | 
Definition at line 293 of file Validations.h.
      
  | 
  private | 
Definition at line 294 of file Validations.h.
      
  | 
  private | 
Definition at line 295 of file Validations.h.
      
  | 
  private | 
Definition at line 296 of file Validations.h.
      
  | 
  private | 
Definition at line 297 of file Validations.h.
      
  | 
  private | 
Definition at line 299 of file Validations.h.
| ripple::Validations< Adaptor >::Validations | ( | ValidationParms const & | p, | 
| beast::abstract_clock< 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 574 of file Validations.h.
      
  | 
  private | 
Definition at line 358 of file Validations.h.
      
  | 
  private | 
Definition at line 385 of file Validations.h.
      
  | 
  private | 
Definition at line 404 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 432 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 | Invokable with signature (LedgerTrie<Ledger> &) | 
f is expected to be a simple transformation of its arguments and will be called with mutex_ under lock. Definition at line 485 of file Validations.h.
      
  | 
  private | 
Iterate current validations.
Iterate current validations, flushing any which are stale.
| lock | Existing lock of mutex_ | 
| pre | Invokable with signature (std::size_t) called prior to looping. | 
| f | Invokable with signature (NodeID const &, Validations const &) for each current validation. | 
pre is called prior to checking for staleness and reflects an upper-bound on the number of calls to f. @warning The invokablef` is expected to be a simple transformation of its arguments and will be called with mutex_ under lock. Definition at line 511 of file Validations.h.
      
  | 
  private | 
Iterate the set of validations associated with a given ledger id.
| lock | Existing lock on mutex_ | 
| ledgerID | The identifier of the ledger | 
| pre | Invokable with signature(std::size_t) | 
| f | Invokable with signature (NodeID const &, Validation const &) | 
pre is called prior to iterating validations. The argument is the number of times f will be called. Definition at line 549 of file Validations.h.
| Adaptor const & ripple::Validations< Adaptor >::adaptor | ( | ) | const | 
Return the adaptor instance.
Definition at line 588 of file Validations.h.
| ValidationParms const & ripple::Validations< Adaptor >::parms | ( | ) | const | 
Return the validation timing parameters.
Definition at line 596 of file Validations.h.
| bool ripple::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 609 of file Validations.h.
| ValStatus ripple::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 624 of file Validations.h.
| void ripple::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 716 of file Validations.h.
| void ripple::Validations< Adaptor >::expire | ( | beast::Journal & | 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 730 of file Validations.h.
| void ripple::Validations< Adaptor >::trustChanged | ( | hash_set< NodeID > const & | added, | 
| hash_set< 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 795 of file Validations.h.
| Json::Value ripple::Validations< Adaptor >::getJsonTrie | ( | ) | const | 
Definition at line 831 of file Validations.h.
| std::optional< std::pair< Seq, ID > > ripple::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 ripple::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 911 of file Validations.h.
| ID ripple::Validations< Adaptor >::getPreferredLCL | ( | Ledger const & | lcl, | 
| Seq | minSeq, | ||
| hash_map< 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 936 of file Validations.h.
| std::size_t ripple::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 974 of file Validations.h.
| std::vector< WrappedValidationType > ripple::Validations< Adaptor >::currentTrusted | ( | ) | 
Get the currently trusted full validations.
Definition at line 1000 of file Validations.h.
| auto ripple::Validations< Adaptor >::getCurrentNodeIDs | ( | ) | -> hash_set<NodeID> | 
Get the set of node ids associated with current validations.
Definition at line 1019 of file Validations.h.
| std::size_t ripple::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 1037 of file Validations.h.
| std::vector< WrappedValidationType > ripple::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 1059 of file Validations.h.
| std::vector< std::uint32_t > ripple::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 1082 of file Validations.h.
| void ripple::Validations< Adaptor >::flush | ( | ) | 
Flush all current validations.
Definition at line 1106 of file Validations.h.
| std::size_t ripple::Validations< Adaptor >::laggards | ( | Seq const | seq, | 
| hash_set< 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 1128 of file Validations.h.
| std::size_t ripple::Validations< Adaptor >::sizeOfCurrentCache | ( | ) | const | 
Definition at line 1150 of file Validations.h.
| std::size_t ripple::Validations< Adaptor >::sizeOfSeqEnforcersCache | ( | ) | const | 
Definition at line 1157 of file Validations.h.
| std::size_t ripple::Validations< Adaptor >::sizeOfByLedgerCache | ( | ) | const | 
Definition at line 1164 of file Validations.h.
| std::size_t ripple::Validations< Adaptor >::sizeOfBySequenceCache | ( | ) | const | 
Definition at line 1171 of file Validations.h.
      
  | 
  mutableprivate | 
Definition at line 303 of file Validations.h.
      
  | 
  private | 
Definition at line 306 of file Validations.h.
      
  | 
  private | 
Definition at line 309 of file Validations.h.
      
  | 
  private | 
Definition at line 312 of file Validations.h.
      
  | 
  private | 
Validations from listed nodes, indexed by ledger id (partial and full)
Definition at line 320 of file Validations.h.
      
  | 
  private | 
Definition at line 328 of file Validations.h.
      
  | 
  private | 
Definition at line 336 of file Validations.h.
      
  | 
  private | 
Definition at line 339 of file Validations.h.
      
  | 
  private | 
Definition at line 343 of file Validations.h.
      
  | 
  private | 
Definition at line 346 of file Validations.h.
      
  | 
  private | 
Definition at line 349 of file Validations.h.
      
  | 
  private | 
Definition at line 353 of file Validations.h.