rippled
Loading...
Searching...
No Matches
ByzantineFailureSim_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/csf.h>
21
22#include <xrpl/beast/unit_test.h>
23
24#include <utility>
25
26namespace ripple {
27namespace test {
28
30{
31 void
32 run() override
33 {
34 using namespace csf;
35 using namespace std::chrono;
36
37 // This test simulates a specific topology with nodes generating
38 // different ledgers due to a simulated byzantine failure (injecting
39 // an extra non-consensus transaction).
40
41 Sim sim;
42 ConsensusParms const parms{};
43
44 SimDuration const delay =
45 round<milliseconds>(0.2 * parms.ledgerGRANULARITY);
46 PeerGroup a = sim.createGroup(1);
47 PeerGroup b = sim.createGroup(1);
48 PeerGroup c = sim.createGroup(1);
49 PeerGroup d = sim.createGroup(1);
50 PeerGroup e = sim.createGroup(1);
51 PeerGroup f = sim.createGroup(1);
52 PeerGroup g = sim.createGroup(1);
53
54 a.trustAndConnect(a + b + c + g, delay);
55 b.trustAndConnect(b + a + c + d + e, delay);
56 c.trustAndConnect(c + a + b + d + e, delay);
57 d.trustAndConnect(d + b + c + e + f, delay);
58 e.trustAndConnect(e + b + c + d + f, delay);
59 f.trustAndConnect(f + d + e + g, delay);
60 g.trustAndConnect(g + a + f, delay);
61
62 PeerGroup network = a + b + c + d + e + f + g;
63
64 StreamCollector sc{std::cout};
65
66 sim.collectors.add(sc);
67
68 for (TrustGraph<Peer*>::ForkInfo const& fi :
69 sim.trustGraph.forkablePairs(0.8))
70 {
71 std::cout << "Can fork " << PeerGroup{fi.unlA} << " "
72 << " " << PeerGroup{fi.unlB} << " overlap " << fi.overlap
73 << " required " << fi.required << "\n";
74 };
75
76 // set prior state
77 sim.run(1);
78
79 PeerGroup byzantineNodes = a + b + c + g;
80 // All peers see some TX 0
81 for (Peer* peer : network)
82 {
83 peer->submit(Tx{0});
84 // Peers 0,1,2,6 will close the next ledger differently by injecting
85 // a non-consensus approved transaciton
86 if (byzantineNodes.contains(peer))
87 {
88 peer->txInjections.emplace(
89 peer->lastClosedLedger.seq(), Tx{42});
90 }
91 }
92 sim.run(4);
93 std::cout << "Branches: " << sim.branches() << "\n";
94 std::cout << "Fully synchronized: " << std::boolalpha
95 << sim.synchronized() << "\n";
96 // Not tessting anything currently.
97 pass();
98 }
99};
100
101BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, ripple);
102
103} // namespace test
104} // namespace ripple
T boolalpha(T... args)
A testsuite class.
Definition suite.h:55
void pass()
Record a successful test condition.
Definition suite.h:511
Represents a peer connection in the overlay.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Consensus algorithm parameters.