@aztec/validator-client 0.0.1-commit.993d52e → 0.0.1-commit.9a89641

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