xrpld
Loading...
Searching...
No Matches
Sim.cpp
1#include <test/csf/Sim.h>
2
3#include <test/csf/PeerGroup.h>
4#include <test/csf/SimTime.h>
5
6#include <algorithm>
7#include <cstddef>
8#include <limits>
9#include <set>
10
11namespace xrpl::test::csf {
12
13void
14Sim::run(int ledgers)
15{
16 for (auto& p : peers_)
17 {
18 p.targetLedgers = p.completedLedgers + ledgers;
19 p.start();
20 }
21 scheduler.step();
22}
23
24void
26{
27 for (auto& p : peers_)
28 {
29 p.targetLedgers = std::numeric_limits<decltype(p.targetLedgers)>::max();
30 p.start();
31 }
32 scheduler.stepFor(dur);
33}
34
35bool
37{
38 return synchronized(allPeers_);
39}
40
41bool
43{
44 if (g.size() < 1)
45 return true;
46 Peer const* ref = g[0];
47 return std::ranges::all_of(g, [&ref](Peer const* p) {
48 return p->lastClosedLedger.id() == ref->lastClosedLedger.id() &&
49 p->fullyValidatedLedger.id() == ref->fullyValidatedLedger.id();
50 });
51}
52
55{
56 return branches(allPeers_);
57}
59Sim::branches(PeerGroup const& g) const
60{
61 if (g.size() < 1)
62 return 0;
63 std::set<Ledger> ledgers;
64 for (auto const& peer : g)
65 ledgers.insert(peer->fullyValidatedLedger);
66
67 return oracle.branches(ledgers);
68}
69
70} // namespace xrpl::test::csf
T all_of(T... args)
A group of simulation Peers.
Definition PeerGroup.h:20
std::size_t size() const
Definition PeerGroup.h:91
std::deque< Peer > peers_
Definition Sim.h:49
LedgerOracle oracle
Definition Sim.h:57
void run(int ledgers)
Run consensus protocol to generate the provided number of ledgers.
Definition Sim.cpp:14
bool synchronized() const
Check whether all peers in the network are synchronized.
Definition Sim.cpp:36
std::size_t branches() const
Calculate the number of branches in the network.
Definition Sim.cpp:54
Scheduler scheduler
Definition Sim.h:54
PeerGroup allPeers_
Definition Sim.h:50
T insert(T... args)
SimClock::duration SimDuration
Definition SimTime.h:14
A single peer in the simulation.
Ledger lastClosedLedger
The last ledger closed by this node.