perf(consensus): flush crypto batches at block boundary#350
perf(consensus): flush crypto batches at block boundary#350ValarDragon wants to merge 2 commits into
Conversation
Analyzed seven files, diff |
|
Fable comments: Verdict: safe — no race in this PR can cause a block to skip or corrupt verification I traced every concurrency path in PR #350 (explicit crypto-batch flush at the block boundary) and ran its concurrency tests. The design has one property that makes it robust: the flush is purely advisory. It only starts pending batch work earlier; it never decides whether something gets verified. Every race I found degrades to extra latency (falling back to the pre-existing 100ms timer), never to skipped verification. Why verification can't be skipped, regardless of flush timing
Races I traced and their outcomes
Coverage is also complete: every batched service used in block transaction verification (ed25519, sapling, the three per-NU halo2 verifiers) is flushed; groth16 joinsplits are an unbatched ServiceFn, and redjubjub/redpallas aren't in the tx path on this
Coverage is also complete: every batched service used in block transaction g, the three per-NU halo2 verifiers) is flushed; groth16 joinsplits are an unbatched ServiceFn, and redjubjub/redpallas aren't in the tx path on this |
…ase tests - Document that the block batch flush guard must be declared after known_outpoint_hashes, so the registry entry is removed while the Arc address is still pinned and cannot be reused by another block's key. - Test that an explicit flush on an empty batch is a no-op and later batches still verify. - Test that re-registering a reused flush key starts a fresh transaction count instead of inheriting a stale one.
Motivation
Semantic block verification near the chain tip can queue proof/signature batch work and then wait for the global
MAX_BATCH_LATENCYbefore the underlying crypto batch starts. Lowering that latency globally would also affect mempool behavior, so this PR adds a targeted block-verification flush instead.Solution
Batch::flush()to queue an explicit flush command on the existing batch worker.Fallback::primary()so consensus code can flush the primary batched service without changing fallback verification behavior.zebra-consensus::primitives, keyed by the existing per-block sharedknown_outpoint_hashesArc.Tests
cargo fmt --all -- --checkcargo test -p tower-batch-control --test ed25519 batch_flushes_on_explicit_flushcargo test -p zebra-consensus primitives::testscargo test -p tower-batch-control --test ed25519cargo check -p zebra-consensus -p tower-batch-control -p tower-fallback --all-targetscargo clippy -p zebra-consensus -p tower-batch-control -p tower-fallback --all-targets -- -D warningsSpecifications & References
None.
Follow-up Work
AI Disclosure
PR Checklist
type(scope): description