dash/src/llmq/debug.h
Konstantin Akimov b8b37f314b Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex
e09c701e0110350f78366fb837308c086b6503c0 scripted-diff: Bump copyright of files changed in 2020 (MarcoFalke)
6cbe6209646db8914b87bf6edbc18c6031a16f1e scripted-diff: Replace CCriticalSection with RecursiveMutex (MarcoFalke)

Pull request description:

  `RecursiveMutex` better clarifies that the mutex is recursive, see also the standard library naming: https://en.cppreference.com/w/cpp/thread/recursive_mutex

  For that reason, and to avoid different people asking me the same question repeatedly (e.g. https://github.com/bitcoin/bitcoin/pull/15932#pullrequestreview-339175124 ), remove the outdated alias `CCriticalSection` with a scripted-diff
2023-05-24 12:43:57 -05:00

113 lines
2.8 KiB
C++

// Copyright (c) 2018-2022 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_LLMQ_DEBUG_H
#define BITCOIN_LLMQ_DEBUG_H
#include <consensus/params.h>
#include <sync.h>
#include <univalue.h>
#include <functional>
#include <set>
#include <llmq/dkgsessionhandler.h>
class CDataStream;
class CInv;
class CScheduler;
namespace llmq
{
class CDKGDebugMemberStatus
{
public:
union {
struct
{
// is it locally considered as bad (and thus removed from the validMembers set)
bool bad : 1;
// did we complain about this member
bool weComplain : 1;
// received message for DKG phases
bool receivedContribution : 1;
bool receivedComplaint : 1;
bool receivedJustification : 1;
bool receivedPrematureCommitment : 1;
};
uint8_t statusBitset;
};
std::set<uint16_t> complaintsFromMembers;
public:
CDKGDebugMemberStatus() : statusBitset(0) {}
};
class CDKGDebugSessionStatus
{
public:
Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash;
uint32_t quorumHeight{0};
QuorumPhase phase{0};
union {
struct
{
// sent messages for DKG phases
bool sentContributions : 1;
bool sentComplaint : 1;
bool sentJustification : 1;
bool sentPrematureCommitment : 1;
bool aborted : 1;
};
uint8_t statusBitset;
};
std::vector<CDKGDebugMemberStatus> members;
public:
CDKGDebugSessionStatus() : statusBitset(0) {}
UniValue ToJson(int quorumIndex, int detailLevel) const;
};
class CDKGDebugStatus
{
public:
int64_t nTime{0};
std::map<std::pair<Consensus::LLMQType, int>, CDKGDebugSessionStatus> sessions;
//std::map<Consensus::LLMQType, CDKGDebugSessionStatus> sessions;
public:
UniValue ToJson(int detailLevel) const;
};
class CDKGDebugManager
{
private:
mutable RecursiveMutex cs;
CDKGDebugStatus localStatus GUARDED_BY(cs);
public:
CDKGDebugManager();
void GetLocalDebugStatus(CDKGDebugStatus& ret) const;
void ResetLocalSessionStatus(Consensus::LLMQType llmqType, int quorumIndex);
void InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, int quorumIndex, const uint256& quorumHash, int quorumHeight);
void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, int quorumIndex, std::function<bool(CDKGDebugSessionStatus& status)>&& func);
void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, int quorumIndex, size_t memberIdx, std::function<bool(CDKGDebugMemberStatus& status)>&& func);
};
} // namespace llmq
#endif // BITCOIN_LLMQ_DEBUG_H