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.
@@ -300,6 +300,8 @@ function start(options, wasmModule, platformBindings) {
300
300
  }
301
301
  // Sanitize `statementStore`.
302
302
  let statementStoreMaxSeenStatements = 0;
303
+ let statementStoreFalsePositiveRate = 0.0;
304
+ let statementStoreAffinityUpdateIntervalMs = 0;
303
305
  if (options.statementStore !== undefined) {
304
306
  statementStoreMaxSeenStatements = options.statementStore.maxSeenStatements === undefined ? 65536 : options.statementStore.maxSeenStatements;
305
307
  statementStoreMaxSeenStatements = Math.floor(statementStoreMaxSeenStatements);
@@ -309,12 +311,24 @@ function start(options, wasmModule, platformBindings) {
309
311
  if (statementStoreMaxSeenStatements > 0xffffffff) {
310
312
  statementStoreMaxSeenStatements = 0xffffffff;
311
313
  }
314
+ statementStoreFalsePositiveRate = options.statementStore.falsePositiveRate === undefined ? 0.01 : options.statementStore.falsePositiveRate;
315
+ if (statementStoreFalsePositiveRate <= 0.0 || statementStoreFalsePositiveRate >= 1.0 || isNaN(statementStoreFalsePositiveRate)) {
316
+ throw new public_types_js_1.AddChainError("Invalid value for `statementStore.falsePositiveRate`");
317
+ }
318
+ statementStoreAffinityUpdateIntervalMs = options.statementStore.affinityUpdateIntervalMs === undefined ? 1000 : options.statementStore.affinityUpdateIntervalMs;
319
+ statementStoreAffinityUpdateIntervalMs = Math.floor(statementStoreAffinityUpdateIntervalMs);
320
+ if (statementStoreAffinityUpdateIntervalMs <= 0 || isNaN(statementStoreAffinityUpdateIntervalMs)) {
321
+ throw new public_types_js_1.AddChainError("Invalid value for `statementStore.affinityUpdateIntervalMs`");
322
+ }
323
+ if (statementStoreAffinityUpdateIntervalMs > 0xffffffff) {
324
+ statementStoreAffinityUpdateIntervalMs = 0xffffffff;
325
+ }
312
326
  }
313
327
  // Sanitize `databaseContent`.
314
328
  if (options.databaseContent !== undefined && typeof options.databaseContent !== 'string')
315
329
  throw new public_types_js_1.AddChainError("`databaseContent` is not a string");
316
330
  const promise = new Promise((resolve) => state.addChainIdAllocations.push(resolve));
317
- state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements);
331
+ state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs);
318
332
  const outcome = yield promise;
319
333
  if (!outcome.success)
320
334
  throw new public_types_js_1.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,
@@ -386,7 +386,7 @@ function startLocalInstance(config, wasmModule, eventCallback) {
386
386
  return null;
387
387
  }
388
388
  },
389
- addChain: (chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements) => {
389
+ addChain: (chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs) => {
390
390
  if (!state.instance) {
391
391
  eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
392
392
  eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" });
@@ -406,7 +406,7 @@ function startLocalInstance(config, wasmModule, eventCallback) {
406
406
  state.bufferIndices[2] = potentialRelayChainsEncoded;
407
407
  let chainId;
408
408
  try {
409
- chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2, statementStoreMaxSeenStatements);
409
+ chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs);
410
410
  }
411
411
  catch (_error) {
412
412
  eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
@@ -147,9 +147,9 @@ function connectToInstanceServer(config) {
147
147
  config.eventCallback(message);
148
148
  };
149
149
  return {
150
- addChain(chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements) {
150
+ addChain(chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs) {
151
151
  return __awaiter(this, void 0, void 0, function* () {
152
- const msg = { ty: "add-chain", chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements };
152
+ const msg = { ty: "add-chain", chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, statementStoreMaxSeenStatements, statementStoreFalsePositiveRate, statementStoreAffinityUpdateIntervalMs };
153
153
  portToServer.postMessage(msg);
154
154
  });
155
155
  },
@@ -287,7 +287,7 @@ function startInstanceServer(config, initPortToClient) {
287
287
  const message = messageEvent.data;
288
288
  switch (message.ty) {
289
289
  case "add-chain": {
290
- state.instance.addChain(message.chainSpec, message.databaseContent, message.potentialRelayChains, message.disableJsonRpc, message.jsonRpcMaxPendingRequests, message.jsonRpcMaxSubscriptions, message.statementStoreMaxSeenStatements);
290
+ state.instance.addChain(message.chainSpec, message.databaseContent, message.potentialRelayChains, message.disableJsonRpc, message.jsonRpcMaxPendingRequests, message.jsonRpcMaxSubscriptions, message.statementStoreMaxSeenStatements, message.statementStoreFalsePositiveRate, message.statementStoreAffinityUpdateIntervalMs);
291
291
  break;
292
292
  }
293
293
  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
  }