From 3a2bc1a6ed078d3d4cc122e5374c5756be08dbf8 Mon Sep 17 00:00:00 2001 From: Xueying Wang Date: Tue, 9 Apr 2024 12:34:20 +0200 Subject: [PATCH] smoldot provider config validation #64 --- packages/server/config/dev.toml | 3 --- packages/server/src/services/config.ts | 4 +++- packages/server/src/services/networking/connector.ts | 4 ++++ packages/server/src/testing/configs.ts | 6 ------ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/server/config/dev.toml b/packages/server/config/dev.toml index 132ad416..16b27096 100644 --- a/packages/server/config/dev.toml +++ b/packages/server/config/dev.toml @@ -3,7 +3,6 @@ id = "urn:ocn:local:0" [networks.provider] # type = "smoldot" - # name = "rococo_local_testnet" # spec = "./chain-specs/rococo-local-relay.json" type = "rpc" url = "ws://127.0.0.1:9900" @@ -14,7 +13,6 @@ relay = "urn:ocn:local:0" [networks.provider] # type = "smoldot" - # name = "asset-hub-local" # spec = "./chain-specs/assethub-local.json" type = "rpc" url = "ws://127.0.0.1:9910" @@ -25,7 +23,6 @@ relay = "urn:ocn:local:0" [networks.provider] # type = "smoldot" - # name = "shibuya-local" # spec = "./chain-specs/shibuya-local.json" type = "rpc" url = "ws://127.0.0.1:9920" diff --git a/packages/server/src/services/config.ts b/packages/server/src/services/config.ts index 0cae5297..798c8f27 100644 --- a/packages/server/src/services/config.ts +++ b/packages/server/src/services/config.ts @@ -13,9 +13,11 @@ const $RpcProvider = z.object({ url: z.string().min(1), }); +const wellKnownChains = ['polkadot', 'ksmcc3', 'rococo_v2_2', 'westend2'] as const; + const $SmoldotProvider = z.object({ type: z.literal('smoldot'), - name: z.string().min(1).optional(), + name: z.enum(wellKnownChains).optional(), spec: z.string().min(1).optional(), }); diff --git a/packages/server/src/services/networking/connector.ts b/packages/server/src/services/networking/connector.ts index 12baaaa7..4c9f9e01 100644 --- a/packages/server/src/services/networking/connector.ts +++ b/packages/server/src/services/networking/connector.ts @@ -95,6 +95,10 @@ export default class Connector { #registerSmoldotRelay(id: string, name?: string, spec?: string) { this.#log.info('Register relay smoldot provider: %s', id); + if (name === undefined && spec === undefined) { + throw new Error(`Please, specify either 'name' or 'spec' in ${id} smoldot configuration`); + } + const key = Object.values(Smoldot.WellKnownChain).find((c) => c === name); if (key) { diff --git a/packages/server/src/testing/configs.ts b/packages/server/src/testing/configs.ts index 126445f1..d07386b5 100644 --- a/packages/server/src/testing/configs.ts +++ b/packages/server/src/testing/configs.ts @@ -26,7 +26,6 @@ export const mockConfigRelayMismatch: ServiceConfiguration = { id: 'urn:ocn:rococo:0', provider: { type: 'smoldot', - name: 'local', spec: './chain-specs/polkadot.json', }, }, @@ -56,7 +55,6 @@ export const mockConfigLC: ServiceConfiguration = { relay: 'urn:ocn:local:0', provider: { type: 'smoldot', - name: 'asset-hub', spec: './chain-specs/ah.json', }, }, @@ -65,7 +63,6 @@ export const mockConfigLC: ServiceConfiguration = { relay: 'urn:ocn:local:0', provider: { type: 'smoldot', - name: 'astar', spec: './chain-specs/astar.json', }, }, @@ -125,7 +122,6 @@ export const mockConfigMixed: ServiceConfiguration = { relay: 'urn:ocn:local:0', provider: { type: 'smoldot', - name: 'interlay', spec: './chain-specs/interlay.json', }, }, @@ -147,7 +143,6 @@ export const mockConfigRelayLast: ServiceConfiguration = { relay: 'urn:ocn:local:0', provider: { type: 'smoldot', - name: 'shiden', spec: './chain-specs/shiden.json', }, }, @@ -155,7 +150,6 @@ export const mockConfigRelayLast: ServiceConfiguration = { id: 'urn:ocn:local:0', provider: { type: 'smoldot', - name: 'kusama', spec: './chain-specs/kusama.json', }, },