Skip to content

Commit

Permalink
smoldot provider config validation #64
Browse files Browse the repository at this point in the history
  • Loading branch information
XY-Wang committed Apr 9, 2024
1 parent ae127a1 commit 3a2bc1a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
3 changes: 0 additions & 3 deletions packages/server/config/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
4 changes: 3 additions & 1 deletion packages/server/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/services/networking/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions packages/server/src/testing/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const mockConfigRelayMismatch: ServiceConfiguration = {
id: 'urn:ocn:rococo:0',
provider: {
type: 'smoldot',
name: 'local',
spec: './chain-specs/polkadot.json',
},
},
Expand Down Expand Up @@ -56,7 +55,6 @@ export const mockConfigLC: ServiceConfiguration = {
relay: 'urn:ocn:local:0',
provider: {
type: 'smoldot',
name: 'asset-hub',
spec: './chain-specs/ah.json',
},
},
Expand All @@ -65,7 +63,6 @@ export const mockConfigLC: ServiceConfiguration = {
relay: 'urn:ocn:local:0',
provider: {
type: 'smoldot',
name: 'astar',
spec: './chain-specs/astar.json',
},
},
Expand Down Expand Up @@ -125,7 +122,6 @@ export const mockConfigMixed: ServiceConfiguration = {
relay: 'urn:ocn:local:0',
provider: {
type: 'smoldot',
name: 'interlay',
spec: './chain-specs/interlay.json',
},
},
Expand All @@ -147,15 +143,13 @@ export const mockConfigRelayLast: ServiceConfiguration = {
relay: 'urn:ocn:local:0',
provider: {
type: 'smoldot',
name: 'shiden',
spec: './chain-specs/shiden.json',
},
},
{
id: 'urn:ocn:local:0',
provider: {
type: 'smoldot',
name: 'kusama',
spec: './chain-specs/kusama.json',
},
},
Expand Down

0 comments on commit 3a2bc1a

Please sign in to comment.