@aztec-labs/validator-client 6.0.0-rc.3 → 6.0.0-rc.4

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.
package/src/validator.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { BlobClientInterface } from '@aztec-labs/blob-client/client';
2
- import { type Blob, getBlobsPerL1Block } from '@aztec-labs/blob-lib';
3
- import type { EpochCache } from '@aztec-labs/epoch-cache';
2
+ import { type EpochCache, requireStableCommittee } from '@aztec-labs/epoch-cache';
4
3
  import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec-labs/foundation/branded-types';
5
4
  import { compactArray } from '@aztec-labs/foundation/collection';
6
5
  import { Fr } from '@aztec-labs/foundation/curves/bn254';
@@ -32,6 +31,7 @@ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
32
31
  import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec-labs/stdlib/block';
33
32
  import type { CheckpointReexecutionTracker } from '@aztec-labs/stdlib/checkpoint';
34
33
  import { getEpochAtSlot } from '@aztec-labs/stdlib/epoch-helpers';
34
+ import { BaseSignerConfigSchema, DEFAULT_SIGNED_DUTIES_RETENTION_HOURS } from '@aztec-labs/stdlib/ha-signing';
35
35
  import type {
36
36
  ITxProvider,
37
37
  Validator,
@@ -62,11 +62,13 @@ import {
62
62
  } from '@aztec-labs/validator-ha-signer/factory';
63
63
  import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec-labs/validator-ha-signer/types';
64
64
  import type { ValidatorHASigner } from '@aztec-labs/validator-ha-signer/validator-ha-signer';
65
+ import { Buffer } from 'buffer';
65
66
  import { EventEmitter } from 'events';
66
67
  import type { TypedDataDefinition } from 'viem';
67
68
 
68
69
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
69
70
  import type { InboxEndpointReader } from './checkpoint_endpoint_check.js';
71
+ import { warnCommitteeNotStable } from './committee_not_stable.js';
70
72
  import { ValidationService } from './duties/validation_service.js';
71
73
  import { HAKeyStore } from './key_store/ha_key_store.js';
72
74
  import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
@@ -184,11 +186,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
184
186
 
185
187
  private async handleEpochCommitteeUpdate() {
186
188
  try {
187
- const { committee, epoch } = await this.epochCache.getCommittee('next');
188
- if (!committee) {
189
+ const lookup = await this.epochCache.getCommittee('next');
190
+ if (lookup.state === 'unstable') {
191
+ this.log.trace(`Committee for epoch ${lookup.epoch} is not stable on L1 yet, retrying on the next tick`, {
192
+ epoch: lookup.epoch,
193
+ });
194
+ return;
195
+ }
196
+ if (lookup.state === 'none') {
189
197
  this.log.trace(`No committee found for slot`);
190
198
  return;
191
199
  }
200
+ const { epoch } = lookup;
201
+ const committee = lookup.state === 'members' ? lookup.committee : [];
192
202
  this.metrics.setCurrentEpoch(epoch);
193
203
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
194
204
  const me = this.getValidatorAddresses();
@@ -253,10 +263,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
253
263
  );
254
264
 
255
265
  const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
266
+ const signerConfig = {
267
+ ...config,
268
+ cleanupOldDutiesAfterHours: Math.max(
269
+ BaseSignerConfigSchema.shape.cleanupOldDutiesAfterHours.parse(config.cleanupOldDutiesAfterHours) ??
270
+ DEFAULT_SIGNED_DUTIES_RETENTION_HOURS,
271
+ (epochCache.getL1Constants().slotDuration * 2) / 3600,
272
+ ),
273
+ };
256
274
  let slashingProtectionSigner: ValidatorHASigner;
257
275
  if (slashingProtectionDb) {
258
276
  // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
259
- ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
277
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, signerConfig, {
260
278
  telemetryClient: telemetry,
261
279
  dateProvider,
262
280
  }));
@@ -264,7 +282,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
264
282
  // Multi-node HA mode: use PostgreSQL-backed distributed locking.
265
283
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
266
284
  const haConfig = {
267
- ...config,
285
+ ...signerConfig,
268
286
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
269
287
  };
270
288
  ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
@@ -274,7 +292,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
274
292
  } else {
275
293
  // Single-node mode: use LMDB-backed local signing protection.
276
294
  // This prevents double-signing if the node crashes and restarts mid-proposal.
277
- ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
295
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(signerConfig, {
278
296
  telemetryClient: telemetry,
279
297
  dateProvider,
280
298
  }));
@@ -368,10 +386,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
368
386
  await this.registerHandlers();
369
387
 
370
388
  const myAddresses = this.getValidatorAddresses();
371
- const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
372
389
  this.log.info(`Started validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
373
- if (inCommittee.length > 0) {
374
- this.log.info(`Addresses in current validator committee: ${inCommittee.map(a => a.toString()).join(', ')}`);
390
+ const membership = await this.epochCache.filterInCommittee('now', myAddresses);
391
+ if (membership.state === 'members' && membership.inCommittee.length > 0) {
392
+ this.log.info(
393
+ `Addresses in current validator committee: ${membership.inCommittee.map(a => a.toString()).join(', ')}`,
394
+ );
375
395
  }
376
396
  this.epochCacheUpdateLoop.start();
377
397
 
@@ -403,7 +423,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
403
423
  ): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
404
424
  this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
405
425
 
406
- // Duplicate proposal handler - triggers slashing for equivocation
426
+ // Duplicate proposal handler - marks the slot as equivocated
407
427
  this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
408
428
  this.handleDuplicateProposal(info);
409
429
  });
@@ -439,7 +459,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
439
459
 
440
460
  // Note: During escape hatch, we still want to "validate" proposals for observability,
441
461
  // but we intentionally reject them and disable slashing invalid block and attestation flow.
442
- const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
462
+ const escapeHatch = await this.epochCache.lookupEscapeHatchAtSlot(slotNumber);
463
+ if (escapeHatch.state === 'unstable') {
464
+ warnCommitteeNotStable(this.log, escapeHatch, slotNumber, 'block proposal');
465
+ return false;
466
+ }
467
+ const escapeHatchOpen = escapeHatch.isEscapeHatchOpen;
443
468
 
444
469
  const proposer = proposal.getSender();
445
470
 
@@ -458,8 +483,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
458
483
  }
459
484
 
460
485
  // Check if we're in the committee (for metrics purposes)
461
- const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
462
- const partOfCommittee = inCommittee.length > 0;
486
+ const membership = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
487
+ if (membership.state === 'unstable') {
488
+ warnCommitteeNotStable(this.log, membership, slotNumber, 'block proposal');
489
+ return false;
490
+ }
491
+ const partOfCommittee = membership.state === 'members' && membership.inCommittee.length > 0;
463
492
 
464
493
  const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
465
494
  this.log.info(`Received block proposal for slot ${slotNumber}`, {
@@ -536,7 +565,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
536
565
  const proposer = proposal.getSender();
537
566
 
538
567
  // If escape hatch is open for this slot's epoch, do not attest.
539
- if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
568
+ const escapeHatch = await this.epochCache.lookupEscapeHatchAtSlot(proposalSlotNumber);
569
+ if (escapeHatch.state === 'unstable') {
570
+ warnCommitteeNotStable(this.log, escapeHatch, proposalSlotNumber, 'checkpoint proposal');
571
+ return undefined;
572
+ }
573
+ if (escapeHatch.isEscapeHatchOpen) {
540
574
  this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
541
575
  return undefined;
542
576
  }
@@ -556,7 +590,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
556
590
  }
557
591
 
558
592
  // Check that I have any address in the committee where this checkpoint will land before attesting
559
- const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
593
+ const membership = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
594
+ if (membership.state === 'unstable') {
595
+ warnCommitteeNotStable(this.log, membership, proposalSlotNumber, 'checkpoint proposal');
596
+ return undefined;
597
+ }
598
+ // An open committee and a missing one have no members, so none of our validators is on it.
599
+ const inCommittee = membership.state === 'members' ? membership.inCommittee : [];
560
600
  const partOfCommittee = inCommittee.length > 0;
561
601
 
562
602
  const proposalInfo = {
@@ -730,35 +770,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
730
770
  return true;
731
771
  }
732
772
 
733
- /**
734
- * Uploads blobs for a checkpoint to the filestore (fire and forget).
735
- */
736
- protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
737
- try {
738
- const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
739
- if (!lastBlockHeader) {
740
- this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
741
- return;
742
- }
743
-
744
- const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
745
- if (blocks.length === 0) {
746
- this.log.warn(`No blocks found for blob upload`, proposalInfo);
747
- return;
748
- }
749
-
750
- const blobFields = blocks.flatMap(b => b.toBlobFields());
751
- const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
752
- await this.blobClient.sendBlobsToFilestore(blobs);
753
- this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
754
- ...proposalInfo,
755
- numBlobs: blobs.length,
756
- });
757
- } catch (err) {
758
- this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
759
- }
760
- }
761
-
762
773
  private slashInvalidBlock(proposal: BlockProposal) {
763
774
  const proposer = proposal.getSender();
764
775
 
@@ -907,29 +918,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
907
918
  }
908
919
 
909
920
  /**
910
- * Handle detection of a duplicate proposal (equivocation).
911
- * Emits a slash event when a proposer sends multiple proposals for the same position.
921
+ * Handle detection of a second proposal at the same position. Marks the slot as equivocated and clears pending
922
+ * bad-attestation offenses for it, but does not slash: p2p counts payloads per position, not per signer, so the
923
+ * reported proposer may be an honest validator whose proposal followed another signer's. The slasher's
924
+ * BroadcastedProposalWatcher attributes DUPLICATE_PROPOSAL per signer once the slot closes.
912
925
  */
913
926
  private handleDuplicateProposal(info: DuplicateProposalInfo): void {
914
927
  const { slot, proposer, type } = info;
915
928
  this.proposalHandler.markProposalEquivocation(slot);
916
929
 
917
- this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
918
- proposer: proposer.toString(),
919
- slot,
920
- type,
921
- amount: this.config.slashDuplicateProposalPenalty,
922
- offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
923
- });
924
-
925
- this.emit(WANT_TO_SLASH_EVENT, [
926
- {
927
- validator: proposer,
928
- amount: this.config.slashDuplicateProposalPenalty,
929
- offenseType: OffenseType.DUPLICATE_PROPOSAL,
930
- epochOrSlot: BigInt(slot),
931
- },
932
- ]);
930
+ this.log.info(
931
+ `Marked slot ${slot} as equivocated after a duplicate ${type} proposal (slasher watcher attributes the offense)`,
932
+ { proposer: proposer.toString(), slot, type },
933
+ );
933
934
 
934
935
  this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
935
936
  {
@@ -1074,7 +1075,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
1074
1075
  checkpointNumber: CheckpointNumber,
1075
1076
  ): Promise<CheckpointAttestation[]> {
1076
1077
  const slot = proposal.slotNumber;
1077
- const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
1078
+ // Our own proposal resolved this committee already, so it can only be unstable after an L1 reorg. Throw rather than
1079
+ // return no attestations, so the caller cannot mistake it for a committee we are not on.
1080
+ const membership = requireStableCommittee(
1081
+ await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses()),
1082
+ );
1083
+ const inCommittee = membership.state === 'members' ? membership.inCommittee : [];
1078
1084
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
1079
1085
  const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
1080
1086