Skip to content

Tickets Pool#1004

Merged
tomusdrw merged 4 commits into
mainfrom
td-ticket-pool
Jun 8, 2026
Merged

Tickets Pool#1004
tomusdrw merged 4 commits into
mainfrom
td-ticket-pool

Conversation

@tomusdrw

@tomusdrw tomusdrw commented Jun 8, 2026

Copy link
Copy Markdown
Member

Resolves #954

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 211975fb-a631-47a0-90d8-d9d3b48af502

📥 Commits

Reviewing files that changed from the base of the PR and between 2e4ce67 and 2ac3bb7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (18)
  • package.json
  • packages/jam/jamnp-s/package.json
  • packages/jam/jamnp-s/tasks/ticket-distribution.test.ts
  • packages/jam/jamnp-s/tasks/ticket-distribution.ts
  • packages/jam/ticket-pool/index.ts
  • packages/jam/ticket-pool/package.json
  • packages/jam/ticket-pool/pending-ticket-pool.test.ts
  • packages/jam/ticket-pool/pending-ticket-pool.ts
  • packages/jam/ticket-pool/ticket-validator.test.ts
  • packages/jam/ticket-pool/ticket-validator.ts
  • packages/jam/ticket-pool/verified-ticket-pool.test.ts
  • packages/jam/ticket-pool/verified-ticket-pool.ts
  • packages/workers/block-authorship/main.ts
  • packages/workers/block-authorship/package.json
  • packages/workers/block-authorship/ticket-validator.ts
  • packages/workers/comms-authorship-network/protocol.ts
  • packages/workers/jam-network/main.ts
  • packages/workers/jam-network/package.json

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Introduced a new ticket pool system for managing and validating tickets across epochs with deduplication.
    • Added ticket validator pattern for consistent validation of incoming tickets.
  • Refactor

    • Refactored ticket distribution and validation to use the new pool-based approach and validator strategy pattern instead of callback mechanisms.
    • Improved ticket synchronization between network and block authorship components.

Walkthrough

This PR introduces a new @typeberry/ticket-pool library package containing abstractions for ticket validation and pooling. It refactors TicketDistributionTask to use a PendingTicketPool and TicketValidator strategy instead of internal state and callbacks. Block authorship integrates a VerifiedTicketPool with BandersnatchTicketValidator for cryptographic verification. The jam-network worker bridges validator and pool-sync communication between workers via new protocol messages and IPC validators.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • FluffyLabs/typeberry#923: Both PRs modify ticket distribution task validation; #923 introduces setOnTicketReceived callback which this PR replaces with setTicketValidator and pool-based architecture.
  • FluffyLabs/typeberry#911: This PR builds on #911's ticket distribution refactoring by extracting pooling logic into the new library.
  • FluffyLabs/typeberry#897: Both PRs modify block-authorship ticket flow; #897 adds ticket generation while this PR refactors storage and validation.

Suggested reviewers

  • mateuszsikora
  • skoszuta
  • DrEverr

Poem

🐰 A pool of tickets, validated true,
With bandersnatch VRF and entropy too,
From network to author, they flow and sync,
Abstraction refined with a strategic blink!
The distribution task now stands so lean,
With validators swapped—a review's dream!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Tickets Pool' is vague and generic, using a non-descriptive term that does not clearly convey the specific refactoring changes in the changeset. Consider a more specific title like 'Refactor TicketDistributionTask with TicketValidator abstraction and PendingTicketPool' to better reflect the main refactoring work.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description references the linked issue #954, which is related to the changeset's objectives, making it minimally compliant despite being very brief.
Linked Issues check ✅ Passed The PR fully satisfies all three proposed changes from #954: renaming setOnTicketReceived to setTicketValidator, introducing TicketValidator abstraction with AcceptTicketsValidator/DenyTicketsValidator implementations, and extracting PendingTicketPool and VerifiedTicketPool classes.
Out of Scope Changes check ✅ Passed All changes are within scope; they directly implement the refactoring objectives from #954, including ticket pool implementations, validator abstractions, task updates, and integration in block-authorship and jam-network workers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch td-ticket-pool

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
View all
File Benchmark Ops
bytes/hex-from.ts[0] parse hex using Number with NaN checking 82446.35 ±0.61% 81.18% slower
bytes/hex-from.ts[1] parse hex from char codes 438064.03 ±0.92% fastest ✅
bytes/hex-from.ts[2] parse hex from string nibbles 254928.43 ±1.1% 41.81% slower
bytes/hex-to.ts[0] number toString + padding 86310.34 ±0.69% fastest ✅
bytes/hex-to.ts[1] manual 7433.9 ±1.11% 91.39% slower
codec/bigint.compare.ts[0] compare custom 87750509.96 ±3.95% 2.17% slower
codec/bigint.compare.ts[1] compare bigint 89701396.18 ±4.85% fastest ✅
codec/bigint.decode.ts[0] decode custom 68237800.29 ±3.3% 25.53% slower
codec/bigint.decode.ts[1] decode bigint 91634363.38 ±3.88% fastest ✅
codec/decoding.ts[0] manual decode 9096429.75 ±1.8% 86.53% slower
codec/decoding.ts[1] int32array decode 67547007.52 ±3.93% fastest ✅
codec/decoding.ts[2] dataview decode 66788293.35 ±4.11% 1.12% slower
codec/encoding.ts[0] manual encode 2256712.77 ±0.93% 25.13% slower
codec/encoding.ts[1] int32array encode 2986723.95 ±1.39% 0.92% slower
codec/encoding.ts[2] dataview encode 3014368.74 ±0.53% fastest ✅
collections/map-set.ts[0] 2 gets + conditional set 47936.85 ±1.41% fastest ✅
collections/map-set.ts[1] 1 get 1 set 37915.69 ±0.49% 20.9% slower
logger/index.ts[0] console.log with string concat 5391646.1 ±22.84% fastest ✅
logger/index.ts[1] console.log with args 1000340.46 ±97.3% 81.45% slower
math/add_one_overflow.ts[0] add and take modulus 10094035.79 ±164.72% 88.66% slower
math/add_one_overflow.ts[1] condition before calculation 89033468.85 ±4.69% fastest ✅
math/count-bits-u32.ts[0] standard method 37745346.46 ±1.97% 55.81% slower
math/count-bits-u32.ts[1] magic 85416967.2 ±3.84% fastest ✅
math/count-bits-u64.ts[0] standard method 678910.92 ±0.62% 85.99% slower
math/count-bits-u64.ts[1] magic 4845605.74 ±0.46% fastest ✅
math/mul_overflow.ts[0] multiply and bring back to u32 93816756.29 ±4.78% fastest ✅
math/mul_overflow.ts[1] multiply and take modulus 91258806.88 ±4.86% 2.73% slower
math/switch.ts[0] switch 89094988.54 ±5.72% 1.48% slower
math/switch.ts[1] if 90429289.45 ±5.88% fastest ✅
hash/index.ts[0] hash with numeric representation 65.15 ±0.37% 34.03% slower
hash/index.ts[1] hash with string representation 41.69 ±0.39% 57.78% slower
hash/index.ts[2] hash with symbol representation 63.64 ±0.44% 35.55% slower
hash/index.ts[3] hash with uint8 representation 73.49 ±0.25% 25.58% slower
hash/index.ts[4] hash with packed representation 98.75 ±0.48% fastest ✅
hash/index.ts[5] hash with bigint representation 75.9 ±0.7% 23.14% slower
hash/index.ts[6] hash with uint32 representation 92.63 ±0.28% 6.2% slower
bytes/bytes-to-number.ts[0] Conversion with bitops 2542.19 ±0.54% fastest ✅
bytes/bytes-to-number.ts[1] Conversion without bitops 1850.21 ±0.77% 27.22% slower
bytes/compare.ts[0] Comparing Uint32 bytes 7987.05 ±0.41% 31.29% slower
bytes/compare.ts[1] Comparing raw bytes 11624.93 ±0.59% fastest ✅
codec/view_vs_collection.ts[0] Get first element from Decoded 18188.72 ±0.98% 50.69% slower
codec/view_vs_collection.ts[1] Get first element from View 36884.63 ±0.63% fastest ✅
codec/view_vs_collection.ts[2] Get 50th element from Decoded 17886.29 ±0.42% 51.51% slower
codec/view_vs_collection.ts[3] Get 50th element from View 17929.61 ±4.53% 51.39% slower
codec/view_vs_collection.ts[4] Get last element from Decoded 17159.36 ±2.77% 53.48% slower
codec/view_vs_collection.ts[5] Get last element from View 13824.21 ±0.97% 62.52% slower
codec/view_vs_object.ts[0] Get the first field from Decoded 252377.73 ±0.61% 2.67% slower
codec/view_vs_object.ts[1] Get the first field from View 54516.94 ±0.56% 78.97% slower
codec/view_vs_object.ts[2] Get the first field as view from View 51932.81 ±2.9% 79.97% slower
codec/view_vs_object.ts[3] Get two fields from Decoded 259290.11 ±0.67% fastest ✅
codec/view_vs_object.ts[4] Get two fields from View 43430.02 ±0.41% 83.25% slower
codec/view_vs_object.ts[5] Get two fields from materialized from View 89676.55 ±0.64% 65.41% slower
codec/view_vs_object.ts[6] Get two fields as views from View 25183.16 ±76.81% 90.29% slower
codec/view_vs_object.ts[7] Get only third field from Decoded 251907.81 ±1.95% 2.85% slower
codec/view_vs_object.ts[8] Get only third field from View 53586.53 ±0.58% 79.33% slower
codec/view_vs_object.ts[9] Get only third field as view from View 51686.21 ±3.12% 80.07% slower
collections/map_vs_sorted.ts[0] Map 164290.48 ±0.25% fastest ✅
collections/map_vs_sorted.ts[1] Map-array 45414.55 ±0.28% 72.36% slower
collections/map_vs_sorted.ts[2] Array 54564.59 ±0.17% 66.79% slower
collections/map_vs_sorted.ts[3] SortedArray 81045.32 ±0.51% 50.67% slower
collections/hash-dict-vs-blob-dict_delete.ts[0] StringHashDictionary 2503.45 ±2.74% 5.62% slower
collections/hash-dict-vs-blob-dict_delete.ts[1] BlobDictionary(1) 2652.62 ±0.96% fastest ✅
collections/hash-dict-vs-blob-dict_delete.ts[2] BlobDictionary(2) 2622.09 ±1.51% 1.15% slower
collections/hash-dict-vs-blob-dict_delete.ts[3] BlobDictionary(3) 2597.43 ±1.44% 2.08% slower
collections/hash-dict-vs-blob-dict_delete.ts[4] BlobDictionary(4) 2551.85 ±1.28% 3.8% slower
collections/hash-dict-vs-blob-dict_delete.ts[5] BlobDictionary(5) 2548.57 ±1.24% 3.92% slower
collections/hash-dict-vs-blob-dict_get.ts[0] StringHashDictionary 2920.83 ±0.92% fastest ✅
collections/hash-dict-vs-blob-dict_get.ts[1] BlobDictionary(1) 2639.42 ±1.16% 9.63% slower
collections/hash-dict-vs-blob-dict_get.ts[2] BlobDictionary(2) 2759.63 ±1.55% 5.52% slower
collections/hash-dict-vs-blob-dict_get.ts[3] BlobDictionary(3) 2824.57 ±1.53% 3.3% slower
collections/hash-dict-vs-blob-dict_get.ts[4] BlobDictionary(4) 2786.46 ±1.42% 4.6% slower
collections/hash-dict-vs-blob-dict_get.ts[5] BlobDictionary(5) 2819.62 ±1.43% 3.47% slower
collections/hash-dict-vs-blob-dict_set.ts[0] StringHashDictionary 2111.79 ±0.65% fastest ✅
collections/hash-dict-vs-blob-dict_set.ts[1] BlobDictionary(1) 2050.38 ±1.01% 2.91% slower
collections/hash-dict-vs-blob-dict_set.ts[2] BlobDictionary(2) 1067.57 ±84.26% 49.45% slower
collections/hash-dict-vs-blob-dict_set.ts[3] BlobDictionary(3) 1523.34 ±2.02% 27.86% slower
collections/hash-dict-vs-blob-dict_set.ts[4] BlobDictionary(4) 1531.83 ±0.62% 27.46% slower
collections/hash-dict-vs-blob-dict_set.ts[5] BlobDictionary(5) 1579.36 ±0.9% 25.21% slower
hash/blake2b.ts[0] our hasher 1.07 ±0.13% fastest ✅
hash/blake2b.ts[1] blake2b js 0.03 ±0.38% 97.2% slower
crypto/ed25519.ts[0] native crypto 4.5 ±0.66% fastest ✅
crypto/ed25519.ts[1] wasm lib 2.88 ±0.32% 36% slower
crypto/ed25519.ts[2] wasm lib batch 2.87 ±0.52% 36.22% slower

Benchmarks summary: 83/83 OK ✅

@tomusdrw tomusdrw added this pull request to the merge queue Jun 8, 2026
Merged via the queue into main with commit 7cde74e Jun 8, 2026
17 checks passed
@tomusdrw tomusdrw deleted the td-ticket-pool branch June 8, 2026 20:58
@coderabbitai coderabbitai Bot mentioned this pull request Jun 10, 2026
4 tasks
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.

Refactor TicketDistributionTask: introduce TicketQueue/TicketPool and TicketValidator abstraction

1 participant