smoldot 3.0.1-dev.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -297,6 +297,8 @@ export function start(options, wasmModule, platformBindings) {
297
297
  }
298
298
  // Sanitize `statementStore`.
299
299
  let statementStoreMaxSeenStatements = 0;
300
+ let statementStoreFalsePositiveRate = 0.0;
301
+ let statementStoreAffinityUpdateIntervalMs = 0;
300
302
  if (options.statementStore !== undefined) {
301
303
  statementStoreMaxSeenStatements = options.statementStore.maxSeenStatements === undefined ? 65536 : options.statementStore.maxSeenStatements;
302
304
  statementStoreMaxSeenStatements = Math.floor(statementStoreMaxSeenStatements);
@@ -306,12 +308,24 @@ export function start(options, wasmModule, platformBindings) {
306
308
  if (statementStoreMaxSeenStatements > 0xffffffff) {
307
309
  statementStoreMaxSeenStatements = 0xffffffff;
308
310
  }
311
+ statementStoreFalsePositiveRate = options.statementStore.falsePositiveRate === undefined ? 0.01 : options.statementStore.falsePositiveRate;
312
+ if (statementStoreFalsePositiveRate <= 0.0 || statementStoreFalsePositiveRate >= 1.0 || isNaN(statementStoreFalsePositiveRate)) {
313
+ throw new AddChainError("Invalid value for `statementStore.falsePositiveRate`");
314
+ }
315
+ statementStoreAffinityUpdateIntervalMs = options.statementStore.affinityUpdateIntervalMs === undefined ? 1000 : options.statementStore.affinityUpdateIntervalMs;
316
+ statementStoreAffinityUpdateIntervalMs = Math.floor(statementStoreAffinityUpdateIntervalMs);
317
+ if (statementStoreAffinityUpdateIntervalMs <= 0 || isNaN(statementStoreAffinityUpdateIntervalMs)) {
318
+ throw new AddChainError("Invalid value for `statementStore.affinityUpdateIntervalMs`");
319
+ }
320
+ if (statementStoreAffinityUpdateIntervalMs > 0xffffffff) {
321
+ statementStoreAffinityUpdateIntervalMs = 0xffffffff;
322
+ }
309
323
  }
310
324
  // Sanitize `databaseContent`.
311
325
  if (options.databaseContent !== undefined && typeof options.databaseContent !== 'string')
312
326
  throw new AddChainError("`databaseContent` is not a string");
313
327
  const promise = new Promise((resolve) => state.addChainIdAllocations.push(resolve));
314
- state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements);
328
+ state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs);
315
329
  const outcome = yield promise;
316
330
  if (!outcome.success)
317
331
  throw new AddChainError(outcome.error);
@@ -105,7 +105,7 @@ export interface Instance {
105
105
  * indicate whether the initialization was actually successful. If `success` is `false`, then
106
106
  * the `chainId` becomes unallocated.
107
107
  */
108
- addChain: (chainSpec: string, databaseContent: string, potentialRelayChains: number[], disableJsonRpc: boolean, jsonRpcMaxPendingRequests: number, jsonRpcMaxSubscriptions: number, statementStoreMaxSeenStatements: number) => void;
108
+ addChain: (chainSpec: string, databaseContent: string, potentialRelayChains: number[], disableJsonRpc: boolean, jsonRpcMaxPendingRequests: number, jsonRpcMaxSubscriptions: number, statementStoreMaxSeenStatements: number, statementStoreFalsePositiveRate: number, statementStoreAffinityUpdateIntervalMs: number) => void;
109
109
  removeChain: (chainId: number) => void;
110
110
  /**
111
111
  * Notifies the background executor that it should stop. Once it has effectively stopped,
@@ -383,7 +383,7 @@ export function startLocalInstance(config, wasmModule, eventCallback) {
383
383
  return null;
384
384
  }
385
385
  },
386
- addChain: (chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements) => {
386
+ addChain: (chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs) => {
387
387
  if (!state.instance) {
388
388
  eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
389
389
  eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" });
@@ -403,7 +403,7 @@ export function startLocalInstance(config, wasmModule, eventCallback) {
403
403
  state.bufferIndices[2] = potentialRelayChainsEncoded;
404
404
  let chainId;
405
405
  try {
406
- chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2, statementStoreMaxSeenStatements);
406
+ chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs);
407
407
  }
408
408
  catch (_error) {
409
409
  eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
@@ -144,9 +144,9 @@ export function connectToInstanceServer(config) {
144
144
  config.eventCallback(message);
145
145
  };
146
146
  return {
147
- addChain(chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements) {
147
+ addChain(chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs) {
148
148
  return __awaiter(this, void 0, void 0, function* () {
149
- const msg = { ty: "add-chain", chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements };
149
+ const msg = { ty: "add-chain", chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs };
150
150
  portToServer.postMessage(msg);
151
151
  });
152
152
  },
@@ -283,7 +283,7 @@ export function startInstanceServer(config, initPortToClient) {
283
283
  const message = messageEvent.data;
284
284
  switch (message.ty) {
285
285
  case "add-chain": {
286
- state.instance.addChain(message.chainSpec, message.databaseContent, message.potentialRelayChains, message.disableJsonRpc, message.jsonRpcMaxPendingRequests, message.jsonRpcMaxSubscriptions, message.statementStoreMaxSeenStatements);
286
+ state.instance.addChain(message.chainSpec, message.databaseContent, message.potentialRelayChains, message.disableJsonRpc, message.jsonRpcMaxPendingRequests, message.jsonRpcMaxSubscriptions, message.statementStoreMaxSeenStatements, message.statementStoreFalsePositiveRate, message.statementStoreAffinityUpdateIntervalMs);
287
287
  break;
288
288
  }
289
289
  case "remove-chain": {
@@ -402,8 +402,17 @@ export interface AddChainOptions {
402
402
  * If set, enables the Statement Store protocol on this chain.
403
403
  *
404
404
  * `maxSeenStatements` is the maximum number of seen statements to cache. Defaults to 65536.
405
+ *
406
+ * `falsePositiveRate` is the bloom filter false positive rate used for topic affinity.
407
+ * Lower values reduce bandwidth from irrelevant statements but reveal more about
408
+ * subscription interests to peers. Defaults to 0.01 (1%).
409
+ *
410
+ * `affinityUpdateIntervalMs` is the debounce interval in milliseconds for sending
411
+ * affinity filter updates to peers after subscription changes. Defaults to 1000.
405
412
  */
406
413
  statementStore?: {
407
414
  maxSeenStatements?: number;
415
+ falsePositiveRate?: number;
416
+ affinityUpdateIntervalMs?: number;
408
417
  };
409
418
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoldot",
3
- "version": "3.0.1-dev.0",
3
+ "version": "3.1.1",
4
4
  "description": "Light client that connects to Polkadot and Substrate-based blockchains",
5
5
  "contributors": [
6
6
  "Parity Technologies <admin@parity.io>",
@@ -67,8 +67,6 @@
67
67
  "buildModules": "tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && bash fix-package-type.sh",
68
68
  "prepack": "node prepare.mjs --release && rm -rf ./dist && npm run buildModules",
69
69
  "build": "node prepare.mjs --release && rm -rf ./dist && npm run buildModules",
70
- "probe:parachain-restart": "node ./scripts/parachain-finalized-database-probe.mjs",
71
- "probe:parachain-restart:bench": "node ./scripts/parachain-finalized-database-benchmark.mjs",
72
70
  "start": "node prepare.mjs --debug && rm -rf ./dist && npm run buildModules && node demo/demo.mjs",
73
71
  "test": "node prepare.mjs --debug && rm -rf ./dist && npm run buildModules && deno run ./dist/mjs/index-deno.js && ava --timeout=2m --concurrency 2 --no-worker-threads",
74
72
  "doc": "node prepare.mjs --debug && typedoc --basePath ./src --out ./dist/doc --treatWarningsAsErrors ./src/index-browser.ts"