rippled
Loading...
Searching...
No Matches
Sim.cpp
1#include <test/csf/Sim.h>
2
3namespace ripple {
4namespace test {
5namespace csf {
6
7void
8Sim::run(int ledgers)
9{
10 for (auto& p : peers)
11 {
12 p.targetLedgers = p.completedLedgers + ledgers;
13 p.start();
14 }
16}
17
18void
20{
21 for (auto& p : peers)
22 {
23 p.targetLedgers = std::numeric_limits<decltype(p.targetLedgers)>::max();
24 p.start();
25 }
27}
28
29bool
31{
32 return synchronized(allPeers);
33}
34
35bool
37{
38 if (g.size() < 1)
39 return true;
40 Peer const* ref = g[0];
41 return std::all_of(g.begin(), g.end(), [&ref](Peer const* p) {
42 return p->lastClosedLedger.id() == ref->lastClosedLedger.id() &&
43 p->fullyValidatedLedger.id() == ref->fullyValidatedLedger.id();
44 });
45}
46
49{
50 return branches(allPeers);
51}
53Sim::branches(PeerGroup const& g) const
54{
55 if (g.size() < 1)
56 return 0;
57 std::set<Ledger> ledgers;
58 for (auto const& peer : g)
59 ledgers.insert(peer->fullyValidatedLedger);
60
61 return oracle.branches(ledgers);
62}
63
64} // namespace csf
65} // namespace test
66} // namespace ripple
T all_of(T... args)
std::size_t branches(std::set< Ledger > const &ledgers) const
Determine the number of distinct branches for the set of ledgers.
Definition ledgers.cpp:121
A group of simulation Peers.
Definition PeerGroup.h:23
std::size_t size() const
Definition PeerGroup.h:95
bool step_for(std::chrono::duration< Period, Rep > const &amount)
Run the scheduler until time has elapsed.
bool step()
Run the scheduler until no events remain.
PeerGroup allPeers
Definition Sim.h:56
LedgerOracle oracle
Definition Sim.h:63
Scheduler scheduler
Definition Sim.h:60
std::size_t branches() const
Calculate the number of branches in the network.
Definition Sim.cpp:48
void run(int ledgers)
Run consensus protocol to generate the provided number of ledgers.
Definition Sim.cpp:8
std::deque< Peer > peers
Definition Sim.h:55
bool synchronized() const
Check whether all peers in the network are synchronized.
Definition Sim.cpp:30
T insert(T... args)
typename SimClock::duration SimDuration
Definition SimTime.h:17
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
A single peer in the simulation.