rippled
Loading...
Searching...
No Matches
ScaleFreeSim_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2016 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
20#include <test/csf.h>
21#include <test/csf/random.h>
22
23#include <xrpl/beast/unit_test.h>
24
25#include <utility>
26
27namespace ripple {
28namespace test {
29
31{
32 void
33 run() override
34 {
35 using namespace std::chrono;
36 using namespace csf;
37
38 // Generate a quasi-random scale free network and simulate consensus
39 // as we vary transaction submission rates
40
41 int const N = 100; // Peers
42
43 int const numUNLs = 15; // UNL lists
44 int const minUNLSize = N / 4, maxUNLSize = N / 2;
45
46 ConsensusParms const parms{};
47 Sim sim;
48 PeerGroup network = sim.createGroup(N);
49
50 // generate trust ranks
51 std::vector<double> const ranks =
52 sample(network.size(), PowerLawDistribution{1, 3}, sim.rng);
53
54 // generate scale-free trust graph
55 randomRankedTrust(
56 network,
57 ranks,
58 numUNLs,
59 std::uniform_int_distribution<>{minUNLSize, maxUNLSize},
60 sim.rng);
61
62 // nodes with a trust line in either direction are network-connected
63 network.connectFromTrust(
64 round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
65
66 // Initialize collectors to track statistics to report
67 TxCollector txCollector;
68 LedgerCollector ledgerCollector;
69 auto colls = makeCollectors(txCollector, ledgerCollector);
70 sim.collectors.add(colls);
71
72 // Initial round to set prior state
73 sim.run(1);
74
75 // Initialize timers
76 HeartbeatTimer heart(sim.scheduler, seconds(10s));
77
78 // Run for 10 minues, submitting 100 tx/second
79 std::chrono::nanoseconds const simDuration = 10min;
80 std::chrono::nanoseconds const quiet = 10s;
81 Rate const rate{100, 1000ms};
82
83 // txs, start/stop/step, target
84 auto peerSelector =
85 makeSelector(network.begin(), network.end(), ranks, sim.rng);
86 auto txSubmitter = makeSubmitter(
87 ConstantDistribution{rate.inv()},
88 sim.scheduler.now() + quiet,
89 sim.scheduler.now() + (simDuration - quiet),
90 peerSelector,
91 sim.scheduler,
92 sim.rng);
93
94 // run simulation for given duration
95 heart.start();
96 sim.run(simDuration);
97
98 BEAST_EXPECT(sim.branches() == 1);
99 BEAST_EXPECT(sim.synchronized());
100
101 // TODO: Clean up this formatting mess!!
102
103 log << "Peers: " << network.size() << std::endl;
104 log << "Simulated Duration: "
105 << duration_cast<milliseconds>(simDuration).count() << " ms"
106 << std::endl;
107 log << "Branches: " << sim.branches() << std::endl;
108 log << "Synchronized: " << (sim.synchronized() ? "Y" : "N")
109 << std::endl;
110 log << std::endl;
111
112 txCollector.report(simDuration, log);
113 ledgerCollector.report(simDuration, log);
114 // Print summary?
115 // # forks? # of LCLs?
116 // # peers
117 // # tx submitted
118 // # ledgers/sec etc.?
119 }
120};
121
122BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(ScaleFreeSim, consensus, ripple, 80);
123
124} // namespace test
125} // namespace ripple
A testsuite class.
Definition suite.h:55
log_os< char > log
Logging output stream.
Definition suite.h:152
void run() override
Runs the suite.
T endl(T... args)
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
Definition rate.cpp:32
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Consensus algorithm parameters.
Represents a transfer rate.
Definition Rate.h:40