Commit 9fb51b1
committed
fix(commitment): count first-nibble branches in CanDoConcurrentNext to fix flaky test
Test_Trie_CorrectSwitchForConcurrentAndSequential fails intermittently (CI run
22561824327, job 65349926766) because CanDoConcurrentNext() only checks if nibble-0
has a branch node. The test uses a globally-shared rand.NewSource(42) protected by
a mutex, so different parallel test runs consume the random stream at different
offsets — occasionally producing a 150-key set where zero (or one) keys land at
nibble 0 after keccak256 hashing. In that case the function returns false even
though the trie is wide enough to parallelize, causing the require.True at line 280
to fail.
Root cause: arbitrary choice of nibble 0 as the single probe. P(zero keys at nibble
0 with 150 random keccak hashes) ≈ (15/16)^150 ≈ 5.6e-5 per run — invisible in dev
but visible across thousands of CI runs.
Fix: instead of probing a single nibble, count how many of the 16 first-nibble
sub-tries have stored branch data. Require at least 4 to justify spawning 16
parallel goroutines.
- 150 random keys: ~15.997 of 16 nibbles filled (P(< 4 filled) ≈ 0) → true ✓
- 2 remaining keys: at most 2 nibbles filled → false ✓
This makes the decision independent of any particular nibble's occupancy, eliminating
the flakiness while keeping the correct semantic (small key sets → sequential).1 parent 3d203a2 commit 9fb51b1
1 file changed
+25
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
318 | 327 | | |
319 | | - | |
320 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
321 | 338 | | |
322 | | - | |
| 339 | + | |
323 | 340 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
328 | 346 | | |
329 | | - | |
330 | 347 | | |
331 | | - | |
332 | 348 | | |
333 | 349 | | |
334 | 350 | | |
| |||
0 commit comments