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  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 
99 BEAST_DEFINE_TESTSUITE_MANUAL(ByzantineFailureSim, consensus, ripple);
100 
101 } // namespace test
102 } // 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(LedgerReplayerLong, app, ripple)
ripple::Peer
Represents a peer connection in the overlay.
Definition: ripple/overlay/Peer.h:45
std::chrono