xrpld
Loading...
Searching...
No Matches
ScaleFreeSim.cpp
1#include <xrpl/consensus/ConsensusParms.h>
2
3#include <csf/PeerGroup.h>
4#include <csf/Sim.h>
5#include <csf/collectors.h>
6#include <csf/random.h>
7#include <csf/submitters.h>
8#include <csf/timers.h>
9#include <gtest/gtest.h>
10
11#include <chrono>
12#include <iostream>
13#include <ostream>
14#include <random>
15#include <vector>
16
17namespace xrpl::test {
18
19TEST(ScaleFreeSimTest, DISABLED_scale_free_sim)
20{
21 using namespace std::chrono;
22 using namespace csf;
23
25
26 // Generate a quasi-random scale free network and simulate consensus
27 // as we vary transaction submission rates
28
29 int const n = 100; // Peers
30
31 int const numUNLs = 15; // UNL lists
32 int const minUNLSize = n / 4, maxUNLSize = n / 2;
33
34 ConsensusParms const parms{};
35 Sim sim;
36 PeerGroup network = sim.createGroup(n);
37
38 // generate trust ranks
39 std::vector<double> const ranks = sample(network.size(), PowerLawDistribution{1, 3}, sim.rng);
40
41 // generate scale-free trust graph
42 randomRankedTrust(
43 network, ranks, numUNLs, std::uniform_int_distribution<>{minUNLSize, maxUNLSize}, sim.rng);
44
45 // nodes with a trust line in either direction are network-connected
46 network.connectFromTrust(round<milliseconds>(0.2 * parms.ledgerGRANULARITY));
47
48 // Initialize collectors to track statistics to report
49 TxCollector txCollector;
50 LedgerCollector ledgerCollector;
51 auto colls = makeCollectors(txCollector, ledgerCollector);
52 sim.collectors.add(colls);
53
54 // Initial round to set prior state
55 sim.run(1);
56
57 // Initialize timers
58 HeartbeatTimer heart(sim.scheduler, seconds(10s));
59
60 // Run for 10 minutes, submitting 100 tx/second
61 std::chrono::nanoseconds const simDuration = 10min;
62 std::chrono::nanoseconds const quiet = 10s;
63 Rate const rate{.count = 100, .duration = 1000ms};
64
65 // txs, start/stop/step, target
66 auto peerSelector = makeSelector(network.begin(), network.end(), ranks, sim.rng);
67 auto txSubmitter = makeSubmitter(
68 ConstantDistribution{rate.inv()},
69 sim.scheduler.now() + quiet,
70 sim.scheduler.now() + (simDuration - quiet),
71 peerSelector,
72 sim.scheduler,
73 sim.rng);
74
75 // run simulation for given duration
76 heart.start();
77 sim.run(simDuration);
78
79 EXPECT_TRUE(sim.branches() == 1);
80 EXPECT_TRUE(sim.synchronized());
81
82 // TODO: Clean up this formatting mess!!
83
84 log << "Peers: " << network.size() << std::endl;
85 log << "Simulated Duration: " << duration_cast<milliseconds>(simDuration).count() << " ms"
86 << std::endl;
87 log << "Branches: " << sim.branches() << std::endl;
88 log << "Synchronized: " << (sim.synchronized() ? "Y" : "N") << std::endl;
89 log << std::endl;
90
91 txCollector.report(simDuration, log);
92 ledgerCollector.report(simDuration, log);
93 // Print summary?
94 // # forks? # of LCLs?
95 // # peers
96 // # tx submitted
97 // # ledgers/sec etc.?
98}
99
100} // namespace xrpl::test
T duration_cast(T... args)
T endl(T... args)
T log(T... args)
T min(T... args)
json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
Definition rate.cpp:15
TEST(UnitsTest, types)
Definition Units.cpp:16
T round(T... args)
T sample(T... args)
Consensus algorithm parameters.
std::chrono::milliseconds const ledgerGRANULARITY
How often we check state or change positions.
Represents a transfer rate.
Definition Rate.h:21