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 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 " << fi.required << "\n";
52 };
53
54 // set prior state
55 sim.run(1);
56
57 PeerGroup byzantineNodes = a + b + c + g;
58 // All peers see some TX 0
59 for (Peer* peer : network)
60 {
61 peer->submit(Tx{0});
62 // Peers 0,1,2,6 will close the next ledger differently by injecting
63 // a non-consensus approved transaction
64 if (byzantineNodes.contains(peer))
65 {
66 peer->txInjections.emplace(peer->lastClosedLedger.seq(), Tx{42});
67 }
68 }
69 sim.run(4);
70 std::cout << "Branches: " << sim.branches() << "\n";
71 std::cout << "Fully synchronized: " << std::boolalpha << sim.synchronized() << "\n";
72 // Not tessting anything currently.
73 pass();
74 }
75};
76
77BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, xrpl);
78
79} // namespace test
80} // namespace xrpl
T boolalpha(T... args)
A testsuite class.
Definition suite.h:52
void pass()
Record a successful test condition.
Definition suite.h:495
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.