@aztec/validator-client 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f

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/dest/validator.js CHANGED
@@ -1,28 +1,30 @@
1
+ import { getBlobsPerL1Block } from '@aztec/blob-lib';
2
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
+ import { FifoSet } from '@aztec/foundation/fifo-set';
1
4
  import { createLogger } from '@aztec/foundation/log';
2
5
  import { RunningPromise } from '@aztec/foundation/running-promise';
3
6
  import { sleep } from '@aztec/foundation/sleep';
4
7
  import { DateProvider } from '@aztec/foundation/timer';
5
8
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
6
- import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
9
+ import { OffenseType, WANT_TO_CLEAR_SLASH_EVENT, WANT_TO_SLASH_EVENT, getOffenseTypeName } from '@aztec/slasher';
7
10
  import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
11
+ import { ConsensusTimetable } from '@aztec/stdlib/timetable';
8
12
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
9
13
  import { getTelemetryClient } from '@aztec/telemetry-client';
10
- import { createHASigner, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
14
+ import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
11
15
  import { DutyType } from '@aztec/validator-ha-signer/types';
12
16
  import { EventEmitter } from 'events';
17
+ import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
13
18
  import { ValidationService } from './duties/validation_service.js';
14
19
  import { HAKeyStore } from './key_store/ha_key_store.js';
15
20
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
16
21
  import { ValidatorMetrics } from './metrics.js';
17
- import { ProposalHandler } from './proposal_handler.js';
22
+ import { ProposalHandler, SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT, SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT } from './proposal_handler.js';
18
23
  // We maintain a set of proposers who have proposed invalid blocks.
19
24
  // Just cap the set to avoid unbounded growth.
20
25
  const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
21
- // What errors from the block proposal handler result in slashing
22
- const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
23
- 'state_mismatch',
24
- 'failed_txs'
25
- ];
26
+ const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
27
+ const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
26
28
  /**
27
29
  * Validator Client
28
30
  */ export class ValidatorClient extends EventEmitter {
@@ -30,9 +32,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
30
32
  epochCache;
31
33
  p2pClient;
32
34
  proposalHandler;
35
+ blockSource;
36
+ checkpointsBuilder;
37
+ worldState;
38
+ l1ToL2MessageSource;
33
39
  config;
34
40
  blobClient;
35
- haSigner;
41
+ slashingProtectionSigner;
36
42
  dateProvider;
37
43
  tracer;
38
44
  validationService;
@@ -46,14 +52,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
46
52
  epochCacheUpdateLoop;
47
53
  /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
48
54
  proposersOfInvalidBlocks;
55
+ invalidCheckpointProposalOffenseKeys;
56
+ oversizedProposalOffenseKeys;
57
+ badAttestationOffenseKeys;
49
58
  /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
50
- constructor(keyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
51
- super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.config = config, this.blobClient = blobClient, this.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
59
+ constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
60
+ super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = FifoSet.withLimit(MAX_PROPOSERS_OF_INVALID_BLOCKS), this.invalidCheckpointProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.oversizedProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.badAttestationOffenseKeys = FifoSet.withLimit(MAX_TRACKED_BAD_ATTESTATIONS);
52
61
  // Create child logger with fisherman prefix if in fisherman mode
53
62
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
54
63
  this.tracer = telemetry.getTracer('Validator');
55
64
  this.metrics = new ValidatorMetrics(telemetry);
56
- this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
65
+ this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
66
+ this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo)=>this.handleInvalidCheckpointProposal(proposal, result, proposalInfo));
57
67
  // Refresh epoch cache every second to trigger alert if participation in committee changes
58
68
  this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
59
69
  const myAddresses = this.getValidatorAddresses();
@@ -103,32 +113,53 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
103
113
  this.log.error(`Error updating epoch committee`, err);
104
114
  }
105
115
  }
106
- static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
116
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, reexecutionTracker, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
107
117
  const metrics = new ValidatorMetrics(telemetry);
108
- const blockProposalValidator = new BlockProposalValidator(epochCache, {
118
+ const consensusTimetable = new ConsensusTimetable({
119
+ l1Constants: epochCache.getL1Constants(),
120
+ blockDuration: config.blockDurationMs / 1000
121
+ });
122
+ const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
109
123
  txsPermitted: !config.disableTransactions,
110
- maxTxsPerBlock: config.validateMaxTxsPerBlock
124
+ maxTxsPerBlock: config.validateMaxTxsPerBlock,
125
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
126
+ skipSlotValidation: config.skipProposalSlotValidation,
127
+ signatureContext: {
128
+ chainId: config.l1ChainId,
129
+ rollupAddress: config.rollupAddress
130
+ },
131
+ clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS
111
132
  });
112
- const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
133
+ const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, consensusTimetable, config, blobClient, reexecutionTracker, metrics, dateProvider, telemetry, undefined);
113
134
  const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
114
- let validatorKeyStore = nodeKeystoreAdapter;
115
- let haSigner;
135
+ let slashingProtectionSigner;
116
136
  if (slashingProtectionDb) {
117
137
  // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
118
- const { signer } = createSignerFromSharedDb(slashingProtectionDb, config);
119
- haSigner = signer;
120
- validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
138
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
139
+ telemetryClient: telemetry,
140
+ dateProvider
141
+ }));
121
142
  } else if (config.haSigningEnabled) {
143
+ // Multi-node HA mode: use PostgreSQL-backed distributed locking.
122
144
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
123
145
  const haConfig = {
124
146
  ...config,
125
147
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
126
148
  };
127
- const { signer } = await createHASigner(haConfig);
128
- haSigner = signer;
129
- validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
130
- }
131
- const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider, telemetry);
149
+ ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
150
+ telemetryClient: telemetry,
151
+ dateProvider
152
+ }));
153
+ } else {
154
+ // Single-node mode: use LMDB-backed local signing protection.
155
+ // This prevents double-signing if the node crashes and restarts mid-proposal.
156
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
157
+ telemetryClient: telemetry,
158
+ dateProvider
159
+ }));
160
+ }
161
+ const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
162
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
132
163
  return validator;
133
164
  }
134
165
  getValidatorAddresses() {
@@ -140,6 +171,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
140
171
  signWithAddress(addr, msg, context) {
141
172
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
142
173
  }
174
+ getSignatureContext() {
175
+ return {
176
+ chainId: this.config.l1ChainId,
177
+ rollupAddress: this.config.rollupAddress
178
+ };
179
+ }
143
180
  getCoinbaseForAttestor(attestor) {
144
181
  return this.keyStore.getCoinbaseAddress(attestor);
145
182
  }
@@ -149,25 +186,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
149
186
  getConfig() {
150
187
  return this.config;
151
188
  }
189
+ hasProposalEquivocation(slotNumber) {
190
+ return this.proposalHandler.hasProposalEquivocation(slotNumber);
191
+ }
192
+ hasInvalidProposals(slotNumber) {
193
+ return this.proposalHandler.hasInvalidProposals(slotNumber);
194
+ }
152
195
  updateConfig(config) {
153
196
  this.config = {
154
197
  ...this.config,
155
198
  ...config
156
199
  };
200
+ this.proposalHandler.updateConfig(config);
157
201
  }
158
202
  reloadKeystore(newManager) {
159
- if (this.config.haSigningEnabled && !this.haSigner) {
160
- this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
161
- } else if (!this.config.haSigningEnabled && this.haSigner) {
162
- this.log.warn('HA signing was disabled via config update but the HA signer is still active. ' + 'Restart the node to fully disable HA signing.');
163
- }
164
203
  const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
165
- if (this.haSigner) {
166
- this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
167
- } else {
168
- this.keyStore = newAdapter;
169
- }
170
- this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
204
+ this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
205
+ this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
171
206
  }
172
207
  async start() {
173
208
  if (this.epochCacheUpdateLoop.isRunning()) {
@@ -200,15 +235,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
200
235
  // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
201
236
  // and processed separately via the block handler above.
202
237
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
203
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
238
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
204
239
  // Duplicate proposal handler - triggers slashing for equivocation
205
240
  this.p2pClient.registerDuplicateProposalCallback((info)=>{
206
241
  this.handleDuplicateProposal(info);
207
242
  });
243
+ // Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
244
+ this.p2pClient.registerOversizedProposalCallback((info)=>{
245
+ this.handleOversizedProposal(info);
246
+ });
208
247
  // Duplicate attestation handler - triggers slashing for attestation equivocation
209
248
  this.p2pClient.registerDuplicateAttestationCallback((info)=>{
210
249
  this.handleDuplicateAttestation(info);
211
250
  });
251
+ this.p2pClient.registerCheckpointAttestationCallback((attestation)=>{
252
+ this.handleCheckpointAttestation(attestation);
253
+ });
212
254
  const myAddresses = this.getValidatorAddresses();
213
255
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
214
256
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
@@ -248,11 +290,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
248
290
  txHashes: proposal.txHashes.map((t)=>t.toString()),
249
291
  fishermanMode: this.config.fishermanMode || false
250
292
  });
251
- // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
252
- // In fisherman mode, we always reexecute to validate proposals.
253
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
254
- const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
255
- const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
293
+ // Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
294
+ const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
256
295
  if (!validationResult.isValid) {
257
296
  const reason = validationResult.reason || 'unknown';
258
297
  this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
@@ -270,10 +309,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
270
309
  // Node issues so we can't validate
271
310
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
272
311
  }
273
- // Slash invalid block proposals (can happen even when not in committee)
274
- if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
275
- this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
312
+ if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)) {
313
+ this.log.info(`Detected invalid block proposal offense`, {
314
+ ...proposalInfo,
315
+ amount: this.config.slashBroadcastedInvalidBlockPenalty,
316
+ offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL)
317
+ });
276
318
  this.slashInvalidBlock(proposal);
319
+ this.markInvalidProposalSlot(proposal.slotNumber);
277
320
  }
278
321
  return false;
279
322
  }
@@ -295,42 +338,50 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
295
338
  * the lastBlock is extracted and processed separately via the block handler.
296
339
  * @returns Checkpoint attestations if valid, undefined otherwise
297
340
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
298
- const slotNumber = proposal.slotNumber;
341
+ const proposalSlotNumber = proposal.slotNumber;
299
342
  const proposer = proposal.getSender();
300
343
  // If escape hatch is open for this slot's epoch, do not attest.
301
- if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
302
- this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
344
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
345
+ this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
346
+ return undefined;
347
+ }
348
+ // Early-out for equivocation: refuses if we've already attested to a higher slot.
349
+ if (!this.shouldAttestToSlot(proposalSlotNumber)) {
303
350
  return undefined;
304
351
  }
305
352
  // Ignore proposals from ourselves (may happen in HA setups)
306
353
  if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
307
- this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
354
+ this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
308
355
  proposer: proposer.toString(),
309
- slotNumber
356
+ proposalSlotNumber
310
357
  });
311
358
  return undefined;
312
359
  }
313
360
  // Check that I have any address in the committee where this checkpoint will land before attesting
314
- const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
361
+ const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
315
362
  const partOfCommittee = inCommittee.length > 0;
316
363
  const proposalInfo = {
317
- slotNumber,
364
+ proposalSlotNumber,
318
365
  archive: proposal.archive.toString(),
319
366
  proposer: proposer?.toString()
320
367
  };
321
- this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
368
+ this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
322
369
  ...proposalInfo,
323
370
  fishermanMode: this.config.fishermanMode || false
324
371
  });
325
- // Validate the checkpoint proposal and upload blobs (unless skipCheckpointProposalValidation is set)
372
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
373
+ // Uses the cached result from the all-nodes callback if available (avoids double validation).
374
+ let checkpointNumber;
326
375
  if (this.config.skipCheckpointProposalValidation) {
327
- this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
376
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
377
+ checkpointNumber = CheckpointNumber(0);
328
378
  } else {
329
379
  const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
330
380
  if (!validationResult.isValid) {
331
381
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
332
382
  return undefined;
333
383
  }
384
+ checkpointNumber = validationResult.checkpointNumber;
334
385
  }
335
386
  // Check that I have any address in current committee before attesting
336
387
  // In fisherman mode, we still create attestations for validation even if not in committee
@@ -339,14 +390,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
339
390
  return undefined;
340
391
  }
341
392
  // Provided all of the above checks pass, we can attest to the proposal
342
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
393
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
343
394
  ...proposalInfo,
344
395
  inCommittee: partOfCommittee,
345
396
  fishermanMode: this.config.fishermanMode || false
346
397
  });
347
398
  this.metrics.incSuccessfulAttestations(inCommittee.length);
348
399
  // Track epoch participation per attester: count each (attester, epoch) pair at most once
349
- const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
400
+ const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
350
401
  for (const attester of inCommittee){
351
402
  const key = attester.toString();
352
403
  const lastEpoch = this.lastAttestedEpochByAttester.get(key);
@@ -371,13 +422,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
371
422
  }
372
423
  if (this.config.fishermanMode) {
373
424
  // bail out early and don't save attestations to the pool in fisherman mode
374
- this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
425
+ this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
375
426
  ...proposalInfo,
376
427
  attestors: attestors.map((a)=>a.toString())
377
428
  });
378
429
  return undefined;
379
430
  }
380
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
431
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
381
432
  }
382
433
  /**
383
434
  * Checks if we should attest to a slot based on equivocation prevention rules.
@@ -394,17 +445,44 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
394
445
  }
395
446
  return true;
396
447
  }
397
- async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
448
+ async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
398
449
  // Equivocation check: must happen right before signing to minimize the race window
399
450
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
400
451
  return undefined;
401
452
  }
402
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
453
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
403
454
  // Track the proposal we attested to (to prevent equivocation)
404
455
  this.lastAttestedProposal = proposal;
405
456
  await this.p2pClient.addOwnCheckpointAttestations(attestations);
406
457
  return attestations;
407
458
  }
459
+ /**
460
+ * Uploads blobs for a checkpoint to the filestore (fire and forget).
461
+ */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
462
+ try {
463
+ const lastBlockHeader = (await this.blockSource.getBlockData({
464
+ archive: proposal.archive
465
+ }))?.header;
466
+ if (!lastBlockHeader) {
467
+ this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
468
+ return;
469
+ }
470
+ const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
471
+ if (blocks.length === 0) {
472
+ this.log.warn(`No blocks found for blob upload`, proposalInfo);
473
+ return;
474
+ }
475
+ const blobFields = blocks.flatMap((b)=>b.toBlobFields());
476
+ const blobs = await getBlobsPerL1Block(blobFields);
477
+ await this.blobClient.sendBlobsToFilestore(blobs);
478
+ this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
479
+ ...proposalInfo,
480
+ numBlobs: blobs.length
481
+ });
482
+ } catch (err) {
483
+ this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
484
+ }
485
+ }
408
486
  slashInvalidBlock(proposal) {
409
487
  const proposer = proposal.getSender();
410
488
  // Skip if signature is invalid (shouldn't happen since we validate earlier)
@@ -412,11 +490,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
412
490
  this.log.warn(`Cannot slash proposal with invalid signature`);
413
491
  return;
414
492
  }
415
- // Trim the set if it's too big.
416
- if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
417
- // remove oldest proposer. `values` is guaranteed to be in insertion order.
418
- this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
419
- }
420
493
  this.proposersOfInvalidBlocks.add(proposer.toString());
421
494
  this.emit(WANT_TO_SLASH_EVENT, [
422
495
  {
@@ -427,17 +500,122 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
427
500
  }
428
501
  ]);
429
502
  }
503
+ handleInvalidCheckpointProposal(proposal, result, proposalInfo) {
504
+ if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
505
+ return;
506
+ }
507
+ // The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
508
+ // so we only emit the proposer slash event here.
509
+ if (this.slashInvalidCheckpointProposal(proposal)) {
510
+ this.log.info(`Detected invalid checkpoint proposal offense`, {
511
+ ...proposalInfo,
512
+ reason: result.reason,
513
+ amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
514
+ offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL)
515
+ });
516
+ }
517
+ }
518
+ slashInvalidCheckpointProposal(proposal) {
519
+ const proposer = proposal.getSender();
520
+ if (!proposer) {
521
+ this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
522
+ slotNumber: proposal.slotNumber,
523
+ archive: proposal.archive.toString()
524
+ });
525
+ return false;
526
+ }
527
+ const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
528
+ const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
529
+ if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
530
+ return false;
531
+ }
532
+ this.emit(WANT_TO_SLASH_EVENT, [
533
+ {
534
+ validator: proposer,
535
+ amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
536
+ offenseType,
537
+ epochOrSlot: BigInt(proposal.slotNumber)
538
+ }
539
+ ]);
540
+ return true;
541
+ }
542
+ markInvalidProposalSlot(slotNumber) {
543
+ this.proposalHandler.markInvalidProposalSlot(slotNumber);
544
+ }
545
+ handleCheckpointAttestation(attestation) {
546
+ const slotNumber = attestation.slotNumber;
547
+ if (!this.proposalHandler.hasInvalidProposals(slotNumber) || this.proposalHandler.hasProposalEquivocation(slotNumber)) {
548
+ return;
549
+ }
550
+ const attester = attestation.getSender();
551
+ if (!attester) {
552
+ this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
553
+ slotNumber,
554
+ archive: attestation.archive.toString()
555
+ });
556
+ return;
557
+ }
558
+ this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
559
+ }
560
+ slashAttestedToInvalidCheckpointProposal(slotNumber, attester) {
561
+ const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
562
+ if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
563
+ return;
564
+ }
565
+ this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
566
+ attester: attester.toString(),
567
+ slotNumber,
568
+ amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
569
+ offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL)
570
+ });
571
+ this.emit(WANT_TO_SLASH_EVENT, [
572
+ {
573
+ validator: attester,
574
+ amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
575
+ offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
576
+ epochOrSlot: BigInt(slotNumber)
577
+ }
578
+ ]);
579
+ }
580
+ /**
581
+ * Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
582
+ * beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
583
+ * self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
584
+ * (proposer, slot) since the p2p layer reports every oversized proposal it stores.
585
+ */ handleOversizedProposal(info) {
586
+ const { slot, proposer } = info;
587
+ const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
588
+ if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
589
+ return;
590
+ }
591
+ this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
592
+ proposer: proposer.toString(),
593
+ slot,
594
+ amount: this.config.slashBroadcastedInvalidBlockPenalty,
595
+ offenseType: getOffenseTypeName(offenseType)
596
+ });
597
+ this.emit(WANT_TO_SLASH_EVENT, [
598
+ {
599
+ validator: proposer,
600
+ amount: this.config.slashBroadcastedInvalidBlockPenalty,
601
+ offenseType,
602
+ epochOrSlot: BigInt(slot)
603
+ }
604
+ ]);
605
+ }
430
606
  /**
431
607
  * Handle detection of a duplicate proposal (equivocation).
432
608
  * Emits a slash event when a proposer sends multiple proposals for the same position.
433
609
  */ handleDuplicateProposal(info) {
434
610
  const { slot, proposer, type } = info;
435
- this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
611
+ this.proposalHandler.markProposalEquivocation(slot);
612
+ this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
436
613
  proposer: proposer.toString(),
437
614
  slot,
438
- type
615
+ type,
616
+ amount: this.config.slashDuplicateProposalPenalty,
617
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL)
439
618
  });
440
- // Emit slash event
441
619
  this.emit(WANT_TO_SLASH_EVENT, [
442
620
  {
443
621
  validator: proposer,
@@ -446,15 +624,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
446
624
  epochOrSlot: BigInt(slot)
447
625
  }
448
626
  ]);
627
+ this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
628
+ {
629
+ offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
630
+ epochOrSlot: BigInt(slot)
631
+ }
632
+ ]);
449
633
  }
450
634
  /**
451
635
  * Handle detection of a duplicate attestation (equivocation).
452
636
  * Emits a slash event when an attester signs attestations for different proposals at the same slot.
453
637
  */ handleDuplicateAttestation(info) {
454
638
  const { slot, attester } = info;
455
- this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
639
+ this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
456
640
  attester: attester.toString(),
457
- slot
641
+ slot,
642
+ amount: this.config.slashDuplicateAttestationPenalty,
643
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION)
458
644
  });
459
645
  this.emit(WANT_TO_SLASH_EVENT, [
460
646
  {
@@ -465,7 +651,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
465
651
  }
466
652
  ]);
467
653
  }
468
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
654
+ async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
469
655
  // Validate that we're not creating a proposal for an older or equal position
470
656
  if (this.lastProposedBlock) {
471
657
  const lastSlot = this.lastProposedBlock.slotNumber;
@@ -476,14 +662,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
476
662
  }
477
663
  }
478
664
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
479
- const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
665
+ const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
480
666
  ...options,
481
- broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
667
+ broadcastInvalidBlockProposal: options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal
482
668
  });
483
669
  this.lastProposedBlock = newProposal;
484
670
  return newProposal;
485
671
  }
486
- async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
672
+ async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
487
673
  // Validate that we're not creating a proposal for an older or equal slot
488
674
  if (this.lastProposedCheckpoint) {
489
675
  const lastSlot = this.lastProposedCheckpoint.slotNumber;
@@ -493,23 +679,30 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
493
679
  }
494
680
  }
495
681
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
496
- const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
682
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
497
683
  this.lastProposedCheckpoint = newProposal;
684
+ // Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
685
+ // own proposals through `handleCheckpointProposal`, so without this call the proposer's
686
+ // sentinel would see no outcome for slots it proposed and would mis-attribute itself as
687
+ // inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
688
+ // be intentionally corrupted under test-only flags); from the proposer's local-view
689
+ // perspective the work it just completed is valid by definition.
690
+ this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
498
691
  return newProposal;
499
692
  }
500
693
  async broadcastBlockProposal(proposal) {
501
694
  await this.p2pClient.broadcastProposal(proposal);
502
695
  }
503
- async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
504
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
696
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
697
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
505
698
  }
506
- async collectOwnAttestations(proposal) {
699
+ async collectOwnAttestations(proposal, checkpointNumber) {
507
700
  const slot = proposal.slotNumber;
508
701
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
509
702
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
510
703
  inCommittee
511
704
  });
512
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
705
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
513
706
  if (!attestations) {
514
707
  return [];
515
708
  }
@@ -521,7 +714,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
521
714
  });
522
715
  return attestations;
523
716
  }
524
- async collectAttestations(proposal, required, deadline) {
717
+ async collectAttestations(proposal, required, deadline, checkpointNumber) {
525
718
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
526
719
  const slot = proposal.slotNumber;
527
720
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
@@ -529,28 +722,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
529
722
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
530
723
  throw new AttestationTimeoutError(0, required, slot);
531
724
  }
532
- await this.collectOwnAttestations(proposal);
533
- const proposalId = proposal.archive.toString();
725
+ await this.collectOwnAttestations(proposal, checkpointNumber);
726
+ const proposalPayloadHash = proposal.getPayloadHash();
534
727
  const myAddresses = this.getValidatorAddresses();
535
728
  let attestations = [];
536
729
  while(true){
537
- // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
538
- // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
539
- const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
540
- if (!attestation.archive.equals(proposal.archive)) {
541
- this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
542
- attestationArchive: attestation.archive.toString(),
543
- proposalArchive: proposal.archive.toString()
544
- });
545
- return false;
546
- }
547
- return true;
548
- });
730
+ // The pool already filters by proposal payload hash; if any attestation slips through with a
731
+ // mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
732
+ // events from libp2p_service.
733
+ const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
549
734
  // Log new attestations we collected
550
735
  const oldSenders = attestations.map((attestation)=>attestation.getSender());
551
736
  for (const collected of collectedAttestations){
552
737
  const collectedSender = collected.getSender();
553
- // Skip attestations with invalid signatures
738
+ // Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
554
739
  if (!collectedSender) {
555
740
  this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
556
741
  continue;