smoldot 2.0.18 → 2.0.19
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.
- package/dist/cjs/internals/bytecode/wasm0.js +1 -1
- package/dist/cjs/internals/bytecode/wasm1.js +1 -1
- package/dist/cjs/internals/bytecode/wasm2.js +1 -1
- package/dist/cjs/internals/client.js +22 -7
- package/dist/cjs/internals/local-instance.d.ts +14 -1
- package/dist/cjs/internals/local-instance.js +16 -11
- package/dist/mjs/internals/bytecode/wasm0.js +1 -1
- package/dist/mjs/internals/bytecode/wasm1.js +1 -1
- package/dist/mjs/internals/bytecode/wasm2.js +1 -1
- package/dist/mjs/internals/client.js +22 -7
- package/dist/mjs/internals/local-instance.d.ts +14 -1
- package/dist/mjs/internals/local-instance.js +16 -11
- package/package.json +1 -1
|
@@ -63,7 +63,8 @@ export function start(options, wasmModule, platformBindings) {
|
|
|
63
63
|
instance: { status: "not-created" },
|
|
64
64
|
chainIds: new WeakMap(),
|
|
65
65
|
connections: new Map(),
|
|
66
|
-
|
|
66
|
+
addChainIdAllocations: [],
|
|
67
|
+
addChainResults: new Map(),
|
|
67
68
|
onExecutorShutdownOrWasmPanic: () => { },
|
|
68
69
|
chains: new Map(),
|
|
69
70
|
};
|
|
@@ -82,10 +83,14 @@ export function start(options, wasmModule, platformBindings) {
|
|
|
82
83
|
};
|
|
83
84
|
state.connections.forEach((connec) => connec.reset());
|
|
84
85
|
state.connections.clear();
|
|
85
|
-
for (const addChainResult of state.
|
|
86
|
+
for (const addChainResult of state.addChainIdAllocations) {
|
|
86
87
|
addChainResult({ success: false, error: "Smoldot has crashed" });
|
|
87
88
|
}
|
|
88
|
-
state.
|
|
89
|
+
state.addChainIdAllocations = [];
|
|
90
|
+
state.addChainResults.forEach((addChainResult) => {
|
|
91
|
+
addChainResult({ success: false, error: "Smoldot has crashed" });
|
|
92
|
+
});
|
|
93
|
+
state.addChainResults.clear();
|
|
89
94
|
for (const chain of Array.from(state.chains.values())) {
|
|
90
95
|
for (const callback of chain.jsonRpcResponsesPromises) {
|
|
91
96
|
callback();
|
|
@@ -108,8 +113,14 @@ export function start(options, wasmModule, platformBindings) {
|
|
|
108
113
|
logCallback(event.level, event.target, event.message);
|
|
109
114
|
break;
|
|
110
115
|
}
|
|
116
|
+
case "add-chain-id-allocated": {
|
|
117
|
+
const callback = state.addChainIdAllocations.shift();
|
|
118
|
+
state.addChainResults.set(event.chainId, callback);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
111
121
|
case "add-chain-result": {
|
|
112
|
-
(state.addChainResults.
|
|
122
|
+
(state.addChainResults.get(event.chainId))(event);
|
|
123
|
+
state.addChainResults.delete(event.chainId);
|
|
113
124
|
break;
|
|
114
125
|
}
|
|
115
126
|
case "json-rpc-responses-non-empty": {
|
|
@@ -287,7 +298,7 @@ export function start(options, wasmModule, platformBindings) {
|
|
|
287
298
|
// Sanitize `databaseContent`.
|
|
288
299
|
if (options.databaseContent !== undefined && typeof options.databaseContent !== 'string')
|
|
289
300
|
throw new AddChainError("`databaseContent` is not a string");
|
|
290
|
-
const promise = new Promise((resolve) => state.
|
|
301
|
+
const promise = new Promise((resolve) => state.addChainIdAllocations.push(resolve));
|
|
291
302
|
state.instance.instance.addChain(options.chainSpec, options.databaseContent || "", potentialRelayChainsIds, !!options.disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions);
|
|
292
303
|
const outcome = yield promise;
|
|
293
304
|
if (!outcome.success)
|
|
@@ -368,10 +379,14 @@ export function start(options, wasmModule, platformBindings) {
|
|
|
368
379
|
state.instance = { status: "destroyed", error: new AlreadyDestroyedError() };
|
|
369
380
|
state.connections.forEach((connec) => connec.reset());
|
|
370
381
|
state.connections.clear();
|
|
371
|
-
for (const addChainResult of state.
|
|
382
|
+
for (const addChainResult of state.addChainIdAllocations) {
|
|
372
383
|
addChainResult({ success: false, error: "Client.terminate() has been called" });
|
|
373
384
|
}
|
|
374
|
-
state.
|
|
385
|
+
state.addChainIdAllocations = [];
|
|
386
|
+
state.addChainResults.forEach((addChainResult) => {
|
|
387
|
+
addChainResult({ success: false, error: "Client.terminate() has been called" });
|
|
388
|
+
});
|
|
389
|
+
state.addChainResults.clear();
|
|
375
390
|
for (const chain of Array.from(state.chains.values())) {
|
|
376
391
|
for (const callback of chain.jsonRpcResponsesPromises) {
|
|
377
392
|
callback();
|
|
@@ -30,11 +30,15 @@ export interface Config {
|
|
|
30
30
|
getRandomValues: (buffer: Uint8Array) => void;
|
|
31
31
|
}
|
|
32
32
|
export type Event = {
|
|
33
|
+
ty: "add-chain-id-allocated";
|
|
34
|
+
chainId: number;
|
|
35
|
+
} | {
|
|
33
36
|
ty: "add-chain-result";
|
|
34
|
-
success: true;
|
|
35
37
|
chainId: number;
|
|
38
|
+
success: true;
|
|
36
39
|
} | {
|
|
37
40
|
ty: "add-chain-result";
|
|
41
|
+
chainId: number;
|
|
38
42
|
success: false;
|
|
39
43
|
error: string;
|
|
40
44
|
} | {
|
|
@@ -92,6 +96,15 @@ export type ParsedMultiaddr = {
|
|
|
92
96
|
export interface Instance {
|
|
93
97
|
request: (request: string, chainId: number) => number;
|
|
94
98
|
peekJsonRpcResponse: (chainId: number) => string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Later generates a `add-chain-id-allocated` event.
|
|
101
|
+
* If this function is called multiple times, the `add-chain-id-allocated` events are generated
|
|
102
|
+
* in the same order as the function calls.
|
|
103
|
+
*
|
|
104
|
+
* Then, later and asynchronously, a `add-chain-result` event is generated in order to
|
|
105
|
+
* indicate whether the initialization was actually successful. If `success` is `false`, then
|
|
106
|
+
* the `chainId` becomes unallocated.
|
|
107
|
+
*/
|
|
95
108
|
addChain: (chainSpec: string, databaseContent: string, potentialRelayChains: number[], disableJsonRpc: boolean, jsonRpcMaxPendingRequests: number, jsonRpcMaxSubscriptions: number) => void;
|
|
96
109
|
removeChain: (chainId: number) => void;
|
|
97
110
|
/**
|
|
@@ -56,6 +56,19 @@ export function startLocalInstance(config, wasmModule, eventCallback) {
|
|
|
56
56
|
state.onShutdownExecutorOrWasmPanic = () => { };
|
|
57
57
|
throw new Error();
|
|
58
58
|
},
|
|
59
|
+
chain_initialized: (chainId, errorMsgPtr, errorMsgLen) => {
|
|
60
|
+
const instance = state.instance;
|
|
61
|
+
const mem = new Uint8Array(instance.exports.memory.buffer);
|
|
62
|
+
errorMsgPtr >>>= 0;
|
|
63
|
+
errorMsgLen >>>= 0;
|
|
64
|
+
if (errorMsgPtr === 0) {
|
|
65
|
+
eventCallback({ ty: "add-chain-result", chainId, success: true });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const errorMsg = buffer.utf8BytesToString(mem, errorMsgPtr, errorMsgLen);
|
|
69
|
+
eventCallback({ ty: "add-chain-result", chainId, success: false, error: errorMsg });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
59
72
|
random_get: (ptr, len) => {
|
|
60
73
|
const instance = state.instance;
|
|
61
74
|
ptr >>>= 0;
|
|
@@ -365,7 +378,8 @@ export function startLocalInstance(config, wasmModule, eventCallback) {
|
|
|
365
378
|
},
|
|
366
379
|
addChain: (chainSpec, databaseContent, potentialRelayChains, disableJsonRpc, jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions) => {
|
|
367
380
|
if (!state.instance) {
|
|
368
|
-
eventCallback({ ty: "add-chain-
|
|
381
|
+
eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
|
|
382
|
+
eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" });
|
|
369
383
|
return;
|
|
370
384
|
}
|
|
371
385
|
// The caller is supposed to avoid this situation.
|
|
@@ -384,16 +398,7 @@ export function startLocalInstance(config, wasmModule, eventCallback) {
|
|
|
384
398
|
delete state.bufferIndices[0];
|
|
385
399
|
delete state.bufferIndices[1];
|
|
386
400
|
delete state.bufferIndices[2];
|
|
387
|
-
|
|
388
|
-
eventCallback({ ty: "add-chain-result", success: true, chainId });
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
const errorMsgLen = state.instance.exports.chain_error_len(chainId) >>> 0;
|
|
392
|
-
const errorMsgPtr = state.instance.exports.chain_error_ptr(chainId) >>> 0;
|
|
393
|
-
const errorMsg = buffer.utf8BytesToString(new Uint8Array(state.instance.exports.memory.buffer), errorMsgPtr, errorMsgLen);
|
|
394
|
-
state.instance.exports.remove_chain(chainId);
|
|
395
|
-
eventCallback({ ty: "add-chain-result", success: false, error: errorMsg });
|
|
396
|
-
}
|
|
401
|
+
eventCallback({ ty: "add-chain-id-allocated", chainId });
|
|
397
402
|
},
|
|
398
403
|
removeChain: (chainId) => {
|
|
399
404
|
if (!state.instance)
|