Skip to content

Commit

Permalink
Throw an AddChainError if the database isn't a string (#861)
Browse files Browse the repository at this point in the history
* Throw an `AddChainError` if the database isn't a string

* PR link

* Accept undefined database
  • Loading branch information
tomaka authored Jul 8, 2023
1 parent fbcb60f commit 68e20c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Blocks are now reported to `chain_subscribeAllHeads` and `chain_subscribeNewHeads` subscribers only after they have been put in the cache, preventing race conditions where JSON-RPC clients suffer from a cache miss if they ask information about these blocks too quickly. ([#854](https://github.com/smol-dot/smoldot/pull/854))
- Runtime updates are now always reported to `state_subscribeRuntimeVersion` subscribers immediately after the `chain_subscribeNewHeads` notification corresponding to the block containing the runtime update. They were previously reported in a pseudo-random order. ([#854](https://github.com/smol-dot/smoldot/pull/854))
- All the storage subscriptions made using `state_subscribeStorage` are now queried together into a single networking request per block, instead of sending one networking query per storage key and per subscription. ([#854](https://github.com/smol-dot/smoldot/pull/854))
- An `AddChainError` is now thrown if the `databaseContent` parameter is not of type `string`. The database was previously silently ignored. ([#861](https://github.com/smol-dot/smoldot/pull/861))

## 1.0.11 - 2023-06-25

Expand Down
6 changes: 5 additions & 1 deletion wasm-node/javascript/src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,15 @@ export function start(options: ClientOptions, wasmModule: SmoldotBytecode | Prom
jsonRpcMaxSubscriptions = 0xffffffff
}

// Sanitize `databaseContent`.
if (options.databaseContent !== undefined && typeof options.databaseContent !== 'string')
throw new AddChainError("`databaseContent` is not a string");

const promise = new Promise<{ success: true, chainId: number } | { success: false, error: string }>((resolve) => state.addChainResults.push(resolve));

state.instance.instance.addChain(
options.chainSpec,
typeof options.databaseContent === 'string' ? options.databaseContent : "",
options.databaseContent || "",
potentialRelayChainsIds,
!!options.disableJsonRpc,
jsonRpcMaxPendingRequests,
Expand Down

0 comments on commit 68e20c2

Please sign in to comment.