From 69956fed7de5b14228395941e01b65b1ba0c735b Mon Sep 17 00:00:00 2001 From: Maksym H Date: Thu, 12 Nov 2026 23:19:33 +0000 Subject: [PATCH 1/4] Fork Westend: relay, Asset Hub and People --- .github/workflows/bite-network.yml | 2 +- networks/README.md | 1 + networks/westend.json | 76 ++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 networks/westend.json diff --git a/.github/workflows/bite-network.yml b/.github/workflows/bite-network.yml index 7a82a36..a9b25aa 100644 --- a/.github/workflows/bite-network.yml +++ b/.github/workflows/bite-network.yml @@ -16,7 +16,7 @@ on: required: true default: kusama type: choice - options: [kusama, polkadot, devnet, paseo-next-v2, previewnet] + options: [kusama, polkadot, westend, devnet, paseo-next-v2, previewnet] upgrade: description: 'Authorize a runtime at import: =, comma-separated' required: false diff --git a/networks/README.md b/networks/README.md index 9608756..d2f94b4 100644 --- a/networks/README.md +++ b/networks/README.md @@ -111,3 +111,4 @@ dial collators, a resolved address is the only way that substream ever opens. | devnet | no | yes | once its `_todo` clears | sources filled from docs.polkadotcommunity.foundation; one open question — whether doppelganger can warp-sync Asset Hub from the published smol (stateRootHash) spec. Verify with `make bite NETWORK=devnet`, then drop the `_todo`. It shares a relay with other parachains, so it needs `bite.sharedRelay` too — already set | | kusama | no | on-the-fly only | no (no sudo) | wired. Asset Hub's spec comes from the parachain binary (`builtin:asset-hub-kusama`). A runtime under test is authorized at bite time — `ppn bite --upgrade asset-hub=` — since nothing can dispatch root after the fork; see docs/FORK.md. Upstream equivalent: [zombie-bite#127](https://github.com/paritytech/zombie-bite/issues/127) | | polkadot | no | on-the-fly only | no (no sudo) | relay + Asset Hub 1000 + People 1004 + Bulletin 1010, all live at runtimes 2.4; the fellowship's 2.5 (Individuality on People and Asset Hub) is what a fork of it is for — `make bite NETWORK=polkadot UPGRADES="asset-hub= people="` authorizes the blobs at import. All six HRMP channels between the three exist live and survive the bite (reset, not cleared). ~50 registered parachains makes the core remapping above load-bearing rather than a nicety. Runbook: docs/POLKADOT-FORK.md | +| westend | no | on-the-fly only | no | relay + Asset Hub 1000 + People 1004, the chains polkadot-sdk releases Westend runtimes for. The relay and Asset Hub have sudo and upgrade after the fork; People has none, so its runtime is authorized at bite time (`UPGRADES="people="`). The Individuality processes are off, since Westend runs none of those pallets | diff --git a/networks/westend.json b/networks/westend.json new file mode 100644 index 0000000..46e6cfd --- /dev/null +++ b/networks/westend.json @@ -0,0 +1,76 @@ +{ + "name": "westend", + "displayName": "Westend", + "description": "Fork-only, bitten on the fly. Relay, Asset Hub and People: the system chains polkadot-sdk's Westend runtimes are released for, without the Individuality pallets. The relay and Asset Hub have sudo; People does not, so a People runtime under test is authorized at bite time (`--upgrade people=`).", + "genesis": false, + "sudo": true, + "bite": { + "prebaked": false, + "source": "wss://westend-rpc.polkadot.io", + "doppelganger": { + "repo": "paritytech/doppelganger-wrapper", + "tag": "v0.2.3" + }, + "sharedRelay": true + }, + "releases": { + "polkadot-sdk": { + "repo": "paritytech/release-automation", + "tag": "latest" + } + }, + "relay": { + "chain": "westend", + "spec": "westend", + "rpc": "wss://westend-rpc.polkadot.io", + "specSource": "builtin", + "validators": 6, + "binary": { + "name": "polkadot", + "release": "polkadot-sdk" + } + }, + "parachains": [ + { + "key": "asset-hub", + "paraId": 1000, + "spec": "asset-hub", + "rpc": "wss://westend-asset-hub-rpc.polkadot.io", + "specSource": "builtin:asset-hub-westend", + "binary": { + "name": "polkadot-parachain", + "release": "polkadot-sdk" + } + }, + { + "key": "people", + "paraId": 1004, + "spec": "people", + "rpc": "wss://westend-people-rpc.polkadot.io", + "specSource": "builtin:people-westend", + "binary": { + "name": "polkadot-parachain", + "release": "polkadot-sdk" + } + } + ], + "services": { + "eth-rpc": { + "binary": { + "name": "eth-rpc", + "release": "polkadot-sdk" + } + }, + "pin-design-families": false, + "increase-people-lite-attestation-allowance": false, + "increase-dotns-attestation-allowance": false, + "grant-invites": false, + "_note": "Westend runs none of the Individuality pallets these processes grant from." + }, + "stack": { + "tld": "westend", + "pointer": { + "url": "https://stack-westend.parity-testnet.parity.io/.well-known/trinity-stack.json" + } + } +} From 14d7ffc4c24bc26a8943b3c6a8356692d0a3a9ba Mon Sep 17 00:00:00 2001 From: Maksym H Date: Thu, 12 Nov 2026 23:30:11 +0000 Subject: [PATCH 2/4] Fill every SessionKeys field when installing a fork's collators --- packages/cli/src/fork/overrides.ts | 25 ++++- packages/cli/src/fork/validators.ts | 90 ++++++++++++++++-- .../cli/tests/fixtures/overrides.golden.json | 8 +- packages/cli/tests/fork-validators.test.ts | 95 +++++++++++++++++-- 4 files changed, 191 insertions(+), 27 deletions(-) diff --git a/packages/cli/src/fork/overrides.ts b/packages/cli/src/fork/overrides.ts index 567186a..ed15a0c 100644 --- a/packages/cli/src/fork/overrides.ts +++ b/packages/cli/src/fork/overrides.ts @@ -25,14 +25,16 @@ import { type PlannedPara, } from './shared-relay.js'; import { - collatorKeys, devValidators, paraCandidates, + paraCollators, paraInjects, relayCandidates, relayInjects, + sessionKeyFields, sudoEndowInjects, authorizedUpgradeCandidate, + type SessionKeyFieldType, } from './validators.js'; import type { AuraScheme } from '@parity/ppn-network-config'; @@ -431,6 +433,17 @@ function seededUpgradeInject(index: StorageIndex, upgrade?: SeededUpgrade): Reco return report('seeded upgrade authorization', verify(index, candidate), candidate); } +/** The fields of the runtime's SessionKeys, from the value type of Session::NextKeys. */ +function sessionKeysType(index: StorageIndex): SessionKeyFieldType[] { + const nextKeys = index.byKey.get(keyOf('Session', 'NextKeys')); + if (nextKeys?.mapValue == null) throw new Error('Session::NextKeys is not a map in this runtime'); + const { lookup } = index.reg; + return lookup.getSiType(nextKeys.mapValue).def.asComposite.fields.map((field) => ({ + name: field.name.toString(), + typePath: lookup.getSiType(field.type).path.map(String), + })); +} + export async function paraOverrides( paraId: number, paraUrl: string, @@ -441,7 +454,10 @@ export async function paraOverrides( collatorCount = 1 ): Promise { const index = await storageIndex(paraUrl); - const collators = await collatorKeys(paraId, collatorCount, scheme); + // A parachain without a Session pallet manages authorities through Aura alone. + const hasSession = index.pallets.has('Session'); + const fields = hasSession ? sessionKeyFields(sessionKeysType(index), scheme) : []; + const collators = await paraCollators(paraId, collatorCount, scheme, fields); // The inherited messaging state is reset on every bite, matching the relay half in // messagingResets() — see ./shared-relay.ts. The channels stay open, so XCM keeps working. // The transaction-storage wipe applies on EVERY bite of a chain with that pallet, not @@ -457,13 +473,12 @@ export async function paraOverrides( console.log( `para ${paraId} (${collators.length} collator${collators.length === 1 ? '' : 's'} from //Collator-${paraId} ` + - `${scheme} = ${collators.map((c) => c.slice(0, 16) + '…').join(', ')}):` + `${scheme} = ${collators.map((collator) => collator.account.slice(0, 16) + '…').join(', ')}):` ); const overrides = report(`para ${paraId} overrides`, verify(index, candidates), candidates); - // A parachain without a Session pallet manages authorities through Aura alone. const injects = { - ...(index.pallets.has('Session') ? paraInjects(collators) : {}), + ...(hasSession ? paraInjects(collators) : {}), // Parachains of a shared relay are live public chains: no dev account holds // funds there, so sudo is endowed at import (see sudoEndowInjects). ...(sharedRelay ? sudoEndowInjects() : {}), diff --git a/packages/cli/src/fork/validators.ts b/packages/cli/src/fork/validators.ts index 0a0c58a..c76bc8c 100644 --- a/packages/cli/src/fork/validators.ts +++ b/packages/cli/src/fork/validators.ts @@ -212,36 +212,106 @@ export function authorizedUpgradeCandidate(codeHash: string, checkVersion: boole return { [keyOf('System', 'AuthorizedUpgrade')]: hash + (checkVersion ? '01' : '00') }; } +/** A SessionKeys field: the KeyTypeId its key is registered under, and the key's curve. */ +export interface SessionKeyField { + keyTypeId: string; + scheme: AuraScheme; +} + +/** A parachain SessionKeys field as metadata describes it: its name and its type's path. */ +export interface SessionKeyFieldType { + name: string; + typePath: string[]; +} + +// Metadata carries the SessionKeys field names but not their KeyTypeIds. +const PARA_KEY_TYPE_IDS: Record = { aura: 'aura', authority_discovery: 'audi' }; + +function keyScheme(typePath: string[]): AuraScheme | undefined { + if (typePath.some((segment) => segment.includes('sr25519'))) return 'sr25519'; + if (typePath.some((segment) => segment.includes('ed25519'))) return 'ed25519'; + // `sp_authority_discovery::app::Public` is sr25519 app crypto; its path does not say so. + if (typePath[0] === 'sp_authority_discovery') return 'sr25519'; + return undefined; +} + +/** + * The KeyTypeId and curve of each SessionKeys field, in field order. Fails on a field whose + * KeyTypeId or curve is unknown, and on an Aura curve other than the one the descriptor declares. + */ +export function sessionKeyFields(fields: SessionKeyFieldType[], auraScheme: AuraScheme): SessionKeyField[] { + return fields.map(({ name, typePath }) => { + const keyTypeId = PARA_KEY_TYPE_IDS[name]; + const scheme = keyScheme(typePath); + if (!keyTypeId || !scheme) { + throw new Error(`SessionKeys field "${name}" (${typePath.join('::')}) has no known KeyTypeId and curve`); + } + if (name === 'aura' && scheme !== auraScheme) { + throw new Error(`the descriptor declares ${auraScheme} Aura keys, but the runtime's SessionKeys has ${scheme}`); + } + return { keyTypeId, scheme }; + }); +} + +/** A collator's account and its session keys, in SessionKeys order. */ +export interface ParaCollator { + account: string; + sessionKeys: { keyTypeId: string; publicKey: string }[]; +} + +/** The collators collatorKeys() derives, each with a key for every field of the runtime's SessionKeys. */ +export async function paraCollators( + paraId: number, + count: number, + scheme: AuraScheme, + fields: SessionKeyField[] +): Promise { + const keysByScheme = new Map([[scheme, await collatorKeys(paraId, count, scheme)]]); + for (const field of fields) { + if (!keysByScheme.has(field.scheme)) keysByScheme.set(field.scheme, await collatorKeys(paraId, count, field.scheme)); + } + return keysByScheme.get(scheme)!.map((account, position) => ({ + account, + sessionKeys: fields.map((field) => ({ + keyTypeId: field.keyTypeId, + publicKey: keysByScheme.get(field.scheme)![position], + })), + })); +} + /** * Parachain storage values that install the collators as its authority set. One key serves as * both the account and the Aura key: the seed is the same and the account is the sr25519 public * key, which is what CollatorSelection and Session hold. */ -export function paraCandidates(collators: string[]): Record { +export function paraCandidates(collators: ParaCollator[]): Record { const len = compactLen(collators.length); - const all = collators.join(''); + const all = collators.map((collator) => collator.account).join(''); return { [keyOf('CollatorSelection', 'DesiredCandidates')]: u32le(collators.length), [keyOf('CollatorSelection', 'Invulnerables')]: len + all, [keyOf('AuraExt', 'Authorities')]: len + all, [keyOf('Aura', 'Authorities')]: len + all, [keyOf('Session', 'Validators')]: len + all, - [keyOf('Session', 'QueuedKeys')]: len + collators.map((c) => c + c).join(''), + [keyOf('Session', 'QueuedKeys')]: + len + + collators.map((collator) => collator.account + collator.sessionKeys.map((key) => key.publicKey).join('')).join(''), [keyOf('Sudo', 'Key')]: ALICE_SR, // ParachainSystem::LastDmqMqcHead is left alone: zeroing it (as zombie-bite does) // desyncs the parachain from the relay's preserved Dmp state. }; } -export function paraInjects(collators: string[]): Record { +export function paraInjects(collators: ParaCollator[]): Record { const injects: Record = {}; for (const collator of collators) { - injects[keyOf('Session', 'NextKeys') + twox64Concat(collator)] = collator; - // Session::KeyOwner(("aura", collatorKey)) - injects[ - 'cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950eab3d4a1675d3d746175726180' + - collator - ] = collator; + injects[keyOf('Session', 'NextKeys') + twox64Concat(collator.account)] = + collator.sessionKeys.map((key) => key.publicKey).join(''); + for (const { keyTypeId, publicKey } of collator.sessionKeys) { + // Session::KeyOwner((KeyTypeId, Vec)) + const owned = Buffer.from(keyTypeId).toString('hex') + compactLen(publicKey.length / 2) + publicKey; + injects[keyOf('Session', 'KeyOwner') + twox64Concat(owned)] = collator.account; + } } return injects; } diff --git a/packages/cli/tests/fixtures/overrides.golden.json b/packages/cli/tests/fixtures/overrides.golden.json index c974f2d..b541697 100644 --- a/packages/cli/tests/fixtures/overrides.golden.json +++ b/packages/cli/tests/fixtures/overrides.golden.json @@ -11,7 +11,7 @@ }, "injects": { "cec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb3c1c2d338a7d5c5c2daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b": "daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b", - "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950eab3d4a1675d3d746175726180daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b": "daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b" + "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa19505e35a0daa77e88186175726180daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b": "daba6e1187737bf6d823eb17dac6825a64ed304754f8290e6bdf30e497bc3b2b" } }, "1501": { @@ -26,7 +26,7 @@ }, "injects": { "cec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb3a902fc38ca718a9298313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22": "98313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22", - "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950eab3d4a1675d3d74617572618098313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22": "98313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22" + "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa19508aff82ec8f37b75c617572618098313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22": "98313b04a2915e6dc2b9e15eab29a6a9c663755ae771edd09ed494adfa21cd22" } }, "1502": { @@ -41,7 +41,7 @@ }, "injects": { "cec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb344066402be75b7153cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03": "3cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03", - "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950eab3d4a1675d3d7461757261803cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03": "3cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03" + "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950742c187aa31e9fed61757261803cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03": "3cfde612e45c223a6f3e0e993e04c43c19ef034c686803b4a2b075a0febd8b03" } }, "1600": { @@ -56,7 +56,7 @@ }, "injects": { "cec5070d609dd3497f72bde07fc96ba04c014e6bf8b8c2c011e7290b85696bb3a87628be6224b353682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60": "682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60", - "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950eab3d4a1675d3d746175726180682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60": "682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60" + "cec5070d609dd3497f72bde07fc96ba0726380404683fc89e8233450c8aa1950b454ce80213e1f976175726180682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60": "682d75e3c59d27867eb4567f1fb2cff9a516c3fdd62f6795ebf5932475e94c60" } }, "relay": { diff --git a/packages/cli/tests/fork-validators.test.ts b/packages/cli/tests/fork-validators.test.ts index b28dc77..bb2e780 100644 --- a/packages/cli/tests/fork-validators.test.ts +++ b/packages/cli/tests/fork-validators.test.ts @@ -12,15 +12,18 @@ import { collatorKeys, devValidators, paraCandidates, + paraCollators, paraInjects, relayCandidates, relayInjects, sessionKeys, + sessionKeyFields, authorizedUpgradeCandidate, type DevValidator, } from '../src/fork/validators.js'; import { verify, verifyInjects } from '../src/fork/overrides.js'; -import { compactLen, keyOf, u32le } from '../src/fork/codec.js'; +import { compactLen, keyOf, twox64Concat, u32le } from '../src/fork/codec.js'; +import { TypeRegistry } from '@polkadot/types'; import { PARACHAINS } from '../src/fork/chains.js'; // Captured from the override files of a bite that produced a verified working fork, before @@ -191,11 +194,14 @@ describe('para overrides', () => { assert.notEqual(a, await collatorKey(1500), 'para id must change the key'); }); + // Every parachain bitten before authority_discovery joined SessionKeys had Aura alone. + const AURA_ONLY = [{ keyTypeId: 'aura', scheme: 'sr25519' as const }]; + it('matches the values a verified bite produced, for every parachain', async () => { for (const { paraId } of PARACHAINS) { - const collator = await collatorKey(paraId); - const candidates = paraCandidates([collator]); - const injects = paraInjects([collator]); + const collators = await paraCollators(paraId, 1, 'sr25519', AURA_ONLY); + const candidates = paraCandidates(collators); + const injects = paraInjects(collators); for (const [key, value] of Object.entries(GOLDEN[paraId].overrides)) { assert.equal(candidates[key], value, `para ${paraId} override ${key} changed`); } @@ -207,7 +213,7 @@ describe('para overrides', () => { it('installs exactly one collator as the authority by default', async () => { const collator = await collatorKey(1500); - const candidates = paraCandidates([collator]); + const candidates = paraCandidates(await paraCollators(1500, 1, 'sr25519', AURA_ONLY)); assert.equal(candidates[keyOf('CollatorSelection', 'DesiredCandidates')], '01000000'); for (const [pallet, item] of [['Aura', 'Authorities'], ['AuraExt', 'Authorities'], ['Session', 'Validators']]) { assert.equal(candidates[keyOf(pallet, item)], compactLen(1) + collator, `${pallet}::${item}`); @@ -231,23 +237,96 @@ describe('para overrides', () => { it('installs every collator it is given as an authority', async () => { const five = await collatorKeys(1502, 5); - const candidates = paraCandidates(five); + const collators = await paraCollators(1502, 5, 'sr25519', AURA_ONLY); + const candidates = paraCandidates(collators); assert.equal(candidates[keyOf('CollatorSelection', 'DesiredCandidates')], u32le(5)); for (const [pallet, item] of [['Aura', 'Authorities'], ['AuraExt', 'Authorities'], ['Session', 'Validators'], ['CollatorSelection', 'Invulnerables']]) { assert.equal(candidates[keyOf(pallet, item)], compactLen(5) + five.join(''), `${pallet}::${item}`); } assert.equal(candidates[keyOf('Session', 'QueuedKeys')], compactLen(5) + five.map((c) => c + c).join('')); // One NextKeys entry and one KeyOwner entry per collator. - assert.equal(Object.keys(paraInjects(five)).length, 10); + assert.equal(Object.keys(paraInjects(collators)).length, 10); }); // Zeroing it, as zombie-bite does, desyncs the parachain from the relay's preserved Dmp. it('leaves ParachainSystem::LastDmqMqcHead alone', async () => { - const candidates = paraCandidates([await collatorKey(1500)]); + const candidates = paraCandidates(await paraCollators(1500, 1, 'sr25519', AURA_ONLY)); assert.equal(candidates[keyOf('ParachainSystem', 'LastDmqMqcHead')], undefined); }); }); +// polkadot-sdk parachains carry `SessionKeys { aura, authority_discovery }` (Westend's Asset Hub +// and People already do). Session::QueuedKeys and NextKeys decode as that struct, so a value +// carrying only the Aura key fails the runtime's round-trip and the bite stops there. +describe('para session keys', () => { + const WESTEND_ASSET_HUB = [ + { name: 'aura', typePath: ['sp_consensus_aura', 'sr25519', 'app_sr25519', 'Public'] }, + { name: 'authority_discovery', typePath: ['sp_authority_discovery', 'app', 'Public'] }, + ]; + + const registry = new TypeRegistry(); + registry.register({ TwoKeySessionKeys: { aura: '[u8;32]', authority_discovery: '[u8;32]' } }); + const roundTrips = (type: string, hex: string) => registry.createType(type, '0x' + hex).toHex() === '0x' + hex; + + it('reads the KeyTypeId and curve of every SessionKeys field', () => { + assert.deepEqual(sessionKeyFields(WESTEND_ASSET_HUB, 'sr25519'), [ + { keyTypeId: 'aura', scheme: 'sr25519' }, + { keyTypeId: 'audi', scheme: 'sr25519' }, + ]); + }); + + it('writes a key for every field, each round-tripping through the runtime type', async () => { + const collators = await paraCollators(1000, 2, 'sr25519', sessionKeyFields(WESTEND_ASSET_HUB, 'sr25519')); + const account = await collatorKey(1000); + assert.deepEqual(collators[0].sessionKeys.map((key) => key.publicKey), [account, account]); + + const queued = paraCandidates(collators)[keyOf('Session', 'QueuedKeys')]; + assert.ok(roundTrips('Vec<(AccountId32, TwoKeySessionKeys)>', queued)); + const [[, firstKeys]] = registry.createType('Vec<(AccountId32, TwoKeySessionKeys)>', '0x' + queued).toJSON() as [string, unknown][]; + assert.deepEqual(firstKeys, { aura: '0x' + account, authority_discovery: '0x' + account }); + + const injects = paraInjects(collators); + const nextKeys = injects[keyOf('Session', 'NextKeys') + twox64Concat(account)]; + assert.ok(roundTrips('TwoKeySessionKeys', nextKeys)); + }); + + // `KeyOwner::get((KeyTypeId, key))` is how the runtime finds the account behind a key, so each + // entry has to sit at the Twox64Concat key of that tuple, one per key. + it('records the owner of every key under its own KeyTypeId', async () => { + const collators = await paraCollators(1000, 1, 'sr25519', sessionKeyFields(WESTEND_ASSET_HUB, 'sr25519')); + const account = collators[0].account; + const injects = paraInjects(collators); + for (const keyTypeId of ['aura', 'audi']) { + const owned = registry.createType('([u8;4], Bytes)', [Buffer.from(keyTypeId), '0x' + account]).toHex().slice(2); + assert.equal(injects[keyOf('Session', 'KeyOwner') + twox64Concat(owned)], account); + } + }); + + it('derives a field on another curve from the same seed', async () => { + const fields = sessionKeyFields( + [ + { name: 'aura', typePath: ['sp_consensus_aura', 'ed25519', 'app_ed25519', 'Public'] }, + { name: 'authority_discovery', typePath: ['sp_authority_discovery', 'app', 'Public'] }, + ], + 'ed25519' + ); + const [collator] = await paraCollators(1000, 1, 'ed25519', fields); + assert.equal(collator.account, await collatorKey(1000, 'ed25519')); + assert.deepEqual(collator.sessionKeys.map((key) => key.publicKey), [ + await collatorKey(1000, 'ed25519'), + await collatorKey(1000, 'sr25519'), + ]); + }); + + it('rejects a field it cannot key, and an Aura curve the descriptor disagrees with', () => { + assert.throws( + () => sessionKeyFields([{ name: 'beefy', typePath: ['sp_consensus_beefy', 'ecdsa_crypto', 'Public'] }], 'sr25519'), + /SessionKeys field "beefy"/ + ); + assert.throws(() => sessionKeyFields(WESTEND_ASSET_HUB, 'ed25519'), /declares ed25519 Aura keys/); + }); +}); + // verify() is what stands between a wrong encoding and a silently broken fork, so its own // behaviour is pinned here with a stand-in registry. describe('verify', () => { From c9863cceea8708949d4cf22e5f1419dbbc5ac083 Mon Sep 17 00:00:00 2001 From: Maksym H Date: Thu, 12 Nov 2026 23:30:12 +0000 Subject: [PATCH 3/4] Copy the PVF workers next to a locally built polkadot --- packages/cli/README.md | 4 ++ packages/cli/src/commands/fetch.ts | 44 ++++++++++++++++--- packages/cli/tests/fetch-local.test.ts | 59 ++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 packages/cli/tests/fetch-local.test.ts diff --git a/packages/cli/README.md b/packages/cli/README.md index f848c5e..fd20b26 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -66,6 +66,10 @@ about what is running. An unknown binary or release name is refused rather than `ppn show --json` marks every overridden slot, so a gate can report what actually executed instead of what it asked for. +A local `polkadot` (`--binary polkadot=file:/path/to/target/release/polkadot`) is copied together with +`polkadot-execute-worker` and `polkadot-prepare-worker` from the same directory, and the fetch fails if +either is missing. + ## Authentication `ppn fetch` reads GitHub releases. The packaged networks name only public ones, so a token is diff --git a/packages/cli/src/commands/fetch.ts b/packages/cli/src/commands/fetch.ts index c5b3563..c9f4b4b 100644 --- a/packages/cli/src/commands/fetch.ts +++ b/packages/cli/src/commands/fetch.ts @@ -64,6 +64,37 @@ function copyLocal(src: string, dest: string, what: string): void { fs.copyFileSync(src, dest); } +const PVF_WORKERS = ['polkadot-execute-worker', 'polkadot-prepare-worker']; + +export interface LocalBinaryCopy { + name: string; + src: string; + dest: string; +} + +/** + * Copy a `file:` pinned binary into `nodeDest`. A local polkadot also brings its PVF workers from + * its own directory, and fails without copying anything when either is not there. + */ +export function copyLocalBinary(name: string, src: string, nodeDest: string): LocalBinaryCopy[] { + const copies = [{ name, src, dest: path.join(nodeDest, name) }]; + if (name === 'polkadot') { + for (const worker of PVF_WORKERS) { + const workerSrc = path.join(path.dirname(src), worker); + if (!fs.existsSync(workerSrc)) { + throw new Error(`--binary polkadot=file:${src}: no ${worker} next to it at ${workerSrc}; ` + + 'a local polkadot needs both PVF workers from its own build'); + } + copies.push({ name: worker, src: workerSrc, dest: path.join(nodeDest, worker) }); + } + } + for (const copy of copies) { + copyLocal(copy.src, copy.dest, `--binary ${copy.name}`); + makeExecutable(copy.dest); + } + return copies; +} + const REPO = repoRoot(); /** Mutable state — binaries, chain data, bundles — lives in the workspace, not the package. */ const WS = workspaceRoot(); @@ -219,11 +250,10 @@ export async function run(args: string[], opts: FetchOptions = {}): Promise b.name === 'polkadot')) { - for (const w of ['polkadot-execute-worker', 'polkadot-prepare-worker']) { + for (const w of PVF_WORKERS) { if (gone(nodeDest, w)) out.push(w); } } diff --git a/packages/cli/tests/fetch-local.test.ts b/packages/cli/tests/fetch-local.test.ts new file mode 100644 index 0000000..6deede5 --- /dev/null +++ b/packages/cli/tests/fetch-local.test.ts @@ -0,0 +1,59 @@ +// Tests for copyLocalBinary in packages/cli/src/commands/fetch.ts +// Run with: tsx --test tests/fetch-local.test.ts +// +// A `file:` pinned polkadot is a local build, and polkadot validates PVFs with the two workers +// built alongside it. Copying only polkadot left a node that spawns and then fails every +// candidate it is asked to validate. + +import { describe, it, beforeEach, afterEach } from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { copyLocalBinary } from '../src/commands/fetch.js'; + +let buildDir: string; +let nodeDest: string; + +const writeBuild = (...names: string[]) => { + for (const name of names) fs.writeFileSync(path.join(buildDir, name), `${name} build`); +}; + +beforeEach(() => { + buildDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-build-')); + nodeDest = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-bin-')); +}); +afterEach(() => { + fs.rmSync(buildDir, { recursive: true, force: true }); + fs.rmSync(nodeDest, { recursive: true, force: true }); +}); + +describe('copyLocalBinary', () => { + it('copies a local polkadot together with the PVF workers from its build', () => { + writeBuild('polkadot', 'polkadot-execute-worker', 'polkadot-prepare-worker'); + const copies = copyLocalBinary('polkadot', path.join(buildDir, 'polkadot'), nodeDest); + + assert.deepEqual(copies.map((copy) => copy.name), ['polkadot', 'polkadot-execute-worker', 'polkadot-prepare-worker']); + for (const name of ['polkadot', 'polkadot-execute-worker', 'polkadot-prepare-worker']) { + const dest = path.join(nodeDest, name); + assert.equal(fs.readFileSync(dest, 'utf-8'), `${name} build`); + assert.ok(fs.statSync(dest).mode & 0o100); + } + }); + + it('fails, copying nothing, when a worker is missing next to polkadot', () => { + writeBuild('polkadot', 'polkadot-execute-worker'); + assert.throws( + () => copyLocalBinary('polkadot', path.join(buildDir, 'polkadot'), nodeDest), + /no polkadot-prepare-worker next to it/ + ); + assert.deepEqual(fs.readdirSync(nodeDest), []); + }); + + it('copies any other binary alone', () => { + writeBuild('polkadot-parachain'); + const copies = copyLocalBinary('polkadot-parachain', path.join(buildDir, 'polkadot-parachain'), nodeDest); + assert.deepEqual(copies.map((copy) => copy.name), ['polkadot-parachain']); + assert.deepEqual(fs.readdirSync(nodeDest), ['polkadot-parachain']); + }); +}); From e031dae91772287b1956406b3381871d0408d49e Mon Sep 17 00:00:00 2001 From: Maksym H Date: Fri, 13 Nov 2026 00:06:51 +0000 Subject: [PATCH 4/4] Fork Westend's relay at its head and fail a bite whose import failed --- packages/cli/src/commands/bite.ts | 45 ++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/commands/bite.ts b/packages/cli/src/commands/bite.ts index 0dd2bea..5cef8ff 100644 --- a/packages/cli/src/commands/bite.ts +++ b/packages/cli/src/commands/bite.ts @@ -125,7 +125,7 @@ function biteLogDir(out: string): string { * * Resolves whatever the exit code is: doppelganger deliberately ends an essential task to stop * the node once it has captured the state, so a non-zero exit is the normal path. Success is - * judged by the info file the node writes, as before. + * judged by readBiteBlock. */ function runBiteNode( cmd: string, @@ -203,6 +203,17 @@ function logTail(logFile: string, lines: number, filter?: RegExp): string[] { return (picked.length ? picked : all).slice(-lines); } +/** + * The block a bite node captured, or null when it captured none. doppelganger writes the info + * file whether or not importing that block succeeded, so the import result in its log decides. + */ +function readBiteBlock(infoFile: string, logFile: string): number | null { + const log = fs.existsSync(logFile) ? fs.readFileSync(logFile, 'utf-8') : ''; + if (!log.includes('Block import done! : Ok(') || !fs.existsSync(infoFile)) return null; + const block = fs.readFileSync(infoFile, 'utf-8').trim(); + return block ? Number(block) : null; +} + export interface BiteOptions { /** Override the network's own bite.source, to bite another instance of it. */ source?: string; @@ -554,7 +565,7 @@ export async function run(args: string[], opts: BiteOptions = {}): Promise console.log(` ${para.key}: syncing state from ${SYNC_SOURCE_PREFIX}${id}, no other peer`); } // The bite node always exits non-zero: doppelganger ends an essential task to stop - // the node once the state import is captured. Success is judged by the info file. + // the node once the state import is captured. Success is judged by readBiteBlock. await runBiteNode( 'doppelganger-parachain', [ @@ -591,16 +602,15 @@ export async function run(args: string[], opts: BiteOptions = {}): Promise const biteBlocks: Record = {}; for (const para of parachains) { const id = String(para.paraId); - const info = path.join(out, 'work', id, 'info.txt'); - const block = fs.existsSync(info) ? fs.readFileSync(info, 'utf-8').trim() : ''; - if (!block) { - const log = path.join(biteLogDir(out), `${id}.log`); - const hint = logTail(log, 3, /not present on the host|error|panic/i); + const log = path.join(biteLogDir(out), `${id}.log`); + const block = readBiteBlock(path.join(out, 'work', id, 'info.txt'), log); + if (block === null) { + const hint = logTail(log, 3, /Block import done|not present on the host|error|panic/i); throw new Error( `para ${id}: bite FAILED (log: ${log})\n${hint.map((l) => ' ' + l).join('\n')}` ); } - biteBlocks[id] = Number(block); + biteBlocks[id] = block; console.log(` para ${id} bitten at block ${block}`); } @@ -621,6 +631,7 @@ export async function run(args: string[], opts: BiteOptions = {}): Promise console.log(` injecting ${Object.keys(headEnv).length} parachain heads over Paras::Heads`); const relayWork = path.join(out, 'work', 'relay'); + const relayLog = path.join(biteLogDir(out), 'relay.log'); fs.mkdirSync(relayWork, { recursive: true }); await runBiteNode( 'doppelganger', @@ -634,19 +645,21 @@ export async function run(args: string[], opts: BiteOptions = {}): Promise ZOMBIE_CHAIN: net.relay.chain, ZOMBIE_RC_EPOCH_DURATION: String(manifest.epochDuration), RUST_LOG: 'doppelganger=info', + // Westend's GRANDPA history carries a forced authority change (#4356716), so no warp + // proof from genesis verifies up to the live head. doppelganger skips the justification + // checks under this variable, as zombie-bite does for Westend. + ...(net.relay.chain === 'westend' ? { ZOMBIE_IS_WESTEND: '1' } : {}), }, - path.join(biteLogDir(out), 'relay.log'), + relayLog, `relay (${net.relay.chain})` ); - const relayInfo = path.join(relayWork, 'info.txt'); - const relayBlock = fs.existsSync(relayInfo) ? fs.readFileSync(relayInfo, 'utf-8').trim() : ''; - if (!relayBlock) { - const log = path.join(biteLogDir(out), 'relay.log'); - const tail = logTail(log, 5); - throw new Error(`relay bite FAILED (log: ${log})\n${tail.map((l) => ' ' + l).join('\n')}`); + const relayBlock = readBiteBlock(path.join(relayWork, 'info.txt'), relayLog); + if (relayBlock === null) { + const tail = logTail(relayLog, 5, /Block import done|error|panic/i); + throw new Error(`relay bite FAILED (log: ${relayLog})\n${tail.map((l) => ' ' + l).join('\n')}`); } - biteBlocks.relay = Number(relayBlock); + biteBlocks.relay = relayBlock; console.log('=== 6/6 packing snapshots ==='); const snapshotBytes: Record = {};