Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/active/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ActiveContext::ActiveContext(CBLSWorker& bls_worker, ChainstateManager& chainman
m_isman{isman},
m_qman{qman},
nodeman{std::make_unique<CActiveMasternodeManager>(connman, dmnman, operator_sk)},
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>()},
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params, quorums_watch)},
shareman{std::make_unique<llmq::CSigSharesManager>(connman, chainman, sigman, *nodeman, qman, sporkman)},
gov_signer{std::make_unique<GovernanceSigner>(connman, dmnman, govman, *nodeman, chainman, mn_sync)},
Expand Down
4 changes: 2 additions & 2 deletions src/active/dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void ActiveDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, Pe

CDKGLogger logger(*this, __func__, __LINE__);

std::set<uint256> justifyFor;
Uint256HashSet justifyFor;

for (const auto& m : members) {
if (m->bad) {
Expand Down Expand Up @@ -338,7 +338,7 @@ void ActiveDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, Pe
}

void ActiveDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman,
const std::set<uint256>& forMembers)
const Uint256HashSet& forMembers)
{
CDKGLogger logger(*this, __func__, __LINE__);

Expand Down
2 changes: 1 addition & 1 deletion src/active/dkgsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ActiveDKGSession final : public llmq::CDKGSession
void VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman) override
EXCLUSIVE_LOCKS_REQUIRED(!invCs);
void SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman,
const std::set<uint256>& forMembers) override;
const Uint256HashSet& forMembers) override;

// Phase 4: commit
void VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman) override;
Expand Down
6 changes: 3 additions & 3 deletions src/active/dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,19 @@ void ActiveDKGSessionHandler::HandlePhase(QuorumPhase curPhase, QuorumPhase next

// returns a set of NodeIds which sent invalid messages
template<typename Message>
std::set<NodeId> BatchVerifyMessageSigs(CDKGSession& session, const std::vector<std::pair<NodeId, std::shared_ptr<Message>>>& messages)
std::unordered_set<NodeId> BatchVerifyMessageSigs(CDKGSession& session, const std::vector<std::pair<NodeId, std::shared_ptr<Message>>>& messages)
{
if (messages.empty()) {
return {};
}

std::set<NodeId> ret;
std::unordered_set<NodeId> ret;
bool revertToSingleVerification = false;

CBLSSignature aggSig;
std::vector<CBLSPublicKey> pubKeys;
std::vector<uint256> messageHashes;
std::set<uint256> messageHashesSet;
Uint256HashSet messageHashesSet;
pubKeys.reserve(messages.size());
messageHashes.reserve(messages.size());
bool first = true;
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ RPCResult CDKGDebugSessionStatus::GetJsonHelp(const std::string& key, bool optio
}};
}

// CDKGDebugStatus::ToJson() defined in llmq/debug.cpp
RPCResult CDKGDebugStatus::GetJsonHelp(const std::string& key, bool optional, bool inner_optional)
// CDKGDebugManager::ToJson() defined in llmq/debug.cpp
RPCResult CDKGDebugManager::GetJsonHelp(const std::string& key, bool optional, bool inner_optional)
{
return {RPCResult::Type::OBJ, key, optional, key.empty() ? "" : "The state of the node's DKG sessions",
{
Expand Down
33 changes: 19 additions & 14 deletions src/llmq/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,40 @@ UniValue CDKGDebugSessionStatus::ToJson(CDeterministicMNManager& dmnman, CQuorum
return ret;
}

CDKGDebugManager::CDKGDebugManager() = default;
CDKGDebugManager::CDKGDebugManager(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
const ChainstateManager& chainman) :
m_dmnman{dmnman},
m_qsnapman{qsnapman},
m_chainman{chainman}
{
}

CDKGDebugManager::~CDKGDebugManager() = default;

UniValue CDKGDebugStatus::ToJson(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
const ChainstateManager& chainman, int detailLevel) const
size_t CDKGDebugManager::GetSessionCount() const
{
UniValue ret(UniValue::VOBJ);
return WITH_LOCK(cs_lockStatus, return localStatus.sessions.size());
}

UniValue CDKGDebugManager::ToJson(int detailLevel) const
{
LOCK(cs_lockStatus);

ret.pushKV("time", nTime);
ret.pushKV("timeStr", FormatISO8601DateTime(nTime));
UniValue ret(UniValue::VOBJ);
ret.pushKV("time", localStatus.nTime);
ret.pushKV("timeStr", FormatISO8601DateTime(localStatus.nTime));

// TODO Support array of sessions
UniValue sessionsArrJson(UniValue::VARR);
for (const auto& p : sessions) {
for (const auto& p : localStatus.sessions) {
const auto& llmq_params_opt = Params().GetLLMQ(p.first.first);
if (!llmq_params_opt.has_value()) {
continue;
}
UniValue s(UniValue::VOBJ);
s.pushKV("llmqType", std::string(llmq_params_opt->name));
s.pushKV("quorumIndex", p.first.second);
s.pushKV("status", p.second.ToJson(dmnman, qsnapman, chainman, p.first.second, detailLevel));
s.pushKV("status", p.second.ToJson(m_dmnman, m_qsnapman, m_chainman, p.first.second, detailLevel));

sessionsArrJson.push_back(s);
}
Expand All @@ -138,12 +149,6 @@ UniValue CDKGDebugStatus::ToJson(CDeterministicMNManager& dmnman, CQuorumSnapsho
return ret;
}

void CDKGDebugManager::GetLocalDebugStatus(llmq::CDKGDebugStatus& ret) const
{
LOCK(cs_lockStatus);
ret = localStatus;
}

void CDKGDebugManager::ResetLocalSessionStatus(Consensus::LLMQType llmqType, int quorumIndex)
{
LOCK(cs_lockStatus);
Expand Down
31 changes: 15 additions & 16 deletions src/llmq/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <univalue.h>

#include <functional>
#include <set>
#include <unordered_set>

class CDataStream;
class CDeterministicMNManager;
Expand Down Expand Up @@ -45,7 +45,7 @@ class CDKGDebugMemberStatus
uint8_t statusBitset;
};

std::set<uint16_t> complaintsFromMembers;
std::unordered_set<uint16_t> complaintsFromMembers;

public:
CDKGDebugMemberStatus() : statusBitset(0) {}
Expand Down Expand Up @@ -83,34 +83,28 @@ class CDKGDebugSessionStatus
const ChainstateManager& chainman, int quorumIndex, int detailLevel) const;
};

class CDKGDebugStatus
{
public:
struct CDKGDebugStatus {
int64_t nTime{0};

std::map<std::pair<Consensus::LLMQType, int>, CDKGDebugSessionStatus> sessions;
//std::map<Consensus::LLMQType, CDKGDebugSessionStatus> sessions;

public:
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional, bool inner_optional = false);
[[nodiscard]] UniValue ToJson(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman,
const ChainstateManager& chainman, int detailLevel) const;
};

class CDKGDebugManager
{
private:
CDeterministicMNManager& m_dmnman;
CQuorumSnapshotManager& m_qsnapman;
const ChainstateManager& m_chainman;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: duplicated private:; should remove next line

private:
mutable Mutex cs_lockStatus;
CDKGDebugStatus localStatus GUARDED_BY(cs_lockStatus);

public:
CDKGDebugManager(const CDKGDebugManager&) = delete;
CDKGDebugManager& operator=(const CDKGDebugManager&) = delete;
CDKGDebugManager();
CDKGDebugManager(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman, const ChainstateManager& chainman);
~CDKGDebugManager();

void GetLocalDebugStatus(CDKGDebugStatus& ret) const EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);

void ResetLocalSessionStatus(Consensus::LLMQType llmqType, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);
void InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, int quorumIndex, const uint256& quorumHash,
int quorumHeight) EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);
Expand All @@ -121,8 +115,13 @@ class CDKGDebugManager
void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, int quorumIndex, size_t memberIdx,
std::function<bool(CDKGDebugMemberStatus& status)>&& func)
EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);
};

size_t GetSessionCount() const
EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);
[[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional, bool inner_optional = false);
[[nodiscard]] UniValue ToJson(int detailLevel) const
EXCLUSIVE_LOCKS_REQUIRED(!cs_lockStatus);
};
} // namespace llmq

#endif // BITCOIN_LLMQ_DEBUG_H
2 changes: 1 addition & 1 deletion src/llmq/dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co
return false;
}

std::set<size_t> contributionsSet;
std::unordered_set<size_t> contributionsSet;
for (const auto& [index, skContribution] : qj.contributions) {
if (GetMemberAtIndex(index) == nullptr) {
logger.Batch("invalid contribution index");
Expand Down
18 changes: 9 additions & 9 deletions src/llmq/dkgsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <bls/bls_ies.h>
#include <bls/bls_worker.h>
#include <evo/types.h>

#include <saltedhasher.h>

#include <sync.h>
#include <util/underlying.h>

Expand Down Expand Up @@ -215,13 +215,13 @@ class CDKGMember
size_t idx;
CBLSId id;

std::set<uint256> contributions;
std::set<uint256> complaints;
std::set<uint256> justifications;
std::set<uint256> prematureCommitments;
Uint256HashSet contributions;
Uint256HashSet complaints;
Uint256HashSet justifications;
Uint256HashSet prematureCommitments;

std::set<uint256> badMemberVotes;
std::set<uint256> complaintsFromOthers;
Uint256HashSet badMemberVotes;
Uint256HashSet complaintsFromOthers;

bool bad{false};
bool badConnection{false};
Expand Down Expand Up @@ -325,7 +325,7 @@ class CDKGSession
std::vector<size_t> pendingContributionVerifications GUARDED_BY(cs_pending);

// filled by ReceivePrematureCommitment and used by FinalizeCommitments
std::set<uint256> validCommitments GUARDED_BY(invCs);
Uint256HashSet validCommitments GUARDED_BY(invCs);

public:
CDKGSession(CBLSWorker& _blsWorker, CDeterministicMNManager& dmnman, CDKGDebugManager& _dkgDebugManager,
Expand Down Expand Up @@ -366,7 +366,7 @@ class CDKGSession

// Phase 3: justification
virtual void VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman) EXCLUSIVE_LOCKS_REQUIRED(!invCs) {}
virtual void SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman, const std::set<uint256>& forMembers) {}
virtual void SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman, const Uint256HashSet& forMembers) {}
bool PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const;
std::optional<CInv> ReceiveMessage(const CDKGJustification& qj) EXCLUSIVE_LOCKS_REQUIRED(!invCs);

Expand Down
4 changes: 2 additions & 2 deletions src/llmq/dkgsessionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string_view>
#include <unordered_set>
#include <vector>

class CBlockIndex;
Expand Down Expand Up @@ -67,7 +67,7 @@ class CDKGPendingMessages
mutable Mutex cs_messages;
std::list<BinaryMessage> pendingMessages GUARDED_BY(cs_messages);
std::map<NodeId, size_t> messagesPerNode GUARDED_BY(cs_messages);
std::set<uint256> seenMessages GUARDED_BY(cs_messages);
Uint256HashSet seenMessages GUARDED_BY(cs_messages);

public:
explicit CDKGPendingMessages(size_t _maxMessagesPerNode, uint32_t _invType) :
Expand Down
4 changes: 3 additions & 1 deletion src/llmq/ehf_signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <llmq/signing.h>
#include <msg_result.h>
#include <saltedhasher.h>

#include <set>

Expand All @@ -30,7 +31,8 @@ class CEHFSignalsHandler : public CRecoveredSigsListener
* keep freshly generated IDs for easier filter sigs in HandleNewRecoveredSig
*/
mutable Mutex cs;
std::set<uint256> ids GUARDED_BY(cs);
Uint256HashSet ids GUARDED_BY(cs);

public:
explicit CEHFSignalsHandler(ChainstateManager& chainman, CSigningManager& sigman, CSigSharesManager& shareman,
const CQuorumManager& qman);
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/observer/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ObserverContext::ObserverContext(CBLSWorker& bls_worker, CConnman& connman, CDet
const CSporkManager& sporkman, const llmq::QvvecSyncModeMap& sync_map,
const util::DbWrapperParams& db_params, bool quorums_recovery) :
m_qman{qman},
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>()},
dkgdbgman{std::make_unique<llmq::CDKGDebugManager>(dmnman, qsnapman, chainman)},
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(dmnman, qsnapman, chainman, sporkman, db_params,
/*quorums_watch=*/true)},
qman_handler{std::make_unique<llmq::QuorumObserver>(connman, dmnman, qman, qsnapman, chainman, mn_sync, sporkman,
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/observer/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void QuorumObserver::StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockI

// do not block the caller thread
workerPool.push([pIndex, t, this](int threadId) {
std::set<uint256> dbKeysToSkip;
Uint256HashSet dbKeysToSkip;

if (LOCK(cs_cleanup); cleanupQuorumsCache.empty()) {
utils::InitQuorumsCache(cleanupQuorumsCache, m_chainman.GetConsensus(), /*limit_by_connections=*/false);
Expand All @@ -346,7 +346,7 @@ void QuorumObserver::StartCleanupOldQuorumDataThread(gsl::not_null<const CBlockI
LOCK(cs_cleanup);
auto& cache = cleanupQuorumsCache[params.type];
const CBlockIndex* pindex_loop{pIndex};
std::set<uint256> quorum_keys;
Uint256HashSet quorum_keys;
while (pindex_loop != nullptr && pIndex->nHeight - pindex_loop->nHeight < params.max_store_depth()) {
uint256 quorum_key;
if (cache.get(pindex_loop->GetBlockHash(), quorum_key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/observer/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <ctpl_stl.h>
#include <llmq/options.h>
#include <llmq/types.h>
#include <saltedhasher.h>

#include <consensus/params.h>
#include <saltedhasher.h>
#include <span.h>
#include <sync.h>
#include <threadsafety.h>
Expand Down Expand Up @@ -59,7 +59,7 @@ class QuorumObserverParent
gsl::not_null<const CBlockIndex*> pindexStart,
size_t nCountRequested) const = 0;
virtual void CleanupExpiredDataRequests() const = 0;
virtual void CleanupOldQuorumData(const std::set<uint256>& dbKeysToSkip) const = 0;
virtual void CleanupOldQuorumData(const Uint256HashSet& dbKeysToSkip) const = 0;
};

class QuorumObserver
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uint256 MakeQuorumKey(const CQuorum& q)
return hw.GetHash();
}

void DataCleanupHelper(CDBWrapper& db, const std::set<uint256>& skip_list, bool compact)
void DataCleanupHelper(CDBWrapper& db, const Uint256HashSet& skip_list, bool compact)
{
const auto prefixes = {DB_QUORUM_QUORUM_VVEC, DB_QUORUM_SK_SHARE};

Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern const std::string DB_QUORUM_SK_SHARE;
extern const std::string DB_QUORUM_QUORUM_VVEC;

uint256 MakeQuorumKey(const CQuorum& q);
void DataCleanupHelper(CDBWrapper& db, const std::set<uint256>& skip_list, bool compact = false);
void DataCleanupHelper(CDBWrapper& db, const Uint256HashSet& skip_list, bool compact = false);

/**
* Object used as a key to store CQuorumDataRequest
Expand Down
Loading