@aztec/validator-client 0.0.1-commit.1bb068fb5 → 0.0.1-commit.1dcfe2301

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 (52) hide show
  1. package/README.md +41 -2
  2. package/dest/checkpoint_builder.d.ts +19 -6
  3. package/dest/checkpoint_builder.d.ts.map +1 -1
  4. package/dest/checkpoint_builder.js +115 -39
  5. package/dest/config.d.ts +1 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +22 -6
  8. package/dest/duties/validation_service.d.ts +7 -9
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +14 -32
  11. package/dest/factory.d.ts +7 -4
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +6 -5
  14. package/dest/index.d.ts +2 -3
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -2
  17. package/dest/key_store/ha_key_store.js +1 -1
  18. package/dest/metrics.d.ts +14 -2
  19. package/dest/metrics.d.ts.map +1 -1
  20. package/dest/metrics.js +24 -0
  21. package/dest/proposal_handler.d.ts +108 -0
  22. package/dest/proposal_handler.d.ts.map +1 -0
  23. package/dest/proposal_handler.js +974 -0
  24. package/dest/validator.d.ts +23 -20
  25. package/dest/validator.d.ts.map +1 -1
  26. package/dest/validator.js +96 -212
  27. package/package.json +19 -19
  28. package/src/checkpoint_builder.ts +135 -39
  29. package/src/config.ts +22 -6
  30. package/src/duties/validation_service.ts +17 -36
  31. package/src/factory.ts +10 -3
  32. package/src/index.ts +1 -2
  33. package/src/key_store/ha_key_store.ts +1 -1
  34. package/src/metrics.ts +37 -1
  35. package/src/proposal_handler.ts +1042 -0
  36. package/src/validator.ts +128 -239
  37. package/dest/block_proposal_handler.d.ts +0 -63
  38. package/dest/block_proposal_handler.d.ts.map +0 -1
  39. package/dest/block_proposal_handler.js +0 -546
  40. package/dest/tx_validator/index.d.ts +0 -3
  41. package/dest/tx_validator/index.d.ts.map +0 -1
  42. package/dest/tx_validator/index.js +0 -2
  43. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  44. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  45. package/dest/tx_validator/nullifier_cache.js +0 -24
  46. package/dest/tx_validator/tx_validator_factory.d.ts +0 -19
  47. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  48. package/dest/tx_validator/tx_validator_factory.js +0 -54
  49. package/src/block_proposal_handler.ts +0 -556
  50. package/src/tx_validator/index.ts +0 -2
  51. package/src/tx_validator/nullifier_cache.ts +0 -30
  52. package/src/tx_validator/tx_validator_factory.ts +0 -154
package/dest/validator.js CHANGED
@@ -1,26 +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 { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
- import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
9
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
14
10
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
15
11
  import { getTelemetryClient } from '@aztec/telemetry-client';
16
- import { createHASigner } from '@aztec/validator-ha-signer/factory';
12
+ import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
17
13
  import { DutyType } from '@aztec/validator-ha-signer/types';
18
14
  import { EventEmitter } from 'events';
19
- import { BlockProposalHandler } from './block_proposal_handler.js';
20
15
  import { ValidationService } from './duties/validation_service.js';
21
16
  import { HAKeyStore } from './key_store/ha_key_store.js';
22
17
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
23
18
  import { ValidatorMetrics } from './metrics.js';
19
+ import { ProposalHandler } from './proposal_handler.js';
24
20
  // We maintain a set of proposers who have proposed invalid blocks.
25
21
  // Just cap the set to avoid unbounded growth.
26
22
  const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
@@ -35,13 +31,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
35
31
  keyStore;
36
32
  epochCache;
37
33
  p2pClient;
38
- blockProposalHandler;
34
+ proposalHandler;
39
35
  blockSource;
40
36
  checkpointsBuilder;
41
37
  worldState;
42
38
  l1ToL2MessageSource;
43
39
  config;
44
40
  blobClient;
41
+ slashingProtectionSigner;
45
42
  dateProvider;
46
43
  tracer;
47
44
  validationService;
@@ -53,10 +50,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
53
50
  /** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
54
51
  lastEpochForCommitteeUpdateLoop;
55
52
  epochCacheUpdateLoop;
53
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
56
54
  proposersOfInvalidBlocks;
57
55
  /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
58
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
59
- 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.dateProvider = dateProvider, this.hasRegisteredHandlers = false, 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();
60
58
  // Create child logger with fisherman prefix if in fisherman mode
61
59
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
62
60
  this.tracer = telemetry.getTracer('Validator');
@@ -95,6 +93,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
95
93
  this.log.trace(`No committee found for slot`);
96
94
  return;
97
95
  }
96
+ this.metrics.setCurrentEpoch(epoch);
98
97
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
99
98
  const me = this.getValidatorAddresses();
100
99
  const committeeSet = new Set(committee.map((v)=>v.toString()));
@@ -110,30 +109,49 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
110
109
  this.log.error(`Error updating epoch committee`, err);
111
110
  }
112
111
  }
113
- static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
112
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
114
113
  const metrics = new ValidatorMetrics(telemetry);
115
114
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
116
- txsPermitted: !config.disableTransactions
115
+ txsPermitted: !config.disableTransactions,
116
+ maxTxsPerBlock: config.validateMaxTxsPerBlock
117
117
  });
118
- const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
119
- let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
120
- if (config.haSigningEnabled) {
118
+ const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry, undefined);
119
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
120
+ let slashingProtectionSigner;
121
+ if (slashingProtectionDb) {
122
+ // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
123
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
124
+ telemetryClient: telemetry,
125
+ dateProvider
126
+ }));
127
+ } else if (config.haSigningEnabled) {
128
+ // Multi-node HA mode: use PostgreSQL-backed distributed locking.
121
129
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
122
130
  const haConfig = {
123
131
  ...config,
124
132
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
125
133
  };
126
- const { signer } = await createHASigner(haConfig);
127
- validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
128
- }
129
- const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
134
+ ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
135
+ telemetryClient: telemetry,
136
+ dateProvider
137
+ }));
138
+ } else {
139
+ // Single-node mode: use LMDB-backed local signing protection.
140
+ // This prevents double-signing if the node crashes and restarts mid-proposal.
141
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
142
+ telemetryClient: telemetry,
143
+ dateProvider
144
+ }));
145
+ }
146
+ const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
147
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
130
148
  return validator;
131
149
  }
132
150
  getValidatorAddresses() {
133
151
  return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
134
152
  }
135
- getBlockProposalHandler() {
136
- return this.blockProposalHandler;
153
+ getProposalHandler() {
154
+ return this.proposalHandler;
137
155
  }
138
156
  signWithAddress(addr, msg, context) {
139
157
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
@@ -153,6 +171,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
153
171
  ...config
154
172
  };
155
173
  }
174
+ reloadKeystore(newManager) {
175
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
176
+ this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
177
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
178
+ }
156
179
  async start() {
157
180
  if (this.epochCacheUpdateLoop.isRunning()) {
158
181
  this.log.warn(`Validator client already started`);
@@ -184,7 +207,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
184
207
  // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
185
208
  // and processed separately via the block handler above.
186
209
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
187
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
210
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
188
211
  // Duplicate proposal handler - triggers slashing for equivocation
189
212
  this.p2pClient.registerDuplicateProposalCallback((info)=>{
190
213
  this.handleDuplicateProposal(info);
@@ -213,13 +236,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
213
236
  this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
214
237
  return false;
215
238
  }
216
- // Ignore proposals from ourselves (may happen in HA setups)
239
+ // Log self-proposals from HA peers (same validator key on different nodes)
217
240
  if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
218
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
241
+ this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
219
242
  proposer: proposer.toString(),
220
243
  slotNumber
221
244
  });
222
- return false;
223
245
  }
224
246
  // Check if we're in the committee (for metrics purposes)
225
247
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
@@ -235,12 +257,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
235
257
  });
236
258
  // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
237
259
  // In fisherman mode, we always reexecute to validate proposals.
238
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
239
- const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
240
- 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);
241
263
  if (!validationResult.isValid) {
242
- this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
243
264
  const reason = validationResult.reason || 'unknown';
265
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
244
266
  // Classify failure reason: bad proposal vs node issue
245
267
  const badProposalReasons = [
246
268
  'invalid_proposal',
@@ -280,58 +302,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
280
302
  * the lastBlock is extracted and processed separately via the block handler.
281
303
  * @returns Checkpoint attestations if valid, undefined otherwise
282
304
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
283
- const slotNumber = proposal.slotNumber;
305
+ const proposalSlotNumber = proposal.slotNumber;
284
306
  const proposer = proposal.getSender();
285
307
  // If escape hatch is open for this slot's epoch, do not attest.
286
- if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
287
- this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
288
- return undefined;
289
- }
290
- // Reject proposals with invalid signatures
291
- if (!proposer) {
292
- this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
308
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
309
+ this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
293
310
  return undefined;
294
311
  }
295
312
  // Ignore proposals from ourselves (may happen in HA setups)
296
- if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
297
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
313
+ if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
314
+ this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
298
315
  proposer: proposer.toString(),
299
- slotNumber
316
+ proposalSlotNumber
300
317
  });
301
318
  return undefined;
302
319
  }
303
- // Validate fee asset price modifier is within allowed range
304
- if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
305
- this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
306
- return undefined;
307
- }
308
- // Check that I have any address in current committee before attesting
309
- const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
320
+ // Check that I have any address in the committee where this checkpoint will land before attesting
321
+ const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
310
322
  const partOfCommittee = inCommittee.length > 0;
311
323
  const proposalInfo = {
312
- slotNumber,
324
+ proposalSlotNumber,
313
325
  archive: proposal.archive.toString(),
314
- proposer: proposer.toString(),
315
- txCount: proposal.txHashes.length
326
+ proposer: proposer?.toString()
316
327
  };
317
- this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
328
+ this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
318
329
  ...proposalInfo,
319
- txHashes: proposal.txHashes.map((t)=>t.toString()),
320
330
  fishermanMode: this.config.fishermanMode || false
321
331
  });
322
- // 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;
323
335
  if (this.config.skipCheckpointProposalValidation) {
324
- this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
336
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
337
+ checkpointNumber = CheckpointNumber(0);
325
338
  } else {
326
- const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
339
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
327
340
  if (!validationResult.isValid) {
328
341
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
329
342
  return undefined;
330
343
  }
331
- }
332
- // Upload blobs to filestore if we can (fire and forget)
333
- if (this.blobClient.canUpload()) {
334
- void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
344
+ checkpointNumber = validationResult.checkpointNumber;
335
345
  }
336
346
  // Check that I have any address in current committee before attesting
337
347
  // In fisherman mode, we still create attestations for validation even if not in committee
@@ -340,12 +350,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
340
350
  return undefined;
341
351
  }
342
352
  // Provided all of the above checks pass, we can attest to the proposal
343
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
353
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
344
354
  ...proposalInfo,
345
355
  inCommittee: partOfCommittee,
346
356
  fishermanMode: this.config.fishermanMode || false
347
357
  });
348
358
  this.metrics.incSuccessfulAttestations(inCommittee.length);
359
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
360
+ const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
361
+ for (const attester of inCommittee){
362
+ const key = attester.toString();
363
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
364
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
365
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
366
+ this.metrics.incAttestedEpochCount(attester);
367
+ }
368
+ }
349
369
  // Determine which validators should attest
350
370
  let attestors;
351
371
  if (partOfCommittee) {
@@ -362,13 +382,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
362
382
  }
363
383
  if (this.config.fishermanMode) {
364
384
  // bail out early and don't save attestations to the pool in fisherman mode
365
- this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
385
+ this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
366
386
  ...proposalInfo,
367
387
  attestors: attestors.map((a)=>a.toString())
368
388
  });
369
389
  return undefined;
370
390
  }
371
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
391
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
372
392
  }
373
393
  /**
374
394
  * Checks if we should attest to a slot based on equivocation prevention rules.
@@ -385,154 +405,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
385
405
  }
386
406
  return true;
387
407
  }
388
- async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
408
+ async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
389
409
  // Equivocation check: must happen right before signing to minimize the race window
390
410
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
391
411
  return undefined;
392
412
  }
393
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
413
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
394
414
  // Track the proposal we attested to (to prevent equivocation)
395
415
  this.lastAttestedProposal = proposal;
396
416
  await this.p2pClient.addOwnCheckpointAttestations(attestations);
397
417
  return attestations;
398
418
  }
399
419
  /**
400
- * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
401
- * @returns Validation result with isValid flag and reason if invalid.
402
- */ async validateCheckpointProposal(proposal, proposalInfo) {
403
- const slot = proposal.slotNumber;
404
- // Timeout block syncing at the start of the next slot
405
- const config = this.checkpointsBuilder.getConfig();
406
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
407
- const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
408
- // Wait for last block to sync by archive
409
- let lastBlockHeader;
410
- try {
411
- lastBlockHeader = await retryUntil(async ()=>{
412
- await this.blockSource.syncImmediate();
413
- return this.blockSource.getBlockHeaderByArchive(proposal.archive);
414
- }, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
415
- } catch (err) {
416
- if (err instanceof TimeoutError) {
417
- this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
418
- return {
419
- isValid: false,
420
- reason: 'last_block_not_found'
421
- };
422
- }
423
- this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
424
- return {
425
- isValid: false,
426
- reason: 'block_fetch_error'
427
- };
428
- }
429
- if (!lastBlockHeader) {
430
- this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
431
- return {
432
- isValid: false,
433
- reason: 'last_block_not_found'
434
- };
435
- }
436
- // Get all full blocks for the slot and checkpoint
437
- const blocks = await this.blockSource.getBlocksForSlot(slot);
438
- if (blocks.length === 0) {
439
- this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
440
- return {
441
- isValid: false,
442
- reason: 'no_blocks_for_slot'
443
- };
444
- }
445
- this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
446
- ...proposalInfo,
447
- blockNumbers: blocks.map((b)=>b.number)
448
- });
449
- // Get checkpoint constants from first block
450
- const firstBlock = blocks[0];
451
- const constants = this.extractCheckpointConstants(firstBlock);
452
- const checkpointNumber = firstBlock.checkpointNumber;
453
- // Get L1-to-L2 messages for this checkpoint
454
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
455
- // Compute the previous checkpoint out hashes for the epoch.
456
- // TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
457
- // actual checkpoints and the blocks/txs in them.
458
- const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
459
- const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
460
- const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
461
- // Fork world state at the block before the first block
462
- const parentBlockNumber = BlockNumber(firstBlock.number - 1);
463
- const fork = await this.worldState.fork(parentBlockNumber);
464
- try {
465
- // Create checkpoint builder with all existing blocks
466
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
467
- // Complete the checkpoint to get computed values
468
- const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
469
- // Compare checkpoint header with proposal
470
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
471
- this.log.warn(`Checkpoint header mismatch`, {
472
- ...proposalInfo,
473
- computed: computedCheckpoint.header.toInspect(),
474
- proposal: proposal.checkpointHeader.toInspect()
475
- });
476
- return {
477
- isValid: false,
478
- reason: 'checkpoint_header_mismatch'
479
- };
480
- }
481
- // Compare archive root with proposal
482
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
483
- this.log.warn(`Archive root mismatch`, {
484
- ...proposalInfo,
485
- computed: computedCheckpoint.archive.root.toString(),
486
- proposal: proposal.archive.toString()
487
- });
488
- return {
489
- isValid: false,
490
- reason: 'archive_mismatch'
491
- };
492
- }
493
- // Check that the accumulated epoch out hash matches the value in the proposal.
494
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
495
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
496
- const computedEpochOutHash = accumulateCheckpointOutHashes([
497
- ...previousCheckpointOutHashes,
498
- checkpointOutHash
499
- ]);
500
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
501
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
502
- this.log.warn(`Epoch out hash mismatch`, {
503
- proposalEpochOutHash: proposalEpochOutHash.toString(),
504
- computedEpochOutHash: computedEpochOutHash.toString(),
505
- checkpointOutHash: checkpointOutHash.toString(),
506
- previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
507
- ...proposalInfo
508
- });
509
- return {
510
- isValid: false,
511
- reason: 'out_hash_mismatch'
512
- };
513
- }
514
- this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
515
- return {
516
- isValid: true
517
- };
518
- } finally{
519
- await fork.close();
520
- }
521
- }
522
- /**
523
- * Extract checkpoint global variables from a block.
524
- */ extractCheckpointConstants(block) {
525
- const gv = block.header.globalVariables;
526
- return {
527
- chainId: gv.chainId,
528
- version: gv.version,
529
- slotNumber: gv.slotNumber,
530
- coinbase: gv.coinbase,
531
- feeRecipient: gv.feeRecipient,
532
- gasFees: gv.gasFees
533
- };
534
- }
535
- /**
536
420
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
537
421
  */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
538
422
  try {
@@ -547,7 +431,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
547
431
  return;
548
432
  }
549
433
  const blobFields = blocks.flatMap((b)=>b.toBlobFields());
550
- const blobs = getBlobsPerL1Block(blobFields);
434
+ const blobs = await getBlobsPerL1Block(blobFields);
551
435
  await this.blobClient.sendBlobsToFilestore(blobs);
552
436
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
553
437
  ...proposalInfo,
@@ -617,7 +501,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
617
501
  }
618
502
  ]);
619
503
  }
620
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
504
+ async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
621
505
  // Validate that we're not creating a proposal for an older or equal position
622
506
  if (this.lastProposedBlock) {
623
507
  const lastSlot = this.lastProposedBlock.slotNumber;
@@ -628,14 +512,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
628
512
  }
629
513
  }
630
514
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
631
- 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, {
632
516
  ...options,
633
517
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
634
518
  });
635
519
  this.lastProposedBlock = newProposal;
636
520
  return newProposal;
637
521
  }
638
- async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
522
+ async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
639
523
  // Validate that we're not creating a proposal for an older or equal slot
640
524
  if (this.lastProposedCheckpoint) {
641
525
  const lastSlot = this.lastProposedCheckpoint.slotNumber;
@@ -645,23 +529,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
645
529
  }
646
530
  }
647
531
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
648
- 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);
649
533
  this.lastProposedCheckpoint = newProposal;
650
534
  return newProposal;
651
535
  }
652
536
  async broadcastBlockProposal(proposal) {
653
537
  await this.p2pClient.broadcastProposal(proposal);
654
538
  }
655
- async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
656
- 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);
657
541
  }
658
- async collectOwnAttestations(proposal) {
542
+ async collectOwnAttestations(proposal, checkpointNumber) {
659
543
  const slot = proposal.slotNumber;
660
544
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
661
545
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
662
546
  inCommittee
663
547
  });
664
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
548
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
665
549
  if (!attestations) {
666
550
  return [];
667
551
  }
@@ -673,7 +557,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
673
557
  });
674
558
  return attestations;
675
559
  }
676
- async collectAttestations(proposal, required, deadline) {
560
+ async collectAttestations(proposal, required, deadline, checkpointNumber) {
677
561
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
678
562
  const slot = proposal.slotNumber;
679
563
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
@@ -681,7 +565,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
681
565
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
682
566
  throw new AttestationTimeoutError(0, required, slot);
683
567
  }
684
- await this.collectOwnAttestations(proposal);
568
+ await this.collectOwnAttestations(proposal, checkpointNumber);
685
569
  const proposalId = proposal.archive.toString();
686
570
  const myAddresses = this.getValidatorAddresses();
687
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.1bb068fb5",
3
+ "version": "0.0.1-commit.1dcfe2301",
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.1bb068fb5",
68
- "@aztec/blob-lib": "0.0.1-commit.1bb068fb5",
69
- "@aztec/constants": "0.0.1-commit.1bb068fb5",
70
- "@aztec/epoch-cache": "0.0.1-commit.1bb068fb5",
71
- "@aztec/ethereum": "0.0.1-commit.1bb068fb5",
72
- "@aztec/foundation": "0.0.1-commit.1bb068fb5",
73
- "@aztec/node-keystore": "0.0.1-commit.1bb068fb5",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.1bb068fb5",
75
- "@aztec/p2p": "0.0.1-commit.1bb068fb5",
76
- "@aztec/protocol-contracts": "0.0.1-commit.1bb068fb5",
77
- "@aztec/prover-client": "0.0.1-commit.1bb068fb5",
78
- "@aztec/simulator": "0.0.1-commit.1bb068fb5",
79
- "@aztec/slasher": "0.0.1-commit.1bb068fb5",
80
- "@aztec/stdlib": "0.0.1-commit.1bb068fb5",
81
- "@aztec/telemetry-client": "0.0.1-commit.1bb068fb5",
82
- "@aztec/validator-ha-signer": "0.0.1-commit.1bb068fb5",
67
+ "@aztec/blob-client": "0.0.1-commit.1dcfe2301",
68
+ "@aztec/blob-lib": "0.0.1-commit.1dcfe2301",
69
+ "@aztec/constants": "0.0.1-commit.1dcfe2301",
70
+ "@aztec/epoch-cache": "0.0.1-commit.1dcfe2301",
71
+ "@aztec/ethereum": "0.0.1-commit.1dcfe2301",
72
+ "@aztec/foundation": "0.0.1-commit.1dcfe2301",
73
+ "@aztec/node-keystore": "0.0.1-commit.1dcfe2301",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.1dcfe2301",
75
+ "@aztec/p2p": "0.0.1-commit.1dcfe2301",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.1dcfe2301",
77
+ "@aztec/prover-client": "0.0.1-commit.1dcfe2301",
78
+ "@aztec/simulator": "0.0.1-commit.1dcfe2301",
79
+ "@aztec/slasher": "0.0.1-commit.1dcfe2301",
80
+ "@aztec/stdlib": "0.0.1-commit.1dcfe2301",
81
+ "@aztec/telemetry-client": "0.0.1-commit.1dcfe2301",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.1dcfe2301",
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.1bb068fb5",
90
- "@aztec/world-state": "0.0.1-commit.1bb068fb5",
89
+ "@aztec/archiver": "0.0.1-commit.1dcfe2301",
90
+ "@aztec/world-state": "0.0.1-commit.1dcfe2301",
91
91
  "@electric-sql/pglite": "^0.3.14",
92
92
  "@jest/globals": "^30.0.0",
93
93
  "@types/jest": "^30.0.0",