@aztec/validator-client 0.0.1-commit.7035c9bd6 → 0.0.1-commit.71324e566

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dest/validator.js CHANGED
@@ -1,27 +1,22 @@
1
1
  import { getBlobsPerL1Block } from '@aztec/blob-lib';
2
- import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
3
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
4
- import { TimeoutError } from '@aztec/foundation/error';
2
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
5
3
  import { createLogger } from '@aztec/foundation/log';
6
- import { retryUntil } from '@aztec/foundation/retry';
7
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
8
5
  import { sleep } from '@aztec/foundation/sleep';
9
6
  import { DateProvider } from '@aztec/foundation/timer';
10
7
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
11
8
  import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
12
- import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
13
- import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
14
- import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
9
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
15
10
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
16
11
  import { getTelemetryClient } from '@aztec/telemetry-client';
17
12
  import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
18
13
  import { DutyType } from '@aztec/validator-ha-signer/types';
19
14
  import { EventEmitter } from 'events';
20
- import { BlockProposalHandler } from './block_proposal_handler.js';
21
15
  import { ValidationService } from './duties/validation_service.js';
22
16
  import { HAKeyStore } from './key_store/ha_key_store.js';
23
17
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
24
18
  import { ValidatorMetrics } from './metrics.js';
19
+ import { ProposalHandler } from './proposal_handler.js';
25
20
  // We maintain a set of proposers who have proposed invalid blocks.
26
21
  // Just cap the set to avoid unbounded growth.
27
22
  const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
@@ -36,7 +31,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
36
31
  keyStore;
37
32
  epochCache;
38
33
  p2pClient;
39
- blockProposalHandler;
34
+ proposalHandler;
40
35
  blockSource;
41
36
  checkpointsBuilder;
42
37
  worldState;
@@ -58,8 +53,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
58
53
  /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
59
54
  proposersOfInvalidBlocks;
60
55
  /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
61
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
62
- super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
56
+ constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
57
+ super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
63
58
  // Create child logger with fisherman prefix if in fisherman mode
64
59
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
65
60
  this.tracer = telemetry.getTracer('Validator');
@@ -120,7 +115,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
120
115
  txsPermitted: !config.disableTransactions,
121
116
  maxTxsPerBlock: config.validateMaxTxsPerBlock
122
117
  });
123
- const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
118
+ const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry, undefined);
124
119
  const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
125
120
  let slashingProtectionSigner;
126
121
  if (slashingProtectionDb) {
@@ -149,14 +144,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
149
144
  }));
150
145
  }
151
146
  const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
152
- const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
147
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
153
148
  return validator;
154
149
  }
155
150
  getValidatorAddresses() {
156
151
  return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
157
152
  }
158
- getBlockProposalHandler() {
159
- return this.blockProposalHandler;
153
+ getProposalHandler() {
154
+ return this.proposalHandler;
160
155
  }
161
156
  signWithAddress(addr, msg, context) {
162
157
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
@@ -212,7 +207,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
212
207
  // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
213
208
  // and processed separately via the block handler above.
214
209
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
215
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
210
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
216
211
  // Duplicate proposal handler - triggers slashing for equivocation
217
212
  this.p2pClient.registerDuplicateProposalCallback((info)=>{
218
213
  this.handleDuplicateProposal(info);
@@ -262,9 +257,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
262
257
  });
263
258
  // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
264
259
  // In fisherman mode, we always reexecute to validate proposals.
265
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
266
- const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
267
- const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
260
+ const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
261
+ const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
262
+ const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
268
263
  if (!validationResult.isValid) {
269
264
  const reason = validationResult.reason || 'unknown';
270
265
  this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
@@ -314,49 +309,39 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
314
309
  this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
315
310
  return undefined;
316
311
  }
317
- // Reject proposals with invalid signatures
318
- if (!proposer) {
319
- this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
320
- return undefined;
321
- }
322
312
  // Ignore proposals from ourselves (may happen in HA setups)
323
- if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
313
+ if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
324
314
  this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
325
315
  proposer: proposer.toString(),
326
316
  proposalSlotNumber
327
317
  });
328
318
  return undefined;
329
319
  }
330
- // Validate fee asset price modifier is within allowed range
331
- if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
332
- this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`);
333
- return undefined;
334
- }
335
320
  // Check that I have any address in the committee where this checkpoint will land before attesting
336
321
  const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
337
322
  const partOfCommittee = inCommittee.length > 0;
338
323
  const proposalInfo = {
339
324
  proposalSlotNumber,
340
325
  archive: proposal.archive.toString(),
341
- proposer: proposer.toString()
326
+ proposer: proposer?.toString()
342
327
  };
343
328
  this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
344
329
  ...proposalInfo,
345
330
  fishermanMode: this.config.fishermanMode || false
346
331
  });
347
- // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
332
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
333
+ // Uses the cached result from the all-nodes callback if available (avoids double validation).
334
+ let checkpointNumber;
348
335
  if (this.config.skipCheckpointProposalValidation) {
349
336
  this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
337
+ checkpointNumber = CheckpointNumber(0);
350
338
  } else {
351
- const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
339
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
352
340
  if (!validationResult.isValid) {
353
341
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
354
342
  return undefined;
355
343
  }
356
- }
357
- // Upload blobs to filestore if we can (fire and forget)
358
- if (this.blobClient.canUpload()) {
359
- void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
344
+ checkpointNumber = validationResult.checkpointNumber;
360
345
  }
361
346
  // Check that I have any address in current committee before attesting
362
347
  // In fisherman mode, we still create attestations for validation even if not in committee
@@ -403,7 +388,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
403
388
  });
404
389
  return undefined;
405
390
  }
406
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
391
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
407
392
  }
408
393
  /**
409
394
  * Checks if we should attest to a slot based on equivocation prevention rules.
@@ -420,176 +405,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
420
405
  }
421
406
  return true;
422
407
  }
423
- async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
408
+ async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
424
409
  // Equivocation check: must happen right before signing to minimize the race window
425
410
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
426
411
  return undefined;
427
412
  }
428
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
413
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
429
414
  // Track the proposal we attested to (to prevent equivocation)
430
415
  this.lastAttestedProposal = proposal;
431
416
  await this.p2pClient.addOwnCheckpointAttestations(attestations);
432
417
  return attestations;
433
418
  }
434
419
  /**
435
- * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
436
- * @returns Validation result with isValid flag and reason if invalid.
437
- */ async validateCheckpointProposal(proposal, proposalInfo) {
438
- const slot = proposal.slotNumber;
439
- // Timeout block syncing at the start of the next slot
440
- const config = this.checkpointsBuilder.getConfig();
441
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
442
- const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
443
- // Wait for last block to sync by archive
444
- let lastBlockHeader;
445
- try {
446
- lastBlockHeader = await retryUntil(async ()=>{
447
- await this.blockSource.syncImmediate();
448
- return this.blockSource.getBlockHeaderByArchive(proposal.archive);
449
- }, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
450
- } catch (err) {
451
- if (err instanceof TimeoutError) {
452
- this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
453
- return {
454
- isValid: false,
455
- reason: 'last_block_not_found'
456
- };
457
- }
458
- this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
459
- return {
460
- isValid: false,
461
- reason: 'block_fetch_error'
462
- };
463
- }
464
- if (!lastBlockHeader) {
465
- this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
466
- return {
467
- isValid: false,
468
- reason: 'last_block_not_found'
469
- };
470
- }
471
- // Get all full blocks for the slot and checkpoint
472
- const blocks = await this.blockSource.getBlocksForSlot(slot);
473
- if (blocks.length === 0) {
474
- this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
475
- return {
476
- isValid: false,
477
- reason: 'no_blocks_for_slot'
478
- };
479
- }
480
- // Ensure the last block for this slot matches the archive in the checkpoint proposal
481
- if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
482
- this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
483
- return {
484
- isValid: false,
485
- reason: 'last_block_archive_mismatch'
486
- };
487
- }
488
- this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
489
- ...proposalInfo,
490
- blockNumbers: blocks.map((b)=>b.number)
491
- });
492
- // Get checkpoint constants from first block
493
- const firstBlock = blocks[0];
494
- const constants = this.extractCheckpointConstants(firstBlock);
495
- const checkpointNumber = firstBlock.checkpointNumber;
496
- // Get L1-to-L2 messages for this checkpoint
497
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
498
- // Collect the out hashes of all the checkpoints before this one in the same epoch
499
- const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
500
- const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
501
- // Fork world state at the block before the first block
502
- const parentBlockNumber = BlockNumber(firstBlock.number - 1);
503
- const fork = await this.worldState.fork(parentBlockNumber);
504
- try {
505
- // Create checkpoint builder with all existing blocks
506
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
507
- // Complete the checkpoint to get computed values
508
- const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
509
- // Compare checkpoint header with proposal
510
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
511
- this.log.warn(`Checkpoint header mismatch`, {
512
- ...proposalInfo,
513
- computed: computedCheckpoint.header.toInspect(),
514
- proposal: proposal.checkpointHeader.toInspect()
515
- });
516
- return {
517
- isValid: false,
518
- reason: 'checkpoint_header_mismatch'
519
- };
520
- }
521
- // Compare archive root with proposal
522
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
523
- this.log.warn(`Archive root mismatch`, {
524
- ...proposalInfo,
525
- computed: computedCheckpoint.archive.root.toString(),
526
- proposal: proposal.archive.toString()
527
- });
528
- return {
529
- isValid: false,
530
- reason: 'archive_mismatch'
531
- };
532
- }
533
- // Check that the accumulated epoch out hash matches the value in the proposal.
534
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
535
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
536
- const computedEpochOutHash = accumulateCheckpointOutHashes([
537
- ...previousCheckpointOutHashes,
538
- checkpointOutHash
539
- ]);
540
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
541
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
542
- this.log.warn(`Epoch out hash mismatch`, {
543
- proposalEpochOutHash: proposalEpochOutHash.toString(),
544
- computedEpochOutHash: computedEpochOutHash.toString(),
545
- checkpointOutHash: checkpointOutHash.toString(),
546
- previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
547
- ...proposalInfo
548
- });
549
- return {
550
- isValid: false,
551
- reason: 'out_hash_mismatch'
552
- };
553
- }
554
- // Final round of validations on the checkpoint, just in case.
555
- try {
556
- validateCheckpoint(computedCheckpoint, {
557
- rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
558
- maxDABlockGas: this.config.validateMaxDABlockGas,
559
- maxL2BlockGas: this.config.validateMaxL2BlockGas,
560
- maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
561
- maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
562
- });
563
- } catch (err) {
564
- this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
565
- return {
566
- isValid: false,
567
- reason: 'checkpoint_validation_failed'
568
- };
569
- }
570
- this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
571
- return {
572
- isValid: true
573
- };
574
- } finally{
575
- await fork.close();
576
- }
577
- }
578
- /**
579
- * Extract checkpoint global variables from a block.
580
- */ extractCheckpointConstants(block) {
581
- const gv = block.header.globalVariables;
582
- return {
583
- chainId: gv.chainId,
584
- version: gv.version,
585
- slotNumber: gv.slotNumber,
586
- timestamp: gv.timestamp,
587
- coinbase: gv.coinbase,
588
- feeRecipient: gv.feeRecipient,
589
- gasFees: gv.gasFees
590
- };
591
- }
592
- /**
593
420
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
594
421
  */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
595
422
  try {
@@ -674,7 +501,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
674
501
  }
675
502
  ]);
676
503
  }
677
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
504
+ async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
678
505
  // Validate that we're not creating a proposal for an older or equal position
679
506
  if (this.lastProposedBlock) {
680
507
  const lastSlot = this.lastProposedBlock.slotNumber;
@@ -685,14 +512,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
685
512
  }
686
513
  }
687
514
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
688
- const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
515
+ const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
689
516
  ...options,
690
517
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
691
518
  });
692
519
  this.lastProposedBlock = newProposal;
693
520
  return newProposal;
694
521
  }
695
- async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
522
+ async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
696
523
  // Validate that we're not creating a proposal for an older or equal slot
697
524
  if (this.lastProposedCheckpoint) {
698
525
  const lastSlot = this.lastProposedCheckpoint.slotNumber;
@@ -702,23 +529,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
702
529
  }
703
530
  }
704
531
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
705
- const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
532
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
706
533
  this.lastProposedCheckpoint = newProposal;
707
534
  return newProposal;
708
535
  }
709
536
  async broadcastBlockProposal(proposal) {
710
537
  await this.p2pClient.broadcastProposal(proposal);
711
538
  }
712
- async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
713
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
539
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
540
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
714
541
  }
715
- async collectOwnAttestations(proposal) {
542
+ async collectOwnAttestations(proposal, checkpointNumber) {
716
543
  const slot = proposal.slotNumber;
717
544
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
718
545
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
719
546
  inCommittee
720
547
  });
721
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
548
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
722
549
  if (!attestations) {
723
550
  return [];
724
551
  }
@@ -730,7 +557,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
730
557
  });
731
558
  return attestations;
732
559
  }
733
- async collectAttestations(proposal, required, deadline) {
560
+ async collectAttestations(proposal, required, deadline, checkpointNumber) {
734
561
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
735
562
  const slot = proposal.slotNumber;
736
563
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
@@ -738,7 +565,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
738
565
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
739
566
  throw new AttestationTimeoutError(0, required, slot);
740
567
  }
741
- await this.collectOwnAttestations(proposal);
568
+ await this.collectOwnAttestations(proposal, checkpointNumber);
742
569
  const proposalId = proposal.archive.toString();
743
570
  const myAddresses = this.getValidatorAddresses();
744
571
  let attestations = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.7035c9bd6",
3
+ "version": "0.0.1-commit.71324e566",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,30 +64,30 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/blob-client": "0.0.1-commit.7035c9bd6",
68
- "@aztec/blob-lib": "0.0.1-commit.7035c9bd6",
69
- "@aztec/constants": "0.0.1-commit.7035c9bd6",
70
- "@aztec/epoch-cache": "0.0.1-commit.7035c9bd6",
71
- "@aztec/ethereum": "0.0.1-commit.7035c9bd6",
72
- "@aztec/foundation": "0.0.1-commit.7035c9bd6",
73
- "@aztec/node-keystore": "0.0.1-commit.7035c9bd6",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.7035c9bd6",
75
- "@aztec/p2p": "0.0.1-commit.7035c9bd6",
76
- "@aztec/protocol-contracts": "0.0.1-commit.7035c9bd6",
77
- "@aztec/prover-client": "0.0.1-commit.7035c9bd6",
78
- "@aztec/simulator": "0.0.1-commit.7035c9bd6",
79
- "@aztec/slasher": "0.0.1-commit.7035c9bd6",
80
- "@aztec/stdlib": "0.0.1-commit.7035c9bd6",
81
- "@aztec/telemetry-client": "0.0.1-commit.7035c9bd6",
82
- "@aztec/validator-ha-signer": "0.0.1-commit.7035c9bd6",
67
+ "@aztec/blob-client": "0.0.1-commit.71324e566",
68
+ "@aztec/blob-lib": "0.0.1-commit.71324e566",
69
+ "@aztec/constants": "0.0.1-commit.71324e566",
70
+ "@aztec/epoch-cache": "0.0.1-commit.71324e566",
71
+ "@aztec/ethereum": "0.0.1-commit.71324e566",
72
+ "@aztec/foundation": "0.0.1-commit.71324e566",
73
+ "@aztec/node-keystore": "0.0.1-commit.71324e566",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.71324e566",
75
+ "@aztec/p2p": "0.0.1-commit.71324e566",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.71324e566",
77
+ "@aztec/prover-client": "0.0.1-commit.71324e566",
78
+ "@aztec/simulator": "0.0.1-commit.71324e566",
79
+ "@aztec/slasher": "0.0.1-commit.71324e566",
80
+ "@aztec/stdlib": "0.0.1-commit.71324e566",
81
+ "@aztec/telemetry-client": "0.0.1-commit.71324e566",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.71324e566",
83
83
  "koa": "^2.16.1",
84
84
  "koa-router": "^13.1.1",
85
85
  "tslib": "^2.4.0",
86
86
  "viem": "npm:@aztec/viem@2.38.2"
87
87
  },
88
88
  "devDependencies": {
89
- "@aztec/archiver": "0.0.1-commit.7035c9bd6",
90
- "@aztec/world-state": "0.0.1-commit.7035c9bd6",
89
+ "@aztec/archiver": "0.0.1-commit.71324e566",
90
+ "@aztec/world-state": "0.0.1-commit.71324e566",
91
91
  "@electric-sql/pglite": "^0.3.14",
92
92
  "@jest/globals": "^30.0.0",
93
93
  "@types/jest": "^30.0.0",
package/src/config.ts CHANGED
@@ -49,11 +49,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
49
49
  description: 'Interval between polling for new attestations',
50
50
  ...numberConfigHelper(200),
51
51
  },
52
- validatorReexecute: {
53
- env: 'VALIDATOR_REEXECUTE',
54
- description: 'Re-execute transactions before attesting',
55
- ...booleanConfigHelper(true),
56
- },
57
52
  alwaysReexecuteBlockProposals: {
58
53
  description:
59
54
  'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
@@ -80,22 +75,22 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
80
75
  validateMaxL2BlockGas: {
81
76
  env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
82
77
  description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
83
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
78
+ parseEnv: (val: string) => parseInt(val, 10),
84
79
  },
85
80
  validateMaxDABlockGas: {
86
81
  env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
87
82
  description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
88
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
83
+ parseEnv: (val: string) => parseInt(val, 10),
89
84
  },
90
85
  validateMaxTxsPerBlock: {
91
86
  env: 'VALIDATOR_MAX_TX_PER_BLOCK',
92
87
  description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
93
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
88
+ parseEnv: (val: string) => parseInt(val, 10),
94
89
  },
95
90
  validateMaxTxsPerCheckpoint: {
96
91
  env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
97
92
  description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
98
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
93
+ parseEnv: (val: string) => parseInt(val, 10),
99
94
  },
100
95
  ...localSignerConfigMappings,
101
96
  ...validatorHASignerConfigMappings,
@@ -1,9 +1,4 @@
1
- import {
2
- BlockNumber,
3
- type CheckpointNumber,
4
- IndexWithinCheckpoint,
5
- type SlotNumber,
6
- } from '@aztec/foundation/branded-types';
1
+ import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
7
2
  import { Buffer32 } from '@aztec/foundation/buffer';
8
3
  import { keccak256 } from '@aztec/foundation/crypto/keccak';
9
4
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -11,7 +6,6 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
11
6
  import type { Signature } from '@aztec/foundation/eth-signature';
12
7
  import { createLogger } from '@aztec/foundation/log';
13
8
  import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
14
- import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
15
9
  import {
16
10
  BlockProposal,
17
11
  type BlockProposalOptions,
@@ -52,6 +46,7 @@ export class ValidationService {
52
46
  */
53
47
  public createBlockProposal(
54
48
  blockHeader: BlockHeader,
49
+ checkpointNumber: CheckpointNumber,
55
50
  blockIndexWithinCheckpoint: IndexWithinCheckpoint,
56
51
  inHash: Fr,
57
52
  archive: Fr,
@@ -72,6 +67,7 @@ export class ValidationService {
72
67
 
73
68
  return BlockProposal.createProposalFromSigner(
74
69
  blockHeader,
70
+ checkpointNumber,
75
71
  blockIndexWithinCheckpoint,
76
72
  inHash,
77
73
  archive,
@@ -86,7 +82,7 @@ export class ValidationService {
86
82
  *
87
83
  * @param checkpointHeader - The checkpoint header containing aggregated data
88
84
  * @param archive - The archive of the checkpoint
89
- * @param lastBlockInfo - Info about the last block (header, index, txs) or undefined
85
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
90
86
  * @param proposerAttesterAddress - The address of the proposer
91
87
  * @param options - Checkpoint proposal options
92
88
  *
@@ -95,14 +91,17 @@ export class ValidationService {
95
91
  public createCheckpointProposal(
96
92
  checkpointHeader: CheckpointHeader,
97
93
  archive: Fr,
94
+ checkpointNumber: CheckpointNumber,
98
95
  feeAssetPriceModifier: bigint,
99
- lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
96
+ lastBlockProposal: BlockProposal | undefined,
100
97
  proposerAttesterAddress: EthAddress | undefined,
101
98
  options: CheckpointProposalOptions,
102
99
  ): Promise<CheckpointProposal> {
103
- // For testing: change the archive to trigger state_mismatch validation failure
100
+ // For testing: change the archive to trigger state_mismatch validation failure.
101
+ // If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
102
+ // so P2P validation passes and the slasher can detect the offense.
104
103
  if (options.broadcastInvalidCheckpointProposal) {
105
- archive = Fr.random();
104
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
106
105
  this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
107
106
  }
108
107
 
@@ -112,19 +111,12 @@ export class ValidationService {
112
111
  return this.keyStore.signMessageWithAddress(address, payload, context);
113
112
  };
114
113
 
115
- // Last block to include in the proposal
116
- const lastBlock = lastBlockInfo && {
117
- blockHeader: lastBlockInfo.blockHeader,
118
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
119
- txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
120
- txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
121
- };
122
-
123
114
  return CheckpointProposal.createProposalFromSigner(
124
115
  checkpointHeader,
125
116
  archive,
117
+ checkpointNumber,
126
118
  feeAssetPriceModifier,
127
- lastBlock,
119
+ lastBlockProposal,
128
120
  payloadSigner,
129
121
  );
130
122
  }
@@ -142,6 +134,7 @@ export class ValidationService {
142
134
  async attestToCheckpointProposal(
143
135
  proposal: CheckpointProposalCore,
144
136
  attestors: EthAddress[],
137
+ checkpointNumber: CheckpointNumber,
145
138
  ): Promise<CheckpointAttestation[]> {
146
139
  // Create the attestation payload from the checkpoint proposal
147
140
  const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
@@ -149,14 +142,9 @@ export class ValidationService {
149
142
  keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
150
143
  );
151
144
 
152
- // TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
153
- // CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
154
- // blockNumber is NOT used for the primary key so it's safe to use here.
155
- // See CheckpointHeader TODO and SigningContext types documentation.
156
- const blockNumber = BlockNumber(0);
157
145
  const context: SigningContext = {
158
146
  slot: proposal.slotNumber,
159
- blockNumber,
147
+ checkpointNumber,
160
148
  dutyType: DutyType.ATTESTATION,
161
149
  };
162
150
 
@@ -195,7 +183,6 @@ export class ValidationService {
195
183
  * @param attestationsAndSigners - The attestations and signers to sign
196
184
  * @param proposer - The proposer address to sign with
197
185
  * @param slot - The slot number for HA signing context
198
- * @param blockNumber - The block or checkpoint number for HA signing context
199
186
  * @returns signature
200
187
  * @throws DutyAlreadySignedError if already signed by another HA node
201
188
  * @throws SlashingProtectionError if attempting to sign different data for same slot
@@ -204,11 +191,11 @@ export class ValidationService {
204
191
  attestationsAndSigners: CommitteeAttestationsAndSigners,
205
192
  proposer: EthAddress,
206
193
  slot: SlotNumber,
207
- blockNumber: BlockNumber | CheckpointNumber,
194
+ checkpointNumber: CheckpointNumber,
208
195
  ): Promise<Signature> {
209
196
  const context: SigningContext = {
210
197
  slot,
211
- blockNumber,
198
+ checkpointNumber,
212
199
  dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
213
200
  };
214
201