rippled
Validations.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2017 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_CONSENSUS_VALIDATIONS_H_INCLUDED
21 #define RIPPLE_CONSENSUS_VALIDATIONS_H_INCLUDED
22 
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/UnorderedContainers.h>
25 #include <ripple/basics/chrono.h>
26 #include <ripple/beast/container/aged_container_utility.h>
27 #include <ripple/beast/container/aged_unordered_map.h>
28 #include <ripple/consensus/LedgerTrie.h>
29 #include <ripple/protocol/PublicKey.h>
30 #include <boost/optional.hpp>
31 #include <mutex>
32 #include <utility>
33 #include <vector>
34 
35 namespace ripple {
36 
44 {
45  explicit ValidationParms() = default;
46 
54 
62 
69 
77 
87 };
88 
95 template <class Seq>
97 {
98  using time_point = std::chrono::steady_clock::time_point;
99  Seq seq_{0};
101 
102 public:
115  bool
116  operator()(time_point now, Seq s, ValidationParms const& p)
117  {
118  if (now > (when_ + p.validationSET_EXPIRES))
119  seq_ = Seq{0};
120  if (s <= seq_)
121  return false;
122  seq_ = s;
123  when_ = now;
124  return true;
125  }
126 
127  Seq
128  largest() const
129  {
130  return seq_;
131  }
132 };
144 inline bool
146  ValidationParms const& p,
148  NetClock::time_point signTime,
149  NetClock::time_point seenTime)
150 {
151  // Because this can be called on untrusted, possibly
152  // malicious validations, we do our math in a way
153  // that avoids any chance of overflowing or underflowing
154  // the signing time.
155 
156  return (signTime > (now - p.validationCURRENT_EARLY)) &&
157  (signTime < (now + p.validationCURRENT_WALL)) &&
158  ((seenTime == NetClock::time_point{}) ||
159  (seenTime < (now + p.validationCURRENT_LOCAL)));
160 }
161 
164 enum class ValStatus {
166  current,
168  stale,
170  badSeq
171 };
172 
173 inline std::string
175 {
176  switch (m)
177  {
178  case ValStatus::current:
179  return "current";
180  case ValStatus::stale:
181  return "stale";
182  case ValStatus::badSeq:
183  return "badSeq";
184  default:
185  return "unknown";
186  }
187 }
188 
275 template <class Adaptor>
276 class Validations
277 {
278  using Mutex = typename Adaptor::Mutex;
279  using Validation = typename Adaptor::Validation;
280  using Ledger = typename Adaptor::Ledger;
281  using ID = typename Ledger::ID;
282  using Seq = typename Ledger::Seq;
283  using NodeID = typename Validation::NodeID;
284  using NodeKey = typename Validation::NodeKey;
285 
287  std::result_of_t<decltype (&Validation::unwrap)(Validation)>>;
288 
289  // Manages concurrent access to members
290  mutable Mutex mutex_;
291 
292  // Validations from currently listed and trusted nodes (partial and full)
294 
295  // Used to enforce the largest validation invariant for the local node
297 
298  // Sequence of the largest validation received from each node
300 
303  ID,
308 
309  // Represents the ancestry of validated ledgers
311 
312  // Last (validated) ledger successfully acquired. If in this map, it is
313  // accounted for in the trie.
315 
316  // Set of ledgers being acquired from the network
318 
319  // Parameters to determine validation staleness
321 
322  // Adaptor instance
323  // Is NOT managed by the mutex_ above
324  Adaptor adaptor_;
325 
326 private:
327  // Remove support of a validated ledger
328  void
329  removeTrie(std::lock_guard<Mutex> const&, NodeID const& nodeID, Validation const& val)
330  {
331  {
332  auto it =
333  acquiring_.find(std::make_pair(val.seq(), val.ledgerID()));
334  if (it != acquiring_.end())
335  {
336  it->second.erase(nodeID);
337  if (it->second.empty())
338  acquiring_.erase(it);
339  }
340  }
341  {
342  auto it = lastLedger_.find(nodeID);
343  if (it != lastLedger_.end() && it->second.id() == val.ledgerID())
344  {
345  trie_.remove(it->second);
346  lastLedger_.erase(nodeID);
347  }
348  }
349  }
350 
351  // Check if any pending acquire ledger requests are complete
352  void
354  {
355  for (auto it = acquiring_.begin(); it != acquiring_.end();)
356  {
357  if (boost::optional<Ledger> ledger =
358  adaptor_.acquire(it->first.second))
359  {
360  for (NodeID const& nodeID : it->second)
361  updateTrie(lock, nodeID, *ledger);
362 
363  it = acquiring_.erase(it);
364  }
365  else
366  ++it;
367  }
368  }
369 
370  // Update the trie to reflect a new validated ledger
371  void
372  updateTrie(std::lock_guard<Mutex> const&, NodeID const& nodeID, Ledger ledger)
373  {
374  auto const [it, inserted] = lastLedger_.emplace(nodeID, ledger);
375  if (!inserted)
376  {
377  trie_.remove(it->second);
378  it->second = ledger;
379  }
380  trie_.insert(ledger);
381  }
382 
396  void
398  std::lock_guard<Mutex> const& lock,
399  NodeID const& nodeID,
400  Validation const& val,
401  boost::optional<std::pair<Seq, ID>> prior)
402  {
403  assert(val.trusted());
404 
405  // Clear any prior acquiring ledger for this node
406  if (prior)
407  {
408  auto it = acquiring_.find(*prior);
409  if (it != acquiring_.end())
410  {
411  it->second.erase(nodeID);
412  if (it->second.empty())
413  acquiring_.erase(it);
414  }
415  }
416 
417  checkAcquired(lock);
418 
419  std::pair<Seq, ID> valPair{val.seq(), val.ledgerID()};
420  auto it = acquiring_.find(valPair);
421  if (it != acquiring_.end())
422  {
423  it->second.insert(nodeID);
424  }
425  else
426  {
427  if (boost::optional<Ledger> ledger =
428  adaptor_.acquire(val.ledgerID()))
429  updateTrie(lock, nodeID, *ledger);
430  else
431  acquiring_[valPair].insert(nodeID);
432  }
433  }
434 
447  template <class F>
448  auto
449  withTrie(std::lock_guard<Mutex> const& lock, F&& f)
450  {
451  // Call current to flush any stale validations
452  current(lock, [](auto) {}, [](auto, auto) {});
453  checkAcquired(lock);
454  return f(trie_);
455  }
456 
473  template <class Pre, class F>
474  void
475  current(std::lock_guard<Mutex> const& lock, Pre&& pre, F&& f)
476  {
477  NetClock::time_point t = adaptor_.now();
478  pre(current_.size());
479  auto it = current_.begin();
480  while (it != current_.end())
481  {
482  // Check for staleness
483  if (!isCurrent(
484  parms_, t, it->second.signTime(), it->second.seenTime()))
485  {
486  removeTrie(lock, it->first, it->second);
487  it = current_.erase(it);
488  }
489  else
490  {
491  auto cit = typename decltype(current_)::const_iterator{it};
492  // contains a live record
493  f(cit->first, cit->second);
494  ++it;
495  }
496  }
497  }
498 
511  template <class Pre, class F>
512  void
513  byLedger(std::lock_guard<Mutex> const&, ID const& ledgerID, Pre&& pre, F&& f)
514  {
515  auto it = byLedger_.find(ledgerID);
516  if (it != byLedger_.end())
517  {
518  // Update set time since it is being used
519  byLedger_.touch(it);
520  pre(it->second.size());
521  for (auto const& [key, val] : it->second)
522  f(key, val);
523  }
524  }
525 
526 public:
533  template <class... Ts>
535  ValidationParms const& p,
537  Ts&&... ts)
538  : byLedger_(c), parms_(p), adaptor_(std::forward<Ts>(ts)...)
539  {
540  }
541 
544  Adaptor const&
545  adaptor() const
546  {
547  return adaptor_;
548  }
549 
552  ValidationParms const&
553  parms() const
554  {
555  return parms_;
556  }
557 
565  bool
567  {
568  std::lock_guard lock{mutex_};
569  return localSeqEnforcer_(byLedger_.clock().now(), s, parms_);
570  }
571 
580  ValStatus
581  add(NodeID const& nodeID, Validation const& val)
582  {
583  if (!isCurrent(parms_, adaptor_.now(), val.signTime(), val.seenTime()))
584  return ValStatus::stale;
585 
586  {
587  std::lock_guard lock{mutex_};
588 
589  // Check that validation sequence is greater than any non-expired
590  // validations sequence from that validator
591  auto const now = byLedger_.clock().now();
592  SeqEnforcer<Seq>& enforcer = seqEnforcers_[nodeID];
593  if (!enforcer(now, val.seq(), parms_))
594  return ValStatus::badSeq;
595 
596  byLedger_[val.ledgerID()].insert_or_assign(nodeID, val);
597 
598  auto const [it, inserted] = current_.emplace(nodeID, val);
599  if (!inserted)
600  {
601  // Replace existing only if this one is newer
602  Validation& oldVal = it->second;
603  if (val.signTime() > oldVal.signTime())
604  {
605  std::pair<Seq, ID> old(oldVal.seq(), oldVal.ledgerID());
606  it->second = val;
607  if (val.trusted())
608  updateTrie(lock, nodeID, val, old);
609  }
610  else
611  return ValStatus::stale;
612  }
613  else if (val.trusted())
614  {
615  updateTrie(lock, nodeID, val, boost::none);
616  }
617  }
618  return ValStatus::current;
619  }
620 
626  void
628  {
629  std::lock_guard lock{mutex_};
631  }
632 
642  void
643  trustChanged(hash_set<NodeID> const& added, hash_set<NodeID> const& removed)
644  {
645  std::lock_guard lock{mutex_};
646 
647  for (auto& [nodeId, validation] : current_)
648  {
649  if (added.find(nodeId) != added.end())
650  {
651  validation.setTrusted();
652  updateTrie(lock, nodeId, validation, boost::none);
653  }
654  else if (removed.find(nodeId) != removed.end())
655  {
656  validation.setUntrusted();
657  removeTrie(lock, nodeId, validation);
658  }
659  }
660 
661  for (auto& [_, validationMap] : byLedger_)
662  {
663  (void)_;
664  for (auto& [nodeId, validation] : validationMap)
665  {
666  if (added.find(nodeId) != added.end())
667  {
668  validation.setTrusted();
669  }
670  else if (removed.find(nodeId) != removed.end())
671  {
672  validation.setUntrusted();
673  }
674  }
675  }
676  }
677 
679  getJsonTrie() const
680  {
681  std::lock_guard lock{mutex_};
682  return trie_.getJson();
683  }
684 
697  boost::optional<std::pair<Seq, ID>>
698  getPreferred(Ledger const& curr)
699  {
700  std::lock_guard lock{mutex_};
701  boost::optional<SpanTip<Ledger>> preferred =
702  withTrie(lock, [this](LedgerTrie<Ledger>& trie) {
703  return trie.getPreferred(localSeqEnforcer_.largest());
704  });
705  // No trusted validations to determine branch
706  if (!preferred)
707  {
708  // fall back to majority over acquiring ledgers
709  auto it = std::max_element(
710  acquiring_.begin(),
711  acquiring_.end(),
712  [](auto const& a, auto const& b) {
713  std::pair<Seq, ID> const& aKey = a.first;
714  typename hash_set<NodeID>::size_type const& aSize =
715  a.second.size();
716  std::pair<Seq, ID> const& bKey = b.first;
717  typename hash_set<NodeID>::size_type const& bSize =
718  b.second.size();
719  // order by number of trusted peers validating that ledger
720  // break ties with ledger ID
721  return std::tie(aSize, aKey.second) <
722  std::tie(bSize, bKey.second);
723  });
724  if (it != acquiring_.end())
725  return it->first;
726  return boost::none;
727  }
728 
729  // If we are the parent of the preferred ledger, stick with our
730  // current ledger since we might be about to generate it
731  if (preferred->seq == curr.seq() + Seq{1} &&
732  preferred->ancestor(curr.seq()) == curr.id())
733  return std::make_pair(curr.seq(), curr.id());
734 
735  // A ledger ahead of us is preferred regardless of whether it is
736  // a descendant of our working ledger or it is on a different chain
737  if (preferred->seq > curr.seq())
738  return std::make_pair(preferred->seq, preferred->id);
739 
740  // Only switch to earlier or same sequence number
741  // if it is a different chain.
742  if (curr[preferred->seq] != preferred->id)
743  return std::make_pair(preferred->seq, preferred->id);
744 
745  // Stick with current ledger
746  return std::make_pair(curr.seq(), curr.id());
747  }
748 
758  ID
759  getPreferred(Ledger const& curr, Seq minValidSeq)
760  {
761  boost::optional<std::pair<Seq, ID>> preferred = getPreferred(curr);
762  if (preferred && preferred->first >= minValidSeq)
763  return preferred->second;
764  return curr.id();
765  }
766 
783  ID
785  Ledger const& lcl,
786  Seq minSeq,
787  hash_map<ID, std::uint32_t> const& peerCounts)
788  {
789  boost::optional<std::pair<Seq, ID>> preferred = getPreferred(lcl);
790 
791  // Trusted validations exist, but stick with local preferred ledger if
792  // preferred is in the past
793  if (preferred)
794  return (preferred->first >= minSeq) ? preferred->second : lcl.id();
795 
796  // Otherwise, rely on peer ledgers
797  auto it = std::max_element(
798  peerCounts.begin(), peerCounts.end(), [](auto& a, auto& b) {
799  // Prefer larger counts, then larger ids on ties
800  // (max_element expects this to return true if a < b)
801  return std::tie(a.second, a.first) <
802  std::tie(b.second, b.first);
803  });
804 
805  if (it != peerCounts.end())
806  return it->first;
807  return lcl.id();
808  }
809 
822  getNodesAfter(Ledger const& ledger, ID const& ledgerID)
823  {
824  std::lock_guard lock{mutex_};
825 
826  // Use trie if ledger is the right one
827  if (ledger.id() == ledgerID)
828  return withTrie(lock, [&ledger](LedgerTrie<Ledger>& trie) {
829  return trie.branchSupport(ledger) - trie.tipSupport(ledger);
830  });
831 
832  // Count parent ledgers as fallback
833  return std::count_if(
834  lastLedger_.begin(),
835  lastLedger_.end(),
836  [&ledgerID](auto const& it) {
837  auto const& curr = it.second;
838  return curr.seq() > Seq{0} &&
839  curr[curr.seq() - Seq{1}] == ledgerID;
840  });
841  }
842 
849  {
851  std::lock_guard lock{mutex_};
852  current(
853  lock,
854  [&](std::size_t numValidations) { ret.reserve(numValidations); },
855  [&](NodeID const&, Validation const& v) {
856  if (v.trusted() && v.full())
857  ret.push_back(v.unwrap());
858  });
859  return ret;
860  }
861 
866  auto
868  {
869  hash_set<NodeID> ret;
870  std::lock_guard lock{mutex_};
871  current(
872  lock,
873  [&](std::size_t numValidations) { ret.reserve(numValidations); },
874  [&](NodeID const& nid, Validation const&) { ret.insert(nid); });
875 
876  return ret;
877  }
878 
885  numTrustedForLedger(ID const& ledgerID)
886  {
887  std::size_t count = 0;
888  std::lock_guard lock{mutex_};
889  byLedger(
890  lock,
891  ledgerID,
892  [&](std::size_t) {}, // nothing to reserve
893  [&](NodeID const&, Validation const& v) {
894  if (v.trusted() && v.full())
895  ++count;
896  });
897  return count;
898  }
899 
906  getTrustedForLedger(ID const& ledgerID)
907  {
909  std::lock_guard lock{mutex_};
910  byLedger(
911  lock,
912  ledgerID,
913  [&](std::size_t numValidations) { res.reserve(numValidations); },
914  [&](NodeID const&, Validation const& v) {
915  if (v.trusted() && v.full())
916  res.emplace_back(v.unwrap());
917  });
918 
919  return res;
920  }
921 
929  fees(ID const& ledgerID, std::uint32_t baseFee)
930  {
932  std::lock_guard lock{mutex_};
933  byLedger(
934  lock,
935  ledgerID,
936  [&](std::size_t numValidations) { res.reserve(numValidations); },
937  [&](NodeID const&, Validation const& v) {
938  if (v.trusted() && v.full())
939  {
940  boost::optional<std::uint32_t> loadFee = v.loadFee();
941  if (loadFee)
942  res.push_back(*loadFee);
943  else
944  res.push_back(baseFee);
945  }
946  });
947  return res;
948  }
949 
952  void
954  {
955  std::lock_guard lock{mutex_};
956  current_.clear();
957  }
958 
975  laggards(Seq const seq, hash_set<NodeKey>& trustedKeys)
976  {
977  std::size_t laggards = 0;
978 
979  current(std::lock_guard{mutex_},
980  [](std::size_t) {},
981  [&](NodeID const&, Validation const& v) {
982  if (adaptor_.now() <
983  v.seenTime() + parms_.validationFRESHNESS &&
984  trustedKeys.find(v.key()) != trustedKeys.end())
985  {
986  trustedKeys.erase(v.key());
987  if (seq > v.seq())
988  ++laggards;
989  }
990  });
991 
992  return laggards;
993  }
994 };
995 
996 } // namespace ripple
997 #endif
ripple::Validations::expire
void expire()
Expire old validation sets.
Definition: Validations.h:627
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::Seq
typename Ledger::Seq Seq
Definition: Validations.h:282
std::max_element
T max_element(T... args)
ripple::LedgerTrie::branchSupport
std::uint32_t branchSupport(Ledger const &ledger) const
Return the count of branch support for the specific ledger.
Definition: LedgerTrie.h:605
std::chrono::steady_clock
ripple::LedgerTrie::getPreferred
boost::optional< SpanTip< Ledger > > getPreferred(Seq const largestIssued) const
Return the preferred ledger ID.
Definition: LedgerTrie.h:679
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::Validation
typename ripple::test::csf::Peer::ValAdaptor ::Validation Validation
Definition: Validations.h:279
ripple::Validations::seqEnforcers_
hash_map< NodeID, SeqEnforcer< Seq > > seqEnforcers_
Definition: Validations.h:299
ripple::Dir::const_iterator
Definition: Directory.h:49
ripple::SeqEnforcer
Enforce validation increasing sequence requirement.
Definition: Validations.h:96
std::string
STL class.
utility
ripple::Validations::laggards
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 ...
Definition: Validations.h:975
std::unordered_set
STL class.
std::pair< Seq, ID >
std::vector::reserve
T reserve(T... args)
ripple::Validations::fees
std::vector< std::uint32_t > fees(ID const &ledgerID, std::uint32_t baseFee)
Returns fees reported by trusted full validators in the given ledger.
Definition: Validations.h:929
ripple::Validations::lastLedger_
hash_map< NodeID, Ledger > lastLedger_
Definition: Validations.h:314
ripple::Validations::Validations
Validations(ValidationParms const &p, beast::abstract_clock< std::chrono::steady_clock > &c, Ts &&... ts)
Constructor.
Definition: Validations.h:534
vector
std::unordered_set::find
T find(T... args)
ripple::Validations::trustChanged
void trustChanged(hash_set< NodeID > const &added, hash_set< NodeID > const &removed)
Update trust status of validations.
Definition: Validations.h:643
ripple::Validations::getPreferredLCL
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.
Definition: Validations.h:784
std::chrono::seconds
ripple::Validations::trie_
LedgerTrie< Ledger > trie_
Definition: Validations.h:310
ripple::LedgerTrie::tipSupport
std::uint32_t tipSupport(Ledger const &ledger) const
Return count of tip support for the specific ledger.
Definition: LedgerTrie.h:591
ripple::Validations::withTrie
auto withTrie(std::lock_guard< Mutex > const &lock, F &&f)
Use the trie for a calculation.
Definition: Validations.h:449
ripple::Validations::current
void current(std::lock_guard< Mutex > const &lock, Pre &&pre, F &&f)
Iterate current validations.
Definition: Validations.h:475
ripple::Validations::byLedger
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.
Definition: Validations.h:513
ripple::ValStatus
ValStatus
Status of newly received validation.
Definition: Validations.h:164
ripple::ValidationParms::validationCURRENT_EARLY
std::chrono::seconds validationCURRENT_EARLY
Duration pre-close in which validations are acceptable.
Definition: Validations.h:68
std::lock_guard
STL class.
ripple::Validations::byLedger_
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)
Definition: Validations.h:307
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::Validations::checkAcquired
void checkAcquired(std::lock_guard< Mutex > const &lock)
Definition: Validations.h:353
ripple::Validations::parms
ValidationParms const & parms() const
Return the validation timing parameters.
Definition: Validations.h:553
ripple::Validations::getJsonTrie
Json::Value getJsonTrie() const
Definition: Validations.h:679
ripple::Validations::updateTrie
void updateTrie(std::lock_guard< Mutex > const &lock, NodeID const &nodeID, Validation const &val, boost::optional< std::pair< Seq, ID >> prior)
Process a new validation.
Definition: Validations.h:397
ripple::SeqEnforcer::largest
Seq largest() const
Definition: Validations.h:128
std::vector::push_back
T push_back(T... args)
ripple::ValStatus::badSeq
@ badSeq
A validation violates the increasing seq requirement.
ripple::Validations::getPreferred
boost::optional< std::pair< Seq, ID > > getPreferred(Ledger const &curr)
Return the sequence number and ID of the preferred working ledger.
Definition: Validations.h:698
ripple::Validations::mutex_
Mutex mutex_
Definition: Validations.h:290
ripple::Validations::add
ValStatus add(NodeID const &nodeID, Validation const &val)
Add a new validation.
Definition: Validations.h:581
ripple::Validations::adaptor_
Adaptor adaptor_
Definition: Validations.h:324
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::Mutex
typename ripple::test::csf::Peer::ValAdaptor ::Mutex Mutex
Definition: Validations.h:278
ripple::SeqEnforcer::time_point
std::chrono::steady_clock::time_point time_point
Definition: Validations.h:98
ripple::Validations::acquiring_
hash_map< std::pair< Seq, ID >, hash_set< NodeID > > acquiring_
Definition: Validations.h:317
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::NodeKey
typename Validation::NodeKey NodeKey
Definition: Validations.h:284
ripple::isCurrent
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
Definition: Validations.h:145
ripple::Validations::getNodesAfter
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.
Definition: Validations.h:822
ripple::Validations::numTrustedForLedger
std::size_t numTrustedForLedger(ID const &ledgerID)
Count the number of trusted full validations for the given ledger.
Definition: Validations.h:885
ripple::SeqEnforcer::when_
time_point when_
Definition: Validations.h:100
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::NodeID
typename Validation::NodeID NodeID
Definition: Validations.h:283
std::chrono::time_point
std::unordered_set::erase
T erase(T... args)
ripple::ValStatus::stale
@ stale
Not current or was older than current from this node.
ripple::ValStatus::current
@ current
This was a new validation and was added.
ripple::ValidationParms::validationCURRENT_LOCAL
std::chrono::seconds validationCURRENT_LOCAL
Duration a validation remains current after first observed.
Definition: Validations.h:61
ripple::Validations::canValidateSeq
bool canValidateSeq(Seq const s)
Return whether the local node can issue a validation for the given sequence number.
Definition: Validations.h:566
ripple::HashPrefix::validation
@ validation
validation for signing
std::uint32_t
ripple::ValidationParms::validationCURRENT_WALL
std::chrono::seconds validationCURRENT_WALL
The number of seconds a validation remains current after its ledger's close time.
Definition: Validations.h:53
ripple::SeqEnforcer::operator()
bool operator()(time_point now, Seq s, ValidationParms const &p)
Try advancing the largest observed validation ledger sequence.
Definition: Validations.h:116
ripple::Validations::getTrustedForLedger
std::vector< WrappedValidationType > getTrustedForLedger(ID const &ledgerID)
Get trusted full validations for a specific ledger.
Definition: Validations.h:906
beast::abstract_clock< std::chrono::steady_clock >
ripple::Validations::getPreferred
ID getPreferred(Ledger const &curr, Seq minValidSeq)
Get the ID of the preferred working ledger that exceeds a minimum valid ledger sequence number.
Definition: Validations.h:759
ripple::Validations::flush
void flush()
Flush all current validations.
Definition: Validations.h:953
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::ID
typename Ledger::ID ID
Definition: Validations.h:281
std::decay_t
ripple::Validations::updateTrie
void updateTrie(std::lock_guard< Mutex > const &, NodeID const &nodeID, Ledger ledger)
Definition: Validations.h:372
ripple::Validations::localSeqEnforcer_
SeqEnforcer< Seq > localSeqEnforcer_
Definition: Validations.h:296
beast::detail::aged_unordered_container
Associative container where each element is also indexed by time.
Definition: aged_unordered_container.h:88
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerTrie
Ancestry trie of ledgers.
Definition: LedgerTrie.h:347
ripple::ValidationParms::validationFRESHNESS
std::chrono::seconds validationFRESHNESS
How long we consider a validation fresh.
Definition: Validations.h:86
std::unordered_map::begin
T begin(T... args)
std
STL namespace.
std::unordered_set::insert
T insert(T... args)
ripple::ValidationParms::validationSET_EXPIRES
std::chrono::seconds validationSET_EXPIRES
Duration a set of validations for a given ledger hash remain valid.
Definition: Validations.h:76
ripple::Validations::parms_
const ValidationParms parms_
Definition: Validations.h:320
std::result_of_t
std::count_if
T count_if(T... args)
beast::expire
std::enable_if< is_aged_container< AgedContainer >::value, std::size_t >::type expire(AgedContainer &c, std::chrono::duration< Rep, Period > const &age)
Expire aged container items past the specified age.
Definition: aged_container_utility.h:35
mutex
std::size_t
std::make_pair
T make_pair(T... args)
std::unordered_set::end
T end(T... args)
ripple::Validations< ripple::test::csf::Peer::ValAdaptor >::Ledger
typename ripple::test::csf::Peer::ValAdaptor ::Ledger Ledger
Definition: Validations.h:280
beast::uhash<>
ripple::Validations::getCurrentNodeIDs
auto getCurrentNodeIDs() -> hash_set< NodeID >
Get the set of node ids associated with current validations.
Definition: Validations.h:867
ripple::ValidationParms::ValidationParms
ValidationParms()=default
ripple::Validations::removeTrie
void removeTrie(std::lock_guard< Mutex > const &, NodeID const &nodeID, Validation const &val)
Definition: Validations.h:329
ripple::Validations::adaptor
Adaptor const & adaptor() const
Return the adaptor instance.
Definition: Validations.h:545
ripple::ValidationParms
Timing parameters to control validation staleness and expiration.
Definition: Validations.h:43
std::unordered_map
STL class.
Json::Value
Represents a JSON value.
Definition: json_value.h:141
ripple::SeqEnforcer::seq_
Seq seq_
Definition: Validations.h:99
ripple::Validations::currentTrusted
std::vector< WrappedValidationType > currentTrusted()
Get the currently trusted full validations.
Definition: Validations.h:848
ripple::Validations::current_
hash_map< NodeID, Validation > current_
Definition: Validations.h:293