rippled
Loading...
Searching...
No Matches
ByzantineFailureSim_test.cpp
1#include <test/csf.h>
2
3#include <xrpl/beast/unit_test.h>
4
5#include <utility>
6
7namespace xrpl {
8namespace test {
9
11{
12 void
13 run() override
14 {
15 using namespace csf;
16 using namespace std::chrono;
17
18 // This test simulates a specific topology with nodes generating
19 // different ledgers due to a simulated byzantine failure (injecting
20 // an extra non-consensus transaction).
21
22 Sim sim;
23 ConsensusParms const parms{};
24
25 SimDuration const delay = round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
26 PeerGroup a = sim.createGroup(1);
27 PeerGroup b = sim.createGroup(1);
28 PeerGroup c = sim.createGroup(1);
29 PeerGroup d = sim.createGroup(1);
30 PeerGroup e = sim.createGroup(1);
31 PeerGroup f = sim.createGroup(1);
32 PeerGroup g = sim.createGroup(1);
33
34 a.trustAndConnect(a + b + c + g, delay);
35 b.trustAndConnect(b + a + c + d + e, delay);
36 c.trustAndConnect(c + a + b + d + e, delay);
37 d.trustAndConnect(d + b + c + e + f, delay);
38 e.trustAndConnect(e + b + c + d + f, delay);
39 f.trustAndConnect(f + d + e + g, delay);
40 g.trustAndConnect(g + a + f, delay);
41
42 PeerGroup const network = a + b + c + d + e + f + g;
43
44 StreamCollector sc{std::cout};
45
46 sim.collectors.add(sc);
47
48 for (TrustGraph<Peer*>::ForkInfo const& fi : sim.trustGraph.forkablePairs(0.8))
49 {
50 std::cout << "Can fork " << PeerGroup{fi.unlA} << " "
51 << " " << PeerGroup{fi.unlB} << " overlap " << fi.overlap << " required "
52 << fi.required << "\n";
53 };
54
55 // set prior state
56 sim.run(1);
57
58 PeerGroup byzantineNodes = a + b + c + g;
59 // All peers see some TX 0
60 for (Peer* peer : network)
61 {
62 peer->submit(Tx{0});
63 // Peers 0,1,2,6 will close the next ledger differently by injecting
64 // a non-consensus approved transaction
65 if (byzantineNodes.contains(peer))
66 {
67 peer->txInjections.emplace(peer->lastClosedLedger.seq(), Tx{42});
68 }
69 }
70 sim.run(4);
71 std::cout << "Branches: " << sim.branches() << "\n";
72 std::cout << "Fully synchronized: " << std::boolalpha << sim.synchronized() << "\n";
73 // Not tessting anything currently.
74 pass();
75 }
76};
77
78BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, xrpl);
79
80} // namespace test
81} // namespace xrpl
T boolalpha(T... args)
A testsuite class.
Definition suite.h:51
void pass()
Record a successful test condition.
Definition suite.h:497
Represents a peer connection in the overlay.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Consensus algorithm parameters.