@typeberry/lib 0.6.0-4df87ee → 0.6.0-a13ff8b
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/package.json +1 -1
- package/packages/workers/api-node/config.d.ts +0 -9
- package/packages/workers/api-node/config.d.ts.map +1 -1
- package/packages/workers/api-node/config.js +0 -10
- package/packages/workers/api-node/protocol.d.ts.map +1 -1
- package/packages/workers/api-node/protocol.js +3 -5
- package/packages/workers/api-node/config.test.d.ts +0 -2
- package/packages/workers/api-node/config.test.d.ts.map +0 -1
- package/packages/workers/api-node/config.test.js +0 -41
package/package.json
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { MessagePort } from "node:worker_threads";
|
|
2
1
|
import { type Decode, type Encode } from "#@typeberry/codec";
|
|
3
2
|
import { ChainSpec } from "#@typeberry/config";
|
|
4
3
|
import { type BlocksDb, type RootDb, type SerializedStatesDb } from "#@typeberry/database";
|
|
@@ -38,14 +37,6 @@ export type TransferableConfig = {
|
|
|
38
37
|
dbPath: string;
|
|
39
38
|
workerPorts: [string, TransferablePort][];
|
|
40
39
|
};
|
|
41
|
-
/**
|
|
42
|
-
* Collect the transferable objects (communication ports) embedded in a config.
|
|
43
|
-
*
|
|
44
|
-
* `MessagePort`s can only be transferred, not structurally cloned, so they have to
|
|
45
|
-
* be listed in the `postMessage` transfer list. Omitting them results in a
|
|
46
|
-
* `DataCloneError`.
|
|
47
|
-
*/
|
|
48
|
-
export declare function configTransferList(config: TransferableConfig): MessagePort[];
|
|
49
40
|
/**
|
|
50
41
|
* In-memory (direct) worker using serialized state database.
|
|
51
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/api-node/config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/api-node/config.ts"],"names":[],"mappings":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
63
|
-
* `MessagePort`s can only be transferred, not structurally cloned, so they have to
|
|
64
|
-
* be listed in the `postMessage` transfer list. Omitting them results in a
|
|
65
|
-
* `DataCloneError`.
|
|
66
|
-
*/
|
|
67
|
-
export function configTransferList(config) {
|
|
68
|
-
return config.workerPorts.map(([, transferable]) => transferable.port);
|
|
69
|
-
}
|
|
70
60
|
/**
|
|
71
61
|
* In-memory (direct) worker using serialized state database.
|
|
72
62
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/api-node/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/api-node/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAMxE,yCAAyC;AACzC,oBAAY,qBAAqB;IAC/B,2DAA2D;IAC3D,iBAAiB,IAAI;IACrB,sCAAsC;IACtC,MAAM,IAAI;CACX;AAED,M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
|
|
|
3
3
|
import { Level, Logger } from "#@typeberry/logger";
|
|
4
4
|
import { assertNever } from "#@typeberry/utils";
|
|
5
5
|
import { Channel } from "#@typeberry/workers-api";
|
|
6
|
-
import {
|
|
6
|
+
import { LmdbWorkerConfig } from "./config.js";
|
|
7
7
|
import { logHeapLimit } from "./host-environment.js";
|
|
8
8
|
import { ThreadPort } from "./port.js";
|
|
9
9
|
const logger = Logger.new(import.meta.filename, "workers");
|
|
@@ -38,10 +38,8 @@ export function spawnWorker(protocol, bootstrapPath, config, paramsEncoder) {
|
|
|
38
38
|
config: config.intoTransferable(paramsEncoder),
|
|
39
39
|
};
|
|
40
40
|
logger.trace `(${protocol.name}) <-- config`;
|
|
41
|
-
// send the config down to the worker
|
|
42
|
-
|
|
43
|
-
// otherwise structured clone fails with a `DataCloneError`.
|
|
44
|
-
worker.postMessage(msg, [msg.parentPort, ...configTransferList(msg.config)]);
|
|
41
|
+
// send the config down to the worker
|
|
42
|
+
worker.postMessage(msg, [msg.parentPort]);
|
|
45
43
|
const workerFinished = new Promise((resolve, reject) => {
|
|
46
44
|
worker.once("error", reject);
|
|
47
45
|
worker.once("exit", (exitCode) => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../../../../packages/workers/api-node/config.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import { MessageChannel } from "node:worker_threads";
|
|
4
|
-
import { codec } from "#@typeberry/codec";
|
|
5
|
-
import { tinyChainSpec } from "#@typeberry/config";
|
|
6
|
-
import { Blake2b } from "#@typeberry/hash";
|
|
7
|
-
import { tryAsU32 } from "#@typeberry/numbers";
|
|
8
|
-
import { configTransferList, LmdbWorkerConfig } from "./config.js";
|
|
9
|
-
import { ThreadPort } from "./port.js";
|
|
10
|
-
const spec = tinyChainSpec;
|
|
11
|
-
describe("LmdbWorkerConfig transfer list", () => {
|
|
12
|
-
it("surfaces embedded worker ports so they can be transferred", async () => {
|
|
13
|
-
const blake2b = await Blake2b.createHasher();
|
|
14
|
-
const [portA, portB] = ThreadPort.pair(spec);
|
|
15
|
-
const config = LmdbWorkerConfig.new({
|
|
16
|
-
nodeName: "node",
|
|
17
|
-
chainSpec: spec,
|
|
18
|
-
workerParams: tryAsU32(7),
|
|
19
|
-
dbPath: "db",
|
|
20
|
-
blake2b,
|
|
21
|
-
ports: new Map([["authorship-network", portA]]),
|
|
22
|
-
});
|
|
23
|
-
const transferable = config.intoTransferable(codec.varU32);
|
|
24
|
-
const transferList = configTransferList(transferable);
|
|
25
|
-
// the single embedded comms port must be reported for transfer
|
|
26
|
-
assert.strictEqual(transferList.length, 1);
|
|
27
|
-
const sink = new MessageChannel();
|
|
28
|
-
try {
|
|
29
|
-
// reproduces the bug: a config carrying a port cannot be cloned without
|
|
30
|
-
// listing that port in the transfer list.
|
|
31
|
-
assert.throws(() => sink.port1.postMessage(transferable, []), /transfer/i);
|
|
32
|
-
// with the ports surfaced, posting succeeds.
|
|
33
|
-
assert.doesNotThrow(() => sink.port1.postMessage(transferable, transferList));
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
sink.port1.close();
|
|
37
|
-
sink.port2.close();
|
|
38
|
-
portB.close();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|