@aztec/foundation 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263

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 (146) hide show
  1. package/dest/branded-types/block_number.d.ts +4 -1
  2. package/dest/branded-types/block_number.d.ts.map +1 -1
  3. package/dest/branded-types/block_number.js +3 -0
  4. package/dest/branded-types/checkpoint_number.d.ts +10 -2
  5. package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
  6. package/dest/branded-types/checkpoint_number.js +17 -8
  7. package/dest/branded-types/index.d.ts +3 -2
  8. package/dest/branded-types/index.d.ts.map +1 -1
  9. package/dest/branded-types/index.js +2 -1
  10. package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
  11. package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
  12. package/dest/branded-types/index_within_checkpoint.js +59 -0
  13. package/dest/buffer/buffer16.d.ts +4 -1
  14. package/dest/buffer/buffer16.d.ts.map +1 -1
  15. package/dest/buffer/buffer16.js +3 -1
  16. package/dest/buffer/buffer32.d.ts +4 -1
  17. package/dest/buffer/buffer32.d.ts.map +1 -1
  18. package/dest/buffer/buffer32.js +3 -1
  19. package/dest/collection/array.d.ts +12 -1
  20. package/dest/collection/array.d.ts.map +1 -1
  21. package/dest/collection/array.js +51 -0
  22. package/dest/config/env_var.d.ts +2 -2
  23. package/dest/config/env_var.d.ts.map +1 -1
  24. package/dest/config/index.d.ts +6 -3
  25. package/dest/config/index.d.ts.map +1 -1
  26. package/dest/config/index.js +16 -7
  27. package/dest/config/parse-env.d.ts +3 -0
  28. package/dest/config/parse-env.d.ts.map +1 -0
  29. package/dest/config/parse-env.js +7 -0
  30. package/dest/config/secret_value.js +3 -1
  31. package/dest/crypto/ecdsa/signature.d.ts +10 -1
  32. package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
  33. package/dest/crypto/poseidon/index.d.ts +1 -2
  34. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  35. package/dest/crypto/poseidon/index.js +0 -9
  36. package/dest/crypto/random/randomness_singleton.d.ts +4 -3
  37. package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
  38. package/dest/crypto/random/randomness_singleton.js +5 -5
  39. package/dest/crypto/sync/poseidon/index.d.ts +1 -2
  40. package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
  41. package/dest/crypto/sync/poseidon/index.js +0 -8
  42. package/dest/curves/bls12/field.js +6 -3
  43. package/dest/curves/bls12/point.d.ts +10 -1
  44. package/dest/curves/bls12/point.d.ts.map +1 -1
  45. package/dest/curves/bls12/point.js +3 -1
  46. package/dest/curves/bn254/field.js +5 -2
  47. package/dest/curves/grumpkin/point.d.ts +11 -2
  48. package/dest/curves/grumpkin/point.d.ts.map +1 -1
  49. package/dest/error/index.d.ts +4 -4
  50. package/dest/error/index.d.ts.map +1 -1
  51. package/dest/eth-address/index.js +4 -2
  52. package/dest/eth-signature/eth_signature.d.ts +4 -1
  53. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  54. package/dest/jest/setup.js +4 -1
  55. package/dest/json-rpc/client/undici.d.ts +1 -1
  56. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  57. package/dest/json-rpc/client/undici.js +21 -4
  58. package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
  59. package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
  60. package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
  61. package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
  62. package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
  63. package/dest/log/libp2p_logger.d.ts +5 -2
  64. package/dest/log/libp2p_logger.d.ts.map +1 -1
  65. package/dest/log/libp2p_logger.js +14 -4
  66. package/dest/log/pino-logger-server.d.ts +9 -0
  67. package/dest/log/pino-logger-server.d.ts.map +1 -0
  68. package/dest/log/pino-logger-server.js +18 -0
  69. package/dest/log/pino-logger.d.ts +37 -8
  70. package/dest/log/pino-logger.d.ts.map +1 -1
  71. package/dest/log/pino-logger.js +116 -27
  72. package/dest/queue/semaphore.d.ts +5 -1
  73. package/dest/queue/semaphore.d.ts.map +1 -1
  74. package/dest/retry/index.d.ts +11 -1
  75. package/dest/retry/index.d.ts.map +1 -1
  76. package/dest/retry/index.js +11 -0
  77. package/dest/serialize/buffer_reader.d.ts +7 -4
  78. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  79. package/dest/serialize/buffer_reader.js +13 -4
  80. package/dest/trees/balanced_merkle_tree_root.d.ts +17 -0
  81. package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
  82. package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +2 -17
  83. package/dest/trees/hasher.d.ts +3 -1
  84. package/dest/trees/hasher.d.ts.map +1 -1
  85. package/dest/trees/hasher.js +10 -5
  86. package/dest/trees/index.d.ts +4 -4
  87. package/dest/trees/index.d.ts.map +1 -1
  88. package/dest/trees/index.js +3 -3
  89. package/dest/trees/membership_witness.d.ts +11 -1
  90. package/dest/trees/membership_witness.d.ts.map +1 -1
  91. package/dest/trees/membership_witness.js +9 -0
  92. package/dest/trees/merkle_tree_calculator.d.ts +1 -1
  93. package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
  94. package/dest/trees/merkle_tree_calculator.js +2 -2
  95. package/dest/trees/sibling_path.d.ts +2 -1
  96. package/dest/trees/sibling_path.d.ts.map +1 -1
  97. package/dest/trees/sibling_path.js +2 -2
  98. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
  99. package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
  100. package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
  101. package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +3 -5
  102. package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
  103. package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +11 -49
  104. package/dest/trees/unbalanced_tree_store.d.ts +5 -1
  105. package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
  106. package/dest/trees/unbalanced_tree_store.js +49 -1
  107. package/dest/types/index.d.ts +1 -1
  108. package/package.json +5 -4
  109. package/src/branded-types/block_number.ts +5 -0
  110. package/src/branded-types/checkpoint_number.ts +22 -7
  111. package/src/branded-types/index.ts +2 -1
  112. package/src/branded-types/index_within_checkpoint.ts +88 -0
  113. package/src/collection/array.ts +52 -0
  114. package/src/config/env_var.ts +24 -7
  115. package/src/config/index.ts +19 -4
  116. package/src/config/parse-env.ts +4 -0
  117. package/src/crypto/poseidon/index.ts +0 -10
  118. package/src/crypto/random/randomness_singleton.ts +6 -4
  119. package/src/crypto/sync/poseidon/index.ts +0 -9
  120. package/src/eth-address/index.ts +1 -1
  121. package/src/jest/setup.mjs +4 -1
  122. package/src/json-rpc/client/undici.ts +21 -3
  123. package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
  124. package/src/log/libp2p_logger.ts +12 -5
  125. package/src/log/pino-logger-server.ts +25 -0
  126. package/src/log/pino-logger.ts +138 -37
  127. package/src/queue/semaphore.ts +5 -0
  128. package/src/retry/index.ts +18 -0
  129. package/src/serialize/buffer_reader.ts +21 -9
  130. package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +2 -18
  131. package/src/trees/hasher.ts +9 -0
  132. package/src/trees/index.ts +3 -3
  133. package/src/trees/membership_witness.ts +8 -0
  134. package/src/trees/merkle_tree_calculator.ts +2 -2
  135. package/src/trees/sibling_path.ts +2 -2
  136. package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
  137. package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -61
  138. package/src/trees/unbalanced_tree_store.ts +57 -2
  139. package/src/types/index.ts +1 -1
  140. package/dest/json-rpc/server/telemetry.d.ts +0 -2
  141. package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
  142. package/dest/json-rpc/server/telemetry.js +0 -0
  143. package/dest/trees/balanced_merkle_tree.d.ts +0 -22
  144. package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
  145. package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
  146. package/src/json-rpc/server/telemetry.ts +0 -0
@@ -85,16 +85,31 @@ CheckpointNumber.isValid = function (value: unknown): value is CheckpointNumber
85
85
  return typeof value === 'number' && Number.isInteger(value) && value >= 0;
86
86
  };
87
87
 
88
- /**
89
- * The zero checkpoint value.
90
- */
88
+ /** The zero checkpoint value. */
91
89
  CheckpointNumber.ZERO = CheckpointNumber(0);
92
90
 
91
+ /** Initial checkpoint. */
92
+ CheckpointNumber.INITIAL = CheckpointNumber(1);
93
+
93
94
  /**
94
95
  * Zod schema for parsing and validating CheckpointNumber values.
95
96
  * Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
96
97
  */
97
- export const CheckpointNumberSchema = z
98
- .union([z.number(), z.bigint(), z.string()])
99
- .pipe(z.coerce.number().int().min(0))
100
- .transform(value => CheckpointNumber(value));
98
+ function makeCheckpointNumberSchema(minValue: number) {
99
+ return z
100
+ .union([z.number(), z.bigint(), z.string()])
101
+ .pipe(z.coerce.number().int().min(minValue))
102
+ .transform(value => CheckpointNumber(value));
103
+ }
104
+
105
+ /**
106
+ * Zod schema for parsing and validating Checkpoint values.
107
+ * Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
108
+ */
109
+ export const CheckpointNumberSchema = makeCheckpointNumberSchema(0);
110
+
111
+ /**
112
+ * Zod schema for parsing and validating CheckpointNumber values that are strictly positive.
113
+ * Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
114
+ */
115
+ export const CheckpointNumberPositiveSchema = makeCheckpointNumberSchema(1);
@@ -1,6 +1,7 @@
1
1
  export { BlockNumber, BlockNumberSchema, BlockNumberPositiveSchema } from './block_number.js';
2
- export { CheckpointNumber, CheckpointNumberSchema } from './checkpoint_number.js';
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));
@@ -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[] = [];
@@ -21,15 +21,13 @@ export type EnvVar =
21
21
  | 'BB_NUM_IVC_VERIFIERS'
22
22
  | 'BB_IVC_CONCURRENCY'
23
23
  | 'BOOTSTRAP_NODES'
24
- | 'BLOB_SINK_ARCHIVE_API_URL'
25
- | 'BLOB_SINK_PORT'
26
- | 'BLOB_SINK_URL'
24
+ | 'BLOB_ARCHIVE_API_URL'
27
25
  | 'BLOB_FILE_STORE_URLS'
28
26
  | 'BLOB_FILE_STORE_UPLOAD_URL'
29
27
  | 'BLOB_HEALTHCHECK_UPLOAD_INTERVAL_MINUTES'
30
28
  | 'BOT_DA_GAS_LIMIT'
31
29
  | 'BOT_FEE_PAYMENT_METHOD'
32
- | 'BOT_BASE_FEE_PADDING'
30
+ | 'BOT_MIN_FEE_PADDING'
33
31
  | 'BOT_FLUSH_SETUP_TRANSACTIONS'
34
32
  | 'BOT_FOLLOW_CHAIN'
35
33
  | 'BOT_L2_GAS_LIMIT'
@@ -79,6 +77,7 @@ export type EnvVar =
79
77
  | 'L1_CONSENSUS_HOST_API_KEY_HEADERS'
80
78
  | 'LOG_JSON'
81
79
  | 'LOG_MULTILINE'
80
+ | 'LOG_NO_COLOR_PER_ACTOR'
82
81
  | 'LOG_LEVEL'
83
82
  | 'MNEMONIC'
84
83
  | 'NETWORK'
@@ -96,6 +95,10 @@ export type EnvVar =
96
95
  | 'PUBLIC_OTEL_INCLUDE_METRICS'
97
96
  | 'PUBLIC_OTEL_COLLECT_FROM'
98
97
  | 'PUBLIC_OTEL_OPT_OUT'
98
+ | 'P2P_BATCH_TX_REQUESTER_SMART_PARALLEL_WORKER_COUNT'
99
+ | 'P2P_BATCH_TX_REQUESTER_DUMB_PARALLEL_WORKER_COUNT'
100
+ | 'P2P_BATCH_TX_REQUESTER_TX_BATCH_SIZE'
101
+ | 'P2P_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD'
99
102
  | 'P2P_BLOCK_CHECK_INTERVAL_MS'
100
103
  | 'P2P_BLOCK_REQUEST_BATCH_SIZE'
101
104
  | 'P2P_BOOTSTRAP_NODE_ENR_VERSION_CHECK'
@@ -153,6 +156,7 @@ export type EnvVar =
153
156
  | 'PROVER_BROKER_BATCH_INTERVAL_MS'
154
157
  | 'PROVER_BROKER_BATCH_SIZE'
155
158
  | 'PROVER_BROKER_MAX_EPOCHS_TO_KEEP_RESULTS_FOR'
159
+ | 'PROVER_CANCEL_JOBS_ON_STOP'
156
160
  | 'PROVER_COORDINATION_NODE_URLS'
157
161
  | 'PROVER_FAILED_PROOF_STORE'
158
162
  | 'PROVER_NODE_FAILED_EPOCH_STORE'
@@ -177,6 +181,7 @@ export type EnvVar =
177
181
  | 'PROVER_TEST_VERIFICATION_DELAY_MS'
178
182
  | 'PXE_L2_BLOCK_BATCH_SIZE'
179
183
  | 'PXE_PROVER_ENABLED'
184
+ | 'PXE_SYNC_CHAIN_TIP'
180
185
  | 'RPC_MAX_BATCH_SIZE'
181
186
  | 'RPC_MAX_BODY_SIZE'
182
187
  | 'RPC_SIMULATE_PUBLIC_MAX_GAS_LIMIT'
@@ -237,6 +242,7 @@ export type EnvVar =
237
242
  | 'TX_COLLECTION_FAST_MAX_PARALLEL_REQUESTS_PER_NODE'
238
243
  | 'TX_COLLECTION_NODE_RPC_MAX_BATCH_SIZE'
239
244
  | 'TX_COLLECTION_NODE_RPC_URLS'
245
+ | 'TX_COLLECTION_PROPOSAL_TX_COLLECTOR_TYPE'
240
246
  | 'TX_PUBLIC_SETUP_ALLOWLIST'
241
247
  | 'TXE_PORT'
242
248
  | 'TRANSACTIONS_DISABLED'
@@ -248,7 +254,6 @@ export type EnvVar =
248
254
  | 'VALIDATOR_ADDRESSES'
249
255
  | 'ROLLUP_VERSION'
250
256
  | 'WS_BLOCK_CHECK_INTERVAL_MS'
251
- | 'WS_PROVEN_BLOCKS_ONLY'
252
257
  | 'WS_BLOCK_REQUEST_BATCH_SIZE'
253
258
  | 'L1_READER_VIEM_POLLING_INTERVAL_MS'
254
259
  | 'WS_DATA_DIRECTORY'
@@ -266,6 +271,7 @@ export type EnvVar =
266
271
  | 'AZTEC_LOCAL_EJECTION_THRESHOLD'
267
272
  | 'AZTEC_MANA_TARGET'
268
273
  | 'AZTEC_PROVING_COST_PER_MANA'
274
+ | 'AZTEC_INITIAL_ETH_PER_FEE_ASSET'
269
275
  | 'AZTEC_SLASHING_QUORUM'
270
276
  | 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS'
271
277
  | 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS'
@@ -279,6 +285,7 @@ export type EnvVar =
279
285
  | 'AZTEC_SLASHER_FLAVOR'
280
286
  | 'AZTEC_GOVERNANCE_PROPOSER_QUORUM'
281
287
  | 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE'
288
+ | 'AZTEC_GOVERNANCE_VOTING_DURATION'
282
289
  | 'AZTEC_EXIT_DELAY_SECONDS'
283
290
  | 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
284
291
  | 'L1_GAS_PRICE_MAX'
@@ -305,7 +312,6 @@ export type EnvVar =
305
312
  | 'K8S_POD_UID'
306
313
  | 'K8S_NAMESPACE_NAME'
307
314
  | 'VALIDATOR_REEXECUTE_DEADLINE_MS'
308
- | 'ALWAYS_REEXECUTE_BLOCK_PROPOSALS'
309
315
  | 'AUTO_UPDATE'
310
316
  | 'AUTO_UPDATE_URL'
311
317
  | 'WEB3_SIGNER_URL'
@@ -314,4 +320,15 @@ export type EnvVar =
314
320
  | 'FISHERMAN_MODE'
315
321
  | 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS'
316
322
  | 'LEGACY_BLS_CLI'
317
- | 'DEBUG_FORCE_TX_PROOF_VERIFICATION';
323
+ | 'DEBUG_FORCE_TX_PROOF_VERIFICATION'
324
+ | 'VALIDATOR_HA_SIGNING_ENABLED'
325
+ | 'VALIDATOR_HA_NODE_ID'
326
+ | 'VALIDATOR_HA_POLLING_INTERVAL_MS'
327
+ | 'VALIDATOR_HA_SIGNING_TIMEOUT_MS'
328
+ | 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS'
329
+ | 'VALIDATOR_HA_DATABASE_URL'
330
+ | 'VALIDATOR_HA_RUN_MIGRATIONS'
331
+ | 'VALIDATOR_HA_POOL_MAX'
332
+ | 'VALIDATOR_HA_POOL_MIN'
333
+ | 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS'
334
+ | 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS';
@@ -2,6 +2,7 @@ import { Fq, Fr } from '../curves/bn254/field.js';
2
2
  import { createConsoleLogger } from '../log/console.js';
3
3
  import type { EnvVar } from './env_var.js';
4
4
  import { type NetworkNames, getActiveNetworkName } from './network_name.js';
5
+ import { parseBooleanEnv } from './parse-env.js';
5
6
  import { SecretValue } from './secret_value.js';
6
7
 
7
8
  export { SecretValue, getActiveNetworkName };
@@ -148,6 +149,23 @@ export function floatConfigHelper(
148
149
  };
149
150
  }
150
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
+
151
169
  /**
152
170
  * Generates parseEnv and default values for a numerical config value.
153
171
  * @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
@@ -231,10 +249,7 @@ export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T
231
249
  };
232
250
  }
233
251
 
234
- /** Parses an env var as boolean. Returns true only if value is 1, true, or TRUE. */
235
- export function parseBooleanEnv(val: string | undefined): boolean {
236
- return val !== undefined && ['1', 'true', 'TRUE'].includes(val);
237
- }
252
+ export { parseBooleanEnv } from './parse-env.js';
238
253
 
239
254
  export function secretStringConfigHelper(): Required<
240
255
  Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
@@ -0,0 +1,4 @@
1
+ /** Parses an env var as boolean. Returns true only if value is 1, true, or TRUE. */
2
+ export function parseBooleanEnv(val: string | undefined): boolean {
3
+ return val !== undefined && ['1', 'true', 'TRUE'].includes(val);
4
+ }
@@ -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,11 +12,13 @@ export class RandomnessSingleton {
12
12
  private static instance: RandomnessSingleton;
13
13
 
14
14
  private counter = 0;
15
+ private log: Logger;
15
16
 
16
17
  private constructor(
17
18
  private readonly seed?: number,
18
- private readonly log = createLogger('foundation:randomness_singleton'),
19
+ bindings?: LoggerBindings,
19
20
  ) {
21
+ this.log = createLogger('foundation:randomness_singleton', bindings);
20
22
  if (seed !== undefined) {
21
23
  this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
22
24
  this.counter = seed;
@@ -25,10 +27,10 @@ export class RandomnessSingleton {
25
27
  }
26
28
  }
27
29
 
28
- public static getInstance(): RandomnessSingleton {
30
+ public static getInstance(bindings?: LoggerBindings): RandomnessSingleton {
29
31
  if (!RandomnessSingleton.instance) {
30
32
  const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
31
- RandomnessSingleton.instance = new RandomnessSingleton(seed);
33
+ RandomnessSingleton.instance = new RandomnessSingleton(seed, bindings);
32
34
  }
33
35
 
34
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.
@@ -249,7 +249,7 @@ export class EthAddress {
249
249
  /** Converts a number into an address. Useful for testing. */
250
250
  static fromNumber(num: bigint | number): EthAddress {
251
251
  const buffer = Buffer.alloc(EthAddress.SIZE_IN_BYTES);
252
- buffer.writeBigUInt64BE(BigInt(num), 0);
252
+ buffer.writeBigUInt64BE(BigInt(num), EthAddress.SIZE_IN_BYTES - 8);
253
253
  return new EthAddress(buffer);
254
254
  }
255
255
 
@@ -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
- overwriteLoggingStream(pretty(pinoPrettyOpts));
10
+ if (!parseBooleanEnv(process.env.LOG_JSON)) {
11
+ overwriteLoggingStream(pretty(pinoPrettyOpts));
12
+ }
@@ -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: jsonStringify(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
- responseJson = await resp.body.json();
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) {
@@ -35,7 +35,7 @@ export type SafeJsonRpcServerConfig = {
35
35
  const defaultServerConfig: SafeJsonRpcServerConfig = {
36
36
  http200OnError: false,
37
37
  maxBatchSize: 100,
38
- maxBodySizeBytes: '50mb',
38
+ maxBodySizeBytes: '1mb',
39
39
  };
40
40
 
41
41
  export class SafeJsonRpcServer {
@@ -2,15 +2,17 @@ import type { ComponentLogger, Logger } from '@libp2p/interface';
2
2
 
3
3
  import { getLogLevelFromFilters } from './log-filters.js';
4
4
  import type { LogLevel } from './log-levels.js';
5
- import { logFilters, logger } from './pino-logger.js';
5
+ import { type LoggerBindings, logFilters, logger } from './pino-logger.js';
6
6
 
7
7
  /**
8
8
  * Creates a libp2p compatible logger that wraps our pino logger.
9
9
  * This adapter implements the ComponentLogger interface required by libp2p.
10
+ * @param namespace - Base namespace for the logger
11
+ * @param bindings - Optional bindings to pass to the logger (actor, instanceId)
10
12
  */
11
- export function createLibp2pComponentLogger(namespace: string): ComponentLogger {
13
+ export function createLibp2pComponentLogger(namespace: string, bindings?: LoggerBindings): ComponentLogger {
12
14
  return {
13
- forComponent: (component: string) => createLibp2pLogger(`${namespace}:${component}`),
15
+ forComponent: (component: string) => createLibp2pLogger(`${namespace}:${component}`, bindings),
14
16
  };
15
17
  }
16
18
 
@@ -24,9 +26,14 @@ function replaceFormatting(message: string) {
24
26
  return message.replace(/(%p|%a)/g, '%s');
25
27
  }
26
28
 
27
- function createLibp2pLogger(component: string): Logger {
29
+ function createLibp2pLogger(component: string, bindings?: LoggerBindings): Logger {
28
30
  // Create a direct pino logger instance for libp2p that supports string interpolation
29
- const log = logger.child({ module: component }, { level: getLogLevelFromFilters(logFilters, component) });
31
+ const actor = bindings?.actor;
32
+ const instanceId = bindings?.instanceId;
33
+ const log = logger.child(
34
+ { module: component, ...(actor && { actor }), ...(instanceId && { instanceId }) },
35
+ { level: getLogLevelFromFilters(logFilters, component) },
36
+ );
30
37
 
31
38
  const logIfEnabled = (level: LogLevel, message: string, ...args: unknown[]) => {
32
39
  if (!log.isLevelEnabled(level)) {
@@ -0,0 +1,25 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+
3
+ import { type LoggerBindings, addLogBindingsHandler, removeLogBindingsHandler } from './pino-logger.js';
4
+
5
+ /** AsyncLocalStorage for logger bindings context propagation (Node.js only). */
6
+ const bindingsStorage = new AsyncLocalStorage<LoggerBindings>();
7
+
8
+ /** Returns the current bindings from AsyncLocalStorage, if any. */
9
+ export function getBindings(): LoggerBindings | undefined {
10
+ return bindingsStorage.getStore();
11
+ }
12
+
13
+ /**
14
+ * Runs a callback within a bindings context. All loggers created within the callback
15
+ * will automatically inherit the bindings (actor, instanceId) via the log bindings handler.
16
+ */
17
+ export async function withLoggerBindings<T>(bindings: LoggerBindings, callback: () => Promise<T>): Promise<T> {
18
+ const handler = () => bindingsStorage.getStore();
19
+ addLogBindingsHandler(handler);
20
+ try {
21
+ return await bindingsStorage.run(bindings, callback);
22
+ } finally {
23
+ removeLogBindingsHandler(handler);
24
+ }
25
+ }