Skip to content

Added RPC Parameters endpoint#779

Merged
DrEverr merged 6 commits into
mainfrom
maso-rpc-segment
Nov 13, 2025
Merged

Added RPC Parameters endpoint#779
DrEverr merged 6 commits into
mainfrom
maso-rpc-segment

Conversation

@DrEverr

@DrEverr DrEverr commented Nov 13, 2025

Copy link
Copy Markdown
Member

https://hackmd.io/@polkadot/jip2#parameters

I've added a bit more fields than it its described in documentation.
I was trying to run Doom on our node and noticed that doom expects a bit more/different fields as well.

example of what jamtop, jamt, etc. expects at current stage v 0.1.26

"jsonrpc":"2.0","id":0,"result":{"V1":{"deposit_per_item":10,"deposit_per_byte":1,"deposit_per_account":100,"core_count":2,"min_turnaround_period":32,"epoch_period":12,"max_accumulate_gas":10000000,"max_is_authorized_gas":50000000,"max_refine_gas":1000000000,"block_gas_limit":20000000,"recent_block_count":8,"max_work_items":16,"max_dependencies":8,"max_tickets_per_block":3,"max_lookup_anchor_age":14400,"tickets_attempts_number":3,"auth_window":8,"slot_period_sec":6,"auth_queue_len":80,"rotation_period":4,"max_extrinsics":128,"availability_timeout":5,"val_count":6,"max_authorizer_code_size":64000,"max_input":13794305,"max_service_code_size":4000000,"basic_piece_len":4,"max_imports":3072,"segment_piece_count":1026,"max_report_elective_data":49152,"transfer_memo_size":128,"max_exports":3072,"epoch_tail_start":10}}}

@coderabbitai

coderabbitai Bot commented Nov 13, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Implemented RPC parameters endpoint that returns comprehensive chain and node configuration settings, including balances, gas limits, memory constraints, timeouts, and validator configurations.
  • Public API

    • Exposed internal constants as part of the public API for broader accessibility and external usage.

Walkthrough

Adds a new RPC method "parameters" implemented in bin/rpc/src/methods/parameters.ts: a Zod-validated V1 schema and an exported async function that returns a structured object populated from chainSpec fields and project constants. Wires the new method into the RPC registry by importing it in bin/rpc/src/method-loader.ts and replacing the previous notImplemented placeholder. Also changes two constants in packages/jam/block/work-item-segment.ts (W_E and W_S) from internal const to exported const.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • parameters.ts: verify Zod V1 schema correctness, ensure each returned field maps to the intended chainSpec property or constant, and confirm types/units.
  • method-loader.ts: confirm the import and Map registration are correct and there are no naming collisions.
  • work-item-segment.ts: check that exporting W_E and W_S does not break encapsulation or produce unintended public API changes.

Possibly related PRs

  • Move values to chain spec. #576 — Changes to ChainSpec fields (erasureCodedPieceSize/W_E, maxBlockGas, maxRefineGas, validatorsCount, etc.) that the new parameters method reads.
  • JSON RPC param validation #402 — Refactors method-loader and RPC method registration patterns; closely related to wiring and schema-registration used here.

Suggested reviewers

  • mateuszsikora

Poem

🐇📜 A little rabbit hopped in today,
Brought parameters wrapped in Zod array.
W_E and W_S now shown to all,
RPC wired up — hear the call!
Hooray for code that hops and plays 🎉

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a new RPC Parameters endpoint, which is the primary purpose of this PR.
Description check ✅ Passed The description is related to the changeset, providing context about the RPC Parameters endpoint implementation and explaining why additional fields were included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch maso-rpc-segment

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

@DrEverr DrEverr marked this pull request as ready for review November 13, 2025 10:55
@DrEverr DrEverr requested review from skoszuta and tomusdrw and removed request for tomusdrw November 13, 2025 10:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fcdfbb1 and 903bc03.

📒 Files selected for processing (3)
  • bin/rpc/src/method-loader.ts (2 hunks)
  • bin/rpc/src/methods/parameters.ts (1 hunks)
  • packages/jam/block/work-item-segment.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.ts

⚙️ CodeRabbit configuration file

**/*.ts: rules from ./CODESTYLE.md should be adhered to.

**/*.ts: Any function whose documentation mention it must not be used in production code,
can be safely used in *.test.ts files. Other usage should be carefuly reviewed
and the comment must explain why it's safe to use there.

**/*.ts: as conversions must not be used. Suggest using tryAs conversion methods.

**/*.ts: Classes with static Codec field must have private constructor and static create method.

**/*.ts: Casting a bigint (or U64) using Number(x) must have an explanation comment why
it is safe.

**/*.ts: When making changes to code with comments containing links (in classes, constants, methods, etc.)
to graypaper.fluffylabs.dev, ensure those links point to the current version for this update.

Files:

  • packages/jam/block/work-item-segment.ts
  • bin/rpc/src/methods/parameters.ts
  • bin/rpc/src/method-loader.ts
🧠 Learnings (1)
📚 Learning: 2025-05-22T18:08:38.725Z
Learnt from: tomusdrw
Repo: FluffyLabs/typeberry PR: 381
File: bin/rpc/src/server.ts:99-112
Timestamp: 2025-05-22T18:08:38.725Z
Learning: RPC methods should implement strict parameter validation, including checking the exact number of parameters and their types. This helps catch errors early when users confuse similar methods (e.g., serviceData vs serviceValue) and prevents cryptic errors from undefined parameters being passed to internal code.

Applied to files:

  • bin/rpc/src/methods/parameters.ts
🧬 Code graph analysis (2)
bin/rpc/src/methods/parameters.ts (7)
bin/rpc/src/types.ts (2)
  • withValidation (84-92)
  • NoArgs (114-114)
packages/jam/state/service.ts (3)
  • BASE_SERVICE_BALANCE (23-23)
  • ELECTIVE_ITEM_BALANCE (29-29)
  • ELECTIVE_BYTE_BALANCE (35-35)
packages/jam/transition/reports/verify-post-signature.ts (1)
  • G_A (8-8)
packages/jam/block/gp-constants.ts (7)
  • G_I (18-18)
  • O (24-24)
  • Q (27-27)
  • T (33-33)
  • W_B (39-39)
  • W_C (42-42)
  • W_T (51-51)
packages/jam/block/work-package.ts (1)
  • MAX_NUMBER_OF_WORK_ITEMS (28-28)
packages/jam/transition/assurances.ts (1)
  • REPORT_TIMEOUT_GRACE_PERIOD (53-53)
packages/jam/block/work-item-segment.ts (1)
  • W_E (6-6)
bin/rpc/src/method-loader.ts (1)
bin/rpc/src/methods/parameters.ts (1)
  • parameters (63-105)

Comment thread bin/rpc/src/methods/parameters.ts

@tomusdrw tomusdrw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hackmd docs should be considered outdated now. Please reference https://github.com/polkadot-fellows/JIPs/blob/main/JIP-2.md#chain-parameters

@DrEverr DrEverr enabled auto-merge (squash) November 13, 2025 19:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
bin/rpc/src/methods/parameters.ts (2)

65-67: Add safety comments for BigInt-to-number conversions.

As noted in the previous review and per coding guidelines, casting bigint using Number(x) requires an explanation comment. While these specific values (100n, 10n, 1n) are clearly safe, the guideline mandates documentation.

Apply this diff:

-      deposit_per_account: Number(BASE_SERVICE_BALANCE),
-      deposit_per_item: Number(ELECTIVE_ITEM_BALANCE),
-      deposit_per_byte: Number(ELECTIVE_BYTE_BALANCE),
+      deposit_per_account: Number(BASE_SERVICE_BALANCE), // safe: 100n < Number.MAX_SAFE_INTEGER
+      deposit_per_item: Number(ELECTIVE_ITEM_BALANCE), // safe: 10n < Number.MAX_SAFE_INTEGER
+      deposit_per_byte: Number(ELECTIVE_BYTE_BALANCE), // safe: 1n < Number.MAX_SAFE_INTEGER

As per coding guidelines


72-73: Add safety comments for BigInt conversions to Number.

Lines 72-73 convert U64 values (which are bigint type) to number without safety documentation. Per coding guidelines, such conversions must include comments explaining why the range is safe.

Since maxRefineGas and maxBlockGas are constrained by chain configuration to small values (e.g., tinyChainSpec uses 1_000_000_000 and 20_000_000 respectively), these are safely within Number.MAX_SAFE_INTEGER. Add clarifying comments:

-      max_refine_gas: Number(chainSpec.maxRefineGas),
-      block_gas_limit: Number(chainSpec.maxBlockGas),
+      max_refine_gas: Number(chainSpec.maxRefineGas), // safe: chain config constrains to < Number.MAX_SAFE_INTEGER
+      block_gas_limit: Number(chainSpec.maxBlockGas), // safe: chain config constrains to < Number.MAX_SAFE_INTEGER

Also apply the same comment pattern to lines 65-67 for consistency (BASE_SERVICE_BALANCE, ELECTIVE_ITEM_BALANCE, ELECTIVE_BYTE_BALANCE are also bigint values being converted).

🧹 Nitpick comments (2)
bin/rpc/src/methods/parameters.ts (2)

15-56: Consider adding integer constraints to appropriate fields.

Many of these parameters represent counts, periods, or sizes that should be integers (e.g., epoch_period, max_work_items, val_count). Consider using .int() refinements on those fields to enforce stricter validation at the API boundary.

Example:

 const V1 = z.object({
   V1: z.object({
     deposit_per_account: z.number(),
     deposit_per_item: z.number(),
     deposit_per_byte: z.number(),
     min_turnaround_period: z.number(),
-    epoch_period: z.number(),
+    epoch_period: z.number().int(),
     max_accumulate_gas: z.number(),
     max_is_authorized_gas: z.number(),
-    max_refine_gas: z.number(),
+    max_refine_gas: z.number().int(),
     // ... and so on for other integer fields
   }),
 });

68-68: Document or extract magic numbers to named constants.

Several hardcoded numeric literals appear without explanation:

  • Line 68: 32 (min_turnaround_period)
  • Lines 89-93: 3072, 64000, 4096 (max_imports, max_is_authorized_code_size, memory limits)
  • Line 95: 49152 (max_report_elective_data)
  • Lines 100-101: 64000, 4000000 (max_authorizer_code_size, max_service_code_size)

These should either reference named constants from the appropriate modules (like the other fields do) or include comments explaining their source and rationale.

Example:

-      min_turnaround_period: 32,
+      min_turnaround_period: 32, // JIP-2 spec: minimum block interval for work package turnaround

Or extract to constants:

const MIN_TURNAROUND_PERIOD = 32;
const MAX_IMPORTS = 3072;
const MAX_AUTHORIZER_CODE_SIZE = 64000;
// ... etc.

Also applies to: 89-93, 95-95, 100-101

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 903bc03 and a09fdb0.

📒 Files selected for processing (1)
  • bin/rpc/src/methods/parameters.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.ts

⚙️ CodeRabbit configuration file

**/*.ts: rules from ./CODESTYLE.md should be adhered to.

**/*.ts: Any function whose documentation mention it must not be used in production code,
can be safely used in *.test.ts files. Other usage should be carefuly reviewed
and the comment must explain why it's safe to use there.

**/*.ts: as conversions must not be used. Suggest using tryAs conversion methods.

**/*.ts: Classes with static Codec field must have private constructor and static create method.

**/*.ts: Casting a bigint (or U64) using Number(x) must have an explanation comment why
it is safe.

**/*.ts: When making changes to code with comments containing links (in classes, constants, methods, etc.)
to graypaper.fluffylabs.dev, ensure those links point to the current version for this update.

Files:

  • bin/rpc/src/methods/parameters.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: tomusdrw
Repo: FluffyLabs/typeberry PR: 381
File: bin/rpc/src/server.ts:99-112
Timestamp: 2025-05-22T18:08:38.725Z
Learning: RPC methods should implement strict parameter validation, including checking the exact number of parameters and their types. This helps catch errors early when users confuse similar methods (e.g., serviceData vs serviceValue) and prevents cryptic errors from undefined parameters being passed to internal code.
🧬 Code graph analysis (1)
bin/rpc/src/methods/parameters.ts (7)
bin/rpc/src/types.ts (2)
  • withValidation (84-92)
  • NoArgs (114-114)
packages/jam/state/service.ts (3)
  • BASE_SERVICE_BALANCE (23-23)
  • ELECTIVE_ITEM_BALANCE (29-29)
  • ELECTIVE_BYTE_BALANCE (35-35)
packages/jam/transition/reports/verify-post-signature.ts (1)
  • G_A (8-8)
packages/jam/block/gp-constants.ts (7)
  • G_I (18-18)
  • O (24-24)
  • Q (27-27)
  • T (33-33)
  • W_B (39-39)
  • W_C (42-42)
  • W_T (51-51)
packages/jam/block/work-package.ts (1)
  • MAX_NUMBER_OF_WORK_ITEMS (28-28)
packages/jam/transition/assurances.ts (1)
  • REPORT_TIMEOUT_GRACE_PERIOD (53-53)
packages/jam/block/work-item-segment.ts (1)
  • W_E (6-6)
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: run (22.x)
  • GitHub Check: run (22.x)
  • GitHub Check: run (22.x)
  • GitHub Check: run (22.x)
🔇 Additional comments (2)
bin/rpc/src/methods/parameters.ts (2)

1-13: LGTM: Imports are well-organized.

All imported constants are properly utilized in the parameters function, and the import organization is clear and logical.


69-69: ChainSpec fields are guaranteed by TypeScript's type system—runtime validation is unnecessary.

The function parameter chainSpec: ChainSpec (bin/rpc/src/types.ts:87) is explicitly typed as non-optional. All accessed fields (epochLength, maxRefineGas, maxBlockGas, etc.) are directly assigned to z.number() properties in the return object. If any of these ChainSpec fields were optional in the type definition, accessing them would produce number | undefined, causing TypeScript type errors when assigning to the schema's z.number() properties. Since the code compiles without errors, the ChainSpec type guarantees all fields are non-optional. The concern about undefined values is already addressed by compile-time type checking.

Likely an incorrect or invalid review comment.

@DrEverr DrEverr merged commit 203a18d into main Nov 13, 2025
16 checks passed
@DrEverr DrEverr deleted the maso-rpc-segment branch November 13, 2025 20:01
@github-actions

Copy link
Copy Markdown
View all
File Benchmark Ops
bytes/hex-from.ts[0] parse hex using Number with NaN checking 114430.68 ±3.25% 84.9% slower
bytes/hex-from.ts[1] parse hex from char codes 757881.37 ±1.84% fastest ✅
bytes/hex-from.ts[2] parse hex from string nibbles 502108.1 ±1.58% 33.75% slower
bytes/hex-to.ts[0] number toString + padding 276116.45 ±1.8% fastest ✅
bytes/hex-to.ts[1] manual 13943.65 ±1.6% 94.95% slower
logger/index.ts[0] console.log with string concat 5816804.18 ±55.42% fastest ✅
logger/index.ts[1] console.log with args 190380.85 ±123.39% 96.73% slower
math/add_one_overflow.ts[0] add and take modulus 149651794.33 ±44.99% 32.48% slower
math/add_one_overflow.ts[1] condition before calculation 221652204.12 ±5.97% fastest ✅
math/count-bits-u64.ts[0] standard method 828460.22 ±1.16% 83.55% slower
math/count-bits-u64.ts[1] magic 5035704.56 ±1.53% fastest ✅
hash/index.ts[0] hash with numeric representation 163.89 ±1.48% 27.58% slower
hash/index.ts[1] hash with string representation 98.01 ±1.31% 56.69% slower
hash/index.ts[2] hash with symbol representation 159.68 ±1.19% 29.44% slower
hash/index.ts[3] hash with uint8 representation 144.89 ±1.43% 35.97% slower
hash/index.ts[4] hash with packed representation 226.29 ±1.57% fastest ✅
hash/index.ts[5] hash with bigint representation 171.58 ±1.56% 24.18% slower
hash/index.ts[6] hash with uint32 representation 186.04 ±1.97% 17.79% slower
codec/bigint.compare.ts[0] compare custom 230355424.64 ±6.91% 8.97% slower
codec/bigint.compare.ts[1] compare bigint 253066395.93 ±5.34% fastest ✅
collections/map-set.ts[0] 2 gets + conditional set 116317.8 ±0.63% fastest ✅
collections/map-set.ts[1] 1 get 1 set 60079.51 ±0.37% 48.35% slower
codec/bigint.decode.ts[0] decode custom 166663654.98 ±2.5% fastest ✅
codec/bigint.decode.ts[1] decode bigint 66202434.05 ±1.96% 60.28% slower
math/count-bits-u32.ts[0] standard method 70337148.56 ±1.75% 72.82% slower
math/count-bits-u32.ts[1] magic 258820988.42 ±4.62% fastest ✅
math/mul_overflow.ts[0] multiply and bring back to u32 270650532.49 ±5.1% fastest ✅
math/mul_overflow.ts[1] multiply and take modulus 254107264.76 ±5.61% 6.11% slower
math/switch.ts[0] switch 261123233.9 ±5.55% fastest ✅
math/switch.ts[1] if 251690994.91 ±6.2% 3.61% slower
codec/encoding.ts[0] manual encode 33644.77 ±40.97% 98.13% slower
codec/encoding.ts[1] int32array encode 1499320.63 ±2.65% 16.62% slower
codec/encoding.ts[2] dataview encode 1798178.17 ±3.07% fastest ✅
codec/decoding.ts[0] manual decode 7567875.74 ±1.46% 96.04% slower
codec/decoding.ts[1] int32array decode 163328021.79 ±3.29% 14.54% slower
codec/decoding.ts[2] dataview decode 191120097.53 ±4.31% fastest ✅
codec/view_vs_collection.ts[0] Get first element from Decoded 22872.72 ±1.37% 52.14% slower
codec/view_vs_collection.ts[1] Get first element from View 47793.47 ±1.29% fastest ✅
codec/view_vs_collection.ts[2] Get 50th element from Decoded 22272.59 ±2.45% 53.4% slower
codec/view_vs_collection.ts[3] Get 50th element from View 25437.23 ±1.15% 46.78% slower
codec/view_vs_collection.ts[4] Get last element from Decoded 23117.44 ±1.39% 51.63% slower
codec/view_vs_collection.ts[5] Get last element from View 15631.52 ±1.37% 67.29% slower
codec/view_vs_object.ts[0] Get the first field from Decoded 377425.75 ±0.91% fastest ✅
codec/view_vs_object.ts[1] Get the first field from View 82691.43 ±0.87% 78.09% slower
codec/view_vs_object.ts[2] Get the first field as view from View 80737.27 ±0.84% 78.61% slower
codec/view_vs_object.ts[3] Get two fields from Decoded 370586.23 ±1.05% 1.81% slower
codec/view_vs_object.ts[4] Get two fields from View 63558.52 ±1.42% 83.16% slower
codec/view_vs_object.ts[5] Get two fields from materialized from View 132416.78 ±0.96% 64.92% slower
codec/view_vs_object.ts[6] Get two fields as views from View 59702.96 ±1.48% 84.18% slower
codec/view_vs_object.ts[7] Get only third field from Decoded 368535.86 ±1.61% 2.36% slower
codec/view_vs_object.ts[8] Get only third field from View 79270.61 ±0.55% 79% slower
codec/view_vs_object.ts[9] Get only third field as view from View 80041.9 ±0.85% 78.79% slower
collections/map_vs_sorted.ts[0] Map 296811.42 ±0.26% fastest ✅
collections/map_vs_sorted.ts[1] Map-array 95875.06 ±1.29% 67.7% slower
collections/map_vs_sorted.ts[2] Array 25981.74 ±6.29% 91.25% slower
collections/map_vs_sorted.ts[3] SortedArray 189533.98 ±0.77% 36.14% slower
bytes/compare.ts[0] Comparing Uint32 bytes 17044.13 ±2.18% fastest ✅
bytes/compare.ts[1] Comparing raw bytes 16164.22 ±3.81% 5.16% slower
hash/blake2b.ts[0] our hasher 2.05 ±1.97% fastest ✅
hash/blake2b.ts[1] blake2b js 0.04 ±7.46% 98.05% slower
crypto/ed25519.ts[0] native crypto 8.02 ±0.95% 73.65% slower
crypto/ed25519.ts[1] wasm lib 10.83 ±0.23% 64.42% slower
crypto/ed25519.ts[2] wasm lib batch 30.44 ±0.58% fastest ✅

Benchmarks summary: 63/63 OK ✅

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.

2 participants