@@ -76,7 +76,7 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, PeerManager* peerman,
76
76
EraseObjectRequest (from, CInv (invType, hash));
77
77
}
78
78
79
- LOCK (cs );
79
+ LOCK (cs_messages );
80
80
81
81
if (messagesPerNode[from] >= maxMessagesPerNode) {
82
82
// TODO ban?
@@ -95,7 +95,7 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, PeerManager* peerman,
95
95
96
96
std::list<CDKGPendingMessages::BinaryMessage> CDKGPendingMessages::PopPendingMessages (size_t maxCount)
97
97
{
98
- LOCK (cs );
98
+ LOCK (cs_messages );
99
99
100
100
std::list<BinaryMessage> ret;
101
101
while (!pendingMessages.empty () && ret.size () < maxCount) {
@@ -108,7 +108,7 @@ std::list<CDKGPendingMessages::BinaryMessage> CDKGPendingMessages::PopPendingMes
108
108
109
109
bool CDKGPendingMessages::HasSeen (const uint256& hash) const
110
110
{
111
- LOCK (cs );
111
+ LOCK (cs_messages );
112
112
return seenMessages.count (hash) != 0 ;
113
113
}
114
114
@@ -120,7 +120,7 @@ void CDKGPendingMessages::Misbehaving(const NodeId from, const int score)
120
120
121
121
void CDKGPendingMessages::Clear ()
122
122
{
123
- LOCK (cs );
123
+ LOCK (cs_messages );
124
124
pendingMessages.clear ();
125
125
messagesPerNode.clear ();
126
126
seenMessages.clear ();
@@ -135,7 +135,7 @@ void CDKGSessionHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
135
135
if (quorumIndex > 0 && !IsQuorumRotationEnabled (params, pindexNew)) {
136
136
return ;
137
137
}
138
- LOCK (cs );
138
+ LOCK (cs_phase_qhash );
139
139
140
140
int quorumStageInt = (pindexNew->nHeight - quorumIndex) % params.dkgInterval ;
141
141
@@ -207,7 +207,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
207
207
208
208
std::pair<QuorumPhase, uint256> CDKGSessionHandler::GetPhaseAndQuorumHash () const
209
209
{
210
- LOCK (cs );
210
+ LOCK (cs_phase_qhash );
211
211
return std::make_pair (phase, quorumHash);
212
212
}
213
213
@@ -304,9 +304,8 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase,
304
304
305
305
int64_t sleepTime = (int64_t )(adjustedPhaseSleepTimePerMember * curSession->GetMyMemberIndex ().value_or (0 ));
306
306
int64_t endTime = GetTimeMillis () + sleepTime;
307
- int heightTmp{-1 };
308
- int heightStart{-1 };
309
- heightTmp = heightStart = WITH_LOCK (cs, return currentHeight);
307
+ int heightTmp{currentHeight.load ()};
308
+ int heightStart{heightTmp};
310
309
311
310
LogPrint (BCLog::LLMQ_DKG, " CDKGSessionManager::%s -- %s qi[%d] - starting sleep for %d ms, curPhase=%d\n " , __func__, params.name , quorumIndex, sleepTime, ToUnderlying (curPhase));
312
311
@@ -315,22 +314,20 @@ void CDKGSessionHandler::SleepBeforePhase(QuorumPhase curPhase,
315
314
LogPrint (BCLog::LLMQ_DKG, " CDKGSessionManager::%s -- %s qi[%d] - aborting due to stop/shutdown requested\n " , __func__, params.name , quorumIndex);
316
315
throw AbortPhaseException ();
317
316
}
318
- {
319
- LOCK (cs);
320
- if (currentHeight > heightTmp) {
321
- // New block(s) just came in
322
- int64_t expectedBlockTime = (currentHeight - heightStart) * Params ().GetConsensus ().nPowTargetSpacing * 1000 ;
323
- if (expectedBlockTime > sleepTime) {
324
- // Blocks came faster than we expected, jump into the phase func asap
325
- break ;
326
- }
327
- heightTmp = currentHeight;
328
- }
329
- if (phase != curPhase || quorumHash != expectedQuorumHash) {
330
- // Something went wrong and/or we missed quite a few blocks and it's just too late now
331
- LogPrint (BCLog::LLMQ_DKG, " CDKGSessionManager::%s -- %s qi[%d] - aborting due unexpected phase/expectedQuorumHash change\n " , __func__, params.name , quorumIndex);
332
- throw AbortPhaseException ();
317
+ auto cur_height = currentHeight.load ();
318
+ if (cur_height > heightTmp) {
319
+ // New block(s) just came in
320
+ int64_t expectedBlockTime = (cur_height - heightStart) * Params ().GetConsensus ().nPowTargetSpacing * 1000 ;
321
+ if (expectedBlockTime > sleepTime) {
322
+ // Blocks came faster than we expected, jump into the phase func asap
323
+ break ;
333
324
}
325
+ heightTmp = cur_height;
326
+ }
327
+ if (WITH_LOCK (cs_phase_qhash, return phase != curPhase || quorumHash != expectedQuorumHash)) {
328
+ // Something went wrong and/or we missed quite a few blocks and it's just too late now
329
+ LogPrint (BCLog::LLMQ_DKG, " CDKGSessionManager::%s -- %s qi[%d] - aborting due unexpected phase/expectedQuorumHash change\n " , __func__, params.name , quorumIndex);
330
+ throw AbortPhaseException ();
334
331
}
335
332
if (!runWhileWaiting ()) {
336
333
UninterruptibleSleep (std::chrono::milliseconds{100 });
@@ -505,18 +502,13 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
505
502
506
503
void CDKGSessionHandler::HandleDKGRound ()
507
504
{
508
- uint256 curQuorumHash;
509
-
510
505
WaitForNextPhase (std::nullopt , QuorumPhase::Initialized);
511
506
512
- {
513
- LOCK (cs);
514
- pendingContributions.Clear ();
515
- pendingComplaints.Clear ();
516
- pendingJustifications.Clear ();
517
- pendingPrematureCommitments.Clear ();
518
- curQuorumHash = quorumHash;
519
- }
507
+ pendingContributions.Clear ();
508
+ pendingComplaints.Clear ();
509
+ pendingJustifications.Clear ();
510
+ pendingPrematureCommitments.Clear ();
511
+ uint256 curQuorumHash = WITH_LOCK (cs_phase_qhash, return quorumHash);
520
512
521
513
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK (cs_main, return m_chainstate.m_blockman .LookupBlockIndex (curQuorumHash));
522
514
0 commit comments