Line data Source code
1 : // Copyright (c) 2018-2021 The Dash Core developers 2 : // Copyright (c) 2022 The PIVX Core developers 3 : // Distributed under the MIT/X11 software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #ifndef PIVX_LLMQ_QUORUMS_DEBUG_H 7 : #define PIVX_LLMQ_QUORUMS_DEBUG_H 8 : 9 : #include "consensus/params.h" 10 : #include "sync.h" 11 : #include "univalue.h" 12 : 13 : #include <functional> 14 : #include <set> 15 : 16 : class CDataStream; 17 : class CInv; 18 : class CScheduler; 19 : 20 : namespace llmq 21 : { 22 : 23 3000 : class CDKGDebugMemberStatus 24 : { 25 : public: 26 : union { 27 : struct 28 : { 29 : // is it locally considered as bad (and thus removed from the validMembers set) 30 : bool bad : 1; 31 : // did we complain about this member 32 : bool weComplain : 1; 33 : 34 : // received message for DKG phases 35 : bool receivedContribution : 1; 36 : bool receivedComplaint : 1; 37 : bool receivedJustification : 1; 38 : bool receivedPrematureCommitment : 1; 39 : }; 40 : uint8_t statusBitset; 41 : }; 42 : 43 : std::set<uint16_t> complaintsFromMembers; 44 : 45 : public: 46 246 : CDKGDebugMemberStatus() : statusBitset(0) {} 47 : }; 48 : 49 776 : class CDKGDebugSessionStatus 50 : { 51 : public: 52 : Consensus::LLMQType llmqType{Consensus::LLMQ_NONE}; 53 : uint256 quorumHash; 54 : uint32_t quorumHeight{0}; 55 : uint8_t phase{0}; 56 : 57 : union { 58 : struct 59 : { 60 : // sent messages for DKG phases 61 : bool sentContributions : 1; 62 : bool sentComplaint : 1; 63 : bool sentJustification : 1; 64 : bool sentPrematureCommitment : 1; 65 : 66 : bool aborted : 1; 67 : }; 68 : uint8_t statusBitset; 69 : }; 70 : 71 : std::vector<CDKGDebugMemberStatus> members; 72 : bool receivedFinalCommitment{false}; 73 : 74 : public: 75 164 : CDKGDebugSessionStatus() : statusBitset(0) {} 76 : 77 : UniValue ToJson(int detailLevel) const; 78 : }; 79 : 80 1393 : class CDKGDebugStatus 81 : { 82 : public: 83 : int64_t nTime{0}; 84 : 85 : std::map<Consensus::LLMQType, CDKGDebugSessionStatus> sessions; 86 : 87 : public: 88 : UniValue ToJson(int detailLevel) const; 89 : }; 90 : 91 475 : class CDKGDebugManager 92 : { 93 : private: 94 : RecursiveMutex cs; 95 : CDKGDebugStatus localStatus; 96 : 97 : public: 98 475 : CDKGDebugManager() = default; 99 : 100 : void GetLocalDebugStatus(CDKGDebugStatus& ret); 101 : 102 : void ResetLocalSessionStatus(Consensus::LLMQType llmqType); 103 : void InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight); 104 : 105 : void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function<bool(CDKGDebugSessionStatus& status)>&& func); 106 : void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function<bool(CDKGDebugMemberStatus& status)>&& func); 107 : }; 108 : 109 : extern std::unique_ptr<CDKGDebugManager> quorumDKGDebugManager; 110 : 111 : } // namespace llmq 112 : 113 : #endif // PIVX_LLMQ_QUORUMS_DEBUG_H