@aztec/validator-client 0.0.1-commit.4d79d1f2d → 0.0.1-commit.4d9804df

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