rippled
Loading...
Searching...
No Matches
Sim.cpp
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#include <test/csf/Sim.h>
20
21namespace ripple {
22namespace test {
23namespace csf {
24
25void
26Sim::run(int ledgers)
27{
28 for (auto& p : peers)
29 {
30 p.targetLedgers = p.completedLedgers + ledgers;
31 p.start();
32 }
34}
35
36void
38{
39 for (auto& p : peers)
40 {
41 p.targetLedgers = std::numeric_limits<decltype(p.targetLedgers)>::max();
42 p.start();
43 }
45}
46
47bool
49{
50 return synchronized(allPeers);
51}
52
53bool
55{
56 if (g.size() < 1)
57 return true;
58 Peer const* ref = g[0];
59 return std::all_of(g.begin(), g.end(), [&ref](Peer const* p) {
60 return p->lastClosedLedger.id() == ref->lastClosedLedger.id() &&
61 p->fullyValidatedLedger.id() == ref->fullyValidatedLedger.id();
62 });
63}
64
67{
68 return branches(allPeers);
69}
71Sim::branches(PeerGroup const& g) const
72{
73 if (g.size() < 1)
74 return 0;
75 std::set<Ledger> ledgers;
76 for (auto const& peer : g)
77 ledgers.insert(peer->fullyValidatedLedger);
78
79 return oracle.branches(ledgers);
80}
81
82} // namespace csf
83} // namespace test
84} // 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:140
A group of simulation Peers.
Definition: PeerGroup.h:40
std::size_t size() const
Definition: PeerGroup.h:112
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:75
LedgerOracle oracle
Definition: Sim.h:82
Scheduler scheduler
Definition: Sim.h:79
std::size_t branches() const
Calculate the number of branches in the network.
Definition: Sim.cpp:66
void run(int ledgers)
Run consensus protocol to generate the provided number of ledgers.
Definition: Sim.cpp:26
std::deque< Peer > peers
Definition: Sim.h:74
bool synchronized() const
Check whether all peers in the network are synchronized.
Definition: Sim.cpp:48
T insert(T... args)
typename SimClock::duration SimDuration
Definition: SimTime.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
A single peer in the simulation.
Definition: test/csf/Peer.h:55