@aztec/validator-client 0.0.1-commit.0b941701 → 0.0.1-commit.10bd49492

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 (50) hide show
  1. package/README.md +63 -18
  2. package/dest/block_proposal_handler.d.ts +7 -7
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +125 -64
  5. package/dest/checkpoint_builder.d.ts +21 -12
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +107 -39
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +28 -4
  11. package/dest/duties/validation_service.d.ts +2 -2
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +5 -11
  14. package/dest/factory.d.ts +1 -1
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +2 -1
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/key_store/ha_key_store.d.ts +1 -1
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -1
  22. package/dest/key_store/ha_key_store.js +3 -3
  23. package/dest/metrics.d.ts +12 -3
  24. package/dest/metrics.d.ts.map +1 -1
  25. package/dest/metrics.js +46 -5
  26. package/dest/validator.d.ts +40 -14
  27. package/dest/validator.d.ts.map +1 -1
  28. package/dest/validator.js +213 -57
  29. package/package.json +19 -17
  30. package/src/block_proposal_handler.ts +155 -85
  31. package/src/checkpoint_builder.ts +144 -38
  32. package/src/config.ts +28 -4
  33. package/src/duties/validation_service.ts +11 -10
  34. package/src/factory.ts +1 -0
  35. package/src/index.ts +0 -1
  36. package/src/key_store/ha_key_store.ts +3 -3
  37. package/src/metrics.ts +63 -6
  38. package/src/validator.ts +263 -68
  39. package/dest/tx_validator/index.d.ts +0 -3
  40. package/dest/tx_validator/index.d.ts.map +0 -1
  41. package/dest/tx_validator/index.js +0 -2
  42. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  43. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  44. package/dest/tx_validator/nullifier_cache.js +0 -24
  45. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  46. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  47. package/dest/tx_validator/tx_validator_factory.js +0 -54
  48. package/src/tx_validator/index.ts +0 -2
  49. package/src/tx_validator/nullifier_cache.ts +0 -30
  50. package/src/tx_validator/tx_validator_factory.ts +0 -135
@@ -1,27 +1,25 @@
1
1
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
2
  import type { EpochCache } from '@aztec/epoch-cache';
3
3
  import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
4
- import { chunkBy } from '@aztec/foundation/collection';
4
+ import { pick } from '@aztec/foundation/collection';
5
5
  import { Fr } from '@aztec/foundation/curves/bn254';
6
6
  import { TimeoutError } from '@aztec/foundation/error';
7
7
  import { createLogger } from '@aztec/foundation/log';
8
8
  import { retryUntil } from '@aztec/foundation/retry';
9
9
  import { DateProvider, Timer } from '@aztec/foundation/timer';
10
10
  import type { P2P, PeerId } from '@aztec/p2p';
11
- import { TxProvider } from '@aztec/p2p';
12
11
  import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
13
- import type { L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
12
+ import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
14
13
  import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
15
- import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
16
- import {
17
- type L1ToL2MessageSource,
18
- computeCheckpointOutHash,
19
- computeInHashFromL1ToL2Messages,
20
- } from '@aztec/stdlib/messaging';
14
+ import { Gas } from '@aztec/stdlib/gas';
15
+ import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
16
+ import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
21
17
  import type { BlockProposal } from '@aztec/stdlib/p2p';
22
- import { BlockHeader, type CheckpointGlobalVariables, type FailedTx, type Tx } from '@aztec/stdlib/tx';
18
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
19
+ import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
23
20
  import {
24
21
  ReExFailedTxsError,
22
+ ReExInitialStateMismatchError,
25
23
  ReExStateMismatchError,
26
24
  ReExTimeoutError,
27
25
  TransactionsNotAvailableError,
@@ -34,6 +32,7 @@ import type { ValidatorMetrics } from './metrics.js';
34
32
  export type BlockProposalValidationFailureReason =
35
33
  | 'invalid_proposal'
36
34
  | 'parent_block_not_found'
35
+ | 'block_source_not_synced'
37
36
  | 'parent_block_wrong_slot'
38
37
  | 'in_hash_mismatch'
39
38
  | 'global_variables_mismatch'
@@ -41,6 +40,7 @@ export type BlockProposalValidationFailureReason =
41
40
  | 'txs_not_available'
42
41
  | 'state_mismatch'
43
42
  | 'failed_txs'
43
+ | 'initial_state_mismatch'
44
44
  | 'timeout'
45
45
  | 'unknown_error';
46
46
 
@@ -78,7 +78,7 @@ export class BlockProposalHandler {
78
78
  private worldState: WorldStateSynchronizer,
79
79
  private blockSource: L2BlockSource & L2BlockSink,
80
80
  private l1ToL2MessageSource: L1ToL2MessageSource,
81
- private txProvider: TxProvider,
81
+ private txProvider: ITxProvider,
82
82
  private blockProposalValidator: BlockProposalValidator,
83
83
  private epochCache: EpochCache,
84
84
  private config: ValidatorClientFullConfig,
@@ -93,25 +93,28 @@ export class BlockProposalHandler {
93
93
  this.tracer = telemetry.getTracer('BlockProposalHandler');
94
94
  }
95
95
 
96
- registerForReexecution(p2pClient: P2P): BlockProposalHandler {
97
- // Non-validator handler that re-executes for monitoring but does not attest.
96
+ register(p2pClient: P2P, shouldReexecute: boolean): BlockProposalHandler {
97
+ // Non-validator handler that processes or re-executes for monitoring but does not attest.
98
98
  // Returns boolean indicating whether the proposal was valid.
99
99
  const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
100
100
  try {
101
- const result = await this.handleBlockProposal(proposal, proposalSender, true);
101
+ const { slotNumber, blockNumber } = proposal;
102
+ const result = await this.handleBlockProposal(proposal, proposalSender, shouldReexecute);
102
103
  if (result.isValid) {
103
- this.log.info(`Non-validator reexecution completed for slot ${proposal.slotNumber}`, {
104
+ this.log.info(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} handled`, {
104
105
  blockNumber: result.blockNumber,
106
+ slotNumber,
105
107
  reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
106
108
  totalManaUsed: result.reexecutionResult?.totalManaUsed,
107
109
  numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
110
+ reexecuted: shouldReexecute,
108
111
  });
109
112
  return true;
110
113
  } else {
111
- this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber}`, {
112
- blockNumber: result.blockNumber,
113
- reason: result.reason,
114
- });
114
+ this.log.warn(
115
+ `Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`,
116
+ { blockNumber: result.blockNumber, slotNumber, reason: result.reason },
117
+ );
115
118
  return false;
116
119
  }
117
120
  } catch (error) {
@@ -139,7 +142,13 @@ export class BlockProposalHandler {
139
142
  return { isValid: false, reason: 'invalid_proposal' };
140
143
  }
141
144
 
142
- const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
145
+ const proposalInfo = {
146
+ ...proposal.toBlockInfo(),
147
+ proposer: proposer.toString(),
148
+ blockNumber: undefined as BlockNumber | undefined,
149
+ checkpointNumber: undefined as CheckpointNumber | undefined,
150
+ };
151
+
143
152
  this.log.info(`Processing proposal for slot ${slotNumber}`, {
144
153
  ...proposalInfo,
145
154
  txHashes: proposal.txHashes.map(t => t.toString()),
@@ -153,17 +162,30 @@ export class BlockProposalHandler {
153
162
  return { isValid: false, reason: 'invalid_proposal' };
154
163
  }
155
164
 
156
- // Check that the parent proposal is a block we know, otherwise reexecution would fail
157
- const parentBlockHeader = await this.getParentBlock(proposal);
158
- if (parentBlockHeader === undefined) {
165
+ // Ensure the block source is synced before checking for existing blocks,
166
+ // since a pending checkpoint prune may remove blocks we'd otherwise find.
167
+ // This affects mostly the block_number_already_exists check, since a pending
168
+ // checkpoint prune could remove a block that would conflict with this proposal.
169
+ // TODO(@Maddiaa0): This may break staggered slots.
170
+ const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
171
+ if (!blockSourceSync) {
172
+ this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
173
+ return { isValid: false, reason: 'block_source_not_synced' };
174
+ }
175
+
176
+ // Check that the parent proposal is a block we know, otherwise reexecution would fail.
177
+ // If we don't find it immediately, we keep retrying for a while; it may be we still
178
+ // need to process other block proposals to get to it.
179
+ const parentBlock = await this.getParentBlock(proposal);
180
+ if (parentBlock === undefined) {
159
181
  this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
160
182
  return { isValid: false, reason: 'parent_block_not_found' };
161
183
  }
162
184
 
163
- // Check that the parent block's slot is less than the proposal's slot (should not happen, but we check anyway)
164
- if (parentBlockHeader !== 'genesis' && parentBlockHeader.getSlot() >= slotNumber) {
165
- this.log.warn(`Parent block slot is greater than or equal to proposal slot, skipping processing`, {
166
- parentBlockSlot: parentBlockHeader.getSlot().toString(),
185
+ // Check that the parent block's slot is not greater than the proposal's slot.
186
+ if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
187
+ this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
188
+ parentBlockSlot: parentBlock.header.getSlot().toString(),
167
189
  proposalSlot: slotNumber.toString(),
168
190
  ...proposalInfo,
169
191
  });
@@ -172,9 +194,10 @@ export class BlockProposalHandler {
172
194
 
173
195
  // Compute the block number based on the parent block
174
196
  const blockNumber =
175
- parentBlockHeader === 'genesis'
197
+ parentBlock === 'genesis'
176
198
  ? BlockNumber(INITIAL_L2_BLOCK_NUM)
177
- : BlockNumber(parentBlockHeader.getBlockNumber() + 1);
199
+ : BlockNumber(parentBlock.header.getBlockNumber() + 1);
200
+ proposalInfo.blockNumber = blockNumber;
178
201
 
179
202
  // Check that this block number does not exist already
180
203
  const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
@@ -190,12 +213,22 @@ export class BlockProposalHandler {
190
213
  deadline: this.getReexecutionDeadline(slotNumber, config),
191
214
  });
192
215
 
216
+ // If reexecution is disabled, bail. We were just interested in triggering tx collection.
217
+ if (!shouldReexecute) {
218
+ this.log.info(
219
+ `Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
220
+ proposalInfo,
221
+ );
222
+ return { isValid: true, blockNumber };
223
+ }
224
+
193
225
  // Compute the checkpoint number for this block and validate checkpoint consistency
194
- const checkpointResult = await this.computeCheckpointNumber(proposal, parentBlockHeader, proposalInfo);
226
+ const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
195
227
  if (checkpointResult.reason) {
196
228
  return { isValid: false, blockNumber, reason: checkpointResult.reason };
197
229
  }
198
230
  const checkpointNumber = checkpointResult.checkpointNumber;
231
+ proposalInfo.checkpointNumber = checkpointNumber;
199
232
 
200
233
  // Check that I have the same set of l1ToL2Messages as the proposal
201
234
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
@@ -216,36 +249,28 @@ export class BlockProposalHandler {
216
249
  return { isValid: false, blockNumber, reason: 'txs_not_available' };
217
250
  }
218
251
 
252
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
253
+ const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
254
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
255
+ .filter(c => c.checkpointNumber < checkpointNumber)
256
+ .map(c => c.checkpointOutHash);
257
+
219
258
  // Try re-executing the transactions in the proposal if needed
220
259
  let reexecutionResult;
221
- if (shouldReexecute) {
222
- // Compute the previous checkpoint out hashes for the epoch.
223
- // TODO(leila/mbps): There can be a more efficient way to get the previous checkpoint out
224
- // hashes without having to fetch all the blocks.
225
- const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
226
- const checkpointedBlocks = (await this.blockSource.getCheckpointedBlocksForEpoch(epoch))
227
- .filter(b => b.block.number < blockNumber)
228
- .sort((a, b) => a.block.number - b.block.number);
229
- const blocksByCheckpoint = chunkBy(checkpointedBlocks, b => b.checkpointNumber);
230
- const previousCheckpointOutHashes = blocksByCheckpoint.map(checkpointBlocks =>
231
- computeCheckpointOutHash(checkpointBlocks.map(b => b.block.body.txEffects.map(tx => tx.l2ToL1Msgs))),
260
+ try {
261
+ this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
262
+ reexecutionResult = await this.reexecuteTransactions(
263
+ proposal,
264
+ blockNumber,
265
+ checkpointNumber,
266
+ txs,
267
+ l1ToL2Messages,
268
+ previousCheckpointOutHashes,
232
269
  );
233
-
234
- try {
235
- this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
236
- reexecutionResult = await this.reexecuteTransactions(
237
- proposal,
238
- blockNumber,
239
- checkpointNumber,
240
- txs,
241
- l1ToL2Messages,
242
- previousCheckpointOutHashes,
243
- );
244
- } catch (error) {
245
- this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
246
- const reason = this.getReexecuteFailureReason(error);
247
- return { isValid: false, blockNumber, reason, reexecutionResult };
248
- }
270
+ } catch (error) {
271
+ this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
272
+ const reason = this.getReexecuteFailureReason(error);
273
+ return { isValid: false, blockNumber, reason, reexecutionResult };
249
274
  }
250
275
 
251
276
  // If we succeeded, push this block into the archiver (unless disabled)
@@ -254,14 +279,14 @@ export class BlockProposalHandler {
254
279
  }
255
280
 
256
281
  this.log.info(
257
- `Successfully processed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
258
- proposalInfo,
282
+ `Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
283
+ { ...proposalInfo, ...pick(reexecutionResult, 'reexecutionTimeMs', 'totalManaUsed') },
259
284
  );
260
285
 
261
286
  return { isValid: true, blockNumber, reexecutionResult };
262
287
  }
263
288
 
264
- private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockHeader | undefined> {
289
+ private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
265
290
  const parentArchive = proposal.blockHeader.lastArchive.root;
266
291
  const slot = proposal.slotNumber;
267
292
  const config = this.checkpointsBuilder.getConfig();
@@ -277,12 +302,11 @@ export class BlockProposalHandler {
277
302
 
278
303
  try {
279
304
  return (
280
- (await this.blockSource.getBlockHeaderByArchive(parentArchive)) ??
305
+ (await this.blockSource.getBlockDataByArchive(parentArchive)) ??
281
306
  (timeoutDurationMs <= 0
282
307
  ? undefined
283
308
  : await retryUntil(
284
- () =>
285
- this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
309
+ () => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
286
310
  'force archiver sync',
287
311
  timeoutDurationMs / 1000,
288
312
  0.5,
@@ -298,12 +322,12 @@ export class BlockProposalHandler {
298
322
  }
299
323
  }
300
324
 
301
- private async computeCheckpointNumber(
325
+ private computeCheckpointNumber(
302
326
  proposal: BlockProposal,
303
- parentBlockHeader: 'genesis' | BlockHeader,
327
+ parentBlock: 'genesis' | BlockData,
304
328
  proposalInfo: object,
305
- ): Promise<CheckpointComputationResult> {
306
- if (parentBlockHeader === 'genesis') {
329
+ ): CheckpointComputationResult {
330
+ if (parentBlock === 'genesis') {
307
331
  // First block is in checkpoint 1
308
332
  if (proposal.indexWithinCheckpoint !== 0) {
309
333
  this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
@@ -312,19 +336,9 @@ export class BlockProposalHandler {
312
336
  return { checkpointNumber: CheckpointNumber.INITIAL };
313
337
  }
314
338
 
315
- // Get the parent block to find its checkpoint number
316
- // TODO(palla/mbps): The block header should include the checkpoint number to avoid this lookup,
317
- // or at least the L2BlockSource should return a different struct that includes it.
318
- const parentBlockNumber = parentBlockHeader.getBlockNumber();
319
- const parentBlock = await this.blockSource.getL2Block(parentBlockNumber);
320
- if (!parentBlock) {
321
- this.log.warn(`Parent block ${parentBlockNumber} not found in archiver`, proposalInfo);
322
- return { reason: 'invalid_proposal' };
323
- }
324
-
325
339
  if (proposal.indexWithinCheckpoint === 0) {
326
340
  // If this is the first block in a new checkpoint, increment the checkpoint number
327
- if (!(proposal.blockHeader.getSlot() > parentBlockHeader.getSlot())) {
341
+ if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
328
342
  this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
329
343
  return { reason: 'invalid_proposal' };
330
344
  }
@@ -336,7 +350,7 @@ export class BlockProposalHandler {
336
350
  this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
337
351
  return { reason: 'invalid_proposal' };
338
352
  }
339
- if (proposal.blockHeader.getSlot() !== parentBlockHeader.getSlot()) {
353
+ if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
340
354
  this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
341
355
  return { reason: 'invalid_proposal' };
342
356
  }
@@ -357,7 +371,7 @@ export class BlockProposalHandler {
357
371
  */
358
372
  private validateNonFirstBlockInCheckpoint(
359
373
  proposal: BlockProposal,
360
- parentBlock: L2Block,
374
+ parentBlock: BlockData,
361
375
  proposalInfo: object,
362
376
  ): CheckpointComputationResult | undefined {
363
377
  const proposalGlobals = proposal.blockHeader.globalVariables;
@@ -436,8 +450,46 @@ export class BlockProposalHandler {
436
450
  return new Date(nextSlotTimestampSeconds * 1000);
437
451
  }
438
452
 
439
- private getReexecuteFailureReason(err: any) {
440
- if (err instanceof ReExStateMismatchError) {
453
+ /** Waits for the block source to sync L1 data up to at least the slot before the given one. */
454
+ private async waitForBlockSourceSync(slot: SlotNumber): Promise<boolean> {
455
+ const deadline = this.getReexecutionDeadline(slot, this.checkpointsBuilder.getConfig());
456
+ const timeoutMs = deadline.getTime() - this.dateProvider.now();
457
+ if (slot === 0) {
458
+ return true;
459
+ }
460
+
461
+ // Make a quick check before triggering an archiver sync
462
+ const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
463
+ if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
464
+ return true;
465
+ }
466
+
467
+ try {
468
+ // Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
469
+ return await retryUntil(
470
+ async () => {
471
+ await this.blockSource.syncImmediate();
472
+ const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
473
+ return syncedSlot !== undefined && syncedSlot + 1 >= slot;
474
+ },
475
+ 'wait for block source sync',
476
+ timeoutMs / 1000,
477
+ 0.5,
478
+ );
479
+ } catch (err) {
480
+ if (err instanceof TimeoutError) {
481
+ this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
482
+ return false;
483
+ } else {
484
+ throw err;
485
+ }
486
+ }
487
+ }
488
+
489
+ private getReexecuteFailureReason(err: any): BlockProposalValidationFailureReason {
490
+ if (err instanceof ReExInitialStateMismatchError) {
491
+ return 'initial_state_mismatch';
492
+ } else if (err instanceof ReExStateMismatchError) {
441
493
  return 'state_mismatch';
442
494
  } else if (err instanceof ReExFailedTxsError) {
443
495
  return 'failed_txs';
@@ -475,13 +527,22 @@ export class BlockProposalHandler {
475
527
 
476
528
  // Fork before the block to be built
477
529
  const parentBlockNumber = BlockNumber(blockNumber - 1);
478
- using fork = await this.worldState.fork(parentBlockNumber);
530
+ await this.worldState.syncImmediate(parentBlockNumber);
531
+ await using fork = await this.worldState.fork(parentBlockNumber);
532
+
533
+ // Verify the fork's archive root matches the proposal's expected last archive.
534
+ // If they don't match, our world state synced to a different chain and reexecution would fail.
535
+ const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
536
+ if (!forkArchiveRoot.equals(proposal.blockHeader.lastArchive.root)) {
537
+ throw new ReExInitialStateMismatchError(proposal.blockHeader.lastArchive.root, forkArchiveRoot);
538
+ }
479
539
 
480
- // Build checkpoint constants from proposal (excludes blockNumber and timestamp which are per-block)
540
+ // Build checkpoint constants from proposal (excludes blockNumber which is per-block)
481
541
  const constants: CheckpointGlobalVariables = {
482
542
  chainId: new Fr(config.l1ChainId),
483
543
  version: new Fr(config.rollupVersion),
484
544
  slotNumber: slot,
545
+ timestamp: blockHeader.globalVariables.timestamp,
485
546
  coinbase: blockHeader.globalVariables.coinbase,
486
547
  feeRecipient: blockHeader.globalVariables.feeRecipient,
487
548
  gasFees: blockHeader.globalVariables.gasFees,
@@ -491,26 +552,35 @@ export class BlockProposalHandler {
491
552
  const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
492
553
  checkpointNumber,
493
554
  constants,
555
+ 0n, // only takes effect in the following checkpoint.
494
556
  l1ToL2Messages,
495
557
  previousCheckpointOutHashes,
496
558
  fork,
497
559
  priorBlocks,
560
+ this.log.getBindings(),
498
561
  );
499
562
 
500
563
  // Build the new block
501
564
  const deadline = this.getReexecutionDeadline(slot, config);
565
+ const maxBlockGas =
566
+ this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined
567
+ ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity)
568
+ : undefined;
502
569
  const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
503
570
  deadline,
504
571
  expectedEndState: blockHeader.state,
572
+ maxTransactions: this.config.validateMaxTxsPerBlock,
573
+ maxBlockGas,
505
574
  });
506
575
 
507
576
  const { block, failedTxs } = result;
508
577
  const numFailedTxs = failedTxs.length;
509
578
 
510
- this.log.verbose(`Transaction re-execution complete for slot ${slot}`, {
579
+ this.log.verbose(`Block proposal ${blockNumber} at slot ${slot} transaction re-execution complete`, {
511
580
  numFailedTxs,
512
581
  numProposalTxs: txHashes.length,
513
582
  numProcessedTxs: block.body.txEffects.length,
583
+ blockNumber,
514
584
  slot,
515
585
  });
516
586