Repository navigation
fix: keep a background chainstate's BLS scheme off other threads #8066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
34233a1
a83ceb3
7e080ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -825,8 +825,8 @@ std::set<size_t> CBLSWorker::FindVerificationVectorsWithSharedCoefficients(Span< | |
|
|
||
| void CBLSWorker::AsyncSign(const CBLSSecretKey& secKey, const uint256& msgHash, const CBLSWorker::SignDoneCallback& doneCallback) | ||
| { | ||
| workerPool.push([secKey, msgHash, doneCallback](int threadId) { | ||
| doneCallback(secKey.Sign(msgHash, bls::bls_legacy_scheme.load())); | ||
| workerPool.push([secKey, msgHash, doneCallback, legacy = bls::EffectiveLegacyScheme()](int threadId) { | ||
| doneCallback(secKey.Sign(msgHash, legacy)); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -838,18 +838,19 @@ void CBLSWorker::AsyncVerifySig(const CBLSSignature& sig, const CBLSPublicKey& p | |
| return; | ||
| } | ||
|
|
||
| const bool legacy{bls::EffectiveLegacyScheme()}; | ||
| std::unique_lock<std::mutex> l(sigVerifyMutex); | ||
|
|
||
| bool foundDuplicate = std::ranges::any_of(sigVerifyQueue, | ||
| [&msgHash](const auto& job) { return job.msgHash == msgHash; }); | ||
|
|
||
| if (foundDuplicate) { | ||
| // batched/aggregated verification does not allow duplicate hashes, so we push what we currently have and start | ||
| // with a fresh batch | ||
| if (foundDuplicate || (!sigVerifyQueue.empty() && sigVerifyQueue.front().legacyScheme != legacy)) { | ||
| // batched/aggregated verification does not allow duplicate hashes or mixed schemes, so we push what we | ||
| // currently have and start with a fresh batch | ||
| PushSigVerifyBatch(); | ||
| } | ||
|
|
||
| sigVerifyQueue.emplace_back(std::move(doneCallback), std::move(cancelCond), sig, pubKey, msgHash); | ||
| sigVerifyQueue.emplace_back(std::move(doneCallback), std::move(cancelCond), sig, pubKey, msgHash, legacy); | ||
|
Comment on lines
+847
to
+853
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Add regression coverage for worker scheme capture and mixed-scheme queueing The PR changes CBLSWorker::AsyncSign and AsyncVerifySig to capture the submitting scheme and adds this mixed-scheme queue-flush condition, but no unit test invokes either worker API. The new CBLSBatchVerifier and BlsCheck tests exercise separate implementations, and AsyncVerifySig's only external caller is the benchmark, so the functional suites do not cover this queue behavior either. Add deterministic coverage in bls_tests using worker.Start(1) and a promise-controlled callback to hold the worker while jobs are submitted under both scoped schemes. Verify signing, singleton and aggregated verification, per-signature fallback, and opposite-scheme rejection after the submitting scopes have ended and the process default differs from the queued jobs' schemes. This would catch loss of a scheme capture or removal of the flush condition without timing-dependent sleeps. source:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, and added in ba207fc, folded into "refactor(bls): resolve the implicit BLS scheme per thread":
Each of these mutants fails the test: 🤖 Posted autonomously by Claude on behalf of pasta.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved (re-reviewed at |
||
| if (sigVerifyBatchesInProgress == 0 || sigVerifyQueue.size() >= SIG_VERIFY_BATCH_SIZE) { | ||
| PushSigVerifyBatch(); | ||
| } | ||
|
|
@@ -876,7 +877,7 @@ void CBLSWorker::PushSigVerifyBatch() | |
| if (jobs.size() == 1) { | ||
| const auto& job = jobs[0]; | ||
| if (!job.cancelCond()) { | ||
| bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash); | ||
| bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash, job.legacyScheme); | ||
| job.doneCallback(valid); | ||
| } | ||
| std::unique_lock<std::mutex> l(sigVerifyMutex); | ||
|
|
@@ -910,7 +911,7 @@ void CBLSWorker::PushSigVerifyBatch() | |
| } | ||
|
|
||
| if (!pubKeys.empty()) { | ||
| bool allValid = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes); | ||
| bool allValid = aggSig.VerifyInsecureAggregated(pubKeys, msgHashes, jobs.front().legacyScheme); | ||
| if (allValid) { | ||
| for (size_t i = 0; i < pubKeys.size(); i++) { | ||
| jobs[indexes[i]].doneCallback(true); | ||
|
|
@@ -920,7 +921,7 @@ void CBLSWorker::PushSigVerifyBatch() | |
| // TODO this could be improved if we would cache pairing results in some way as the previous aggregated verification already calculated all the pairings for the hashes | ||
| for (size_t i = 0; i < pubKeys.size(); i++) { | ||
| const auto& job = jobs[indexes[i]]; | ||
| bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash); | ||
| bool valid = job.sig.VerifyInsecure(job.pubKey, job.msgHash, job.legacyScheme); | ||
| job.doneCallback(valid); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.