Skip to content

Commit 01876c7

Browse files
committed
refactor: move PeerManager out of CDKGSession{,Handler,Manager} ctor
1 parent cc0e771 commit 01876c7

10 files changed

+108
-122
lines changed

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
22802280

22812281
// ********************************************************* Step 10a: schedule Dash-specific tasks
22822282

2283-
node.llmq_ctx->Start();
2283+
node.llmq_ctx->Start(*node.peerman);
22842284

22852285
node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(*node.netfulfilledman)), std::chrono::minutes{1});
22862286
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(*node.mn_sync), std::cref(*node.peerman), std::cref(*node.govman)), std::chrono::seconds{1});

src/llmq/context.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LLMQContext::LLMQContext(ChainstateManager& chainman, CConnman& connman, CDeterm
2929
quorum_block_processor{std::make_unique<llmq::CQuorumBlockProcessor>(chainman.ActiveChainstate(), dmnman, evo_db)},
3030
qdkgsman{std::make_unique<llmq::CDKGSessionManager>(*bls_worker, chainman.ActiveChainstate(), connman, dmnman,
3131
*dkg_debugman, mn_metaman, *quorum_block_processor,
32-
mn_activeman, sporkman, peerman, unit_tests, wipe)},
32+
mn_activeman, sporkman, unit_tests, wipe)},
3333
qman{std::make_unique<llmq::CQuorumManager>(*bls_worker, chainman.ActiveChainstate(), connman, dmnman, *qdkgsman,
3434
evo_db, *quorum_block_processor, mn_activeman, mn_sync, sporkman,
3535
unit_tests, wipe)},
@@ -74,12 +74,13 @@ void LLMQContext::Interrupt() {
7474
llmq::quorumInstantSendManager->InterruptWorkerThread();
7575
}
7676

77-
void LLMQContext::Start() {
77+
void LLMQContext::Start(PeerManager& peerman)
78+
{
7879
assert(clhandler == llmq::chainLocksHandler.get());
7980
assert(isman == llmq::quorumInstantSendManager.get());
8081

8182
if (is_masternode) {
82-
qdkgsman->StartThreads();
83+
qdkgsman->StartThreads(peerman);
8384
}
8485
qman->Start();
8586
shareman->RegisterAsRecoveredSigsListener();

src/llmq/context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct LLMQContext {
4646
~LLMQContext();
4747

4848
void Interrupt();
49-
void Start();
49+
void Start(PeerManager& peerman);
5050
void Stop();
5151

5252
/** Guaranteed if LLMQContext is initialized then all members are valid too

src/llmq/dkgsession.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ bool CDKGSession::Init(const uint256& _myProTxHash, int _quorumIndex)
156156
return true;
157157
}
158158

159-
void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages)
159+
void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
160160
{
161161
CDKGLogger logger(*this, __func__, __LINE__);
162162

@@ -174,10 +174,10 @@ void CDKGSession::Contribute(CDKGPendingMessages& pendingMessages)
174174
logger.Batch("generated contributions. time=%d", t1.count());
175175
logger.Flush();
176176

177-
SendContributions(pendingMessages);
177+
SendContributions(pendingMessages, peerman);
178178
}
179179

180-
void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages)
180+
void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
181181
{
182182
CDKGLogger logger(*this, __func__, __LINE__);
183183

@@ -226,7 +226,7 @@ void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages)
226226
return true;
227227
});
228228

229-
pendingMessages.PushPendingMessage(-1, nullptr, qc);
229+
pendingMessages.PushPendingMessage(-1, qc, peerman);
230230
}
231231

232232
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification
@@ -417,7 +417,7 @@ void CDKGSession::VerifyPendingContributions()
417417
pendingContributionVerifications.clear();
418418
}
419419

420-
void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
420+
void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
421421
{
422422
if (!AreWeMember()) {
423423
return;
@@ -455,7 +455,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
455455

456456
VerifyConnectionAndMinProtoVersions();
457457

458-
SendComplaint(pendingMessages);
458+
SendComplaint(pendingMessages, peerman);
459459
}
460460

461461
void CDKGSession::VerifyConnectionAndMinProtoVersions() const
@@ -499,7 +499,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const
499499
}
500500
}
501501

502-
void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages)
502+
void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
503503
{
504504
CDKGLogger logger(*this, __func__, __LINE__);
505505

@@ -538,7 +538,7 @@ void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages)
538538
return true;
539539
});
540540

541-
pendingMessages.PushPendingMessage(-1, nullptr, qc);
541+
pendingMessages.PushPendingMessage(-1, qc, peerman);
542542
}
543543

544544
// 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)
645645
return inv;
646646
}
647647

648-
void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages)
648+
void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
649649
{
650650
if (!AreWeMember()) {
651651
return;
@@ -682,11 +682,12 @@ void CDKGSession::VerifyAndJustify(CDKGPendingMessages& pendingMessages)
682682

683683
logger.Flush();
684684
if (!justifyFor.empty()) {
685-
SendJustification(pendingMessages, justifyFor);
685+
SendJustification(pendingMessages, peerman, justifyFor);
686686
}
687687
}
688688

689-
void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const std::set<uint256>& forMembers)
689+
void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman,
690+
const std::set<uint256>& forMembers)
690691
{
691692
CDKGLogger logger(*this, __func__, __LINE__);
692693

@@ -731,7 +732,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const
731732
return true;
732733
});
733734

734-
pendingMessages.PushPendingMessage(-1, nullptr, qj);
735+
pendingMessages.PushPendingMessage(-1, qj, peerman);
735736
}
736737

737738
// 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)
885886
return inv;
886887
}
887888

888-
void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages)
889+
void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
889890
{
890891
if (!AreWeMember()) {
891892
return;
@@ -927,10 +928,10 @@ void CDKGSession::VerifyAndCommit(CDKGPendingMessages& pendingMessages)
927928

928929
logger.Flush();
929930

930-
SendCommitment(pendingMessages);
931+
SendCommitment(pendingMessages, peerman);
931932
}
932933

933-
void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
934+
void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages, PeerManager& peerman)
934935
{
935936
CDKGLogger logger(*this, __func__, __LINE__);
936937

@@ -1041,7 +1042,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
10411042
return true;
10421043
});
10431044

1044-
pendingMessages.PushPendingMessage(-1, nullptr, qc);
1045+
pendingMessages.PushPendingMessage(-1, qc, peerman);
10451046
}
10461047

10471048
// only performs cheap verifications, but not the signature of the message. this is checked with batched verification

src/llmq/dkgsession.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CConnman;
2222
class CDeterministicMN;
2323
class CMasternodeMetaMan;
2424
class CSporkManager;
25+
class PeerManager;
2526

2627
using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;
2728

@@ -349,28 +350,28 @@ class CDKGSession
349350
*/
350351

351352
// Phase 1: contribution
352-
void Contribute(CDKGPendingMessages& pendingMessages);
353-
void SendContributions(CDKGPendingMessages& pendingMessages);
353+
void Contribute(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
354+
void SendContributions(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
354355
bool PreVerifyMessage(const CDKGContribution& qc, bool& retBan) const;
355356
std::optional<CInv> ReceiveMessage(const CDKGContribution& qc);
356357
void VerifyPendingContributions() EXCLUSIVE_LOCKS_REQUIRED(cs_pending);
357358

358359
// Phase 2: complaint
359-
void VerifyAndComplain(CDKGPendingMessages& pendingMessages);
360+
void VerifyAndComplain(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
360361
void VerifyConnectionAndMinProtoVersions() const;
361-
void SendComplaint(CDKGPendingMessages& pendingMessages);
362+
void SendComplaint(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
362363
bool PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const;
363364
std::optional<CInv> ReceiveMessage(const CDKGComplaint& qc);
364365

365366
// Phase 3: justification
366-
void VerifyAndJustify(CDKGPendingMessages& pendingMessages);
367-
void SendJustification(CDKGPendingMessages& pendingMessages, const std::set<uint256>& forMembers);
367+
void VerifyAndJustify(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
368+
void SendJustification(CDKGPendingMessages& pendingMessages, PeerManager& peerman, const std::set<uint256>& forMembers);
368369
bool PreVerifyMessage(const CDKGJustification& qj, bool& retBan) const;
369370
std::optional<CInv> ReceiveMessage(const CDKGJustification& qj);
370371

371372
// Phase 4: commit
372-
void VerifyAndCommit(CDKGPendingMessages& pendingMessages);
373-
void SendCommitment(CDKGPendingMessages& pendingMessages);
373+
void VerifyAndCommit(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
374+
void SendCommitment(CDKGPendingMessages& pendingMessages, PeerManager& peerman);
374375
bool PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retBan) const;
375376
std::optional<CInv> ReceiveMessage(const CDKGPrematureCommitment& qc);
376377

0 commit comments

Comments
 (0)