@aztec/native 3.0.0-nightly.20251205 → 3.0.0-nightly.20251207
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/dest/native_module.d.ts +6 -4
- package/dest/native_module.d.ts.map +1 -1
- package/dest/native_module.js +36 -3
- package/package.json +3 -3
- package/src/native_module.ts +51 -10
package/dest/native_module.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LogLevel } from '@aztec/foundation/log';
|
|
1
2
|
import type { MessageReceiver } from './msgpack_channel.js';
|
|
2
3
|
interface NativeClassCtor {
|
|
3
4
|
new (...args: unknown[]): MessageReceiver;
|
|
@@ -63,17 +64,18 @@ export interface ContractProvider {
|
|
|
63
64
|
* @param inputs - Msgpack-serialized AvmFastSimulationInputs buffer
|
|
64
65
|
* @param contractProvider - Object with callbacks for fetching contract instances and classes
|
|
65
66
|
* @param worldStateHandle - Native handle to WorldState instance
|
|
66
|
-
*
|
|
67
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
67
68
|
* @returns Promise resolving to msgpack-serialized AvmCircuitPublicInputs buffer
|
|
68
69
|
*/
|
|
69
|
-
export declare
|
|
70
|
+
export declare function avmSimulate(inputs: Buffer, contractProvider: ContractProvider, worldStateHandle: any, logLevel?: LogLevel): Promise<Buffer>;
|
|
70
71
|
/**
|
|
71
72
|
* AVM simulation function that uses pre-collected hints from TypeScript simulation.
|
|
72
73
|
* All contract data and merkle tree hints are included in the AvmCircuitInputs, so no runtime
|
|
73
74
|
* callbacks to TS or WS pointer are needed.
|
|
74
75
|
* @param inputs - Msgpack-serialized AvmCircuitInputs (AvmProvingInputs in C++) buffer
|
|
76
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
75
77
|
* @returns Promise resolving to msgpack-serialized simulation results buffer
|
|
76
78
|
*/
|
|
77
|
-
export declare
|
|
79
|
+
export declare function avmSimulateWithHintedDbs(inputs: Buffer, logLevel?: LogLevel): Promise<Buffer>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QUFDO0lBRXBFOzs7OztPQUtHO0lBQ0gsb0JBQW9CLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBQUM7SUFFckY7Ozs7T0FJRztJQUNILGdCQUFnQixJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUVsQzs7O09BR0c7SUFDSCxnQkFBZ0IsSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFbEM7OztPQUdHO0lBQ0gsZ0JBQWdCLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ25DO0FBOEJEOzs7Ozs7OztHQVFHO0FBQ0gsd0JBQXNCLFdBQVcsQ0FDL0IsTUFBTSxFQUFFLE1BQU0sRUFDZCxnQkFBZ0IsRUFBRSxnQkFBZ0IsRUFDbEMsZ0JBQWdCLEVBQUUsR0FBRyxFQUNyQixRQUFRLEdBQUUsUUFBaUIsR0FDMUIsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQU9qQjtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBc0Isd0JBQXdCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLEdBQUUsUUFBaUIsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBTzNHIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_module.d.ts","sourceRoot":"","sources":["../src/native_module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native_module.d.ts","sourceRoot":"","sources":["../src/native_module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,uBAAuB,CAAC;AAKjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,UAAU,eAAe;IACvB,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAA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@@
|
|
|
1
1
|
import { findNapiBinary } from '@aztec/bb.js';
|
|
2
|
+
import { LogLevels } from '@aztec/foundation/log';
|
|
3
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
2
4
|
import { createRequire } from 'module';
|
|
3
5
|
function loadNativeModule() {
|
|
4
6
|
const require = createRequire(import.meta.url);
|
|
@@ -11,19 +13,50 @@ function loadNativeModule() {
|
|
|
11
13
|
const nativeModule = loadNativeModule();
|
|
12
14
|
export const NativeWorldState = nativeModule.WorldState;
|
|
13
15
|
export const NativeLMDBStore = nativeModule.LMDBStore;
|
|
16
|
+
// Internal native functions with numeric log level
|
|
17
|
+
const nativeAvmSimulate = nativeModule.avmSimulate;
|
|
18
|
+
const nativeAvmSimulateWithHintedDbs = nativeModule.avmSimulateWithHintedDbs;
|
|
19
|
+
/**
|
|
20
|
+
* Concurrency limiting for C++ AVM simulation to prevent libuv thread pool exhaustion.
|
|
21
|
+
*
|
|
22
|
+
* The C++ simulator uses NAPI BlockingCall to callback to TypeScript for contract data.
|
|
23
|
+
* This blocks the libuv thread while waiting for the callback to complete. If all libuv
|
|
24
|
+
* threads are blocked waiting for callbacks, no threads remain to service those callbacks,
|
|
25
|
+
* causing deadlock.
|
|
26
|
+
*
|
|
27
|
+
* We limit concurrent simulations to UV_THREADPOOL_SIZE / 2 to ensure threads remain
|
|
28
|
+
* available for callback processing.
|
|
29
|
+
*/ const UV_THREADPOOL_SIZE = parseInt(process.env.UV_THREADPOOL_SIZE ?? '4', 10);
|
|
30
|
+
const MAX_CONCURRENT_AVM_SIMULATIONS = Math.max(1, Math.floor(UV_THREADPOOL_SIZE / 2));
|
|
31
|
+
const avmSimulationSemaphore = new Semaphore(MAX_CONCURRENT_AVM_SIMULATIONS);
|
|
14
32
|
/**
|
|
15
33
|
* AVM simulation function that takes serialized inputs and a contract provider.
|
|
16
34
|
* The contract provider enables C++ to callback to TypeScript for contract data during simulation.
|
|
17
35
|
* @param inputs - Msgpack-serialized AvmFastSimulationInputs buffer
|
|
18
36
|
* @param contractProvider - Object with callbacks for fetching contract instances and classes
|
|
19
37
|
* @param worldStateHandle - Native handle to WorldState instance
|
|
20
|
-
*
|
|
38
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
21
39
|
* @returns Promise resolving to msgpack-serialized AvmCircuitPublicInputs buffer
|
|
22
|
-
*/ export
|
|
40
|
+
*/ export async function avmSimulate(inputs, contractProvider, worldStateHandle, logLevel = 'info') {
|
|
41
|
+
await avmSimulationSemaphore.acquire();
|
|
42
|
+
try {
|
|
43
|
+
return await nativeAvmSimulate(inputs, contractProvider, worldStateHandle, LogLevels.indexOf(logLevel));
|
|
44
|
+
} finally{
|
|
45
|
+
avmSimulationSemaphore.release();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
23
48
|
/**
|
|
24
49
|
* AVM simulation function that uses pre-collected hints from TypeScript simulation.
|
|
25
50
|
* All contract data and merkle tree hints are included in the AvmCircuitInputs, so no runtime
|
|
26
51
|
* callbacks to TS or WS pointer are needed.
|
|
27
52
|
* @param inputs - Msgpack-serialized AvmCircuitInputs (AvmProvingInputs in C++) buffer
|
|
53
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
28
54
|
* @returns Promise resolving to msgpack-serialized simulation results buffer
|
|
29
|
-
*/ export
|
|
55
|
+
*/ export async function avmSimulateWithHintedDbs(inputs, logLevel = 'info') {
|
|
56
|
+
await avmSimulationSemaphore.acquire();
|
|
57
|
+
try {
|
|
58
|
+
return await nativeAvmSimulateWithHintedDbs(inputs, LogLevels.indexOf(logLevel));
|
|
59
|
+
} finally{
|
|
60
|
+
avmSimulationSemaphore.release();
|
|
61
|
+
}
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/native",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251207",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js"
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"../package.common.json"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@aztec/bb.js": "3.0.0-nightly.
|
|
19
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
18
|
+
"@aztec/bb.js": "3.0.0-nightly.20251207",
|
|
19
|
+
"@aztec/foundation": "3.0.0-nightly.20251207",
|
|
20
20
|
"msgpackr": "^1.11.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/src/native_module.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { findNapiBinary } from '@aztec/bb.js';
|
|
2
|
+
import { type LogLevel, LogLevels } from '@aztec/foundation/log';
|
|
3
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
2
4
|
|
|
3
5
|
import { createRequire } from 'module';
|
|
4
6
|
|
|
@@ -82,31 +84,70 @@ export interface ContractProvider {
|
|
|
82
84
|
revertCheckpoint(): Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
// Internal native functions with numeric log level
|
|
88
|
+
const nativeAvmSimulate = nativeModule.avmSimulate as (
|
|
89
|
+
inputs: Buffer,
|
|
90
|
+
contractProvider: ContractProvider,
|
|
91
|
+
worldStateHandle: any,
|
|
92
|
+
logLevel: number,
|
|
93
|
+
) => Promise<Buffer>;
|
|
94
|
+
|
|
95
|
+
const nativeAvmSimulateWithHintedDbs = nativeModule.avmSimulateWithHintedDbs as (
|
|
96
|
+
inputs: Buffer,
|
|
97
|
+
logLevel: number,
|
|
98
|
+
) => Promise<Buffer>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Concurrency limiting for C++ AVM simulation to prevent libuv thread pool exhaustion.
|
|
102
|
+
*
|
|
103
|
+
* The C++ simulator uses NAPI BlockingCall to callback to TypeScript for contract data.
|
|
104
|
+
* This blocks the libuv thread while waiting for the callback to complete. If all libuv
|
|
105
|
+
* threads are blocked waiting for callbacks, no threads remain to service those callbacks,
|
|
106
|
+
* causing deadlock.
|
|
107
|
+
*
|
|
108
|
+
* We limit concurrent simulations to UV_THREADPOOL_SIZE / 2 to ensure threads remain
|
|
109
|
+
* available for callback processing.
|
|
110
|
+
*/
|
|
111
|
+
const UV_THREADPOOL_SIZE = parseInt(process.env.UV_THREADPOOL_SIZE ?? '4', 10);
|
|
112
|
+
const MAX_CONCURRENT_AVM_SIMULATIONS = Math.max(1, Math.floor(UV_THREADPOOL_SIZE / 2));
|
|
113
|
+
const avmSimulationSemaphore = new Semaphore(MAX_CONCURRENT_AVM_SIMULATIONS);
|
|
114
|
+
|
|
85
115
|
/**
|
|
86
116
|
* AVM simulation function that takes serialized inputs and a contract provider.
|
|
87
117
|
* The contract provider enables C++ to callback to TypeScript for contract data during simulation.
|
|
88
118
|
* @param inputs - Msgpack-serialized AvmFastSimulationInputs buffer
|
|
89
119
|
* @param contractProvider - Object with callbacks for fetching contract instances and classes
|
|
90
120
|
* @param worldStateHandle - Native handle to WorldState instance
|
|
91
|
-
*
|
|
121
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
92
122
|
* @returns Promise resolving to msgpack-serialized AvmCircuitPublicInputs buffer
|
|
93
123
|
*/
|
|
94
|
-
export
|
|
124
|
+
export async function avmSimulate(
|
|
95
125
|
inputs: Buffer,
|
|
96
126
|
contractProvider: ContractProvider,
|
|
97
127
|
worldStateHandle: any,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
128
|
+
logLevel: LogLevel = 'info',
|
|
129
|
+
): Promise<Buffer> {
|
|
130
|
+
await avmSimulationSemaphore.acquire();
|
|
131
|
+
try {
|
|
132
|
+
return await nativeAvmSimulate(inputs, contractProvider, worldStateHandle, LogLevels.indexOf(logLevel));
|
|
133
|
+
} finally {
|
|
134
|
+
avmSimulationSemaphore.release();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
103
138
|
/**
|
|
104
139
|
* AVM simulation function that uses pre-collected hints from TypeScript simulation.
|
|
105
140
|
* All contract data and merkle tree hints are included in the AvmCircuitInputs, so no runtime
|
|
106
141
|
* callbacks to TS or WS pointer are needed.
|
|
107
142
|
* @param inputs - Msgpack-serialized AvmCircuitInputs (AvmProvingInputs in C++) buffer
|
|
143
|
+
* @param logLevel - Log level to control C++ verbosity
|
|
108
144
|
* @returns Promise resolving to msgpack-serialized simulation results buffer
|
|
109
145
|
*/
|
|
110
|
-
export
|
|
111
|
-
|
|
112
|
-
|
|
146
|
+
export async function avmSimulateWithHintedDbs(inputs: Buffer, logLevel: LogLevel = 'info'): Promise<Buffer> {
|
|
147
|
+
await avmSimulationSemaphore.acquire();
|
|
148
|
+
try {
|
|
149
|
+
return await nativeAvmSimulateWithHintedDbs(inputs, LogLevels.indexOf(logLevel));
|
|
150
|
+
} finally {
|
|
151
|
+
avmSimulationSemaphore.release();
|
|
152
|
+
}
|
|
153
|
+
}
|