xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
consensus
ByzantineFailureSim.cpp
1
#include <xrpl/consensus/ConsensusParms.h>
2
3
#include <csf/Peer.h>
4
#include <csf/PeerGroup.h>
5
#include <csf/Sim.h>
6
#include <csf/SimTime.h>
7
#include <csf/TrustGraph.h>
8
#include <csf/collectors.h>
9
#include <gtest/gtest.h>
10
11
#include <
chrono
>
12
#include <
ios
>
13
#include <
iostream
>
14
15
namespace
xrpl::test
{
16
17
TEST
(ByzantineFailureSimTest, DISABLED_byzantine_failure_sim)
18
{
19
using namespace
csf
;
20
using namespace
std::chrono
;
21
22
// This test simulates a specific topology with nodes generating
23
// different ledgers due to a simulated byzantine failure (injecting
24
// an extra non-consensus transaction).
25
26
Sim sim;
27
ConsensusParms
const
parms{};
28
29
SimDuration
const
delay =
round<milliseconds>
(0.2 * parms.
ledgerGRANULARITY
);
30
PeerGroup a = sim.createGroup(1);
31
PeerGroup b = sim.createGroup(1);
32
PeerGroup c = sim.createGroup(1);
33
PeerGroup d = sim.createGroup(1);
34
PeerGroup e = sim.createGroup(1);
35
PeerGroup f = sim.createGroup(1);
36
PeerGroup g = sim.createGroup(1);
37
38
a.trustAndConnect(a + b + c + g, delay);
39
b.trustAndConnect(b + a + c + d + e, delay);
40
c.trustAndConnect(c + a + b + d + e, delay);
41
d.trustAndConnect(d + b + c + e + f, delay);
42
e.trustAndConnect(e + b + c + d + f, delay);
43
f.trustAndConnect(f + d + e + g, delay);
44
g.trustAndConnect(g + a + f, delay);
45
46
PeerGroup
const
network = a + b + c + d + e + f + g;
47
48
StreamCollector sc{
std::cout
};
49
50
sim.collectors.add(sc);
51
52
for
(TrustGraph<Peer*>::ForkInfo
const
& fi : sim.trustGraph.forkablePairs(0.8))
53
{
54
std::cout
<<
"Can fork "
<< PeerGroup{fi.unlA} <<
" "
55
<<
" "
<< PeerGroup{fi.unlB} <<
" overlap "
<< fi.overlap <<
" required "
56
<< fi.required <<
"\n"
;
57
};
58
59
// set prior state
60
sim.run(1);
61
62
PeerGroup byzantineNodes = a + b + c + g;
63
// All peers see some TX 0
64
for
(Peer* peer : network)
65
{
66
peer->submit(Tx{0});
67
// Peers 0,1,2,6 will close the next ledger differently by injecting
68
// a non-consensus approved transaction
69
if
(byzantineNodes.contains(peer))
70
{
71
peer->txInjections.emplace(peer->lastClosedLedger.seq(), Tx{42});
72
}
73
}
74
sim.run(4);
75
std::cout
<<
"Branches: "
<< sim.branches() <<
"\n"
;
76
std::cout
<<
"Fully synchronized: "
<<
std::boolalpha
<< sim.synchronized() <<
"\n"
;
77
// Not tessting anything currently.
78
SUCCEED();
79
}
80
81
}
// namespace xrpl::test
std::boolalpha
T boolalpha(T... args)
chrono
std::cout
ios
iostream
std::chrono
xrpl::test::csf
Definition
Validations.cpp:23
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::TEST
TEST(UnitsTest, types)
Definition
Units.cpp:16
std::round
T round(T... args)
xrpl::ConsensusParms
Consensus algorithm parameters.
Definition
ConsensusParms.h:20
xrpl::ConsensusParms::ledgerGRANULARITY
std::chrono::milliseconds const ledgerGRANULARITY
How often we check state or change positions.
Definition
ConsensusParms.h:98
Generated by
1.17.0