@aztec/foundation 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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/array/sorted_array.d.ts +6 -1
- package/dest/array/sorted_array.d.ts.map +1 -1
- package/dest/array/sorted_array.js +18 -15
- package/dest/branded-types/block_number.d.ts +4 -1
- package/dest/branded-types/block_number.d.ts.map +1 -1
- package/dest/branded-types/block_number.js +3 -0
- package/dest/branded-types/index.d.ts +2 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +1 -0
- package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
- package/dest/branded-types/index_within_checkpoint.js +59 -0
- package/dest/buffer/buffer16.d.ts +4 -1
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer32.d.ts +4 -1
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/collection/array.d.ts +12 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +51 -0
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +5 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +14 -0
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +2 -0
- package/dest/crypto/ecdsa/signature.d.ts +10 -1
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.d.ts +1 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +0 -9
- package/dest/crypto/random/randomness_singleton.d.ts +4 -3
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +4 -4
- package/dest/crypto/sync/poseidon/index.d.ts +1 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +0 -8
- package/dest/curves/bls12/point.d.ts +10 -1
- package/dest/curves/bls12/point.d.ts.map +1 -1
- package/dest/curves/grumpkin/point.d.ts +11 -2
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.d.ts +4 -1
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/jest/setup.js +4 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -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 +1 -1
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +21 -4
- package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
- package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
- package/dest/json-rpc/server/api_key_auth.js +57 -0
- package/dest/json-rpc/server/index.d.ts +2 -1
- package/dest/json-rpc/server/index.d.ts.map +1 -1
- package/dest/json-rpc/server/index.js +1 -0
- package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
- package/dest/log/bigint-utils.d.ts +5 -0
- package/dest/log/bigint-utils.d.ts.map +1 -0
- package/dest/log/bigint-utils.js +18 -0
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +3 -0
- package/dest/log/libp2p_logger.d.ts +5 -2
- package/dest/log/libp2p_logger.d.ts.map +1 -1
- package/dest/log/libp2p_logger.js +14 -4
- package/dest/log/log-filters.d.ts +17 -4
- package/dest/log/log-filters.d.ts.map +1 -1
- package/dest/log/log-filters.js +26 -12
- package/dest/log/pino-logger-server.d.ts +9 -0
- package/dest/log/pino-logger-server.d.ts.map +1 -0
- package/dest/log/pino-logger-server.js +18 -0
- package/dest/log/pino-logger.d.ts +37 -8
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +121 -28
- package/dest/queue/base_memory_queue.d.ts +2 -2
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/semaphore.d.ts +5 -1
- package/dest/queue/semaphore.d.ts.map +1 -1
- package/dest/retry/index.d.ts +11 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +11 -0
- package/dest/serialize/buffer_reader.d.ts +14 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +26 -4
- package/dest/serialize/serialize.d.ts +19 -1
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +31 -0
- package/dest/timer/date.d.ts +25 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +33 -0
- package/dest/transport/transport_client.js +2 -2
- package/dest/trees/balanced_merkle_tree_root.d.ts +17 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +2 -17
- package/dest/trees/hasher.d.ts +3 -1
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +10 -5
- package/dest/trees/index.d.ts +4 -4
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +3 -3
- package/dest/trees/membership_witness.d.ts +11 -1
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +9 -0
- package/dest/trees/merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +2 -2
- package/dest/trees/sibling_path.d.ts +2 -1
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -2
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -2
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -1
- package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +3 -7
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +8 -52
- package/dest/trees/unbalanced_tree_store.d.ts +5 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +49 -1
- package/dest/types/index.d.ts +4 -2
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/package.json +25 -4
- package/src/array/sorted_array.ts +22 -17
- package/src/branded-types/block_number.ts +5 -0
- package/src/branded-types/index.ts +1 -0
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/collection/array.ts +52 -0
- package/src/config/env_var.ts +47 -9
- package/src/config/index.ts +17 -0
- package/src/config/network_name.ts +4 -1
- package/src/crypto/poseidon/index.ts +0 -10
- package/src/crypto/random/randomness_singleton.ts +9 -5
- package/src/crypto/sync/poseidon/index.ts +0 -9
- package/src/jest/setup.mjs +4 -1
- package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
- package/src/json-rpc/client/undici.ts +21 -3
- package/src/json-rpc/server/api_key_auth.ts +63 -0
- package/src/json-rpc/server/index.ts +1 -0
- package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
- package/src/log/bigint-utils.ts +22 -0
- package/src/log/gcloud-logger-config.ts +5 -0
- package/src/log/libp2p_logger.ts +12 -5
- package/src/log/log-filters.ts +29 -11
- package/src/log/pino-logger-server.ts +25 -0
- package/src/log/pino-logger.ts +142 -38
- package/src/queue/base_memory_queue.ts +1 -1
- package/src/queue/semaphore.ts +5 -0
- package/src/retry/index.ts +18 -0
- package/src/serialize/buffer_reader.ts +36 -9
- package/src/serialize/serialize.ts +32 -0
- package/src/timer/date.ts +48 -0
- package/src/transport/transport_client.ts +2 -2
- package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +2 -18
- package/src/trees/hasher.ts +9 -0
- package/src/trees/index.ts +3 -3
- package/src/trees/membership_witness.ts +8 -0
- package/src/trees/merkle_tree_calculator.ts +2 -2
- package/src/trees/sibling_path.ts +2 -2
- package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -2
- package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +8 -66
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +6 -1
- package/dest/trees/balanced_merkle_tree.d.ts +0 -22
- package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.96dac018d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
7
|
+
"typedocOptions": {
|
|
8
|
+
"entryPoints": [
|
|
9
|
+
"./src/buffer/index.ts",
|
|
10
|
+
"./src/collection/index.ts",
|
|
11
|
+
"./src/config/index.ts",
|
|
12
|
+
"./src/crypto/random/index.ts",
|
|
13
|
+
"./src/error/index.ts",
|
|
14
|
+
"./src/eth-address/index.ts",
|
|
15
|
+
"./src/json-rpc/index.ts",
|
|
16
|
+
"./src/log/index.ts",
|
|
17
|
+
"./src/retry/index.ts",
|
|
18
|
+
"./src/schemas/index.ts",
|
|
19
|
+
"./src/serialize/index.ts",
|
|
20
|
+
"./src/sleep/index.ts",
|
|
21
|
+
"./src/timer/index.ts",
|
|
22
|
+
"./src/types/index.ts"
|
|
23
|
+
],
|
|
24
|
+
"name": "Foundation",
|
|
25
|
+
"tsconfig": "./tsconfig.json"
|
|
26
|
+
},
|
|
7
27
|
"exports": {
|
|
8
28
|
"./eslint": "./eslint.config.js",
|
|
9
29
|
"./eslint.docs": "./eslint.config.docs.js",
|
|
@@ -51,6 +71,7 @@
|
|
|
51
71
|
"./iterable": "./dest/iterable/index.js",
|
|
52
72
|
"./iterator": "./dest/iterator/index.js",
|
|
53
73
|
"./log": "./dest/log/index.js",
|
|
74
|
+
"./log/server": "./dest/log/pino-logger-server.js",
|
|
54
75
|
"./mutex": "./dest/mutex/index.js",
|
|
55
76
|
"./retry": "./dest/retry/index.js",
|
|
56
77
|
"./running-promise": "./dest/running-promise/index.js",
|
|
@@ -123,7 +144,7 @@
|
|
|
123
144
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
124
145
|
},
|
|
125
146
|
"dependencies": {
|
|
126
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
147
|
+
"@aztec/bb.js": "0.0.1-commit.96dac018d",
|
|
127
148
|
"@koa/cors": "^5.0.0",
|
|
128
149
|
"@noble/curves": "=1.7.0",
|
|
129
150
|
"@noble/hashes": "^1.6.1",
|
|
@@ -162,11 +183,11 @@
|
|
|
162
183
|
"@types/node": "^22.15.17",
|
|
163
184
|
"@types/pako": "^2.0.0",
|
|
164
185
|
"@types/supertest": "^2.0.12",
|
|
165
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
186
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
166
187
|
"comlink": "^4.4.1",
|
|
167
188
|
"eslint": "^9.26.0",
|
|
168
189
|
"eslint-config-prettier": "^10.1.5",
|
|
169
|
-
"eslint-plugin-import": "^
|
|
190
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
170
191
|
"eslint-plugin-jsdoc": "^50.6.14",
|
|
171
192
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
172
193
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
@@ -21,34 +21,39 @@ export function dedupeSortedArray<T>(arr: T[], cmp: Cmp<T>): void {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function insertIntoSortedArray<T>(arr: T[], item: T, cmp: Cmp<T>, allowDuplicates = true): boolean {
|
|
24
|
+
const index = findInsertionIndexInSortedArray(arr, item, cmp);
|
|
25
|
+
|
|
26
|
+
if (!allowDuplicates) {
|
|
27
|
+
// Check element before insertion point (upper bound returns index after equal elements)
|
|
28
|
+
if (index > 0 && cmp(arr[index - 1], item) === 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
arr.splice(index, 0, item);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Finds the index where needle would be inserted to maintain sorted order.
|
|
39
|
+
* Returns the count of elements less than or equal to needle.
|
|
40
|
+
*/
|
|
41
|
+
export function findInsertionIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
|
|
24
42
|
let start = 0;
|
|
25
|
-
let end =
|
|
43
|
+
let end = values.length;
|
|
26
44
|
|
|
27
45
|
while (start < end) {
|
|
28
46
|
const mid = start + (((end - start) / 2) | 0);
|
|
29
|
-
const comparison = cmp(
|
|
47
|
+
const comparison = cmp(values[mid], needle);
|
|
30
48
|
|
|
31
|
-
if (comparison
|
|
49
|
+
if (comparison <= 0) {
|
|
32
50
|
start = mid + 1;
|
|
33
51
|
} else {
|
|
34
52
|
end = mid;
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
55
|
|
|
38
|
-
|
|
39
|
-
// Check element at insertion point
|
|
40
|
-
if (start < arr.length && cmp(arr[start], item) === 0) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Check element before insertion point (in case we landed after duplicates)
|
|
45
|
-
if (start > 0 && cmp(arr[start - 1], item) === 0) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
arr.splice(start, 0, item);
|
|
51
|
-
return true;
|
|
56
|
+
return start;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
export function findIndexInSortedArray<T, N>(values: T[], needle: N, cmp: (a: T, b: N) => number): number {
|
|
@@ -87,6 +87,11 @@ BlockNumber.isValid = function (value: unknown): value is BlockNumber {
|
|
|
87
87
|
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
/** Increments a BlockNumber by a given value. */
|
|
91
|
+
BlockNumber.add = function (bn: BlockNumber, increment: number): BlockNumber {
|
|
92
|
+
return BlockNumber(bn + increment);
|
|
93
|
+
};
|
|
94
|
+
|
|
90
95
|
/**
|
|
91
96
|
* The zero block value (genesis block).
|
|
92
97
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BlockNumber, BlockNumberSchema, BlockNumberPositiveSchema } from './block_number.js';
|
|
2
2
|
export { CheckpointNumber, CheckpointNumberSchema, CheckpointNumberPositiveSchema } from './checkpoint_number.js';
|
|
3
3
|
export { EpochNumber, EpochNumberSchema } from './epoch.js';
|
|
4
|
+
export { IndexWithinCheckpoint, IndexWithinCheckpointSchema } from './index_within_checkpoint.js';
|
|
4
5
|
export { SlotNumber, SlotNumberSchema } from './slot.js';
|
|
5
6
|
|
|
6
7
|
export type { Branded } from './types.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { Branded } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A branded type representing the index of a block within a checkpoint.
|
|
7
|
+
* The first block in a checkpoint has index 0, the second has index 1, etc.
|
|
8
|
+
*
|
|
9
|
+
* This is a nominal type backed by a number, but TypeScript will treat it as
|
|
10
|
+
* incompatible with plain numbers and other branded numeric types.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const index = IndexWithinCheckpoint(0);
|
|
15
|
+
* const plainNumber: number = index; // OK - IndexWithinCheckpoint is assignable to number
|
|
16
|
+
* const indexFromNumber: IndexWithinCheckpoint = 0; // ERROR - number is not assignable to IndexWithinCheckpoint
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type IndexWithinCheckpoint = Branded<number, 'IndexWithinCheckpoint'>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates an IndexWithinCheckpoint from a number.
|
|
23
|
+
* @param value - The index (must be a non-negative integer)
|
|
24
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
25
|
+
* @throws If the value is negative or not an integer
|
|
26
|
+
*/
|
|
27
|
+
export function IndexWithinCheckpoint(value: number): IndexWithinCheckpoint {
|
|
28
|
+
if (!Number.isInteger(value)) {
|
|
29
|
+
throw new Error(`IndexWithinCheckpoint must be an integer, got ${value}`);
|
|
30
|
+
}
|
|
31
|
+
if (value < 0) {
|
|
32
|
+
throw new Error(`IndexWithinCheckpoint must be non-negative, got ${value}`);
|
|
33
|
+
}
|
|
34
|
+
return value as IndexWithinCheckpoint;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an IndexWithinCheckpoint from a bigint.
|
|
39
|
+
* @param value - The index as bigint (must be a non-negative integer within safe integer range)
|
|
40
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
41
|
+
* @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
|
|
42
|
+
*/
|
|
43
|
+
IndexWithinCheckpoint.fromBigInt = function (value: bigint): IndexWithinCheckpoint {
|
|
44
|
+
if (value < 0n) {
|
|
45
|
+
throw new Error(`IndexWithinCheckpoint must be non-negative, got ${value}`);
|
|
46
|
+
}
|
|
47
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
48
|
+
throw new Error(`IndexWithinCheckpoint ${value} exceeds MAX_SAFE_INTEGER`);
|
|
49
|
+
}
|
|
50
|
+
return Number(value) as IndexWithinCheckpoint;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates an IndexWithinCheckpoint from a string.
|
|
55
|
+
* @param value - The index as a string
|
|
56
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
57
|
+
* @throws If the string cannot be parsed as a valid index
|
|
58
|
+
*/
|
|
59
|
+
IndexWithinCheckpoint.fromString = function (value: string): IndexWithinCheckpoint {
|
|
60
|
+
const parsed = parseInt(value, 10);
|
|
61
|
+
if (isNaN(parsed)) {
|
|
62
|
+
throw new Error(`Cannot parse IndexWithinCheckpoint from string: ${value}`);
|
|
63
|
+
}
|
|
64
|
+
return IndexWithinCheckpoint(parsed);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if a value is a valid IndexWithinCheckpoint.
|
|
69
|
+
* Note: At runtime, an IndexWithinCheckpoint is just a number, so this checks if the value
|
|
70
|
+
* is a non-negative integer.
|
|
71
|
+
*/
|
|
72
|
+
IndexWithinCheckpoint.isValid = function (value: unknown): value is IndexWithinCheckpoint {
|
|
73
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The zero index value (first block in checkpoint).
|
|
78
|
+
*/
|
|
79
|
+
IndexWithinCheckpoint.ZERO = IndexWithinCheckpoint(0);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Zod schema for parsing and validating IndexWithinCheckpoint values.
|
|
83
|
+
* Accepts numbers, bigints, or strings and coerces them to IndexWithinCheckpoint.
|
|
84
|
+
*/
|
|
85
|
+
export const IndexWithinCheckpointSchema = z
|
|
86
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
87
|
+
.pipe(z.coerce.number().int().min(0))
|
|
88
|
+
.transform(value => IndexWithinCheckpoint(value));
|
package/src/collection/array.ts
CHANGED
|
@@ -250,6 +250,58 @@ export function chunk<T>(items: T[], chunkSize: number): T[][] {
|
|
|
250
250
|
return chunks;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Splits the given array into chunks of the given size, wrapping around to the beginning
|
|
255
|
+
* if the last chunk would be smaller than the requested size.
|
|
256
|
+
* Returns empty array for empty input. Returns single chunk with all items if chunkSize <= 0.
|
|
257
|
+
*/
|
|
258
|
+
export function chunkWrapAround<T>(items: T[], chunkSize: number): T[][] {
|
|
259
|
+
if (items.length === 0) {
|
|
260
|
+
return [];
|
|
261
|
+
}
|
|
262
|
+
if (chunkSize <= 0 || items.length <= chunkSize) {
|
|
263
|
+
return [items];
|
|
264
|
+
}
|
|
265
|
+
const remainder = items.length % chunkSize;
|
|
266
|
+
if (remainder === 0) {
|
|
267
|
+
return chunk(items, chunkSize);
|
|
268
|
+
}
|
|
269
|
+
const wrapAroundCount = chunkSize - remainder;
|
|
270
|
+
const wrappedItems = [...items, ...items.slice(0, wrapAroundCount)];
|
|
271
|
+
return chunk(wrappedItems, chunkSize);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const UNINITIALIZED = Symbol('uninitialized');
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Splits the given iterable into chunks based on the key returned by the given function.
|
|
278
|
+
* Items must be contiguous to be included in the same chunk.
|
|
279
|
+
*/
|
|
280
|
+
export function chunkBy<T, U>(items: T[], fn: (item: T) => U): T[][] {
|
|
281
|
+
const chunks: T[][] = [];
|
|
282
|
+
let currentChunk: T[] = [];
|
|
283
|
+
let currentKey: U | typeof UNINITIALIZED = UNINITIALIZED;
|
|
284
|
+
|
|
285
|
+
for (const item of items) {
|
|
286
|
+
const key = fn(item);
|
|
287
|
+
if (currentKey === UNINITIALIZED || key !== currentKey) {
|
|
288
|
+
if (currentChunk.length > 0) {
|
|
289
|
+
chunks.push(currentChunk);
|
|
290
|
+
}
|
|
291
|
+
currentChunk = [item];
|
|
292
|
+
currentKey = key;
|
|
293
|
+
} else {
|
|
294
|
+
currentChunk.push(item);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (currentChunk.length > 0) {
|
|
299
|
+
chunks.push(currentChunk);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return chunks;
|
|
303
|
+
}
|
|
304
|
+
|
|
253
305
|
/** Partitions the given iterable into two arrays based on the predicate. */
|
|
254
306
|
export function partition<T>(items: T[], predicate: (item: T) => boolean): [T[], T[]] {
|
|
255
307
|
const pass: T[] = [];
|
package/src/config/env_var.ts
CHANGED
|
@@ -12,6 +12,9 @@ export type EnvVar =
|
|
|
12
12
|
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
|
|
13
13
|
| 'ARCHIVER_BATCH_SIZE'
|
|
14
14
|
| 'AZTEC_ADMIN_PORT'
|
|
15
|
+
| 'AZTEC_ADMIN_API_KEY_HASH'
|
|
16
|
+
| 'AZTEC_DISABLE_ADMIN_API_KEY'
|
|
17
|
+
| 'AZTEC_RESET_ADMIN_API_KEY'
|
|
15
18
|
| 'AZTEC_NODE_ADMIN_URL'
|
|
16
19
|
| 'AZTEC_NODE_URL'
|
|
17
20
|
| 'AZTEC_PORT'
|
|
@@ -47,7 +50,10 @@ export type EnvVar =
|
|
|
47
50
|
| 'BOT_TX_MINED_WAIT_SECONDS'
|
|
48
51
|
| 'BOT_MAX_CONSECUTIVE_ERRORS'
|
|
49
52
|
| 'BOT_STOP_WHEN_UNHEALTHY'
|
|
50
|
-
| '
|
|
53
|
+
| 'BOT_MODE'
|
|
54
|
+
| 'BOT_L2_TO_L1_MESSAGES_PER_TX'
|
|
55
|
+
| 'BOT_L1_TO_L2_SEED_COUNT'
|
|
56
|
+
| 'BOT_L1_TO_L2_SEED_INTERVAL'
|
|
51
57
|
| 'COINBASE'
|
|
52
58
|
| 'CRS_PATH'
|
|
53
59
|
| 'DATA_DIRECTORY'
|
|
@@ -64,6 +70,7 @@ export type EnvVar =
|
|
|
64
70
|
| 'PUBLIC_DATA_TREE_MAP_SIZE_KB'
|
|
65
71
|
| 'DEBUG'
|
|
66
72
|
| 'DEBUG_P2P_DISABLE_COLOCATION_PENALTY'
|
|
73
|
+
| 'ENABLE_PROVER_NODE'
|
|
67
74
|
| 'ETHEREUM_HOSTS'
|
|
68
75
|
| 'ETHEREUM_DEBUG_HOSTS'
|
|
69
76
|
| 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS'
|
|
@@ -75,8 +82,10 @@ export type EnvVar =
|
|
|
75
82
|
| 'L1_CONSENSUS_HOST_URLS'
|
|
76
83
|
| 'L1_CONSENSUS_HOST_API_KEYS'
|
|
77
84
|
| 'L1_CONSENSUS_HOST_API_KEY_HEADERS'
|
|
85
|
+
| 'L1_TX_FAILED_STORE'
|
|
78
86
|
| 'LOG_JSON'
|
|
79
87
|
| 'LOG_MULTILINE'
|
|
88
|
+
| 'LOG_NO_COLOR_PER_ACTOR'
|
|
80
89
|
| 'LOG_LEVEL'
|
|
81
90
|
| 'MNEMONIC'
|
|
82
91
|
| 'NETWORK'
|
|
@@ -94,7 +103,12 @@ export type EnvVar =
|
|
|
94
103
|
| 'PUBLIC_OTEL_INCLUDE_METRICS'
|
|
95
104
|
| 'PUBLIC_OTEL_COLLECT_FROM'
|
|
96
105
|
| 'PUBLIC_OTEL_OPT_OUT'
|
|
106
|
+
| 'P2P_BATCH_TX_REQUESTER_SMART_PARALLEL_WORKER_COUNT'
|
|
107
|
+
| 'P2P_BATCH_TX_REQUESTER_DUMB_PARALLEL_WORKER_COUNT'
|
|
108
|
+
| 'P2P_BATCH_TX_REQUESTER_TX_BATCH_SIZE'
|
|
109
|
+
| 'P2P_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD'
|
|
97
110
|
| 'P2P_BLOCK_CHECK_INTERVAL_MS'
|
|
111
|
+
| 'P2P_SLOT_CHECK_INTERVAL_MS'
|
|
98
112
|
| 'P2P_BLOCK_REQUEST_BATCH_SIZE'
|
|
99
113
|
| 'P2P_BOOTSTRAP_NODE_ENR_VERSION_CHECK'
|
|
100
114
|
| 'P2P_BOOTSTRAP_NODES_AS_FULL_PEERS'
|
|
@@ -135,9 +149,9 @@ export type EnvVar =
|
|
|
135
149
|
| 'P2P_PREFERRED_PEERS'
|
|
136
150
|
| 'P2P_MAX_PENDING_TX_COUNT'
|
|
137
151
|
| 'P2P_SEEN_MSG_CACHE_SIZE'
|
|
138
|
-
| 'P2P_DROP_TX'
|
|
139
152
|
| 'P2P_DROP_TX_CHANCE'
|
|
140
153
|
| 'P2P_TX_POOL_DELETE_TXS_AFTER_REORG'
|
|
154
|
+
| 'P2P_MIN_TX_POOL_AGE_MS'
|
|
141
155
|
| 'DEBUG_P2P_INSTRUMENT_MESSAGES'
|
|
142
156
|
| 'PEER_ID_PRIVATE_KEY'
|
|
143
157
|
| 'PEER_ID_PRIVATE_KEY_PATH'
|
|
@@ -151,7 +165,10 @@ export type EnvVar =
|
|
|
151
165
|
| 'PROVER_BROKER_BATCH_INTERVAL_MS'
|
|
152
166
|
| 'PROVER_BROKER_BATCH_SIZE'
|
|
153
167
|
| 'PROVER_BROKER_MAX_EPOCHS_TO_KEEP_RESULTS_FOR'
|
|
168
|
+
| 'PROVER_BROKER_DEBUG_REPLAY_ENABLED'
|
|
169
|
+
| 'PROVER_CANCEL_JOBS_ON_STOP'
|
|
154
170
|
| 'PROVER_COORDINATION_NODE_URLS'
|
|
171
|
+
| 'PROVER_PROOF_STORE'
|
|
155
172
|
| 'PROVER_FAILED_PROOF_STORE'
|
|
156
173
|
| 'PROVER_NODE_FAILED_EPOCH_STORE'
|
|
157
174
|
| 'PROVER_NODE_DISABLE_PROOF_PUBLISH'
|
|
@@ -175,6 +192,7 @@ export type EnvVar =
|
|
|
175
192
|
| 'PROVER_TEST_VERIFICATION_DELAY_MS'
|
|
176
193
|
| 'PXE_L2_BLOCK_BATCH_SIZE'
|
|
177
194
|
| 'PXE_PROVER_ENABLED'
|
|
195
|
+
| 'PXE_SYNC_CHAIN_TIP'
|
|
178
196
|
| 'RPC_MAX_BATCH_SIZE'
|
|
179
197
|
| 'RPC_MAX_BODY_SIZE'
|
|
180
198
|
| 'RPC_SIMULATE_PUBLIC_MAX_GAS_LIMIT'
|
|
@@ -198,9 +216,11 @@ export type EnvVar =
|
|
|
198
216
|
| 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT'
|
|
199
217
|
| 'SEQ_ATTESTATION_PROPAGATION_TIME'
|
|
200
218
|
| 'SEQ_BLOCK_DURATION_MS'
|
|
219
|
+
| 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT'
|
|
201
220
|
| 'SEQ_BUILD_CHECKPOINT_IF_EMPTY'
|
|
202
221
|
| 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER'
|
|
203
222
|
| 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER'
|
|
223
|
+
| 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT'
|
|
204
224
|
| 'SLASH_MIN_PENALTY_PERCENTAGE'
|
|
205
225
|
| 'SLASH_MAX_PENALTY_PERCENTAGE'
|
|
206
226
|
| 'SLASH_VALIDATORS_ALWAYS'
|
|
@@ -211,6 +231,8 @@ export type EnvVar =
|
|
|
211
231
|
| 'SLASH_INACTIVITY_TARGET_PERCENTAGE'
|
|
212
232
|
| 'SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD'
|
|
213
233
|
| 'SLASH_INVALID_BLOCK_PENALTY'
|
|
234
|
+
| 'SLASH_DUPLICATE_PROPOSAL_PENALTY'
|
|
235
|
+
| 'SLASH_DUPLICATE_ATTESTATION_PENALTY'
|
|
214
236
|
| 'SLASH_OVERRIDE_PAYLOAD'
|
|
215
237
|
| 'SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY'
|
|
216
238
|
| 'SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY'
|
|
@@ -235,6 +257,20 @@ export type EnvVar =
|
|
|
235
257
|
| 'TX_COLLECTION_FAST_MAX_PARALLEL_REQUESTS_PER_NODE'
|
|
236
258
|
| 'TX_COLLECTION_NODE_RPC_MAX_BATCH_SIZE'
|
|
237
259
|
| 'TX_COLLECTION_NODE_RPC_URLS'
|
|
260
|
+
| 'TX_COLLECTION_MISSING_TXS_COLLECTOR_TYPE'
|
|
261
|
+
| 'TX_COLLECTION_FILE_STORE_URLS'
|
|
262
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_DELAY_MS'
|
|
263
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_DELAY_MS'
|
|
264
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_WORKER_COUNT'
|
|
265
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_WORKER_COUNT'
|
|
266
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_BASE_MS'
|
|
267
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_BASE_MS'
|
|
268
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_MAX_MS'
|
|
269
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_MAX_MS'
|
|
270
|
+
| 'TX_FILE_STORE_URL'
|
|
271
|
+
| 'TX_FILE_STORE_UPLOAD_CONCURRENCY'
|
|
272
|
+
| 'TX_FILE_STORE_MAX_QUEUE_SIZE'
|
|
273
|
+
| 'TX_FILE_STORE_ENABLED'
|
|
238
274
|
| 'TX_PUBLIC_SETUP_ALLOWLIST'
|
|
239
275
|
| 'TXE_PORT'
|
|
240
276
|
| 'TRANSACTIONS_DISABLED'
|
|
@@ -246,10 +282,10 @@ export type EnvVar =
|
|
|
246
282
|
| 'VALIDATOR_ADDRESSES'
|
|
247
283
|
| 'ROLLUP_VERSION'
|
|
248
284
|
| 'WS_BLOCK_CHECK_INTERVAL_MS'
|
|
249
|
-
| 'WS_PROVEN_BLOCKS_ONLY'
|
|
250
285
|
| 'WS_BLOCK_REQUEST_BATCH_SIZE'
|
|
251
286
|
| 'L1_READER_VIEM_POLLING_INTERVAL_MS'
|
|
252
287
|
| 'WS_DATA_DIRECTORY'
|
|
288
|
+
| 'WS_NUM_HISTORIC_CHECKPOINTS'
|
|
253
289
|
| 'WS_NUM_HISTORIC_BLOCKS'
|
|
254
290
|
| 'ETHEREUM_SLOT_DURATION'
|
|
255
291
|
| 'AZTEC_SLOT_DURATION'
|
|
@@ -264,6 +300,7 @@ export type EnvVar =
|
|
|
264
300
|
| 'AZTEC_LOCAL_EJECTION_THRESHOLD'
|
|
265
301
|
| 'AZTEC_MANA_TARGET'
|
|
266
302
|
| 'AZTEC_PROVING_COST_PER_MANA'
|
|
303
|
+
| 'AZTEC_INITIAL_ETH_PER_FEE_ASSET'
|
|
267
304
|
| 'AZTEC_SLASHING_QUORUM'
|
|
268
305
|
| 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS'
|
|
269
306
|
| 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS'
|
|
@@ -277,6 +314,7 @@ export type EnvVar =
|
|
|
277
314
|
| 'AZTEC_SLASHER_FLAVOR'
|
|
278
315
|
| 'AZTEC_GOVERNANCE_PROPOSER_QUORUM'
|
|
279
316
|
| 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE'
|
|
317
|
+
| 'AZTEC_GOVERNANCE_VOTING_DURATION'
|
|
280
318
|
| 'AZTEC_EXIT_DELAY_SECONDS'
|
|
281
319
|
| 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
|
|
282
320
|
| 'L1_GAS_PRICE_MAX'
|
|
@@ -303,7 +341,6 @@ export type EnvVar =
|
|
|
303
341
|
| 'K8S_POD_UID'
|
|
304
342
|
| 'K8S_NAMESPACE_NAME'
|
|
305
343
|
| 'VALIDATOR_REEXECUTE_DEADLINE_MS'
|
|
306
|
-
| 'ALWAYS_REEXECUTE_BLOCK_PROPOSALS'
|
|
307
344
|
| 'AUTO_UPDATE'
|
|
308
345
|
| 'AUTO_UPDATE_URL'
|
|
309
346
|
| 'WEB3_SIGNER_URL'
|
|
@@ -313,11 +350,12 @@ export type EnvVar =
|
|
|
313
350
|
| 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS'
|
|
314
351
|
| 'LEGACY_BLS_CLI'
|
|
315
352
|
| 'DEBUG_FORCE_TX_PROOF_VERIFICATION'
|
|
316
|
-
| '
|
|
317
|
-
| '
|
|
318
|
-
| '
|
|
319
|
-
| '
|
|
320
|
-
| '
|
|
353
|
+
| 'VALIDATOR_HA_SIGNING_ENABLED'
|
|
354
|
+
| 'VALIDATOR_HA_NODE_ID'
|
|
355
|
+
| 'VALIDATOR_HA_POLLING_INTERVAL_MS'
|
|
356
|
+
| 'VALIDATOR_HA_SIGNING_TIMEOUT_MS'
|
|
357
|
+
| 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS'
|
|
358
|
+
| 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H'
|
|
321
359
|
| 'VALIDATOR_HA_DATABASE_URL'
|
|
322
360
|
| 'VALIDATOR_HA_RUN_MIGRATIONS'
|
|
323
361
|
| 'VALIDATOR_HA_POOL_MAX'
|
package/src/config/index.ts
CHANGED
|
@@ -149,6 +149,23 @@ export function floatConfigHelper(
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Parses an environment variable to a 0-1 percentage value
|
|
154
|
+
*/
|
|
155
|
+
export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
|
|
156
|
+
return {
|
|
157
|
+
parseEnv: (val: string): number => {
|
|
158
|
+
const parsed = safeParseFloat(val, defaultVal);
|
|
159
|
+
if (parsed < 0 || parsed > 1) {
|
|
160
|
+
throw new TypeError(`Invalid percentage value: ${parsed} should be between 0 and 1`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return parsed;
|
|
164
|
+
},
|
|
165
|
+
defaultValue: defaultVal,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
152
169
|
/**
|
|
153
170
|
* Generates parseEnv and default values for a numerical config value.
|
|
154
171
|
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
|
|
@@ -5,7 +5,8 @@ export type NetworkNames =
|
|
|
5
5
|
| 'testnet'
|
|
6
6
|
| 'mainnet'
|
|
7
7
|
| 'next-net'
|
|
8
|
-
| 'devnet'
|
|
8
|
+
| 'devnet'
|
|
9
|
+
| `v${number}-devnet-${number}`;
|
|
9
10
|
|
|
10
11
|
export function getActiveNetworkName(name?: string): NetworkNames {
|
|
11
12
|
const network = name || process.env.NETWORK;
|
|
@@ -23,6 +24,8 @@ export function getActiveNetworkName(name?: string): NetworkNames {
|
|
|
23
24
|
return 'next-net';
|
|
24
25
|
} else if (network === 'devnet') {
|
|
25
26
|
return 'devnet';
|
|
27
|
+
} else if (/^v\d+-devnet-\d+$/.test(network)) {
|
|
28
|
+
return network as `v${number}-devnet-${number}`;
|
|
26
29
|
}
|
|
27
30
|
throw new Error(`Unknown network: ${network}`);
|
|
28
31
|
}
|
|
@@ -35,16 +35,6 @@ export async function poseidon2HashWithSeparator(input: Fieldable[], separator:
|
|
|
35
35
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
|
|
39
|
-
const inputFields = serializeToFields(input);
|
|
40
|
-
await BarretenbergSync.initSingleton();
|
|
41
|
-
const api = BarretenbergSync.getSingleton();
|
|
42
|
-
const response = api.poseidon2HashAccumulate({
|
|
43
|
-
inputs: inputFields.map(i => i.toBuffer()),
|
|
44
|
-
});
|
|
45
|
-
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
38
|
/**
|
|
49
39
|
* Runs a Poseidon2 permutation.
|
|
50
40
|
* @param input the input state. Expected to be of size 4.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '../../log/pino-logger.js';
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '../../log/pino-logger.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A number generator which is used as a source of randomness in the system. If the SEED env variable is set, the
|
|
@@ -12,9 +12,13 @@ export class RandomnessSingleton {
|
|
|
12
12
|
private static instance: RandomnessSingleton;
|
|
13
13
|
|
|
14
14
|
private counter = 0;
|
|
15
|
-
private
|
|
15
|
+
private log: Logger;
|
|
16
16
|
|
|
17
|
-
private constructor(
|
|
17
|
+
private constructor(
|
|
18
|
+
private readonly seed?: number,
|
|
19
|
+
bindings?: LoggerBindings,
|
|
20
|
+
) {
|
|
21
|
+
this.log = createLogger('foundation:randomness_singleton', bindings);
|
|
18
22
|
if (seed !== undefined) {
|
|
19
23
|
this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
|
|
20
24
|
this.counter = seed;
|
|
@@ -23,10 +27,10 @@ export class RandomnessSingleton {
|
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
public static getInstance(): RandomnessSingleton {
|
|
30
|
+
public static getInstance(bindings?: LoggerBindings): RandomnessSingleton {
|
|
27
31
|
if (!RandomnessSingleton.instance) {
|
|
28
32
|
const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
|
|
29
|
-
RandomnessSingleton.instance = new RandomnessSingleton(seed);
|
|
33
|
+
RandomnessSingleton.instance = new RandomnessSingleton(seed, bindings);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
return RandomnessSingleton.instance;
|
|
@@ -34,15 +34,6 @@ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number
|
|
|
34
34
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function poseidon2HashAccumulate(input: Fieldable[]): Fr {
|
|
38
|
-
const inputFields = serializeToFields(input);
|
|
39
|
-
const api = BarretenbergSync.getSingleton();
|
|
40
|
-
const response = api.poseidon2HashAccumulate({
|
|
41
|
-
inputs: inputFields.map(i => i.toBuffer()),
|
|
42
|
-
});
|
|
43
|
-
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
37
|
/**
|
|
47
38
|
* Runs a Poseidon2 permutation.
|
|
48
39
|
* @param input the input state. Expected to be of size 4.
|
package/src/jest/setup.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseBooleanEnv } from '@aztec/foundation/config';
|
|
1
2
|
import { overwriteLoggingStream, pinoPrettyOpts } from '@aztec/foundation/log';
|
|
2
3
|
|
|
3
4
|
import pretty from 'pino-pretty';
|
|
@@ -6,4 +7,6 @@ import pretty from 'pino-pretty';
|
|
|
6
7
|
// file so we don't mess up with dependencies in non-testing environments,
|
|
7
8
|
// since pino-pretty messes up with browser bundles.
|
|
8
9
|
// See also https://www.npmjs.com/package/pino-pretty?activeTab=readme#user-content-usage-with-jest
|
|
9
|
-
|
|
10
|
+
if (!parseBooleanEnv(process.env.LOG_JSON)) {
|
|
11
|
+
overwriteLoggingStream(pretty(pinoPrettyOpts));
|
|
12
|
+
}
|
|
@@ -24,6 +24,7 @@ export type SafeJsonRpcClientOptions = {
|
|
|
24
24
|
batchWindowMS?: number;
|
|
25
25
|
maxBatchSize?: number;
|
|
26
26
|
maxRequestBodySize?: number;
|
|
27
|
+
extraHeaders?: Record<string, string>;
|
|
27
28
|
onResponse?: (res: {
|
|
28
29
|
response: any;
|
|
29
30
|
headers: { get: (header: string) => string | null | undefined };
|
|
@@ -129,6 +130,7 @@ export function createSafeJsonRpcClient<T extends object>(
|
|
|
129
130
|
const { response, headers } = await fetch(
|
|
130
131
|
host,
|
|
131
132
|
rpcCalls.map(({ request }) => request),
|
|
133
|
+
config.extraHeaders,
|
|
132
134
|
);
|
|
133
135
|
|
|
134
136
|
if (config.onResponse) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
|
+
import { gunzip as gunzipCb, gzip as gzipCb } from 'node:zlib';
|
|
1
3
|
import { Agent, type Dispatcher } from 'undici';
|
|
2
4
|
|
|
3
5
|
import { createLogger } from '../../log/pino-logger.js';
|
|
@@ -5,8 +7,14 @@ import { NoRetryError } from '../../retry/index.js';
|
|
|
5
7
|
import { jsonStringify } from '../convert.js';
|
|
6
8
|
import type { JsonRpcFetch } from './fetch.js';
|
|
7
9
|
|
|
10
|
+
const gzip = promisify(gzipCb);
|
|
11
|
+
const gunzip = promisify(gunzipCb);
|
|
12
|
+
|
|
8
13
|
const log = createLogger('json-rpc:json_rpc_client:undici');
|
|
9
14
|
|
|
15
|
+
/** Minimum request size in bytes to trigger compression. */
|
|
16
|
+
const COMPRESSION_THRESHOLD = 1024;
|
|
17
|
+
|
|
10
18
|
export { Agent };
|
|
11
19
|
|
|
12
20
|
export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
@@ -14,14 +22,18 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
14
22
|
log.trace(`JsonRpcClient.fetch: ${host}`, { host, body });
|
|
15
23
|
let resp: Dispatcher.ResponseData;
|
|
16
24
|
try {
|
|
25
|
+
const jsonBody = Buffer.from(jsonStringify(body));
|
|
26
|
+
const shouldCompress = jsonBody.length >= COMPRESSION_THRESHOLD;
|
|
17
27
|
resp = await client.request({
|
|
18
28
|
method: 'POST',
|
|
19
29
|
origin: new URL(host),
|
|
20
30
|
path: '/',
|
|
21
|
-
body:
|
|
31
|
+
body: shouldCompress ? await gzip(jsonBody) : jsonBody,
|
|
22
32
|
headers: {
|
|
23
33
|
...extraHeaders,
|
|
24
34
|
'content-type': 'application/json',
|
|
35
|
+
...(shouldCompress && { 'content-encoding': 'gzip' }),
|
|
36
|
+
'accept-encoding': 'gzip',
|
|
25
37
|
},
|
|
26
38
|
});
|
|
27
39
|
} catch (err) {
|
|
@@ -31,13 +43,19 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
31
43
|
|
|
32
44
|
let responseJson: any;
|
|
33
45
|
const responseOk = resp.statusCode >= 200 && resp.statusCode <= 299;
|
|
46
|
+
const contentEncoding = resp.headers['content-encoding'];
|
|
34
47
|
try {
|
|
35
|
-
|
|
48
|
+
if (contentEncoding === 'gzip') {
|
|
49
|
+
const jsonBuffer = await gunzip(await resp.body.arrayBuffer());
|
|
50
|
+
responseJson = JSON.parse(jsonBuffer.toString('utf-8'));
|
|
51
|
+
} else {
|
|
52
|
+
responseJson = await resp.body.json();
|
|
53
|
+
}
|
|
36
54
|
} catch {
|
|
37
55
|
if (!responseOk) {
|
|
38
56
|
throw new Error('HTTP ' + resp.statusCode);
|
|
39
57
|
}
|
|
40
|
-
throw new Error(`Failed to parse body as JSON: ${await resp.body.text()}`);
|
|
58
|
+
throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${await resp.body.text()}`);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
if (!responseOk) {
|