rippled
test/csf/Peer.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 #ifndef RIPPLE_TEST_CSF_PEER_H_INCLUDED
20 #define RIPPLE_TEST_CSF_PEER_H_INCLUDED
21 
22 #include <ripple/beast/utility/WrappedSink.h>
23 #include <ripple/consensus/Consensus.h>
24 #include <ripple/consensus/Validations.h>
25 #include <ripple/protocol/PublicKey.h>
26 #include <boost/container/flat_map.hpp>
27 #include <boost/container/flat_set.hpp>
28 #include <algorithm>
29 #include <test/csf/CollectorRef.h>
30 #include <test/csf/Scheduler.h>
31 #include <test/csf/TrustGraph.h>
32 #include <test/csf/Tx.h>
33 #include <test/csf/Validation.h>
34 #include <test/csf/events.h>
35 #include <test/csf/ledgers.h>
36 
37 namespace ripple {
38 namespace test {
39 namespace csf {
40 
41 namespace bc = boost::container;
42 
54 struct Peer
55 {
61  class Position
62  {
63  public:
64  Position(Proposal const& p) : proposal_(p)
65  {
66  }
67 
68  Proposal const&
69  proposal() const
70  {
71  return proposal_;
72  }
73 
75  getJson() const
76  {
77  return proposal_.getJson();
78  }
79 
80  private:
82  };
83 
87  {
92 
95 
96  // Return the receive delay for message type M, default is no delay
97  // Received delay is the time from receiving the message to actually
98  // handling it.
99  template <class M>
101  onReceive(M const&) const
102  {
103  return SimDuration{};
104  }
105 
107  onReceive(Validation const&) const
108  {
109  return recvValidation;
110  }
111  };
112 
117  {
119 
120  public:
121  struct Mutex
122  {
123  void
125  {
126  }
127 
128  void
130  {
131  }
132  };
133 
136 
137  ValAdaptor(Peer& p) : p_{p}
138  {
139  }
140 
142  now() const
143  {
144  return p_.now();
145  }
146 
148  acquire(Ledger::ID const& lId)
149  {
150  if (Ledger const* ledger = p_.acquireLedger(lId))
151  return *ledger;
152  return std::nullopt;
153  }
154  };
155 
157  using Ledger_t = Ledger;
158  using NodeID_t = PeerID;
160  using TxSet_t = TxSet;
164 
168 
171 
174 
177 
180 
183 
186 
189 
192 
195 
198 
201 
205 
206  //-------------------------------------------------------------------------
207  // Store most network messages; these could be purged if memory use ever
208  // becomes problematic
209 
212  bc::flat_map<Ledger::ID, std::vector<Proposal>> peerPositions;
214  bc::flat_map<TxSet::ID, TxSet> txSets;
215 
216  // Ledgers/TxSets we are acquiring and when that request times out
217  bc::flat_map<Ledger::ID, SimTime> acquiringLedgers;
218  bc::flat_map<TxSet::ID, SimTime> acquiringTxSets;
219 
222 
225 
228 
231 
233  bool runAsValidator = true;
234 
235  // TODO: Consider removing these two, they are only a convenience for tests
236  // Number of proposers in the prior round
238  // Duration of prior round
240 
241  // Quorum of validations needed for a ledger to be fully validated
242  // TODO: Use the logic in ValidatorList to set this dynamically
244 
246 
247  // Simulation parameters
249 
252 
265  PeerID i,
266  Scheduler& s,
267  LedgerOracle& o,
269  TrustGraph<Peer*>& tg,
270  CollectorRefs& c,
271  beast::Journal jIn)
272  : sink(jIn, "Peer " + to_string(i) + ": ")
273  , j(sink)
274  , consensus(s.clock(), *this, j)
275  , id{i}
276  , key{id, 0}
277  , oracle{o}
278  , scheduler{s}
279  , net{n}
280  , trustGraph(tg)
281  , lastClosedLedger{Ledger::MakeGenesis{}}
282  , validations{ValidationParms{}, s.clock(), *this}
283  , fullyValidatedLedger{Ledger::MakeGenesis{}}
284  , collectors{c}
285  {
286  // All peers start from the default constructed genesis ledger
288 
289  // nodes always trust themselves . . SHOULD THEY?
290  trustGraph.trust(this, this);
291  }
292 
296  template <class T>
297  void
299  {
300  using namespace std::chrono_literals;
301 
302  if (when == 0ns)
303  what();
304  else
305  scheduler.in(when, std::forward<T>(what));
306  }
307 
308  // Issue a new event to the collectors
309  template <class E>
310  void
311  issue(E const& event)
312  {
313  // Use the scheduler time and not the peer's (skewed) local time
314  collectors.on(id, scheduler.now(), event);
315  }
316 
317  //--------------------------------------------------------------------------
318  // Trust and Network members
319  // Methods for modifying and querying the network and trust graphs from
320  // the perspective of this Peer
321 
322  //< Extend trust to a peer
323  void
325  {
326  trustGraph.trust(this, &o);
327  }
328 
329  //< Revoke trust from a peer
330  void
332  {
333  trustGraph.untrust(this, &o);
334  }
335 
336  //< Check whether we trust a peer
337  bool
339  {
340  return trustGraph.trusts(this, &o);
341  }
342 
343  //< Check whether we trust a peer based on its ID
344  bool
345  trusts(PeerID const& oId)
346  {
347  for (auto const p : trustGraph.trustedPeers(this))
348  if (p->id == oId)
349  return true;
350  return false;
351  }
352 
362  bool
364  {
365  return net.connect(this, &o, dur);
366  }
367 
375  bool
377  {
378  return net.disconnect(this, &o);
379  }
380 
381  //--------------------------------------------------------------------------
382  // Generic Consensus members
383 
384  // Attempt to acquire the Ledger associated with the given ID
385  Ledger const*
386  acquireLedger(Ledger::ID const& ledgerID)
387  {
388  if (auto it = ledgers.find(ledgerID); it != ledgers.end())
389  {
390  return &(it->second);
391  }
392 
393  // No peers
394  if (net.links(this).empty())
395  return nullptr;
396 
397  // Don't retry if we already are acquiring it and haven't timed out
398  auto aIt = acquiringLedgers.find(ledgerID);
399  if (aIt != acquiringLedgers.end())
400  {
401  if (scheduler.now() < aIt->second)
402  return nullptr;
403  }
404 
405  using namespace std::chrono_literals;
406  SimDuration minDuration{10s};
407  for (auto const link : net.links(this))
408  {
409  minDuration = std::min(minDuration, link.data.delay);
410 
411  // Send a messsage to neighbors to find the ledger
412  net.send(
413  this, link.target, [to = link.target, from = this, ledgerID]() {
414  if (auto it = to->ledgers.find(ledgerID);
415  it != to->ledgers.end())
416  {
417  // if the ledger is found, send it back to the original
418  // requesting peer where it is added to the available
419  // ledgers
420  to->net.send(to, from, [from, ledger = it->second]() {
421  from->acquiringLedgers.erase(ledger.id());
422  from->ledgers.emplace(ledger.id(), ledger);
423  });
424  }
425  });
426  }
427  acquiringLedgers[ledgerID] = scheduler.now() + 2 * minDuration;
428  return nullptr;
429  }
430 
431  // Attempt to acquire the TxSet associated with the given ID
432  TxSet const*
433  acquireTxSet(TxSet::ID const& setId)
434  {
435  if (auto it = txSets.find(setId); it != txSets.end())
436  {
437  return &(it->second);
438  }
439 
440  // No peers
441  if (net.links(this).empty())
442  return nullptr;
443 
444  // Don't retry if we already are acquiring it and haven't timed out
445  auto aIt = acquiringTxSets.find(setId);
446  if (aIt != acquiringTxSets.end())
447  {
448  if (scheduler.now() < aIt->second)
449  return nullptr;
450  }
451 
452  using namespace std::chrono_literals;
453  SimDuration minDuration{10s};
454  for (auto const link : net.links(this))
455  {
456  minDuration = std::min(minDuration, link.data.delay);
457  // Send a message to neighbors to find the tx set
458  net.send(
459  this, link.target, [to = link.target, from = this, setId]() {
460  if (auto it = to->txSets.find(setId);
461  it != to->txSets.end())
462  {
463  // If the txSet is found, send it back to the original
464  // requesting peer, where it is handled like a TxSet
465  // that was broadcast over the network
466  to->net.send(to, from, [from, txSet = it->second]() {
467  from->acquiringTxSets.erase(txSet.id());
468  from->handle(txSet);
469  });
470  }
471  });
472  }
473  acquiringTxSets[setId] = scheduler.now() + 2 * minDuration;
474  return nullptr;
475  }
476 
477  bool
479  {
480  return !openTxs.empty();
481  }
482 
484  proposersValidated(Ledger::ID const& prevLedger)
485  {
486  return validations.numTrustedForLedger(prevLedger);
487  }
488 
490  proposersFinished(Ledger const& prevLedger, Ledger::ID const& prevLedgerID)
491  {
492  return validations.getNodesAfter(prevLedger, prevLedgerID);
493  }
494 
495  Result
497  Ledger const& prevLedger,
498  NetClock::time_point closeTime,
499  ConsensusMode mode)
500  {
501  issue(CloseLedger{prevLedger, openTxs});
502 
503  return Result(
504  TxSet{openTxs},
505  Proposal(
506  prevLedger.id(),
509  closeTime,
510  now(),
511  id));
512  }
513 
514  void
516  Result const& result,
517  Ledger const& prevLedger,
518  NetClock::duration const& closeResolution,
519  ConsensusCloseTimes const& rawCloseTimes,
520  ConsensusMode const& mode,
521  Json::Value&& consensusJson)
522  {
523  onAccept(
524  result,
525  prevLedger,
526  closeResolution,
527  rawCloseTimes,
528  mode,
529  std::move(consensusJson));
530  }
531 
532  void
534  Result const& result,
535  Ledger const& prevLedger,
536  NetClock::duration const& closeResolution,
537  ConsensusCloseTimes const& rawCloseTimes,
538  ConsensusMode const& mode,
539  Json::Value&& consensusJson)
540  {
541  schedule(delays.ledgerAccept, [=, this]() {
542  const bool proposing = mode == ConsensusMode::proposing;
543  const bool consensusFail = result.state == ConsensusState::MovedOn;
544 
545  TxSet const acceptedTxs = injectTxs(prevLedger, result.txns);
546  Ledger const newLedger = oracle.accept(
547  prevLedger,
548  acceptedTxs.txs(),
549  closeResolution,
550  result.position.closeTime());
551  ledgers[newLedger.id()] = newLedger;
552 
553  issue(AcceptLedger{newLedger, lastClosedLedger});
554  prevProposers = result.proposers;
555  prevRoundTime = result.roundTime.read();
556  lastClosedLedger = newLedger;
557 
558  auto const it = std::remove_if(
559  openTxs.begin(), openTxs.end(), [&](Tx const& tx) {
560  return acceptedTxs.exists(tx.id());
561  });
562  openTxs.erase(it, openTxs.end());
563 
564  // Only send validation if the new ledger is compatible with our
565  // fully validated ledger
566  bool const isCompatible =
567  newLedger.isAncestor(fullyValidatedLedger);
568 
569  // Can only send one validated ledger per seq
570  if (runAsValidator && isCompatible && !consensusFail &&
571  validations.canValidateSeq(newLedger.seq()))
572  {
573  bool isFull = proposing;
574 
575  Validation v{
576  newLedger.id(),
577  newLedger.seq(),
578  now(),
579  now(),
580  key,
581  id,
582  isFull};
583  // share the new validation; it is trusted by the receiver
584  share(v);
585  // we trust ourselves
587  }
588 
589  checkFullyValidated(newLedger);
590 
591  // kick off the next round...
592  // in the actual implementation, this passes back through
593  // network ops
595  // startRound sets the LCL state, so we need to call it once after
596  // the last requested round completes
598  {
599  startRound();
600  }
601  });
602  }
603 
604  // Earliest allowed sequence number when checking for ledgers with more
605  // validations than our current ledger
608  {
609  return fullyValidatedLedger.seq();
610  }
611 
612  Ledger::ID
614  Ledger::ID const& ledgerID,
615  Ledger const& ledger,
616  ConsensusMode mode)
617  {
618  // only do if we are past the genesis ledger
619  if (ledger.seq() == Ledger::Seq{0})
620  return ledgerID;
621 
622  Ledger::ID const netLgr =
623  validations.getPreferred(ledger, earliestAllowedSeq());
624 
625  if (netLgr != ledgerID)
626  {
627  JLOG(j.trace()) << Json::Compact(validations.getJsonTrie());
628  issue(WrongPrevLedger{ledgerID, netLgr});
629  }
630 
631  return netLgr;
632  }
633 
634  void
635  propose(Proposal const& pos)
636  {
637  share(pos);
638  }
639 
640  ConsensusParms const&
641  parms() const
642  {
643  return consensusParms;
644  }
645 
646  // Not interested in tracking consensus mode changes for now
648  {
649  }
650 
651  // Share a message by broadcasting to all connected peers
652  template <class M>
653  void
654  share(M const& m)
655  {
656  issue(Share<M>{m});
657  send(BroadcastMesg<M>{m, router.nextSeq++, this->id}, this->id);
658  }
659 
660  // Unwrap the Position and share the raw proposal
661  void
662  share(Position const& p)
663  {
664  share(p.proposal());
665  }
666 
667  //--------------------------------------------------------------------------
668  // Validation members
669 
671  bool
673  {
674  v.setTrusted();
675  v.setSeen(now());
676  ValStatus const res = validations.add(v.nodeID(), v);
677 
678  if (res == ValStatus::stale)
679  return false;
680 
681  // Acquire will try to get from network if not already local
682  if (Ledger const* lgr = acquireLedger(v.ledgerID()))
683  checkFullyValidated(*lgr);
684  return true;
685  }
686 
688  void
690  {
691  // Only consider ledgers newer than our last fully validated ledger
692  if (ledger.seq() <= fullyValidatedLedger.seq())
693  return;
694 
695  std::size_t const count = validations.numTrustedForLedger(ledger.id());
696  std::size_t const numTrustedPeers = trustGraph.graph().outDegree(this);
697  quorum = static_cast<std::size_t>(std::ceil(numTrustedPeers * 0.8));
698  if (count >= quorum && ledger.isAncestor(fullyValidatedLedger))
699  {
701  fullyValidatedLedger = ledger;
702  }
703  }
704 
705  //-------------------------------------------------------------------------
706  // Peer messaging members
707 
708  // Basic Sequence number router
709  // A message that will be flooded across the network is tagged with a
710  // sequence number by the origin node in a BroadcastMesg. Receivers will
711  // ignore a message as stale if they've already processed a newer sequence
712  // number, or will process and potentially relay the message along.
713  //
714  // The various bool handle(MessageType) members do the actual processing
715  // and should return true if the message should continue to be sent to
716  // peers.
717  //
718  // WARN: This assumes messages are received and processed in the order they
719  // are sent, so that a peer receives a message with seq 1 from node 0
720  // before seq 2 from node 0, etc.
721  // TODO: Break this out into a class and identify type interface to allow
722  // alternate routing strategies
723  template <class M>
725  {
726  M mesg;
729  };
730 
731  struct Router
732  {
734  bc::flat_map<PeerID, std::size_t> lastObservedSeq;
735  };
736 
738 
739  // Send a broadcast message to all peers
740  template <class M>
741  void
742  send(BroadcastMesg<M> const& bm, PeerID from)
743  {
744  for (auto const link : net.links(this))
745  {
746  if (link.target->id != from && link.target->id != bm.origin)
747  {
748  // cheat and don't bother sending if we know it has already been
749  // used on the other end
750  if (link.target->router.lastObservedSeq[bm.origin] < bm.seq)
751  {
752  issue(Relay<M>{link.target->id, bm.mesg});
753  net.send(
754  this,
755  link.target,
756  [to = link.target, bm, id = this->id] {
757  to->receive(bm, id);
758  });
759  }
760  }
761  }
762  }
763 
764  // Receive a shared message, process it and consider continuing to relay it
765  template <class M>
766  void
767  receive(BroadcastMesg<M> const& bm, PeerID from)
768  {
769  issue(Receive<M>{from, bm.mesg});
770  if (router.lastObservedSeq[bm.origin] < bm.seq)
771  {
772  router.lastObservedSeq[bm.origin] = bm.seq;
773  schedule(delays.onReceive(bm.mesg), [this, bm, from] {
774  if (handle(bm.mesg))
775  send(bm, from);
776  });
777  }
778  }
779 
780  // Type specific receive handlers, return true if the message should
781  // continue to be broadcast to peers
782  bool
783  handle(Proposal const& p)
784  {
785  // Only relay untrusted proposals on the same ledger
786  if (!trusts(p.nodeID()))
787  return p.prevLedger() == lastClosedLedger.id();
788 
789  // TODO: This always suppresses relay of peer positions already seen
790  // Should it allow forwarding if for a recent ledger ?
791  auto& dest = peerPositions[p.prevLedger()];
792  if (std::find(dest.begin(), dest.end(), p) != dest.end())
793  return false;
794 
795  dest.push_back(p);
796 
797  // Rely on consensus to decide whether to relay
798  return consensus.peerProposal(now(), Position{p});
799  }
800 
801  bool
802  handle(TxSet const& txs)
803  {
804  bool const inserted =
805  txSets.insert(std::make_pair(txs.id(), txs)).second;
806  if (inserted)
807  consensus.gotTxSet(now(), txs);
808  // relay only if new
809  return inserted;
810  }
811 
812  bool
813  handle(Tx const& tx)
814  {
815  // Ignore and suppress relay of transactions already in last ledger
816  TxSetType const& lastClosedTxs = lastClosedLedger.txs();
817  if (lastClosedTxs.find(tx) != lastClosedTxs.end())
818  return false;
819 
820  // only relay if it was new to our open ledger
821  return openTxs.insert(tx).second;
822  }
823 
824  bool
825  handle(Validation const& v)
826  {
827  // TODO: This is not relaying untrusted validations
828  if (!trusts(v.nodeID()))
829  return false;
830 
831  // Will only relay if current
832  return addTrustedValidation(v);
833  }
834 
835  bool
837  {
838  return fullyValidatedLedger.seq() > Ledger::Seq{0};
839  }
840 
843  {
844  return earliestAllowedSeq();
845  }
846 
849  {
850  hash_set<NodeKey_t> keys;
851  for (auto const p : trustGraph.trustedPeers(this))
852  keys.insert(p->key);
853  return {quorum, keys};
854  }
855 
858  {
859  return validations.laggards(seq, trusted);
860  }
861 
862  bool
863  validator() const
864  {
865  return runAsValidator;
866  }
867 
868  void
869  updateOperatingMode(std::size_t const positions) const
870  {
871  }
872 
873  //--------------------------------------------------------------------------
874  // A locally submitted transaction
875  void
876  submit(Tx const& tx)
877  {
878  issue(SubmitTx{tx});
879  if (handle(tx))
880  share(tx);
881  }
882 
883  //--------------------------------------------------------------------------
884  // Simulation "driver" members
885 
887  void
889  {
890  consensus.timerEntry(now());
891  // only reschedule if not completed
893  scheduler.in(parms().ledgerGRANULARITY, [this]() { timerEntry(); });
894  }
895 
896  // Called to begin the next round
897  void
899  {
900  // Between rounds, we take the majority ledger
901  // In the future, consider taking peer dominant ledger if no validations
902  // yet
903  Ledger::ID bestLCL =
905  if (bestLCL == Ledger::ID{0})
906  bestLCL = lastClosedLedger.id();
907 
908  issue(StartRound{bestLCL, lastClosedLedger});
909 
910  // Not yet modeling dynamic UNL.
911  hash_set<PeerID> nowUntrusted;
912  consensus.startRound(
913  now(), bestLCL, lastClosedLedger, nowUntrusted, runAsValidator);
914  }
915 
916  // Start the consensus process assuming it is not yet running
917  // This runs forever unless targetLedgers is specified
918  void
920  {
921  // TODO: Expire validations less frequently?
922  validations.expire(j);
923  scheduler.in(parms().ledgerGRANULARITY, [&]() { timerEntry(); });
924  startRound();
925  }
926 
928  now() const
929  {
930  // We don't care about the actual epochs, but do want the
931  // generated NetClock time to be well past its epoch to ensure
932  // any subtractions of two NetClock::time_point in the consensus
933  // code are positive. (e.g. proposeFRESHNESS)
934  using namespace std::chrono;
935  using namespace std::chrono_literals;
936  return NetClock::time_point(duration_cast<NetClock::duration>(
937  scheduler.now().time_since_epoch() + 86400s + clockSkew));
938  }
939 
940  Ledger::ID
941  prevLedgerID() const
942  {
943  return consensus.prevLedgerID();
944  }
945 
946  //-------------------------------------------------------------------------
947  // Injects a specific transaction when generating the ledger following
948  // the provided sequence. This allows simulating a byzantine failure in
949  // which a node generates the wrong ledger, even when consensus worked
950  // properly.
951  // TODO: Make this more robust
953 
964  TxSet
965  injectTxs(Ledger prevLedger, TxSet const& src)
966  {
967  auto const it = txInjections.find(prevLedger.seq());
968 
969  if (it == txInjections.end())
970  return src;
971  TxSetType res{src.txs()};
972  res.insert(it->second);
973 
974  return TxSet{res};
975  }
976 };
977 
978 } // namespace csf
979 } // namespace test
980 } // namespace ripple
981 #endif
ripple::test::csf::Peer::acquiringLedgers
bc::flat_map< Ledger::ID, SimTime > acquiringLedgers
Definition: test/csf/Peer.h:217
ripple::test::csf::Peer::haveValidated
bool haveValidated() const
Definition: test/csf/Peer.h:836
ripple::test::csf::Peer::prevProposers
std::size_t prevProposers
Definition: test/csf/Peer.h:237
ripple::test::csf::Peer::validator
bool validator() const
Definition: test/csf/Peer.h:863
ripple::test::csf::Peer::ProcessingDelays::onReceive
SimDuration onReceive(M const &) const
Definition: test/csf/Peer.h:101
ripple::test::csf::Peer::handle
bool handle(TxSet const &txs)
Definition: test/csf/Peer.h:802
ripple::test::csf::Peer::propose
void propose(Proposal const &pos)
Definition: test/csf/Peer.h:635
ripple::test::csf::Peer::Position::getJson
Json::Value getJson() const
Definition: test/csf/Peer.h:75
ripple::test::csf::Peer::router
Router router
Definition: test/csf/Peer.h:737
ripple::test::csf::Peer::trusts
bool trusts(Peer &o)
Definition: test/csf/Peer.h:338
ripple::test::csf::Peer::clockSkew
std::chrono::seconds clockSkew
Skew of time relative to the common scheduler clock.
Definition: test/csf/Peer.h:227
ripple::test::csf::TrustGraph
Trust graph.
Definition: TrustGraph.h:43
ripple::ConsensusMode::proposing
@ proposing
We are normal participant in consensus and propose our position.
ripple::test::csf::TxSet::calcID
static ID calcID(TxSetType const &txs)
Definition: Tx.h:83
ripple::test::csf::TxSetType
boost::container::flat_set< Tx > TxSetType
Definition: Tx.h:73
ripple::test::csf::Peer::ValAdaptor::p_
Peer & p_
Definition: test/csf/Peer.h:118
ripple::test::csf::Peer::Position::proposal_
Proposal proposal_
Definition: test/csf/Peer.h:81
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::test::csf::Peer::trustedKeys
hash_set< NodeKey_t > trustedKeys
Definition: test/csf/Peer.h:245
ripple::test::csf::Peer::getValidLedgerIndex
Ledger::Seq getValidLedgerIndex() const
Definition: test/csf/Peer.h:842
ripple::test::csf::Peer::Router::lastObservedSeq
bc::flat_map< PeerID, std::size_t > lastObservedSeq
Definition: test/csf/Peer.h:734
std::unordered_set
STL class.
ripple::test::csf::PeerID
tagged_integer< std::uint32_t, PeerIDTag > PeerID
Definition: Validation.h:35
std::pair< PeerID, std::uint32_t >
ripple::test::csf::Peer::txInjections
hash_map< Ledger::Seq, Tx > txInjections
Definition: test/csf/Peer.h:952
ripple::test::csf::Peer::ValAdaptor
Generic Validations adaptor that simply ignores recently stale validations.
Definition: test/csf/Peer.h:116
ripple::test::csf::Peer::share
void share(Position const &p)
Definition: test/csf/Peer.h:662
ripple::test::csf::TxSet
TxSet is a set of transactions to consider including in the ledger.
Definition: Tx.h:76
Json::Compact
Decorator for streaming out compact json.
Definition: json_writer.h:316
ripple::test::csf::Peer::connect
bool connect(Peer &o, SimDuration dur)
Create network connection.
Definition: test/csf/Peer.h:363
ripple::ConsensusProposal::getJson
Json::Value getJson() const
Get JSON representation for debugging.
Definition: ConsensusProposal.h:199
std::find
T find(T... args)
ripple::test::csf::Peer::key
PeerKey key
Current signing key.
Definition: test/csf/Peer.h:176
ripple::test::csf::Peer::onAccept
void onAccept(Result const &result, Ledger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson)
Definition: test/csf/Peer.h:533
ripple::test::csf::Peer::trusts
bool trusts(PeerID const &oId)
Definition: test/csf/Peer.h:345
ripple::test::csf::Peer::updateOperatingMode
void updateOperatingMode(std::size_t const positions) const
Definition: test/csf/Peer.h:869
ripple::Consensus
Generic implementation of consensus algorithm.
Definition: Consensus.h:284
ripple::test::csf::Scheduler
Simulated discrete-event scheduler.
Definition: test/csf/Scheduler.h:47
std::chrono::milliseconds
ripple::test::csf::Peer::ValAdaptor::Mutex
Definition: test/csf/Peer.h:121
ripple::test::csf::Validation::nodeID
PeerID const & nodeID() const
Definition: Validation.h:118
ripple::test::csf::Validation::setTrusted
void setTrusted()
Definition: Validation.h:183
ripple::test::csf::Validation::seq
Ledger::Seq seq() const
Definition: Validation.h:94
ripple::test::csf::FullyValidateLedger
Peer fully validated a new ledger.
Definition: events.h:137
ripple::test::csf::Peer::getPrevLedger
Ledger::ID getPrevLedger(Ledger::ID const &ledgerID, Ledger const &ledger, ConsensusMode mode)
Definition: test/csf/Peer.h:613
ripple::test::csf::Peer::Router
Definition: test/csf/Peer.h:731
ripple::test::csf::Ledger::txs
TxSetType const & txs() const
Definition: ledgers.h:209
ripple::ValStatus
ValStatus
Status of validation we received.
Definition: Validations.h:168
ripple::test::csf::Peer::Result
ConsensusResult< Peer > Result
Definition: test/csf/Peer.h:162
ripple::test::csf::TxSet::id
ID id() const
Definition: Tx.h:144
ripple::test::csf::Peer::sink
beast::WrappedSink sink
Logging support that prefixes messages with the peer ID.
Definition: test/csf/Peer.h:166
ripple::test::csf::Peer::txSets
bc::flat_map< TxSet::ID, TxSet > txSets
TxSet associated with a TxSet::ID.
Definition: test/csf/Peer.h:214
ripple::ConsensusResult::roundTime
ConsensusTimer roundTime
Definition: ConsensusTypes.h:233
ripple::test::csf::Ledger
A ledger is a set of observed transactions and a sequence number identifying the ledger.
Definition: ledgers.h:58
ripple::test::csf::Peer::lastClosedLedger
Ledger lastClosedLedger
The last ledger closed by this node.
Definition: test/csf/Peer.h:194
ripple::test::csf::Peer::ProcessingDelays
Simulated delays in internal peer processing.
Definition: test/csf/Peer.h:86
ripple::test::csf::Ledger::seq
Seq seq() const
Definition: ledgers.h:173
ripple::test::csf::Peer::start
void start()
Definition: test/csf/Peer.h:919
ripple::test::csf::Peer::share
void share(M const &m)
Definition: test/csf/Peer.h:654
ripple::test::csf::Peer::validations
Validations< ValAdaptor > validations
Validations from trusted nodes.
Definition: test/csf/Peer.h:200
ripple::ConsensusResult
Encapsulates the result of consensus.
Definition: ConsensusTypes.h:201
algorithm
ripple::test::csf::Peer::handle
bool handle(Tx const &tx)
Definition: test/csf/Peer.h:813
ripple::test::csf::Peer::handle
bool handle(Proposal const &p)
Definition: test/csf/Peer.h:783
ripple::test::csf::TxSet::txs
TxSetType const & txs() const
Definition: Tx.h:138
ripple::test::csf::Peer::acquireTxSet
TxSet const * acquireTxSet(TxSet::ID const &setId)
Definition: test/csf/Peer.h:433
ripple::test::csf::Peer::ProcessingDelays::recvValidation
std::chrono::milliseconds recvValidation
Delay in processing validations from remote peers.
Definition: test/csf/Peer.h:94
ripple::test::csf::Peer::disconnect
bool disconnect(Peer &o)
Remove a network connection.
Definition: test/csf/Peer.h:376
ripple::test::csf::Peer::trust
void trust(Peer &o)
Definition: test/csf/Peer.h:324
ripple::test::csf::Peer::untrust
void untrust(Peer &o)
Definition: test/csf/Peer.h:331
ripple::test::csf::Peer::earliestAllowedSeq
Ledger::Seq earliestAllowedSeq() const
Definition: test/csf/Peer.h:607
ripple::ConsensusProposal::prevLedger
LedgerID_t const & prevLedger() const
Get the prior accepted ledger this position is based on.
Definition: ConsensusProposal.h:107
ripple::test::csf::TxSet::ID
beast::uhash<>::result_type ID
Definition: Tx.h:79
ripple::test::csf::Peer::collectors
CollectorRefs & collectors
The collectors to report events to.
Definition: test/csf/Peer.h:251
ripple::test::csf::Peer::completedLedgers
int completedLedgers
The number of ledgers this peer has completed.
Definition: test/csf/Peer.h:221
ripple::test::csf::Peer::oracle
LedgerOracle & oracle
The oracle that manages unique ledgers.
Definition: test/csf/Peer.h:179
ripple::test::csf::Scheduler::in
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
ripple::test::csf::Peer::BroadcastMesg::mesg
M mesg
Definition: test/csf/Peer.h:726
ripple::test::csf::Peer::scheduler
Scheduler & scheduler
Scheduler of events.
Definition: test/csf/Peer.h:182
ripple::test::csf::Peer::handle
bool handle(Validation const &v)
Definition: test/csf/Peer.h:825
ripple::ConsensusTimer::read
std::chrono::milliseconds read() const
Definition: ConsensusTypes.h:142
ripple::test::csf::Peer::prevLedgerID
Ledger::ID prevLedgerID() const
Definition: test/csf/Peer.h:941
ripple::test::csf::Peer::fullyValidatedLedger
Ledger fullyValidatedLedger
The most recent ledger that has been fully validated by the network from the perspective of this Peer...
Definition: test/csf/Peer.h:204
ripple::test::csf::Peer::Position::Position
Position(Proposal const &p)
Definition: test/csf/Peer.h:64
ripple::test::csf::Peer::ValAdaptor::Mutex::lock
void lock()
Definition: test/csf/Peer.h:124
ripple::test::csf::Peer::acquireLedger
Ledger const * acquireLedger(Ledger::ID const &ledgerID)
Definition: test/csf/Peer.h:386
ripple::test::csf::Peer::BroadcastMesg::origin
PeerID origin
Definition: test/csf/Peer.h:728
ripple::test::csf::Peer::onForceAccept
void onForceAccept(Result const &result, Ledger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson)
Definition: test/csf/Peer.h:515
ripple::test::csf::Peer::laggards
std::size_t laggards(Ledger::Seq const seq, hash_set< NodeKey_t > &trusted)
Definition: test/csf/Peer.h:857
ripple::test::csf::LedgerOracle
Oracle maintaining unique ledgers for a simulation.
Definition: ledgers.h:244
ripple::test::csf::Peer::ValAdaptor::now
NetClock::time_point now() const
Definition: test/csf/Peer.h:142
ripple::test::csf::Peer::runAsValidator
bool runAsValidator
Whether to simulate running as validator or a tracking node.
Definition: test/csf/Peer.h:233
ripple::test::csf::CloseLedger
Peer closed the open ledger.
Definition: events.h:108
ripple::test::csf::PeerKey
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition: Validation.h:43
ripple::test::csf::Tx
A single transaction.
Definition: Tx.h:35
ripple::test::csf::Peer::getQuorumKeys
std::pair< std::size_t, hash_set< NodeKey_t > > getQuorumKeys()
Definition: test/csf/Peer.h:848
std::chrono::time_point
ripple::ValStatus::stale
@ stale
Not current or was older than current from this node.
ripple::test::csf::Peer::schedule
void schedule(std::chrono::nanoseconds when, T &&what)
Schedule the provided callback in when duration, but if when is 0, call immediately.
Definition: test/csf/Peer.h:298
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::test::csf::Peer::quorum
std::size_t quorum
Definition: test/csf/Peer.h:243
ripple::test::csf::Peer::id
PeerID id
Our unique ID.
Definition: test/csf/Peer.h:173
ripple::test::csf::Peer::parms
ConsensusParms const & parms() const
Definition: test/csf/Peer.h:641
std::remove_if
T remove_if(T... args)
ripple::test::csf::Peer::checkFullyValidated
void checkFullyValidated(Ledger const &ledger)
Check if a new ledger can be deemed fully validated.
Definition: test/csf/Peer.h:689
ripple::test::csf::Proposal
ConsensusProposal< PeerID, Ledger::ID, TxSet::ID > Proposal
Proposal is a position taken in the consensus process and is represented directly from the generic ty...
Definition: Proposal.h:33
ripple::test::csf::Relay
A value relayed to another peer as part of flooding.
Definition: events.h:67
ripple::test::csf::Peer::proposersValidated
std::size_t proposersValidated(Ledger::ID const &prevLedger)
Definition: test/csf/Peer.h:484
std::ceil
T ceil(T... args)
ripple::test::csf::Peer::send
void send(BroadcastMesg< M > const &bm, PeerID from)
Definition: test/csf/Peer.h:742
ripple::test::csf::Peer::acquiringTxSets
bc::flat_map< TxSet::ID, SimTime > acquiringTxSets
Definition: test/csf/Peer.h:218
ripple::test::csf::Peer::submit
void submit(Tx const &tx)
Definition: test/csf/Peer.h:876
ripple::test::csf::Peer::injectTxs
TxSet injectTxs(Ledger prevLedger, TxSet const &src)
Inject non-consensus Tx.
Definition: test/csf/Peer.h:965
std::min
T min(T... args)
ripple::test::csf::Receive
A value received from another peer as part of flooding.
Definition: events.h:79
ripple::test::csf::Peer
A single peer in the simulation.
Definition: test/csf/Peer.h:54
ripple::test::csf::Validation::NodeKey
PeerKey NodeKey
Definition: Validation.h:62
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:33
ripple::ConsensusProposal::nodeID
NodeID_t const & nodeID() const
Identifying which peer took this position.
Definition: ConsensusProposal.h:93
ripple::test::csf::Ledger::id
ID id() const
Definition: ledgers.h:167
ripple::test::csf::Peer::addTrustedValidation
bool addTrustedValidation(Validation v)
Add a trusted validation and return true if it is worth forwarding.
Definition: test/csf/Peer.h:672
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::csf::Peer::onModeChange
void onModeChange(ConsensusMode, ConsensusMode)
Definition: test/csf/Peer.h:647
ripple::test::csf::Peer::ProcessingDelays::ledgerAccept
std::chrono::milliseconds ledgerAccept
Delay in consensus calling doAccept to accepting and issuing validation TODO: This should be a functi...
Definition: test/csf/Peer.h:91
ripple::ConsensusMode
ConsensusMode
Represents how a node currently participates in Consensus.
Definition: ConsensusTypes.h:55
ripple::test::csf::WrongPrevLedger
Peer detected a wrong prior ledger during consensus.
Definition: events.h:128
ripple::test::csf::Peer::BroadcastMesg::seq
std::size_t seq
Definition: test/csf/Peer.h:727
ripple::ConsensusParms
Consensus algorithm parameters.
Definition: ConsensusParms.h:33
ripple::test::csf::Peer::j
beast::Journal j
Definition: test/csf/Peer.h:167
ripple::test::csf::Peer::openTxs
TxSetType openTxs
openTxs that haven't been closed in a ledger yet
Definition: test/csf/Peer.h:191
ripple::test::csf::Peer::ValAdaptor::ValAdaptor
ValAdaptor(Peer &p)
Definition: test/csf/Peer.h:137
ripple::test::csf::Peer::prevRoundTime
std::chrono::milliseconds prevRoundTime
Definition: test/csf/Peer.h:239
ripple::test::csf::Validation
Validation of a specific ledger by a specific Peer.
Definition: Validation.h:47
ripple::test::csf::Validation::setSeen
void setSeen(NetClock::time_point seen)
Definition: Validation.h:195
ripple::test::csf::Peer::peerPositions
bc::flat_map< Ledger::ID, std::vector< Proposal > > peerPositions
Map from Ledger::ID to vector of Positions with that ledger as the prior ledger.
Definition: test/csf/Peer.h:212
std::unordered_set::insert
T insert(T... args)
ripple::test::csf::Peer::timerEntry
void timerEntry()
Heartbeat timer call.
Definition: test/csf/Peer.h:888
ripple::test::csf::Peer::Position::proposal
Proposal const & proposal() const
Definition: test/csf/Peer.h:69
ripple::test::csf::Ledger::isAncestor
bool isAncestor(Ledger const &ancestor) const
Determine whether ancestor is really an ancestor of this ledger.
Definition: ledgers.cpp:40
ripple::ConsensusProposal< PeerID, Ledger::ID, TxSet::ID >::seqJoin
static const std::uint32_t seqJoin
Definition: ConsensusProposal.h:61
ripple::test::csf::Ledger::Seq
tagged_integer< std::uint32_t, SeqTag > Seq
Definition: ledgers.h:64
ripple::test::csf::Peer::ProcessingDelays::onReceive
SimDuration onReceive(Validation const &) const
Definition: test/csf/Peer.h:107
ripple::test::csf::Peer::ValAdaptor::acquire
std::optional< Ledger > acquire(Ledger::ID const &lId)
Definition: test/csf/Peer.h:148
ripple::test::csf::Peer::now
NetClock::time_point now() const
Definition: test/csf/Peer.h:928
beast::WrappedSink
Wraps a Journal::Sink to prefix its output with a string.
Definition: WrappedSink.h:33
ripple::test::csf::Peer::net
BasicNetwork< Peer * > & net
Handle to network for sending messages.
Definition: test/csf/Peer.h:185
ripple::test::csf::Validation::ledgerID
Ledger::ID ledgerID() const
Definition: Validation.h:88
ripple::test::csf::Peer::startRound
void startRound()
Definition: test/csf/Peer.h:898
ripple::test::csf::CollectorRefs
A container of CollectorRefs.
Definition: CollectorRef.h:323
ripple::test::csf::Peer::delays
ProcessingDelays delays
Simulated delays to use for internal processing.
Definition: test/csf/Peer.h:230
ripple::Validations
Maintains current and recent ledger validations.
Definition: Application.h:111
std::optional
ripple::test::csf::Peer::trustGraph
TrustGraph< Peer * > & trustGraph
Handle to Trust graph of network.
Definition: test/csf/Peer.h:188
ripple::test::csf::Share
A value to be flooded to all other peers starting from this peer.
Definition: events.h:58
std::size_t
ripple::test::csf::Peer::Router::nextSeq
std::size_t nextSeq
Definition: test/csf/Peer.h:733
ripple::test::csf::StartRound
Peer starts a new consensus round.
Definition: events.h:97
std::make_pair
T make_pair(T... args)
ripple::test::csf::Peer::receive
void receive(BroadcastMesg< M > const &bm, PeerID from)
Definition: test/csf/Peer.h:767
ripple::test::csf::Peer::targetLedgers
int targetLedgers
The number of ledgers this peer should complete before stopping to run.
Definition: test/csf/Peer.h:224
ripple::tagged_integer< std::uint32_t, IdTag >
ripple::test::csf::SimDuration
typename SimClock::duration SimDuration
Definition: SimTime.h:35
std::numeric_limits::max
T max(T... args)
ripple::test::csf::Peer::proposersFinished
std::size_t proposersFinished(Ledger const &prevLedger, Ledger::ID const &prevLedgerID)
Definition: test/csf/Peer.h:490
ripple::test::csf::CollectorRefs::on
void on(PeerID node, SimTime when, E const &e)
Definition: CollectorRef.h:337
ripple::test::csf::Scheduler::now
time_point now() const
Return the current network time.
Definition: test/csf/Scheduler.h:365
ripple::test::csf::Peer::hasOpenTransactions
bool hasOpenTransactions() const
Definition: test/csf/Peer.h:478
ripple::test::csf::Peer::ledgers
hash_map< Ledger::ID, Ledger > ledgers
Ledgers this node has closed or loaded from the network.
Definition: test/csf/Peer.h:197
ripple::test::csf::Peer::BroadcastMesg
Definition: test/csf/Peer.h:724
ripple::test::csf::SubmitTx
A transaction submitted to a peer.
Definition: events.h:89
ripple::test::csf::to_string
std::string to_string(TxSetType const &txs)
Definition: Tx.h:209
std::unordered_map
STL class.
ripple::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition: chrono.h:56
ripple::test::csf::BasicNetwork
Peer to peer network simulator.
Definition: BasicNetwork.h:83
ripple::test::csf::Peer::onClose
Result onClose(Ledger const &prevLedger, NetClock::time_point closeTime, ConsensusMode mode)
Definition: test/csf/Peer.h:496
ripple::ConsensusCloseTimes
Stores the set of initial close times.
Definition: ConsensusTypes.h:174
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::test::csf::Peer::ValAdaptor::Mutex::unlock
void unlock()
Definition: test/csf/Peer.h:129
ripple::ConsensusResult::proposers
std::size_t proposers
Definition: ConsensusTypes.h:240
ripple::test::csf::Peer::consensus
Consensus< Peer > consensus
Generic consensus.
Definition: test/csf/Peer.h:170
ripple::test::csf::Peer::Peer
Peer(PeerID i, Scheduler &s, LedgerOracle &o, BasicNetwork< Peer * > &n, TrustGraph< Peer * > &tg, CollectorRefs &c, beast::Journal jIn)
Constructor.
Definition: test/csf/Peer.h:264
ripple::test::csf::Peer::issue
void issue(E const &event)
Definition: test/csf/Peer.h:311
ripple::test::csf::Peer::Position
Basic wrapper of a proposed position taken by a peer.
Definition: test/csf/Peer.h:61
ripple::test::csf::Peer::consensusParms
ConsensusParms consensusParms
Definition: test/csf/Peer.h:248
ripple::ConsensusProposal< PeerID, Ledger::ID, TxSet::ID >
std::chrono