From d6ec37817e214419136908465123c8155d5bdc20 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:00:56 +0000 Subject: [PATCH 01/14] Run People on three cores, with each parachain's core count in the descriptor --- CLAUDE.md | 14 +- README.md | 8 +- docs/FORK.md | 11 +- networks/README.md | 3 +- networks/devnet.json | 1 + networks/kusama.json | 1 + networks/paseo-next-v2.json | 1 + networks/polkadot.json | 1 + networks/previewnet.json | 4 +- networks/westend.json | 1 + packages/cli/src/commands/fork.ts | 2 +- packages/cli/src/commands/service.ts | 129 ++++++++++++------ packages/cli/src/fork/chains.ts | 2 + packages/cli/src/fork/overrides.ts | 2 +- packages/cli/src/fork/shared-relay.ts | 16 +-- packages/cli/src/fork/topology.ts | 3 +- packages/cli/src/fork/validators.ts | 5 +- packages/cli/tests/assign-cores.test.ts | 54 ++++++++ packages/cli/tests/fork-shared-relay.test.ts | 20 ++- packages/cli/tests/fork-validators.test.ts | 2 +- .../network-config/src/dashboard-model.ts | 5 +- packages/network-config/src/networks.ts | 31 ++++- packages/network-config/src/toml-generator.ts | 55 +++++--- .../network-config/tests/fork-toml.test.ts | 4 +- .../network-config/tests/networks.test.ts | 73 +++++++--- .../tests/toml-generator.test.ts | 51 ++++--- zombienet-configs/local-dev.toml | 22 ++- 27 files changed, 351 insertions(+), 170 deletions(-) create mode 100644 packages/cli/tests/assign-cores.test.ts diff --git a/CLAUDE.md b/CLAUDE.md index 5038699..a978d40 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,10 +10,10 @@ Do not add `Co-Authored-By: Claude` (or any other AI attribution) lines to commi Product Preview Network (PPN) is infrastructure tooling for spinning up a local Polkadot ecosystem with Zombienet. It provides pre-built binaries, WASM runtimes, and configuration for: -- **Relay Chain**: Paseo (6 validators: alice, bob, charlie, dave, eve, ferdie) +- **Relay Chain**: Paseo (8 validators: alice, bob, charlie, dave, eve, ferdie, Validator-7, Validator-8) - **Parachains**: - Asset Hub (ID 1500) - port 10020 - **2-second blocks** via elastic scaling - - People/Individuality Chain (ID 1502) - port 10010 + - People/Individuality Chain (ID 1502) - port 10010 - **2-second blocks** via elastic scaling - Bulletin Chain (ID 1501) - port 10030 - Web3 Storage Chain (ID 1600) - port 10040 @@ -235,11 +235,13 @@ zombienet-configs/ | DUB API Reference | `http://127.0.0.1:8092/docs` | Generated OpenAPI reference | | TURN/STUN (eturnal) | `stun:127.0.0.1:3478`, `turn:127.0.0.1:3478` | Relay for p2p clients; credentials from DUB `/api/v1/turn/issue` (see `docs/TURN.md`) | -## Elastic Scaling (Asset Hub) +## Elastic Scaling (Asset Hub, People) -Asset Hub runs with 2-second block times using elastic scaling: -- 6 validators required for 5 cores (3 parachains + 2 extra for Asset Hub) -- Core assignment via `scripts/assign-cores.sh` (runs automatically as custom_process) +Asset Hub and People run with 2-second block times on three cores each (`parachains[].cores` in +the descriptor): +- 8 validators for 8 cores (one per core, or a core has no group to back its blocks) +- The genesis TOML adds the extra cores; `ppn service assign-cores` (a custom process) hands + them out, and on a kept chain assigns only cores that have a validator group and no assignment ## Testing diff --git a/README.md b/README.md index f935b3a..575b1d6 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ > been audited, is actively experimental, and may contain bugs, vulnerabilities, or incomplete > features. Use at your own risk. -A complete Polkadot ecosystem on your machine, in one command: a relay chain with six -validators, plus Asset Hub (2-second blocks via elastic scaling), People, Bulletin and Web3 +A complete Polkadot ecosystem on your machine, in one command: a relay chain with eight +validators, plus Asset Hub and People (2-second blocks via elastic scaling), Bulletin and Web3 Storage, plus the Ethereum RPC, IPFS, identity backend and storage provider those chains expect, already wired together. The same tool forks a live network, Polkadot included, so the chains come up carrying real state instead of an empty genesis. @@ -175,9 +175,9 @@ strips the dev keys from anything long-lived. A server's secrets file holds the | | Endpoint | | | --- | --- | --- | -| Relay (alice … ferdie) | `ws://127.0.0.1:10000` – `10005` | 6 validators | +| Relay (alice … ferdie) | `ws://127.0.0.1:10000` – `10005` | 8 validators; Validator-7 and -8 on `10006`, `10007` | | Asset Hub | `ws://127.0.0.1:10020` | **2-second blocks**, elastic scaling | -| People | `ws://127.0.0.1:10010` | individuality | +| People | `ws://127.0.0.1:10010` | individuality, **2-second blocks**, elastic scaling | | Bulletin | `ws://127.0.0.1:10030` | transaction storage | | Web3 Storage | `ws://127.0.0.1:10040` | storage parachain, previewnet only | | Dashboard | | status UI and API for all of the above | diff --git a/docs/FORK.md b/docs/FORK.md index b641319..055f790 100644 --- a/docs/FORK.md +++ b/docs/FORK.md @@ -90,8 +90,9 @@ instead of driving doppelganger itself ([#120](https://github.com/paritytech/zom ## What you get, and what you don't The fork resumes at the bite block and diverges from there — it is a real fork, not a mirror. It -runs six relay validators and one collator per parachain, on PPN's normal ports, with Asset Hub's -2-second elastic scaling intact — unless the bite was asked for a different layout, below. +runs the descriptor's relay validators and one collator per parachain, on PPN's normal ports. A +previewnet fork keeps the core layout it bit; a fork of a shared relay lays the parachains out on +the descriptor's `cores` — unless the bite was asked for a different layout, below. ### Cores and collators @@ -100,15 +101,15 @@ make start FORK=1 FRESH_BITE=1 CORES=people=3 COLLATORS=people=5 make bite CORES="people=3 asset-hub=1" COLLATORS=people=5 ``` -`CORES==` lays a parachain out on that many cores (Asset Hub defaults to three, the -rest to one); `COLLATORS==` installs that many collators as its authorities. Both are +`CORES==` lays a parachain out on that many cores (the descriptor's `cores` otherwise); +`COLLATORS==` installs that many collators as its authorities. Both are **bite-time** settings: the collator authority sets and the relay's core layout are state inside the snapshots, so a published bundle — bitten with the defaults — cannot take them. `ppn start` refuses a bundle whose recorded layout differs from what it was asked for and says how to re-bite. The bundle's `manifest.json` carries the layout under `topology`, and the fork TOML follows it. The relay grows to one validator per core, because a core with no validator group backs nothing: -previewnet with `people=3` is 3 + 3 + 1 + 1 = 8 cores, so 8 validators. Past the well-known six +paseo-next-v2 with `people=3` is 3 + 3 + 1 = 7 cores, so 7 validators. Past the well-known six they are named `Validator-7`, `Validator-8`, … and their keys derived from those names, the same way zombienet does it; the cap is 10, where the relay RPC ports (`10000 + i`) would run into People's. Extra collators are `Collator--2` … and restore the same snapshot as the first; diff --git a/networks/README.md b/networks/README.md index ded1ba9..98405a5 100644 --- a/networks/README.md +++ b/networks/README.md @@ -50,9 +50,10 @@ or `PPN_NETWORK=` in the environment of the scripts. | `relay.rpc`, `parachains[].rpc` | RPC endpoint: an absolute `ws(s)://`/`http(s)://` URL, or a path resolved against `bite.source`. | | `rpcAlternates` | Informational: other public providers for the same chain, for when the primary is re-homed. Not consumed by tooling (yet). | | `relay.specSource`, `parachains[].specSource` | Explicit location of the chain spec the bite warp-syncs from (it must carry the live network's bootnodes): an absolute URL, a path resolved against `bite.source` (previewnet uses `chainspecs/-local.json`, so biting a different instance follows the base-URL override), or `"builtin"` (generated with `build-spec --chain --raw`, relay only). | -| `relay.validators` | Number of dev-key validators the fork runs with (max 6: alice…ferdie). | +| `relay.validators` | Number of relay validators, 1..10: alice…ferdie, then `Validator-7`… with keys derived from those names. At least the parachains' total `cores`, which loading the descriptor checks: a core with no validator group backs nothing. The genesis TOML and a fork both run this many; only the well-known six get a public `/relay/` path. | | `parachains[].key` | One of `asset-hub`, `people`, `bulletin`, `web3-storage` — the keys PPN's port table and per-chain flags are defined for. | | `parachains[].paraId` | The network's real para id. Previewnet/paseo-next-v2 use the 1500 band; devnet and real networks the 1000 band. | +| `parachains[].cores` | Relay cores the chain runs on, 1 when absent. More than one is elastic scaling, and shortens block time only when the runtime is built for that many blocks per relay block (previewnet's Asset Hub and People: 3, so 2-second blocks). Genesis adds the extra cores and `assign-cores` hands them out. A fork of a shared relay lays its parachains out with these counts and `--cores` overrides them; a previewnet fork keeps the layout it bit. | | `parachains[].spec` | Basename of the parachain spec inside the bundle. | | `services` | Optional `{ "": false }` map to disable custom processes that would otherwise run for the present parachains (e.g. eth-rpc for asset-hub, ipfs for bulletin). | | `dotns.resolver` | DotnsContentResolver address for `pin-bulletin-products` — per network, since every DotNS deployment has its own. Omitted → read from `bin/dotns-addresses.json` (previewnet's release artifact); still absent → the import is skipped. | diff --git a/networks/devnet.json b/networks/devnet.json index 31db5e7..01091f6 100644 --- a/networks/devnet.json +++ b/networks/devnet.json @@ -40,6 +40,7 @@ { "key": "asset-hub", "paraId": 1000, + "cores": 3, "spec": "asset-hub", "rpc": "wss://asset-hub-paseo-rpc.n.dwellir.com", "rpcAlternates": [ diff --git a/networks/kusama.json b/networks/kusama.json index 5520b08..f11c983 100644 --- a/networks/kusama.json +++ b/networks/kusama.json @@ -35,6 +35,7 @@ { "key": "asset-hub", "paraId": 1000, + "cores": 3, "spec": "asset-hub", "rpc": "wss://kusama-asset-hub-rpc.polkadot.io", "specSource": "builtin:asset-hub-kusama", diff --git a/networks/paseo-next-v2.json b/networks/paseo-next-v2.json index d16e603..1906f49 100644 --- a/networks/paseo-next-v2.json +++ b/networks/paseo-next-v2.json @@ -39,6 +39,7 @@ { "key": "asset-hub", "paraId": 1500, + "cores": 3, "spec": "asset-hub", "rpc": "wss://paseo-asset-hub-next-rpc.polkadot.io", "specSource": "https://raw.githubusercontent.com/paritytech/chainspecs/main/paseo/parachain/asset-hub-next/raw.json", diff --git a/networks/polkadot.json b/networks/polkadot.json index 10aab1f..024519c 100644 --- a/networks/polkadot.json +++ b/networks/polkadot.json @@ -35,6 +35,7 @@ { "key": "asset-hub", "paraId": 1000, + "cores": 3, "spec": "asset-hub", "rpc": "wss://polkadot-asset-hub-rpc.polkadot.io", "specSource": "builtin:asset-hub-polkadot", diff --git a/networks/previewnet.json b/networks/previewnet.json index 43f3b25..ad36e70 100644 --- a/networks/previewnet.json +++ b/networks/previewnet.json @@ -48,7 +48,7 @@ "spec": "paseo", "rpc": "relay/alice", "specSource": "chainspecs/paseo-local.json", - "validators": 6, + "validators": 8, "binary": { "name": "polkadot", "release": "polkadot-sdk" @@ -75,6 +75,7 @@ { "key": "asset-hub", "paraId": 1500, + "cores": 3, "spec": "asset-hub", "rpc": "asset-hub", "specSource": "chainspecs/asset-hub-local.json", @@ -97,6 +98,7 @@ { "key": "people", "paraId": 1502, + "cores": 3, "spec": "individuality", "rpc": "people", "specSource": "chainspecs/individuality-local.json", diff --git a/networks/westend.json b/networks/westend.json index 7839712..1398d39 100644 --- a/networks/westend.json +++ b/networks/westend.json @@ -34,6 +34,7 @@ { "key": "asset-hub", "paraId": 1000, + "cores": 3, "spec": "asset-hub", "rpc": "wss://westend-asset-hub-rpc.polkadot.io", "specSource": "builtin:asset-hub-westend", diff --git a/packages/cli/src/commands/fork.ts b/packages/cli/src/commands/fork.ts index eff0c9d..4aab3b2 100644 --- a/packages/cli/src/commands/fork.ts +++ b/packages/cli/src/commands/fork.ts @@ -84,7 +84,7 @@ export async function run(args: string[]): Promise { endpointOf(relay, NETWORK, baseUrl), `${outDir}/rc_overrides.json`, { - paras: PARACHAINS.map((p) => ({ key: p.key, paraId: p.paraId })), + paras: PARACHAINS.map((p) => ({ key: p.key, paraId: p.paraId, cores: p.cores })), validators: topology?.validators ?? NETWORK.relay.validators, cores: topology?.cores, sharedRelay: NETWORK.bite.sharedRelay === true, diff --git a/packages/cli/src/commands/service.ts b/packages/cli/src/commands/service.ts index db39c40..a0b930b 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -13,6 +13,7 @@ import os from 'node:os'; import path from 'node:path'; import { execFileSync, spawn } from 'node:child_process'; import type { ServiceContext } from './service-context.js'; +import type { ApiPromise } from '@polkadot/api'; import { loadCurrentNetwork, readEnvFile, hrmpChannels, type NetworkDef, repoRoot, workspaceRoot, BOB_SS58, @@ -112,57 +113,105 @@ export async function run(args: string[], deps: ServiceDeps = {}): Promise } // --------------------------------------------------------------------------- -// assign-cores — Asset Hub's 2-second blocks +// assign-cores — elastic scaling // --------------------------------------------------------------------------- +/** A parachain's core count as the descriptor states it. */ +export interface CoreTarget { + key: string; + paraId: number; + cores: number; +} + /** - * Give Asset Hub two extra cores so it can author at 2 seconds via elastic scaling. - * zombienet assigns it one; these are cores 0 and 1 at 100% each (57600 parts). - * - * Which para id gets them comes from the descriptor — this used to be a shell script - * exporting an env var into a Node script, with the id fetched by a third process. + * The assignments that bring each parachain up to its descriptor core count, and what still + * lacks a core afterwards. Uses only cores below `coreCount` (one per validator group, since a + * core without a group backs nothing) that nothing is assigned to, lowest first, and never + * moves an assigned core, so running it again on a kept chain changes nothing. */ -async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promise { - const assetHub = ctx.net.parachains.find((p) => p.key === 'asset-hub'); - if (!assetHub) { - console.log(`assign-cores: ${ctx.net.name} has no asset-hub — nothing to assign`); - return; +export function planExtraCores( + targets: CoreTarget[], + assigned: Map, + coreCount: number +): { assignments: { core: number; paraId: number }[]; missing: { key: string; cores: number }[] } { + const free = Array.from({ length: coreCount }, (_, core) => core).filter((core) => !assigned.has(core)); + const assignments: { core: number; paraId: number }[] = []; + const missing: { key: string; cores: number }[] = []; + for (const target of targets) { + const held = [...assigned.values()].filter((paraIds) => paraIds.includes(target.paraId)).length; + const lacking = Math.max(0, target.cores - held); + const granted = free.splice(0, lacking); + assignments.push(...granted.map((core) => ({ core, paraId: target.paraId }))); + if (granted.length < lacking) missing.push({ key: target.key, cores: lacking - granted.length }); } - const waitSeconds = Number(process.env.WAIT_SECONDS ?? 30); - if (waitSeconds > 0) { - console.log(`assign-cores: waiting ${waitSeconds}s for the relay chain to be ready...`); - await new Promise((r) => setTimeout(r, waitSeconds * 1000)); + return { assignments, missing }; +} + +/** `ParaScheduler::CoreDescriptors` as polkadot.js decodes it to JSON. */ +type CoreDescriptorsJson = Record< + string, + { queue: { last: number } | null; currentWork: { assignments: [unknown, unknown][] } | null } +>; + +/** + * The para ids on each core with an assignment, as the relay will run them: a queued schedule + * replaces the current work once its block is reached, so the latest one wins. + */ +async function assignedCores(api: ApiPromise): Promise> { + const paraIdsOf = (assignments: [unknown, unknown][] = []) => + assignments.flatMap(([assignment]) => + typeof assignment === 'object' && assignment !== null && 'task' in assignment && typeof assignment.task === 'number' + ? [assignment.task] + : [] + ); + // Decoded against the relay's own metadata, so the shape is the runtime's. + const descriptors = (await api.query.paraScheduler.coreDescriptors()).toJSON() as unknown as CoreDescriptorsJson; + const assigned = new Map(); + for (const [core, descriptor] of Object.entries(descriptors)) { + if (descriptor.queue) { + const schedule = (await api.query.paraScheduler.coreSchedules([descriptor.queue.last, Number(core)])).toJSON() as { + assignments: [unknown, unknown][]; + } | null; + assigned.set(Number(core), paraIdsOf(schedule?.assignments)); + } else if (descriptor.currentWork) { + assigned.set(Number(core), paraIdsOf(descriptor.currentWork.assignments)); + } } + return assigned; +} +/** + * Put every parachain on as many cores as the descriptor states, from the cores the relay has + * validator groups for and nothing assigned to. At genesis those are the extra cores the genesis + * TOML adds; on a kept chain that has already been laid out there is nothing to do, and one + * whose relay lacks validators for the cores is reported rather than half laid out. + */ +async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promise { + await waitSeconds('the relay chain', 30); const { ApiPromise, WsProvider, Keyring } = await import('@polkadot/api'); - console.log(`assign-cores: relay ${ctx.relayWs}, para ${assetHub.paraId}`); + console.log(`assign-cores: relay ${ctx.relayWs}`); const api = await ApiPromise.create({ provider: new WsProvider(ctx.relayWs) }); try { - console.log(` connected to ${(await api.rpc.system.chain()).toString()}`); - const signer = new Keyring({ type: 'sr25519' }).addFromUri(ctx.sudoUri); + const coreCount = ((await api.query.paraScheduler.validatorGroups()).toJSON() as unknown[]).length; + const { assignments, missing } = planExtraCores(ctx.net.parachains, await assignedCores(api), coreCount); + for (const { key, cores } of missing) { + console.log( + `assign-cores: ${key} lacks ${cores} core(s), and none of the relay's ${coreCount} validator groups ` + + 'has a free core: the relay needs one validator per core' + ); + } + if (assignments.length === 0) { + console.log('assign-cores: nothing to assign'); + return; + } - // assignCore(coreIndex, begin=0 (immediately), [[assignment, parts]], endHint=null) - const assign = (core: number) => - api.tx.coretime.assignCore(core, 0, [[{ Task: assetHub.paraId }, 57600]], null); - const call = api.tx.sudo.sudo(api.tx.utility.batch([assign(0), assign(1)])); - - await new Promise((resolve, reject) => { - call - .signAndSend(signer, ({ status, dispatchError }) => { - if (status.isInBlock) console.log(` included in ${status.asInBlock.toString()}`); - if (!status.isFinalized) return; - console.log(` finalized in ${status.asFinalized.toString()}`); - if (!dispatchError) return resolve(); - if (dispatchError.isModule) { - const e = api.registry.findMetaError(dispatchError.asModule); - reject(new Error(`${e.section}.${e.name}: ${e.docs.join(' ')}`)); - } else { - reject(new Error(dispatchError.toString())); - } - }) - .catch(reject); - }); - console.log(`assign-cores: para ${assetHub.paraId} now has 3 cores (1 from zombienet + 2 here) — ~2s blocks`); + const signer = new Keyring({ type: 'sr25519' }).addFromUri(ctx.sudoUri); + // begin 0: from the next block; 57600 parts: the whole core. + const calls = assignments.map(({ core, paraId }) => + api.tx.coretime.assignCore(core, 0, [[{ Task: paraId }, 57600]], null) + ); + await submitSudo(api, signer, api.tx.sudo.sudo(api.tx.utility.batch(calls))); + for (const { core, paraId } of assignments) console.log(`assign-cores: core ${core} -> para ${paraId}`); } finally { await api.disconnect(); } diff --git a/packages/cli/src/fork/chains.ts b/packages/cli/src/fork/chains.ts index 5b1a7dc..3ca5096 100644 --- a/packages/cli/src/fork/chains.ts +++ b/packages/cli/src/fork/chains.ts @@ -24,6 +24,7 @@ export interface ForkParachain extends ForkChain { paraId: number; /** Curve this chain's Aura keys are on, as the descriptor declares it. */ aura?: AuraScheme; + cores: number; } export function parachainsOf(net: NetworkDef): ForkParachain[] { @@ -33,6 +34,7 @@ export function parachainsOf(net: NetworkDef): ForkParachain[] { endpoint: p.rpc, paraId: p.paraId, aura: p.aura, + cores: p.cores, })); } diff --git a/packages/cli/src/fork/overrides.ts b/packages/cli/src/fork/overrides.ts index ae00450..011b82d 100644 --- a/packages/cli/src/fork/overrides.ts +++ b/packages/cli/src/fork/overrides.ts @@ -268,7 +268,7 @@ async function coreLayoutCandidates( const config = patchNumCores(index, liveConfig, plan.length); console.log( - ` cores: ${paras.map((p) => `${p.key}=${coresFor(p.key, cores)}`).join(', ')} on cores 0-${plan.length - 1}, ` + + ` cores: ${paras.map((p) => `${p.key}=${coresFor(p, cores)}`).join(', ')} on cores 0-${plan.length - 1}, ` + `num_cores ${config.before} -> ${plan.length}, ${validators} validators` ); diff --git a/packages/cli/src/fork/shared-relay.ts b/packages/cli/src/fork/shared-relay.ts index c3fc89d..39919d3 100644 --- a/packages/cli/src/fork/shared-relay.ts +++ b/packages/cli/src/fork/shared-relay.ts @@ -48,17 +48,13 @@ export interface CoreAssignment { export interface PlannedPara { key: string; paraId: number; + /** The descriptor's core count for it. */ + cores: number; } -/** - * How many cores each parachain gets. - * - * Asset Hub keeps three: that is what gives it 2-second blocks through elastic scaling, and it - * is the one place where the number is a property of the network rather than a default. The - * rest get one each — unless the bite was asked for more (`ppn bite --cores people=3`). - */ -export function coresFor(key: string, cores: Record = {}): number { - return cores[key] ?? (key === 'asset-hub' ? 3 : 1); +/** How many cores a parachain gets: the descriptor's count, unless the bite was asked for another (`ppn bite --cores people=3`). */ +export function coresFor(para: PlannedPara, cores: Record = {}): number { + return cores[para.key] ?? para.cores; } /** @@ -72,7 +68,7 @@ export function planCores(paras: PlannedPara[], cores: Record = const plan: CoreAssignment[] = []; let core = 0; for (const para of paras) { - for (let i = 0; i < coresFor(para.key, cores); i++) plan.push({ core: core++, paraId: para.paraId }); + for (let i = 0; i < coresFor(para, cores); i++) plan.push({ core: core++, paraId: para.paraId }); } return plan; } diff --git a/packages/cli/src/fork/topology.ts b/packages/cli/src/fork/topology.ts index 6be5041..9412f4a 100644 --- a/packages/cli/src/fork/topology.ts +++ b/packages/cli/src/fork/topology.ts @@ -5,9 +5,8 @@ // are state inside the snapshots (fork/validators.ts, fork/shared-relay.ts), so the fork TOML // can only follow what the bundle says. A bundle bitten with the defaults carries no topology. -import type { ForkTopology, NetworkDef } from '@parity/ppn-network-config'; +import { MAX_VALIDATORS, type ForkTopology, type NetworkDef } from '@parity/ppn-network-config'; import { planCores } from './shared-relay.js'; -import { MAX_VALIDATORS } from './validators.js'; function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef): Record { const counts: Record = {}; diff --git a/packages/cli/src/fork/validators.ts b/packages/cli/src/fork/validators.ts index 8b14128..401a2c3 100644 --- a/packages/cli/src/fork/validators.ts +++ b/packages/cli/src/fork/validators.ts @@ -11,7 +11,7 @@ import { Keyring } from '@polkadot/keyring'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import { blake2128Concat, compactLen, keyOf, twox64Concat, u128le, u32le } from './codec.js'; -import { collatorNodeName, relayNodeName, type AuraScheme } from '@parity/ppn-network-config'; +import { collatorNodeName, MAX_VALIDATORS, relayNodeName, type AuraScheme } from '@parity/ppn-network-config'; export const ALICE_SR = 'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'; @@ -25,9 +25,6 @@ export interface DevValidator { authorityDiscovery: string; } -/** Relay RPC ports are `RELAY_BASE_PORT + i`, and the eleventh would land on People's. */ -export const MAX_VALIDATORS = 10; - /** * The names the relay's dev keys derive from, in the order the authority set lists them. * diff --git a/packages/cli/tests/assign-cores.test.ts b/packages/cli/tests/assign-cores.test.ts new file mode 100644 index 0000000..8ee3f6b --- /dev/null +++ b/packages/cli/tests/assign-cores.test.ts @@ -0,0 +1,54 @@ +// assign-cores runs on every start, from genesis and on kept chains alike. A plan that moved an +// assigned core would take it from a running chain, and one that used a core without a validator +// group would leave blocks on it unbacked. + +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import { loadNetwork } from '@parity/ppn-network-config'; +import { planExtraCores } from '../src/commands/service.js'; + +const PARACHAINS = loadNetwork('previewnet').parachains; + +/** Cores to para ids, as assignedCores() reads them off the relay. */ +const cores = (layout: Record) => + new Map(Object.entries(layout).map(([core, paraId]) => [Number(core), [paraId]])); + +describe('planExtraCores', () => { + it('hands the genesis extra cores to the parachains that run on more than one', () => { + // The genesis TOML adds four cores; the relay puts each parachain on one after them. + const genesis = cores({ 4: 1500, 5: 1502, 6: 1501, 7: 1600 }); + assert.deepEqual(planExtraCores(PARACHAINS, genesis, 8), { + assignments: [ + { core: 0, paraId: 1500 }, + { core: 1, paraId: 1500 }, + { core: 2, paraId: 1502 }, + { core: 3, paraId: 1502 }, + ], + missing: [], + }); + }); + + it('changes nothing on a relay that is already laid out', () => { + const laidOut = cores({ 0: 1500, 1: 1500, 2: 1500, 3: 1502, 4: 1501, 5: 1600, 6: 1502, 7: 1502 }); + assert.deepEqual(planExtraCores(PARACHAINS, laidOut, 8), { assignments: [], missing: [] }); + }); + + it('reports the cores a relay lacks validators for instead of taking them from another chain', () => { + const sixValidators = cores({ 0: 1500, 1: 1500, 2: 1500, 3: 1502, 4: 1501, 5: 1600 }); + assert.deepEqual(planExtraCores(PARACHAINS, sixValidators, 6), { + assignments: [], + missing: [{ key: 'people', cores: 2 }], + }); + }); + + it('gives a grown relay its new cores, leaving the assigned ones where they are', () => { + const grown = cores({ 0: 1500, 1: 1500, 2: 1500, 3: 1502, 4: 1501, 5: 1600 }); + assert.deepEqual(planExtraCores(PARACHAINS, grown, 8), { + assignments: [ + { core: 6, paraId: 1502 }, + { core: 7, paraId: 1502 }, + ], + missing: [], + }); + }); +}); diff --git a/packages/cli/tests/fork-shared-relay.test.ts b/packages/cli/tests/fork-shared-relay.test.ts index 5a9a9ec..37a7d28 100644 --- a/packages/cli/tests/fork-shared-relay.test.ts +++ b/packages/cli/tests/fork-shared-relay.test.ts @@ -7,6 +7,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; +import { loadNetwork } from '@parity/ppn-network-config'; import { compactLen, keyOf, twox64Concat, u32le } from '../src/fork/codec.js'; import { @@ -27,17 +28,12 @@ import { FULL_CORE, } from '../src/fork/shared-relay.js'; -const PNV2 = [ - { key: 'asset-hub', paraId: 1500 }, - { key: 'people', paraId: 1502 }, - { key: 'bulletin', paraId: 1501 }, -]; +const PNV2 = loadNetwork('paseo-next-v2').parachains; +const [ASSET_HUB, PEOPLE] = PNV2; describe('planCores', () => { - it('keeps Asset Hub on three cores, everything else on one', () => { - assert.equal(coresFor('asset-hub'), 3); - assert.equal(coresFor('people'), 1); - assert.equal(coresFor('bulletin'), 1); + it('takes each parachain core count from the descriptor: Asset Hub on three, the rest on one', () => { + assert.deepEqual(PNV2.map((p) => [p.key, coresFor(p)]), [['asset-hub', 3], ['people', 1], ['bulletin', 1]]); }); // Upward from zero is the whole point: those are the cores the runtime staffs first. @@ -60,9 +56,9 @@ describe('planCores', () => { // `ppn bite --cores people=3`: the asked-for count replaces the default for that chain only. it('lays a parachain out on as many cores as the bite asked for', () => { - assert.equal(coresFor('people', { people: 3 }), 3); - assert.equal(coresFor('asset-hub', { people: 3 }), 3, 'the default stays for the others'); - assert.equal(coresFor('asset-hub', { 'asset-hub': 1 }), 1, 'and can be cut too'); + assert.equal(coresFor(PEOPLE, { people: 3 }), 3); + assert.equal(coresFor(ASSET_HUB, { people: 3 }), 3, 'the default stays for the others'); + assert.equal(coresFor(ASSET_HUB, { 'asset-hub': 1 }), 1, 'and can be cut too'); assert.deepEqual(planCores(PNV2, { people: 3 }), [ { core: 0, paraId: 1500 }, { core: 1, paraId: 1500 }, diff --git a/packages/cli/tests/fork-validators.test.ts b/packages/cli/tests/fork-validators.test.ts index cdd3d63..f66f96f 100644 --- a/packages/cli/tests/fork-validators.test.ts +++ b/packages/cli/tests/fork-validators.test.ts @@ -7,7 +7,6 @@ import fs from 'node:fs'; import path from 'node:path'; import { ALICE_SR, - MAX_VALIDATORS, collatorKey, collatorKeys, devValidators, @@ -21,6 +20,7 @@ import { authorizedUpgradeCandidate, type DevValidator, } from '../src/fork/validators.js'; +import { MAX_VALIDATORS } from '@parity/ppn-network-config'; import { verify, verifyInjects } from '../src/fork/overrides.js'; import { compactLen, keyOf, twox64Concat, u32le } from '../src/fork/codec.js'; import { TypeRegistry } from '@polkadot/types'; diff --git a/packages/network-config/src/dashboard-model.ts b/packages/network-config/src/dashboard-model.ts index 2eb0ec1..a38db0d 100644 --- a/packages/network-config/src/dashboard-model.ts +++ b/packages/network-config/src/dashboard-model.ts @@ -105,8 +105,9 @@ export function dashboardModel(net: NetworkDef, baseUrl: string): DashboardModel const base = baseUrl.replace(/\/$/, ''); const chains: DashboardChain[] = []; - // Relay validators. Only the ones this network runs (a fork may run fewer than six). - for (let i = 0; i < net.relay.validators; i++) { + // Relay validators this network runs, up to the six well-known ones: those past them get no + // public path. + for (let i = 0; i < Math.min(net.relay.validators, VALIDATORS.length); i++) { const name = VALIDATORS[i]; const path = `/relay/${name}`; const port = RELAY_BASE_PORT + i; diff --git a/packages/network-config/src/networks.ts b/packages/network-config/src/networks.ts index 4855785..6ef3fdb 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -128,17 +128,28 @@ export interface NetworkParachain { rpcNodes: number; /** Extra args for the RPC nodes, applied over the chain's own args. */ rpcNodeArgs: string[]; + /** + * Relay cores this chain is laid out on, 1 when absent. More than one is elastic scaling, + * which shortens block time only when the runtime is built for that many blocks per relay block. + */ + cores: number; } /** RPC node i of a parachain listens on the chain's port + i, below the next chain's port. */ export const MAX_RPC_NODES = 9; -type ChainFields = Omit; +/** Relay RPC ports are `RELAY_BASE_PORT + i`, and the eleventh would land on People's. */ +export const MAX_VALIDATORS = 10; + +type ChainFields = Omit; export interface NetworkRelay extends ChainFields { /** Built-in chain name doppelganger runs with (ZOMBIE_CHAIN), e.g. 'paseo'. */ chain: string; - /** Dev-key validators the fork runs with, max 6 (alice…ferdie). */ + /** + * Relay validators: alice…ferdie, then Validator-7… up to MAX_VALIDATORS. At least one per + * parachain core, since a core without a validator group backs nothing. + */ validators: number; /** Same as `runtime`, but used when `PPN_PROFILE` is `local`. Needs a different `file`. */ fastRuntime?: RuntimeRef; @@ -425,9 +436,20 @@ export function loadDescriptor(name: string): NetworkDef { } } + const cores = Object.fromEntries( + raw.parachains.map((p: NetworkParachain) => { + const count = p.cores ?? 1; + if (!Number.isInteger(count) || count < 1) bad(`parachains.${p.key}.cores must be an integer of at least 1`); + return [p.key, count]; + }) + ); + const totalCores = Object.values(cores).reduce((sum, count) => sum + count, 0); const validators = raw.relay.validators ?? 6; - if (!Number.isInteger(validators) || validators < 1 || validators > 6) { - bad('relay.validators must be 1..6 (alice…ferdie)'); + if (!Number.isInteger(validators) || validators < 1 || validators > MAX_VALIDATORS) { + bad(`relay.validators must be 1..${MAX_VALIDATORS}`); + } + if (validators < totalCores) { + bad(`relay.validators is ${validators}, fewer than the ${totalCores} cores of the parachains: a core without a validator backs nothing`); } const services: Record = raw.services ?? {}; @@ -477,6 +499,7 @@ export function loadDescriptor(name: string): NetworkDef { extraArgs: checkArgs(`parachains.${p.key}`, p.extraArgs), rpcNodes: parseRpcNodes(`parachains.${p.key}.rpcNodes`, p.rpcNodes, bad), rpcNodeArgs: parseArgs(`parachains.${p.key}.rpcNodeArgs`, p.rpcNodeArgs, bad), + cores: cores[p.key], })), services, turnProofProducts: parseTurnProofProducts( diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index 7d79c8b..3c5d14b 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -14,7 +14,7 @@ import path from 'node:path'; import { repoRoot } from './repo-root.js'; import { PARACHAIN_KEYS } from './types.js'; import type { Parachain, ChainKey, ChainDef, LogLevel, GenerateTomlOptions } from './types.js'; -import { DEFAULT_NETWORK, type NetworkDef, type NetworkParachain } from './networks.js'; +import { DEFAULT_NETWORK, MAX_VALIDATORS, type NetworkDef, type NetworkParachain } from './networks.js'; import { loadNetwork } from './load.js'; import { dubCustomProcesses } from './dub.js'; import { addMissing, flagOf, overrideArgs } from './args.js'; @@ -43,12 +43,12 @@ const VALID_PARACHAINS: Parachain[] = PARACHAIN_KEYS; // Genesis is previewnet-only by design (see networks/README.md), but everything about // previewnet that the descriptor states — para ids, chain ids, spec files, binaries, -// per-chain flags, validator count and naming, which services run — is read from it -// here rather than restated, so this generator and fork mode cannot disagree, and +// per-chain flags, core counts, validator count and naming, which services run — is read +// from it here rather than restated, so this generator and fork mode cannot disagree, and // editing the descriptor changes both. // -// What stays in code is what the descriptor does not describe: the elastic-scaling -// core count, the HRMP topology, and the bootstrap processes' own arguments. +// What stays in code is what the descriptor does not describe: the HRMP topology and the +// bootstrap processes' own arguments. // Loaded on first use, not at import. A module-level load makes importing this package // require a descriptor on disk — which is fine in a checkout and fatal once published: a // consumer that only wants the types or the generators cannot even import it, and the failure @@ -137,7 +137,8 @@ function prometheusPort(rpcPort: number): number { /** RPC ports of a parachain's RPC nodes: the chain's own port + 1..rpcNodes. Throws on a port another chain uses. */ function rpcNodePorts(parachain: NetworkParachain): number[] { const ports = Array.from({ length: parachain.rpcNodes }, (_, index) => PORTS[parachain.key] + index + 1); - const used = [...Object.values(PORTS), ...VALIDATORS.map((_, index) => RELAY_BASE_PORT + index)]; + const relayPorts = Array.from({ length: MAX_VALIDATORS }, (_, index) => RELAY_BASE_PORT + index); + const used = [...Object.values(PORTS), ...relayPorts]; const clash = ports.find((port) => used.includes(port)); if (clash !== undefined) { throw new Error( @@ -346,7 +347,7 @@ ${rpcNodeBlocks(genesisChainOf(key) as NetworkParachain, args, launch)}`; } function validatorNodes(count: number): string { - return VALIDATORS.slice(0, count) + return Array.from({ length: count }, (_, i) => relayNodeName(i)) .map( (v, i) => ` [[relaychain.nodes]] @@ -408,12 +409,16 @@ function calcValidatorCount(parachains: Parachain[] | null): number { const selected = new Set( (parachains || []).filter((p) => VALID_PARACHAINS.includes(p)) ); - // Asset Hub's elastic scaling needs two extra validators for the extra cores. The - // ceiling is what the descriptor says this network runs with. - return Math.max( - 4, - Math.min(genesisNet().relay.validators, selected.size + (selected.has('asset-hub') ? 2 : 0) + 1) - ); + const cores = genesisNet().parachains.filter((p) => selected.has(p.key)).reduce((sum, p) => sum + p.cores, 0); + // Every core needs a validator group of its own. The ceiling is what the descriptor says this + // network runs with, and the descriptor rejects a count below its cores. + return Math.max(4, Math.min(genesisNet().relay.validators, cores + 1)); +} + +/** The section title, with the core count of a chain that runs on more than one. */ +function parachainTitle(key: Parachain, name: string): string { + const cores = (genesisChainOf(key) as NetworkParachain).cores; + return `${name} (Parachain ${paraIds()[key]})${cores > 1 ? ` - Elastic Scaling on ${cores} cores` : ''}`; } // --------------------------------------------------------------------------- @@ -464,6 +469,9 @@ function generateToml(parachains: Parachain[] | null, options: GenerateTomlOptio const lt = options.logTargets || {}; const validatorCount = calcValidatorCount(parachains); + // The relay puts each parachain registered at genesis on one core after these; assign-cores + // hands these out to the chains that run on more than one. + const extraCores = genesisNet().parachains.filter((p) => has(p.key)).reduce((sum, p) => sum + p.cores - 1, 0); const hasChannels = both('people', 'bulletin') || both('people', 'asset-hub'); @@ -478,11 +486,11 @@ function generateToml(parachains: Parachain[] | null, options: GenerateTomlOptio timeout = 600 node_spawn_timeout = 240 ${section( - has('asset-hub'), + extraCores > 0, ` -# Elastic scaling: 2 extra cores for Asset Hub 2-second blocks +# Elastic scaling: the cores beyond each parachain's first, which assign-cores hands out [relaychain.genesis.configuration.config.scheduler_params] -num_cores = 2 +num_cores = ${extraCores} max_validators_per_core = 1 ` )} @@ -496,24 +504,24 @@ ${section( has('asset-hub'), genesisParachainSection( 'asset-hub', - `Asset Hub Paseo Next (Parachain ${paraIds()['asset-hub']}) - Elastic Scaling with 2-second blocks`, + parachainTitle('asset-hub', 'Asset Hub Paseo Next'), genesisChainArgs('asset-hub', lt['asset-hub']) ) )}${section( has('people'), - genesisParachainSection('people', `People Chain (Parachain ${paraIds().people})`, genesisChainArgs('people', lt.people)) + genesisParachainSection('people', parachainTitle('people', 'People Chain'), genesisChainArgs('people', lt.people)) )}${section( has('bulletin'), genesisParachainSection( 'bulletin', - `Bulletin Chain (Parachain ${paraIds().bulletin})`, + parachainTitle('bulletin', 'Bulletin Chain'), genesisChainArgs('bulletin', lt.bulletin, options.enableHop) ) )}${section( has('web3-storage'), genesisParachainSection( 'web3-storage', - `Web3 Storage Chain (Parachain ${paraIds()['web3-storage']})`, + parachainTitle('web3-storage', 'Web3 Storage Chain'), genesisChainArgs('web3-storage', lt['web3-storage']) ) )}${section(both('people', 'bulletin'), hrmpPair(paraIds().people, paraIds().bulletin))} @@ -602,12 +610,15 @@ ${section(serviceEnabled('pin-design-families'), ` name = "pin-design-families" command = "{{SCRIPTS}}/pin-design-families.sh" `)}${section( - has('asset-hub') && serviceEnabled('assign-cores'), + extraCores > 0 && serviceEnabled('assign-cores'), ` [[custom_processes]] name = "assign-cores" command = "{{SCRIPTS}}/assign-cores.sh" - +` +)}${section( + has('asset-hub') && serviceEnabled('assign-cores'), + ` [[custom_processes]] name = "set-dispatcher-address" command = "{{SCRIPTS}}/set-dispatcher-address.sh" diff --git a/packages/network-config/tests/fork-toml.test.ts b/packages/network-config/tests/fork-toml.test.ts index 6a90a5c..bb498c5 100644 --- a/packages/network-config/tests/fork-toml.test.ts +++ b/packages/network-config/tests/fork-toml.test.ts @@ -162,8 +162,8 @@ describe('generateForkToml — relay chain', () => { it('sets the dispute lifetime env var on every relay node', () => { const nodes = toml.split('[[relaychain.nodes]]').length - 1; const envs = toml.split('ZOMBIE_DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION').length - 1; - assert.equal(nodes, 6); - assert.equal(envs, 6); + assert.equal(nodes, 8); + assert.equal(envs, 8); }); it('only gives a p2p port to the first node', () => { diff --git a/packages/network-config/tests/networks.test.ts b/packages/network-config/tests/networks.test.ts index bc03c5a..0280278 100644 --- a/packages/network-config/tests/networks.test.ts +++ b/packages/network-config/tests/networks.test.ts @@ -17,6 +17,7 @@ import { asHttp, asWs, DEFAULT_NETWORK, + type NetworkDef, } from '../src/networks.js'; import { loadNetwork } from '../src/load.js'; import { repoRoot } from '../src/repo-root.js'; @@ -55,7 +56,11 @@ describe('network descriptors', () => { // The one place bundle spec name and chain key differ. assert.equal(net.parachains.find((p) => p.key === 'people')!.spec, 'individuality'); assert.equal(net.relay.chain, 'paseo'); - assert.equal(net.relay.validators, 6); + assert.equal(net.relay.validators, 8); + assert.deepEqual( + Object.fromEntries(net.parachains.map((p) => [p.key, p.cores])), + { 'asset-hub': 3, people: 3, bulletin: 1, 'web3-storage': 1 } + ); }); // The rule this whole registry exists to encode. @@ -286,25 +291,28 @@ describe('product import', () => { }); }); -describe('turnProofProducts', () => { - function loadWith(fields: Record): () => ReturnType { - return () => { - const saved = process.env.PPN_HOME; - const home = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-home-')); - fs.mkdirSync(path.join(home, 'networks')); - const raw = JSON.parse(fs.readFileSync(path.join(repoRoot(), 'networks/previewnet.json'), 'utf-8')); - fs.writeFileSync(path.join(home, 'networks', 'proof-test.json'), JSON.stringify({ ...raw, name: 'proof-test', ...fields })); - process.env.PPN_HOME = home; - try { - return loadNetwork('proof-test'); - } finally { - if (saved === undefined) delete process.env.PPN_HOME; - else process.env.PPN_HOME = saved; - fs.rmSync(home, { recursive: true, force: true }); - } - }; - } +type RawDescriptor = Record & { relay: Record; parachains: Record[] }; +/** Loads previewnet's descriptor as changed by `edit`, under another name. */ +function loadEdited(edit: (raw: RawDescriptor) => RawDescriptor): () => NetworkDef { + return () => { + const saved = process.env.PPN_HOME; + const home = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-home-')); + fs.mkdirSync(path.join(home, 'networks')); + const raw = JSON.parse(fs.readFileSync(path.join(repoRoot(), 'networks/previewnet.json'), 'utf-8')); + fs.writeFileSync(path.join(home, 'networks', 'edited.json'), JSON.stringify({ ...edit(raw), name: 'edited' })); + process.env.PPN_HOME = home; + try { + return loadNetwork('edited'); + } finally { + if (saved === undefined) delete process.env.PPN_HOME; + else process.env.PPN_HOME = saved; + fs.rmSync(home, { recursive: true, force: true }); + } + }; +} + +describe('turnProofProducts', () => { it('accepts Jollity on previewnet, under its TLD', () => { assert.deepEqual(loadNetwork('previewnet').turnProofProducts, ['dim2.testnet']); }); @@ -314,7 +322,30 @@ describe('turnProofProducts', () => { }); it('rejects a product that is not a name under the network TLD', () => { - assert.throws(loadWith({ turnProofProducts: ['dim2'] }), /dotNS names under \.testnet/); - assert.throws(loadWith({ turnProofProducts: ['dim2.paseo'] }), /dotNS names under \.testnet/); + assert.throws(loadEdited((raw) => ({ ...raw, turnProofProducts: ['dim2'] })), /dotNS names under \.testnet/); + assert.throws(loadEdited((raw) => ({ ...raw, turnProofProducts: ['dim2.paseo'] })), /dotNS names under \.testnet/); + }); +}); + +// A core whose validator group is empty backs nothing, so a descriptor that lays its parachains +// out on more cores than it has validators describes a network whose blocks stall. +describe('cores', () => { + it('defaults a parachain to one core', () => { + const net = loadEdited((raw) => ({ ...raw, parachains: raw.parachains.map(({ cores: _, ...p }) => p) }))(); + assert.deepEqual(net.parachains.map((p) => p.cores), [1, 1, 1, 1]); + }); + + it('rejects fewer relay validators than cores', () => { + assert.throws( + loadEdited((raw) => ({ ...raw, relay: { ...raw.relay, validators: 7 } })), + /relay\.validators is 7, fewer than the 8 cores/ + ); + }); + + it('rejects a parachain on no core', () => { + assert.throws( + loadEdited((raw) => ({ ...raw, parachains: raw.parachains.map((p) => (p.key === 'people' ? { ...p, cores: 0 } : p)) })), + /parachains\.people\.cores must be an integer of at least 1/ + ); }); }); diff --git a/packages/network-config/tests/toml-generator.test.ts b/packages/network-config/tests/toml-generator.test.ts index 99e5455..c57688a 100644 --- a/packages/network-config/tests/toml-generator.test.ts +++ b/packages/network-config/tests/toml-generator.test.ts @@ -76,22 +76,20 @@ describe('generateToml', () => { assert.ok(toml.includes('[settings]')); assert.ok(toml.includes('timeout = 600')); - // Elastic scaling for asset-hub + // Elastic scaling: two extra cores each for asset-hub and people assert.ok(toml.includes('[relaychain.genesis.configuration.config.scheduler_params]')); - assert.ok(toml.includes('num_cores = 2')); + assert.ok(toml.includes('num_cores = 4')); // Relay chain assert.ok(toml.includes('[relaychain]')); assert.ok(toml.includes('chain = "paseo-local"')); assert.ok(toml.includes('chain_spec_path = "{{BIN}}/relay_paseo.json"')); - // 6 validators (3 parachains + 2 for asset-hub + 1 = 6, clamped to 6) - assert.ok(toml.includes('alice-paseo-validator')); - assert.ok(toml.includes('bob-paseo-validator')); - assert.ok(toml.includes('charlie-paseo-validator')); - assert.ok(toml.includes('dave-paseo-validator')); - assert.ok(toml.includes('eve-paseo-validator')); - assert.ok(toml.includes('ferdie-paseo-validator')); + // 8 validators: one per core (3 + 3 + 1), plus one, capped at the descriptor's 8 + for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'Validator-7', 'Validator-8']) { + assert.ok(toml.includes(`name = "${name}-paseo-validator"`), name); + } + assert.ok(!toml.includes('Validator-9')); // All parachains assert.ok(toml.includes('id = 1500')); @@ -145,12 +143,12 @@ describe('generateToml', () => { it('generates TOML for people + bulletin', () => { const toml = generateToml(['people', 'bulletin']); - // No elastic scaling - assert.ok(!toml.includes('num_cores')); + // People's two extra cores + assert.ok(toml.includes('num_cores = 2')); - // 4 validators (2 + 0 + 1 = 3, clamped to 4) - assert.ok(toml.includes('dave-paseo-validator')); - assert.ok(!toml.includes('eve-paseo-validator')); + // 5 validators (3 + 1 + 1) + assert.ok(toml.includes('eve-paseo-validator')); + assert.ok(!toml.includes('ferdie-paseo-validator')); // People and bulletin only assert.ok(!toml.includes('id = 1500')); @@ -167,7 +165,7 @@ describe('generateToml', () => { assert.ok(toml.includes('name = "force-open-hrmp"')); assert.ok(toml.includes('name = "increase-people-lite-attestation-allowance"')); assert.ok(!toml.includes('name = "eth-rpc"')); - assert.ok(!toml.includes('name = "assign-cores"')); + assert.ok(toml.includes('name = "assign-cores"')); }); it('generates TOML for bulletin only', () => { @@ -204,7 +202,8 @@ describe('generateToml', () => { assert.ok(!toml.includes('name = "inject-bootnodes"')); assert.ok(!toml.includes('name = "eth-rpc"')); assert.ok(!toml.includes('name = "ipfs-daemon"')); - assert.ok(!toml.includes('name = "assign-cores"')); + assert.ok(toml.includes('name = "assign-cores"')); + assert.ok(!toml.includes('name = "set-dispatcher-address"')); assert.ok(toml.includes('name = "increase-people-lite-attestation-allowance"')); }); @@ -432,26 +431,24 @@ describe('generateToml validation', () => { }); describe('calcValidatorCount', () => { - it('returns 4 for single non-asset-hub parachain', () => { + it('returns 4 for a single one-core parachain', () => { assert.equal(calcValidatorCount(['bulletin']), 4); - assert.equal(calcValidatorCount(['people']), 4); }); - it('returns 4 for asset-hub alone (1+2+1=4)', () => { + it('returns 4 for a three-core parachain alone (3+1=4)', () => { assert.equal(calcValidatorCount(['asset-hub']), 4); + assert.equal(calcValidatorCount(['people']), 4); }); - it('returns 5 for asset-hub + one other (2+2+1=5)', () => { - assert.equal(calcValidatorCount(['asset-hub', 'people']), 5); + it('gives every core of the selection a validator, plus one', () => { + assert.equal(calcValidatorCount(['asset-hub', 'people']), 7); assert.equal(calcValidatorCount(['asset-hub', 'bulletin']), 5); + assert.equal(calcValidatorCount(['people', 'bulletin']), 5); }); - it('returns 4 for two non-asset-hub (2+0+1=3, clamped to 4)', () => { - assert.equal(calcValidatorCount(['people', 'bulletin']), 4); - }); - - it('returns 6 for all parachains (3+2+1=6)', () => { - assert.equal(calcValidatorCount(['asset-hub', 'people', 'bulletin']), 6); + it('caps at the descriptor count, which covers every core', () => { + assert.equal(calcValidatorCount(['asset-hub', 'people', 'bulletin']), 8); + assert.equal(calcValidatorCount([...VALID_PARACHAINS]), 8); }); it('returns 4 for empty/null input', () => { diff --git a/zombienet-configs/local-dev.toml b/zombienet-configs/local-dev.toml index ead6e39..149dba9 100644 --- a/zombienet-configs/local-dev.toml +++ b/zombienet-configs/local-dev.toml @@ -5,9 +5,9 @@ timeout = 600 node_spawn_timeout = 240 -# Elastic scaling: 2 extra cores for Asset Hub 2-second blocks +# Elastic scaling: the cores beyond each parachain's first, which assign-cores hands out [relaychain.genesis.configuration.config.scheduler_params] -num_cores = 2 +num_cores = 4 max_validators_per_core = 1 [relaychain] @@ -59,7 +59,21 @@ rpc_port = 10005 prometheus_port = 20005 balance = 1000000000000000 -## Asset Hub Paseo Next (Parachain 1500) - Elastic Scaling with 2-second blocks +[[relaychain.nodes]] +name = "Validator-7-paseo-validator" +validator = true +rpc_port = 10006 +prometheus_port = 20006 +balance = 1000000000000000 + +[[relaychain.nodes]] +name = "Validator-8-paseo-validator" +validator = true +rpc_port = 10007 +prometheus_port = 20007 +balance = 1000000000000000 + +## Asset Hub Paseo Next (Parachain 1500) - Elastic Scaling on 3 cores [[parachains]] id = 1500 cumulus_based = true @@ -74,7 +88,7 @@ prometheus_port = 20020 command = "{{SCRIPTS}}/omni-node.sh" args = ["-lxcm=trace", "--rpc-max-connections=500", "--force-authoring", "--authoring=slot-based", "--unsafe-rpc-external", "--rpc-max-response-size=50", "--listen-addr=/ip4/127.0.0.1/udp/30335/webrtc-direct"] -## People Chain (Parachain 1502) +## People Chain (Parachain 1502) - Elastic Scaling on 3 cores [[parachains]] id = 1502 cumulus_based = true From 5f3bd3c79bb2e69e81683915e165090e06ef619f Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:03:42 +0000 Subject: [PATCH 02/14] Check in the integration run that People makes a block every 2 s --- tests/03-people-chain.zndsl | 3 ++ tests/scripts/test-people-block-time.ts | 37 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/scripts/test-people-block-time.ts diff --git a/tests/03-people-chain.zndsl b/tests/03-people-chain.zndsl index 0b33ff3..6443a63 100644 --- a/tests/03-people-chain.zndsl +++ b/tests/03-people-chain.zndsl @@ -13,6 +13,9 @@ people-collator1: is up alice-paseo-validator: parachain 1502 is registered within 400 seconds alice-paseo-validator: parachain 1502 block height is at least 5 within 500 seconds +# Three cores give a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner +people-collator1: js-script ./scripts/dist/test-people-block-time.js with "3" return is equal to 1 within 300 seconds + # ============================================ # Individuality Pallet Tests # ============================================ diff --git a/tests/scripts/test-people-block-time.ts b/tests/scripts/test-people-block-time.ts new file mode 100644 index 0000000..c52e0d5 --- /dev/null +++ b/tests/scripts/test-people-block-time.ts @@ -0,0 +1,37 @@ +import type { PolkadotClient } from "polkadot-api"; +import type { NetworkInfo } from "./types/zombienet"; +import { SUCCESS, FAILURE, connectWithRetry, safeDisconnect, sleep, waitForChainReady } from "./utils"; + +const WINDOW_SECONDS = 60; + +/** + * Passes when People averages at most `args[0]` seconds per block over a minute. On one core it + * makes a block every 6 s; on the three cores the descriptor gives it, every 2 s. + */ +export async function run(nodeName: string, networkInfo: NetworkInfo, args: string[]): Promise { + let client: PolkadotClient | null = null; + try { + const maxSeconds = Number(args[0]); + const node = networkInfo.nodesByName[nodeName]; + if (!node || !(maxSeconds > 0)) { + console.error(`[TEST] needs a known node and a block time in seconds, got ${nodeName} and ${args[0]}`); + return FAILURE; + } + const connection = await connectWithRetry(node.wsUri, "people"); + client = connection.client; + const api = connection.api; + await waitForChainReady(api); + + const start = await api.query.System.Number.getValue({ at: "best" }); + await sleep(WINDOW_SECONDS * 1000); + const blocks = (await api.query.System.Number.getValue({ at: "best" })) - start; + const average = WINDOW_SECONDS / blocks; + console.log(`[TEST] ${blocks} People blocks in ${WINDOW_SECONDS}s: ${average.toFixed(2)}s per block, at most ${maxSeconds}s`); + return average <= maxSeconds ? SUCCESS : FAILURE; + } catch (error) { + console.error(`[TEST] ${(error as Error).message}`); + return FAILURE; + } finally { + safeDisconnect(client); + } +} From 51e2252e1013d93cbd8a5b267cf9363792016135 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:13:27 +0000 Subject: [PATCH 03/14] Give no extra core to a parachain the relay does not run --- packages/cli/src/commands/fork.ts | 2 +- packages/cli/src/commands/service.ts | 34 +++++++++++-------------- packages/cli/tests/assign-cores.test.ts | 12 +++++++++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/packages/cli/src/commands/fork.ts b/packages/cli/src/commands/fork.ts index 4aab3b2..e31e32e 100644 --- a/packages/cli/src/commands/fork.ts +++ b/packages/cli/src/commands/fork.ts @@ -84,7 +84,7 @@ export async function run(args: string[]): Promise { endpointOf(relay, NETWORK, baseUrl), `${outDir}/rc_overrides.json`, { - paras: PARACHAINS.map((p) => ({ key: p.key, paraId: p.paraId, cores: p.cores })), + paras: PARACHAINS, validators: topology?.validators ?? NETWORK.relay.validators, cores: topology?.cores, sharedRelay: NETWORK.bite.sharedRelay === true, diff --git a/packages/cli/src/commands/service.ts b/packages/cli/src/commands/service.ts index a0b930b..d60f4e5 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -20,6 +20,7 @@ import { loadCurrentNetwork, readEnvFile, hrmpChannels, type NetworkDef, repoRoo } from '@parity/ppn-network-config'; import { forkBundleName } from '../lib/fork-bundle-name.js'; import { loadSecrets } from '../lib/secrets.js'; +import type { CoreAssignment, PlannedPara } from '../fork/shared-relay.js'; const REPO = repoRoot(); /** Mutable state — binaries, chain data, bundles — lives in the workspace, not the package. */ @@ -116,33 +117,28 @@ export async function run(args: string[], deps: ServiceDeps = {}): Promise // assign-cores — elastic scaling // --------------------------------------------------------------------------- -/** A parachain's core count as the descriptor states it. */ -export interface CoreTarget { - key: string; - paraId: number; - cores: number; -} - /** - * The assignments that bring each parachain up to its descriptor core count, and what still - * lacks a core afterwards. Uses only cores below `coreCount` (one per validator group, since a - * core without a group backs nothing) that nothing is assigned to, lowest first, and never - * moves an assigned core, so running it again on a kept chain changes nothing. + * The assignments that bring each parachain the relay runs up to its descriptor core count, and + * what still lacks a core afterwards. A parachain on no core is not running there (a spawn of a + * subset of chains) and gets none. Uses only cores below `coreCount` (one per validator group, + * since a core without a group backs nothing) that nothing is assigned to, lowest first, and + * never moves an assigned core, so running it again on a kept chain changes nothing. */ export function planExtraCores( - targets: CoreTarget[], + paras: PlannedPara[], assigned: Map, coreCount: number -): { assignments: { core: number; paraId: number }[]; missing: { key: string; cores: number }[] } { +): { assignments: CoreAssignment[]; missing: { key: string; cores: number }[] } { const free = Array.from({ length: coreCount }, (_, core) => core).filter((core) => !assigned.has(core)); - const assignments: { core: number; paraId: number }[] = []; + const assignments: CoreAssignment[] = []; const missing: { key: string; cores: number }[] = []; - for (const target of targets) { - const held = [...assigned.values()].filter((paraIds) => paraIds.includes(target.paraId)).length; - const lacking = Math.max(0, target.cores - held); + for (const para of paras) { + const held = [...assigned.values()].filter((paraIds) => paraIds.includes(para.paraId)).length; + if (held === 0) continue; + const lacking = Math.max(0, para.cores - held); const granted = free.splice(0, lacking); - assignments.push(...granted.map((core) => ({ core, paraId: target.paraId }))); - if (granted.length < lacking) missing.push({ key: target.key, cores: lacking - granted.length }); + assignments.push(...granted.map((core) => ({ core, paraId: para.paraId }))); + if (granted.length < lacking) missing.push({ key: para.key, cores: lacking - granted.length }); } return { assignments, missing }; } diff --git a/packages/cli/tests/assign-cores.test.ts b/packages/cli/tests/assign-cores.test.ts index 8ee3f6b..3a6ec6b 100644 --- a/packages/cli/tests/assign-cores.test.ts +++ b/packages/cli/tests/assign-cores.test.ts @@ -51,4 +51,16 @@ describe('planExtraCores', () => { missing: [], }); }); + + // `PPN_PARACHAINS=people,bulletin`: Asset Hub comes first in the descriptor but is not registered. + it('gives no core to a parachain the relay does not run', () => { + const subset = cores({ 2: 1502, 3: 1501 }); + assert.deepEqual(planExtraCores(PARACHAINS, subset, 5), { + assignments: [ + { core: 0, paraId: 1502 }, + { core: 1, paraId: 1502 }, + ], + missing: [], + }); + }); }); From 21b7827f95f85260fe2e27b032c5b8f6771bd82d Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:13:27 +0000 Subject: [PATCH 04/14] Keep forks on the descriptor's six validators, growing a genesis spawn to one per core --- docs/FORK.md | 2 +- networks/README.md | 2 +- networks/previewnet.json | 2 +- packages/cli/src/fork/overrides.ts | 9 ++++----- packages/cli/src/fork/shared-relay.ts | 9 +++++++++ packages/cli/src/fork/topology.ts | 10 +++++----- packages/network-config/src/bundle.ts | 7 +++---- packages/network-config/src/dashboard-model.ts | 5 ++--- packages/network-config/src/networks.ts | 15 ++++++++------- packages/network-config/src/toml-generator.ts | 6 +++--- packages/network-config/tests/fork-toml.test.ts | 4 ++-- packages/network-config/tests/networks.test.ts | 8 ++++---- .../network-config/tests/toml-generator.test.ts | 14 +++++++------- 13 files changed, 50 insertions(+), 43 deletions(-) diff --git a/docs/FORK.md b/docs/FORK.md index 055f790..9545c58 100644 --- a/docs/FORK.md +++ b/docs/FORK.md @@ -109,7 +109,7 @@ refuses a bundle whose recorded layout differs from what it was asked for and sa The bundle's `manifest.json` carries the layout under `topology`, and the fork TOML follows it. The relay grows to one validator per core, because a core with no validator group backs nothing: -paseo-next-v2 with `people=3` is 3 + 3 + 1 = 7 cores, so 7 validators. Past the well-known six +previewnet with `people=3` is 3 + 3 + 1 + 1 = 8 cores, so 8 validators. Past the well-known six they are named `Validator-7`, `Validator-8`, … and their keys derived from those names, the same way zombienet does it; the cap is 10, where the relay RPC ports (`10000 + i`) would run into People's. Extra collators are `Collator--2` … and restore the same snapshot as the first; diff --git a/networks/README.md b/networks/README.md index 98405a5..6c59599 100644 --- a/networks/README.md +++ b/networks/README.md @@ -50,7 +50,7 @@ or `PPN_NETWORK=` in the environment of the scripts. | `relay.rpc`, `parachains[].rpc` | RPC endpoint: an absolute `ws(s)://`/`http(s)://` URL, or a path resolved against `bite.source`. | | `rpcAlternates` | Informational: other public providers for the same chain, for when the primary is re-homed. Not consumed by tooling (yet). | | `relay.specSource`, `parachains[].specSource` | Explicit location of the chain spec the bite warp-syncs from (it must carry the live network's bootnodes): an absolute URL, a path resolved against `bite.source` (previewnet uses `chainspecs/-local.json`, so biting a different instance follows the base-URL override), or `"builtin"` (generated with `build-spec --chain --raw`, relay only). | -| `relay.validators` | Number of relay validators, 1..10: alice…ferdie, then `Validator-7`… with keys derived from those names. At least the parachains' total `cores`, which loading the descriptor checks: a core with no validator group backs nothing. The genesis TOML and a fork both run this many; only the well-known six get a public `/relay/` path. | +| `relay.validators` | Number of dev-key validators the fork runs with (max 6: alice…ferdie). A bite asked for `--cores` and a genesis spawn run one per core where that is more, named `Validator-7`… with keys derived from those names; the parachains' total `cores` can be at most 10. | | `parachains[].key` | One of `asset-hub`, `people`, `bulletin`, `web3-storage` — the keys PPN's port table and per-chain flags are defined for. | | `parachains[].paraId` | The network's real para id. Previewnet/paseo-next-v2 use the 1500 band; devnet and real networks the 1000 band. | | `parachains[].cores` | Relay cores the chain runs on, 1 when absent. More than one is elastic scaling, and shortens block time only when the runtime is built for that many blocks per relay block (previewnet's Asset Hub and People: 3, so 2-second blocks). Genesis adds the extra cores and `assign-cores` hands them out. A fork of a shared relay lays its parachains out with these counts and `--cores` overrides them; a previewnet fork keeps the layout it bit. | diff --git a/networks/previewnet.json b/networks/previewnet.json index ad36e70..b180aa9 100644 --- a/networks/previewnet.json +++ b/networks/previewnet.json @@ -48,7 +48,7 @@ "spec": "paseo", "rpc": "relay/alice", "specSource": "chainspecs/paseo-local.json", - "validators": 8, + "validators": 6, "binary": { "name": "polkadot", "release": "polkadot-sdk" diff --git a/packages/cli/src/fork/overrides.ts b/packages/cli/src/fork/overrides.ts index 011b82d..88bad63 100644 --- a/packages/cli/src/fork/overrides.ts +++ b/packages/cli/src/fork/overrides.ts @@ -20,6 +20,7 @@ import { hrmpParaKey, paraMessagingWipes, planCores, + relaysCores, transactionStorageWipes, validatorGroups, type PlannedPara, @@ -386,11 +387,9 @@ export async function relayOverrides( const validators = await devValidators(layout.validators); console.log('relay:'); - // Production's own core layout is kept unless it has to move: a shared relay's is wrong for - // us, and a bite asked for cores is asking for a layout production does not have. Order - // matters: these values replace the ones relayCandidates() sets (ValidatorGroups above all), - // so they come second. - const relaid = layout.sharedRelay || Object.keys(layout.cores ?? {}).length > 0; + // Order matters: these values replace the ones relayCandidates() sets (ValidatorGroups above + // all), so they come second. + const relaid = relaysCores(layout.sharedRelay, layout.cores); const candidates = { ...relayCandidates(validators), ...(relaid ? await coreLayoutCandidates(index, relayUrl, layout) : {}), diff --git a/packages/cli/src/fork/shared-relay.ts b/packages/cli/src/fork/shared-relay.ts index 39919d3..a918479 100644 --- a/packages/cli/src/fork/shared-relay.ts +++ b/packages/cli/src/fork/shared-relay.ts @@ -57,6 +57,15 @@ export function coresFor(para: PlannedPara, cores: Record = {}): return cores[para.key] ?? para.cores; } +/** + * Whether a bite lays the relay's cores out anew. A shared relay's layout is wrong for us, and a + * bite asked for cores is asking for a layout production does not have; otherwise production's + * own layout is kept, with the validators it already staffs. + */ +export function relaysCores(sharedRelay: boolean, cores: Record = {}): boolean { + return sharedRelay || Object.keys(cores).length > 0; +} + /** * Lay the parachains out from core 0 upward. * diff --git a/packages/cli/src/fork/topology.ts b/packages/cli/src/fork/topology.ts index 9412f4a..ca0582e 100644 --- a/packages/cli/src/fork/topology.ts +++ b/packages/cli/src/fork/topology.ts @@ -6,7 +6,7 @@ // can only follow what the bundle says. A bundle bitten with the defaults carries no topology. import { MAX_VALIDATORS, type ForkTopology, type NetworkDef } from '@parity/ppn-network-config'; -import { planCores } from './shared-relay.js'; +import { planCores, relaysCores } from './shared-relay.js'; function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef): Record { const counts: Record = {}; @@ -30,9 +30,9 @@ function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef) /** * The topology a bite was asked for, or undefined when it was asked for nothing. * - * The validator count is not asked for: every core needs a validator group of its own or nothing - * backs the blocks on it, so it is the descriptor's count or the number of cores, whichever is - * larger. That is capped where the relay ports run out (MAX_VALIDATORS). + * The validator count is not asked for: every core a bite lays out needs a validator group of its + * own or nothing backs the blocks on it, so it is the descriptor's count or the number of those + * cores, whichever is larger. That is capped where the relay ports run out (MAX_VALIDATORS). */ export function resolveTopology( opts: { cores?: string[]; collators?: string[] }, @@ -42,7 +42,7 @@ export function resolveTopology( const collators = parseCounts('--collators', opts.collators, net); if (!Object.keys(cores).length && !Object.keys(collators).length) return undefined; - const totalCores = planCores(net.parachains, cores).length; + const totalCores = relaysCores(net.bite.sharedRelay === true, cores) ? planCores(net.parachains, cores).length : 0; const validators = Math.max(net.relay.validators, totalCores); if (validators > MAX_VALIDATORS) { throw new Error( diff --git a/packages/network-config/src/bundle.ts b/packages/network-config/src/bundle.ts index f5a918d..c52b34a 100644 --- a/packages/network-config/src/bundle.ts +++ b/packages/network-config/src/bundle.ts @@ -18,10 +18,9 @@ export interface ForkManifestChain { /** * How many nodes and cores a bite laid the network out with, when `ppn bite --cores/--collators` - * asked for something other than the default (one collator per parachain, three cores for Asset - * Hub and one for everything else, the descriptor's validators). Fixed at bite time: the - * authority sets and the core layout are state inside the snapshots, so a spawn can only follow - * what the bundle says. + * asked for something other than the default (one collator per parachain, the descriptor's cores + * and validators). Fixed at bite time: the authority sets and the core layout are state inside + * the snapshots, so a spawn can only follow what the bundle says. */ export interface ForkTopology { /** Relay validators — at least one per core, so this grows with `cores`. */ diff --git a/packages/network-config/src/dashboard-model.ts b/packages/network-config/src/dashboard-model.ts index a38db0d..2eb0ec1 100644 --- a/packages/network-config/src/dashboard-model.ts +++ b/packages/network-config/src/dashboard-model.ts @@ -105,9 +105,8 @@ export function dashboardModel(net: NetworkDef, baseUrl: string): DashboardModel const base = baseUrl.replace(/\/$/, ''); const chains: DashboardChain[] = []; - // Relay validators this network runs, up to the six well-known ones: those past them get no - // public path. - for (let i = 0; i < Math.min(net.relay.validators, VALIDATORS.length); i++) { + // Relay validators. Only the ones this network runs (a fork may run fewer than six). + for (let i = 0; i < net.relay.validators; i++) { const name = VALIDATORS[i]; const path = `/relay/${name}`; const port = RELAY_BASE_PORT + i; diff --git a/packages/network-config/src/networks.ts b/packages/network-config/src/networks.ts index 6ef3fdb..ca74a89 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -147,8 +147,9 @@ export interface NetworkRelay extends ChainFields { /** Built-in chain name doppelganger runs with (ZOMBIE_CHAIN), e.g. 'paseo'. */ chain: string; /** - * Relay validators: alice…ferdie, then Validator-7… up to MAX_VALIDATORS. At least one per - * parachain core, since a core without a validator group backs nothing. + * Dev-key validators the fork runs with, max 6 (alice…ferdie). A genesis spawn runs one per + * parachain core where that is more, named Validator-7… past the six: a core without a + * validator group backs nothing. */ validators: number; /** Same as `runtime`, but used when `PPN_PROFILE` is `local`. Needs a different `file`. */ @@ -444,12 +445,12 @@ export function loadDescriptor(name: string): NetworkDef { }) ); const totalCores = Object.values(cores).reduce((sum, count) => sum + count, 0); - const validators = raw.relay.validators ?? 6; - if (!Number.isInteger(validators) || validators < 1 || validators > MAX_VALIDATORS) { - bad(`relay.validators must be 1..${MAX_VALIDATORS}`); + if (totalCores > MAX_VALIDATORS) { + bad(`the parachains run on ${totalCores} cores, each needing a validator, and a relay runs at most ${MAX_VALIDATORS}`); } - if (validators < totalCores) { - bad(`relay.validators is ${validators}, fewer than the ${totalCores} cores of the parachains: a core without a validator backs nothing`); + const validators = raw.relay.validators ?? 6; + if (!Number.isInteger(validators) || validators < 1 || validators > 6) { + bad('relay.validators must be 1..6 (alice…ferdie)'); } const services: Record = raw.services ?? {}; diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index 3c5d14b..9d54ebb 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -410,9 +410,9 @@ function calcValidatorCount(parachains: Parachain[] | null): number { (parachains || []).filter((p) => VALID_PARACHAINS.includes(p)) ); const cores = genesisNet().parachains.filter((p) => selected.has(p.key)).reduce((sum, p) => sum + p.cores, 0); - // Every core needs a validator group of its own. The ceiling is what the descriptor says this - // network runs with, and the descriptor rejects a count below its cores. - return Math.max(4, Math.min(genesisNet().relay.validators, cores + 1)); + // One more validator than cores, up to the descriptor's count, and never fewer than the cores: + // a core without a validator group of its own backs nothing. + return Math.max(4, cores, Math.min(genesisNet().relay.validators, cores + 1)); } /** The section title, with the core count of a chain that runs on more than one. */ diff --git a/packages/network-config/tests/fork-toml.test.ts b/packages/network-config/tests/fork-toml.test.ts index bb498c5..6a90a5c 100644 --- a/packages/network-config/tests/fork-toml.test.ts +++ b/packages/network-config/tests/fork-toml.test.ts @@ -162,8 +162,8 @@ describe('generateForkToml — relay chain', () => { it('sets the dispute lifetime env var on every relay node', () => { const nodes = toml.split('[[relaychain.nodes]]').length - 1; const envs = toml.split('ZOMBIE_DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION').length - 1; - assert.equal(nodes, 8); - assert.equal(envs, 8); + assert.equal(nodes, 6); + assert.equal(envs, 6); }); it('only gives a p2p port to the first node', () => { diff --git a/packages/network-config/tests/networks.test.ts b/packages/network-config/tests/networks.test.ts index 0280278..7b5ddaf 100644 --- a/packages/network-config/tests/networks.test.ts +++ b/packages/network-config/tests/networks.test.ts @@ -56,7 +56,7 @@ describe('network descriptors', () => { // The one place bundle spec name and chain key differ. assert.equal(net.parachains.find((p) => p.key === 'people')!.spec, 'individuality'); assert.equal(net.relay.chain, 'paseo'); - assert.equal(net.relay.validators, 8); + assert.equal(net.relay.validators, 6); assert.deepEqual( Object.fromEntries(net.parachains.map((p) => [p.key, p.cores])), { 'asset-hub': 3, people: 3, bulletin: 1, 'web3-storage': 1 } @@ -335,10 +335,10 @@ describe('cores', () => { assert.deepEqual(net.parachains.map((p) => p.cores), [1, 1, 1, 1]); }); - it('rejects fewer relay validators than cores', () => { + it('rejects more cores than a relay can have validators for', () => { assert.throws( - loadEdited((raw) => ({ ...raw, relay: { ...raw.relay, validators: 7 } })), - /relay\.validators is 7, fewer than the 8 cores/ + loadEdited((raw) => ({ ...raw, parachains: raw.parachains.map((p) => (p.key === 'people' ? { ...p, cores: 6 } : p)) })), + /run on 11 cores, each needing a validator, and a relay runs at most 10/ ); }); diff --git a/packages/network-config/tests/toml-generator.test.ts b/packages/network-config/tests/toml-generator.test.ts index c57688a..9beea85 100644 --- a/packages/network-config/tests/toml-generator.test.ts +++ b/packages/network-config/tests/toml-generator.test.ts @@ -85,11 +85,11 @@ describe('generateToml', () => { assert.ok(toml.includes('chain = "paseo-local"')); assert.ok(toml.includes('chain_spec_path = "{{BIN}}/relay_paseo.json"')); - // 8 validators: one per core (3 + 3 + 1), plus one, capped at the descriptor's 8 - for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'Validator-7', 'Validator-8']) { + // 7 validators: one per core (3 + 3 + 1), past the descriptor's 6 + for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'Validator-7']) { assert.ok(toml.includes(`name = "${name}-paseo-validator"`), name); } - assert.ok(!toml.includes('Validator-9')); + assert.ok(!toml.includes('Validator-8')); // All parachains assert.ok(toml.includes('id = 1500')); @@ -440,14 +440,14 @@ describe('calcValidatorCount', () => { assert.equal(calcValidatorCount(['people']), 4); }); - it('gives every core of the selection a validator, plus one', () => { - assert.equal(calcValidatorCount(['asset-hub', 'people']), 7); + it('gives every core of the selection a validator, plus one up to the descriptor count', () => { assert.equal(calcValidatorCount(['asset-hub', 'bulletin']), 5); assert.equal(calcValidatorCount(['people', 'bulletin']), 5); + assert.equal(calcValidatorCount(['asset-hub', 'people']), 6); }); - it('caps at the descriptor count, which covers every core', () => { - assert.equal(calcValidatorCount(['asset-hub', 'people', 'bulletin']), 8); + it('runs one validator per core past the descriptor count', () => { + assert.equal(calcValidatorCount(['asset-hub', 'people', 'bulletin']), 7); assert.equal(calcValidatorCount([...VALID_PARACHAINS]), 8); }); From 7c16b3ad82aaa2db32e354b411f7f98ca0fafff3 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:21:49 +0000 Subject: [PATCH 05/14] Count a genesis relay's configured cores, which it has before any validator group --- packages/cli/src/commands/service.ts | 30 ++++++++++++++----------- packages/cli/tests/assign-cores.test.ts | 8 +++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/commands/service.ts b/packages/cli/src/commands/service.ts index d60f4e5..b192e90 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -20,7 +20,7 @@ import { loadCurrentNetwork, readEnvFile, hrmpChannels, type NetworkDef, repoRoo } from '@parity/ppn-network-config'; import { forkBundleName } from '../lib/fork-bundle-name.js'; import { loadSecrets } from '../lib/secrets.js'; -import type { CoreAssignment, PlannedPara } from '../fork/shared-relay.js'; +import { FULL_CORE, type CoreAssignment, type PlannedPara } from '../fork/shared-relay.js'; const REPO = repoRoot(); /** Mutable state — binaries, chain data, bundles — lives in the workspace, not the package. */ @@ -120,9 +120,9 @@ export async function run(args: string[], deps: ServiceDeps = {}): Promise /** * The assignments that bring each parachain the relay runs up to its descriptor core count, and * what still lacks a core afterwards. A parachain on no core is not running there (a spawn of a - * subset of chains) and gets none. Uses only cores below `coreCount` (one per validator group, - * since a core without a group backs nothing) that nothing is assigned to, lowest first, and - * never moves an assigned core, so running it again on a kept chain changes nothing. + * subset of chains) and gets none. Uses only cores below `coreCount`, the cores the relay + * schedules, that nothing is assigned to, lowest first, and never moves an assigned core, so + * running it again on a kept chain changes nothing. */ export function planExtraCores( paras: PlannedPara[], @@ -177,10 +177,10 @@ async function assignedCores(api: ApiPromise): Promise> { } /** - * Put every parachain on as many cores as the descriptor states, from the cores the relay has - * validator groups for and nothing assigned to. At genesis those are the extra cores the genesis - * TOML adds; on a kept chain that has already been laid out there is nothing to do, and one - * whose relay lacks validators for the cores is reported rather than half laid out. + * Put every parachain on as many cores as the descriptor states, from the cores the relay + * schedules and nothing is assigned to. At genesis those are the extra cores the genesis TOML + * adds; on a kept chain that has already been laid out there is nothing to do. A relay with too + * few validators gets the free cores there are, and the log says which chain still lacks how many. */ async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promise { await waitSeconds('the relay chain', 30); @@ -188,12 +188,16 @@ async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promis console.log(`assign-cores: relay ${ctx.relayWs}`); const api = await ApiPromise.create({ provider: new WsProvider(ctx.relayWs) }); try { - const coreCount = ((await api.query.paraScheduler.validatorGroups()).toJSON() as unknown[]).length; + // One core per validator group, and at least `num_cores`: the genesis session has no groups, + // so until the first session change only the configuration says how many cores there are. + const groups = (await api.query.paraScheduler.validatorGroups()).toJSON() as unknown[]; + const config = (await api.query.configuration.activeConfig()).toJSON() as { schedulerParams: { numCores: number } }; + const coreCount = Math.max(groups.length, config.schedulerParams.numCores); const { assignments, missing } = planExtraCores(ctx.net.parachains, await assignedCores(api), coreCount); for (const { key, cores } of missing) { console.log( - `assign-cores: ${key} lacks ${cores} core(s), and none of the relay's ${coreCount} validator groups ` + - 'has a free core: the relay needs one validator per core' + `assign-cores: ${key} lacks ${cores} core(s), and the relay has no free one among its ${coreCount}: ` + + 'it needs one validator per core' ); } if (assignments.length === 0) { @@ -202,9 +206,9 @@ async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promis } const signer = new Keyring({ type: 'sr25519' }).addFromUri(ctx.sudoUri); - // begin 0: from the next block; 57600 parts: the whole core. + // begin 0: from the next block. const calls = assignments.map(({ core, paraId }) => - api.tx.coretime.assignCore(core, 0, [[{ Task: paraId }, 57600]], null) + api.tx.coretime.assignCore(core, 0, [[{ Task: paraId }, FULL_CORE]], null) ); await submitSudo(api, signer, api.tx.sudo.sudo(api.tx.utility.batch(calls))); for (const { core, paraId } of assignments) console.log(`assign-cores: core ${core} -> para ${paraId}`); diff --git a/packages/cli/tests/assign-cores.test.ts b/packages/cli/tests/assign-cores.test.ts index 3a6ec6b..6b5c4f2 100644 --- a/packages/cli/tests/assign-cores.test.ts +++ b/packages/cli/tests/assign-cores.test.ts @@ -52,6 +52,14 @@ describe('planExtraCores', () => { }); }); + it('gives a relay one validator short the free core there is, and reports the other', () => { + const oneShort = cores({ 0: 1500, 1: 1500, 2: 1500, 3: 1502, 4: 1501, 5: 1600 }); + assert.deepEqual(planExtraCores(PARACHAINS, oneShort, 7), { + assignments: [{ core: 6, paraId: 1502 }], + missing: [{ key: 'people', cores: 1 }], + }); + }); + // `PPN_PARACHAINS=people,bulletin`: Asset Hub comes first in the descriptor but is not registered. it('gives no core to a parachain the relay does not run', () => { const subset = cores({ 2: 1502, 3: 1501 }); From b2910e75471c272dce9009dd2b5f9e2cf75f7c5f Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:21:50 +0000 Subject: [PATCH 06/14] List the RPC ports of genesis validators 7 and 8 in ports.env --- config/ports.env | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/ports.env b/config/ports.env index 4fe18df..53902d8 100644 --- a/config/ports.env +++ b/config/ports.env @@ -9,6 +9,9 @@ RELAY_CHARLIE_PORT=10002 RELAY_DAVE_PORT=10003 RELAY_EVE_PORT=10004 RELAY_FERDIE_PORT=10005 +# The validators a genesis spawn runs past the six, one per parachain core: alice's port + i. +RELAY_VALIDATOR_7_PORT=10006 +RELAY_VALIDATOR_8_PORT=10007 # Parachain collator RPC ports. A chain's RPC nodes (rpcNodes in the descriptor or the # network overlay) take the next ports up: 10011, 10012, ... for People. @@ -172,6 +175,6 @@ DUB_POSTGRES_DATA_DIR= # Aggregate lists -RELAY_PORTS="$RELAY_ALICE_PORT $RELAY_BOB_PORT $RELAY_CHARLIE_PORT $RELAY_DAVE_PORT $RELAY_EVE_PORT $RELAY_FERDIE_PORT" +RELAY_PORTS="$RELAY_ALICE_PORT $RELAY_BOB_PORT $RELAY_CHARLIE_PORT $RELAY_DAVE_PORT $RELAY_EVE_PORT $RELAY_FERDIE_PORT $RELAY_VALIDATOR_7_PORT $RELAY_VALIDATOR_8_PORT" PARACHAIN_PORTS="$PEOPLE_PORT $ASSET_HUB_PORT $BULLETIN_PORT $WEB3_STORAGE_PORT" ALL_PORTS="$RELAY_PORTS $PARACHAIN_PORTS" From f62ff1ff70f641b54f86b1b2eef931c180f53445 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:21:50 +0000 Subject: [PATCH 07/14] Check Asset Hub's block time with the same script as People's --- tests/01-asset-hub-revive.zndsl | 3 +++ tests/03-people-chain.zndsl | 2 +- ...-people-block-time.ts => test-block-time.ts} | 17 +++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) rename tests/scripts/{test-people-block-time.ts => test-block-time.ts} (54%) diff --git a/tests/01-asset-hub-revive.zndsl b/tests/01-asset-hub-revive.zndsl index ea5beb0..6b2deff 100644 --- a/tests/01-asset-hub-revive.zndsl +++ b/tests/01-asset-hub-revive.zndsl @@ -13,6 +13,9 @@ asset-hub-collator1: is up alice-paseo-validator: parachain 1500 is registered within 400 seconds alice-paseo-validator: parachain 1500 block height is at least 5 within 500 seconds +# Three cores give a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner +asset-hub-collator1: js-script ./scripts/dist/test-block-time.js with "assetHub,3" return is equal to 1 within 300 seconds + # ============================================ # pallet-revive Tests # ============================================ diff --git a/tests/03-people-chain.zndsl b/tests/03-people-chain.zndsl index 6443a63..71ba384 100644 --- a/tests/03-people-chain.zndsl +++ b/tests/03-people-chain.zndsl @@ -14,7 +14,7 @@ alice-paseo-validator: parachain 1502 is registered within 400 seconds alice-paseo-validator: parachain 1502 block height is at least 5 within 500 seconds # Three cores give a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner -people-collator1: js-script ./scripts/dist/test-people-block-time.js with "3" return is equal to 1 within 300 seconds +people-collator1: js-script ./scripts/dist/test-block-time.js with "people,3" return is equal to 1 within 300 seconds # ============================================ # Individuality Pallet Tests diff --git a/tests/scripts/test-people-block-time.ts b/tests/scripts/test-block-time.ts similarity index 54% rename from tests/scripts/test-people-block-time.ts rename to tests/scripts/test-block-time.ts index c52e0d5..494b40d 100644 --- a/tests/scripts/test-people-block-time.ts +++ b/tests/scripts/test-block-time.ts @@ -1,23 +1,24 @@ import type { PolkadotClient } from "polkadot-api"; import type { NetworkInfo } from "./types/zombienet"; -import { SUCCESS, FAILURE, connectWithRetry, safeDisconnect, sleep, waitForChainReady } from "./utils"; +import { SUCCESS, FAILURE, CHAINS, connectWithRetry, safeDisconnect, sleep, waitForChainReady, type ChainName } from "./utils"; const WINDOW_SECONDS = 60; /** - * Passes when People averages at most `args[0]` seconds per block over a minute. On one core it - * makes a block every 6 s; on the three cores the descriptor gives it, every 2 s. + * Passes when chain `args[0]` (a CHAINS key) averages at most `args[1]` seconds per block over a + * minute. On one core a parachain makes a block every 6 s; on three cores, every 2 s. */ export async function run(nodeName: string, networkInfo: NetworkInfo, args: string[]): Promise { let client: PolkadotClient | null = null; try { - const maxSeconds = Number(args[0]); + const [chain, max] = args; + const maxSeconds = Number(max); const node = networkInfo.nodesByName[nodeName]; - if (!node || !(maxSeconds > 0)) { - console.error(`[TEST] needs a known node and a block time in seconds, got ${nodeName} and ${args[0]}`); + if (!node || !(chain in CHAINS) || !(maxSeconds > 0)) { + console.error(`[TEST] needs a known node, chain and block time in seconds, got ${nodeName}, ${chain}, ${max}`); return FAILURE; } - const connection = await connectWithRetry(node.wsUri, "people"); + const connection = await connectWithRetry(node.wsUri, chain as ChainName); client = connection.client; const api = connection.api; await waitForChainReady(api); @@ -26,7 +27,7 @@ export async function run(nodeName: string, networkInfo: NetworkInfo, args: stri await sleep(WINDOW_SECONDS * 1000); const blocks = (await api.query.System.Number.getValue({ at: "best" })) - start; const average = WINDOW_SECONDS / blocks; - console.log(`[TEST] ${blocks} People blocks in ${WINDOW_SECONDS}s: ${average.toFixed(2)}s per block, at most ${maxSeconds}s`); + console.log(`[TEST] ${blocks} ${chain} blocks in ${WINDOW_SECONDS}s: ${average.toFixed(2)}s per block, at most ${maxSeconds}s`); return average <= maxSeconds ? SUCCESS : FAILURE; } catch (error) { console.error(`[TEST] ${(error as Error).message}`); From 3e08e22d0daa8be2fc38999912e89f03ec1014c1 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:21:52 +0000 Subject: [PATCH 08/14] Rename relaysCores to replacesCoreLayout and fix the comments the change outdated --- packages/cli/src/fork/overrides.ts | 4 ++-- packages/cli/src/fork/shared-relay.ts | 6 +++--- packages/cli/src/fork/topology.ts | 4 ++-- packages/network-config/src/toml-generator.ts | 15 ++++++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/fork/overrides.ts b/packages/cli/src/fork/overrides.ts index 88bad63..1b87da3 100644 --- a/packages/cli/src/fork/overrides.ts +++ b/packages/cli/src/fork/overrides.ts @@ -20,7 +20,7 @@ import { hrmpParaKey, paraMessagingWipes, planCores, - relaysCores, + replacesCoreLayout, transactionStorageWipes, validatorGroups, type PlannedPara, @@ -389,7 +389,7 @@ export async function relayOverrides( // Order matters: these values replace the ones relayCandidates() sets (ValidatorGroups above // all), so they come second. - const relaid = relaysCores(layout.sharedRelay, layout.cores); + const relaid = replacesCoreLayout(layout.sharedRelay, layout.cores); const candidates = { ...relayCandidates(validators), ...(relaid ? await coreLayoutCandidates(index, relayUrl, layout) : {}), diff --git a/packages/cli/src/fork/shared-relay.ts b/packages/cli/src/fork/shared-relay.ts index a918479..68764a4 100644 --- a/packages/cli/src/fork/shared-relay.ts +++ b/packages/cli/src/fork/shared-relay.ts @@ -62,7 +62,7 @@ export function coresFor(para: PlannedPara, cores: Record = {}): * bite asked for cores is asking for a layout production does not have; otherwise production's * own layout is kept, with the validators it already staffs. */ -export function relaysCores(sharedRelay: boolean, cores: Record = {}): boolean { +export function replacesCoreLayout(sharedRelay: boolean, cores: Record = {}): boolean { return sharedRelay || Object.keys(cores).length > 0; } @@ -236,8 +236,8 @@ export function transactionStorageWipes(): Record { * map, where the one bug this file's verification already caught in a sibling value was a * missing compact length. The registry knows the shape; we should not restate it. * - * `ratio`/`step` of 57600 is a whole core (the parts-per-core unit the relay uses), matching - * what `ppn service assign-cores` submits for Asset Hub's extra cores on a genesis network. + * `ratio`/`step` of 57600 is a whole core (the parts-per-core unit the relay uses), which is also + * what `ppn service assign-cores` gives each extra core on a genesis network. */ export const FULL_CORE = 57600; diff --git a/packages/cli/src/fork/topology.ts b/packages/cli/src/fork/topology.ts index ca0582e..47acdce 100644 --- a/packages/cli/src/fork/topology.ts +++ b/packages/cli/src/fork/topology.ts @@ -6,7 +6,7 @@ // can only follow what the bundle says. A bundle bitten with the defaults carries no topology. import { MAX_VALIDATORS, type ForkTopology, type NetworkDef } from '@parity/ppn-network-config'; -import { planCores, relaysCores } from './shared-relay.js'; +import { planCores, replacesCoreLayout } from './shared-relay.js'; function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef): Record { const counts: Record = {}; @@ -42,7 +42,7 @@ export function resolveTopology( const collators = parseCounts('--collators', opts.collators, net); if (!Object.keys(cores).length && !Object.keys(collators).length) return undefined; - const totalCores = relaysCores(net.bite.sharedRelay === true, cores) ? planCores(net.parachains, cores).length : 0; + const totalCores = replacesCoreLayout(net.bite.sharedRelay === true, cores) ? planCores(net.parachains, cores).length : 0; const validators = Math.max(net.relay.validators, totalCores); if (validators > MAX_VALIDATORS) { throw new Error( diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index 9d54ebb..cdfd3f2 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -22,10 +22,11 @@ import { addMissing, flagOf, overrideArgs } from './args.js'; const VALIDATORS = ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie'] as const; /** - * The name of the i-th relay node in fork mode. The first six are the well-known names, which - * zombienet maps to the well-known dev keys; past them zombienet derives a node's keys from - * `//` — the same rule that makes `Collator-` work — so any name serves, as long - * as the bite installs the keys derived from it (cli fork/validators.ts). + * The name of the i-th relay node: the well-known names, then `Validator-`. A fork uses them + * as they are, which zombienet maps to the well-known dev keys for the first six; past them, and + * for genesis names with the network's suffix, zombienet derives a node's keys from `//` — + * the same rule that makes `Collator-` work — so any name serves, as long as a bite + * installs the keys derived from it (cli fork/validators.ts). */ function relayNodeName(i: number): string { return VALIDATORS[i] ?? `Validator-${i + 1}`; @@ -43,9 +44,9 @@ const VALID_PARACHAINS: Parachain[] = PARACHAIN_KEYS; // Genesis is previewnet-only by design (see networks/README.md), but everything about // previewnet that the descriptor states — para ids, chain ids, spec files, binaries, -// per-chain flags, core counts, validator count and naming, which services run — is read -// from it here rather than restated, so this generator and fork mode cannot disagree, and -// editing the descriptor changes both. +// per-chain flags, core counts, validator naming, which services run — is read from it here +// rather than restated, so this generator and fork mode cannot disagree, and editing the +// descriptor changes both. // // What stays in code is what the descriptor does not describe: the HRMP topology and the // bootstrap processes' own arguments. From e6459b540aceace9890fc9972597b2d438ec9d39 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:27:30 +0000 Subject: [PATCH 09/14] Title a genesis parachain section inside it, and toggle set-dispatcher-address on its own --- packages/network-config/src/toml-generator.ts | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index cdfd3f2..935e2c5 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -327,12 +327,14 @@ function tomlArgs(args: string[]): string { return '[' + args.map((a) => `"${a}"`).join(', ') + ']'; } -function genesisParachainSection(key: Parachain, title: string, args: string[]): string { +/** A parachain's genesis section, titled `name`, with its core count when it runs on more than one. */ +function genesisParachainSection(key: Parachain, name: string, args: string[]): string { + const chain = genesisChainOf(key) as NetworkParachain; const launch = `command = "{{SCRIPTS}}/omni-node.sh"${genesisCollatorEnv(key)}`; return ` -## ${title} +## ${name} (Parachain ${chain.paraId})${chain.cores > 1 ? ` - Elastic Scaling on ${chain.cores} cores` : ''} [[parachains]] -id = ${paraIds()[key]} +id = ${chain.paraId} cumulus_based = true chain = "${genesisSpecOf(key).chainId}" chain_spec_path = "{{BIN}}/${genesisSpecOf(key).file}" @@ -344,21 +346,20 @@ p2p_port = ${P2P_PORTS[key]} prometheus_port = ${prometheusPort(PORTS[key])} ${launch} args = ${tomlArgs(args)} -${rpcNodeBlocks(genesisChainOf(key) as NetworkParachain, args, launch)}`; +${rpcNodeBlocks(chain, args, launch)}`; } function validatorNodes(count: number): string { - return Array.from({ length: count }, (_, i) => relayNodeName(i)) - .map( - (v, i) => ` + return Array.from( + { length: count }, + (_, i) => ` [[relaychain.nodes]] -name = "${v}-${genesisConfig().validatorNameSuffix}" +name = "${relayNodeName(i)}-${genesisConfig().validatorNameSuffix}" validator = true rpc_port = ${RELAY_BASE_PORT + i}${i === 0 ? `\np2p_port = ${P2P_PORTS.relay}` : ''} prometheus_port = ${prometheusPort(RELAY_BASE_PORT + i)} balance = 1000000000000000` - ) - .join('\n'); + ).join('\n'); } /** Which parachains talk to each other. Both directions are opened for each pair. */ @@ -416,12 +417,6 @@ function calcValidatorCount(parachains: Parachain[] | null): number { return Math.max(4, cores, Math.min(genesisNet().relay.validators, cores + 1)); } -/** The section title, with the core count of a chain that runs on more than one. */ -function parachainTitle(key: Parachain, name: string): string { - const cores = (genesisChainOf(key) as NetworkParachain).cores; - return `${name} (Parachain ${paraIds()[key]})${cores > 1 ? ` - Elastic Scaling on ${cores} cores` : ''}`; -} - // --------------------------------------------------------------------------- // Validation // --------------------------------------------------------------------------- @@ -503,28 +498,16 @@ default_args = ${relayArgs} ${validatorNodes(validatorCount)} ${section( has('asset-hub'), - genesisParachainSection( - 'asset-hub', - parachainTitle('asset-hub', 'Asset Hub Paseo Next'), - genesisChainArgs('asset-hub', lt['asset-hub']) - ) + genesisParachainSection('asset-hub', 'Asset Hub Paseo Next', genesisChainArgs('asset-hub', lt['asset-hub'])) )}${section( has('people'), - genesisParachainSection('people', parachainTitle('people', 'People Chain'), genesisChainArgs('people', lt.people)) + genesisParachainSection('people', 'People Chain', genesisChainArgs('people', lt.people)) )}${section( has('bulletin'), - genesisParachainSection( - 'bulletin', - parachainTitle('bulletin', 'Bulletin Chain'), - genesisChainArgs('bulletin', lt.bulletin, options.enableHop) - ) + genesisParachainSection('bulletin', 'Bulletin Chain', genesisChainArgs('bulletin', lt.bulletin, options.enableHop)) )}${section( has('web3-storage'), - genesisParachainSection( - 'web3-storage', - parachainTitle('web3-storage', 'Web3 Storage Chain'), - genesisChainArgs('web3-storage', lt['web3-storage']) - ) + genesisParachainSection('web3-storage', 'Web3 Storage Chain', genesisChainArgs('web3-storage', lt['web3-storage'])) )}${section(both('people', 'bulletin'), hrmpPair(paraIds().people, paraIds().bulletin))} ${section(both('people', 'asset-hub'), hrmpPair(paraIds().people, paraIds()['asset-hub']))} ${section( @@ -618,7 +601,7 @@ name = "assign-cores" command = "{{SCRIPTS}}/assign-cores.sh" ` )}${section( - has('asset-hub') && serviceEnabled('assign-cores'), + has('asset-hub') && serviceEnabled('set-dispatcher-address'), ` [[custom_processes]] name = "set-dispatcher-address" From d1e7e33bacfafd38342ef34c6d523acfca605cfd Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 21:27:30 +0000 Subject: [PATCH 10/14] Read core assignments through one JSON type, and plan fork cores from the descriptor directly --- packages/cli/src/commands/fork.ts | 2 +- packages/cli/src/commands/service.ts | 34 ++++++++++++---------------- packages/cli/src/fork/chains.ts | 2 -- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/packages/cli/src/commands/fork.ts b/packages/cli/src/commands/fork.ts index e31e32e..44d0a83 100644 --- a/packages/cli/src/commands/fork.ts +++ b/packages/cli/src/commands/fork.ts @@ -84,7 +84,7 @@ export async function run(args: string[]): Promise { endpointOf(relay, NETWORK, baseUrl), `${outDir}/rc_overrides.json`, { - paras: PARACHAINS, + paras: NETWORK.parachains, validators: topology?.validators ?? NETWORK.relay.validators, cores: topology?.cores, sharedRelay: NETWORK.bite.sharedRelay === true, diff --git a/packages/cli/src/commands/service.ts b/packages/cli/src/commands/service.ts index b192e90..98dc511 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -143,34 +143,28 @@ export function planExtraCores( return { assignments, missing }; } -/** `ParaScheduler::CoreDescriptors` as polkadot.js decodes it to JSON. */ -type CoreDescriptorsJson = Record< - string, - { queue: { last: number } | null; currentWork: { assignments: [unknown, unknown][] } | null } ->; +/** A core's work (current or scheduled) as polkadot.js decodes it to JSON; a `Task` assignment is `{ task }`. */ +type CoreWorkJson = { assignments: [{ task?: number }, unknown][] }; /** * The para ids on each core with an assignment, as the relay will run them: a queued schedule * replaces the current work once its block is reached, so the latest one wins. */ async function assignedCores(api: ApiPromise): Promise> { - const paraIdsOf = (assignments: [unknown, unknown][] = []) => - assignments.flatMap(([assignment]) => - typeof assignment === 'object' && assignment !== null && 'task' in assignment && typeof assignment.task === 'number' - ? [assignment.task] - : [] - ); + const paraIdsOf = (work: CoreWorkJson | null) => + (work?.assignments ?? []).flatMap(([{ task }]) => (task === undefined ? [] : [task])); // Decoded against the relay's own metadata, so the shape is the runtime's. - const descriptors = (await api.query.paraScheduler.coreDescriptors()).toJSON() as unknown as CoreDescriptorsJson; + const descriptors = (await api.query.paraScheduler.coreDescriptors()).toJSON() as unknown as Record< + string, + { queue: { last: number } | null; currentWork: CoreWorkJson | null } + >; const assigned = new Map(); - for (const [core, descriptor] of Object.entries(descriptors)) { - if (descriptor.queue) { - const schedule = (await api.query.paraScheduler.coreSchedules([descriptor.queue.last, Number(core)])).toJSON() as { - assignments: [unknown, unknown][]; - } | null; - assigned.set(Number(core), paraIdsOf(schedule?.assignments)); - } else if (descriptor.currentWork) { - assigned.set(Number(core), paraIdsOf(descriptor.currentWork.assignments)); + for (const [core, { queue, currentWork }] of Object.entries(descriptors)) { + if (queue) { + const schedule = (await api.query.paraScheduler.coreSchedules([queue.last, Number(core)])).toJSON(); + assigned.set(Number(core), paraIdsOf(schedule as unknown as CoreWorkJson | null)); + } else if (currentWork) { + assigned.set(Number(core), paraIdsOf(currentWork)); } } return assigned; diff --git a/packages/cli/src/fork/chains.ts b/packages/cli/src/fork/chains.ts index 3ca5096..5b1a7dc 100644 --- a/packages/cli/src/fork/chains.ts +++ b/packages/cli/src/fork/chains.ts @@ -24,7 +24,6 @@ export interface ForkParachain extends ForkChain { paraId: number; /** Curve this chain's Aura keys are on, as the descriptor declares it. */ aura?: AuraScheme; - cores: number; } export function parachainsOf(net: NetworkDef): ForkParachain[] { @@ -34,7 +33,6 @@ export function parachainsOf(net: NetworkDef): ForkParachain[] { endpoint: p.rpc, paraId: p.paraId, aura: p.aura, - cores: p.cores, })); } From c81974964333ea099c8f1845ebe9dd999a5e7981 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 22:25:42 +0000 Subject: [PATCH 11/14] Reject a shared-relay descriptor with fewer validators than cores --- packages/network-config/src/networks.ts | 8 ++++++-- packages/network-config/tests/networks.test.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/network-config/src/networks.ts b/packages/network-config/src/networks.ts index ca74a89..ab3239f 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -148,7 +148,7 @@ export interface NetworkRelay extends ChainFields { chain: string; /** * Dev-key validators the fork runs with, max 6 (alice…ferdie). A genesis spawn runs one per - * parachain core where that is more, named Validator-7… past the six: a core without a + * parachain core where that is more, called Validator-7… past the six: a core without a * validator group backs nothing. */ validators: number; @@ -446,12 +446,16 @@ export function loadDescriptor(name: string): NetworkDef { ); const totalCores = Object.values(cores).reduce((sum, count) => sum + count, 0); if (totalCores > MAX_VALIDATORS) { - bad(`the parachains run on ${totalCores} cores, each needing a validator, and a relay runs at most ${MAX_VALIDATORS}`); + bad(`the parachains run on ${totalCores} cores, one validator per core, and a relay runs at most ${MAX_VALIDATORS} validators`); } const validators = raw.relay.validators ?? 6; if (!Number.isInteger(validators) || validators < 1 || validators > 6) { bad('relay.validators must be 1..6 (alice…ferdie)'); } + // A shared relay's fork lays the parachains out on their declared cores with these validators. + if (raw.bite?.sharedRelay === true && validators < totalCores) { + bad(`relay.validators is ${validators}, fewer than the parachains' ${totalCores} cores, which a fork of a shared relay lays out`); + } const services: Record = raw.services ?? {}; for (const [svc, cfg] of Object.entries(services)) { diff --git a/packages/network-config/tests/networks.test.ts b/packages/network-config/tests/networks.test.ts index 7b5ddaf..361f825 100644 --- a/packages/network-config/tests/networks.test.ts +++ b/packages/network-config/tests/networks.test.ts @@ -338,7 +338,15 @@ describe('cores', () => { it('rejects more cores than a relay can have validators for', () => { assert.throws( loadEdited((raw) => ({ ...raw, parachains: raw.parachains.map((p) => (p.key === 'people' ? { ...p, cores: 6 } : p)) })), - /run on 11 cores, each needing a validator, and a relay runs at most 10/ + /run on 11 cores, one validator per core, and a relay runs at most 10 validators/ + ); + }); + + // previewnet's own relay keeps production's layout on a fork; a shared relay's is laid out anew. + it('rejects a shared relay with fewer validators than cores', () => { + assert.throws( + loadEdited((raw) => ({ ...raw, bite: { ...(raw.bite as object), sharedRelay: true } })), + /relay\.validators is 6, fewer than the parachains' 8 cores/ ); }); From 7b4f67c25f7bea4467cf9c9e497673a4c0bfe3b5 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 22:25:42 +0000 Subject: [PATCH 12/14] Rename assign-cores' locals and fix comments against the naming rules --- packages/cli/src/commands/service.ts | 42 +++++++++---------- packages/cli/src/fork/shared-relay.ts | 7 ++-- packages/cli/tests/assign-cores.test.ts | 2 +- packages/network-config/src/toml-generator.ts | 1 - tests/01-asset-hub-revive.zndsl | 2 +- tests/03-people-chain.zndsl | 2 +- 6 files changed, 26 insertions(+), 30 deletions(-) diff --git a/packages/cli/src/commands/service.ts b/packages/cli/src/commands/service.ts index 98dc511..b61df8e 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -118,27 +118,25 @@ export async function run(args: string[], deps: ServiceDeps = {}): Promise // --------------------------------------------------------------------------- /** - * The assignments that bring each parachain the relay runs up to its descriptor core count, and - * what still lacks a core afterwards. A parachain on no core is not running there (a spawn of a - * subset of chains) and gets none. Uses only cores below `coreCount`, the cores the relay - * schedules, that nothing is assigned to, lowest first, and never moves an assigned core, so - * running it again on a kept chain changes nothing. + * Assignments that bring each parachain on the relay up to its descriptor core count from free + * cores below `coreCount`, without moving an assigned core, and the chains still short. A + * parachain on no core isn't running on this relay (a spawn of some chains only) and gets none. */ export function planExtraCores( paras: PlannedPara[], - assigned: Map, + coreParaIds: Map, coreCount: number ): { assignments: CoreAssignment[]; missing: { key: string; cores: number }[] } { - const free = Array.from({ length: coreCount }, (_, core) => core).filter((core) => !assigned.has(core)); + const free = Array.from({ length: coreCount }, (_, core) => core).filter((core) => !coreParaIds.has(core)); const assignments: CoreAssignment[] = []; const missing: { key: string; cores: number }[] = []; for (const para of paras) { - const held = [...assigned.values()].filter((paraIds) => paraIds.includes(para.paraId)).length; - if (held === 0) continue; - const lacking = Math.max(0, para.cores - held); - const granted = free.splice(0, lacking); - assignments.push(...granted.map((core) => ({ core, paraId: para.paraId }))); - if (granted.length < lacking) missing.push({ key: para.key, cores: lacking - granted.length }); + const currentCores = [...coreParaIds.values()].filter((paraIds) => paraIds.includes(para.paraId)).length; + if (currentCores === 0) continue; + const lacking = Math.max(0, para.cores - currentCores); + const newCores = free.splice(0, lacking); + assignments.push(...newCores.map((core) => ({ core, paraId: para.paraId }))); + if (newCores.length < lacking) missing.push({ key: para.key, cores: lacking - newCores.length }); } return { assignments, missing }; } @@ -150,7 +148,7 @@ type CoreWorkJson = { assignments: [{ task?: number }, unknown][] }; * The para ids on each core with an assignment, as the relay will run them: a queued schedule * replaces the current work once its block is reached, so the latest one wins. */ -async function assignedCores(api: ApiPromise): Promise> { +async function readCoreAssignments(api: ApiPromise): Promise> { const paraIdsOf = (work: CoreWorkJson | null) => (work?.assignments ?? []).flatMap(([{ task }]) => (task === undefined ? [] : [task])); // Decoded against the relay's own metadata, so the shape is the runtime's. @@ -158,23 +156,23 @@ async function assignedCores(api: ApiPromise): Promise> { string, { queue: { last: number } | null; currentWork: CoreWorkJson | null } >; - const assigned = new Map(); + const coreParaIds = new Map(); for (const [core, { queue, currentWork }] of Object.entries(descriptors)) { if (queue) { const schedule = (await api.query.paraScheduler.coreSchedules([queue.last, Number(core)])).toJSON(); - assigned.set(Number(core), paraIdsOf(schedule as unknown as CoreWorkJson | null)); + coreParaIds.set(Number(core), paraIdsOf(schedule as unknown as CoreWorkJson | null)); } else if (currentWork) { - assigned.set(Number(core), paraIdsOf(currentWork)); + coreParaIds.set(Number(core), paraIdsOf(currentWork)); } } - return assigned; + return coreParaIds; } /** * Put every parachain on as many cores as the descriptor states, from the cores the relay * schedules and nothing is assigned to. At genesis those are the extra cores the genesis TOML * adds; on a kept chain that has already been laid out there is nothing to do. A relay with too - * few validators gets the free cores there are, and the log says which chain still lacks how many. + * few validators gets the free cores there are, and the log lists how many cores each chain lacks. */ async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promise { await waitSeconds('the relay chain', 30); @@ -183,15 +181,15 @@ async function assignCores(ctx: ServiceContext, _deps: ServiceDeps = {}): Promis const api = await ApiPromise.create({ provider: new WsProvider(ctx.relayWs) }); try { // One core per validator group, and at least `num_cores`: the genesis session has no groups, - // so until the first session change only the configuration says how many cores there are. + // so until the first session change `num_cores` is the only count of cores. const groups = (await api.query.paraScheduler.validatorGroups()).toJSON() as unknown[]; const config = (await api.query.configuration.activeConfig()).toJSON() as { schedulerParams: { numCores: number } }; const coreCount = Math.max(groups.length, config.schedulerParams.numCores); - const { assignments, missing } = planExtraCores(ctx.net.parachains, await assignedCores(api), coreCount); + const { assignments, missing } = planExtraCores(ctx.net.parachains, await readCoreAssignments(api), coreCount); for (const { key, cores } of missing) { console.log( `assign-cores: ${key} lacks ${cores} core(s), and the relay has no free one among its ${coreCount}: ` + - 'it needs one validator per core' + 'the relay schedules one core per validator group' ); } if (assignments.length === 0) { diff --git a/packages/cli/src/fork/shared-relay.ts b/packages/cli/src/fork/shared-relay.ts index 68764a4..537c86c 100644 --- a/packages/cli/src/fork/shared-relay.ts +++ b/packages/cli/src/fork/shared-relay.ts @@ -48,19 +48,18 @@ export interface CoreAssignment { export interface PlannedPara { key: string; paraId: number; - /** The descriptor's core count for it. */ cores: number; } -/** How many cores a parachain gets: the descriptor's count, unless the bite was asked for another (`ppn bite --cores people=3`). */ +/** How many cores a parachain gets: the descriptor's count, unless `ppn bite --cores` sets another. */ export function coresFor(para: PlannedPara, cores: Record = {}): number { return cores[para.key] ?? para.cores; } /** * Whether a bite lays the relay's cores out anew. A shared relay's layout is wrong for us, and a - * bite asked for cores is asking for a layout production does not have; otherwise production's - * own layout is kept, with the validators it already staffs. + * bite with `--cores` lays out cores production does not have; otherwise production's own layout + * is kept, with the validators it already staffs. */ export function replacesCoreLayout(sharedRelay: boolean, cores: Record = {}): boolean { return sharedRelay || Object.keys(cores).length > 0; diff --git a/packages/cli/tests/assign-cores.test.ts b/packages/cli/tests/assign-cores.test.ts index 6b5c4f2..d9229be 100644 --- a/packages/cli/tests/assign-cores.test.ts +++ b/packages/cli/tests/assign-cores.test.ts @@ -9,7 +9,7 @@ import { planExtraCores } from '../src/commands/service.js'; const PARACHAINS = loadNetwork('previewnet').parachains; -/** Cores to para ids, as assignedCores() reads them off the relay. */ +/** Cores to para ids, as readCoreAssignments() reads them off the relay. */ const cores = (layout: Record) => new Map(Object.entries(layout).map(([core, paraId]) => [Number(core), [paraId]])); diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index 935e2c5..7bead81 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -327,7 +327,6 @@ function tomlArgs(args: string[]): string { return '[' + args.map((a) => `"${a}"`).join(', ') + ']'; } -/** A parachain's genesis section, titled `name`, with its core count when it runs on more than one. */ function genesisParachainSection(key: Parachain, name: string, args: string[]): string { const chain = genesisChainOf(key) as NetworkParachain; const launch = `command = "{{SCRIPTS}}/omni-node.sh"${genesisCollatorEnv(key)}`; diff --git a/tests/01-asset-hub-revive.zndsl b/tests/01-asset-hub-revive.zndsl index 6b2deff..86130ef 100644 --- a/tests/01-asset-hub-revive.zndsl +++ b/tests/01-asset-hub-revive.zndsl @@ -13,7 +13,7 @@ asset-hub-collator1: is up alice-paseo-validator: parachain 1500 is registered within 400 seconds alice-paseo-validator: parachain 1500 block height is at least 5 within 500 seconds -# Three cores give a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner +# Three cores make a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner asset-hub-collator1: js-script ./scripts/dist/test-block-time.js with "assetHub,3" return is equal to 1 within 300 seconds # ============================================ diff --git a/tests/03-people-chain.zndsl b/tests/03-people-chain.zndsl index 71ba384..77ffb09 100644 --- a/tests/03-people-chain.zndsl +++ b/tests/03-people-chain.zndsl @@ -13,7 +13,7 @@ people-collator1: is up alice-paseo-validator: parachain 1502 is registered within 400 seconds alice-paseo-validator: parachain 1502 block height is at least 5 within 500 seconds -# Three cores give a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner +# Three cores make a block every 2 s, one core every 6 s; 3 s leaves room for a loaded runner people-collator1: js-script ./scripts/dist/test-block-time.js with "people,3" return is equal to 1 within 300 seconds # ============================================ From 28775c20a24f917712ff09cb284b9f56bdc5db47 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 22:52:00 +0000 Subject: [PATCH 13/14] Name relay validators 7 and 8 after the keyring's One and Two --- CLAUDE.md | 2 +- README.md | 2 +- config/ports.env | 8 ++++---- packages/cli/src/fork/validators.ts | 6 +++--- packages/cli/tests/fork-validators.test.ts | 15 ++++++++------- packages/network-config/src/toml-generator.ts | 9 +++++---- packages/network-config/tests/fork-toml.test.ts | 2 +- .../network-config/tests/toml-generator.test.ts | 4 ++-- zombienet-configs/local-dev.toml | 4 ++-- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a978d40..a65ced4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,7 +10,7 @@ Do not add `Co-Authored-By: Claude` (or any other AI attribution) lines to commi Product Preview Network (PPN) is infrastructure tooling for spinning up a local Polkadot ecosystem with Zombienet. It provides pre-built binaries, WASM runtimes, and configuration for: -- **Relay Chain**: Paseo (8 validators: alice, bob, charlie, dave, eve, ferdie, Validator-7, Validator-8) +- **Relay Chain**: Paseo (8 validators: alice, bob, charlie, dave, eve, ferdie, one, two) - **Parachains**: - Asset Hub (ID 1500) - port 10020 - **2-second blocks** via elastic scaling - People/Individuality Chain (ID 1502) - port 10010 - **2-second blocks** via elastic scaling diff --git a/README.md b/README.md index 575b1d6..05cbd74 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ strips the dev keys from anything long-lived. A server's secrets file holds the | | Endpoint | | | --- | --- | --- | -| Relay (alice … ferdie) | `ws://127.0.0.1:10000` – `10005` | 8 validators; Validator-7 and -8 on `10006`, `10007` | +| Relay (alice … ferdie) | `ws://127.0.0.1:10000` – `10005` | 8 validators; `one` and `two` on `10006`, `10007` | | Asset Hub | `ws://127.0.0.1:10020` | **2-second blocks**, elastic scaling | | People | `ws://127.0.0.1:10010` | individuality, **2-second blocks**, elastic scaling | | Bulletin | `ws://127.0.0.1:10030` | transaction storage | diff --git a/config/ports.env b/config/ports.env index 53902d8..6db2bb0 100644 --- a/config/ports.env +++ b/config/ports.env @@ -9,9 +9,9 @@ RELAY_CHARLIE_PORT=10002 RELAY_DAVE_PORT=10003 RELAY_EVE_PORT=10004 RELAY_FERDIE_PORT=10005 -# The validators a genesis spawn runs past the six, one per parachain core: alice's port + i. -RELAY_VALIDATOR_7_PORT=10006 -RELAY_VALIDATOR_8_PORT=10007 +# The keyring's One and Two, which a genesis spawn runs past the six, one validator per core. +RELAY_ONE_PORT=10006 +RELAY_TWO_PORT=10007 # Parachain collator RPC ports. A chain's RPC nodes (rpcNodes in the descriptor or the # network overlay) take the next ports up: 10011, 10012, ... for People. @@ -175,6 +175,6 @@ DUB_POSTGRES_DATA_DIR= # Aggregate lists -RELAY_PORTS="$RELAY_ALICE_PORT $RELAY_BOB_PORT $RELAY_CHARLIE_PORT $RELAY_DAVE_PORT $RELAY_EVE_PORT $RELAY_FERDIE_PORT $RELAY_VALIDATOR_7_PORT $RELAY_VALIDATOR_8_PORT" +RELAY_PORTS="$RELAY_ALICE_PORT $RELAY_BOB_PORT $RELAY_CHARLIE_PORT $RELAY_DAVE_PORT $RELAY_EVE_PORT $RELAY_FERDIE_PORT $RELAY_ONE_PORT $RELAY_TWO_PORT" PARACHAIN_PORTS="$PEOPLE_PORT $ASSET_HUB_PORT $BULLETIN_PORT $WEB3_STORAGE_PORT" ALL_PORTS="$RELAY_PORTS $PARACHAIN_PORTS" diff --git a/packages/cli/src/fork/validators.ts b/packages/cli/src/fork/validators.ts index 401a2c3..7c0cbe6 100644 --- a/packages/cli/src/fork/validators.ts +++ b/packages/cli/src/fork/validators.ts @@ -31,11 +31,11 @@ export interface DevValidator { * The first six are zombie-bite's get_validator_keys() order — ALICE, BOB, CHARLIE, DAVE, * FERDIE, EVE (note FERDIE before EVE) — because ActiveValidatorIndices and ValidatorGroups * index into the list positionally, and a bundle bitten with the old hard-coded keys had that - * order. The names beyond them are whatever the fork TOML calls the extra nodes: zombienet - * derives a non-well-known node's keys from `//`, exactly as done here. + * order. Then the keyring's One and Two, and past them whatever the fork TOML calls the extra + * nodes: zombienet derives a node's keys from `//`, exactly as done here. */ function validatorNames(count: number): string[] { - const wellKnown = ['Alice', 'Bob', 'Charlie', 'Dave', 'Ferdie', 'Eve']; + const wellKnown = ['Alice', 'Bob', 'Charlie', 'Dave', 'Ferdie', 'Eve', 'One', 'Two']; return Array.from({ length: count }, (_, i) => wellKnown[i] ?? relayNodeName(i)); } diff --git a/packages/cli/tests/fork-validators.test.ts b/packages/cli/tests/fork-validators.test.ts index f66f96f..8a6693c 100644 --- a/packages/cli/tests/fork-validators.test.ts +++ b/packages/cli/tests/fork-validators.test.ts @@ -79,15 +79,16 @@ describe('the dev authority set', () => { // keystore from that name — the keys here must be the same derivation, or the node holds // keys no authority entry mentions and never authors. it('extends past the well-known six with keys derived from the node names', async () => { - const eight = await devValidators(8); - assert.deepEqual(eight.slice(0, 6), ZOMBIE_BITE_KEYS, 'the first six do not move'); + const ten = await devValidators(10); + assert.deepEqual(ten.slice(0, 6), ZOMBIE_BITE_KEYS, 'the first six do not move'); const { Keyring } = await import('@polkadot/keyring'); const hex = (k: Uint8Array) => Buffer.from(k).toString('hex'); - assert.equal(eight[6].babe, hex(new Keyring({ type: 'sr25519' }).addFromUri('//Validator-7').publicKey)); - assert.equal(eight[6].stash, hex(new Keyring({ type: 'sr25519' }).addFromUri('//Validator-7//stash').publicKey)); - assert.equal(eight[6].grandpa, hex(new Keyring({ type: 'ed25519' }).addFromUri('//Validator-7').publicKey)); - assert.equal(eight[6].beefy, hex(new Keyring({ type: 'ecdsa' }).addFromUri('//Validator-7').publicKey)); - assert.equal(eight[7].babe, hex(new Keyring({ type: 'sr25519' }).addFromUri('//Validator-8').publicKey)); + assert.equal(ten[6].babe, hex(new Keyring({ type: 'sr25519' }).addFromUri('//One').publicKey)); + assert.equal(ten[6].stash, hex(new Keyring({ type: 'sr25519' }).addFromUri('//One//stash').publicKey)); + assert.equal(ten[6].grandpa, hex(new Keyring({ type: 'ed25519' }).addFromUri('//One').publicKey)); + assert.equal(ten[6].beefy, hex(new Keyring({ type: 'ecdsa' }).addFromUri('//One').publicKey)); + assert.equal(ten[7].babe, hex(new Keyring({ type: 'sr25519' }).addFromUri('//Two').publicKey)); + assert.equal(ten[8].babe, hex(new Keyring({ type: 'sr25519' }).addFromUri('//Validator-9').publicKey)); }); it('has no duplicate keys, however many', async () => { diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index 7bead81..27f50bc 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -19,12 +19,13 @@ import { loadNetwork } from './load.js'; import { dubCustomProcesses } from './dub.js'; import { addMissing, flagOf, overrideArgs } from './args.js'; -const VALIDATORS = ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie'] as const; +/** The well-known dev accounts, as polkadot-sdk's keyring lists them. */ +const VALIDATORS = ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'one', 'two'] as const; /** - * The name of the i-th relay node: the well-known names, then `Validator-`. A fork uses them - * as they are, which zombienet maps to the well-known dev keys for the first six; past them, and - * for genesis names with the network's suffix, zombienet derives a node's keys from `//` — + * The name of the i-th relay node: the dev account names, then `Validator-`. A fork uses them + * as they are, which zombienet maps to the well-known dev keys; for genesis names with the + * network's suffix and past the dev accounts, zombienet derives a node's keys from `//` — * the same rule that makes `Collator-` work — so any name serves, as long as a bite * installs the keys derived from it (cli fork/validators.ts). */ diff --git a/packages/network-config/tests/fork-toml.test.ts b/packages/network-config/tests/fork-toml.test.ts index 6a90a5c..e08b5cf 100644 --- a/packages/network-config/tests/fork-toml.test.ts +++ b/packages/network-config/tests/fork-toml.test.ts @@ -179,7 +179,7 @@ describe('generateForkToml — topology from the bundle', () => { it('runs as many relay validators as the bite installed keys for', () => { assert.equal(toml.split('[[relaychain.nodes]]').length - 1, 8); - for (const [i, name] of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'Validator-7', 'Validator-8'].entries()) { + for (const [i, name] of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'one', 'two'].entries()) { assert.ok(toml.includes(`name = "${name}"\nvalidator = true\nrpc_port = ${RELAY_BASE_PORT + i}`), `${name} missing or on the wrong port`); } diff --git a/packages/network-config/tests/toml-generator.test.ts b/packages/network-config/tests/toml-generator.test.ts index 9beea85..38b3b28 100644 --- a/packages/network-config/tests/toml-generator.test.ts +++ b/packages/network-config/tests/toml-generator.test.ts @@ -86,10 +86,10 @@ describe('generateToml', () => { assert.ok(toml.includes('chain_spec_path = "{{BIN}}/relay_paseo.json"')); // 7 validators: one per core (3 + 3 + 1), past the descriptor's 6 - for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'Validator-7']) { + for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'one']) { assert.ok(toml.includes(`name = "${name}-paseo-validator"`), name); } - assert.ok(!toml.includes('Validator-8')); + assert.ok(!toml.includes('two-paseo-validator')); // All parachains assert.ok(toml.includes('id = 1500')); diff --git a/zombienet-configs/local-dev.toml b/zombienet-configs/local-dev.toml index 149dba9..5e0422d 100644 --- a/zombienet-configs/local-dev.toml +++ b/zombienet-configs/local-dev.toml @@ -60,14 +60,14 @@ prometheus_port = 20005 balance = 1000000000000000 [[relaychain.nodes]] -name = "Validator-7-paseo-validator" +name = "one-paseo-validator" validator = true rpc_port = 10006 prometheus_port = 20006 balance = 1000000000000000 [[relaychain.nodes]] -name = "Validator-8-paseo-validator" +name = "two-paseo-validator" validator = true rpc_port = 10007 prometheus_port = 20007 From f4e15137b4a529bc50f7e955263bf0fa2a9adec6 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 20 Nov 2026 22:52:00 +0000 Subject: [PATCH 14/14] Put People on three cores on every network, growing a fork's validators to the cores it lays out --- docs/FORK.md | 21 ++++++------ networks/README.md | 4 +-- networks/devnet.json | 1 + networks/paseo-next-v2.json | 1 + networks/polkadot.json | 1 + networks/westend.json | 1 + packages/cli/src/commands/bite.ts | 2 +- packages/cli/src/commands/start.ts | 4 +-- packages/cli/src/fork/topology.ts | 24 ++++++++------ packages/cli/tests/fork-shared-relay.test.ts | 32 +++++++------------ packages/cli/tests/fork-topology.test.ts | 11 +++++++ packages/network-config/src/networks.ts | 4 --- .../network-config/tests/networks.test.ts | 8 ----- 13 files changed, 58 insertions(+), 56 deletions(-) diff --git a/docs/FORK.md b/docs/FORK.md index 9545c58..92fd74a 100644 --- a/docs/FORK.md +++ b/docs/FORK.md @@ -90,9 +90,10 @@ instead of driving doppelganger itself ([#120](https://github.com/paritytech/zom ## What you get, and what you don't The fork resumes at the bite block and diverges from there — it is a real fork, not a mirror. It -runs the descriptor's relay validators and one collator per parachain, on PPN's normal ports. A -previewnet fork keeps the core layout it bit; a fork of a shared relay lays the parachains out on -the descriptor's `cores` — unless the bite was asked for a different layout, below. +runs one collator per parachain, on PPN's normal ports. A previewnet fork keeps the core layout it +bit, with the descriptor's six validators; a fork of a shared relay lays the parachains out on the +descriptor's `cores` (Asset Hub and People three each) — unless the bite was asked for a different +layout, below. ### Cores and collators @@ -105,13 +106,15 @@ make bite CORES="people=3 asset-hub=1" COLLATORS=people=5 `COLLATORS==` installs that many collators as its authorities. Both are **bite-time** settings: the collator authority sets and the relay's core layout are state inside the snapshots, so a published bundle — bitten with the defaults — cannot take them. `ppn start` -refuses a bundle whose recorded layout differs from what it was asked for and says how to re-bite. +refuses a bundle bitten with other `--cores`/`--collators` than it was asked for and says how to +re-bite. The bundle's `manifest.json` carries the layout under `topology`, and the fork TOML follows it. -The relay grows to one validator per core, because a core with no validator group backs nothing: -previewnet with `people=3` is 3 + 3 + 1 + 1 = 8 cores, so 8 validators. Past the well-known six -they are named `Validator-7`, `Validator-8`, … and their keys derived from those names, the same -way zombienet does it; the cap is 10, where the relay RPC ports (`10000 + i`) would run into +The relay grows to one validator per core it lays out, because a core with no validator group +backs nothing: paseo-next-v2 is 3 + 3 + 1 = 7 cores, so 7 validators, and previewnet with +`--cores people=3` is 8. Past the well-known six they are the keyring's `one` and `two`, then +`Validator-9`, `Validator-10`, with keys derived from those names the same way zombienet does it; +the cap is 10, where the relay RPC ports (`10000 + i`) would run into People's. Extra collators are `Collator--2` … and restore the same snapshot as the first; only the first holds the documented ports. @@ -218,7 +221,7 @@ against the descriptor with no mapping table in between. well-known names to the well-known dev keys, which is exactly the authority set the bite installs. PPN's genesis-mode names (`alice-paseo-validator`, …) get generated keys instead, and the network cannot author. This is why fork mode has its own config rather than overlaying `local-dev.toml`. -Any node past those (`Validator-7`, `Collator-1502-2`) gets keys zombienet derives from `//`, +Any node past those (`one`, `Collator-1502-2`) gets keys zombienet derives from `//`, and the bite derives the same — `relayNodeName()`/`collatorNodeName()` in `toml-generator.ts` are the one place both read the name from. diff --git a/networks/README.md b/networks/README.md index 6c59599..84bea22 100644 --- a/networks/README.md +++ b/networks/README.md @@ -50,10 +50,10 @@ or `PPN_NETWORK=` in the environment of the scripts. | `relay.rpc`, `parachains[].rpc` | RPC endpoint: an absolute `ws(s)://`/`http(s)://` URL, or a path resolved against `bite.source`. | | `rpcAlternates` | Informational: other public providers for the same chain, for when the primary is re-homed. Not consumed by tooling (yet). | | `relay.specSource`, `parachains[].specSource` | Explicit location of the chain spec the bite warp-syncs from (it must carry the live network's bootnodes): an absolute URL, a path resolved against `bite.source` (previewnet uses `chainspecs/-local.json`, so biting a different instance follows the base-URL override), or `"builtin"` (generated with `build-spec --chain --raw`, relay only). | -| `relay.validators` | Number of dev-key validators the fork runs with (max 6: alice…ferdie). A bite asked for `--cores` and a genesis spawn run one per core where that is more, named `Validator-7`… with keys derived from those names; the parachains' total `cores` can be at most 10. | +| `relay.validators` | Number of dev-key validators the fork runs with (max 6: alice…ferdie). A bite that lays the cores out (a shared relay, or `--cores`) and a genesis spawn run one per core where that is more: the keyring's `one` and `two`, then `Validator-9`…, with keys derived from those names. The parachains' total `cores` can be at most 10. | | `parachains[].key` | One of `asset-hub`, `people`, `bulletin`, `web3-storage` — the keys PPN's port table and per-chain flags are defined for. | | `parachains[].paraId` | The network's real para id. Previewnet/paseo-next-v2 use the 1500 band; devnet and real networks the 1000 band. | -| `parachains[].cores` | Relay cores the chain runs on, 1 when absent. More than one is elastic scaling, and shortens block time only when the runtime is built for that many blocks per relay block (previewnet's Asset Hub and People: 3, so 2-second blocks). Genesis adds the extra cores and `assign-cores` hands them out. A fork of a shared relay lays its parachains out with these counts and `--cores` overrides them; a previewnet fork keeps the layout it bit. | +| `parachains[].cores` | Relay cores the chain runs on, 1 when absent. More than one is elastic scaling, and shortens block time only when the runtime is built for that many blocks per relay block (Asset Hub and People: 3, so 2-second blocks). Genesis adds the extra cores and `assign-cores` hands them out. A fork of a shared relay lays its parachains out with these counts and `--cores` overrides them; a previewnet fork keeps the layout it bit. | | `parachains[].spec` | Basename of the parachain spec inside the bundle. | | `services` | Optional `{ "": false }` map to disable custom processes that would otherwise run for the present parachains (e.g. eth-rpc for asset-hub, ipfs for bulletin). | | `dotns.resolver` | DotnsContentResolver address for `pin-bulletin-products` — per network, since every DotNS deployment has its own. Omitted → read from `bin/dotns-addresses.json` (previewnet's release artifact); still absent → the import is skipped. | diff --git a/networks/devnet.json b/networks/devnet.json index 01091f6..7c35e0c 100644 --- a/networks/devnet.json +++ b/networks/devnet.json @@ -56,6 +56,7 @@ { "key": "people", "paraId": 1004, + "cores": 3, "spec": "people", "rpc": "wss://people-paseo.rotko.net", "rpcAlternates": [ diff --git a/networks/paseo-next-v2.json b/networks/paseo-next-v2.json index 1906f49..0c22f23 100644 --- a/networks/paseo-next-v2.json +++ b/networks/paseo-next-v2.json @@ -51,6 +51,7 @@ { "key": "people", "paraId": 1502, + "cores": 3, "spec": "people", "rpc": "wss://paseo-people-next-system-rpc.polkadot.io", "specSource": "https://raw.githubusercontent.com/paritytech/chainspecs/main/paseo/parachain/people-next-system/raw.json", diff --git a/networks/polkadot.json b/networks/polkadot.json index 024519c..f830a55 100644 --- a/networks/polkadot.json +++ b/networks/polkadot.json @@ -49,6 +49,7 @@ { "key": "people", "paraId": 1004, + "cores": 3, "spec": "people", "rpc": "wss://polkadot-people-rpc.polkadot.io", "specSource": "builtin:people-polkadot", diff --git a/networks/westend.json b/networks/westend.json index 1398d39..02147bd 100644 --- a/networks/westend.json +++ b/networks/westend.json @@ -46,6 +46,7 @@ { "key": "people", "paraId": 1004, + "cores": 3, "spec": "people", "rpc": "wss://westend-people-rpc.polkadot.io", "specSource": "builtin:people-westend", diff --git a/packages/cli/src/commands/bite.ts b/packages/cli/src/commands/bite.ts index d0eb133..fb91371 100644 --- a/packages/cli/src/commands/bite.ts +++ b/packages/cli/src/commands/bite.ts @@ -529,7 +529,7 @@ export async function run(args: string[], opts: BiteOptions = {}): Promise // after minutes of syncing. const staged = stageUpgrades(opts.upgrades, chains, out, opts.upgradeCheckVersion ?? true); const topology = resolveTopology(opts, net); - if (topology) console.log(` topology: ${topologyFlags(topology)} → ${topology.validators} validators`); + if (topology) console.log(` topology: ${topologyFlags(topology) || 'the defaults'} → ${topology.validators} validators`); console.log(`=== 1/6 collecting chain specs (network: ${net.name}) ===`); for (const chain of chains) await collectSpec(chain, net, out, baseUrl, dgDir); diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index ce4f1a5..a4944ec 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -406,11 +406,11 @@ async function ensureDeps(netDef: NetworkDef, opts: StartOptions, binDir: string */ export function assertBundleTopology(forkDir: string, network: string, asked: ForkTopology | undefined): void { const m = JSON.parse(fs.readFileSync(path.join(forkDir, 'manifest.json'), 'utf-8')) as ForkManifest; - if (m.topology) console.log(` bitten with ${topologyFlags(m.topology)} (${m.topology.validators} validators)`); + if (m.topology) console.log(` bitten with ${topologyFlags(m.topology) || 'the defaults'} (${m.topology.validators} validators)`); if (sameTopology(asked, m.topology)) return; throw new Error( `--cores/--collators change how the bite lays the network out, and the bundle in ${forkDir} was bitten` + - (m.topology ? ` with ${topologyFlags(m.topology)}.` : ' with the defaults.') + + ` with ${(m.topology && topologyFlags(m.topology)) || 'the defaults'}.` + `\n Re-bite with it: ppn start ${network} --fork --fresh-bite${asked ? ' ' + topologyFlags(asked) : ''}` ); } diff --git a/packages/cli/src/fork/topology.ts b/packages/cli/src/fork/topology.ts index 47acdce..0fe6ce4 100644 --- a/packages/cli/src/fork/topology.ts +++ b/packages/cli/src/fork/topology.ts @@ -3,7 +3,8 @@ // // Settled at bite time, not at spawn: the collator authority sets and the relay's core layout // are state inside the snapshots (fork/validators.ts, fork/shared-relay.ts), so the fork TOML -// can only follow what the bundle says. A bundle bitten with the defaults carries no topology. +// can only follow what the bundle says. A bundle carries a topology only when it was asked for +// one or its descriptor's cores need more validators than `relay.validators`. import { MAX_VALIDATORS, type ForkTopology, type NetworkDef } from '@parity/ppn-network-config'; import { planCores, replacesCoreLayout } from './shared-relay.js'; @@ -28,7 +29,8 @@ function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef) } /** - * The topology a bite was asked for, or undefined when it was asked for nothing. + * The topology of a bite, or undefined when it was asked for nothing and the descriptor's + * validators staff every core it lays out. * * The validator count is not asked for: every core a bite lays out needs a validator group of its * own or nothing backs the blocks on it, so it is the descriptor's count or the number of those @@ -40,23 +42,25 @@ export function resolveTopology( ): ForkTopology | undefined { const cores = parseCounts('--cores', opts.cores, net); const collators = parseCounts('--collators', opts.collators, net); - if (!Object.keys(cores).length && !Object.keys(collators).length) return undefined; - const totalCores = replacesCoreLayout(net.bite.sharedRelay === true, cores) ? planCores(net.parachains, cores).length : 0; const validators = Math.max(net.relay.validators, totalCores); if (validators > MAX_VALIDATORS) { throw new Error( - `--cores adds up to ${totalCores} cores, which need ${totalCores} validators; a fork runs at most ${MAX_VALIDATORS}` + `the bite lays out ${totalCores} cores, which need ${totalCores} validators; a fork runs at most ${MAX_VALIDATORS}` ); } - return { validators, cores, collators }; + const asked = Object.keys(cores).length > 0 || Object.keys(collators).length > 0; + return asked || validators > net.relay.validators ? { validators, cores, collators } : undefined; } -/** Whether a bundle was bitten with this topology — both absent counts as the same. */ +/** + * Whether a bundle was bitten with the `--cores` and `--collators` a run asks for, none on both + * sides counting as the same. The validator count follows from them and the descriptor of the + * engine that bit the bundle, and the fork TOML takes it from the bundle. + */ export function sameTopology(a: ForkTopology | undefined, b: ForkTopology | undefined): boolean { - const norm = (t: ForkTopology | undefined) => - JSON.stringify(t ? { v: t.validators, c: sorted(t.cores), k: sorted(t.collators) } : null); - const sorted = (r: Record) => Object.fromEntries(Object.entries(r).sort()); + const sorted = (r: Record = {}) => Object.fromEntries(Object.entries(r).sort()); + const norm = (t: ForkTopology | undefined) => JSON.stringify({ c: sorted(t?.cores), k: sorted(t?.collators) }); return norm(a) === norm(b); } diff --git a/packages/cli/tests/fork-shared-relay.test.ts b/packages/cli/tests/fork-shared-relay.test.ts index 37a7d28..494a0e7 100644 --- a/packages/cli/tests/fork-shared-relay.test.ts +++ b/packages/cli/tests/fork-shared-relay.test.ts @@ -32,8 +32,8 @@ const PNV2 = loadNetwork('paseo-next-v2').parachains; const [ASSET_HUB, PEOPLE] = PNV2; describe('planCores', () => { - it('takes each parachain core count from the descriptor: Asset Hub on three, the rest on one', () => { - assert.deepEqual(PNV2.map((p) => [p.key, coresFor(p)]), [['asset-hub', 3], ['people', 1], ['bulletin', 1]]); + it('takes each parachain core count from the descriptor', () => { + assert.deepEqual(PNV2.map((p) => [p.key, coresFor(p)]), [['asset-hub', 3], ['people', 3], ['bulletin', 1]]); }); // Upward from zero is the whole point: those are the cores the runtime staffs first. @@ -43,30 +43,22 @@ describe('planCores', () => { { core: 1, paraId: 1500 }, { core: 2, paraId: 1500 }, { core: 3, paraId: 1502 }, - { core: 4, paraId: 1501 }, + { core: 4, paraId: 1502 }, + { core: 5, paraId: 1502 }, + { core: 6, paraId: 1501 }, ]); }); - // 5 cores + 1 = 6 validators, which is exactly the number of dev keys a fork runs by - // default. If this ever exceeds them, groups start coming out empty again and blocks stop - // being backed — which is why a bite asked for more cores grows the validator set to match. - it('plans no more cores than six validators can staff, by default', () => { - assert.ok(planCores(PNV2).length < 6, 'a fork has six dev validators'); - }); - - // `ppn bite --cores people=3`: the asked-for count replaces the default for that chain only. + // `ppn bite --cores people=1`: the asked-for count replaces the descriptor's for that chain only. it('lays a parachain out on as many cores as the bite asked for', () => { - assert.equal(coresFor(PEOPLE, { people: 3 }), 3); - assert.equal(coresFor(ASSET_HUB, { people: 3 }), 3, 'the default stays for the others'); - assert.equal(coresFor(ASSET_HUB, { 'asset-hub': 1 }), 1, 'and can be cut too'); - assert.deepEqual(planCores(PNV2, { people: 3 }), [ + assert.equal(coresFor(PEOPLE, { people: 1 }), 1); + assert.equal(coresFor(ASSET_HUB, { people: 1 }), 3, 'the descriptor count stays for the others'); + assert.deepEqual(planCores(PNV2, { people: 1 }), [ { core: 0, paraId: 1500 }, { core: 1, paraId: 1500 }, { core: 2, paraId: 1500 }, { core: 3, paraId: 1502 }, - { core: 4, paraId: 1502 }, - { core: 5, paraId: 1502 }, - { core: 6, paraId: 1501 }, + { core: 4, paraId: 1501 }, ]); }); }); @@ -236,10 +228,10 @@ describe('coreDescriptorsValue', () => { it('describes every planned core', () => { const value = coreDescriptorsValue(planCores(PNV2)); - assert.deepEqual(Object.keys(value), ['0', '1', '2', '3', '4']); + assert.deepEqual(Object.keys(value), ['0', '1', '2', '3', '4', '5', '6']); assert.deepEqual( Object.values(value).map((d: any) => d.currentWork.assignments[0][0].Task), - [1500, 1500, 1500, 1502, 1501] + [1500, 1500, 1500, 1502, 1502, 1502, 1501] ); }); }); diff --git a/packages/cli/tests/fork-topology.test.ts b/packages/cli/tests/fork-topology.test.ts index 84f9296..bafb6d8 100644 --- a/packages/cli/tests/fork-topology.test.ts +++ b/packages/cli/tests/fork-topology.test.ts @@ -28,6 +28,12 @@ describe('resolveTopology', () => { assert.equal(resolveTopology({ collators: ['people=5'] }, previewnet)?.validators, previewnet.relay.validators); }); + // paseo-next-v2's relay is shared, so a bite lays its chains out on their declared cores: + // Asset Hub 3 + People 3 + Bulletin 1 = 7, one more than the descriptor's six validators. + it('grows a default bite to one validator per core it lays out', () => { + assert.deepEqual(resolveTopology({}, loadNetwork('paseo-next-v2')), { validators: 7, cores: {}, collators: {} }); + }); + it('refuses a chain the network does not run, a bad count, and a malformed spec', () => { assert.throws(() => resolveTopology({ cores: ['kitchen-sink=3'] }, previewnet), /does not run/); assert.throws(() => resolveTopology({ cores: ['people=0'] }, previewnet), /at least 1/); @@ -53,6 +59,11 @@ describe('sameTopology', () => { assert.ok(!sameTopology(undefined, t)); }); + // A bundle bitten before the default grew still spawns with its own six validators. + it('treats a default bite grown to the descriptor cores as the same as an older default bundle', () => { + assert.ok(sameTopology({ validators: 7, cores: {}, collators: {} }, undefined)); + }); + it('compares what was asked for, not key order', () => { assert.ok(sameTopology(t, { validators: 8, collators: { people: 5 }, cores: { people: 3 } })); assert.ok(!sameTopology(t, { ...t, collators: { people: 4 } })); diff --git a/packages/network-config/src/networks.ts b/packages/network-config/src/networks.ts index ab3239f..e4747cd 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -452,10 +452,6 @@ export function loadDescriptor(name: string): NetworkDef { if (!Number.isInteger(validators) || validators < 1 || validators > 6) { bad('relay.validators must be 1..6 (alice…ferdie)'); } - // A shared relay's fork lays the parachains out on their declared cores with these validators. - if (raw.bite?.sharedRelay === true && validators < totalCores) { - bad(`relay.validators is ${validators}, fewer than the parachains' ${totalCores} cores, which a fork of a shared relay lays out`); - } const services: Record = raw.services ?? {}; for (const [svc, cfg] of Object.entries(services)) { diff --git a/packages/network-config/tests/networks.test.ts b/packages/network-config/tests/networks.test.ts index 361f825..5db2257 100644 --- a/packages/network-config/tests/networks.test.ts +++ b/packages/network-config/tests/networks.test.ts @@ -342,14 +342,6 @@ describe('cores', () => { ); }); - // previewnet's own relay keeps production's layout on a fork; a shared relay's is laid out anew. - it('rejects a shared relay with fewer validators than cores', () => { - assert.throws( - loadEdited((raw) => ({ ...raw, bite: { ...(raw.bite as object), sharedRelay: true } })), - /relay\.validators is 6, fewer than the parachains' 8 cores/ - ); - }); - it('rejects a parachain on no core', () => { assert.throws( loadEdited((raw) => ({ ...raw, parachains: raw.parachains.map((p) => (p.key === 'people' ? { ...p, cores: 0 } : p)) })),