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