mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
refactor: move PeerManager
out of CDKGSession{,Handler,Manager}
ctor
This commit is contained in:
parent
cc0e771c29
commit
01876c7e56
@ -2280,7 +2280,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
|
||||
// ********************************************************* Step 10a: schedule Dash-specific tasks
|
||||
|
||||
node.llmq_ctx->Start();
|
||||
node.llmq_ctx->Start(*node.peerman);
|
||||
|
||||
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});
|
||||
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(*node.mn_sync), std::cref(*node.peerman), std::cref(*node.govman)), std::chrono::seconds{1});
|
||||
|
@ -29,7 +29,7 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CConnman& connman, CDeterm
|
||||
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db)},
|
||||
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainman.ActiveChainstate(), connman, dmnman,
|
||||
*dkg_debugman, mn_metaman, *quorum_block_processor,
|
||||
mn_activeman, sporkman, peerman, unit_tests, wipe)},
|
||||
mn_activeman, sporkman, unit_tests, wipe)},
|
||||
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), connman, dmnman, *qdkgsman,
|
||||
evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman,
|
||||
unit_tests, wipe)},
|
||||
@ -74,12 +74,13 @@ void LLMQContext::Interrupt() {
|
||||
llmq::quorumInstantSendManager->InterruptWorkerThread();
|
||||
}
|
||||
|
||||
void LLMQContext::Start() {
|
||||
void LLMQContext::Start(PeerManager& peerman)
|
||||
{
|
||||
assert(clhandler == llmq::chainLocksHandler.get());
|
||||
assert(isman == llmq::quorumInstantSendManager.get());
|
||||
|
||||
if (is_masternode) {
|
||||
qdkgsman->StartThreads();
|
||||
qdkgsman->StartThreads(peerman);
|
||||
}
|
||||
qman->Start();
|
||||
shareman->RegisterAsRecoveredSigsListener();
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
~LLMQContext();
|
||||
|
||||
void Interrupt();
|
||||
void Start();
|
||||
void Start(PeerManager& peerman);
|
||||
void Stop();
|
||||
|
||||
/** Guaranteed if LLMQContext is initialized then all members are valid too
|
||||
|
@ -156,7 +156,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
CDKGLogger logger(*this, __func__, __LINE__);
|
||||
|
||||
@ -174,10 +174,10 @@ void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages)
|
||||
logger.Batch("generated contributions. time=%d", t1.count());
|
||||
logger.Flush();
|
||||
|
||||
SendContributions(pendingMessages);
|
||||
SendContributions(pendingMessages, peerman);
|
||||
}
|
||||
|
||||
void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
CDKGLogger logger(*this, __func__, __LINE__);
|
||||
|
||||
@ -226,7 +226,7 @@ void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages)
|
||||
return true;
|
||||
});
|
||||
|
||||
pendingMessages.PushPendingMessage(-1, nullptr, qc);
|
||||
pendingMessages.PushPendingMessage(-1, qc, peerman);
|
||||
}
|
||||
|
||||
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification
|
||||
@ -417,7 +417,7 @@ void CDKGSession::VerifyPendingContributions()
|
||||
pendingContributionVerifications.clear();
|
||||
}
|
||||
|
||||
void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
if (!AreWeMember()) {
|
||||
return;
|
||||
@ -455,7 +455,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
|
||||
|
||||
VerifyConnectionAndMinProtoVersions();
|
||||
|
||||
SendComplaint(pendingMessages);
|
||||
SendComplaint(pendingMessages, peerman);
|
||||
}
|
||||
|
||||
void CDKGSession::VerifyConnectionAndMinProtoVersions() const
|
||||
@ -499,7 +499,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const
|
||||
}
|
||||
}
|
||||
|
||||
void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
CDKGLogger logger(*this, __func__, __LINE__);
|
||||
|
||||
@ -538,7 +538,7 @@ void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages)
|
||||
return true;
|
||||
});
|
||||
|
||||
pendingMessages.PushPendingMessage(-1, nullptr, qc);
|
||||
pendingMessages.PushPendingMessage(-1, qc, peerman);
|
||||
}
|
||||
|
||||
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification
|
||||
@ -645,7 +645,7 @@ std::optional<CInv> CDKGSession::ReceiveMessage(const CDKGComplaint& qc)
|
||||
return inv;
|
||||
}
|
||||
|
||||
void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
if (!AreWeMember()) {
|
||||
return;
|
||||
@ -682,11 +682,12 @@ void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages)
|
||||
|
||||
logger.Flush();
|
||||
if (!justifyFor.empty()) {
|
||||
SendJustification(pendingMessages, justifyFor);
|
||||
SendJustification(pendingMessages, peerman, justifyFor);
|
||||
}
|
||||
}
|
||||
|
||||
void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const std::set<uint256>& forMembers)
|
||||
void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman,
|
||||
const std::set<uint256>& forMembers)
|
||||
{
|
||||
CDKGLogger logger(*this, __func__, __LINE__);
|
||||
|
||||
@ -731,7 +732,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const
|
||||
return true;
|
||||
});
|
||||
|
||||
pendingMessages.PushPendingMessage(-1, nullptr, qj);
|
||||
pendingMessages.PushPendingMessage(-1, qj, peerman);
|
||||
}
|
||||
|
||||
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification
|
||||
@ -885,7 +886,7 @@ std::optional<CInv> CDKGSession::ReceiveMessage(const CDKGJustification& qj)
|
||||
return inv;
|
||||
}
|
||||
|
||||
void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
if (!AreWeMember()) {
|
||||
return;
|
||||
@ -927,10 +928,10 @@ void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages)
|
||||
|
||||
logger.Flush();
|
||||
|
||||
SendCommitment(pendingMessages);
|
||||
SendCommitment(pendingMessages, peerman);
|
||||
}
|
||||
|
||||
void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
|
||||
void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
|
||||
{
|
||||
CDKGLogger logger(*this, __func__, __LINE__);
|
||||
|
||||
@ -1041,7 +1042,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
|
||||
return true;
|
||||
});
|
||||
|
||||
pendingMessages.PushPendingMessage(-1, nullptr, qc);
|
||||
pendingMessages.PushPendingMessage(-1, qc, peerman);
|
||||
}
|
||||
|
||||
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification
|
||||
|
@ -22,6 +22,7 @@ class CConnman;
|
||||
class CDeterministicMN;
|
||||
class CMasternodeMetaMan;
|
||||
class CSporkManager;
|
||||
class PeerManager;
|
||||
|
||||
using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;
|
||||
|
||||
@ -349,28 +350,28 @@ public:
|
||||
*/
|
||||
|
||||
// Phase 1: contribution
|
||||
void Contribute(CDKGPendingMessages& pendingMessages);
|
||||
void SendContributions(CDKGPendingMessages& pendingMessages);
|
||||
void Contribute(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
void SendContributions(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
bool PreVerifyMessage(const CDKGContribution& qc, bool& retBan) const;
|
||||
std::optional<CInv> ReceiveMessage(const CDKGContribution& qc);
|
||||
void VerifyPendingContributions() EXCLUSIVE_LOCKS_REQUIRED(cs_pending);
|
||||
|
||||
// Phase 2: complaint
|
||||
void VerifyAndComplain(CDKGPendingMessages& pendingMessages);
|
||||
void VerifyAndComplain(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
void VerifyConnectionAndMinProtoVersions() const;
|
||||
void SendComplaint(CDKGPendingMessages& pendingMessages);
|
||||
void SendComplaint(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
bool PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const;
|
||||
std::optional<CInv> ReceiveMessage(const CDKGComplaint& qc);
|
||||
|
||||
// Phase 3: justification
|
||||
void VerifyAndJustify(CDKGPendingMessages& pendingMessages);
|
||||
void SendJustification(CDKGPendingMessages& pendingMessages, const std::set<uint256>& forMembers);
|
||||
void VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
void SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman, const std::set<uint256>& forMembers);
|
||||
bool PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const;
|
||||
std::optional<CInv> ReceiveMessage(const CDKGJustification& qj);
|
||||
|
||||
// Phase 4: commit
|
||||
void VerifyAndCommit(CDKGPendingMessages& pendingMessages);
|
||||
void SendCommitment(CDKGPendingMessages& pendingMessages);
|
||||
void VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
void SendCommitment(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
|
||||
bool PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retBan) const;
|
||||
std::optional<CInv> ReceiveMessage(const CDKGPrematureCommitment& qc);
|
||||
|
||||
|
@ -28,8 +28,7 @@ CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chai
|
||||
CDeterministicMNManager& dmnman, CDKGDebugManager& _dkgDebugManager,
|
||||
CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman,
|
||||
CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman,
|
||||
const CSporkManager& sporkman, const std::unique_ptr<PeerManager>& peerman,
|
||||
const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman,
|
||||
const Consensus::LLMQParams& _params, int _quorumIndex) :
|
||||
blsWorker(_blsWorker),
|
||||
m_chainstate(chainstate),
|
||||
@ -41,7 +40,6 @@ CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chai
|
||||
quorumBlockProcessor(_quorumBlockProcessor),
|
||||
m_mn_activeman(mn_activeman),
|
||||
m_sporkman(sporkman),
|
||||
m_peerman(peerman),
|
||||
params(_params),
|
||||
quorumIndex(_quorumIndex),
|
||||
curSession(std::make_unique<CDKGSession>(nullptr, _params, _blsWorker, _connman, dmnman, _dkgManager,
|
||||
@ -60,18 +58,8 @@ CDKGSessionHandler::CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chai
|
||||
|
||||
CDKGSessionHandler::~CDKGSessionHandler() = default;
|
||||
|
||||
void CDKGPendingMessages::PushPendingMessage(NodeId from, PeerManager* peerman, CDataStream& vRecv)
|
||||
void CDKGPendingMessages::PushPendingMessage(NodeId from, CDataStream& vRecv, PeerManager& peerman)
|
||||
{
|
||||
// if peer is not -1 we should always pass valid peerman
|
||||
assert(from == -1 || peerman != nullptr);
|
||||
if (peerman != nullptr) {
|
||||
if (m_peerman == nullptr) {
|
||||
m_peerman = peerman;
|
||||
}
|
||||
// we should never use one different PeerManagers for same queue
|
||||
assert(m_peerman == peerman);
|
||||
}
|
||||
|
||||
// this will also consume the data, even if we bail out early
|
||||
auto pm = std::make_shared<CDataStream>(std::move(vRecv));
|
||||
|
||||
@ -80,7 +68,7 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, PeerManager* peerman,
|
||||
uint256 hash = hw.GetHash();
|
||||
|
||||
if (from != -1) {
|
||||
WITH_LOCK(::cs_main, Assert(m_peerman.load())->EraseObjectRequest(from, CInv(invType, hash)));
|
||||
WITH_LOCK(::cs_main, peerman.EraseObjectRequest(from, CInv(invType, hash)));
|
||||
}
|
||||
|
||||
LOCK(cs_messages);
|
||||
@ -119,10 +107,10 @@ bool CDKGPendingMessages::HasSeen(const uint256& hash) const
|
||||
return seenMessages.count(hash) != 0;
|
||||
}
|
||||
|
||||
void CDKGPendingMessages::Misbehaving(const NodeId from, const int score)
|
||||
void CDKGPendingMessages::Misbehaving(const NodeId from, const int score, PeerManager& peerman)
|
||||
{
|
||||
if (from == -1) return;
|
||||
m_peerman.load()->Misbehaving(from, score);
|
||||
peerman.Misbehaving(from, score);
|
||||
}
|
||||
|
||||
void CDKGPendingMessages::Clear()
|
||||
@ -162,28 +150,30 @@ void CDKGSessionHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
|
||||
params.name, quorumIndex, currentHeight, pQuorumBaseBlockIndex->nHeight, ToUnderlying(oldPhase), ToUnderlying(phase));
|
||||
}
|
||||
|
||||
void CDKGSessionHandler::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv)
|
||||
void CDKGSessionHandler::ProcessMessage(const CNode& pfrom, PeerManager& peerman, const std::string& msg_type,
|
||||
CDataStream& vRecv)
|
||||
{
|
||||
// We don't handle messages in the calling thread as deserialization/processing of these would block everything
|
||||
if (msg_type == NetMsgType::QCONTRIB) {
|
||||
pendingContributions.PushPendingMessage(pfrom.GetId(), peerman, vRecv);
|
||||
pendingContributions.PushPendingMessage(pfrom.GetId(), vRecv, peerman);
|
||||
} else if (msg_type == NetMsgType::QCOMPLAINT) {
|
||||
pendingComplaints.PushPendingMessage(pfrom.GetId(), peerman, vRecv);
|
||||
pendingComplaints.PushPendingMessage(pfrom.GetId(), vRecv, peerman);
|
||||
} else if (msg_type == NetMsgType::QJUSTIFICATION) {
|
||||
pendingJustifications.PushPendingMessage(pfrom.GetId(), peerman, vRecv);
|
||||
pendingJustifications.PushPendingMessage(pfrom.GetId(), vRecv, peerman);
|
||||
} else if (msg_type == NetMsgType::QPCOMMITMENT) {
|
||||
pendingPrematureCommitments.PushPendingMessage(pfrom.GetId(), peerman, vRecv);
|
||||
pendingPrematureCommitments.PushPendingMessage(pfrom.GetId(), vRecv, peerman);
|
||||
}
|
||||
}
|
||||
|
||||
void CDKGSessionHandler::StartThread()
|
||||
void CDKGSessionHandler::StartThread(PeerManager& peerman)
|
||||
{
|
||||
if (phaseHandlerThread.joinable()) {
|
||||
throw std::runtime_error("Tried to start an already started CDKGSessionHandler thread.");
|
||||
}
|
||||
|
||||
m_thread_name = strprintf("llmq-%d-%d", ToUnderlying(params.type), quorumIndex);
|
||||
phaseHandlerThread = std::thread(util::TraceThread, m_thread_name.c_str(), [this] { PhaseHandlerThread(); });
|
||||
phaseHandlerThread = std::thread(&util::TraceThread, m_thread_name.c_str(),
|
||||
[this, &peerman] { PhaseHandlerThread(peerman); });
|
||||
}
|
||||
|
||||
void CDKGSessionHandler::StopThread()
|
||||
@ -476,9 +466,10 @@ static void RelayInvToParticipants(const CDKGSession& session, CConnman& connman
|
||||
logger.Batch("forMember[%s] NOTrelayMembers[%s]", session.ProTx().ToString().substr(0, 4), ss2.str());
|
||||
logger.Flush();
|
||||
}
|
||||
|
||||
template <typename Message, int MessageType>
|
||||
bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSession& session,
|
||||
CDKGPendingMessages& pendingMessages, size_t maxCount)
|
||||
bool ProcessPendingMessageBatch(CConnman& connman, CDKGSession& session, CDKGPendingMessages& pendingMessages,
|
||||
PeerManager& peerman, size_t maxCount)
|
||||
{
|
||||
auto msgs = pendingMessages.PopAndDeserializeMessages<Message>(maxCount);
|
||||
if (msgs.empty()) {
|
||||
@ -493,7 +484,7 @@ bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSes
|
||||
if (!p.second) {
|
||||
LogPrint(BCLog::LLMQ_DKG, "%s -- failed to deserialize message, peer=%d\n", __func__, nodeId);
|
||||
{
|
||||
pendingMessages.Misbehaving(nodeId, 100);
|
||||
pendingMessages.Misbehaving(nodeId, 100, peerman);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -502,7 +493,7 @@ bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSes
|
||||
if (ban) {
|
||||
LogPrint(BCLog::LLMQ_DKG, "%s -- banning node due to failed preverification, peer=%d\n", __func__, nodeId);
|
||||
{
|
||||
pendingMessages.Misbehaving(nodeId, 100);
|
||||
pendingMessages.Misbehaving(nodeId, 100, peerman);
|
||||
}
|
||||
}
|
||||
LogPrint(BCLog::LLMQ_DKG, "%s -- skipping message due to failed preverification, peer=%d\n", __func__, nodeId);
|
||||
@ -519,7 +510,7 @@ bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSes
|
||||
LOCK(cs_main);
|
||||
for (auto nodeId : badNodes) {
|
||||
LogPrint(BCLog::LLMQ_DKG, "%s -- failed to verify signature, peer=%d\n", __func__, nodeId);
|
||||
pendingMessages.Misbehaving(nodeId, 100);
|
||||
pendingMessages.Misbehaving(nodeId, 100, peerman);
|
||||
}
|
||||
}
|
||||
|
||||
@ -529,15 +520,15 @@ bool ProcessPendingMessageBatch(CConnman& connman, PeerManager* peerman, CDKGSes
|
||||
continue;
|
||||
}
|
||||
const std::optional<CInv> inv = session.ReceiveMessage(*p.second);
|
||||
if (inv && peerman) {
|
||||
RelayInvToParticipants(session, connman, *peerman, *inv);
|
||||
if (inv) {
|
||||
RelayInvToParticipants(session, connman, peerman, *inv);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDKGSessionHandler::HandleDKGRound()
|
||||
void CDKGSessionHandler::HandleDKGRound(PeerManager& peerman)
|
||||
{
|
||||
WaitForNextPhase(std::nullopt, QuorumPhase::Initialized);
|
||||
|
||||
@ -570,60 +561,51 @@ void CDKGSessionHandler::HandleDKGRound()
|
||||
WaitForNextPhase(QuorumPhase::Initialized, QuorumPhase::Contribute, curQuorumHash);
|
||||
|
||||
// Contribute
|
||||
auto fContributeStart = [this]() {
|
||||
curSession->Contribute(pendingContributions);
|
||||
};
|
||||
auto fContributeWait = [this] {
|
||||
return ProcessPendingMessageBatch<CDKGContribution, MSG_QUORUM_CONTRIB>(connman, m_peerman.get(), *curSession,
|
||||
pendingContributions, 8);
|
||||
auto fContributeStart = [this, &peerman]() { curSession->Contribute(pendingContributions, peerman); };
|
||||
auto fContributeWait = [this, &peerman] {
|
||||
return ProcessPendingMessageBatch<CDKGContribution, MSG_QUORUM_CONTRIB>(connman, *curSession,
|
||||
pendingContributions, peerman, 8);
|
||||
};
|
||||
HandlePhase(QuorumPhase::Contribute, QuorumPhase::Complain, curQuorumHash, 0.05, fContributeStart, fContributeWait);
|
||||
|
||||
// Complain
|
||||
auto fComplainStart = [this]() {
|
||||
curSession->VerifyAndComplain(pendingComplaints);
|
||||
};
|
||||
auto fComplainWait = [this] {
|
||||
return ProcessPendingMessageBatch<CDKGComplaint, MSG_QUORUM_COMPLAINT>(connman, m_peerman.get(), *curSession,
|
||||
pendingComplaints, 8);
|
||||
auto fComplainStart = [this, &peerman]() { curSession->VerifyAndComplain(pendingComplaints, peerman); };
|
||||
auto fComplainWait = [this, &peerman] {
|
||||
return ProcessPendingMessageBatch<CDKGComplaint, MSG_QUORUM_COMPLAINT>(connman, *curSession, pendingComplaints,
|
||||
peerman, 8);
|
||||
};
|
||||
HandlePhase(QuorumPhase::Complain, QuorumPhase::Justify, curQuorumHash, 0.05, fComplainStart, fComplainWait);
|
||||
|
||||
// Justify
|
||||
auto fJustifyStart = [this]() {
|
||||
curSession->VerifyAndJustify(pendingJustifications);
|
||||
};
|
||||
auto fJustifyWait = [this] {
|
||||
return ProcessPendingMessageBatch<CDKGJustification, MSG_QUORUM_JUSTIFICATION>(connman, m_peerman.get(),
|
||||
*curSession,
|
||||
pendingJustifications, 8);
|
||||
auto fJustifyStart = [this, &peerman]() { curSession->VerifyAndJustify(pendingJustifications, peerman); };
|
||||
auto fJustifyWait = [this, &peerman] {
|
||||
return ProcessPendingMessageBatch<CDKGJustification, MSG_QUORUM_JUSTIFICATION>(connman, *curSession,
|
||||
pendingJustifications, peerman, 8);
|
||||
};
|
||||
HandlePhase(QuorumPhase::Justify, QuorumPhase::Commit, curQuorumHash, 0.05, fJustifyStart, fJustifyWait);
|
||||
|
||||
// Commit
|
||||
auto fCommitStart = [this]() {
|
||||
curSession->VerifyAndCommit(pendingPrematureCommitments);
|
||||
};
|
||||
auto fCommitWait = [this] {
|
||||
auto fCommitStart = [this, &peerman]() { curSession->VerifyAndCommit(pendingPrematureCommitments, peerman); };
|
||||
auto fCommitWait = [this, &peerman] {
|
||||
return ProcessPendingMessageBatch<CDKGPrematureCommitment, MSG_QUORUM_PREMATURE_COMMITMENT>(
|
||||
connman, m_peerman.get(), *curSession, pendingPrematureCommitments, 8);
|
||||
connman, *curSession, pendingPrematureCommitments, peerman, 8);
|
||||
};
|
||||
HandlePhase(QuorumPhase::Commit, QuorumPhase::Finalize, curQuorumHash, 0.1, fCommitStart, fCommitWait);
|
||||
|
||||
auto finalCommitments = curSession->FinalizeCommitments();
|
||||
for (const auto& fqc : finalCommitments) {
|
||||
if (auto inv_opt = quorumBlockProcessor.AddMineableCommitment(fqc); inv_opt.has_value()) {
|
||||
Assert(m_peerman.get())->RelayInv(inv_opt.value());
|
||||
peerman.RelayInv(inv_opt.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDKGSessionHandler::PhaseHandlerThread()
|
||||
void CDKGSessionHandler::PhaseHandlerThread(PeerManager& peerman)
|
||||
{
|
||||
while (!stopRequested) {
|
||||
try {
|
||||
LogPrint(BCLog::LLMQ_DKG, "CDKGSessionHandler::%s -- %s qi[%d] - starting HandleDKGRound\n", __func__, params.name, quorumIndex);
|
||||
HandleDKGRound();
|
||||
HandleDKGRound(peerman);
|
||||
} catch (AbortPhaseException& e) {
|
||||
dkgDebugManager.UpdateLocalSessionStatus(params.type, quorumIndex, [&](CDKGDebugSessionStatus& status) {
|
||||
status.statusBits.aborted = true;
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
#include <net.h> // for NodeId
|
||||
|
||||
#include <gsl/pointers.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@ -65,7 +63,6 @@ public:
|
||||
using BinaryMessage = std::pair<NodeId, std::shared_ptr<CDataStream>>;
|
||||
|
||||
private:
|
||||
std::atomic<PeerManager*> m_peerman{nullptr};
|
||||
const int invType;
|
||||
const size_t maxMessagesPerNode;
|
||||
mutable Mutex cs_messages;
|
||||
@ -77,18 +74,18 @@ public:
|
||||
explicit CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType) :
|
||||
invType(_invType), maxMessagesPerNode(_maxMessagesPerNode) {};
|
||||
|
||||
void PushPendingMessage(NodeId from, PeerManager* peerman, CDataStream& vRecv);
|
||||
void PushPendingMessage(NodeId from, CDataStream& vRecv, PeerManager& peerman);
|
||||
std::list<BinaryMessage> PopPendingMessages(size_t maxCount);
|
||||
bool HasSeen(const uint256& hash) const;
|
||||
void Misbehaving(NodeId from, int score);
|
||||
void Misbehaving(NodeId from, int score, PeerManager& peerman);
|
||||
void Clear();
|
||||
|
||||
template <typename Message>
|
||||
void PushPendingMessage(NodeId from, PeerManager* peerman, Message& msg)
|
||||
void PushPendingMessage(NodeId from, Message& msg, PeerManager& peerman)
|
||||
{
|
||||
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ds << msg;
|
||||
PushPendingMessage(from, peerman, ds);
|
||||
PushPendingMessage(from, ds, peerman);
|
||||
}
|
||||
|
||||
// Might return nullptr messages, which indicates that deserialization failed for some reason
|
||||
@ -140,7 +137,6 @@ private:
|
||||
CQuorumBlockProcessor& quorumBlockProcessor;
|
||||
const CActiveMasternodeManager* const m_mn_activeman;
|
||||
const CSporkManager& m_sporkman;
|
||||
const std::unique_ptr<PeerManager>& m_peerman;
|
||||
const Consensus::LLMQParams params;
|
||||
const int quorumIndex;
|
||||
|
||||
@ -160,16 +156,17 @@ private:
|
||||
CDKGPendingMessages pendingPrematureCommitments;
|
||||
|
||||
public:
|
||||
CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman,
|
||||
CDKGDebugManager& _dkgDebugManager, CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman,
|
||||
CDKGSessionHandler(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman,
|
||||
CDeterministicMNManager& dmnman, CDKGDebugManager& _dkgDebugManager,
|
||||
CDKGSessionManager& _dkgManager, CMasternodeMetaMan& mn_metaman,
|
||||
CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman,
|
||||
const CSporkManager& sporkman, const std::unique_ptr<PeerManager>& peerman, const Consensus::LLMQParams& _params, int _quorumIndex);
|
||||
const CSporkManager& sporkman, const Consensus::LLMQParams& _params, int _quorumIndex);
|
||||
~CDKGSessionHandler();
|
||||
|
||||
void UpdatedBlockTip(const CBlockIndex *pindexNew);
|
||||
void ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv);
|
||||
void ProcessMessage(const CNode& pfrom, PeerManager& peerman, const std::string& msg_type, CDataStream& vRecv);
|
||||
|
||||
void StartThread();
|
||||
void StartThread(PeerManager& peerman);
|
||||
void StopThread();
|
||||
|
||||
bool GetContribution(const uint256& hash, CDKGContribution& ret) const;
|
||||
@ -194,8 +191,8 @@ private:
|
||||
void WaitForNewQuorum(const uint256& oldQuorumHash) const;
|
||||
void SleepBeforePhase(QuorumPhase curPhase, const uint256& expectedQuorumHash, double randomSleepFactor, const WhileWaitFunc& runWhileWaiting) const;
|
||||
void HandlePhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256& expectedQuorumHash, double randomSleepFactor, const StartPhaseFunc& startPhaseFunc, const WhileWaitFunc& runWhileWaiting);
|
||||
void HandleDKGRound();
|
||||
void PhaseHandlerThread();
|
||||
void HandleDKGRound(PeerManager& peerman);
|
||||
void PhaseHandlerThread(PeerManager& peerman);
|
||||
};
|
||||
|
||||
} // namespace llmq
|
||||
|
@ -29,10 +29,11 @@ static const std::string DB_VVEC = "qdkg_V";
|
||||
static const std::string DB_SKCONTRIB = "qdkg_S";
|
||||
static const std::string DB_ENC_CONTRIB = "qdkg_E";
|
||||
|
||||
CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman,
|
||||
CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman,
|
||||
const std::unique_ptr<PeerManager>& peerman, bool unitTests, bool fWipe) :
|
||||
CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman,
|
||||
CDeterministicMNManager& dmnman, CDKGDebugManager& _dkgDebugManager,
|
||||
CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman,
|
||||
const CSporkManager& sporkman, bool unitTests, bool fWipe) :
|
||||
db(std::make_unique<CDBWrapper>(unitTests ? "" : (gArgs.GetDataDirNet() / "llmq/dkgdb"), 1 << 20, unitTests, fWipe)),
|
||||
blsWorker(_blsWorker),
|
||||
m_chainstate(chainstate),
|
||||
@ -51,19 +52,20 @@ CDKGSessionManager::CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chai
|
||||
for (const auto& params : consensus_params.llmqs) {
|
||||
auto session_count = (params.useRotation) ? params.signingActiveQuorumCount : 1;
|
||||
for (const auto i : irange::range(session_count)) {
|
||||
dkgSessionHandlers.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(params.type, i),
|
||||
std::forward_as_tuple(blsWorker, m_chainstate, connman, dmnman, dkgDebugManager, *this, mn_metaman,
|
||||
quorumBlockProcessor, mn_activeman, spork_manager, peerman, params, i));
|
||||
dkgSessionHandlers.emplace(std::piecewise_construct, std::forward_as_tuple(params.type, i),
|
||||
std::forward_as_tuple(blsWorker, m_chainstate, connman, dmnman, dkgDebugManager,
|
||||
*this, mn_metaman, quorumBlockProcessor, mn_activeman,
|
||||
spork_manager, params, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDKGSessionManager::~CDKGSessionManager() = default;
|
||||
void CDKGSessionManager::StartThreads()
|
||||
|
||||
void CDKGSessionManager::StartThreads(PeerManager& peerman)
|
||||
{
|
||||
for (auto& it : dkgSessionHandlers) {
|
||||
it.second.StartThread();
|
||||
it.second.StartThread(peerman);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +92,8 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni
|
||||
}
|
||||
}
|
||||
|
||||
PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager* peerman, bool is_masternode, const std::string& msg_type, CDataStream& vRecv)
|
||||
PeerMsgRet CDKGSessionManager::ProcessMessage(CNode& pfrom, PeerManager& peerman, bool is_masternode,
|
||||
const std::string& msg_type, CDataStream& vRecv)
|
||||
{
|
||||
static Mutex cs_indexedQuorumsCache;
|
||||
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>> indexedQuorumsCache GUARDED_BY(cs_indexedQuorumsCache);
|
||||
|
@ -71,18 +71,19 @@ private:
|
||||
mutable std::map<ContributionsCacheKey, ContributionsCacheEntry> contributionsCache GUARDED_BY(contributionsCacheCs);
|
||||
|
||||
public:
|
||||
CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDeterministicMNManager& dmnman,
|
||||
CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman, CQuorumBlockProcessor& _quorumBlockProcessor,
|
||||
const CActiveMasternodeManager* const mn_activeman, const CSporkManager& sporkman,
|
||||
const std::unique_ptr<PeerManager>& peerman, bool unitTests, bool fWipe);
|
||||
CDKGSessionManager(CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman,
|
||||
CDeterministicMNManager& dmnman, CDKGDebugManager& _dkgDebugManager, CMasternodeMetaMan& mn_metaman,
|
||||
CQuorumBlockProcessor& _quorumBlockProcessor, const CActiveMasternodeManager* const mn_activeman,
|
||||
const CSporkManager& sporkman, bool unitTests, bool fWipe);
|
||||
~CDKGSessionManager();
|
||||
|
||||
void StartThreads();
|
||||
void StartThreads(PeerManager& peerman);
|
||||
void StopThreads();
|
||||
|
||||
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload);
|
||||
|
||||
PeerMsgRet ProcessMessage(CNode& pfrom, PeerManager* peerman, bool is_masternode, const std::string& msg_type, CDataStream& vRecv);
|
||||
PeerMsgRet ProcessMessage(CNode& pfrom, PeerManager& peerman, bool is_masternode, const std::string& msg_type,
|
||||
CDataStream& vRecv);
|
||||
bool AlreadyHave(const CInv& inv) const;
|
||||
bool GetContribution(const uint256& hash, CDKGContribution& ret) const;
|
||||
bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const;
|
||||
|
@ -5262,7 +5262,7 @@ void PeerManagerImpl::ProcessMessage(
|
||||
ProcessPeerMsgRet(m_govman.ProcessMessage(pfrom, m_connman, *this, msg_type, vRecv), pfrom);
|
||||
ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, peer->m_their_services, m_connman, m_mn_metaman, m_mn_activeman, m_chainman.ActiveChain(), m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom);
|
||||
PostProcessMessage(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom.GetId());
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, this, is_masternode, msg_type, vRecv), pfrom);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, *this, is_masternode, msg_type, vRecv), pfrom);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
m_llmq_ctx->shareman->ProcessMessage(pfrom, m_sporkman, msg_type, vRecv);
|
||||
ProcessPeerMsgRet(m_llmq_ctx->sigman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
|
||||
|
Loading…
Reference in New Issue
Block a user