Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

quorums_debug.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <llmq/quorums_debug.h>
6 
7 #include <chainparams.h>
8 #include <validation.h>
9 
10 #include <evo/deterministicmns.h>
11 #include <llmq/quorums_utils.h>
12 
13 namespace llmq
14 {
16 
18 {
20 
21  if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)llmqType) || quorumHash.IsNull()) {
22  return ret;
23  }
24 
25  std::vector<CDeterministicMNCPtr> dmnMembers;
26  if (detailLevel == 2) {
27  const CBlockIndex* pindex = nullptr;
28  {
29  LOCK(cs_main);
30  auto it = mapBlockIndex.find(quorumHash);
31  if (it != mapBlockIndex.end()) {
32  pindex = it->second;
33  }
34  }
35  if (pindex != nullptr) {
37  }
38  }
39 
40  ret.push_back(Pair("llmqType", llmqType));
41  ret.push_back(Pair("quorumHash", quorumHash.ToString()));
42  ret.push_back(Pair("quorumHeight", (int)quorumHeight));
43  ret.push_back(Pair("phase", (int)phase));
44 
45  ret.push_back(Pair("sentContributions", sentContributions));
46  ret.push_back(Pair("sentComplaint", sentComplaint));
47  ret.push_back(Pair("sentJustification", sentJustification));
48  ret.push_back(Pair("sentPrematureCommitment", sentPrematureCommitment));
49  ret.push_back(Pair("aborted", aborted));
50 
51  struct ArrOrCount {
52  int count{0};
54  };
55 
56  ArrOrCount badMembers;
57  ArrOrCount weComplain;
58  ArrOrCount receivedContributions;
59  ArrOrCount receivedComplaints;
60  ArrOrCount receivedJustifications;
61  ArrOrCount receivedPrematureCommitments;
62  ArrOrCount complaintsFromMembers;
63 
64  auto add = [&](ArrOrCount& v, size_t idx, bool flag) {
65  if (flag) {
66  if (detailLevel == 0) {
67  v.count++;
68  } else if (detailLevel == 1) {
69  v.arr.push_back((int)idx);
70  } else if (detailLevel == 2) {
72  a.push_back(Pair("memberIndex", (int)idx));
73  if (idx < dmnMembers.size()) {
74  a.push_back(Pair("proTxHash", dmnMembers[idx]->proTxHash.ToString()));
75  }
76  v.arr.push_back(a);
77  }
78  }
79  };
80  auto push = [&](ArrOrCount& v, const std::string& name) {
81  if (detailLevel == 0) {
82  ret.push_back(Pair(name, v.count));
83  } else {
84  ret.push_back(Pair(name, v.arr));
85  }
86  };
87 
88  for (size_t i = 0; i < members.size(); i++) {
89  const auto& m = members[i];
90  add(badMembers, i, m.bad);
91  add(weComplain, i, m.weComplain);
92  add(receivedContributions, i, m.receivedContribution);
93  add(receivedComplaints, i, m.receivedComplaint);
94  add(receivedJustifications, i, m.receivedJustification);
95  add(receivedPrematureCommitments, i, m.receivedPrematureCommitment);
96  }
97  push(badMembers, "badMembers");
98  push(weComplain, "weComplain");
99  push(receivedContributions, "receivedContributions");
100  push(receivedComplaints, "receivedComplaints");
101  push(receivedJustifications, "receivedJustifications");
102  push(receivedPrematureCommitments, "receivedPrematureCommitments");
103 
104  if (detailLevel == 2) {
106  for (const auto& dmn : dmnMembers) {
107  arr.push_back(dmn->proTxHash.ToString());
108  }
109  ret.push_back(Pair("allMembers", arr));
110  }
111 
112  return ret;
113 }
114 
116 {
117 }
118 
119 UniValue CDKGDebugStatus::ToJson(int detailLevel) const
120 {
122 
123  ret.push_back(Pair("time", nTime));
124  ret.push_back(Pair("timeStr", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTime)));
125 
126  UniValue sessionsJson(UniValue::VOBJ);
127  for (const auto& p : sessions) {
128  if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)p.first)) {
129  continue;
130  }
131  const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)p.first);
132  sessionsJson.push_back(Pair(params.name, p.second.ToJson(detailLevel)));
133  }
134 
135  ret.push_back(Pair("session", sessionsJson));
136 
137  return ret;
138 }
139 
141 {
142  LOCK(cs);
143  ret = localStatus;
144 }
145 
147 {
148  LOCK(cs);
149 
150  auto it = localStatus.sessions.find(llmqType);
151  if (it == localStatus.sessions.end()) {
152  return;
153  }
154 
155  localStatus.sessions.erase(it);
157 }
158 
159 void CDKGDebugManager::InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight)
160 {
161  LOCK(cs);
162 
163  auto it = localStatus.sessions.find(llmqType);
164  if (it == localStatus.sessions.end()) {
165  it = localStatus.sessions.emplace(llmqType, CDKGDebugSessionStatus()).first;
166  }
167 
168  auto& params = Params().GetConsensus().llmqs.at(llmqType);
169  auto& session = it->second;
170  session.llmqType = llmqType;
171  session.quorumHash = quorumHash;
172  session.quorumHeight = (uint32_t)quorumHeight;
173  session.phase = 0;
174  session.statusBitset = 0;
175  session.members.clear();
176  session.members.resize((size_t)params.size);
177 }
178 
180 {
181  LOCK(cs);
182 
183  auto it = localStatus.sessions.find(llmqType);
184  if (it == localStatus.sessions.end()) {
185  return;
186  }
187 
188  if (func(it->second)) {
190  }
191 }
192 
193 void CDKGDebugManager::UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function<bool(CDKGDebugMemberStatus& status)>&& func)
194 {
195  LOCK(cs);
196 
197  auto it = localStatus.sessions.find(llmqType);
198  if (it == localStatus.sessions.end()) {
199  return;
200  }
201 
202  if (func(it->second.members.at(memberIdx))) {
204  }
205 }
206 
207 } // namespace llmq
std::map< Consensus::LLMQType, CDKGDebugSessionStatus > sessions
Definition: quorums_debug.h:83
void InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256 &quorumHash, int quorumHeight)
void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function< bool(CDKGDebugSessionStatus &status)> &&func)
UniValue ToJson(int detailLevel) const
BlockMap & mapBlockIndex
Definition: validation.cpp:215
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
Definition: utiltime.cpp:93
CCriticalSection cs_main
Definition: validation.cpp:213
void ResetLocalSessionStatus(Consensus::LLMQType llmqType)
CCriticalSection cs
Definition: quorums_debug.h:92
bool IsNull() const
Definition: uint256.h:33
void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function< bool(CDKGDebugMemberStatus &status)> &&func)
LLMQType
Definition: params.h:48
UniValue ToJson(int detailLevel) const
CDKGDebugStatus localStatus
Definition: quorums_debug.h:93
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
Consensus::LLMQType llmqType
Definition: quorums_debug.h:51
#define LOCK(cs)
Definition: sync.h:178
const char * name
Definition: rest.cpp:36
void GetLocalDebugStatus(CDKGDebugStatus &ret)
CDKGDebugManager * quorumDKGDebugManager
std::string ToString() const
Definition: uint256.cpp:62
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
std::map< LLMQType, LLMQParams > llmqs
Definition: params.h:189
256-bit opaque blob.
Definition: uint256.h:123
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
int64_t GetAdjustedTime()
Definition: timedata.cpp:35
static int count
Definition: tests.c:45
std::vector< CDKGDebugMemberStatus > members
Definition: quorums_debug.h:70
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:54
static std::vector< CDeterministicMNCPtr > GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum)
Released under the MIT license