From 467f62e0831ca2a922bd2242c4aa21951214b8e9 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Sun, 4 Dec 2022 08:52:58 -0500 Subject: [PATCH] chainspec related rpc definitions --- effects/rpc_known_methods.ts | 5 +++ rpc/known/Readme.md | 1 - rpc/known/mod.ts | 1 + rpc/known/sync.ts | 71 ++++++++++++++++++++++++++++++++++++ rpc/known/system.ts | 6 +++ 5 files changed, 83 insertions(+), 1 deletion(-) delete mode 100644 rpc/known/Readme.md create mode 100644 rpc/known/sync.ts diff --git a/effects/rpc_known_methods.ts b/effects/rpc_known_methods.ts index 5dc397dc8..0092b1452 100644 --- a/effects/rpc_known_methods.ts +++ b/effects/rpc_known_methods.ts @@ -52,3 +52,8 @@ export namespace payment { "payment_queryInfo", ) } +export namespace sync { + export namespace state { + export const genSyncSpec = rpcCall<[boolean], known.ChainSpec>("sync_state_genSyncSpec") + } +} diff --git a/rpc/known/Readme.md b/rpc/known/Readme.md deleted file mode 100644 index e15cc1f3f..000000000 --- a/rpc/known/Readme.md +++ /dev/null @@ -1 +0,0 @@ -# TODO: integrate this dir into RPC re-implementation dir diff --git a/rpc/known/mod.ts b/rpc/known/mod.ts index 93bab0f2d..5f07cf146 100644 --- a/rpc/known/mod.ts +++ b/rpc/known/mod.ts @@ -13,5 +13,6 @@ export * from "./payment.ts" export * as smoldot from "./smoldot.ts" export * from "./state.ts" export * from "./statemigration.ts" +export * from "./sync.ts" export * from "./system.ts" export * from "./utils.ts" diff --git a/rpc/known/sync.ts b/rpc/known/sync.ts new file mode 100644 index 000000000..79c8c9bb5 --- /dev/null +++ b/rpc/known/sync.ts @@ -0,0 +1,71 @@ +import { ChainType } from "./system.ts" +import { Hash, Hex, RpcResult } from "./utils.ts" + +// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L161 +/** A configuration of a client. Does not include runtime storage initialization. */ +export interface ChainSpec { + // https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L34 + genesis: GenesisSource + name: string + id: string + chainType: ChainType + bootNodes: string[] + telemetryEndpoints: null | [string, number][] + protocolId: null | string + /** + * Arbitrary string. Nodes will only synchronize with other nodes that have the same value + * in their `fork_id`. This can be used in order to segregate nodes in cases when multiple + * chains have the same genesis hash. + */ + forkId?: string + properties?: { + ss58Format?: number + tokenDecimals: number + tokenSymbol: string + } + /** + * Mapping from `block_number` to `wasm_code`. + * + * The given `wasm_code` will be used to substitute the on-chain wasm code starting with the + * given block number until the `spec_version` on chain changes. + */ + codeSubstitutes: Record + // Extensions, flattened into this structure by Serde: https://github.com/paritytech/substrate/blob/409167ef/bin/node/cli/src/chain_spec.rs#L55 + /** Block numbers with known hashes. */ + forkBlocks: null | string + /** Known bad block hashes. */ + badBlocks: null | Hash[] + /** The light sync state extension used by the sync-state rpc. */ + lightSyncState: LightSyncState +} + +// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L34 +export interface GenesisSource { + raw: RawGenesis +} + +// https://github.com/paritytech/substrate/blob/a7ba55d3/client/chain-spec/src/chain_spec.rs#L142 +/** Raw storage content for genesis block. */ +export interface RawGenesis { + top: Hex[] + childrenDefault: Hex[] +} + +// https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L111 +export interface LightSyncState { + /** The header of the best finalized block. */ + finalizedBlockHeader: Hex + /** The epoch changes tree for babe. */ + babeEpochChanges: Hex + /** The babe weight of the finalized block. */ + babeFinalizedBlockWeight: number + /** The authority set for grandpa. */ + grandpaAuthoritySet: Hex +} + +// https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L128 +export type SyncRpc = { + // https://github.com/paritytech/substrate/blob/eddf8883/client/sync-state-rpc/src/lib.rs#L131 + /** Returns the JSON serialized chainspec running the node, with a sync state. */ + system_gen_sync_spec(raw: boolean): RpcResult +} diff --git a/rpc/known/system.ts b/rpc/known/system.ts index ea2ee2451..e1210971d 100644 --- a/rpc/known/system.ts +++ b/rpc/known/system.ts @@ -1,6 +1,12 @@ import { Hash, RpcResult, SerdeEnum } from "./utils.ts" // https://github.com/paritytech/substrate/blob/57e3486/client/chain-spec/src/lib.rs#L198 +/** + * The type of a chain. + * + * This can be used by tools to determine the type of a chain for displaying + * additional information or enabling additional features. + */ export type ChainType = SerdeEnum<{ /** A development chain that runs mainly on one node. */ Development: void