@aztec/foundation 0.65.2 → 0.66.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.
- package/dest/async-pool/index.d.ts +3 -0
- package/dest/async-pool/index.d.ts.map +1 -0
- package/dest/async-pool/index.js +50 -0
- package/dest/collection/array.d.ts +14 -0
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +23 -1
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +2 -2
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +2 -2
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts +2 -2
- package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
- package/dest/log/index.d.ts +1 -1
- package/dest/log/index.d.ts.map +1 -1
- package/dest/log/index.js +2 -2
- package/dest/log/log-filters.d.ts +7 -0
- package/dest/log/log-filters.d.ts.map +1 -0
- package/dest/log/log-filters.js +43 -0
- package/dest/log/log-levels.d.ts +3 -0
- package/dest/log/log-levels.d.ts.map +1 -0
- package/dest/log/log-levels.js +2 -0
- package/dest/log/pino-logger.d.ts +39 -0
- package/dest/log/pino-logger.d.ts.map +1 -0
- package/dest/log/pino-logger.js +146 -0
- package/dest/queue/base_memory_queue.d.ts +1 -1
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/bounded_serial_queue.d.ts +1 -1
- package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
- package/dest/queue/fifo_memory_queue.d.ts +1 -1
- package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
- package/dest/retry/index.d.ts +1 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts +1 -1
- package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/async-pool/index.ts +50 -0
- package/src/collection/array.ts +24 -0
- package/src/config/env_var.ts +15 -1
- package/src/crypto/random/randomness_singleton.ts +1 -1
- package/src/json-rpc/client/safe_json_rpc_client.ts +1 -1
- package/src/log/index.ts +1 -1
- package/src/log/log-filters.ts +49 -0
- package/src/log/log-levels.ts +3 -0
- package/src/log/pino-logger.ts +196 -0
- package/src/queue/fifo_memory_queue.ts +1 -1
- package/dest/log/logger.d.ts +0 -57
- package/dest/log/logger.d.ts.map +0 -1
- package/dest/log/logger.js +0 -139
- package/src/log/logger.ts +0 -179
|
@@ -6,7 +6,7 @@ export declare class BoundedSerialQueue {
|
|
|
6
6
|
private log;
|
|
7
7
|
private readonly queue;
|
|
8
8
|
private semaphore;
|
|
9
|
-
constructor(maxQueueSize: number, log?: import("../log/logger.js").Logger);
|
|
9
|
+
constructor(maxQueueSize: number, log?: import("../log/pino-logger.js").Logger);
|
|
10
10
|
/**
|
|
11
11
|
* Initializes the underlying SerialQueue instance, allowing items to be processed from the queue.
|
|
12
12
|
* The start method should be called before using the BoundedSerialQueue to ensure proper functionality.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded_serial_queue.d.ts","sourceRoot":"","sources":["../../src/queue/bounded_serial_queue.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAIK,OAAO,CAAC,GAAG;IAH7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,SAAS,CAAY;gBAEjB,YAAY,EAAE,MAAM,EAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"bounded_serial_queue.d.ts","sourceRoot":"","sources":["../../src/queue/bounded_serial_queue.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAIK,OAAO,CAAC,GAAG;IAH7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,SAAS,CAAY;gBAEjB,YAAY,EAAE,MAAM,EAAU,GAAG,yCAA6D;IAI1G;;;OAGG;IACI,KAAK;IAIZ;;;;;OAKG;IACI,MAAM;IAIb;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;OAOG;IACI,GAAG;IAIV;;;;;OAKG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD;;;;OAIG;IACU,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWtD;;OAEG;IACU,SAAS;CAGvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fifo_memory_queue.d.ts","sourceRoot":"","sources":["../../src/queue/fifo_memory_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"fifo_memory_queue.d.ts","sourceRoot":"","sources":["../../src/queue/fifo_memory_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,SAAS,CAAsB;gBAE3B,GAAG,CAAC,EAAE,WAAW;IAI7B,cAAuB,KAAK,iBAE3B;CACF;AAED,cAAM,SAAS,CAAC,CAAC;IACf,OAAO,CAAC,KAAK,CAAW;IAEjB,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAIlB,GAAG,IAAI,CAAC,GAAG,SAAS;IAI3B,IAAW,MAAM,IAAI,MAAM,CAE1B;IAEM,KAAK;CAGb"}
|
package/dest/retry/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare function makeBackoff(retries: number[]): Generator<number, void,
|
|
|
28
28
|
* @returns A Promise that resolves with the successful result of the provided function, or rejects if backoff generator ends.
|
|
29
29
|
* @throws If `NoRetryError` is thrown by the `fn`, it is rethrown.
|
|
30
30
|
*/
|
|
31
|
-
export declare function retry<Result>(fn: () => Promise<Result>, name?: string, backoff?: Generator<number, void, unknown>, log?: import("../log/logger.js").Logger, failSilently?: boolean): Promise<Result>;
|
|
31
|
+
export declare function retry<Result>(fn: () => Promise<Result>, name?: string, backoff?: Generator<number, void, unknown>, log?: import("../log/pino-logger.js").Logger, failSilently?: boolean): Promise<Result>;
|
|
32
32
|
/**
|
|
33
33
|
* Retry an asynchronous function until it returns a truthy value or the specified timeout is exceeded.
|
|
34
34
|
* The function is retried periodically with a fixed interval between attempts. The operation can be named for better error messages.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AAIA,wEAAwE;AACxE,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACzB,IAAI,SAAc,EAClB,OAAO,mCAAqB,EAC5B,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AAIA,wEAAwE;AACxE,qBAAa,YAAa,SAAQ,KAAK;CAAG;AAE1C;;;;;;;GAOG;AACH,wBAAiB,gBAAgB,qCAMhC;AAED;;;;GAIG;AACH,wBAAiB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oCAI7C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACzB,IAAI,SAAc,EAClB,OAAO,mCAAqB,EAC5B,GAAG,yCAA8C,EACjD,YAAY,UAAQ,mBAoBrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,IAAI,SAAK,EAAE,OAAO,SAAI,EAAE,QAAQ,SAAI,oCAczG"}
|
|
@@ -21,5 +21,5 @@ export interface DispatchMsg {
|
|
|
21
21
|
* @param log - Optional logging function for debugging purposes.
|
|
22
22
|
* @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
|
|
23
23
|
*/
|
|
24
|
-
export declare function createDispatchFn(targetFn: () => any, log?: import("../../log/logger.js").Logger): ({ fn, args }: DispatchMsg) => Promise<any>;
|
|
24
|
+
export declare function createDispatchFn(targetFn: () => any, log?: import("../../log/pino-logger.js").Logger): ({ fn, args }: DispatchMsg) => Promise<any>;
|
|
25
25
|
//# sourceMappingURL=create_dispatch_fn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,4CAAiD,kBAC5E,WAAW,kBAKxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"packageManager": "yarn@3.4.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dest/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"./prettier": "./.prettierrc.json",
|
|
12
12
|
"./abi": "./dest/abi/index.js",
|
|
13
13
|
"./async-map": "./dest/async-map/index.js",
|
|
14
|
+
"./async-pool": "./dest/async-pool/index.js",
|
|
14
15
|
"./aztec-address": "./dest/aztec-address/index.js",
|
|
15
16
|
"./collection": "./dest/collection/index.js",
|
|
16
17
|
"./config": "./dest/config/index.js",
|
|
@@ -98,10 +99,11 @@
|
|
|
98
99
|
]
|
|
99
100
|
},
|
|
100
101
|
"dependencies": {
|
|
101
|
-
"@aztec/bb.js": "0.
|
|
102
|
+
"@aztec/bb.js": "0.66.0",
|
|
102
103
|
"@koa/cors": "^5.0.0",
|
|
103
104
|
"@noble/curves": "^1.2.0",
|
|
104
105
|
"bn.js": "^5.2.1",
|
|
106
|
+
"colorette": "^2.0.20",
|
|
105
107
|
"debug": "^4.3.4",
|
|
106
108
|
"detect-node": "^2.1.0",
|
|
107
109
|
"elliptic": "^6.5.4",
|
|
@@ -116,6 +118,8 @@
|
|
|
116
118
|
"lodash.clonedeepwith": "^4.5.0",
|
|
117
119
|
"memdown": "^6.1.1",
|
|
118
120
|
"pako": "^2.1.0",
|
|
121
|
+
"pino": "^9.5.0",
|
|
122
|
+
"pino-pretty": "^13.0.0",
|
|
119
123
|
"sha3": "^2.1.4",
|
|
120
124
|
"zod": "^3.23.8"
|
|
121
125
|
},
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Adapted from https://github.com/rxaviers/async-pool/blob/1.x/lib/es6.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017 Rafael Xavier de Souza http://rafael.xavier.blog.br
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person
|
|
7
|
+
* obtaining a copy of this software and associated documentation
|
|
8
|
+
* files (the "Software"), to deal in the Software without
|
|
9
|
+
* restriction, including without limitation the rights to use,
|
|
10
|
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the
|
|
12
|
+
* Software is furnished to do so, subject to the following
|
|
13
|
+
* conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be
|
|
16
|
+
* included in all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
20
|
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
23
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
24
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
25
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** Executes the given async function over the iterable, up to a determined number of promises in parallel. */
|
|
29
|
+
export function asyncPool<T, R>(poolLimit: number, iterable: T[], iteratorFn: (item: T, iterable: T[]) => Promise<R>) {
|
|
30
|
+
let i = 0;
|
|
31
|
+
const ret: Promise<R>[] = [];
|
|
32
|
+
const executing: Set<Promise<R>> = new Set();
|
|
33
|
+
const enqueue = (): Promise<any> => {
|
|
34
|
+
if (i === iterable.length) {
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
const item = iterable[i++];
|
|
38
|
+
const p = Promise.resolve().then(() => iteratorFn(item, iterable));
|
|
39
|
+
ret.push(p);
|
|
40
|
+
executing.add(p);
|
|
41
|
+
const clean = () => executing.delete(p);
|
|
42
|
+
p.then(clean).catch(clean);
|
|
43
|
+
let r: Promise<any> = Promise.resolve();
|
|
44
|
+
if (executing.size >= poolLimit) {
|
|
45
|
+
r = Promise.race(executing);
|
|
46
|
+
}
|
|
47
|
+
return r.then(() => enqueue());
|
|
48
|
+
};
|
|
49
|
+
return enqueue().then(() => Promise.all(ret));
|
|
50
|
+
}
|
package/src/collection/array.ts
CHANGED
|
@@ -75,6 +75,20 @@ export function times<T>(n: number, fn: (i: number) => T): T[] {
|
|
|
75
75
|
return [...Array(n).keys()].map(i => fn(i));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Executes the given async function n times and returns the results in an array. Awaits each execution before starting the next one.
|
|
80
|
+
* @param n - How many times to repeat.
|
|
81
|
+
* @param fn - Mapper from index to value.
|
|
82
|
+
* @returns The array with the result from all executions.
|
|
83
|
+
*/
|
|
84
|
+
export async function timesAsync<T>(n: number, fn: (i: number) => Promise<T>): Promise<T[]> {
|
|
85
|
+
const results: T[] = [];
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
results.push(await fn(i));
|
|
88
|
+
}
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
|
|
78
92
|
/**
|
|
79
93
|
* Returns the serialized size of all non-empty items in an array.
|
|
80
94
|
* @param arr - Array
|
|
@@ -121,3 +135,13 @@ export function areArraysEqual<T>(a: T[], b: T[], eq: (a: T, b: T) => boolean =
|
|
|
121
135
|
}
|
|
122
136
|
return true;
|
|
123
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Returns the element of the array that has the maximum value of the given function.
|
|
141
|
+
* In case of a tie, returns the first element with the maximum value.
|
|
142
|
+
* @param arr - The array.
|
|
143
|
+
* @param fn - The function to get the value to compare.
|
|
144
|
+
*/
|
|
145
|
+
export function maxBy<T>(arr: T[], fn: (x: T) => number): T | undefined {
|
|
146
|
+
return arr.reduce((max, x) => (fn(x) > fn(max) ? x : max), arr[0]);
|
|
147
|
+
}
|
package/src/config/env_var.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type EnvVar =
|
|
|
8
8
|
| 'ARCHIVER_POLLING_INTERVAL_MS'
|
|
9
9
|
| 'ARCHIVER_URL'
|
|
10
10
|
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
|
|
11
|
+
| 'ARCHIVER_BATCH_SIZE'
|
|
11
12
|
| 'ASSUME_PROVEN_THROUGH_BLOCK_NUMBER'
|
|
12
13
|
| 'AZTEC_NODE_URL'
|
|
13
14
|
| 'AZTEC_PORT'
|
|
@@ -91,6 +92,7 @@ export type EnvVar =
|
|
|
91
92
|
| 'P2P_TCP_LISTEN_ADDR'
|
|
92
93
|
| 'P2P_TCP_ANNOUNCE_ADDR'
|
|
93
94
|
| 'P2P_TX_POOL_KEEP_PROVEN_FOR'
|
|
95
|
+
| 'P2P_ATTESTATION_POOL_KEEP_FOR'
|
|
94
96
|
| 'P2P_TX_PROTOCOL'
|
|
95
97
|
| 'P2P_UDP_ANNOUNCE_ADDR'
|
|
96
98
|
| 'P2P_UDP_LISTEN_ADDR'
|
|
@@ -115,6 +117,7 @@ export type EnvVar =
|
|
|
115
117
|
| 'PROVER_JOB_TIMEOUT_MS'
|
|
116
118
|
| 'PROVER_NODE_POLLING_INTERVAL_MS'
|
|
117
119
|
| 'PROVER_NODE_MAX_PENDING_JOBS'
|
|
120
|
+
| 'PROVER_NODE_MAX_PARALLEL_BLOCKS_PER_EPOCH'
|
|
118
121
|
| 'PROVER_PUBLISH_RETRY_INTERVAL_MS'
|
|
119
122
|
| 'PROVER_PUBLISHER_PRIVATE_KEY'
|
|
120
123
|
| 'PROVER_REAL_PROOFS'
|
|
@@ -143,6 +146,7 @@ export type EnvVar =
|
|
|
143
146
|
| 'SEQ_REQUIRED_CONFIRMATIONS'
|
|
144
147
|
| 'SEQ_TX_POLLING_INTERVAL_MS'
|
|
145
148
|
| 'SEQ_ENFORCE_TIME_TABLE'
|
|
149
|
+
| 'STAKING_ASSET_CONTRACT_ADDRESS'
|
|
146
150
|
| 'REWARD_DISTRIBUTOR_CONTRACT_ADDRESS'
|
|
147
151
|
| 'TELEMETRY'
|
|
148
152
|
| 'TEST_ACCOUNTS'
|
|
@@ -168,4 +172,14 @@ export type EnvVar =
|
|
|
168
172
|
| 'AZTEC_SLOT_DURATION'
|
|
169
173
|
| 'AZTEC_EPOCH_DURATION'
|
|
170
174
|
| 'AZTEC_TARGET_COMMITTEE_SIZE'
|
|
171
|
-
| 'AZTEC_EPOCH_PROOF_CLAIM_WINDOW_IN_L2_SLOTS'
|
|
175
|
+
| 'AZTEC_EPOCH_PROOF_CLAIM_WINDOW_IN_L2_SLOTS'
|
|
176
|
+
| 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
|
|
177
|
+
| 'L1_GAS_LIMIT_BUFFER_FIXED'
|
|
178
|
+
| 'L1_GAS_PRICE_MIN'
|
|
179
|
+
| 'L1_GAS_PRICE_MAX'
|
|
180
|
+
| 'L1_PRIORITY_FEE_BUMP_PERCENTAGE'
|
|
181
|
+
| 'L1_PRIORITY_FEE_RETRY_BUMP_PERCENTAGE'
|
|
182
|
+
| 'L1_TX_MONITOR_MAX_ATTEMPTS'
|
|
183
|
+
| 'L1_TX_MONITOR_CHECK_INTERVAL_MS'
|
|
184
|
+
| 'L1_TX_MONITOR_STALL_TIME_MS'
|
|
185
|
+
| 'L1_TX_MONITOR_TX_TIMEOUT_MS';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { format } from 'util';
|
|
2
2
|
|
|
3
|
-
import { createDebugLogger } from '../../log/logger.js';
|
|
3
|
+
import { createDebugLogger } from '../../log/pino-logger.js';
|
|
4
4
|
import { type ApiSchema, type ApiSchemaFor, schemaHasMethod } from '../../schemas/api.js';
|
|
5
5
|
import { defaultFetch } from './fetch.js';
|
|
6
6
|
|
package/src/log/index.ts
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type LogLevel, LogLevels } from './log-levels.js';
|
|
2
|
+
|
|
3
|
+
export type LogFilters = [string, LogLevel][];
|
|
4
|
+
|
|
5
|
+
export function getLogLevelFromFilters(filters: LogFilters, module: string): LogLevel | undefined {
|
|
6
|
+
for (const [filterModule, level] of filters) {
|
|
7
|
+
if (module.startsWith(filterModule)) {
|
|
8
|
+
return level as LogLevel;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function assertLogLevel(level: string): asserts level is LogLevel {
|
|
15
|
+
if (!LogLevels.includes(level as LogLevel)) {
|
|
16
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function parseEnv(env: string | undefined, defaultLevel: LogLevel): [LogLevel, LogFilters] {
|
|
21
|
+
if (!env) {
|
|
22
|
+
return [defaultLevel, []];
|
|
23
|
+
}
|
|
24
|
+
const [level] = env.split(';', 1);
|
|
25
|
+
assertLogLevel(level);
|
|
26
|
+
return [level, parseFilters(env.slice(level.length + 1))];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseFilters(definition: string | undefined): LogFilters {
|
|
30
|
+
if (!definition) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const statements = definition.split(';');
|
|
35
|
+
const filters: LogFilters = [];
|
|
36
|
+
for (const statement of statements) {
|
|
37
|
+
const [level] = statement.split(':', 1);
|
|
38
|
+
const modules = statement.slice(level.length + 1);
|
|
39
|
+
if (!modules || !level) {
|
|
40
|
+
throw new Error(`Invalid log filter statement: ${statement}`);
|
|
41
|
+
}
|
|
42
|
+
const sanitizedLevel = level.trim().toLowerCase();
|
|
43
|
+
assertLogLevel(sanitizedLevel);
|
|
44
|
+
for (const module of modules.split(',')) {
|
|
45
|
+
filters.push([module.trim().toLowerCase(), sanitizedLevel as LogLevel | 'silent']);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return filters.reverse();
|
|
49
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { createColors } from 'colorette';
|
|
2
|
+
import isNode from 'detect-node';
|
|
3
|
+
import { pino, symbols } from 'pino';
|
|
4
|
+
import pretty from 'pino-pretty';
|
|
5
|
+
import { type Writable } from 'stream';
|
|
6
|
+
import { inspect } from 'util';
|
|
7
|
+
|
|
8
|
+
import { compactArray } from '../collection/array.js';
|
|
9
|
+
import { getLogLevelFromFilters, parseEnv } from './log-filters.js';
|
|
10
|
+
import { type LogLevel } from './log-levels.js';
|
|
11
|
+
import { type LogData, type LogFn } from './log_fn.js';
|
|
12
|
+
|
|
13
|
+
// TODO(palla/log): Rename to createLogger
|
|
14
|
+
export function createDebugLogger(module: string): DebugLogger {
|
|
15
|
+
// TODO(palla/log): Rename all module names to remove the aztec prefix
|
|
16
|
+
const pinoLogger = logger.child(
|
|
17
|
+
{ module: module.replace(/^aztec:/, '') },
|
|
18
|
+
{ level: getLogLevelFromFilters(logFilters, module) },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// We check manually for isLevelEnabled to avoid calling processLogData unnecessarily.
|
|
22
|
+
// Note that isLevelEnabled is missing from the browser version of pino.
|
|
23
|
+
const logFn = (level: LogLevel, msg: string, data?: LogData) =>
|
|
24
|
+
isLevelEnabled(pinoLogger, level) && pinoLogger[level](processLogData(data ?? {}), msg);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
silent: () => {},
|
|
28
|
+
// TODO(palla/log): Should we move err to data instead of the text message?
|
|
29
|
+
/** Log as fatal. Use when an error has brought down the system. */
|
|
30
|
+
fatal: (msg: string, err?: unknown, data?: LogData) => logFn('fatal', formatErr(msg, err), data),
|
|
31
|
+
/** Log as error. Use for errors in general. */
|
|
32
|
+
error: (msg: string, err?: unknown, data?: LogData) => logFn('error', formatErr(msg, err), data),
|
|
33
|
+
/** Log as warn. Use for when we stray from the happy path. */
|
|
34
|
+
warn: (msg: string, data?: LogData) => logFn('warn', msg, data),
|
|
35
|
+
/** Log as info. Use for providing an operator with info on what the system is doing. */
|
|
36
|
+
info: (msg: string, data?: LogData) => logFn('info', msg, data),
|
|
37
|
+
/** Log as verbose. Use for when we need additional insight on what a subsystem is doing. */
|
|
38
|
+
verbose: (msg: string, data?: LogData) => logFn('verbose', msg, data),
|
|
39
|
+
/** Log as debug. Use for when we need debugging info to troubleshoot an issue on a specific component. */
|
|
40
|
+
debug: (msg: string, data?: LogData) => logFn('debug', msg, data),
|
|
41
|
+
/** Log as trace. Use for when we want to denial-of-service any recipient of the logs. */
|
|
42
|
+
trace: (msg: string, data?: LogData) => logFn('trace', msg, data),
|
|
43
|
+
level: pinoLogger.level as LogLevel,
|
|
44
|
+
isLevelEnabled: (level: LogLevel) => isLevelEnabled(pinoLogger, level),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Allow global hooks for processing log data.
|
|
49
|
+
// Used for injecting OTEL trace_id in telemetry client.
|
|
50
|
+
type LogDataHandler = (data: LogData) => LogData;
|
|
51
|
+
const logDataHandlers: LogDataHandler[] = [];
|
|
52
|
+
|
|
53
|
+
export function addLogDataHandler(handler: LogDataHandler): void {
|
|
54
|
+
logDataHandlers.push(handler);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function processLogData(data: LogData): LogData {
|
|
58
|
+
return logDataHandlers.reduce((accum, handler) => handler(accum), data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Patch isLevelEnabled missing from pino/browser.
|
|
62
|
+
function isLevelEnabled(logger: pino.Logger<'verbose', boolean>, level: LogLevel): boolean {
|
|
63
|
+
return typeof logger.isLevelEnabled === 'function'
|
|
64
|
+
? logger.isLevelEnabled(level)
|
|
65
|
+
: logger.levels.values[level] >= logger.levels.values[logger.level];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Load log levels from environment variables.
|
|
69
|
+
const defaultLogLevel = process.env.NODE_ENV === 'test' ? 'silent' : 'info';
|
|
70
|
+
const [logLevel, logFilters] = parseEnv(process.env.LOG_LEVEL, defaultLogLevel);
|
|
71
|
+
|
|
72
|
+
// Transport options for pretty logging to stderr via pino-pretty.
|
|
73
|
+
const useColor = true;
|
|
74
|
+
const { bold, reset } = createColors({ useColor });
|
|
75
|
+
const pinoPrettyOpts = {
|
|
76
|
+
destination: 2,
|
|
77
|
+
sync: true,
|
|
78
|
+
colorize: useColor,
|
|
79
|
+
ignore: 'module,pid,hostname,trace_id,span_id,trace_flags',
|
|
80
|
+
messageFormat: `${bold('{module}')} ${reset('{msg}')}`,
|
|
81
|
+
customLevels: 'fatal:60,error:50,warn:40,info:30,verbose:25,debug:20,trace:10',
|
|
82
|
+
customColors: 'fatal:bgRed,error:red,warn:yellow,info:green,verbose:magenta,debug:blue,trace:gray',
|
|
83
|
+
minimumLevel: 'trace' as const,
|
|
84
|
+
};
|
|
85
|
+
const prettyTransport: pino.TransportSingleOptions = {
|
|
86
|
+
target: 'pino-pretty',
|
|
87
|
+
options: pinoPrettyOpts,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Transport for vanilla stdio logging as JSON.
|
|
91
|
+
const stdioTransport: pino.TransportSingleOptions = {
|
|
92
|
+
target: 'pino/file',
|
|
93
|
+
options: { destination: 2 },
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Define custom logging levels for pino.
|
|
97
|
+
const customLevels = { verbose: 25 };
|
|
98
|
+
const pinoOpts = { customLevels, useOnlyCustomLevels: false, level: logLevel };
|
|
99
|
+
|
|
100
|
+
export const levels = {
|
|
101
|
+
labels: { ...pino.levels.labels, ...Object.fromEntries(Object.entries(customLevels).map(e => e.reverse())) },
|
|
102
|
+
values: { ...pino.levels.values, ...customLevels },
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Transport for OpenTelemetry logging. While defining this here is an abstraction leakage since this
|
|
106
|
+
// should live in the telemetry-client, it is necessary to ensure that the logger is initialized with
|
|
107
|
+
// the correct transport. Tweaking transports of a live pino instance is tricky, and creating a new instance
|
|
108
|
+
// would mean that all child loggers created before the telemetry-client is initialized would not have
|
|
109
|
+
// this transport configured. Note that the target is defined as the export in the telemetry-client,
|
|
110
|
+
// since pino will load this transport separately on a worker thread, to minimize disruption to the main loop.
|
|
111
|
+
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT;
|
|
112
|
+
const otelOpts = { levels };
|
|
113
|
+
const otelTransport: pino.TransportSingleOptions = {
|
|
114
|
+
target: '@aztec/telemetry-client/otel-pino-stream',
|
|
115
|
+
options: otelOpts,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function makeLogger() {
|
|
119
|
+
if (!isNode) {
|
|
120
|
+
// We are on the browser
|
|
121
|
+
return pino({ ...pinoOpts, browser: { asObject: false } });
|
|
122
|
+
} else if (process.env.JEST_WORKER_ID) {
|
|
123
|
+
// We are on jest, so we need sync logging. We stream to stderr with pretty.
|
|
124
|
+
return pino(pinoOpts, pretty(pinoPrettyOpts));
|
|
125
|
+
} else {
|
|
126
|
+
// Regular nodejs with transports on worker thread, using pino-pretty for console logging if LOG_JSON
|
|
127
|
+
// is not set, and an optional OTLP transport if the OTLP endpoint is provided.
|
|
128
|
+
const targets: pino.TransportSingleOptions[] = compactArray([
|
|
129
|
+
['1', 'true', 'TRUE'].includes(process.env.LOG_JSON ?? '') ? stdioTransport : prettyTransport,
|
|
130
|
+
otlpEndpoint ? otelTransport : undefined,
|
|
131
|
+
]);
|
|
132
|
+
return pino(pinoOpts, pino.transport({ targets }));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const logger = makeLogger();
|
|
137
|
+
|
|
138
|
+
// Log the logger configuration.
|
|
139
|
+
logger.verbose(
|
|
140
|
+
{
|
|
141
|
+
module: 'logger',
|
|
142
|
+
...logFilters.reduce((accum, [module, level]) => ({ ...accum, [`log.${module}`]: level }), {}),
|
|
143
|
+
},
|
|
144
|
+
isNode
|
|
145
|
+
? `Logger initialized with level ${logLevel}` + (otlpEndpoint ? ` with OTLP exporter to ${otlpEndpoint}` : '')
|
|
146
|
+
: `Browser console logger initialized with level ${logLevel}`,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Registers an additional destination to the pino logger.
|
|
151
|
+
* Use only when working with destinations, not worker transports.
|
|
152
|
+
*/
|
|
153
|
+
export function registerLoggingStream(stream: Writable): void {
|
|
154
|
+
logger.verbose({ module: 'logger' }, `Registering additional logging stream`);
|
|
155
|
+
const original = (logger as any)[symbols.streamSym];
|
|
156
|
+
const destination = original
|
|
157
|
+
? pino.multistream(
|
|
158
|
+
[
|
|
159
|
+
// Set streams to lowest logging level, and control actual logging from the parent logger
|
|
160
|
+
// otherwise streams default to info and refuse to log anything below that.
|
|
161
|
+
{ level: 'trace', stream: original },
|
|
162
|
+
{ level: 'trace', stream },
|
|
163
|
+
],
|
|
164
|
+
{ levels: levels.values },
|
|
165
|
+
)
|
|
166
|
+
: stream;
|
|
167
|
+
(logger as any)[symbols.streamSym] = destination;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Log function that accepts an exception object */
|
|
171
|
+
type ErrorLogFn = (msg: string, err?: Error | unknown, data?: LogData) => void;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Logger that supports multiple severity levels.
|
|
175
|
+
*/
|
|
176
|
+
export type Logger = { [K in LogLevel]: LogFn } & { /** Error log function */ error: ErrorLogFn } & {
|
|
177
|
+
level: LogLevel;
|
|
178
|
+
isLevelEnabled: (level: LogLevel) => boolean;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Logger that supports multiple severity levels and can be called directly to issue a debug statement.
|
|
183
|
+
* Intended as a drop-in replacement for the debug module.
|
|
184
|
+
* TODO(palla/log): Remove this alias
|
|
185
|
+
*/
|
|
186
|
+
export type DebugLogger = Logger;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Concatenates a log message and an exception.
|
|
190
|
+
* @param msg - Log message
|
|
191
|
+
* @param err - Error to log
|
|
192
|
+
* @returns A string with both the log message and the error message.
|
|
193
|
+
*/
|
|
194
|
+
function formatErr(msg: string, err?: Error | unknown): string {
|
|
195
|
+
return err ? `${msg}: ${inspect(err)}` : msg;
|
|
196
|
+
}
|
package/dest/log/logger.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { type LogData, type LogFn } from './log_fn.js';
|
|
2
|
-
declare const LogLevels: readonly ["silent", "error", "warn", "info", "verbose", "debug"];
|
|
3
|
-
/**
|
|
4
|
-
* A valid log severity level.
|
|
5
|
-
*/
|
|
6
|
-
export type LogLevel = (typeof LogLevels)[number];
|
|
7
|
-
export declare let currentLevel: "silent" | "error" | "warn" | "info" | "verbose" | "debug";
|
|
8
|
-
/** Log function that accepts an exception object */
|
|
9
|
-
type ErrorLogFn = (msg: string, err?: Error | unknown, data?: LogData) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Logger that supports multiple severity levels.
|
|
12
|
-
*/
|
|
13
|
-
export type Logger = {
|
|
14
|
-
[K in LogLevel]: LogFn;
|
|
15
|
-
} & {
|
|
16
|
-
error: ErrorLogFn;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Logger that supports multiple severity levels and can be called directly to issue a debug statement.
|
|
20
|
-
* Intended as a drop-in replacement for the debug module.
|
|
21
|
-
*/
|
|
22
|
-
export type DebugLogger = Logger;
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new DebugLogger for the current module, defaulting to the LOG_LEVEL env var.
|
|
25
|
-
* If DEBUG="[module]" env is set, will enable debug logging if the module matches.
|
|
26
|
-
* Uses npm debug for debug level and console.error for other levels.
|
|
27
|
-
* @param name - Name of the module.
|
|
28
|
-
* @param fixedLogData - Additional data to include in the log message.
|
|
29
|
-
* @usage createDebugLogger('aztec:validator');
|
|
30
|
-
* // will always add the validator address to the log labels
|
|
31
|
-
* @returns A debug logger.
|
|
32
|
-
*/
|
|
33
|
-
export declare function createDebugLogger(name: string): DebugLogger;
|
|
34
|
-
/**
|
|
35
|
-
* A function to create a logger that automatically includes fixed data in each log entry.
|
|
36
|
-
* @param debugLogger - The base DebugLogger instance to which we attach fixed log data.
|
|
37
|
-
* @param fixedLogData - The data to be included in every log entry.
|
|
38
|
-
* @returns A DebugLogger with log level methods (error, warn, info, verbose, debug) that
|
|
39
|
-
* automatically attach `fixedLogData` to every log message.
|
|
40
|
-
*/
|
|
41
|
-
export declare function attachedFixedDataToLogger(debugLogger: DebugLogger, fixedLogData: LogData): DebugLogger;
|
|
42
|
-
/** A callback to capture all logs. */
|
|
43
|
-
export type LogHandler = (level: LogLevel, namespace: string, msg: string, data?: LogData) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Registers a callback for all logs, whether they are emitted in the current log level or not.
|
|
46
|
-
* @param handler - Callback to be called on every log.
|
|
47
|
-
*/
|
|
48
|
-
export declare function onLog(handler: LogHandler): void;
|
|
49
|
-
/** Overrides current log level. */
|
|
50
|
-
export declare function setLevel(level: LogLevel): void;
|
|
51
|
-
/**
|
|
52
|
-
* Formats structured log data as a string for console output.
|
|
53
|
-
* @param data - Optional log data.
|
|
54
|
-
*/
|
|
55
|
-
export declare function fmtLogData(data?: LogData): string;
|
|
56
|
-
export {};
|
|
57
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dest/log/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/log/logger.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAEvD,QAAA,MAAM,SAAS,kEAAmE,CAAC;AAEnF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAelD,eAAO,IAAI,YAAY,4DAAgB,CAAC;AAwBxC,oDAAoD;AACpD,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;KAAG,CAAC,IAAI,QAAQ,GAAG,KAAK;CAAE,GAAG;IAA4B,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAElG;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;GASG;AAEH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAqB3D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,GAAG,WAAW,CActG;AAED,sCAAsC;AACtC,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAInG;;;GAGG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,UAAU,QAExC;AAED,mCAAmC;AACnC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,QAEvC;AAkCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAIjD"}
|