Commit 1d212a1
committed
Merge dashpay#7225: fix: collect sigshares synchronously in dispatcher for parallel verification
018298b fix: collect sigshares synchronously in dispatcher for parallel verification (PastaClaw)
Pull request description:
## Summary
The dispatcher thread in `WorkThreadDispatcher()` unconditionally enqueued a
`ProcessPendingSigShares` worker into the thread pool every 10ms whenever any
`pendingIncomingSigShares` existed. Since the workers would then find nothing
to do and immediately exit, this wasted allocations and queue operations.
This was flagged during review of dashpay#7004 by CodeRabbit as a nitpick but was not
addressed at the time.
## Fix
Move `CollectPendingSigSharesToVerify` out of `ProcessPendingSigShares` and
into the dispatcher loop, where it runs synchronously (it holds `cs` briefly
and does no BLS work). Each collected batch is moved into its own worker for
parallel BLS verification.
This approach (suggested knst) has two advantages over the initial
atomic-guard implementation:
1. **Parallel verification**: Multiple verification batches can run
concurrently across the thread pool (up to 4 workers), instead of being
serialised to a single worker.
2. **Natural queue bounding**: Each `Collect` call dequeues its batch from
the pending queue, so only as many tasks are enqueued as there are actual
batches of work — no redundant empty-exit tasks.
**Performance impact: slight improvement.** Multiple BLS verification batches
can now run in parallel when there are more than 32 pending sig shares
(`nMaxBatchSize`). The collection step is cheap (no BLS ops).
## Validation
- Code review of the dispatch path confirms collect-then-dispatch preserves
the existing drain behavior
- Each `CollectPendingSigSharesToVerify` call removes its batch from the
pending queue, preventing duplicate work across workers
- No functional change to sigshare processing semantics
ACKs for top commit:
UdjinM6:
utACK 018298b
knst:
utACK 018298b
Tree-SHA512: 667f510f7b4a75025cf840bc2835895bd09c25563da1617116b5bb721bf950e9823a4b911f6e86b5a6b8096e70d08d8238e2a2a80f5c2f06db221bdc2a0b2b682 files changed
+26
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
319 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
320 | 328 | | |
321 | 329 | | |
322 | 330 | | |
| |||
329 | 337 | | |
330 | 338 | | |
331 | 339 | | |
332 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
333 | 343 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
| |||
400 | 401 | | |
401 | 402 | | |
402 | 403 | | |
403 | | - | |
404 | | - | |
405 | 404 | | |
406 | 405 | | |
407 | 406 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
0 commit comments