@aztec/validator-client 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928

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