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 ripple {
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 =
26 round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
27 PeerGroup a = sim.createGroup(1);
28 PeerGroup b = sim.createGroup(1);
29 PeerGroup c = sim.createGroup(1);
30 PeerGroup d = sim.createGroup(1);
31 PeerGroup e = sim.createGroup(1);
32 PeerGroup f = sim.createGroup(1);
33 PeerGroup g = sim.createGroup(1);
34
35 a.trustAndConnect(a + b + c + g, delay);
36 b.trustAndConnect(b + a + c + d + e, delay);
37 c.trustAndConnect(c + a + b + d + e, delay);
38 d.trustAndConnect(d + b + c + e + f, delay);
39 e.trustAndConnect(e + b + c + d + f, delay);
40 f.trustAndConnect(f + d + e + g, delay);
41 g.trustAndConnect(g + a + f, delay);
42
43 PeerGroup network = a + b + c + d + e + f + g;
44
45 StreamCollector sc{std::cout};
46
47 sim.collectors.add(sc);
48
49 for (TrustGraph<Peer*>::ForkInfo const& fi :
50 sim.trustGraph.forkablePairs(0.8))
51 {
52 std::cout << "Can fork " << PeerGroup{fi.unlA} << " "
53 << " " << PeerGroup{fi.unlB} << " overlap " << fi.overlap
54 << " required " << fi.required << "\n";
55 };
56
57 // set prior state
58 sim.run(1);
59
60 PeerGroup byzantineNodes = a + b + c + g;
61 // All peers see some TX 0
62 for (Peer* peer : network)
63 {
64 peer->submit(Tx{0});
65 // Peers 0,1,2,6 will close the next ledger differently by injecting
66 // a non-consensus approved transaciton
67 if (byzantineNodes.contains(peer))
68 {
69 peer->txInjections.emplace(
70 peer->lastClosedLedger.seq(), Tx{42});
71 }
72 }
73 sim.run(4);
74 std::cout << "Branches: " << sim.branches() << "\n";
75 std::cout << "Fully synchronized: " << std::boolalpha
76 << sim.synchronized() << "\n";
77 // Not tessting anything currently.
78 pass();
79 }
80};
81
82BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, ripple);
83
84} // namespace test
85} // namespace ripple
T boolalpha(T... args)
A testsuite class.
Definition suite.h:52
void pass()
Record a successful test condition.
Definition suite.h:508
Represents a peer connection in the overlay.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Consensus algorithm parameters.