@aztec/foundation 0.83.1 → 0.84.0

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.
Files changed (115) hide show
  1. package/dest/config/env_var.d.ts +1 -1
  2. package/dest/config/env_var.d.ts.map +1 -1
  3. package/dest/index.d.ts +0 -2
  4. package/dest/index.d.ts.map +1 -1
  5. package/dest/index.js +0 -2
  6. package/dest/log/index.d.ts +3 -4
  7. package/dest/log/index.d.ts.map +1 -1
  8. package/dest/log/index.js +3 -4
  9. package/dest/log/noir_debug_log_util.d.ts +14 -0
  10. package/dest/log/noir_debug_log_util.d.ts.map +1 -0
  11. package/dest/log/noir_debug_log_util.js +14 -0
  12. package/dest/transport/index.d.ts +0 -1
  13. package/dest/transport/index.d.ts.map +1 -1
  14. package/dest/transport/index.js +0 -1
  15. package/package.json +2 -4
  16. package/src/config/env_var.ts +1 -1
  17. package/src/index.ts +0 -2
  18. package/src/log/index.ts +3 -4
  19. package/src/log/noir_debug_log_util.ts +21 -0
  20. package/src/transport/index.ts +0 -1
  21. package/dest/log/debug.d.ts +0 -56
  22. package/dest/log/debug.d.ts.map +0 -1
  23. package/dest/log/debug.js +0 -75
  24. package/dest/log/log_history.d.ts +0 -31
  25. package/dest/log/log_history.d.ts.map +0 -1
  26. package/dest/log/log_history.js +0 -38
  27. package/dest/transport/browser/index.d.ts +0 -5
  28. package/dest/transport/browser/index.d.ts.map +0 -1
  29. package/dest/transport/browser/index.js +0 -4
  30. package/dest/transport/browser/message_port_socket.d.ts +0 -37
  31. package/dest/transport/browser/message_port_socket.d.ts.map +0 -1
  32. package/dest/transport/browser/message_port_socket.js +0 -42
  33. package/dest/transport/browser/shared_worker_connector.d.ts +0 -19
  34. package/dest/transport/browser/shared_worker_connector.d.ts.map +0 -1
  35. package/dest/transport/browser/shared_worker_connector.js +0 -19
  36. package/dest/transport/browser/shared_worker_listener.d.ts +0 -38
  37. package/dest/transport/browser/shared_worker_listener.d.ts.map +0 -1
  38. package/dest/transport/browser/shared_worker_listener.js +0 -33
  39. package/dest/transport/browser/worker_connector.d.ts +0 -26
  40. package/dest/transport/browser/worker_connector.d.ts.map +0 -1
  41. package/dest/transport/browser/worker_connector.js +0 -30
  42. package/dest/transport/browser/worker_listener.d.ts +0 -39
  43. package/dest/transport/browser/worker_listener.d.ts.map +0 -1
  44. package/dest/transport/browser/worker_listener.js +0 -35
  45. package/dest/wasm/empty_wasi_sdk.d.ts +0 -130
  46. package/dest/wasm/empty_wasi_sdk.d.ts.map +0 -1
  47. package/dest/wasm/empty_wasi_sdk.js +0 -148
  48. package/dest/wasm/index.d.ts +0 -2
  49. package/dest/wasm/index.d.ts.map +0 -1
  50. package/dest/wasm/index.js +0 -1
  51. package/dest/wasm/wasm_module.d.ts +0 -136
  52. package/dest/wasm/wasm_module.d.ts.map +0 -1
  53. package/dest/wasm/wasm_module.js +0 -196
  54. package/dest/worker/browser/index.d.ts +0 -3
  55. package/dest/worker/browser/index.d.ts.map +0 -1
  56. package/dest/worker/browser/index.js +0 -2
  57. package/dest/worker/browser/start_web_module.d.ts +0 -7
  58. package/dest/worker/browser/start_web_module.d.ts.map +0 -1
  59. package/dest/worker/browser/start_web_module.js +0 -27
  60. package/dest/worker/browser/web_data_store.d.ts +0 -24
  61. package/dest/worker/browser/web_data_store.d.ts.map +0 -1
  62. package/dest/worker/browser/web_data_store.js +0 -29
  63. package/dest/worker/browser/web_worker.d.ts +0 -10
  64. package/dest/worker/browser/web_worker.d.ts.map +0 -1
  65. package/dest/worker/browser/web_worker.js +0 -25
  66. package/dest/worker/data_store.d.ts +0 -21
  67. package/dest/worker/data_store.d.ts.map +0 -1
  68. package/dest/worker/data_store.js +0 -3
  69. package/dest/worker/index.d.ts +0 -3
  70. package/dest/worker/index.d.ts.map +0 -1
  71. package/dest/worker/index.js +0 -1
  72. package/dest/worker/node/index.d.ts +0 -3
  73. package/dest/worker/node/index.d.ts.map +0 -1
  74. package/dest/worker/node/index.js +0 -2
  75. package/dest/worker/node/node_data_store.d.ts +0 -13
  76. package/dest/worker/node/node_data_store.d.ts.map +0 -1
  77. package/dest/worker/node/node_data_store.js +0 -20
  78. package/dest/worker/node/node_worker.d.ts +0 -6
  79. package/dest/worker/node/node_worker.d.ts.map +0 -1
  80. package/dest/worker/node/node_worker.js +0 -22
  81. package/dest/worker/node/start_node_module.d.ts +0 -7
  82. package/dest/worker/node/start_node_module.d.ts.map +0 -1
  83. package/dest/worker/node/start_node_module.js +0 -31
  84. package/dest/worker/wasm_worker.d.ts +0 -9
  85. package/dest/worker/wasm_worker.d.ts.map +0 -1
  86. package/dest/worker/wasm_worker.js +0 -3
  87. package/dest/worker/worker_pool.d.ts +0 -40
  88. package/dest/worker/worker_pool.d.ts.map +0 -1
  89. package/dest/worker/worker_pool.js +0 -51
  90. package/src/log/debug.ts +0 -104
  91. package/src/log/log_history.ts +0 -44
  92. package/src/transport/browser/index.ts +0 -4
  93. package/src/transport/browser/message_port_socket.ts +0 -48
  94. package/src/transport/browser/shared_worker_connector.ts +0 -21
  95. package/src/transport/browser/shared_worker_listener.ts +0 -53
  96. package/src/transport/browser/worker_connector.ts +0 -30
  97. package/src/transport/browser/worker_listener.ts +0 -54
  98. package/src/wasm/README.md +0 -6
  99. package/src/wasm/empty_wasi_sdk.ts +0 -166
  100. package/src/wasm/fixtures/gcd.wasm +0 -0
  101. package/src/wasm/fixtures/gcd.wat +0 -27
  102. package/src/wasm/index.ts +0 -1
  103. package/src/wasm/wasm_module.ts +0 -260
  104. package/src/worker/browser/index.ts +0 -2
  105. package/src/worker/browser/start_web_module.ts +0 -24
  106. package/src/worker/browser/web_data_store.ts +0 -38
  107. package/src/worker/browser/web_worker.ts +0 -25
  108. package/src/worker/data_store.ts +0 -19
  109. package/src/worker/index.ts +0 -2
  110. package/src/worker/node/index.ts +0 -2
  111. package/src/worker/node/node_data_store.ts +0 -27
  112. package/src/worker/node/node_worker.ts +0 -23
  113. package/src/worker/node/start_node_module.ts +0 -30
  114. package/src/worker/wasm_worker.ts +0 -7
  115. package/src/worker/worker_pool.ts +0 -73
@@ -1,196 +0,0 @@
1
- import { Buffer } from 'buffer';
2
- import { randomBytes } from '../crypto/index.js';
3
- import { createDebugOnlyLogger } from '../log/index.js';
4
- import { FifoMemoryQueue } from '../queue/index.js';
5
- import { getEmptyWasiSdk } from './empty_wasi_sdk.js';
6
- /**
7
- * WasmModule:
8
- * Helper over a webassembly module.
9
- * Assumes a few quirks.
10
- * 1) the module expects wasi_snapshot_preview1 with the methods from getEmptyWasiSdk
11
- * 2) of which the webassembly
12
- * we instantiate only uses random_get (update this if more WASI sdk methods are needed).
13
- */ export class WasmModule {
14
- module;
15
- importFn;
16
- memory;
17
- heap;
18
- instance;
19
- mutexQ;
20
- debug;
21
- /**
22
- * Create a wasm module. Should be followed by await init();.
23
- * @param module - The module as a WebAssembly.Module or a Buffer.
24
- * @param importFn - Imports expected by the WASM.
25
- * @param loggerName - Optional, for debug logging.
26
- */ constructor(module, importFn, loggerName = 'wasm'){
27
- this.module = module;
28
- this.importFn = importFn;
29
- this.mutexQ = new FifoMemoryQueue();
30
- this.debug = createDebugOnlyLogger(loggerName);
31
- this.mutexQ.put(true);
32
- }
33
- /**
34
- * Return the wasm source.
35
- * @returns The source.
36
- */ getModule() {
37
- return this.module;
38
- }
39
- /**
40
- * Initialize this wasm module.
41
- * @param wasmImportEnv - Linked to a module called "env". Functions implementations referenced from e.g. C++.
42
- * @param initial - 30 pages by default. 30*2**16 \> 1mb stack size plus other overheads.
43
- * @param initMethod - Defaults to calling '_initialize'.
44
- * @param maximum - 8192 maximum by default. 512mb.
45
- */ async init(initial = 31, maximum = 8192, initMethod = '_initialize') {
46
- this.debug(`initial mem: ${initial} pages, ${initial * 2 ** 16 / (1024 * 1024)}mb. max mem: ${maximum} pages, ${maximum * 2 ** 16 / (1024 * 1024)}mb`);
47
- this.memory = new WebAssembly.Memory({
48
- initial,
49
- maximum
50
- });
51
- // Create a view over the memory buffer.
52
- // We do this once here, as webkit *seems* bugged out and actually shows this as new memory,
53
- // thus displaying double. It's only worse if we create views on demand. I haven't established yet if
54
- // the bug is also exasperating the termination on mobile due to "excessive memory usage". It could be
55
- // that the OS is actually getting an incorrect reading in the same way the memory profiler does...
56
- // The view will have to be recreated if the memory is grown. See getMemory().
57
- this.heap = new Uint8Array(this.memory.buffer);
58
- // We support the wasi 12 SDK, but only implement random_get
59
- /* eslint-disable camelcase */ const importObj = {
60
- wasi_snapshot_preview1: {
61
- ...getEmptyWasiSdk(this.debug),
62
- random_get: (arr, length)=>{
63
- arr = arr >>> 0;
64
- const heap = this.getMemory();
65
- const randomData = randomBytes(length);
66
- for(let i = arr; i < arr + length; ++i){
67
- heap[i] = randomData[i - arr];
68
- }
69
- }
70
- },
71
- env: this.importFn(this)
72
- };
73
- if (this.module instanceof WebAssembly.Module) {
74
- this.instance = await WebAssembly.instantiate(this.module, importObj);
75
- } else {
76
- const { instance } = await WebAssembly.instantiate(this.module, importObj);
77
- this.instance = instance;
78
- }
79
- // Init all global/static data.
80
- if (initMethod) {
81
- this.call(initMethod);
82
- }
83
- }
84
- /**
85
- * The methods or objects exported by the WASM module.
86
- * @returns An indexable object.
87
- */ exports() {
88
- if (!this.instance) {
89
- throw new Error('WasmModule: not initialized!');
90
- }
91
- return this.instance.exports;
92
- }
93
- /**
94
- * Get the current logger.
95
- * @returns Logging function.
96
- */ getLogger() {
97
- return this.debug;
98
- }
99
- /**
100
- * Add a logger.
101
- * @param logger - Function to call when logging.
102
- */ addLogger(logger) {
103
- const oldDebug = this.debug;
104
- this.debug = (msg)=>{
105
- logger(msg);
106
- oldDebug(msg);
107
- };
108
- }
109
- /**
110
- * Calls into the WebAssembly.
111
- * @param name - The method name.
112
- * @param args - The arguments to the method.
113
- * @returns The numeric method result.
114
- */ call(name, ...args) {
115
- if (!this.exports()[name]) {
116
- throw new Error(`WASM function ${name} not found.`);
117
- }
118
- try {
119
- // When returning values from the WASM, use >>> operator to convert
120
- // signed representation to unsigned representation.
121
- return this.exports()[name](...args) >>> 0;
122
- } catch (err) {
123
- const message = `WASM function ${name} aborted, error: ${err}\n${err.stack}`;
124
- throw new Error(message);
125
- }
126
- }
127
- /**
128
- * Get the memory used by the WASM module.
129
- * @returns A WebAssembly memory object.
130
- */ getRawMemory() {
131
- return this.memory;
132
- }
133
- /**
134
- * Get the memory used by the WASM module, as a byte array.
135
- * @returns A Uint8Array view of the WASM module memory.
136
- */ getMemory() {
137
- // If the memory is grown, our view over it will be lost. Recreate the view.
138
- if (this.heap.length === 0) {
139
- this.heap = new Uint8Array(this.memory.buffer);
140
- }
141
- return this.heap;
142
- }
143
- /**
144
- * The memory size in bytes.
145
- * @returns Number of bytes.
146
- */ memSize() {
147
- return this.getMemory().length;
148
- }
149
- /**
150
- * Get a slice of memory between two addresses.
151
- * @param start - The start address.
152
- * @param end - The end address.
153
- * @returns A Uint8Array view of memory.
154
- */ getMemorySlice(start, end) {
155
- return this.getMemory().slice(start, end);
156
- }
157
- /**
158
- * Write data into the heap.
159
- * @param offset - The address to write data at.
160
- * @param arr - The data to write.
161
- */ writeMemory(offset, arr) {
162
- const mem = this.getMemory();
163
- for(let i = 0; i < arr.length; i++){
164
- mem[i + offset] = arr[i];
165
- }
166
- }
167
- /**
168
- * Read WASM memory as a JS string.
169
- * @param addr - The memory address.
170
- * @returns A JS string.
171
- */ getMemoryAsString(addr) {
172
- addr = addr >>> 0;
173
- const m = this.getMemory();
174
- let i = addr;
175
- while(m[i] !== 0){
176
- ++i;
177
- }
178
- return Buffer.from(m.slice(addr, i)).toString('ascii');
179
- }
180
- /**
181
- * When calling the wasm, sometimes a caller will require exclusive access over a series of calls.
182
- * E.g. When a result is written to address 0, one cannot have another caller writing to the same address via
183
- * writeMemory before the result is read via sliceMemory.
184
- * Acquire() gets a single token from a fifo. The caller must call release() to add the token back.
185
- */ async acquire() {
186
- await this.mutexQ.get();
187
- }
188
- /**
189
- * Release the mutex, letting another promise call acquire().
190
- */ release() {
191
- if (this.mutexQ.length() !== 0) {
192
- throw new Error('Release called but not acquired.');
193
- }
194
- this.mutexQ.put(true);
195
- }
196
- }
@@ -1,3 +0,0 @@
1
- export * from './web_worker.js';
2
- export * from './web_data_store.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/worker/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './web_worker.js';
2
- export * from './web_data_store.js';
@@ -1,7 +0,0 @@
1
- import type { WasmModule } from '../../wasm/index.js';
2
- /**
3
- * Start the transport server corresponding to this module.
4
- * @param module - The WasmModule to host.
5
- */
6
- export declare function startWebModule(module: WasmModule): void;
7
- //# sourceMappingURL=start_web_module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"start_web_module.d.ts","sourceRoot":"","sources":["../../../src/worker/browser/start_web_module.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,QAgBhD"}
@@ -1,27 +0,0 @@
1
- import { TransportServer, WorkerListener } from '../../transport/index.js';
2
- /**
3
- * Start the transport server corresponding to this module.
4
- * @param module - The WasmModule to host.
5
- */ export function startWebModule(module) {
6
- const dispatch = async ({ fn, args })=>{
7
- if (fn === '__destroyWorker__') {
8
- transportServer.stop();
9
- return;
10
- }
11
- if (!module[fn]) {
12
- throw new Error(`dispatch error, function not found: ${fn}`);
13
- }
14
- return await module[fn](...args);
15
- };
16
- const transportListener = new WorkerListener(self);
17
- const transportServer = new TransportServer(transportListener, dispatch);
18
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
19
- module.addLogger((...args)=>transportServer.broadcast({
20
- fn: 'emit',
21
- args: [
22
- 'log',
23
- ...args
24
- ]
25
- }));
26
- transportServer.start();
27
- }
@@ -1,24 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import type { DataStore } from '../data_store.js';
4
- /**
5
- * Cache for data used by wasm module.
6
- * Stores in a LevelUp database.
7
- */
8
- export declare class WebDataStore implements DataStore {
9
- private db;
10
- constructor();
11
- /**
12
- * Lookup a key.
13
- * @param key - Key to lookup.
14
- * @returns The buffer.
15
- */
16
- get(key: string): Promise<Buffer | undefined>;
17
- /**
18
- * Alter a key.
19
- * @param key - Key to alter.
20
- * @param value - Buffer to store.
21
- */
22
- set(key: string, value: Buffer): Promise<void>;
23
- }
24
- //# sourceMappingURL=web_data_store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web_data_store.d.ts","sourceRoot":"","sources":["../../../src/worker/browser/web_data_store.ts"],"names":[],"mappings":";;AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;GAGG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C,OAAO,CAAC,EAAE,CAAU;;IAUpB;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAInD;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
@@ -1,29 +0,0 @@
1
- import levelup from 'levelup';
2
- import memdown from 'memdown';
3
- /**
4
- * Cache for data used by wasm module.
5
- * Stores in a LevelUp database.
6
- */ export class WebDataStore {
7
- db;
8
- constructor(){
9
- // TODO: The whole point of this is to reduce memory load in the browser.
10
- // Replace with leveljs so the data is stored in indexeddb and not in memory.
11
- // Hack: Cast as any to work around package "broken" with node16 resolution
12
- // See https://github.com/microsoft/TypeScript/issues/49160
13
- this.db = levelup(memdown());
14
- }
15
- /**
16
- * Lookup a key.
17
- * @param key - Key to lookup.
18
- * @returns The buffer.
19
- */ async get(key) {
20
- return await this.db.get(key).catch(()=>{});
21
- }
22
- /**
23
- * Alter a key.
24
- * @param key - Key to alter.
25
- * @param value - Buffer to store.
26
- */ async set(key, value) {
27
- await this.db.put(key, value);
28
- }
29
- }
@@ -1,10 +0,0 @@
1
- import type { WasmWorker } from '../wasm_worker.js';
2
- /**
3
- * Instantiate a web worker.
4
- * @param url - The URL.
5
- * @param initialMem - Initial memory pages.
6
- * @param maxMem - Maximum memory pages.
7
- * @returns The worker.
8
- */
9
- export declare function createWebWorker(url: string, initialMem?: number, maxMem?: number): Promise<WasmWorker>;
10
- //# sourceMappingURL=web_worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web_worker.d.ts","sourceRoot":"","sources":["../../../src/worker/browser/web_worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAa5G"}
@@ -1,25 +0,0 @@
1
- import { TransportClient, WorkerConnector, createDispatchProxy } from '../../transport/index.js';
2
- import { WasmModule } from '../../wasm/index.js';
3
- /**
4
- * Instantiate a web worker.
5
- * @param url - The URL.
6
- * @param initialMem - Initial memory pages.
7
- * @param maxMem - Maximum memory pages.
8
- * @returns The worker.
9
- */ export async function createWebWorker(url, initialMem, maxMem) {
10
- const worker = new Worker(url);
11
- const transportConnect = new WorkerConnector(worker);
12
- const transportClient = new TransportClient(transportConnect);
13
- await transportClient.open();
14
- const remoteModule = createDispatchProxy(WasmModule, transportClient);
15
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
16
- remoteModule.destroyWorker = async ()=>{
17
- await transportClient.request({
18
- fn: '__destroyWorker__',
19
- args: []
20
- });
21
- transportClient.close();
22
- };
23
- await remoteModule.init(initialMem, maxMem);
24
- return remoteModule;
25
- }
@@ -1,21 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- /**
4
- * Simple read/write interface for wasm modules.
5
- */
6
- export interface DataStore {
7
- /**
8
- * Get a value from our DB.
9
- * @param key - The key to look up.
10
- * @returns The value.
11
- */
12
- get(key: string): Promise<Buffer | undefined>;
13
- /**
14
- * Set a value in our DB.
15
- * @param key - The key to update.
16
- * @param value - The value to set.
17
- * @returns Nothing.
18
- */
19
- set(key: string, value: Buffer): Promise<void>;
20
- }
21
- //# sourceMappingURL=data_store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data_store.d.ts","sourceRoot":"","sources":["../../src/worker/data_store.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAE9C;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
@@ -1,3 +0,0 @@
1
- /**
2
- * Simple read/write interface for wasm modules.
3
- */ export { };
@@ -1,3 +0,0 @@
1
- export { WorkerPool } from './worker_pool.js';
2
- export type { WasmWorker } from './wasm_worker.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1 +0,0 @@
1
- export { WorkerPool } from './worker_pool.js';
@@ -1,3 +0,0 @@
1
- export * from './node_worker.js';
2
- export * from './node_data_store.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/worker/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './node_worker.js';
2
- export * from './node_data_store.js';
@@ -1,13 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import type { DataStore } from '../data_store.js';
4
- /**
5
- * Cache for data used by wasm module.
6
- */
7
- export declare class NodeDataStore implements DataStore {
8
- private db;
9
- constructor(path?: string);
10
- get(key: string): Promise<Buffer | undefined>;
11
- set(key: string, value: Buffer): Promise<void>;
12
- }
13
- //# sourceMappingURL=node_data_store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node_data_store.d.ts","sourceRoot":"","sources":["../../../src/worker/node/node_data_store.ts"],"names":[],"mappings":";;AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;GAEG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,OAAO,CAAC,EAAE,CAAU;gBAGR,IAAI,CAAC,EAAE,MAAM;IAMnB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrD"}
@@ -1,20 +0,0 @@
1
- import leveldown from 'leveldown';
2
- import levelup from 'levelup';
3
- import memdown from 'memdown';
4
- /**
5
- * Cache for data used by wasm module.
6
- */ export class NodeDataStore {
7
- db;
8
- // eslint-disable-next-line
9
- constructor(path){
10
- // Hack: Cast as any to work around packages "broken" with node16 resolution
11
- // See https://github.com/microsoft/TypeScript/issues/49160
12
- this.db = levelup(path ? leveldown(path) : memdown());
13
- }
14
- async get(key) {
15
- return await this.db.get(key).catch(()=>{});
16
- }
17
- async set(key, value) {
18
- await this.db.put(key, value);
19
- }
20
- }
@@ -1,6 +0,0 @@
1
- import type { WasmWorker } from '../wasm_worker.js';
2
- /**
3
- * Creates a node worker.
4
- */
5
- export declare function createNodeWorker(filepath: string, initialMem?: number, maxMem?: number): Promise<WasmWorker>;
6
- //# sourceMappingURL=node_worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node_worker.d.ts","sourceRoot":"","sources":["../../../src/worker/node/node_worker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAalH"}
@@ -1,22 +0,0 @@
1
- import { Worker } from 'worker_threads';
2
- import { NodeConnector, TransportClient, createDispatchProxy } from '../../transport/index.js';
3
- import { WasmModule } from '../../wasm/wasm_module.js';
4
- /**
5
- * Creates a node worker.
6
- */ export async function createNodeWorker(filepath, initialMem, maxMem) {
7
- const worker = new Worker(filepath);
8
- const transportConnect = new NodeConnector(worker);
9
- const transportClient = new TransportClient(transportConnect);
10
- await transportClient.open();
11
- const remoteModule = createDispatchProxy(WasmModule, transportClient);
12
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
13
- remoteModule.destroyWorker = async ()=>{
14
- await transportClient.request({
15
- fn: '__destroyWorker__',
16
- args: []
17
- });
18
- transportClient.close();
19
- };
20
- await remoteModule.init(initialMem, maxMem);
21
- return remoteModule;
22
- }
@@ -1,7 +0,0 @@
1
- import type { WasmModule } from '../../wasm/wasm_module.js';
2
- /**
3
- * Start the transport server corresponding to this module.
4
- * @param module - The WasmModule to host.
5
- */
6
- export declare function startNodeModule(module: WasmModule): void;
7
- //# sourceMappingURL=start_node_module.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"start_node_module.d.ts","sourceRoot":"","sources":["../../../src/worker/node/start_node_module.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAM5D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,QAgBjD"}
@@ -1,31 +0,0 @@
1
- import { parentPort } from 'worker_threads';
2
- import { NodeListener, TransportServer } from '../../transport/index.js';
3
- if (!parentPort) {
4
- throw new Error('InvalidWorker');
5
- }
6
- /**
7
- * Start the transport server corresponding to this module.
8
- * @param module - The WasmModule to host.
9
- */ export function startNodeModule(module) {
10
- const dispatch = async ({ fn, args })=>{
11
- if (fn === '__destroyWorker__') {
12
- transportServer.stop();
13
- return;
14
- }
15
- if (!module[fn]) {
16
- throw new Error(`dispatch error, function not found: ${fn}`);
17
- }
18
- return await module[fn](...args);
19
- };
20
- const transportListener = new NodeListener();
21
- const transportServer = new TransportServer(transportListener, dispatch);
22
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
23
- module.addLogger((...args)=>transportServer.broadcast({
24
- fn: 'emit',
25
- args: [
26
- 'log',
27
- ...args
28
- ]
29
- }));
30
- transportServer.start();
31
- }
@@ -1,9 +0,0 @@
1
- import type { Proxify } from '../transport/index.js';
2
- import type { WasmModule } from '../wasm/wasm_module.js';
3
- /**
4
- * Represents either a WASM web worker, or node.js worker.
5
- */
6
- export type WasmWorker = Proxify<WasmModule> & {
7
- destroyWorker(): void;
8
- };
9
- //# sourceMappingURL=wasm_worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wasm_worker.d.ts","sourceRoot":"","sources":["../../src/worker/wasm_worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAAE,aAAa,IAAI,IAAI,CAAA;CAAE,CAAC"}
@@ -1,3 +0,0 @@
1
- /**
2
- * Represents either a WASM web worker, or node.js worker.
3
- */ export { };
@@ -1,40 +0,0 @@
1
- import type { WasmWorker } from './wasm_worker.js';
2
- /**
3
- * Type of a worker factory.
4
- * Used to customize WorkerPool worker construction.
5
- */
6
- export type CreateWorker = (name: string, minMem: number, maxMem: number) => WasmWorker;
7
- /**
8
- * Allocates a pool of WasmWorker's.
9
- * Worker 0 is allocated MAX_PAGES memory pages. This is because worker 0 will need to hold the proving key
10
- * (i.e. Has state), whereas the others are pure compute (they hold a little crs state).
11
- */
12
- export declare class WorkerPool {
13
- /**
14
- * The maximum number of memory pages to be used by the webassembly.
15
- */
16
- static MAX_PAGES: number;
17
- /**
18
- * The workers in the pool.
19
- */
20
- private workers;
21
- /**
22
- * Create an instance and initialize the workers.
23
- * @param createWorker - Worker factory.
24
- * @param poolSize - Pool size.
25
- * @returns An initialized WorkerPool.
26
- */
27
- static new(createWorker: CreateWorker, poolSize: number): Promise<WorkerPool>;
28
- /**
29
- * Initialize the workers.
30
- * @param createWorker - Worker factory().
31
- * @param poolSize - Pool size.
32
- * @param maxMem - Max memory pages.
33
- */
34
- init(createWorker: CreateWorker, poolSize: number, maxMem?: number): Promise<void>;
35
- /**
36
- * Tell all workers in the pool to stop processing.
37
- */
38
- destroy(): Promise<void>;
39
- }
40
- //# sourceMappingURL=worker_pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker_pool.d.ts","sourceRoot":"","sources":["../../src/worker/worker_pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,UAAU,CAAC;AACxF;;;;GAIG;AACH,qBAAa,UAAU;IAYrB;;OAEG;IACH,OAAc,SAAS,SAAQ;IAC/B;;OAEG;IACH,OAAO,CAAC,OAAO,CAAoB;IAEnC;;;;;OAKG;WACU,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM;IAM7D;;;;;OAKG;IACU,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAuB;IAY7F;;OAEG;IACU,OAAO;CAGrB"}
@@ -1,51 +0,0 @@
1
- import { createLogger } from '../log/index.js';
2
- const log = createLogger('foundation:worker_pool');
3
- /**
4
- * Allocates a pool of WasmWorker's.
5
- * Worker 0 is allocated MAX_PAGES memory pages. This is because worker 0 will need to hold the proving key
6
- * (i.e. Has state), whereas the others are pure compute (they hold a little crs state).
7
- */ export class WorkerPool {
8
- // TODO(AD): Revisit what this means in aztec 3 context
9
- // --
10
- // Introduction of low mem prover work (polynomial cache) may actually increase mem usage when the backing store isn't
11
- // enabled. We were seeing intermittent failings related to memory in production for some users when limiting to
12
- // 6660 (416MB). It would be nice to understand why this is (the non determinism and/or the increased mem usage).
13
- // For now, increasing mem usage to 512MB. This maybe preferable to backing out the low mem work, but
14
- // ironically may break the chance of us using it in mobile.
15
- // We *could* enable the low memory backing store, but this needs a little bit of work to actually
16
- // read/write from indexeddb, performance testing, and actual further memory load testing.
17
- // At this point it's hard to know what our memory savings would be relative to just fully reverting the LMP.
18
- // public static MAX_PAGES = 6660;
19
- /**
20
- * The maximum number of memory pages to be used by the webassembly.
21
- */ static MAX_PAGES = 8192;
22
- /**
23
- * The workers in the pool.
24
- */ workers = [];
25
- /**
26
- * Create an instance and initialize the workers.
27
- * @param createWorker - Worker factory.
28
- * @param poolSize - Pool size.
29
- * @returns An initialized WorkerPool.
30
- */ static async new(createWorker, poolSize) {
31
- const pool = new WorkerPool();
32
- await pool.init(createWorker, poolSize);
33
- return pool;
34
- }
35
- /**
36
- * Initialize the workers.
37
- * @param createWorker - Worker factory().
38
- * @param poolSize - Pool size.
39
- * @param maxMem - Max memory pages.
40
- */ async init(createWorker, poolSize, maxMem = WorkerPool.MAX_PAGES) {
41
- log.debug(`creating ${poolSize} workers...`);
42
- const start = new Date().getTime();
43
- this.workers = await Promise.all(Array(poolSize).fill(0).map((_, i)=>createWorker(`${i}`, i === 0 ? Math.min(WorkerPool.MAX_PAGES, maxMem) : 768, maxMem)));
44
- log.debug(`created workers: ${new Date().getTime() - start}ms`);
45
- }
46
- /**
47
- * Tell all workers in the pool to stop processing.
48
- */ async destroy() {
49
- await Promise.all(this.workers.map((w)=>w.destroyWorker()));
50
- }
51
- }