xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
csf
impl
Sim.cpp
1
#include <csf/Sim.h>
2
3
#include <csf/PeerGroup.h>
4
#include <csf/SimTime.h>
5
6
#include <
algorithm
>
7
#include <
cstddef
>
8
#include <
limits
>
9
#include <
set
>
10
11
namespace
xrpl::test::csf
{
12
13
void
14
Sim::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
24
void
25
Sim::run
(
SimDuration
const
& dur)
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
35
bool
36
Sim::synchronized
()
const
37
{
38
return
synchronized
(
allPeers_
);
39
}
40
41
bool
42
Sim::synchronized
(
PeerGroup
const
& g)
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
53
std::size_t
54
Sim::branches
()
const
55
{
56
return
branches
(
allPeers_
);
57
}
58
std::size_t
59
Sim::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
algorithm
std::ranges::all_of
T all_of(T... args)
xrpl::test::csf::Ledger::id
ID id() const
Definition
ledgers.h:166
xrpl::test::csf::PeerGroup
A group of simulation Peers.
Definition
PeerGroup.h:30
xrpl::test::csf::PeerGroup::size
std::size_t size() const
Definition
PeerGroup.h:101
xrpl::test::csf::Sim::peers_
std::deque< Peer > peers_
Definition
Sim.h:57
xrpl::test::csf::Sim::oracle
LedgerOracle oracle
Definition
Sim.h:65
xrpl::test::csf::Sim::run
void run(int ledgers)
Run consensus protocol to generate the provided number of ledgers.
Definition
Sim.cpp:14
xrpl::test::csf::Sim::synchronized
bool synchronized() const
Check whether all peers in the network are synchronized.
Definition
Sim.cpp:36
xrpl::test::csf::Sim::branches
std::size_t branches() const
Calculate the number of branches in the network.
Definition
Sim.cpp:54
xrpl::test::csf::Sim::scheduler
Scheduler scheduler
Definition
Sim.h:62
xrpl::test::csf::Sim::allPeers_
PeerGroup allPeers_
Definition
Sim.h:58
cstddef
std::set::insert
T insert(T... args)
limits
xrpl::test::csf
Definition
Validations.cpp:23
xrpl::test::csf::SimDuration
SimClock::duration SimDuration
Definition
SimTime.h:14
std::numeric_limits
set
std::size_t
xrpl::test::csf::Peer
A single peer in the simulation.
Definition
tests/libxrpl/csf/Peer.h:57
xrpl::test::csf::Peer::lastClosedLedger
Ledger lastClosedLedger
The last ledger closed by this node.
Definition
tests/libxrpl/csf/Peer.h:235
xrpl::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
tests/libxrpl/csf/Peer.h:251
Generated by
1.17.0