Skip to content

Commit c4ca959

Browse files
Merge #6972: fix: move more_work calculation into CollectPendingRecoveredSigsToVerify replacing incorrect logic in ProcessPendingRecoveredSigs
3b948d2 fix: update CollectPendingSigSharesToVerify to return work status instead of a constant true (pasta) 72c3efc fix: move `more_work` calculation into CollectPendingRecoveredSigsToVerify replacing incorrect logic in ProcessPendingRecoveredSigs (pasta) Pull request description: ## Issue being fixed or feature implemented I believe the current "moreWork" logic in ProcessPendingRecoveredSigs is improper, and always or almost always returns false. I believe the check `recSigsByNode.size() >= nMaxBatchSize` will only report as "needs more work" if the **number of nodes** we are verifying regSigs from is more than 32; **rather than** performing aggregation / verification on 32 recSigs. ## What was done? Move moreWork logic into ProcessPendingRecoveredSigs ## How Has This Been Tested? Builds ## Breaking Changes _Please describe any breaking changes your code introduces_ ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 3b948d2 kwvg: utACK 3b948d2 Tree-SHA512: 8fba0d0364b15af618d46d752d218a61d5c19f26d3d8d401724ad84c4cf16f85b49e5da4f8d4b4056291e17864e5d0d440e7e0cc0c18c4ab6e43258be4438d1e
2 parents 9590d57 + 3b948d2 commit c4ca959

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/llmq/signing.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,17 @@ MessageProcessingResult CSigningManager::ProcessMessage(NodeId from, std::string
435435
return ret;
436436
}
437437

438-
void CSigningManager::CollectPendingRecoveredSigsToVerify(
438+
bool CSigningManager::CollectPendingRecoveredSigsToVerify(
439439
size_t maxUniqueSessions,
440440
std::unordered_map<NodeId, std::list<std::shared_ptr<const CRecoveredSig>>>& retSigShares,
441441
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher>& retQuorums)
442442
{
443+
bool more_work{false};
444+
443445
{
444446
LOCK(cs_pending);
445447
if (pendingRecoveredSigs.empty()) {
446-
return;
448+
return false;
447449
}
448450

449451
// TODO: refactor it to remove duplicated code with `CSigSharesManager::CollectPendingSigSharesToVerify`
@@ -466,8 +468,12 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
466468
}, rnd);
467469

468470
if (retSigShares.empty()) {
469-
return;
471+
return false;
470472
}
473+
474+
more_work = std::any_of(pendingRecoveredSigs.begin(), pendingRecoveredSigs.end(),
475+
[](const auto& p) { return !p.second.empty(); }) ||
476+
!pendingReconstructedRecoveredSigs.empty();
471477
}
472478

473479
for (auto& p : retSigShares) {
@@ -500,6 +506,8 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
500506
++it;
501507
}
502508
}
509+
510+
return more_work;
503511
}
504512

505513
void CSigningManager::ProcessPendingReconstructedRecoveredSigs(PeerManager& peerman)
@@ -520,7 +528,7 @@ bool CSigningManager::ProcessPendingRecoveredSigs(PeerManager& peerman)
520528
ProcessPendingReconstructedRecoveredSigs(peerman);
521529

522530
const size_t nMaxBatchSize{32};
523-
CollectPendingRecoveredSigsToVerify(nMaxBatchSize, recSigsByNode, quorums);
531+
bool more_work = CollectPendingRecoveredSigsToVerify(nMaxBatchSize, recSigsByNode, quorums);
524532
if (recSigsByNode.empty()) {
525533
return false;
526534
}
@@ -574,7 +582,7 @@ bool CSigningManager::ProcessPendingRecoveredSigs(PeerManager& peerman)
574582
}
575583
}
576584

577-
return recSigsByNode.size() >= nMaxBatchSize;
585+
return more_work;
578586
}
579587

580588
// signature must be verified already

src/llmq/signing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CSigningManager
209209
void TruncateRecoveredSig(Consensus::LLMQType llmqType, const uint256& id);
210210

211211
private:
212-
void CollectPendingRecoveredSigsToVerify(
212+
bool CollectPendingRecoveredSigsToVerify(
213213
size_t maxUniqueSessions, std::unordered_map<NodeId, std::list<std::shared_ptr<const CRecoveredSig>>>& retSigShares,
214214
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher>& retQuorums)
215215
EXCLUSIVE_LOCKS_REQUIRED(!cs_pending);

src/llmq/signing_shares.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ bool CSigSharesManager::CollectPendingSigSharesToVerify(
568568
size_t maxUniqueSessions, std::unordered_map<NodeId, std::vector<CSigShare>>& retSigShares,
569569
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher>& retQuorums)
570570
{
571+
bool more_work{false};
572+
571573
{
572574
LOCK(cs);
573575
if (nodeStates.empty()) {
@@ -606,6 +608,13 @@ bool CSigSharesManager::CollectPendingSigSharesToVerify(
606608
if (retSigShares.empty()) {
607609
return false;
608610
}
611+
612+
// Determine if there is still work left in any node state after pulling this batch
613+
more_work = std::any_of(nodeStates.begin(), nodeStates.end(),
614+
[](const auto& entry) {
615+
const auto& ns = entry.second;
616+
return !ns.pendingIncomingSigShares.Empty();
617+
});
609618
}
610619

611620
// For the convenience of the caller, also build a map of quorumHash -> quorum
@@ -632,7 +641,7 @@ bool CSigSharesManager::CollectPendingSigSharesToVerify(
632641
}
633642
}
634643

635-
return true;
644+
return more_work;
636645
}
637646

638647
bool CSigSharesManager::ProcessPendingSigShares()
@@ -641,8 +650,8 @@ bool CSigSharesManager::ProcessPendingSigShares()
641650
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher> quorums;
642651

643652
const size_t nMaxBatchSize{32};
644-
bool collect_status = CollectPendingSigSharesToVerify(nMaxBatchSize, sigSharesByNodes, quorums);
645-
if (!collect_status || sigSharesByNodes.empty()) {
653+
bool more_work = CollectPendingSigSharesToVerify(nMaxBatchSize, sigSharesByNodes, quorums);
654+
if (sigSharesByNodes.empty()) {
646655
return false;
647656
}
648657

@@ -703,7 +712,7 @@ bool CSigSharesManager::ProcessPendingSigShares()
703712
ProcessPendingSigShares(v, quorums);
704713
}
705714

706-
return sigSharesByNodes.size() >= nMaxBatchSize;
715+
return more_work;
707716
}
708717

709718
// It's ensured that no duplicates are passed to this method

0 commit comments

Comments
 (0)