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