diff --git a/CLAUDE.md b/CLAUDE.md index 5038699..a65ced4 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, one, two) - **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..05cbd74 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; `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 | +| 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/config/ports.env b/config/ports.env index 4fe18df..6db2bb0 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 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. @@ -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_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/docs/FORK.md b/docs/FORK.md index b641319..92fd74a 100644 --- a/docs/FORK.md +++ b/docs/FORK.md @@ -90,8 +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 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 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 @@ -100,17 +102,19 @@ 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. +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. @@ -217,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 ded1ba9..84bea22 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 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 (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..7c35e0c 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": [ @@ -55,6 +56,7 @@ { "key": "people", "paraId": 1004, + "cores": 3, "spec": "people", "rpc": "wss://people-paseo.rotko.net", "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..0c22f23 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", @@ -50,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 10aab1f..f830a55 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", @@ -48,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/previewnet.json b/networks/previewnet.json index 43f3b25..b180aa9 100644 --- a/networks/previewnet.json +++ b/networks/previewnet.json @@ -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..02147bd 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", @@ -45,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/fork.ts b/packages/cli/src/commands/fork.ts index eff0c9d..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.map((p) => ({ key: p.key, paraId: p.paraId })), + 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 db39c40..b61df8e 100644 --- a/packages/cli/src/commands/service.ts +++ b/packages/cli/src/commands/service.ts @@ -13,12 +13,14 @@ 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, } from '@parity/ppn-network-config'; import { forkBundleName } from '../lib/fork-bundle-name.js'; import { loadSecrets } from '../lib/secrets.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. */ @@ -112,57 +114,96 @@ export async function run(args: string[], deps: ServiceDeps = {}): Promise } // --------------------------------------------------------------------------- -// assign-cores — Asset Hub's 2-second blocks +// assign-cores — elastic scaling // --------------------------------------------------------------------------- /** - * 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. + * 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. */ -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( + paras: PlannedPara[], + coreParaIds: Map, + coreCount: number +): { assignments: CoreAssignment[]; missing: { key: string; cores: number }[] } { + 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 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 }); } - 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 }; +} + +/** 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 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. + const descriptors = (await api.query.paraScheduler.coreDescriptors()).toJSON() as unknown as Record< + string, + { queue: { last: number } | null; currentWork: CoreWorkJson | null } + >; + 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(); + coreParaIds.set(Number(core), paraIdsOf(schedule as unknown as CoreWorkJson | null)); + } else if (currentWork) { + coreParaIds.set(Number(core), paraIdsOf(currentWork)); + } } + 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 lists how many cores each chain lacks. + */ +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); + // One core per validator group, and at least `num_cores`: the genesis session has no groups, + // 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 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}: ` + + 'the relay schedules one core per validator group' + ); + } + 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. + const calls = assignments.map(({ core, paraId }) => + 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}`); } finally { await api.disconnect(); } 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/overrides.ts b/packages/cli/src/fork/overrides.ts index ae00450..1b87da3 100644 --- a/packages/cli/src/fork/overrides.ts +++ b/packages/cli/src/fork/overrides.ts @@ -20,6 +20,7 @@ import { hrmpParaKey, paraMessagingWipes, planCores, + replacesCoreLayout, transactionStorageWipes, validatorGroups, type PlannedPara, @@ -268,7 +269,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` ); @@ -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 = 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 c3fc89d..537c86c 100644 --- a/packages/cli/src/fork/shared-relay.ts +++ b/packages/cli/src/fork/shared-relay.ts @@ -48,17 +48,21 @@ export interface CoreAssignment { export interface PlannedPara { key: string; paraId: number; + cores: number; +} + +/** 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; } /** - * 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`). + * Whether a bite lays the relay's cores out anew. A shared relay's layout is wrong for us, and a + * 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 coresFor(key: string, cores: Record = {}): number { - return cores[key] ?? (key === 'asset-hub' ? 3 : 1); +export function replacesCoreLayout(sharedRelay: boolean, cores: Record = {}): boolean { + return sharedRelay || Object.keys(cores).length > 0; } /** @@ -72,7 +76,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; } @@ -231,8 +235,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 6be5041..0fe6ce4 100644 --- a/packages/cli/src/fork/topology.ts +++ b/packages/cli/src/fork/topology.ts @@ -3,11 +3,11 @@ // // 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 type { ForkTopology, NetworkDef } from '@parity/ppn-network-config'; -import { planCores } from './shared-relay.js'; -import { MAX_VALIDATORS } from './validators.js'; +import { MAX_VALIDATORS, type ForkTopology, type NetworkDef } from '@parity/ppn-network-config'; +import { planCores, replacesCoreLayout } from './shared-relay.js'; function parseCounts(flag: string, specs: string[] | undefined, net: NetworkDef): Record { const counts: Record = {}; @@ -29,11 +29,12 @@ 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 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[] }, @@ -41,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 = planCores(net.parachains, cores).length; + 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/src/fork/validators.ts b/packages/cli/src/fork/validators.ts index 8b14128..7c0cbe6 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,20 +25,17 @@ 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. * * 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/assign-cores.test.ts b/packages/cli/tests/assign-cores.test.ts new file mode 100644 index 0000000..d9229be --- /dev/null +++ b/packages/cli/tests/assign-cores.test.ts @@ -0,0 +1,74 @@ +// 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 readCoreAssignments() 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: [], + }); + }); + + 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 }); + assert.deepEqual(planExtraCores(PARACHAINS, subset, 5), { + assignments: [ + { core: 0, paraId: 1502 }, + { core: 1, 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..494a0e7 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', () => { + 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. @@ -47,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 }, ]); }); }); @@ -240,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/cli/tests/fork-validators.test.ts b/packages/cli/tests/fork-validators.test.ts index cdd3d63..8a6693c 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'; @@ -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/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/networks.ts b/packages/network-config/src/networks.ts index 4855785..e4747cd 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -128,17 +128,29 @@ 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). */ + /** + * Dev-key validators the fork runs with, max 6 (alice…ferdie). A genesis spawn runs one per + * parachain core where that is more, called 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`. */ fastRuntime?: RuntimeRef; @@ -425,6 +437,17 @@ 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); + if (totalCores > 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)'); @@ -477,6 +500,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..27f50bc 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -14,18 +14,20 @@ 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'; -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 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 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). */ function relayNodeName(i: number): string { return VALIDATORS[i] ?? `Validator-${i + 1}`; @@ -43,12 +45,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 -// 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 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 +139,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( @@ -325,12 +328,13 @@ function tomlArgs(args: string[]): string { return '[' + args.map((a) => `"${a}"`).join(', ') + ']'; } -function genesisParachainSection(key: Parachain, title: string, args: string[]): string { +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}" @@ -342,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 VALIDATORS.slice(0, count) - .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. */ @@ -408,12 +411,10 @@ 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); + // 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)); } // --------------------------------------------------------------------------- @@ -464,6 +465,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 +482,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 ` )} @@ -494,28 +498,16 @@ default_args = ${relayArgs} ${validatorNodes(validatorCount)} ${section( has('asset-hub'), - genesisParachainSection( - 'asset-hub', - `Asset Hub Paseo Next (Parachain ${paraIds()['asset-hub']}) - Elastic Scaling with 2-second blocks`, - genesisChainArgs('asset-hub', lt['asset-hub']) - ) + genesisParachainSection('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', 'People Chain', genesisChainArgs('people', lt.people)) )}${section( has('bulletin'), - genesisParachainSection( - 'bulletin', - `Bulletin Chain (Parachain ${paraIds().bulletin})`, - genesisChainArgs('bulletin', lt.bulletin, options.enableHop) - ) + genesisParachainSection('bulletin', 'Bulletin Chain', genesisChainArgs('bulletin', lt.bulletin, options.enableHop)) )}${section( has('web3-storage'), - genesisParachainSection( - 'web3-storage', - `Web3 Storage Chain (Parachain ${paraIds()['web3-storage']})`, - 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( @@ -602,12 +594,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('set-dispatcher-address'), + ` [[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..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/networks.test.ts b/packages/network-config/tests/networks.test.ts index bc03c5a..5db2257 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'; @@ -56,6 +57,10 @@ describe('network descriptors', () => { assert.equal(net.parachains.find((p) => p.key === 'people')!.spec, 'individuality'); assert.equal(net.relay.chain, 'paseo'); 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 } + ); }); // 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 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, one validator per core, and a relay runs at most 10 validators/ + ); + }); + + 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..38b3b28 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')); + // 7 validators: one per core (3 + 3 + 1), past the descriptor's 6 + for (const name of ['alice', 'bob', 'charlie', 'dave', 'eve', 'ferdie', 'one']) { + assert.ok(toml.includes(`name = "${name}-paseo-validator"`), name); + } + assert.ok(!toml.includes('two-paseo-validator')); // 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 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('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('runs one validator per core past the descriptor count', () => { + assert.equal(calcValidatorCount(['asset-hub', 'people', 'bulletin']), 7); + assert.equal(calcValidatorCount([...VALID_PARACHAINS]), 8); }); it('returns 4 for empty/null input', () => { diff --git a/tests/01-asset-hub-revive.zndsl b/tests/01-asset-hub-revive.zndsl index ea5beb0..86130ef 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 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 + # ============================================ # pallet-revive Tests # ============================================ diff --git a/tests/03-people-chain.zndsl b/tests/03-people-chain.zndsl index 0b33ff3..77ffb09 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 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 + # ============================================ # Individuality Pallet Tests # ============================================ diff --git a/tests/scripts/test-block-time.ts b/tests/scripts/test-block-time.ts new file mode 100644 index 0000000..494b40d --- /dev/null +++ b/tests/scripts/test-block-time.ts @@ -0,0 +1,38 @@ +import type { PolkadotClient } from "polkadot-api"; +import type { NetworkInfo } from "./types/zombienet"; +import { SUCCESS, FAILURE, CHAINS, connectWithRetry, safeDisconnect, sleep, waitForChainReady, type ChainName } from "./utils"; + +const WINDOW_SECONDS = 60; + +/** + * 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 [chain, max] = args; + const maxSeconds = Number(max); + const node = networkInfo.nodesByName[nodeName]; + 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, chain as ChainName); + 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} ${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}`); + return FAILURE; + } finally { + safeDisconnect(client); + } +} diff --git a/zombienet-configs/local-dev.toml b/zombienet-configs/local-dev.toml index ead6e39..5e0422d 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 = "one-paseo-validator" +validator = true +rpc_port = 10006 +prometheus_port = 20006 +balance = 1000000000000000 + +[[relaychain.nodes]] +name = "two-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