@aztec/validator-client 0.0.1-commit.0c875d939 → 0.0.1-commit.0ec55a70b

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 +29 -7
  8. package/dest/duties/validation_service.d.ts +11 -12
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +27 -45
  11. package/dest/factory.d.ts +7 -4
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +11 -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 +986 -0
  24. package/dest/validator.d.ts +24 -20
  25. package/dest/validator.d.ts.map +1 -1
  26. package/dest/validator.js +108 -213
  27. package/package.json +19 -19
  28. package/src/checkpoint_builder.ts +135 -39
  29. package/src/config.ts +29 -6
  30. package/src/duties/validation_service.ts +46 -53
  31. package/src/factory.ts +15 -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 +1052 -0
  36. package/src/validator.ts +153 -241
  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,15 +50,16 @@ 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');
63
61
  this.metrics = new ValidatorMetrics(telemetry);
64
- this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
62
+ this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
65
63
  // Refresh epoch cache every second to trigger alert if participation in committee changes
66
64
  this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
67
65
  const myAddresses = this.getValidatorAddresses();
@@ -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,34 +109,64 @@ 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
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
118
+ signatureContext: {
119
+ chainId: config.l1ChainId,
120
+ rollupAddress: config.l1Contracts.rollupAddress
121
+ }
117
122
  });
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) {
123
+ const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry, undefined);
124
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
125
+ let slashingProtectionSigner;
126
+ if (slashingProtectionDb) {
127
+ // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
128
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
129
+ telemetryClient: telemetry,
130
+ dateProvider
131
+ }));
132
+ } else if (config.haSigningEnabled) {
133
+ // Multi-node HA mode: use PostgreSQL-backed distributed locking.
121
134
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
122
135
  const haConfig = {
123
136
  ...config,
124
137
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
125
138
  };
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);
139
+ ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
140
+ telemetryClient: telemetry,
141
+ dateProvider
142
+ }));
143
+ } else {
144
+ // Single-node mode: use LMDB-backed local signing protection.
145
+ // This prevents double-signing if the node crashes and restarts mid-proposal.
146
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
147
+ telemetryClient: telemetry,
148
+ dateProvider
149
+ }));
150
+ }
151
+ const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
152
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
130
153
  return validator;
131
154
  }
132
155
  getValidatorAddresses() {
133
156
  return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
134
157
  }
135
- getBlockProposalHandler() {
136
- return this.blockProposalHandler;
158
+ getProposalHandler() {
159
+ return this.proposalHandler;
137
160
  }
138
161
  signWithAddress(addr, msg, context) {
139
162
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
140
163
  }
164
+ getSignatureContext() {
165
+ return {
166
+ chainId: this.config.l1ChainId,
167
+ rollupAddress: this.config.l1Contracts.rollupAddress
168
+ };
169
+ }
141
170
  getCoinbaseForAttestor(attestor) {
142
171
  return this.keyStore.getCoinbaseAddress(attestor);
143
172
  }
@@ -153,6 +182,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
153
182
  ...config
154
183
  };
155
184
  }
185
+ reloadKeystore(newManager) {
186
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
187
+ this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
188
+ this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
189
+ }
156
190
  async start() {
157
191
  if (this.epochCacheUpdateLoop.isRunning()) {
158
192
  this.log.warn(`Validator client already started`);
@@ -184,7 +218,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
184
218
  // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
185
219
  // and processed separately via the block handler above.
186
220
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
187
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
221
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
188
222
  // Duplicate proposal handler - triggers slashing for equivocation
189
223
  this.p2pClient.registerDuplicateProposalCallback((info)=>{
190
224
  this.handleDuplicateProposal(info);
@@ -213,13 +247,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
213
247
  this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
214
248
  return false;
215
249
  }
216
- // Ignore proposals from ourselves (may happen in HA setups)
250
+ // Log self-proposals from HA peers (same validator key on different nodes)
217
251
  if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
218
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
252
+ this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
219
253
  proposer: proposer.toString(),
220
254
  slotNumber
221
255
  });
222
- return false;
223
256
  }
224
257
  // Check if we're in the committee (for metrics purposes)
225
258
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
@@ -235,12 +268,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
235
268
  });
236
269
  // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
237
270
  // 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);
271
+ const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
272
+ const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
273
+ const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
241
274
  if (!validationResult.isValid) {
242
- this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
243
275
  const reason = validationResult.reason || 'unknown';
276
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
244
277
  // Classify failure reason: bad proposal vs node issue
245
278
  const badProposalReasons = [
246
279
  'invalid_proposal',
@@ -280,58 +313,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
280
313
  * the lastBlock is extracted and processed separately via the block handler.
281
314
  * @returns Checkpoint attestations if valid, undefined otherwise
282
315
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
283
- const slotNumber = proposal.slotNumber;
316
+ const proposalSlotNumber = proposal.slotNumber;
284
317
  const proposer = proposal.getSender();
285
318
  // 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}`);
319
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
320
+ this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
293
321
  return undefined;
294
322
  }
295
323
  // 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}`, {
324
+ if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
325
+ this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
298
326
  proposer: proposer.toString(),
299
- slotNumber
327
+ proposalSlotNumber
300
328
  });
301
329
  return undefined;
302
330
  }
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());
331
+ // Check that I have any address in the committee where this checkpoint will land before attesting
332
+ const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
310
333
  const partOfCommittee = inCommittee.length > 0;
311
334
  const proposalInfo = {
312
- slotNumber,
335
+ proposalSlotNumber,
313
336
  archive: proposal.archive.toString(),
314
- proposer: proposer.toString(),
315
- txCount: proposal.txHashes.length
337
+ proposer: proposer?.toString()
316
338
  };
317
- this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
339
+ this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
318
340
  ...proposalInfo,
319
- txHashes: proposal.txHashes.map((t)=>t.toString()),
320
341
  fishermanMode: this.config.fishermanMode || false
321
342
  });
322
- // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
343
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
344
+ // Uses the cached result from the all-nodes callback if available (avoids double validation).
345
+ let checkpointNumber;
323
346
  if (this.config.skipCheckpointProposalValidation) {
324
- this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
347
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
348
+ checkpointNumber = CheckpointNumber(0);
325
349
  } else {
326
- const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
350
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
327
351
  if (!validationResult.isValid) {
328
352
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
329
353
  return undefined;
330
354
  }
331
- }
332
- // Upload blobs to filestore if we can (fire and forget)
333
- if (this.blobClient.canUpload()) {
334
- void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
355
+ checkpointNumber = validationResult.checkpointNumber;
335
356
  }
336
357
  // Check that I have any address in current committee before attesting
337
358
  // In fisherman mode, we still create attestations for validation even if not in committee
@@ -340,12 +361,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
340
361
  return undefined;
341
362
  }
342
363
  // 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}`, {
364
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
344
365
  ...proposalInfo,
345
366
  inCommittee: partOfCommittee,
346
367
  fishermanMode: this.config.fishermanMode || false
347
368
  });
348
369
  this.metrics.incSuccessfulAttestations(inCommittee.length);
370
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
371
+ const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
372
+ for (const attester of inCommittee){
373
+ const key = attester.toString();
374
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
375
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
376
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
377
+ this.metrics.incAttestedEpochCount(attester);
378
+ }
379
+ }
349
380
  // Determine which validators should attest
350
381
  let attestors;
351
382
  if (partOfCommittee) {
@@ -362,13 +393,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
362
393
  }
363
394
  if (this.config.fishermanMode) {
364
395
  // bail out early and don't save attestations to the pool in fisherman mode
365
- this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
396
+ this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
366
397
  ...proposalInfo,
367
398
  attestors: attestors.map((a)=>a.toString())
368
399
  });
369
400
  return undefined;
370
401
  }
371
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
402
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
372
403
  }
373
404
  /**
374
405
  * Checks if we should attest to a slot based on equivocation prevention rules.
@@ -385,154 +416,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
385
416
  }
386
417
  return true;
387
418
  }
388
- async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
419
+ async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
389
420
  // Equivocation check: must happen right before signing to minimize the race window
390
421
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
391
422
  return undefined;
392
423
  }
393
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
424
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
394
425
  // Track the proposal we attested to (to prevent equivocation)
395
426
  this.lastAttestedProposal = proposal;
396
427
  await this.p2pClient.addOwnCheckpointAttestations(attestations);
397
428
  return attestations;
398
429
  }
399
430
  /**
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
431
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
537
432
  */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
538
433
  try {
@@ -547,7 +442,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
547
442
  return;
548
443
  }
549
444
  const blobFields = blocks.flatMap((b)=>b.toBlobFields());
550
- const blobs = getBlobsPerL1Block(blobFields);
445
+ const blobs = await getBlobsPerL1Block(blobFields);
551
446
  await this.blobClient.sendBlobsToFilestore(blobs);
552
447
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
553
448
  ...proposalInfo,
@@ -617,7 +512,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
617
512
  }
618
513
  ]);
619
514
  }
620
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
515
+ async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
621
516
  // Validate that we're not creating a proposal for an older or equal position
622
517
  if (this.lastProposedBlock) {
623
518
  const lastSlot = this.lastProposedBlock.slotNumber;
@@ -628,14 +523,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
628
523
  }
629
524
  }
630
525
  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, {
526
+ const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
632
527
  ...options,
633
528
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
634
529
  });
635
530
  this.lastProposedBlock = newProposal;
636
531
  return newProposal;
637
532
  }
638
- async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
533
+ async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
639
534
  // Validate that we're not creating a proposal for an older or equal slot
640
535
  if (this.lastProposedCheckpoint) {
641
536
  const lastSlot = this.lastProposedCheckpoint.slotNumber;
@@ -645,23 +540,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
645
540
  }
646
541
  }
647
542
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
648
- const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
543
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
649
544
  this.lastProposedCheckpoint = newProposal;
650
545
  return newProposal;
651
546
  }
652
547
  async broadcastBlockProposal(proposal) {
653
548
  await this.p2pClient.broadcastProposal(proposal);
654
549
  }
655
- async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
656
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
550
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
551
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
657
552
  }
658
- async collectOwnAttestations(proposal) {
553
+ async collectOwnAttestations(proposal, checkpointNumber) {
659
554
  const slot = proposal.slotNumber;
660
555
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
661
556
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
662
557
  inCommittee
663
558
  });
664
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
559
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
665
560
  if (!attestations) {
666
561
  return [];
667
562
  }
@@ -673,7 +568,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
673
568
  });
674
569
  return attestations;
675
570
  }
676
- async collectAttestations(proposal, required, deadline) {
571
+ async collectAttestations(proposal, required, deadline, checkpointNumber) {
677
572
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
678
573
  const slot = proposal.slotNumber;
679
574
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
@@ -681,7 +576,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
681
576
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
682
577
  throw new AttestationTimeoutError(0, required, slot);
683
578
  }
684
- await this.collectOwnAttestations(proposal);
579
+ await this.collectOwnAttestations(proposal, checkpointNumber);
685
580
  const proposalId = proposal.archive.toString();
686
581
  const myAddresses = this.getValidatorAddresses();
687
582
  let attestations = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.0c875d939",
3
+ "version": "0.0.1-commit.0ec55a70b",
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.0c875d939",
68
- "@aztec/blob-lib": "0.0.1-commit.0c875d939",
69
- "@aztec/constants": "0.0.1-commit.0c875d939",
70
- "@aztec/epoch-cache": "0.0.1-commit.0c875d939",
71
- "@aztec/ethereum": "0.0.1-commit.0c875d939",
72
- "@aztec/foundation": "0.0.1-commit.0c875d939",
73
- "@aztec/node-keystore": "0.0.1-commit.0c875d939",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.0c875d939",
75
- "@aztec/p2p": "0.0.1-commit.0c875d939",
76
- "@aztec/protocol-contracts": "0.0.1-commit.0c875d939",
77
- "@aztec/prover-client": "0.0.1-commit.0c875d939",
78
- "@aztec/simulator": "0.0.1-commit.0c875d939",
79
- "@aztec/slasher": "0.0.1-commit.0c875d939",
80
- "@aztec/stdlib": "0.0.1-commit.0c875d939",
81
- "@aztec/telemetry-client": "0.0.1-commit.0c875d939",
82
- "@aztec/validator-ha-signer": "0.0.1-commit.0c875d939",
67
+ "@aztec/blob-client": "0.0.1-commit.0ec55a70b",
68
+ "@aztec/blob-lib": "0.0.1-commit.0ec55a70b",
69
+ "@aztec/constants": "0.0.1-commit.0ec55a70b",
70
+ "@aztec/epoch-cache": "0.0.1-commit.0ec55a70b",
71
+ "@aztec/ethereum": "0.0.1-commit.0ec55a70b",
72
+ "@aztec/foundation": "0.0.1-commit.0ec55a70b",
73
+ "@aztec/node-keystore": "0.0.1-commit.0ec55a70b",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.0ec55a70b",
75
+ "@aztec/p2p": "0.0.1-commit.0ec55a70b",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.0ec55a70b",
77
+ "@aztec/prover-client": "0.0.1-commit.0ec55a70b",
78
+ "@aztec/simulator": "0.0.1-commit.0ec55a70b",
79
+ "@aztec/slasher": "0.0.1-commit.0ec55a70b",
80
+ "@aztec/stdlib": "0.0.1-commit.0ec55a70b",
81
+ "@aztec/telemetry-client": "0.0.1-commit.0ec55a70b",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.0ec55a70b",
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.0c875d939",
90
- "@aztec/world-state": "0.0.1-commit.0c875d939",
89
+ "@aztec/archiver": "0.0.1-commit.0ec55a70b",
90
+ "@aztec/world-state": "0.0.1-commit.0ec55a70b",
91
91
  "@electric-sql/pglite": "^0.3.14",
92
92
  "@jest/globals": "^30.0.0",
93
93
  "@types/jest": "^30.0.0",