rippled
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 <ripple/beast/clock/manual_clock.h>
20 #include <ripple/beast/unit_test.h>
21 #include <test/csf.h>
22 #include <utility>
23 
24 namespace ripple {
25 namespace test {
26 
27 class ByzantineFailureSim_test : public beast::unit_test::suite
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  date::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}
71  << " overlap " << fi.overlap << " required "
72  << fi.required << "\n";
73  };
74 
75  // set prior state
76  sim.run(1);
77 
78  PeerGroup byzantineNodes = a + b + c + g;
79  // All peers see some TX 0
80  for (Peer * peer : network)
81  {
82  peer->submit(Tx(0));
83  // Peers 0,1,2,6 will close the next ledger differently by injecting
84  // a non-consensus approved transaciton
85  if (byzantineNodes.contains(peer))
86  {
87  peer->txInjections.emplace(
88  peer->lastClosedLedger.seq(), Tx{42});
89  }
90  }
91  sim.run(4);
92  std::cout << "Branches: " << sim.branches() << "\n";
93  std::cout << "Fully synchronized: " << std::boolalpha
94  << sim.synchronized() << "\n";
95  // Not tessting anything currently.
96  pass();
97  }
98 };
99 
100 BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, ripple);
101 
102 } // namespace test
103 } // namespace ripple
utility
ripple::test::ByzantineFailureSim_test
Definition: ByzantineFailureSim_test.cpp:27
ripple::test::ByzantineFailureSim_test::run
void run() override
Definition: ByzantineFailureSim_test.cpp:30
std::cout
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ConsensusParms
Consensus algorithm parameters.
Definition: ConsensusParms.h:33
std::boolalpha
T boolalpha(T... args)
ripple::test::BEAST_DEFINE_TESTSUITE_MANUAL
BEAST_DEFINE_TESTSUITE_MANUAL(DetectCrash, unit_test, beast)
ripple::Peer
Represents a peer connection in the overlay.
Definition: ripple/overlay/Peer.h:43
std::chrono