@aztec/validator-client 0.0.1-commit.b655e406 → 0.0.1-commit.c31f2472

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 (69) hide show
  1. package/README.md +282 -0
  2. package/dest/block_proposal_handler.d.ts +24 -13
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +349 -89
  5. package/dest/checkpoint_builder.d.ts +70 -0
  6. package/dest/checkpoint_builder.d.ts.map +1 -0
  7. package/dest/checkpoint_builder.js +167 -0
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +16 -7
  11. package/dest/duties/validation_service.d.ts +42 -13
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +113 -31
  14. package/dest/factory.d.ts +13 -8
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +2 -2
  17. package/dest/index.d.ts +3 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +2 -0
  20. package/dest/key_store/ha_key_store.d.ts +99 -0
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  22. package/dest/key_store/ha_key_store.js +208 -0
  23. package/dest/key_store/index.d.ts +2 -1
  24. package/dest/key_store/index.d.ts.map +1 -1
  25. package/dest/key_store/index.js +1 -0
  26. package/dest/key_store/interface.d.ts +36 -6
  27. package/dest/key_store/interface.d.ts.map +1 -1
  28. package/dest/key_store/local_key_store.d.ts +10 -5
  29. package/dest/key_store/local_key_store.d.ts.map +1 -1
  30. package/dest/key_store/local_key_store.js +9 -5
  31. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  32. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  33. package/dest/key_store/node_keystore_adapter.js +18 -4
  34. package/dest/key_store/web3signer_key_store.d.ts +10 -11
  35. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  36. package/dest/key_store/web3signer_key_store.js +9 -5
  37. package/dest/metrics.d.ts +4 -3
  38. package/dest/metrics.d.ts.map +1 -1
  39. package/dest/metrics.js +34 -30
  40. package/dest/tx_validator/index.d.ts +3 -0
  41. package/dest/tx_validator/index.d.ts.map +1 -0
  42. package/dest/tx_validator/index.js +2 -0
  43. package/dest/tx_validator/nullifier_cache.d.ts +14 -0
  44. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  45. package/dest/tx_validator/nullifier_cache.js +24 -0
  46. package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
  47. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
  48. package/dest/tx_validator/tx_validator_factory.js +54 -0
  49. package/dest/validator.d.ts +48 -20
  50. package/dest/validator.d.ts.map +1 -1
  51. package/dest/validator.js +359 -63
  52. package/package.json +24 -14
  53. package/src/block_proposal_handler.ts +278 -66
  54. package/src/checkpoint_builder.ts +310 -0
  55. package/src/config.ts +16 -6
  56. package/src/duties/validation_service.ts +157 -38
  57. package/src/factory.ts +17 -8
  58. package/src/index.ts +2 -0
  59. package/src/key_store/ha_key_store.ts +269 -0
  60. package/src/key_store/index.ts +1 -0
  61. package/src/key_store/interface.ts +44 -5
  62. package/src/key_store/local_key_store.ts +14 -5
  63. package/src/key_store/node_keystore_adapter.ts +28 -5
  64. package/src/key_store/web3signer_key_store.ts +18 -5
  65. package/src/metrics.ts +45 -33
  66. package/src/tx_validator/index.ts +2 -0
  67. package/src/tx_validator/nullifier_cache.ts +30 -0
  68. package/src/tx_validator/tx_validator_factory.ts +154 -0
  69. package/src/validator.ts +483 -95
package/dest/validator.js CHANGED
@@ -1,14 +1,23 @@
1
+ import { getBlobsPerL1Block } from '@aztec/blob-lib';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { TimeoutError } from '@aztec/foundation/error';
1
4
  import { createLogger } from '@aztec/foundation/log';
5
+ import { retryUntil } from '@aztec/foundation/retry';
2
6
  import { RunningPromise } from '@aztec/foundation/running-promise';
3
7
  import { sleep } from '@aztec/foundation/sleep';
4
8
  import { DateProvider } from '@aztec/foundation/timer';
5
9
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
6
10
  import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
11
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
12
+ import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
7
13
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
8
14
  import { getTelemetryClient } from '@aztec/telemetry-client';
15
+ import { createHASigner } from '@aztec/validator-ha-signer/factory';
16
+ import { DutyType } from '@aztec/validator-ha-signer/types';
9
17
  import { EventEmitter } from 'events';
10
18
  import { BlockProposalHandler } from './block_proposal_handler.js';
11
19
  import { ValidationService } from './duties/validation_service.js';
20
+ import { HAKeyStore } from './key_store/ha_key_store.js';
12
21
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
13
22
  import { ValidatorMetrics } from './metrics.js';
14
23
  // We maintain a set of proposers who have proposed invalid blocks.
@@ -26,12 +35,17 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
26
35
  epochCache;
27
36
  p2pClient;
28
37
  blockProposalHandler;
38
+ blockSource;
39
+ checkpointsBuilder;
40
+ worldState;
41
+ l1ToL2MessageSource;
29
42
  config;
43
+ blobClient;
30
44
  dateProvider;
31
- log;
32
45
  tracer;
33
46
  validationService;
34
47
  metrics;
48
+ log;
35
49
  // Whether it has already registered handlers on the p2p client
36
50
  hasRegisteredHandlers;
37
51
  // Used to check if we are sending the same proposal twice
@@ -39,13 +53,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
39
53
  lastEpochForCommitteeUpdateLoop;
40
54
  epochCacheUpdateLoop;
41
55
  proposersOfInvalidBlocks;
42
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, config, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
43
- super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.config = config, this.dateProvider = dateProvider, this.log = log, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
56
+ constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
57
+ 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();
58
+ // Create child logger with fisherman prefix if in fisherman mode
59
+ this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
44
60
  this.tracer = telemetry.getTracer('Validator');
45
61
  this.metrics = new ValidatorMetrics(telemetry);
46
- this.validationService = new ValidationService(keyStore, log.createChild('validation-service'));
62
+ this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
47
63
  // Refresh epoch cache every second to trigger alert if participation in committee changes
48
- this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), log, 1000);
64
+ this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
49
65
  const myAddresses = this.getValidatorAddresses();
50
66
  this.log.verbose(`Initialized validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
51
67
  }
@@ -92,13 +108,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
92
108
  this.log.error(`Error updating epoch committee`, err);
93
109
  }
94
110
  }
95
- static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
111
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
96
112
  const metrics = new ValidatorMetrics(telemetry);
97
113
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
98
114
  txsPermitted: !config.disableTransactions
99
115
  });
100
- const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
101
- const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
116
+ const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
117
+ let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
118
+ if (config.haSigningEnabled) {
119
+ // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
120
+ const haConfig = {
121
+ ...config,
122
+ maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
123
+ };
124
+ const { signer } = await createHASigner(haConfig);
125
+ validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
126
+ }
127
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
102
128
  return validator;
103
129
  }
104
130
  getValidatorAddresses() {
@@ -107,12 +133,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
107
133
  getBlockProposalHandler() {
108
134
  return this.blockProposalHandler;
109
135
  }
110
- // Proxy method for backwards compatibility with tests
111
- reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
112
- return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
113
- }
114
- signWithAddress(addr, msg) {
115
- return this.keyStore.signTypedDataWithAddress(addr, msg);
136
+ signWithAddress(addr, msg, context) {
137
+ return this.keyStore.signTypedDataWithAddress(addr, msg, context);
116
138
  }
117
139
  getCoinbaseForAttestor(attestor) {
118
140
  return this.keyStore.getCoinbaseAddress(attestor);
@@ -134,57 +156,72 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
134
156
  this.log.warn(`Validator client already started`);
135
157
  return;
136
158
  }
159
+ await this.keyStore.start();
137
160
  await this.registerHandlers();
138
161
  const myAddresses = this.getValidatorAddresses();
139
162
  const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
163
+ this.log.info(`Started validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
140
164
  if (inCommittee.length > 0) {
141
- this.log.info(`Started validator with addresses in current validator committee: ${inCommittee.map((a)=>a.toString()).join(', ')}`);
142
- } else {
143
- this.log.info(`Started validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
165
+ this.log.info(`Addresses in current validator committee: ${inCommittee.map((a)=>a.toString()).join(', ')}`);
144
166
  }
145
167
  this.epochCacheUpdateLoop.start();
146
168
  return Promise.resolve();
147
169
  }
148
170
  async stop() {
149
171
  await this.epochCacheUpdateLoop.stop();
172
+ await this.keyStore.stop();
150
173
  }
151
174
  /** Register handlers on the p2p client */ async registerHandlers() {
152
175
  if (!this.hasRegisteredHandlers) {
153
176
  this.hasRegisteredHandlers = true;
154
177
  this.log.debug(`Registering validator handlers for p2p client`);
155
- const handler = (block, proposalSender)=>this.attestToProposal(block, proposalSender);
156
- this.p2pClient.registerBlockProposalHandler(handler);
178
+ // Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
179
+ const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
180
+ this.p2pClient.registerBlockProposalHandler(blockHandler);
181
+ // Checkpoint proposal handler - validates and creates attestations
182
+ // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
183
+ // and processed separately via the block handler above.
184
+ const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
185
+ this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
157
186
  const myAddresses = this.getValidatorAddresses();
158
187
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
159
188
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
160
189
  }
161
190
  }
162
- async attestToProposal(proposal, proposalSender) {
163
- const slotNumber = proposal.slotNumber.toBigInt();
191
+ /**
192
+ * Validate a block proposal from a peer.
193
+ * Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
194
+ * @returns true if the proposal is valid, false otherwise
195
+ */ async validateBlockProposal(proposal, proposalSender) {
196
+ const slotNumber = proposal.slotNumber;
197
+ // Note: During escape hatch, we still want to "validate" proposals for observability,
198
+ // but we intentionally reject them and disable slashing invalid block and attestation flow.
199
+ const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
164
200
  const proposer = proposal.getSender();
165
201
  // Reject proposals with invalid signatures
166
202
  if (!proposer) {
167
- this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
168
- return undefined;
203
+ this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
204
+ return false;
169
205
  }
170
- // Check that I have any address in current committee before attesting
206
+ // Check if we're in the committee (for metrics purposes)
171
207
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
172
208
  const partOfCommittee = inCommittee.length > 0;
173
209
  const proposalInfo = {
174
210
  ...proposal.toBlockInfo(),
175
211
  proposer: proposer.toString()
176
212
  };
177
- this.log.info(`Received proposal for slot ${slotNumber}`, {
213
+ this.log.info(`Received block proposal for slot ${slotNumber}`, {
178
214
  ...proposalInfo,
179
- txHashes: proposal.txHashes.map((t)=>t.toString())
215
+ txHashes: proposal.txHashes.map((t)=>t.toString()),
216
+ fishermanMode: this.config.fishermanMode || false
180
217
  });
181
- // Reexecute txs if we are part of the committee so we can attest, or if slashing is enabled so we can slash
182
- // invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
183
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals } = this.config;
184
- const shouldReexecute = slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
185
- const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
218
+ // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
219
+ // In fisherman mode, we always reexecute to validate proposals.
220
+ const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
221
+ const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
222
+ const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
186
223
  if (!validationResult.isValid) {
187
- this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
224
+ this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
188
225
  const reason = validationResult.reason || 'unknown';
189
226
  // Classify failure reason: bad proposal vs node issue
190
227
  const badProposalReasons = [
@@ -197,26 +234,273 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
197
234
  if (badProposalReasons.includes(reason)) {
198
235
  this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
199
236
  } else {
200
- // Node issues so we can't attest
237
+ // Node issues so we can't validate
201
238
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
202
239
  }
203
240
  // Slash invalid block proposals (can happen even when not in committee)
204
- if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
241
+ if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
205
242
  this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
206
243
  this.slashInvalidBlock(proposal);
207
244
  }
245
+ return false;
246
+ }
247
+ this.log.info(`Validated block proposal for slot ${slotNumber}`, {
248
+ ...proposalInfo,
249
+ inCommittee: partOfCommittee,
250
+ fishermanMode: this.config.fishermanMode || false,
251
+ escapeHatchOpen
252
+ });
253
+ if (escapeHatchOpen) {
254
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
255
+ return false;
256
+ }
257
+ return true;
258
+ }
259
+ /**
260
+ * Validate and attest to a checkpoint proposal from a peer.
261
+ * The proposal is received as CheckpointProposalCore (without lastBlock) since
262
+ * the lastBlock is extracted and processed separately via the block handler.
263
+ * @returns Checkpoint attestations if valid, undefined otherwise
264
+ */ async attestToCheckpointProposal(proposal, _proposalSender) {
265
+ const slotNumber = proposal.slotNumber;
266
+ const proposer = proposal.getSender();
267
+ // If escape hatch is open for this slot's epoch, do not attest.
268
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
269
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
208
270
  return undefined;
209
271
  }
272
+ // Reject proposals with invalid signatures
273
+ if (!proposer) {
274
+ this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
275
+ return undefined;
276
+ }
277
+ // Check that I have any address in current committee before attesting
278
+ const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
279
+ const partOfCommittee = inCommittee.length > 0;
280
+ const proposalInfo = {
281
+ slotNumber,
282
+ archive: proposal.archive.toString(),
283
+ proposer: proposer.toString(),
284
+ txCount: proposal.txHashes.length
285
+ };
286
+ this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
287
+ ...proposalInfo,
288
+ txHashes: proposal.txHashes.map((t)=>t.toString()),
289
+ fishermanMode: this.config.fishermanMode || false
290
+ });
291
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
292
+ if (this.config.skipCheckpointProposalValidation) {
293
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
294
+ } else {
295
+ const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
296
+ if (!validationResult.isValid) {
297
+ this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
298
+ return undefined;
299
+ }
300
+ }
301
+ // Upload blobs to filestore if we can (fire and forget)
302
+ if (this.blobClient.canUpload()) {
303
+ void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
304
+ }
210
305
  // Check that I have any address in current committee before attesting
211
- if (!partOfCommittee) {
306
+ // In fisherman mode, we still create attestations for validation even if not in committee
307
+ if (!partOfCommittee && !this.config.fishermanMode) {
212
308
  this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
213
309
  return undefined;
214
310
  }
215
311
  // Provided all of the above checks pass, we can attest to the proposal
216
- this.log.info(`Attesting to proposal for slot ${slotNumber}`, proposalInfo);
312
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
313
+ ...proposalInfo,
314
+ inCommittee: partOfCommittee,
315
+ fishermanMode: this.config.fishermanMode || false
316
+ });
217
317
  this.metrics.incSuccessfulAttestations(inCommittee.length);
218
- // If the above function does not throw an error, then we can attest to the proposal
219
- return this.createBlockAttestationsFromProposal(proposal, inCommittee);
318
+ // Determine which validators should attest
319
+ let attestors;
320
+ if (partOfCommittee) {
321
+ attestors = inCommittee;
322
+ } else if (this.config.fishermanMode) {
323
+ // In fisherman mode, create attestations for validation purposes even if not in committee. These won't be broadcast.
324
+ attestors = this.getValidatorAddresses();
325
+ } else {
326
+ attestors = [];
327
+ }
328
+ // Only create attestations if we have attestors
329
+ if (attestors.length === 0) {
330
+ return undefined;
331
+ }
332
+ if (this.config.fishermanMode) {
333
+ // bail out early and don't save attestations to the pool in fisherman mode
334
+ this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
335
+ ...proposalInfo,
336
+ attestors: attestors.map((a)=>a.toString())
337
+ });
338
+ return undefined;
339
+ }
340
+ return this.createCheckpointAttestationsFromProposal(proposal, attestors);
341
+ }
342
+ async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
343
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
344
+ await this.p2pClient.addCheckpointAttestations(attestations);
345
+ return attestations;
346
+ }
347
+ /**
348
+ * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
349
+ * @returns Validation result with isValid flag and reason if invalid.
350
+ */ async validateCheckpointProposal(proposal, proposalInfo) {
351
+ const slot = proposal.slotNumber;
352
+ const timeoutSeconds = 10; // TODO(palla/mbps): This should map to the timetable settings
353
+ // Wait for last block to sync by archive
354
+ let lastBlockHeader;
355
+ try {
356
+ lastBlockHeader = await retryUntil(async ()=>{
357
+ await this.blockSource.syncImmediate();
358
+ return this.blockSource.getBlockHeaderByArchive(proposal.archive);
359
+ }, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
360
+ } catch (err) {
361
+ if (err instanceof TimeoutError) {
362
+ this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
363
+ return {
364
+ isValid: false,
365
+ reason: 'last_block_not_found'
366
+ };
367
+ }
368
+ this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
369
+ return {
370
+ isValid: false,
371
+ reason: 'block_fetch_error'
372
+ };
373
+ }
374
+ if (!lastBlockHeader) {
375
+ this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
376
+ return {
377
+ isValid: false,
378
+ reason: 'last_block_not_found'
379
+ };
380
+ }
381
+ // Get all full blocks for the slot and checkpoint
382
+ const blocks = await this.blockSource.getBlocksForSlot(slot);
383
+ if (blocks.length === 0) {
384
+ this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
385
+ return {
386
+ isValid: false,
387
+ reason: 'no_blocks_for_slot'
388
+ };
389
+ }
390
+ this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
391
+ ...proposalInfo,
392
+ blockNumbers: blocks.map((b)=>b.number)
393
+ });
394
+ // Get checkpoint constants from first block
395
+ const firstBlock = blocks[0];
396
+ const constants = this.extractCheckpointConstants(firstBlock);
397
+ const checkpointNumber = firstBlock.checkpointNumber;
398
+ // Get L1-to-L2 messages for this checkpoint
399
+ const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
400
+ // Compute the previous checkpoint out hashes for the epoch.
401
+ // TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
402
+ // actual checkpoints and the blocks/txs in them.
403
+ const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
404
+ const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
405
+ const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
406
+ // Fork world state at the block before the first block
407
+ const parentBlockNumber = BlockNumber(firstBlock.number - 1);
408
+ const fork = await this.worldState.fork(parentBlockNumber);
409
+ try {
410
+ // Create checkpoint builder with all existing blocks
411
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
412
+ // Complete the checkpoint to get computed values
413
+ const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
414
+ // Compare checkpoint header with proposal
415
+ if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
416
+ this.log.warn(`Checkpoint header mismatch`, {
417
+ ...proposalInfo,
418
+ computed: computedCheckpoint.header.toInspect(),
419
+ proposal: proposal.checkpointHeader.toInspect()
420
+ });
421
+ return {
422
+ isValid: false,
423
+ reason: 'checkpoint_header_mismatch'
424
+ };
425
+ }
426
+ // Compare archive root with proposal
427
+ if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
428
+ this.log.warn(`Archive root mismatch`, {
429
+ ...proposalInfo,
430
+ computed: computedCheckpoint.archive.root.toString(),
431
+ proposal: proposal.archive.toString()
432
+ });
433
+ return {
434
+ isValid: false,
435
+ reason: 'archive_mismatch'
436
+ };
437
+ }
438
+ // Check that the accumulated epoch out hash matches the value in the proposal.
439
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
440
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
441
+ const computedEpochOutHash = accumulateCheckpointOutHashes([
442
+ ...previousCheckpointOutHashes,
443
+ checkpointOutHash
444
+ ]);
445
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
446
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
447
+ this.log.warn(`Epoch out hash mismatch`, {
448
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
449
+ computedEpochOutHash: computedEpochOutHash.toString(),
450
+ checkpointOutHash: checkpointOutHash.toString(),
451
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
452
+ ...proposalInfo
453
+ });
454
+ return {
455
+ isValid: false,
456
+ reason: 'out_hash_mismatch'
457
+ };
458
+ }
459
+ this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
460
+ return {
461
+ isValid: true
462
+ };
463
+ } finally{
464
+ await fork.close();
465
+ }
466
+ }
467
+ /**
468
+ * Extract checkpoint global variables from a block.
469
+ */ extractCheckpointConstants(block) {
470
+ const gv = block.header.globalVariables;
471
+ return {
472
+ chainId: gv.chainId,
473
+ version: gv.version,
474
+ slotNumber: gv.slotNumber,
475
+ coinbase: gv.coinbase,
476
+ feeRecipient: gv.feeRecipient,
477
+ gasFees: gv.gasFees
478
+ };
479
+ }
480
+ /**
481
+ * Uploads blobs for a checkpoint to the filestore (fire and forget).
482
+ */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
483
+ try {
484
+ const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
485
+ if (!lastBlockHeader) {
486
+ this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
487
+ return;
488
+ }
489
+ const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
490
+ if (blocks.length === 0) {
491
+ this.log.warn(`No blocks found for blob upload`, proposalInfo);
492
+ return;
493
+ }
494
+ const blobFields = blocks.flatMap((b)=>b.toBlobFields());
495
+ const blobs = getBlobsPerL1Block(blobFields);
496
+ await this.blobClient.sendBlobsToFilestore(blobs);
497
+ this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
498
+ ...proposalInfo,
499
+ numBlobs: blobs.length
500
+ });
501
+ } catch (err) {
502
+ this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
503
+ }
220
504
  }
221
505
  slashInvalidBlock(proposal) {
222
506
  const proposer = proposal.getSender();
@@ -236,39 +520,52 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
236
520
  validator: proposer,
237
521
  amount: this.config.slashBroadcastedInvalidBlockPenalty,
238
522
  offenseType: OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL,
239
- epochOrSlot: proposal.slotNumber.toBigInt()
523
+ epochOrSlot: BigInt(proposal.slotNumber)
240
524
  }
241
525
  ]);
242
526
  }
243
- async createBlockProposal(blockNumber, header, archive, stateReference, txs, proposerAddress, options) {
244
- if (this.previousProposal?.slotNumber.equals(header.slotNumber)) {
245
- this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
246
- return Promise.resolve(undefined);
247
- }
248
- const newProposal = await this.validationService.createBlockProposal(header, archive, stateReference, txs, proposerAddress, {
527
+ async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
528
+ // TODO(palla/mbps): Prevent double proposals properly
529
+ // if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
530
+ // this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
531
+ // return Promise.resolve(undefined);
532
+ // }
533
+ this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
534
+ const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
249
535
  ...options,
250
536
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
251
537
  });
252
538
  this.previousProposal = newProposal;
253
539
  return newProposal;
254
540
  }
541
+ async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options = {}) {
542
+ this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
543
+ return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
544
+ }
255
545
  async broadcastBlockProposal(proposal) {
256
546
  await this.p2pClient.broadcastProposal(proposal);
257
547
  }
258
- async signAttestationsAndSigners(attestationsAndSigners, proposer) {
259
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
548
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
549
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
260
550
  }
261
551
  async collectOwnAttestations(proposal) {
262
- const slot = proposal.payload.header.slotNumber.toBigInt();
552
+ const slot = proposal.slotNumber;
263
553
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
264
554
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
265
555
  inCommittee
266
556
  });
267
- return this.createBlockAttestationsFromProposal(proposal, inCommittee);
557
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
558
+ // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
559
+ // other nodes can see that our validators did attest to this block proposal, and do not slash us
560
+ // due to inactivity for missed attestations.
561
+ void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
562
+ this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
563
+ });
564
+ return attestations;
268
565
  }
269
566
  async collectAttestations(proposal, required, deadline) {
270
- // Wait and poll the p2pClient's attestation pool for this block until we have enough attestations
271
- const slot = proposal.payload.header.slotNumber.toBigInt();
567
+ // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
568
+ const slot = proposal.slotNumber;
272
569
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
273
570
  if (+deadline < this.dateProvider.now()) {
274
571
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
@@ -279,13 +576,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
279
576
  const myAddresses = this.getValidatorAddresses();
280
577
  let attestations = [];
281
578
  while(true){
282
- // Filter out attestations with a mismatching payload. This should NOT happen since we have verified
579
+ // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
283
580
  // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
284
- const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
285
- if (!attestation.payload.equals(proposal.payload)) {
286
- this.log.warn(`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`, {
287
- attestationPayload: attestation.payload,
288
- proposalPayload: proposal.payload
581
+ const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
582
+ if (!attestation.archive.equals(proposal.archive)) {
583
+ this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
584
+ attestationArchive: attestation.archive.toString(),
585
+ proposalArchive: proposal.archive.toString()
289
586
  });
290
587
  return false;
291
588
  }
@@ -317,11 +614,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
317
614
  await sleep(this.config.attestationPollingIntervalMs);
318
615
  }
319
616
  }
320
- async createBlockAttestationsFromProposal(proposal, attestors = []) {
321
- const attestations = await this.validationService.attestToProposal(proposal, attestors);
322
- await this.p2pClient.addAttestations(attestations);
323
- return attestations;
324
- }
325
617
  async handleAuthRequest(peer, msg) {
326
618
  const authRequest = AuthRequest.fromBuffer(msg);
327
619
  const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
@@ -336,7 +628,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
336
628
  return Buffer.alloc(0);
337
629
  }
338
630
  const payloadToSign = authRequest.getPayloadToSign();
339
- const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
631
+ // AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
632
+ const context = {
633
+ dutyType: DutyType.AUTH_REQUEST
634
+ };
635
+ const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
340
636
  const authResponse = new AuthResponse(statusMessage, signature);
341
637
  return authResponse.toBuffer();
342
638
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.b655e406",
3
+ "version": "0.0.1-commit.c31f2472",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "scripts": {
20
20
  "start": "node --no-warnings ./dest/bin",
21
- "build": "yarn clean && tsc -b",
22
- "build:dev": "tsc -b --watch",
21
+ "build": "yarn clean && ../scripts/tsc.sh",
22
+ "build:dev": "../scripts/tsc.sh --watch",
23
23
  "clean": "rm -rf ./dest .tsbuildinfo",
24
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
25
25
  },
@@ -64,25 +64,35 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.b655e406",
68
- "@aztec/epoch-cache": "0.0.1-commit.b655e406",
69
- "@aztec/ethereum": "0.0.1-commit.b655e406",
70
- "@aztec/foundation": "0.0.1-commit.b655e406",
71
- "@aztec/node-keystore": "0.0.1-commit.b655e406",
72
- "@aztec/p2p": "0.0.1-commit.b655e406",
73
- "@aztec/prover-client": "0.0.1-commit.b655e406",
74
- "@aztec/slasher": "0.0.1-commit.b655e406",
75
- "@aztec/stdlib": "0.0.1-commit.b655e406",
76
- "@aztec/telemetry-client": "0.0.1-commit.b655e406",
67
+ "@aztec/blob-client": "0.0.1-commit.c31f2472",
68
+ "@aztec/blob-lib": "0.0.1-commit.c31f2472",
69
+ "@aztec/constants": "0.0.1-commit.c31f2472",
70
+ "@aztec/epoch-cache": "0.0.1-commit.c31f2472",
71
+ "@aztec/ethereum": "0.0.1-commit.c31f2472",
72
+ "@aztec/foundation": "0.0.1-commit.c31f2472",
73
+ "@aztec/node-keystore": "0.0.1-commit.c31f2472",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.c31f2472",
75
+ "@aztec/p2p": "0.0.1-commit.c31f2472",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.c31f2472",
77
+ "@aztec/prover-client": "0.0.1-commit.c31f2472",
78
+ "@aztec/simulator": "0.0.1-commit.c31f2472",
79
+ "@aztec/slasher": "0.0.1-commit.c31f2472",
80
+ "@aztec/stdlib": "0.0.1-commit.c31f2472",
81
+ "@aztec/telemetry-client": "0.0.1-commit.c31f2472",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.c31f2472",
77
83
  "koa": "^2.16.1",
78
84
  "koa-router": "^13.1.1",
79
85
  "tslib": "^2.4.0",
80
- "viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
86
+ "viem": "npm:@aztec/viem@2.38.2"
81
87
  },
82
88
  "devDependencies": {
89
+ "@aztec/archiver": "0.0.1-commit.c31f2472",
90
+ "@aztec/world-state": "0.0.1-commit.c31f2472",
91
+ "@electric-sql/pglite": "^0.3.14",
83
92
  "@jest/globals": "^30.0.0",
84
93
  "@types/jest": "^30.0.0",
85
94
  "@types/node": "^22.15.17",
95
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
86
96
  "jest": "^30.0.0",
87
97
  "jest-mock-extended": "^4.0.0",
88
98
  "ts-node": "^10.9.1",