@aztec/validator-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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 +285 -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 +329 -87
  5. package/dest/checkpoint_builder.d.ts +66 -0
  6. package/dest/checkpoint_builder.d.ts.map +1 -0
  7. package/dest/checkpoint_builder.js +175 -0
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +16 -8
  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 +111 -28
  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 -5
  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 +74 -21
  50. package/dest/validator.d.ts.map +1 -1
  51. package/dest/validator.js +452 -56
  52. package/package.json +23 -13
  53. package/src/block_proposal_handler.ts +253 -59
  54. package/src/checkpoint_builder.ts +321 -0
  55. package/src/config.ts +15 -7
  56. package/src/duties/validation_service.ts +162 -33
  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 +619 -85
package/src/validator.ts CHANGED
@@ -1,31 +1,62 @@
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
+ import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
1
3
  import type { EpochCache } from '@aztec/epoch-cache';
2
- import { EpochNumber } from '@aztec/foundation/branded-types';
4
+ import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
5
+ import {
6
+ BlockNumber,
7
+ CheckpointNumber,
8
+ EpochNumber,
9
+ IndexWithinCheckpoint,
10
+ SlotNumber,
11
+ } from '@aztec/foundation/branded-types';
12
+ import { Fr } from '@aztec/foundation/curves/bn254';
13
+ import { TimeoutError } from '@aztec/foundation/error';
3
14
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
15
  import type { Signature } from '@aztec/foundation/eth-signature';
5
- import { Fr } from '@aztec/foundation/fields';
6
- import { type Logger, createLogger } from '@aztec/foundation/log';
16
+ import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
17
+ import { retryUntil } from '@aztec/foundation/retry';
7
18
  import { RunningPromise } from '@aztec/foundation/running-promise';
8
19
  import { sleep } from '@aztec/foundation/sleep';
9
20
  import { DateProvider } from '@aztec/foundation/timer';
10
21
  import type { KeystoreManager } from '@aztec/node-keystore';
11
- import type { P2P, PeerId, TxProvider } from '@aztec/p2p';
22
+ import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
12
23
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
13
24
  import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
14
25
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
15
- import type { CommitteeAttestationsAndSigners, L2BlockSource } from '@aztec/stdlib/block';
16
- import type { IFullNodeBlockBuilder, Validator, ValidatorClientFullConfig } from '@aztec/stdlib/interfaces/server';
17
- import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
18
- import type { BlockAttestation, BlockProposal, BlockProposalOptions } from '@aztec/stdlib/p2p';
26
+ import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
27
+ import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
28
+ import type {
29
+ CreateCheckpointProposalLastBlockData,
30
+ ITxProvider,
31
+ Validator,
32
+ ValidatorClientFullConfig,
33
+ WorldStateSynchronizer,
34
+ } from '@aztec/stdlib/interfaces/server';
35
+ import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
36
+ import {
37
+ type BlockProposal,
38
+ type BlockProposalOptions,
39
+ type CheckpointAttestation,
40
+ CheckpointProposal,
41
+ type CheckpointProposalCore,
42
+ type CheckpointProposalOptions,
43
+ } from '@aztec/stdlib/p2p';
19
44
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
20
- import type { Tx } from '@aztec/stdlib/tx';
45
+ import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
21
46
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
22
47
  import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
48
+ import { createHASigner } from '@aztec/validator-ha-signer/factory';
49
+ import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
50
+ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
23
51
 
24
52
  import { EventEmitter } from 'events';
25
53
  import type { TypedDataDefinition } from 'viem';
26
54
 
27
55
  import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
56
+ import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
28
57
  import { ValidationService } from './duties/validation_service.js';
58
+ import { HAKeyStore } from './key_store/ha_key_store.js';
59
+ import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
29
60
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
30
61
  import { ValidatorMetrics } from './metrics.js';
31
62
 
@@ -47,24 +78,35 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
47
78
  private validationService: ValidationService;
48
79
  private metrics: ValidatorMetrics;
49
80
  private log: Logger;
50
-
51
81
  // Whether it has already registered handlers on the p2p client
52
82
  private hasRegisteredHandlers = false;
53
83
 
54
- // Used to check if we are sending the same proposal twice
55
- private previousProposal?: BlockProposal;
84
+ /** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
85
+ private lastProposedBlock?: BlockProposal;
86
+
87
+ /** Tracks the last checkpoint proposal we created. */
88
+ private lastProposedCheckpoint?: CheckpointProposal;
56
89
 
57
90
  private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
58
91
  private epochCacheUpdateLoop: RunningPromise;
59
92
 
60
93
  private proposersOfInvalidBlocks: Set<string> = new Set();
61
94
 
95
+ /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
96
+ private lastAttestedProposal?: CheckpointProposalCore;
97
+
62
98
  protected constructor(
63
- private keyStore: NodeKeystoreAdapter,
99
+ private keyStore: ExtendedValidatorKeyStore,
64
100
  private epochCache: EpochCache,
65
101
  private p2pClient: P2P,
66
102
  private blockProposalHandler: BlockProposalHandler,
103
+ private blockSource: L2BlockSource,
104
+ private checkpointsBuilder: FullNodeCheckpointsBuilder,
105
+ private worldState: WorldStateSynchronizer,
106
+ private l1ToL2MessageSource: L1ToL2MessageSource,
67
107
  private config: ValidatorClientFullConfig,
108
+ private blobClient: BlobClientInterface,
109
+ private haSigner: ValidatorHASigner | undefined,
68
110
  private dateProvider: DateProvider = new DateProvider(),
69
111
  telemetry: TelemetryClient = getTelemetryClient(),
70
112
  log = createLogger('validator'),
@@ -138,15 +180,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
138
180
  }
139
181
  }
140
182
 
141
- static new(
183
+ static async new(
142
184
  config: ValidatorClientFullConfig,
143
- blockBuilder: IFullNodeBlockBuilder,
185
+ checkpointsBuilder: FullNodeCheckpointsBuilder,
186
+ worldState: WorldStateSynchronizer,
144
187
  epochCache: EpochCache,
145
188
  p2pClient: P2P,
146
- blockSource: L2BlockSource,
189
+ blockSource: L2BlockSource & L2BlockSink,
147
190
  l1ToL2MessageSource: L1ToL2MessageSource,
148
- txProvider: TxProvider,
191
+ txProvider: ITxProvider,
149
192
  keyStoreManager: KeystoreManager,
193
+ blobClient: BlobClientInterface,
150
194
  dateProvider: DateProvider = new DateProvider(),
151
195
  telemetry: TelemetryClient = getTelemetryClient(),
152
196
  ) {
@@ -155,23 +199,45 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
155
199
  txsPermitted: !config.disableTransactions,
156
200
  });
157
201
  const blockProposalHandler = new BlockProposalHandler(
158
- blockBuilder,
202
+ checkpointsBuilder,
203
+ worldState,
159
204
  blockSource,
160
205
  l1ToL2MessageSource,
161
206
  txProvider,
162
207
  blockProposalValidator,
208
+ epochCache,
163
209
  config,
164
210
  metrics,
165
211
  dateProvider,
166
212
  telemetry,
167
213
  );
168
214
 
215
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
216
+ let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
217
+ let haSigner: ValidatorHASigner | undefined;
218
+ if (config.haSigningEnabled) {
219
+ // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
220
+ const haConfig = {
221
+ ...config,
222
+ maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
223
+ };
224
+ const { signer } = await createHASigner(haConfig, { telemetryClient: telemetry, dateProvider });
225
+ haSigner = signer;
226
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
227
+ }
228
+
169
229
  const validator = new ValidatorClient(
170
- NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager),
230
+ validatorKeyStore,
171
231
  epochCache,
172
232
  p2pClient,
173
233
  blockProposalHandler,
234
+ blockSource,
235
+ checkpointsBuilder,
236
+ worldState,
237
+ l1ToL2MessageSource,
174
238
  config,
239
+ blobClient,
240
+ haSigner,
175
241
  dateProvider,
176
242
  telemetry,
177
243
  );
@@ -189,18 +255,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
189
255
  return this.blockProposalHandler;
190
256
  }
191
257
 
192
- // Proxy method for backwards compatibility with tests
193
- public reExecuteTransactions(
194
- proposal: BlockProposal,
195
- blockNumber: number,
196
- txs: any[],
197
- l1ToL2Messages: Fr[],
198
- ): Promise<any> {
199
- return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
200
- }
201
-
202
- public signWithAddress(addr: EthAddress, msg: TypedDataDefinition) {
203
- return this.keyStore.signTypedDataWithAddress(addr, msg);
258
+ public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
259
+ return this.keyStore.signTypedDataWithAddress(addr, msg, context);
204
260
  }
205
261
 
206
262
  public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
@@ -219,12 +275,36 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
219
275
  this.config = { ...this.config, ...config };
220
276
  }
221
277
 
278
+ public reloadKeystore(newManager: KeystoreManager): void {
279
+ if (this.config.haSigningEnabled && !this.haSigner) {
280
+ this.log.warn(
281
+ 'HA signing is enabled in config but was not initialized at startup. ' +
282
+ 'Restart the node to enable HA signing.',
283
+ );
284
+ } else if (!this.config.haSigningEnabled && this.haSigner) {
285
+ this.log.warn(
286
+ 'HA signing was disabled via config update but the HA signer is still active. ' +
287
+ 'Restart the node to fully disable HA signing.',
288
+ );
289
+ }
290
+
291
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
292
+ if (this.haSigner) {
293
+ this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
294
+ } else {
295
+ this.keyStore = newAdapter;
296
+ }
297
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
298
+ }
299
+
222
300
  public async start() {
223
301
  if (this.epochCacheUpdateLoop.isRunning()) {
224
302
  this.log.warn(`Validator client already started`);
225
303
  return;
226
304
  }
227
305
 
306
+ await this.keyStore.start();
307
+
228
308
  await this.registerHandlers();
229
309
 
230
310
  const myAddresses = this.getValidatorAddresses();
@@ -240,6 +320,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
240
320
 
241
321
  public async stop() {
242
322
  await this.epochCacheUpdateLoop.stop();
323
+ await this.keyStore.stop();
243
324
  }
244
325
 
245
326
  /** Register handlers on the p2p client */
@@ -248,9 +329,29 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
248
329
  this.hasRegisteredHandlers = true;
249
330
  this.log.debug(`Registering validator handlers for p2p client`);
250
331
 
251
- const handler = (block: BlockProposal, proposalSender: PeerId): Promise<BlockAttestation[] | undefined> =>
252
- this.attestToProposal(block, proposalSender);
253
- this.p2pClient.registerBlockProposalHandler(handler);
332
+ // Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
333
+ const blockHandler = (block: BlockProposal, proposalSender: PeerId): Promise<boolean> =>
334
+ this.validateBlockProposal(block, proposalSender);
335
+ this.p2pClient.registerBlockProposalHandler(blockHandler);
336
+
337
+ // Checkpoint proposal handler - validates and creates attestations
338
+ // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
339
+ // and processed separately via the block handler above.
340
+ const checkpointHandler = (
341
+ checkpoint: CheckpointProposalCore,
342
+ proposalSender: PeerId,
343
+ ): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
344
+ this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
345
+
346
+ // Duplicate proposal handler - triggers slashing for equivocation
347
+ this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
348
+ this.handleDuplicateProposal(info);
349
+ });
350
+
351
+ // Duplicate attestation handler - triggers slashing for attestation equivocation
352
+ this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
353
+ this.handleDuplicateAttestation(info);
354
+ });
254
355
 
255
356
  const myAddresses = this.getValidatorAddresses();
256
357
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
@@ -259,29 +360,47 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
259
360
  }
260
361
  }
261
362
 
262
- async attestToProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<BlockAttestation[] | undefined> {
363
+ /**
364
+ * Validate a block proposal from a peer.
365
+ * Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
366
+ * @returns true if the proposal is valid, false otherwise
367
+ */
368
+ async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
263
369
  const slotNumber = proposal.slotNumber;
370
+
371
+ // Note: During escape hatch, we still want to "validate" proposals for observability,
372
+ // but we intentionally reject them and disable slashing invalid block and attestation flow.
373
+ const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
374
+
264
375
  const proposer = proposal.getSender();
265
376
 
266
377
  // Reject proposals with invalid signatures
267
378
  if (!proposer) {
268
- this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
269
- return undefined;
379
+ this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
380
+ return false;
270
381
  }
271
382
 
272
- // Check that I have any address in current committee before attesting
383
+ // Ignore proposals from ourselves (may happen in HA setups)
384
+ if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
385
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
386
+ proposer: proposer.toString(),
387
+ slotNumber,
388
+ });
389
+ return false;
390
+ }
391
+
392
+ // Check if we're in the committee (for metrics purposes)
273
393
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
274
394
  const partOfCommittee = inCommittee.length > 0;
275
395
 
276
396
  const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
277
- this.log.info(`Received proposal for slot ${slotNumber}`, {
397
+ this.log.info(`Received block proposal for slot ${slotNumber}`, {
278
398
  ...proposalInfo,
279
399
  txHashes: proposal.txHashes.map(t => t.toString()),
280
400
  fishermanMode: this.config.fishermanMode || false,
281
401
  });
282
402
 
283
- // Reexecute txs if we are part of the committee so we can attest, or if slashing is enabled so we can slash
284
- // invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
403
+ // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
285
404
  // In fisherman mode, we always reexecute to validate proposals.
286
405
  const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
287
406
  this.config;
@@ -289,16 +408,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
289
408
  fishermanMode ||
290
409
  (slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
291
410
  (partOfCommittee && validatorReexecute) ||
292
- alwaysReexecuteBlockProposals;
411
+ alwaysReexecuteBlockProposals ||
412
+ this.blobClient.canUpload();
293
413
 
294
414
  const validationResult = await this.blockProposalHandler.handleBlockProposal(
295
415
  proposal,
296
416
  proposalSender,
297
- !!shouldReexecute,
417
+ !!shouldReexecute && !escapeHatchOpen,
298
418
  );
299
419
 
300
420
  if (!validationResult.isValid) {
301
- this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
421
+ this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
302
422
 
303
423
  const reason = validationResult.reason || 'unknown';
304
424
  // Classify failure reason: bad proposal vs node issue
@@ -313,12 +433,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
313
433
  if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
314
434
  this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
315
435
  } else {
316
- // Node issues so we can't attest
436
+ // Node issues so we can't validate
317
437
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
318
438
  }
319
439
 
320
440
  // Slash invalid block proposals (can happen even when not in committee)
321
441
  if (
442
+ !escapeHatchOpen &&
322
443
  validationResult.reason &&
323
444
  SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
324
445
  slashBroadcastedInvalidBlockPenalty > 0n
@@ -326,9 +447,98 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
326
447
  this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
327
448
  this.slashInvalidBlock(proposal);
328
449
  }
450
+ return false;
451
+ }
452
+
453
+ this.log.info(`Validated block proposal for slot ${slotNumber}`, {
454
+ ...proposalInfo,
455
+ inCommittee: partOfCommittee,
456
+ fishermanMode: this.config.fishermanMode || false,
457
+ escapeHatchOpen,
458
+ });
459
+
460
+ if (escapeHatchOpen) {
461
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
462
+ return false;
463
+ }
464
+
465
+ return true;
466
+ }
467
+
468
+ /**
469
+ * Validate and attest to a checkpoint proposal from a peer.
470
+ * The proposal is received as CheckpointProposalCore (without lastBlock) since
471
+ * the lastBlock is extracted and processed separately via the block handler.
472
+ * @returns Checkpoint attestations if valid, undefined otherwise
473
+ */
474
+ async attestToCheckpointProposal(
475
+ proposal: CheckpointProposalCore,
476
+ _proposalSender: PeerId,
477
+ ): Promise<CheckpointAttestation[] | undefined> {
478
+ const slotNumber = proposal.slotNumber;
479
+ const proposer = proposal.getSender();
480
+
481
+ // If escape hatch is open for this slot's epoch, do not attest.
482
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
483
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
484
+ return undefined;
485
+ }
486
+
487
+ // Reject proposals with invalid signatures
488
+ if (!proposer) {
489
+ this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
490
+ return undefined;
491
+ }
492
+
493
+ // Ignore proposals from ourselves (may happen in HA setups)
494
+ if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
495
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
496
+ proposer: proposer.toString(),
497
+ slotNumber,
498
+ });
499
+ return undefined;
500
+ }
501
+
502
+ // Validate fee asset price modifier is within allowed range
503
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
504
+ this.log.warn(
505
+ `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
506
+ );
329
507
  return undefined;
330
508
  }
331
509
 
510
+ // Check that I have any address in current committee before attesting
511
+ const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
512
+ const partOfCommittee = inCommittee.length > 0;
513
+
514
+ const proposalInfo = {
515
+ slotNumber,
516
+ archive: proposal.archive.toString(),
517
+ proposer: proposer.toString(),
518
+ txCount: proposal.txHashes.length,
519
+ };
520
+ this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
521
+ ...proposalInfo,
522
+ txHashes: proposal.txHashes.map(t => t.toString()),
523
+ fishermanMode: this.config.fishermanMode || false,
524
+ });
525
+
526
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
527
+ if (this.config.skipCheckpointProposalValidation) {
528
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
529
+ } else {
530
+ const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
531
+ if (!validationResult.isValid) {
532
+ this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
533
+ return undefined;
534
+ }
535
+ }
536
+
537
+ // Upload blobs to filestore if we can (fire and forget)
538
+ if (this.blobClient.canUpload()) {
539
+ void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
540
+ }
541
+
332
542
  // Check that I have any address in current committee before attesting
333
543
  // In fisherman mode, we still create attestations for validation even if not in committee
334
544
  if (!partOfCommittee && !this.config.fishermanMode) {
@@ -337,7 +547,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
337
547
  }
338
548
 
339
549
  // Provided all of the above checks pass, we can attest to the proposal
340
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
550
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
341
551
  ...proposalInfo,
342
552
  inCommittee: partOfCommittee,
343
553
  fishermanMode: this.config.fishermanMode || false,
@@ -345,7 +555,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
345
555
 
346
556
  this.metrics.incSuccessfulAttestations(inCommittee.length);
347
557
 
348
- // If the above function does not throw an error, then we can attest to the proposal
349
558
  // Determine which validators should attest
350
559
  let attestors: EthAddress[];
351
560
  if (partOfCommittee) {
@@ -364,13 +573,234 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
364
573
 
365
574
  if (this.config.fishermanMode) {
366
575
  // bail out early and don't save attestations to the pool in fisherman mode
367
- this.log.info(`Creating attestations for proposal for slot ${slotNumber}`, {
576
+ this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
368
577
  ...proposalInfo,
369
578
  attestors: attestors.map(a => a.toString()),
370
579
  });
371
580
  return undefined;
372
581
  }
373
- return this.createBlockAttestationsFromProposal(proposal, attestors);
582
+
583
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
584
+ }
585
+
586
+ /**
587
+ * Checks if we should attest to a slot based on equivocation prevention rules.
588
+ * @returns true if we should attest, false if we should skip
589
+ */
590
+ private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
591
+ // If attestToEquivocatedProposals is true, always allow
592
+ if (this.config.attestToEquivocatedProposals) {
593
+ return true;
594
+ }
595
+
596
+ // Check if incoming slot is strictly greater than last attested
597
+ if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
598
+ this.log.warn(
599
+ `Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
600
+ );
601
+ return false;
602
+ }
603
+
604
+ return true;
605
+ }
606
+
607
+ private async createCheckpointAttestationsFromProposal(
608
+ proposal: CheckpointProposalCore,
609
+ attestors: EthAddress[] = [],
610
+ ): Promise<CheckpointAttestation[] | undefined> {
611
+ // Equivocation check: must happen right before signing to minimize the race window
612
+ if (!this.shouldAttestToSlot(proposal.slotNumber)) {
613
+ return undefined;
614
+ }
615
+
616
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
617
+
618
+ // Track the proposal we attested to (to prevent equivocation)
619
+ this.lastAttestedProposal = proposal;
620
+
621
+ await this.p2pClient.addOwnCheckpointAttestations(attestations);
622
+ return attestations;
623
+ }
624
+
625
+ /**
626
+ * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
627
+ * @returns Validation result with isValid flag and reason if invalid.
628
+ */
629
+ private async validateCheckpointProposal(
630
+ proposal: CheckpointProposalCore,
631
+ proposalInfo: LogData,
632
+ ): Promise<{ isValid: true } | { isValid: false; reason: string }> {
633
+ const slot = proposal.slotNumber;
634
+
635
+ // Timeout block syncing at the start of the next slot
636
+ const config = this.checkpointsBuilder.getConfig();
637
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
638
+ const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
639
+
640
+ // Wait for last block to sync by archive
641
+ let lastBlockHeader: BlockHeader | undefined;
642
+ try {
643
+ lastBlockHeader = await retryUntil(
644
+ async () => {
645
+ await this.blockSource.syncImmediate();
646
+ return this.blockSource.getBlockHeaderByArchive(proposal.archive);
647
+ },
648
+ `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
649
+ timeoutSeconds,
650
+ 0.5,
651
+ );
652
+ } catch (err) {
653
+ if (err instanceof TimeoutError) {
654
+ this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
655
+ return { isValid: false, reason: 'last_block_not_found' };
656
+ }
657
+ this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
658
+ return { isValid: false, reason: 'block_fetch_error' };
659
+ }
660
+
661
+ if (!lastBlockHeader) {
662
+ this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
663
+ return { isValid: false, reason: 'last_block_not_found' };
664
+ }
665
+
666
+ // Get all full blocks for the slot and checkpoint
667
+ const blocks = await this.blockSource.getBlocksForSlot(slot);
668
+ if (blocks.length === 0) {
669
+ this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
670
+ return { isValid: false, reason: 'no_blocks_for_slot' };
671
+ }
672
+
673
+ // Ensure the last block for this slot matches the archive in the checkpoint proposal
674
+ if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
675
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
676
+ return { isValid: false, reason: 'last_block_archive_mismatch' };
677
+ }
678
+
679
+ this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
680
+ ...proposalInfo,
681
+ blockNumbers: blocks.map(b => b.number),
682
+ });
683
+
684
+ // Get checkpoint constants from first block
685
+ const firstBlock = blocks[0];
686
+ const constants = this.extractCheckpointConstants(firstBlock);
687
+ const checkpointNumber = firstBlock.checkpointNumber;
688
+
689
+ // Get L1-to-L2 messages for this checkpoint
690
+ const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
691
+
692
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
693
+ const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
694
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
695
+ .filter(c => c.checkpointNumber < checkpointNumber)
696
+ .map(c => c.checkpointOutHash);
697
+
698
+ // Fork world state at the block before the first block
699
+ const parentBlockNumber = BlockNumber(firstBlock.number - 1);
700
+ const fork = await this.worldState.fork(parentBlockNumber);
701
+
702
+ try {
703
+ // Create checkpoint builder with all existing blocks
704
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
705
+ checkpointNumber,
706
+ constants,
707
+ proposal.feeAssetPriceModifier,
708
+ l1ToL2Messages,
709
+ previousCheckpointOutHashes,
710
+ fork,
711
+ blocks,
712
+ this.log.getBindings(),
713
+ );
714
+
715
+ // Complete the checkpoint to get computed values
716
+ const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
717
+
718
+ // Compare checkpoint header with proposal
719
+ if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
720
+ this.log.warn(`Checkpoint header mismatch`, {
721
+ ...proposalInfo,
722
+ computed: computedCheckpoint.header.toInspect(),
723
+ proposal: proposal.checkpointHeader.toInspect(),
724
+ });
725
+ return { isValid: false, reason: 'checkpoint_header_mismatch' };
726
+ }
727
+
728
+ // Compare archive root with proposal
729
+ if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
730
+ this.log.warn(`Archive root mismatch`, {
731
+ ...proposalInfo,
732
+ computed: computedCheckpoint.archive.root.toString(),
733
+ proposal: proposal.archive.toString(),
734
+ });
735
+ return { isValid: false, reason: 'archive_mismatch' };
736
+ }
737
+
738
+ // Check that the accumulated epoch out hash matches the value in the proposal.
739
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
740
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
741
+ const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
742
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
743
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
744
+ this.log.warn(`Epoch out hash mismatch`, {
745
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
746
+ computedEpochOutHash: computedEpochOutHash.toString(),
747
+ checkpointOutHash: checkpointOutHash.toString(),
748
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
749
+ ...proposalInfo,
750
+ });
751
+ return { isValid: false, reason: 'out_hash_mismatch' };
752
+ }
753
+
754
+ this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
755
+ return { isValid: true };
756
+ } finally {
757
+ await fork.close();
758
+ }
759
+ }
760
+
761
+ /**
762
+ * Extract checkpoint global variables from a block.
763
+ */
764
+ private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
765
+ const gv = block.header.globalVariables;
766
+ return {
767
+ chainId: gv.chainId,
768
+ version: gv.version,
769
+ slotNumber: gv.slotNumber,
770
+ timestamp: gv.timestamp,
771
+ coinbase: gv.coinbase,
772
+ feeRecipient: gv.feeRecipient,
773
+ gasFees: gv.gasFees,
774
+ };
775
+ }
776
+
777
+ /**
778
+ * Uploads blobs for a checkpoint to the filestore (fire and forget).
779
+ */
780
+ protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
781
+ try {
782
+ const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
783
+ if (!lastBlockHeader) {
784
+ this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
785
+ return;
786
+ }
787
+
788
+ const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
789
+ if (blocks.length === 0) {
790
+ this.log.warn(`No blocks found for blob upload`, proposalInfo);
791
+ return;
792
+ }
793
+
794
+ const blobFields = blocks.flatMap(b => b.toBlobFields());
795
+ const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
796
+ await this.blobClient.sendBlobsToFilestore(blobs);
797
+ this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
798
+ ...proposalInfo,
799
+ numBlobs: blobs.length,
800
+ });
801
+ } catch (err) {
802
+ this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
803
+ }
374
804
  }
375
805
 
376
806
  private slashInvalidBlock(proposal: BlockProposal) {
@@ -400,24 +830,125 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
400
830
  ]);
401
831
  }
402
832
 
833
+ /**
834
+ * Handle detection of a duplicate proposal (equivocation).
835
+ * Emits a slash event when a proposer sends multiple proposals for the same position.
836
+ */
837
+ private handleDuplicateProposal(info: DuplicateProposalInfo): void {
838
+ const { slot, proposer, type } = info;
839
+
840
+ this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
841
+ proposer: proposer.toString(),
842
+ slot,
843
+ type,
844
+ });
845
+
846
+ // Emit slash event
847
+ this.emit(WANT_TO_SLASH_EVENT, [
848
+ {
849
+ validator: proposer,
850
+ amount: this.config.slashDuplicateProposalPenalty,
851
+ offenseType: OffenseType.DUPLICATE_PROPOSAL,
852
+ epochOrSlot: BigInt(slot),
853
+ },
854
+ ]);
855
+ }
856
+
857
+ /**
858
+ * Handle detection of a duplicate attestation (equivocation).
859
+ * Emits a slash event when an attester signs attestations for different proposals at the same slot.
860
+ */
861
+ private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
862
+ const { slot, attester } = info;
863
+
864
+ this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
865
+ attester: attester.toString(),
866
+ slot,
867
+ });
868
+
869
+ this.emit(WANT_TO_SLASH_EVENT, [
870
+ {
871
+ validator: attester,
872
+ amount: this.config.slashDuplicateAttestationPenalty,
873
+ offenseType: OffenseType.DUPLICATE_ATTESTATION,
874
+ epochOrSlot: BigInt(slot),
875
+ },
876
+ ]);
877
+ }
878
+
403
879
  async createBlockProposal(
404
- blockNumber: number,
405
- header: CheckpointHeader,
880
+ blockHeader: BlockHeader,
881
+ indexWithinCheckpoint: IndexWithinCheckpoint,
882
+ inHash: Fr,
406
883
  archive: Fr,
407
884
  txs: Tx[],
408
885
  proposerAddress: EthAddress | undefined,
409
- options: BlockProposalOptions,
410
- ): Promise<BlockProposal | undefined> {
411
- if (this.previousProposal?.slotNumber === header.slotNumber) {
412
- this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
413
- return Promise.resolve(undefined);
886
+ options: BlockProposalOptions = {},
887
+ ): Promise<BlockProposal> {
888
+ // Validate that we're not creating a proposal for an older or equal position
889
+ if (this.lastProposedBlock) {
890
+ const lastSlot = this.lastProposedBlock.slotNumber;
891
+ const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
892
+ const newSlot = blockHeader.globalVariables.slotNumber;
893
+
894
+ if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
895
+ throw new Error(
896
+ `Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
897
+ `already proposed block for slot ${lastSlot} index ${lastIndex}`,
898
+ );
899
+ }
414
900
  }
415
901
 
416
- const newProposal = await this.validationService.createBlockProposal(header, archive, txs, proposerAddress, {
417
- ...options,
418
- broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
419
- });
420
- this.previousProposal = newProposal;
902
+ this.log.info(
903
+ `Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
904
+ );
905
+ const newProposal = await this.validationService.createBlockProposal(
906
+ blockHeader,
907
+ indexWithinCheckpoint,
908
+ inHash,
909
+ archive,
910
+ txs,
911
+ proposerAddress,
912
+ {
913
+ ...options,
914
+ broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
915
+ },
916
+ );
917
+ this.lastProposedBlock = newProposal;
918
+ return newProposal;
919
+ }
920
+
921
+ async createCheckpointProposal(
922
+ checkpointHeader: CheckpointHeader,
923
+ archive: Fr,
924
+ feeAssetPriceModifier: bigint,
925
+ lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
926
+ proposerAddress: EthAddress | undefined,
927
+ options: CheckpointProposalOptions = {},
928
+ ): Promise<CheckpointProposal> {
929
+ // Validate that we're not creating a proposal for an older or equal slot
930
+ if (this.lastProposedCheckpoint) {
931
+ const lastSlot = this.lastProposedCheckpoint.slotNumber;
932
+ const newSlot = checkpointHeader.slotNumber;
933
+
934
+ if (newSlot <= lastSlot) {
935
+ throw new Error(
936
+ `Cannot create checkpoint proposal for slot ${newSlot}: ` +
937
+ `already proposed checkpoint for slot ${lastSlot}`,
938
+ );
939
+ }
940
+ }
941
+
942
+ this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
943
+ const newProposal = await this.validationService.createCheckpointProposal(
944
+ checkpointHeader,
945
+ archive,
946
+ feeAssetPriceModifier,
947
+ lastBlockInfo,
948
+ proposerAddress,
949
+ options,
950
+ );
951
+ this.lastProposedCheckpoint = newProposal;
421
952
  return newProposal;
422
953
  }
423
954
 
@@ -428,28 +959,38 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
428
959
  async signAttestationsAndSigners(
429
960
  attestationsAndSigners: CommitteeAttestationsAndSigners,
430
961
  proposer: EthAddress,
962
+ slot: SlotNumber,
963
+ blockNumber: BlockNumber | CheckpointNumber,
431
964
  ): Promise<Signature> {
432
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
965
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
433
966
  }
434
967
 
435
- async collectOwnAttestations(proposal: BlockProposal): Promise<BlockAttestation[]> {
436
- const slot = proposal.payload.header.slotNumber;
968
+ async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
969
+ const slot = proposal.slotNumber;
437
970
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
438
971
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
439
- const attestations = await this.createBlockAttestationsFromProposal(proposal, inCommittee);
972
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
973
+
974
+ if (!attestations) {
975
+ return [];
976
+ }
440
977
 
441
978
  // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
442
979
  // other nodes can see that our validators did attest to this block proposal, and do not slash us
443
980
  // due to inactivity for missed attestations.
444
- void this.p2pClient.broadcastAttestations(attestations).catch(err => {
981
+ void this.p2pClient.broadcastCheckpointAttestations(attestations).catch(err => {
445
982
  this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
446
983
  });
447
984
  return attestations;
448
985
  }
449
986
 
450
- async collectAttestations(proposal: BlockProposal, required: number, deadline: Date): Promise<BlockAttestation[]> {
451
- // Wait and poll the p2pClient's attestation pool for this block until we have enough attestations
452
- const slot = proposal.payload.header.slotNumber;
987
+ async collectAttestations(
988
+ proposal: CheckpointProposal,
989
+ required: number,
990
+ deadline: Date,
991
+ ): Promise<CheckpointAttestation[]> {
992
+ // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
993
+ const slot = proposal.slotNumber;
453
994
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
454
995
 
455
996
  if (+deadline < this.dateProvider.now()) {
@@ -464,16 +1005,16 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
464
1005
  const proposalId = proposal.archive.toString();
465
1006
  const myAddresses = this.getValidatorAddresses();
466
1007
 
467
- let attestations: BlockAttestation[] = [];
1008
+ let attestations: CheckpointAttestation[] = [];
468
1009
  while (true) {
469
- // Filter out attestations with a mismatching payload. This should NOT happen since we have verified
1010
+ // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
470
1011
  // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
471
- const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter(
1012
+ const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
472
1013
  attestation => {
473
- if (!attestation.payload.equals(proposal.payload)) {
1014
+ if (!attestation.archive.equals(proposal.archive)) {
474
1015
  this.log.warn(
475
- `Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`,
476
- { attestationPayload: attestation.payload, proposalPayload: proposal.payload },
1016
+ `Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
1017
+ { attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
477
1018
  );
478
1019
  return false;
479
1020
  }
@@ -514,15 +1055,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
514
1055
  }
515
1056
  }
516
1057
 
517
- private async createBlockAttestationsFromProposal(
518
- proposal: BlockProposal,
519
- attestors: EthAddress[] = [],
520
- ): Promise<BlockAttestation[]> {
521
- const attestations = await this.validationService.attestToProposal(proposal, attestors);
522
- await this.p2pClient.addAttestations(attestations);
523
- return attestations;
524
- }
525
-
526
1058
  private async handleAuthRequest(peer: PeerId, msg: Buffer): Promise<Buffer> {
527
1059
  const authRequest = AuthRequest.fromBuffer(msg);
528
1060
  const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch(_ => undefined);
@@ -541,7 +1073,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
541
1073
  }
542
1074
 
543
1075
  const payloadToSign = authRequest.getPayloadToSign();
544
- const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
1076
+ // AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
1077
+ const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
1078
+ const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
545
1079
  const authResponse = new AuthResponse(statusMessage, signature);
546
1080
  return authResponse.toBuffer();
547
1081
  }