@aztec/validator-client 0.0.1-commit.64b6bbb → 0.0.1-commit.69c59a8b3

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