Skip to content

feat: add computePtcIndices and computePtcIndicesForEpoch - #24

Open
guha-rahul wants to merge 8 commits into
ChainSafe:mainfrom
guha-rahul:compute_ptc
Open

guha-rahul wants to merge 8 commits into
ChainSafe:mainfrom
guha-rahul:compute_ptc

Conversation

@guha-rahul

Copy link
Copy Markdown

Motivation

ChainSafe/lodestar#9013

Description

This pr implements compute_ptc_indices which will be used in computePayloadTimelinessCommitteesForSlot in lodestar and compute_ptc_indices_for_epochwhich will be used in computePayloadTimelinessCommitteesForEpoch.

Current benchmark

  computePtcIndices - per slot
    ✔ naive JS - computePtcIndices - 16384 indices                        44.12140 ops/s    22.66474 ms/op        -         16 runs  0.865 s
    ✔ RS - computePtcIndices - 16384 indices                              11686.75 ops/s    85.56700 us/op   x0.940       2468 runs  0.303 s
    ✔ naive JS - computePtcIndices - 250000 indices                       45.97564 ops/s    21.75065 ms/op        -         16 runs  0.854 s
    ✔ RS - computePtcIndices - 250000 indices                             12001.06 ops/s    83.32600 us/op   x0.938       2576 runs  0.303 s
    ✔ naive JS - computePtcIndices - 1000000 indices                      42.18472 ops/s    23.70527 ms/op        -         11 runs  0.763 s
    ✔ RS - computePtcIndices - 1000000 indices                            11059.13 ops/s    90.42300 us/op   x1.041       2293 runs  0.303 s

  computePtcIndicesForEpoch - full epoch (32 slots)
    ✔ naive JS - computePtcForEpoch - 250000 validators                   1.358208 ops/s    736.2640 ms/op        -         10 runs   8.28 s
    ✔ RS - computePtcIndicesForEpoch - 250000 validators                  1392.591 ops/s    718.0860 us/op        -        266 runs  0.704 s
    ✔ naive JS - computePtcForEpoch - 1000000 validators                  1.344093 ops/s    743.9963 ms/op        -         10 runs   8.21 s
    ✔ RS - computePtcIndicesForEpoch - 1000000 validators                 1375.149 ops/s    727.1940 us/op        -        274 runs  0.703 s

nazarhussain added a commit to ChainSafe/lodestar-z that referenced this pull request Aug 27, 2026
## Summary

Adds payload timeliness committee (PTC) sampling to the Zig
`swap_or_not_shuffle` module and its JS binding, so
ChainSafe/lodestar#9263 can stop computing it in JS.

- Ports `compute_ptc_indices` and `compute_ptc_indices_for_epoch`, whose
original implementation is ChainSafe/swap-or-not-shuffle#24
(`453b639b`).
- Exposes a per-slot entry point and a whole-epoch one that derives each
slot's seed and returns the committees concatenated.
- Returns explicit errors for degenerate inputs that the reference
package would crash or hang on.
- Runs the epoch variant sequentially where the Rust uses rayon; still
roughly 287x the naive JS path Lodestar uses today.

## Testing

- Added Zig vectors generated from the naive Lodestar sampler, plus
epoch/per-slot consistency and error-path coverage.
- Added JS tests comparing the binding against the naive sampler at full
PTC size for one slot and across a full epoch.
- Added per-slot and per-epoch benches alongside the existing shuffle
ones.

## Follow-ups

- The epoch variant can be parallelised if its sequential cost ever
matters.

AI assistance was used for drafting and implementation support.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: bing <spiralladder@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant