Skip to content

Commit

Permalink
feat(light client): Use wss boot nodes only (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat authored Dec 1, 2024
1 parent 40f8b5f commit 02e778d
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/app/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,32 @@ export class Api {
const smMetadata = getLightClientMetadata(this.#chainType, this.network);
const { chainSpec: relayChainSpec } = await smMetadata.relay.fn();

// Filter non-encrypted boot nodes in production.
const wssRelayChainSpec =
import.meta.env.MODE === 'development'
? relayChainSpec
: this.wssBootNodesOnly(relayChainSpec);

let chain;
if (this.#chainType === 'relay') {
chain = smoldot.addChain({ chainSpec: relayChainSpec });
chain = smoldot.addChain({
chainSpec: wssRelayChainSpec,
});
this.#apiClient = createClient(getSmProvider(chain));
} else {
const { chainSpec: paraChainSpec } = await smMetadata!.para!.fn();
// Filter non-encrypted boot nodes in production.
const wssParaChainSpec =
import.meta.env.MODE === 'development'
? paraChainSpec
: this.wssBootNodesOnly(paraChainSpec);

chain = smoldot.addChain({
chainSpec: paraChainSpec,
chainSpec: this.wssBootNodesOnly(wssParaChainSpec),
potentialRelayChains: [
await smoldot.addChain({ chainSpec: relayChainSpec }),
await smoldot.addChain({
chainSpec: wssRelayChainSpec,
}),
],
});
this.#apiClient = createClient(getSmProvider(chain));
Expand Down Expand Up @@ -261,4 +277,12 @@ export class Api {
this.dispatchEvent(this.ensureEventStatus('disconnected'));
}
}

wssBootNodesOnly(spec: string) {
const filtered = Object.assign({}, JSON.parse(spec));
filtered.bootNodes = filtered.bootNodes.filter((node: string) =>
/\/wss\//.test(node)
);
return JSON.stringify(filtered);
}
}

0 comments on commit 02e778d

Please sign in to comment.