forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInferredQuorumUtils.cpp
95 lines (88 loc) · 2.59 KB
/
InferredQuorumUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2018 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "herder/Herder.h"
#include "herder/QuorumIntersectionChecker.h"
#include "history/HistoryManager.h"
#include "main/Application.h"
#include "main/Config.h"
#include "util/Logging.h"
#include "util/XDROperators.h"
#include "xdr/Stellar-SCP.h"
#include "xdr/Stellar-types.h"
#include <algorithm>
#include <set>
namespace stellar
{
static stellar::QuorumTracker::QuorumMap
getQuorumMapForLedger(Application::pointer app, uint32_t ledgerNum)
{
if (ledgerNum == 0)
{
return app->getHerder().getCurrentlyTrackedQuorum();
}
else
{
return app->getHistoryManager().inferQuorum(ledgerNum).getQuorumMap();
}
}
void
checkQuorumIntersection(Config const& cfg, uint32_t ledgerNum)
{
VirtualClock clock;
Config cfg2(cfg);
cfg2.setNoListen();
Application::pointer app = Application::create(clock, cfg2, false);
LOG(INFO) << "Checking last-heard quorum from herder";
app->start();
auto qmap = getQuorumMapForLedger(app, ledgerNum);
auto qic = QuorumIntersectionChecker::create(qmap, cfg);
qic->networkEnjoysQuorumIntersection();
}
void
inferQuorumAndWrite(Config const& cfg, uint32_t ledgerNum)
{
Config cfg2(cfg);
InferredQuorum iq;
{
VirtualClock clock;
cfg2.setNoListen();
Application::pointer app = Application::create(clock, cfg2, false);
auto qmap = getQuorumMapForLedger(app, ledgerNum);
iq = InferredQuorum(qmap);
}
LOG(INFO) << "Inferred quorum";
std::cout << iq.toString(cfg2) << std::endl;
}
void
writeQuorumGraph(Config const& cfg, std::string const& outputFile,
uint32_t ledgerNum)
{
Config cfg2(cfg);
InferredQuorum iq;
{
VirtualClock clock;
cfg2.setNoListen();
Application::pointer app = Application::create(clock, cfg2, false);
auto qmap = getQuorumMapForLedger(app, ledgerNum);
iq = InferredQuorum(qmap);
}
std::string filename = outputFile.empty() ? "-" : outputFile;
if (filename == "-")
{
std::stringstream out;
iq.writeQuorumGraph(cfg2, out);
LOG(INFO) << "*";
LOG(INFO) << "* Quorum graph: " << out.str();
LOG(INFO) << "*";
}
else
{
std::ofstream out(filename);
iq.writeQuorumGraph(cfg2, out);
LOG(INFO) << "*";
LOG(INFO) << "* Wrote quorum graph to " << filename;
LOG(INFO) << "*";
}
}
}