@aztec/stdlib 4.0.0-nightly.20260121 → 4.0.0-nightly.20260123

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 (105) hide show
  1. package/dest/block/checkpointed_l2_block.d.ts +6 -6
  2. package/dest/block/checkpointed_l2_block.d.ts.map +1 -1
  3. package/dest/block/checkpointed_l2_block.js +3 -3
  4. package/dest/block/in_block.d.ts +3 -3
  5. package/dest/block/in_block.d.ts.map +1 -1
  6. package/dest/block/index.d.ts +2 -2
  7. package/dest/block/index.d.ts.map +1 -1
  8. package/dest/block/index.js +1 -1
  9. package/dest/block/{l2_block_new.d.ts → l2_block.d.ts} +6 -6
  10. package/dest/block/l2_block.d.ts.map +1 -0
  11. package/dest/block/{l2_block_new.js → l2_block.js} +5 -9
  12. package/dest/block/l2_block_source.d.ts +37 -29
  13. package/dest/block/l2_block_source.d.ts.map +1 -1
  14. package/dest/block/l2_block_stream/interfaces.d.ts +3 -3
  15. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  16. package/dest/block/l2_block_stream/l2_block_stream.d.ts +6 -3
  17. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  18. package/dest/block/l2_block_stream/l2_block_stream.js +37 -25
  19. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +3 -3
  20. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  21. package/dest/block/test/l2_tips_store_test_suite.js +2 -2
  22. package/dest/checkpoint/checkpoint.d.ts +8 -8
  23. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  24. package/dest/checkpoint/checkpoint.js +4 -4
  25. package/dest/checkpoint/published_checkpoint.d.ts +2 -2
  26. package/dest/config/node-rpc-config.js +1 -1
  27. package/dest/contract/private_function.d.ts +1 -1
  28. package/dest/contract/private_function.d.ts.map +1 -1
  29. package/dest/contract/private_function.js +1 -2
  30. package/dest/epoch-helpers/index.js +1 -1
  31. package/dest/interfaces/api_limit.d.ts +2 -1
  32. package/dest/interfaces/api_limit.d.ts.map +1 -1
  33. package/dest/interfaces/api_limit.js +1 -0
  34. package/dest/interfaces/archiver.d.ts +1 -1
  35. package/dest/interfaces/archiver.d.ts.map +1 -1
  36. package/dest/interfaces/archiver.js +17 -17
  37. package/dest/interfaces/aztec-node-admin.d.ts +4 -1
  38. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  39. package/dest/interfaces/aztec-node.d.ts +32 -14
  40. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  41. package/dest/interfaces/aztec-node.js +10 -11
  42. package/dest/interfaces/block-builder.d.ts +4 -4
  43. package/dest/interfaces/block-builder.d.ts.map +1 -1
  44. package/dest/interfaces/l2_logs_source.d.ts +14 -5
  45. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  46. package/dest/interfaces/prover-client.d.ts +10 -1
  47. package/dest/interfaces/prover-client.d.ts.map +1 -1
  48. package/dest/interfaces/prover-client.js +7 -1
  49. package/dest/interfaces/tx_provider.d.ts +3 -3
  50. package/dest/interfaces/tx_provider.d.ts.map +1 -1
  51. package/dest/p2p/block_proposal.d.ts +4 -4
  52. package/dest/p2p/block_proposal.d.ts.map +1 -1
  53. package/dest/p2p/block_proposal.js +1 -1
  54. package/dest/p2p/constants.d.ts +3 -0
  55. package/dest/p2p/constants.d.ts.map +1 -0
  56. package/dest/p2p/constants.js +2 -0
  57. package/dest/p2p/index.d.ts +2 -1
  58. package/dest/p2p/index.d.ts.map +1 -1
  59. package/dest/p2p/index.js +1 -0
  60. package/dest/tests/factories.js +1 -1
  61. package/dest/tests/jest.d.ts +4 -4
  62. package/dest/tests/jest.js +9 -9
  63. package/dest/tests/mocks.d.ts +10 -9
  64. package/dest/tests/mocks.d.ts.map +1 -1
  65. package/dest/tests/mocks.js +15 -10
  66. package/dest/tx/tx.d.ts +2 -1
  67. package/dest/tx/tx.d.ts.map +1 -1
  68. package/dest/tx/tx.js +6 -3
  69. package/dest/tx/tx_receipt.d.ts +39 -11
  70. package/dest/tx/tx_receipt.d.ts.map +1 -1
  71. package/dest/tx/tx_receipt.js +44 -13
  72. package/dest/tx/validator/error_texts.d.ts +2 -1
  73. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  74. package/dest/tx/validator/error_texts.js +2 -0
  75. package/package.json +9 -9
  76. package/src/block/checkpointed_l2_block.ts +4 -4
  77. package/src/block/in_block.ts +2 -2
  78. package/src/block/index.ts +1 -1
  79. package/src/block/{l2_block_new.ts → l2_block.ts} +6 -11
  80. package/src/block/l2_block_source.ts +38 -30
  81. package/src/block/l2_block_stream/interfaces.ts +2 -2
  82. package/src/block/l2_block_stream/l2_block_stream.ts +44 -27
  83. package/src/block/l2_block_stream/l2_tips_store_base.ts +2 -2
  84. package/src/block/test/l2_tips_store_test_suite.ts +4 -4
  85. package/src/checkpoint/checkpoint.ts +7 -7
  86. package/src/config/node-rpc-config.ts +1 -1
  87. package/src/contract/private_function.ts +1 -2
  88. package/src/epoch-helpers/index.ts +1 -1
  89. package/src/interfaces/api_limit.ts +1 -0
  90. package/src/interfaces/archiver.ts +17 -26
  91. package/src/interfaces/aztec-node.ts +47 -35
  92. package/src/interfaces/block-builder.ts +3 -3
  93. package/src/interfaces/l2_logs_source.ts +17 -4
  94. package/src/interfaces/prover-client.ts +15 -0
  95. package/src/interfaces/tx_provider.ts +2 -2
  96. package/src/p2p/block_proposal.ts +3 -3
  97. package/src/p2p/constants.ts +3 -0
  98. package/src/p2p/index.ts +1 -0
  99. package/src/tests/factories.ts +1 -1
  100. package/src/tests/jest.ts +9 -9
  101. package/src/tests/mocks.ts +20 -13
  102. package/src/tx/tx.ts +8 -9
  103. package/src/tx/tx_receipt.ts +72 -15
  104. package/src/tx/validator/error_texts.ts +3 -0
  105. package/dest/block/l2_block_new.d.ts.map +0 -1
@@ -18,15 +18,10 @@ import { BlockHeader } from '../tx/block_header.js';
18
18
  import { Body } from './body.js';
19
19
  import type { L2BlockInfo } from './l2_block_info.js';
20
20
 
21
- // TODO(palla/mbps): Delete the existing `L2Block` class and rename this to `L2Block`.
22
- // TODO(palla/mbps): Consider moving the checkpointNumber and indexWithinCheckpoint to the header:
23
- // if the blockNumber is there, why not these as well? Consider whether they should be part of the
24
- // circuits structs though.
25
-
26
21
  /**
27
22
  * An L2 block with a header and a body.
28
23
  */
29
- export class L2BlockNew {
24
+ export class L2Block {
30
25
  constructor(
31
26
  /** Snapshot of archive tree after the block is applied. */
32
27
  public archive: AppendOnlyTreeSnapshot,
@@ -63,7 +58,7 @@ export class L2BlockNew {
63
58
  })
64
59
  .transform(
65
60
  ({ archive, header, body, checkpointNumber, indexWithinCheckpoint }) =>
66
- new L2BlockNew(archive, header, body, checkpointNumber, indexWithinCheckpoint),
61
+ new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint),
67
62
  );
68
63
  }
69
64
 
@@ -79,7 +74,7 @@ export class L2BlockNew {
79
74
  const checkpointNumber = CheckpointNumber(reader.readNumber());
80
75
  const indexWithinCheckpoint = IndexWithinCheckpoint(reader.readNumber());
81
76
 
82
- return new L2BlockNew(archive, header, body, checkpointNumber, indexWithinCheckpoint);
77
+ return new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
83
78
  }
84
79
 
85
80
  /**
@@ -143,7 +138,7 @@ export class L2BlockNew {
143
138
  }
144
139
 
145
140
  static empty(header?: BlockHeader) {
146
- return new L2BlockNew(
141
+ return new L2Block(
147
142
  AppendOnlyTreeSnapshot.empty(),
148
143
  header ?? BlockHeader.empty(),
149
144
  Body.empty(),
@@ -177,11 +172,11 @@ export class L2BlockNew {
177
172
  txOptions?: Partial<Parameters<typeof Body.random>[0]>;
178
173
  makeTxOptions?: (txIndex: number) => Partial<Parameters<typeof Body.random>[0]>;
179
174
  } & Partial<Parameters<typeof BlockHeader.random>[0]> = {},
180
- ): Promise<L2BlockNew> {
175
+ ): Promise<L2Block> {
181
176
  const archive = new AppendOnlyTreeSnapshot(Fr.random(), blockNumber + 1);
182
177
  const header = BlockHeader.random({ blockNumber, ...blockHeaderOverrides });
183
178
  const body = await Body.random({ txsPerBlock, makeTxOptions, ...txOptions });
184
- return new L2BlockNew(archive, header, body, checkpointNumber, indexWithinCheckpoint);
179
+ return new L2Block(archive, header, body, checkpointNumber, indexWithinCheckpoint);
185
180
  }
186
181
 
187
182
  /**
@@ -21,7 +21,7 @@ import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
21
21
  import type { TxHash } from '../tx/tx_hash.js';
22
22
  import type { TxReceipt } from '../tx/tx_receipt.js';
23
23
  import type { CheckpointedL2Block } from './checkpointed_l2_block.js';
24
- import type { L2BlockNew } from './l2_block_new.js';
24
+ import type { L2Block } from './l2_block.js';
25
25
  import type { ValidateCheckpointNegativeResult, ValidateCheckpointResult } from './validate_block_result.js';
26
26
 
27
27
  /**
@@ -52,6 +52,20 @@ export interface L2BlockSource {
52
52
  */
53
53
  getProvenBlockNumber(): Promise<BlockNumber>;
54
54
 
55
+ /**
56
+ * Gets the number of the latest L2 block checkpointed seen by the block source implementation.
57
+ * @returns The number of the latest L2 block checkpointed seen by the block source implementation.
58
+ */
59
+ getCheckpointedL2BlockNumber(): Promise<BlockNumber>;
60
+
61
+ /**
62
+ * Computes the finalized block number based on the proven block number.
63
+ * A block is considered finalized when it's 2 epochs behind the proven block.
64
+ * TODO(#13569): Compute proper finalized block number based on L1 finalized block.
65
+ * @returns The finalized block number.
66
+ */
67
+ getFinalizedL2BlockNumber(): Promise<BlockNumber>;
68
+
55
69
  /**
56
70
  * Gets an l2 block header.
57
71
  * @param number - The block number to return or 'latest' for the most recent one.
@@ -67,15 +81,15 @@ export interface L2BlockSource {
67
81
  */
68
82
  getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined>;
69
83
 
70
- getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]>;
84
+ getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]>;
71
85
 
72
86
  /**
73
- * Retrieves a collection of published checkpoints
74
- * @param checkpointNumber The first checkpoint to be retrieved
75
- * @param limit The number of checkpoints to be retrieved
76
- * @returns The collection of complete checkpoints
87
+ * Retrieves a collection of checkpoints.
88
+ * @param checkpointNumber The first checkpoint to be retrieved.
89
+ * @param limit The number of checkpoints to be retrieved.
90
+ * @returns The collection of complete checkpoints.
77
91
  */
78
- getPublishedCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]>;
92
+ getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]>;
79
93
 
80
94
  /**
81
95
  * Gets the checkpoints for a given epoch
@@ -102,21 +116,21 @@ export interface L2BlockSource {
102
116
  * @param number - The block number to return.
103
117
  * @returns The requested L2 block (or undefined if not found).
104
118
  */
105
- getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined>;
119
+ getL2Block(number: BlockNumber): Promise<L2Block | undefined>;
106
120
 
107
121
  /**
108
122
  * Gets an L2 block by its hash.
109
123
  * @param blockHash - The block hash to retrieve.
110
124
  * @returns The requested L2 block (or undefined if not found).
111
125
  */
112
- getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | undefined>;
126
+ getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined>;
113
127
 
114
128
  /**
115
129
  * Gets an L2 block by its archive root.
116
130
  * @param archive - The archive root to retrieve.
117
131
  * @returns The requested L2 block (or undefined if not found).
118
132
  */
119
- getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined>;
133
+ getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined>;
120
134
 
121
135
  /**
122
136
  * Gets a tx effect.
@@ -143,11 +157,11 @@ export interface L2BlockSource {
143
157
  getL2EpochNumber(): Promise<EpochNumber | undefined>;
144
158
 
145
159
  /**
146
- * Returns all block headers for a given epoch.
160
+ * Returns all checkpointed block headers for a given epoch.
147
161
  * @dev Use this method only with recent epochs, since it walks the block list backwards.
148
162
  * @param epochNumber - The epoch number to return headers for.
149
163
  */
150
- getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
164
+ getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
151
165
 
152
166
  /**
153
167
  * Returns whether the given epoch is completed on L1, based on the current L1 and L2 block numbers.
@@ -193,49 +207,43 @@ export interface L2BlockSource {
193
207
  * @param number - The block number to return (inclusive).
194
208
  * @returns The requested L2 block.
195
209
  */
196
- getBlock(number: BlockNumber): Promise<L2BlockNew | undefined>;
197
-
198
- getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]>;
210
+ getBlock(number: BlockNumber): Promise<L2Block | undefined>;
199
211
 
200
212
  /**
201
- * Returns all blocks for a given epoch.
213
+ * Returns all checkpointed blocks for a given epoch.
202
214
  * @dev Use this method only with recent epochs, since it walks the block list backwards.
203
215
  * @param epochNumber - The epoch number to return blocks for.
204
216
  */
205
- getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]>;
217
+ getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]>;
206
218
 
207
219
  /**
208
220
  * Returns all blocks for a given slot.
209
221
  * @dev Use this method only with recent slots, since it walks the block list backwards.
210
222
  * @param slotNumber - The slot number to return blocks for.
211
223
  */
212
- getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]>;
224
+ getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]>;
213
225
 
214
226
  /**
215
- * Gets a published block by its block hash.
227
+ * Gets a checkpointed block by its block hash.
216
228
  * @param blockHash - The block hash to retrieve.
217
229
  * @returns The requested block (or undefined if not found).
218
230
  */
219
- getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
231
+ getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined>;
220
232
 
221
233
  /**
222
- * Gets a published block by its archive root.
234
+ * Gets a checkpointed block by its archive root.
223
235
  * @param archive - The archive root to retrieve.
224
236
  * @returns The requested block (or undefined if not found).
225
237
  */
226
- getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined>;
238
+ getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined>;
227
239
 
228
240
  /**
229
241
  * Gets up to `limit` amount of L2 blocks starting from `from`.
230
242
  * @param from - Number of the first block to return (inclusive).
231
243
  * @param limit - The maximum number of blocks to return.
232
- * @param proven - If true, only return blocks that have been proven.
233
244
  * @returns The requested L2 blocks.
234
245
  */
235
- getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]>;
236
-
237
- /** Equivalent to getBlocks but includes publish data. */
238
- getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]>;
246
+ getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]>;
239
247
  }
240
248
 
241
249
  /**
@@ -247,7 +255,7 @@ export interface L2BlockSink {
247
255
  * @param block - The L2 block to add.
248
256
  * @throws If block number is not incremental (i.e., not exactly one more than the last stored block).
249
257
  */
250
- addBlock(block: L2BlockNew): Promise<void>;
258
+ addBlock(block: L2Block): Promise<void>;
251
259
  }
252
260
 
253
261
  /**
@@ -344,13 +352,13 @@ export type L2BlockProvenEvent = {
344
352
  export type L2PruneUnprovenEvent = {
345
353
  type: 'l2PruneUnproven';
346
354
  epochNumber: EpochNumber;
347
- blocks: L2BlockNew[];
355
+ blocks: L2Block[];
348
356
  };
349
357
 
350
358
  export type L2PruneUncheckpointedEvent = {
351
359
  type: 'l2PruneUncheckpointed';
352
360
  slotNumber: SlotNumber;
353
- blocks: L2BlockNew[];
361
+ blocks: L2Block[];
354
362
  };
355
363
 
356
364
  export type L2CheckpointEvent = {
@@ -1,5 +1,5 @@
1
1
  import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
2
- import type { L2BlockNew } from '../l2_block_new.js';
2
+ import type { L2Block } from '../l2_block.js';
3
3
  import type { CheckpointId, L2BlockId, L2Tips } from '../l2_block_source.js';
4
4
 
5
5
  /** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
@@ -16,7 +16,7 @@ export interface L2BlockStreamEventHandler {
16
16
  export type L2BlockStreamEvent =
17
17
  | /** Emits blocks added to the chain. */ {
18
18
  type: 'blocks-added';
19
- blocks: L2BlockNew[];
19
+ blocks: L2Block[];
20
20
  }
21
21
  | /** Emits checkpoints published to L1. */ {
22
22
  type: 'chain-checkpointed';
@@ -7,6 +7,9 @@ import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.
7
7
  import { type L2BlockId, type L2BlockSource, makeL2BlockId } from '../l2_block_source.js';
8
8
  import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider } from './interfaces.js';
9
9
 
10
+ /** Maximum number of checkpoints to prefetch at once during sync. Matches MAX_RPC_CHECKPOINTS_LEN. */
11
+ export const CHECKPOINT_PREFETCH_LIMIT = 50;
12
+
10
13
  /** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */
11
14
  export class L2BlockStream {
12
15
  private readonly runningPromise: RunningPromise;
@@ -16,13 +19,12 @@ export class L2BlockStream {
16
19
  constructor(
17
20
  private l2BlockSource: Pick<
18
21
  L2BlockSource,
19
- 'getL2BlocksNew' | 'getBlockHeader' | 'getL2Tips' | 'getPublishedCheckpoints' | 'getCheckpointedBlocks'
22
+ 'getBlocks' | 'getBlockHeader' | 'getL2Tips' | 'getCheckpoints' | 'getCheckpointedBlocks'
20
23
  >,
21
24
  private localData: L2BlockStreamLocalDataProvider,
22
25
  private handler: L2BlockStreamEventHandler,
23
26
  private readonly log = createLogger('types:block_stream'),
24
27
  private opts: {
25
- proven?: boolean;
26
28
  pollIntervalMS?: number;
27
29
  batchSize?: number;
28
30
  startingBlock?: number;
@@ -30,6 +32,8 @@ export class L2BlockStream {
30
32
  skipFinalized?: boolean;
31
33
  /** When true, checkpoint events will not be emitted. Blocks are still fetched via checkpoints but only blocks-added events are emitted. */
32
34
  ignoreCheckpoints?: boolean;
35
+ /** Maximum number of checkpoints to prefetch at once during sync. Defaults to CHECKPOINT_PREFETCH_LIMIT (50). */
36
+ checkpointPrefetchLimit?: number;
33
37
  } = {},
34
38
  ) {
35
39
  // Note that RunningPromise is in stopped state by default. This promise won't run until someone invokes `start`,
@@ -124,7 +128,7 @@ export class L2BlockStream {
124
128
  if (!this.opts.ignoreCheckpoints) {
125
129
  let loop1Iterations = 0;
126
130
  while (nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number) {
127
- const checkpoints = await this.l2BlockSource.getPublishedCheckpoints(nextCheckpointToEmit, 1);
131
+ const checkpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointToEmit, 1);
128
132
  if (checkpoints.length === 0) {
129
133
  break;
130
134
  }
@@ -150,27 +154,36 @@ export class L2BlockStream {
150
154
  }
151
155
  }
152
156
 
153
- // Loop 2: Fetch new checkpointed blocks. For each block, get its checkpoint, emit all blocks
157
+ // Loop 2: Fetch new checkpointed blocks. For each checkpoint, emit all blocks
154
158
  // from that checkpoint that we need, then emit the checkpoint event.
155
- // We cache the current checkpoint to avoid redundant fetches when batchSize < checkpoint size.
156
- let checkpoint: PublishedCheckpoint | undefined;
157
- while (nextBlockNumber <= sourceTips.checkpointed.block.number) {
158
- const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.checkpointed.block.number - nextBlockNumber + 1);
159
+ // We prefetch multiple checkpoints, then process them one by one.
160
+ let prefetchedCheckpoints: PublishedCheckpoint[] = [];
161
+ let prefetchIdx = 0;
162
+ let nextCheckpointNumber: CheckpointNumber | undefined;
159
163
 
160
- // Check if we need to fetch a new checkpoint (nextBlockNumber is beyond the cached one)
161
- if (!checkpoint || nextBlockNumber > checkpoint.checkpoint.blocks.at(-1)!.number) {
162
- const blocks = await this.l2BlockSource.getCheckpointedBlocks(BlockNumber(nextBlockNumber), 1);
163
- if (blocks.length === 0) {
164
- break;
165
- }
166
- const checkpoints = await this.l2BlockSource.getPublishedCheckpoints(blocks[0].checkpointNumber, 1);
167
- if (checkpoints.length === 0) {
164
+ // Find the starting checkpoint number
165
+ if (nextBlockNumber <= sourceTips.checkpointed.block.number) {
166
+ const blocks = await this.l2BlockSource.getCheckpointedBlocks(BlockNumber(nextBlockNumber), 1);
167
+ if (blocks.length > 0) {
168
+ nextCheckpointNumber = blocks[0].checkpointNumber;
169
+ }
170
+ }
171
+
172
+ while (nextBlockNumber <= sourceTips.checkpointed.block.number && nextCheckpointNumber !== undefined) {
173
+ // Refill the prefetch buffer when exhausted
174
+ if (prefetchIdx >= prefetchedCheckpoints.length) {
175
+ const prefetchLimit = this.opts.checkpointPrefetchLimit ?? CHECKPOINT_PREFETCH_LIMIT;
176
+ prefetchedCheckpoints = await this.l2BlockSource.getCheckpoints(nextCheckpointNumber, prefetchLimit);
177
+ prefetchIdx = 0;
178
+ if (prefetchedCheckpoints.length === 0) {
168
179
  break;
169
180
  }
170
- checkpoint = checkpoints[0];
171
181
  }
172
182
 
183
+ const checkpoint = prefetchedCheckpoints[prefetchIdx]!;
184
+
173
185
  // Get all blocks from this checkpoint that we need, respecting batchSize
186
+ const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.checkpointed.block.number - nextBlockNumber + 1);
174
187
  const blocksForCheckpoint = checkpoint.checkpoint.blocks
175
188
  .filter(b => b.number >= nextBlockNumber)
176
189
  .slice(0, limit);
@@ -180,23 +193,27 @@ export class L2BlockStream {
180
193
  await this.emitEvent({ type: 'blocks-added', blocks: blocksForCheckpoint });
181
194
  nextBlockNumber = blocksForCheckpoint.at(-1)!.number + 1;
182
195
 
183
- // If we've reached the end of this checkpoint, emit the checkpoint event
196
+ // If we've reached the end of this checkpoint, emit the checkpoint event and move to next
184
197
  const lastBlockInCheckpoint = checkpoint.checkpoint.blocks.at(-1)!;
185
- if (!this.opts.ignoreCheckpoints && nextBlockNumber > lastBlockInCheckpoint.number) {
186
- const lastBlockHash = await lastBlockInCheckpoint.hash();
187
- await this.emitEvent({
188
- type: 'chain-checkpointed',
189
- checkpoint,
190
- block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString()),
191
- });
198
+ if (nextBlockNumber > lastBlockInCheckpoint.number) {
199
+ if (!this.opts.ignoreCheckpoints) {
200
+ const lastBlockHash = await lastBlockInCheckpoint.hash();
201
+ await this.emitEvent({
202
+ type: 'chain-checkpointed',
203
+ checkpoint,
204
+ block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString()),
205
+ });
206
+ }
207
+ prefetchIdx++;
208
+ nextCheckpointNumber = CheckpointNumber(nextCheckpointNumber + 1);
192
209
  }
193
210
  }
194
211
 
195
212
  // Loop 3: Fetch any remaining uncheckpointed (proposed) blocks.
196
213
  while (nextBlockNumber <= sourceTips.proposed.number) {
197
214
  const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
198
- this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit} proven=${this.opts.proven}`);
199
- const blocks = await this.l2BlockSource.getL2BlocksNew(BlockNumber(nextBlockNumber), limit, this.opts.proven);
215
+ this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}`);
216
+ const blocks = await this.l2BlockSource.getBlocks(BlockNumber(nextBlockNumber), BlockNumber(limit));
200
217
  if (blocks.length === 0) {
201
218
  break;
202
219
  }
@@ -2,7 +2,7 @@ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
2
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
3
 
4
4
  import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
5
- import type { L2BlockNew } from '../l2_block_new.js';
5
+ import type { L2Block } from '../l2_block.js';
6
6
  import {
7
7
  type CheckpointId,
8
8
  GENESIS_CHECKPOINT_HEADER_HASH,
@@ -109,7 +109,7 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
109
109
  }
110
110
 
111
111
  // Protected helper that subclasses can override for block hash computation
112
- protected computeBlockHash(block: L2BlockNew): Promise<string> {
112
+ protected computeBlockHash(block: L2Block): Promise<string> {
113
113
  return block.hash().then(hash => hash.toString());
114
114
  }
115
115
 
@@ -5,8 +5,8 @@ import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import {
6
6
  type CheckpointId,
7
7
  GENESIS_CHECKPOINT_HEADER_HASH,
8
+ L2Block,
8
9
  type L2BlockId,
9
- L2BlockNew,
10
10
  type L2TipId,
11
11
  } from '@aztec/stdlib/block';
12
12
  import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
@@ -31,8 +31,8 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
31
31
  blockToCheckpoint.clear();
32
32
  });
33
33
 
34
- const makeBlock = async (number: number): Promise<L2BlockNew> => {
35
- const block = await L2BlockNew.random(BlockNumber(number));
34
+ const makeBlock = async (number: number): Promise<L2Block> => {
35
+ const block = await L2Block.random(BlockNumber(number));
36
36
  blockHashes.set(number, (await block.hash()).toString());
37
37
  return block;
38
38
  };
@@ -74,7 +74,7 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
74
74
  checkpointed: makeTipId(checkpointed),
75
75
  });
76
76
 
77
- const makeCheckpoint = async (checkpointNumber: number, blocks: L2BlockNew[]): Promise<PublishedCheckpoint> => {
77
+ const makeCheckpoint = async (checkpointNumber: number, blocks: L2Block[]): Promise<PublishedCheckpoint> => {
78
78
  const checkpoint = await Checkpoint.random(CheckpointNumber(checkpointNumber), {
79
79
  numBlocks: blocks.length,
80
80
  startBlockNumber: blocks[0].number,
@@ -13,7 +13,7 @@ import type { FieldsOf } from '@aztec/foundation/types';
13
13
 
14
14
  import { z } from 'zod';
15
15
 
16
- import { L2BlockNew } from '../block/l2_block_new.js';
16
+ import { L2Block } from '../block/l2_block.js';
17
17
  import { MAX_BLOCKS_PER_CHECKPOINT } from '../deserialization/index.js';
18
18
  import { computeCheckpointOutHash } from '../messaging/out_hash.js';
19
19
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
@@ -29,7 +29,7 @@ export class Checkpoint {
29
29
  /** Header of the checkpoint. */
30
30
  public header: CheckpointHeader,
31
31
  /** L2 blocks in the checkpoint. */
32
- public blocks: L2BlockNew[],
32
+ public blocks: L2Block[],
33
33
  /** Number of the checkpoint. */
34
34
  public number: CheckpointNumber,
35
35
  ) {}
@@ -43,7 +43,7 @@ export class Checkpoint {
43
43
  .object({
44
44
  archive: AppendOnlyTreeSnapshot.schema,
45
45
  header: CheckpointHeader.schema,
46
- blocks: z.array(L2BlockNew.schema),
46
+ blocks: z.array(L2Block.schema),
47
47
  number: CheckpointNumberSchema,
48
48
  })
49
49
  .transform(({ archive, header, blocks, number }) => new Checkpoint(archive, header, blocks, number));
@@ -62,7 +62,7 @@ export class Checkpoint {
62
62
  return new Checkpoint(
63
63
  reader.readObject(AppendOnlyTreeSnapshot),
64
64
  reader.readObject(CheckpointHeader),
65
- reader.readVector(L2BlockNew, MAX_BLOCKS_PER_CHECKPOINT),
65
+ reader.readVector(L2Block, MAX_BLOCKS_PER_CHECKPOINT),
66
66
  CheckpointNumber(reader.readNumber()),
67
67
  );
68
68
  }
@@ -135,16 +135,16 @@ export class Checkpoint {
135
135
  startBlockNumber?: number;
136
136
  previousArchive?: AppendOnlyTreeSnapshot;
137
137
  } & Partial<Parameters<typeof CheckpointHeader.random>[0]> &
138
- Partial<Parameters<typeof L2BlockNew.random>[1]> = {},
138
+ Partial<Parameters<typeof L2Block.random>[1]> = {},
139
139
  ) {
140
140
  const header = CheckpointHeader.random(options);
141
141
 
142
142
  // Create blocks sequentially to chain archive roots properly.
143
143
  // Each block's header.lastArchive must equal the previous block's archive.
144
- const blocks: L2BlockNew[] = [];
144
+ const blocks: L2Block[] = [];
145
145
  let lastArchive = previousArchive;
146
146
  for (let i = 0; i < numBlocks; i++) {
147
- const block = await L2BlockNew.random(BlockNumber(startBlockNumber + i), {
147
+ const block = await L2Block.random(BlockNumber(startBlockNumber + i), {
148
148
  indexWithinCheckpoint: IndexWithinCheckpoint(i),
149
149
  ...options,
150
150
  ...(lastArchive ? { lastArchive } : {}),
@@ -21,7 +21,7 @@ export const nodeRpcConfigMappings: ConfigMappingsType<NodeRPCConfig> = {
21
21
  rpcMaxBodySize: {
22
22
  env: 'RPC_MAX_BODY_SIZE',
23
23
  description: 'Maximum allowed batch size for JSON RPC batch requests.',
24
- defaultValue: '50mb',
24
+ defaultValue: '1mb',
25
25
  },
26
26
  };
27
27
 
@@ -1,5 +1,4 @@
1
1
  import { FUNCTION_TREE_HEIGHT, GeneratorIndex } from '@aztec/constants';
2
- import { pedersenHash } from '@aztec/foundation/crypto/pedersen';
3
2
  import { poseidon2Hash, poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
4
3
  import { Fr } from '@aztec/foundation/curves/bn254';
5
4
  import { type MerkleTree, MerkleTreeCalculator } from '@aztec/foundation/trees';
@@ -38,7 +37,7 @@ export async function computePrivateFunctionLeaf(fn: PrivateFunction): Promise<B
38
37
  async function getPrivateFunctionTreeCalculator(): Promise<MerkleTreeCalculator> {
39
38
  if (!privateFunctionTreeCalculator) {
40
39
  const functionTreeZeroLeaf = (
41
- await pedersenHash(new Array(PRIVATE_FUNCTION_SIZE).fill(0))
40
+ await poseidon2Hash(new Array(PRIVATE_FUNCTION_SIZE).fill(0))
42
41
  ).toBuffer() as Buffer<ArrayBuffer>;
43
42
  privateFunctionTreeCalculator = await MerkleTreeCalculator.create(
44
43
  FUNCTION_TREE_HEIGHT,
@@ -69,7 +69,7 @@ export function getSlotRangeForEpoch(
69
69
  epochNumber: EpochNumber,
70
70
  constants: Pick<L1RollupConstants, 'epochDuration'>,
71
71
  ): [SlotNumber, SlotNumber] {
72
- const startSlot = SlotNumber(epochNumber * constants.epochDuration);
72
+ const startSlot = SlotNumber(Number(epochNumber) * constants.epochDuration);
73
73
  return [startSlot, SlotNumber(startSlot + constants.epochDuration - 1)];
74
74
  }
75
75
 
@@ -2,3 +2,4 @@ export const MAX_RPC_LEN = 100;
2
2
  export const MAX_RPC_TXS_LEN = 50;
3
3
  export const MAX_RPC_BLOCKS_LEN = 50;
4
4
  export const MAX_RPC_CHECKPOINTS_LEN = 50;
5
+ export const MAX_LOGS_PER_TAG = 10;
@@ -5,7 +5,7 @@ import type { ApiSchemaFor } from '@aztec/foundation/schemas';
5
5
  import { z } from 'zod';
6
6
 
7
7
  import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
8
- import { L2BlockNew } from '../block/l2_block_new.js';
8
+ import { L2Block } from '../block/l2_block.js';
9
9
  import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
10
10
  import { ValidateCheckpointResultSchema } from '../block/validate_block_result.js';
11
11
  import { Checkpoint } from '../checkpoint/checkpoint.js';
@@ -82,7 +82,9 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
82
82
  getRegistryAddress: z.function().args().returns(schemas.EthAddress),
83
83
  getBlockNumber: z.function().args().returns(BlockNumberSchema),
84
84
  getProvenBlockNumber: z.function().args().returns(BlockNumberSchema),
85
- getBlock: z.function().args(BlockNumberSchema).returns(L2BlockNew.schema.optional()),
85
+ getCheckpointedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
86
+ getFinalizedL2BlockNumber: z.function().args().returns(BlockNumberSchema),
87
+ getBlock: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
86
88
  getBlockHeader: z
87
89
  .function()
88
90
  .args(z.union([BlockNumberSchema, z.literal('latest')]))
@@ -90,48 +92,37 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
90
92
  getCheckpointedBlock: z.function().args(BlockNumberSchema).returns(CheckpointedL2Block.schema.optional()),
91
93
  getCheckpointedBlocks: z
92
94
  .function()
93
- .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
95
+ .args(BlockNumberSchema, schemas.Integer)
94
96
  .returns(z.array(CheckpointedL2Block.schema)),
95
- getBlocks: z
96
- .function()
97
- .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
98
- .returns(z.array(L2BlockNew.schema)),
99
- getPublishedCheckpoints: z
97
+ getBlocks: z.function().args(BlockNumberSchema, schemas.Integer).returns(z.array(L2Block.schema)),
98
+ getCheckpoints: z
100
99
  .function()
101
100
  .args(CheckpointNumberSchema, schemas.Integer)
102
101
  .returns(z.array(PublishedCheckpoint.schema)),
103
- getPublishedBlocks: z
104
- .function()
105
- .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
106
- .returns(z.array(CheckpointedL2Block.schema)),
107
- getL2BlocksNew: z
108
- .function()
109
- .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
110
- .returns(z.array(L2BlockNew.schema)),
111
- getPublishedBlockByHash: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
112
- getPublishedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
102
+ getCheckpointedBlockByHash: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
103
+ getCheckpointedBlockByArchive: z.function().args(schemas.Fr).returns(CheckpointedL2Block.schema.optional()),
113
104
  getBlockHeaderByHash: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
114
105
  getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
115
- getL2BlockNew: z.function().args(BlockNumberSchema).returns(L2BlockNew.schema.optional()),
116
- getL2BlockNewByHash: z.function().args(schemas.Fr).returns(L2BlockNew.schema.optional()),
117
- getL2BlockNewByArchive: z.function().args(schemas.Fr).returns(L2BlockNew.schema.optional()),
106
+ getL2Block: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
107
+ getL2BlockByHash: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
108
+ getL2BlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
118
109
  getTxEffect: z.function().args(TxHash.schema).returns(indexedTxSchema().optional()),
119
110
  getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
120
111
  getL2SlotNumber: z.function().args().returns(schemas.SlotNumber.optional()),
121
112
  getL2EpochNumber: z.function().args().returns(EpochNumberSchema.optional()),
122
113
  getCheckpointsForEpoch: z.function().args(EpochNumberSchema).returns(z.array(Checkpoint.schema)),
123
- getBlocksForEpoch: z.function().args(EpochNumberSchema).returns(z.array(L2BlockNew.schema)),
124
- getBlocksForSlot: z.function().args(schemas.SlotNumber).returns(z.array(L2BlockNew.schema)),
125
- getBlockHeadersForEpoch: z.function().args(EpochNumberSchema).returns(z.array(BlockHeader.schema)),
114
+ getCheckpointedBlocksForEpoch: z.function().args(EpochNumberSchema).returns(z.array(CheckpointedL2Block.schema)),
115
+ getBlocksForSlot: z.function().args(schemas.SlotNumber).returns(z.array(L2Block.schema)),
116
+ getCheckpointedBlockHeadersForEpoch: z.function().args(EpochNumberSchema).returns(z.array(BlockHeader.schema)),
126
117
  isEpochComplete: z.function().args(EpochNumberSchema).returns(z.boolean()),
127
118
  getL2Tips: z.function().args().returns(L2TipsSchema),
128
119
  getPrivateLogsByTags: z
129
120
  .function()
130
- .args(z.array(SiloedTag.schema))
121
+ .args(z.array(SiloedTag.schema), optional(z.number().gte(0)))
131
122
  .returns(z.array(z.array(TxScopedL2Log.schema))),
132
123
  getPublicLogsByTagsFromContract: z
133
124
  .function()
134
- .args(schemas.AztecAddress, z.array(Tag.schema))
125
+ .args(schemas.AztecAddress, z.array(Tag.schema), optional(z.number().gte(0)))
135
126
  .returns(z.array(z.array(TxScopedL2Log.schema))),
136
127
  getPublicLogs: z.function().args(LogFilterSchema).returns(GetPublicLogsResponseSchema),
137
128
  getContractClassLogs: z.function().args(LogFilterSchema).returns(GetContractClassLogsResponseSchema),