@aztec/validator-client 0.0.1-commit.4d3c002 → 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.
@@ -4,10 +4,16 @@ import { type Blob, encodeCheckpointBlobDataFromBlocks, getBlobsPerL1Block } fro
4
4
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
5
5
  import type { EpochCache } from '@aztec/epoch-cache';
6
6
  import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
7
- import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
7
+ import {
8
+ BlockNumber,
9
+ CheckpointNumber,
10
+ type CheckpointProposalHash,
11
+ SlotNumber,
12
+ } from '@aztec/foundation/branded-types';
8
13
  import { pick } from '@aztec/foundation/collection';
9
14
  import { Fr } from '@aztec/foundation/curves/bn254';
10
15
  import { TimeoutError } from '@aztec/foundation/error';
16
+ import { FifoSet } from '@aztec/foundation/fifo-set';
11
17
  import type { LogData } from '@aztec/foundation/log';
12
18
  import { createLogger } from '@aztec/foundation/log';
13
19
  import { retryUntil } from '@aztec/foundation/retry';
@@ -15,8 +21,9 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
15
21
  import type { P2P, PeerId } from '@aztec/p2p';
16
22
  import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
17
23
  import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
18
- import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
19
- import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
24
+ import type { CheckpointReexecutionTracker, ReexecutionOutcome } from '@aztec/stdlib/checkpoint';
25
+ import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
26
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
20
27
  import { Gas } from '@aztec/stdlib/gas';
21
28
  import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
22
29
  import {
@@ -25,6 +32,7 @@ import {
25
32
  computeInHashFromL1ToL2Messages,
26
33
  } from '@aztec/stdlib/messaging';
27
34
  import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore } from '@aztec/stdlib/p2p';
35
+ import type { ConsensusTimetable } from '@aztec/stdlib/timetable';
28
36
  import { MerkleTreeId } from '@aztec/stdlib/trees';
29
37
  import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
30
38
  import {
@@ -40,9 +48,9 @@ import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
40
48
  import type { ValidatorMetrics } from './metrics.js';
41
49
 
42
50
  export type BlockProposalValidationFailureReason =
51
+ | 'invalid_signature'
43
52
  | 'invalid_proposal'
44
53
  | 'parent_block_not_found'
45
- | 'block_source_not_synced'
46
54
  | 'parent_block_wrong_slot'
47
55
  | 'in_hash_mismatch'
48
56
  | 'global_variables_mismatch'
@@ -52,6 +60,8 @@ export type BlockProposalValidationFailureReason =
52
60
  | 'failed_txs'
53
61
  | 'initial_state_mismatch'
54
62
  | 'timeout'
63
+ | 'block_proposal_beyond_checkpoint'
64
+ | 'checkpoint_proposal_equivocation'
55
65
  | 'unknown_error';
56
66
 
57
67
  type ReexecuteTransactionsResult = {
@@ -76,29 +86,144 @@ export type BlockProposalValidationFailureResult = {
76
86
 
77
87
  export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
78
88
 
79
- export type CheckpointProposalValidationResult = { isValid: true } | { isValid: false; reason: string };
89
+ export type CheckpointProposalValidationFailureReason =
90
+ | 'invalid_signature'
91
+ | 'invalid_fee_asset_price_modifier'
92
+ | 'last_block_not_found'
93
+ | 'block_fetch_error'
94
+ | 'checkpoint_already_published'
95
+ | 'no_blocks_for_slot'
96
+ | 'last_block_archive_mismatch'
97
+ | 'too_many_blocks_in_checkpoint'
98
+ | 'checkpoint_header_mismatch'
99
+ | 'archive_mismatch'
100
+ | 'out_hash_mismatch'
101
+ | 'checkpoint_validation_failed';
102
+
103
+ /**
104
+ * Mapping from a checkpoint-proposal validation failure reason to the tracker outcome that
105
+ * `handleCheckpointProposal` should record. `undefined` means do not record (signature
106
+ * couldn't be verified, or the checkpoint is already on L1 so the question is moot).
107
+ */
108
+ /* eslint-disable camelcase */
109
+ const CHECKPOINT_VALIDATION_REASON_TO_OUTCOME: Record<
110
+ CheckpointProposalValidationFailureReason,
111
+ ReexecutionOutcome | undefined
112
+ > = {
113
+ invalid_signature: undefined,
114
+ invalid_fee_asset_price_modifier: 'invalid',
115
+ checkpoint_already_published: undefined,
116
+ last_block_not_found: 'unvalidated',
117
+ block_fetch_error: 'unvalidated',
118
+ no_blocks_for_slot: 'unvalidated',
119
+ last_block_archive_mismatch: 'invalid',
120
+ too_many_blocks_in_checkpoint: 'invalid',
121
+ checkpoint_header_mismatch: 'invalid',
122
+ archive_mismatch: 'invalid',
123
+ out_hash_mismatch: 'invalid',
124
+ checkpoint_validation_failed: 'invalid',
125
+ };
126
+
127
+ export type CheckpointProposalValidationSuccessResult = {
128
+ isValid: true;
129
+ checkpointNumber: CheckpointNumber;
130
+ };
131
+
132
+ export type CheckpointProposalValidationFailureResult = {
133
+ isValid: false;
134
+ reason: CheckpointProposalValidationFailureReason;
135
+ checkpointNumber?: CheckpointNumber;
136
+ };
137
+
138
+ export type CheckpointProposalValidationResult =
139
+ | CheckpointProposalValidationSuccessResult
140
+ | CheckpointProposalValidationFailureResult;
141
+
142
+ export type CheckpointProposalValidationFailureCallback = (
143
+ proposal: CheckpointProposalCore,
144
+ result: CheckpointProposalValidationFailureResult,
145
+ proposalInfo: LogData,
146
+ ) => void | Promise<void>;
80
147
 
81
148
  type CheckpointComputationResult =
82
149
  | { checkpointNumber: CheckpointNumber; reason?: undefined }
83
150
  | { checkpointNumber?: undefined; reason: 'invalid_proposal' | 'global_variables_mismatch' };
84
151
 
85
- /** Handles block and checkpoint proposals for both validator and non-validator nodes. */
152
+ type BlockProposalSlotValidationResult =
153
+ | { isValid: true }
154
+ | { isValid: false; reason: 'block_proposal_beyond_checkpoint' | 'checkpoint_proposal_equivocation' };
155
+
156
+ const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
157
+
158
+ /** Block-proposal validation failures that constitute a slashable invalid-block offense. */
159
+ export const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
160
+ 'state_mismatch',
161
+ 'failed_txs',
162
+ 'global_variables_mismatch',
163
+ 'invalid_proposal',
164
+ 'parent_block_wrong_slot',
165
+ 'in_hash_mismatch',
166
+ ];
167
+
168
+ /** Checkpoint-proposal validation failures that constitute a slashable invalid-checkpoint offense. */
169
+ export const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT: Record<
170
+ CheckpointProposalValidationFailureReason,
171
+ boolean
172
+ > = {
173
+ // enabled
174
+ ['invalid_fee_asset_price_modifier']: true,
175
+ ['checkpoint_header_mismatch']: true,
176
+ // These late mismatches should normally be caught by earlier checks, but if reached after validating the local
177
+ // checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
178
+ ['archive_mismatch']: true,
179
+ ['out_hash_mismatch']: true,
180
+ ['no_blocks_for_slot']: true,
181
+ ['too_many_blocks_in_checkpoint']: true,
182
+ ['checkpoint_validation_failed']: true,
183
+ ['last_block_archive_mismatch']: true,
184
+
185
+ // disabled
186
+ ['invalid_signature']: false,
187
+ ['last_block_not_found']: false,
188
+ ['block_fetch_error']: false,
189
+ ['checkpoint_already_published']: false,
190
+ };
191
+
192
+ /**
193
+ * Handles block and checkpoint proposals for both validator and non-validator nodes. Also tracks which slots
194
+ * had a slashable invalid proposal or a proposal equivocation, exposing them via the
195
+ * `InvalidProposalSlotSource` interface consumed by the attested-invalid-proposal slashing watcher. The
196
+ * tracking is populated as a side effect of validating/re-executing proposals, so any node that re-executes
197
+ * proposals (the default) can serve it — not only validators.
198
+ */
86
199
  export class ProposalHandler {
87
200
  public readonly tracer: Tracer;
88
201
 
89
- /** Cached last checkpoint validation result to avoid double-validation on validator nodes. */
202
+ /** Cached last checkpoint validation result to avoid double-validation on validator nodes.
203
+ * Keyed by signed-payload hash so two proposals at the same (slot, archive) but with a
204
+ * different `feeAssetPriceModifier` (or any other signed field) are validated independently. */
90
205
  private lastCheckpointValidationResult?: {
91
- archive: Fr;
92
- slotNumber: SlotNumber;
206
+ payloadHash: CheckpointProposalHash;
93
207
  result: CheckpointProposalValidationResult;
94
208
  };
95
209
 
96
210
  /** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */
97
- private archiver?: Pick<Archiver, 'setProposedCheckpoint' | 'getL1Constants'>;
211
+ private archiver?: Pick<Archiver, 'addProposedCheckpoint' | 'getProposedCheckpointData'>;
98
212
 
99
213
  /** Returns current validator addresses for own-proposal detection. Set via register(). */
100
214
  private getOwnValidatorAddresses?: () => string[];
101
215
 
216
+ /** P2P proposal pool access for deciding when retained proposals should block archiver processing. */
217
+ private p2pClient?: Pick<P2P, 'getProposalsForSlot'>;
218
+
219
+ private checkpointProposalValidationFailureCallback?: CheckpointProposalValidationFailureCallback;
220
+
221
+ /** Slots at which a slashable invalid block or checkpoint proposal was observed. */
222
+ private readonly slotsWithInvalidProposals = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
223
+
224
+ /** Slots at which a proposal equivocation was observed; suppresses attested-to-invalid-proposal slashing. */
225
+ private readonly slotsWithProposalEquivocation = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
226
+
102
227
  constructor(
103
228
  private checkpointsBuilder: FullNodeCheckpointsBuilder,
104
229
  private worldState: WorldStateSynchronizer,
@@ -107,8 +232,10 @@ export class ProposalHandler {
107
232
  private txProvider: ITxProvider,
108
233
  private blockProposalValidator: BlockProposalValidator,
109
234
  private epochCache: EpochCache,
235
+ private timetable: ConsensusTimetable,
110
236
  private config: ValidatorClientFullConfig,
111
237
  private blobClient: BlobClientInterface,
238
+ private reexecutionTracker: CheckpointReexecutionTracker,
112
239
  private metrics?: ValidatorMetrics,
113
240
  private dateProvider: DateProvider = new DateProvider(),
114
241
  telemetry: TelemetryClient = getTelemetryClient(),
@@ -120,8 +247,52 @@ export class ProposalHandler {
120
247
  this.tracer = telemetry.getTracer('ProposalHandler');
121
248
  }
122
249
 
250
+ public updateConfig(config: Partial<ValidatorClientFullConfig>): void {
251
+ this.config = { ...this.config, ...config };
252
+ }
253
+
254
+ public setCheckpointProposalValidationFailureCallback(callback?: CheckpointProposalValidationFailureCallback): void {
255
+ this.checkpointProposalValidationFailureCallback = callback;
256
+ }
257
+
258
+ /**
259
+ * Records the proposer's own checkpoint proposal as a `valid` outcome in the re-execution
260
+ * tracker. Without this, the node's own checkpoint proposals never flow through
261
+ * `handleCheckpointProposal` (proposers don't validate their own proposals), so its sentinel
262
+ * sees no outcome for slots where it was the proposer and reports itself as inactive.
263
+ *
264
+ * `archive` should be the locally-computed archive (NOT the broadcast archive, which may have
265
+ * been deliberately corrupted in tests via `broadcastInvalidBlockProposal` /
266
+ * `broadcastInvalidCheckpointProposalOnly`). Recording the local archive correctly models the
267
+ * proposer's own view of its own work.
268
+ */
269
+ public recordOwnCheckpointProposalAsValid(slot: SlotNumber, archive: Fr, checkpointNumber: CheckpointNumber): void {
270
+ this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
271
+ }
272
+
273
+ /** Whether a slashable invalid block or checkpoint proposal was observed at the given slot (InvalidProposalSlotSource). */
274
+ public hasInvalidProposals(slotNumber: SlotNumber): boolean {
275
+ return this.slotsWithInvalidProposals.has(slotNumber);
276
+ }
277
+
278
+ /** Whether a proposal equivocation was observed at the given slot (InvalidProposalSlotSource). */
279
+ public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
280
+ return this.slotsWithProposalEquivocation.has(slotNumber);
281
+ }
282
+
283
+ /** Records a slot as having a slashable invalid proposal, for offense observers (sentinel/slasher watchers). */
284
+ public markInvalidProposalSlot(slotNumber: SlotNumber): void {
285
+ this.slotsWithInvalidProposals.add(slotNumber);
286
+ }
287
+
288
+ /** Records a slot as having a proposal equivocation, which suppresses attested-to-invalid-proposal slashing. */
289
+ public markProposalEquivocation(slotNumber: SlotNumber): void {
290
+ this.slotsWithProposalEquivocation.add(slotNumber);
291
+ }
292
+
123
293
  /**
124
294
  * Registers handlers for block and checkpoint proposals on the p2p client.
295
+ * Records the p2p client so validation can inspect retained proposals.
125
296
  * Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
126
297
  * The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
127
298
  * @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
@@ -130,9 +301,10 @@ export class ProposalHandler {
130
301
  register(
131
302
  p2pClient: P2P,
132
303
  shouldReexecute: boolean,
133
- archiver?: Pick<Archiver, 'setProposedCheckpoint' | 'getL1Constants'>,
304
+ archiver?: Pick<Archiver, 'addProposedCheckpoint' | 'getProposedCheckpointData'>,
134
305
  getOwnValidatorAddresses?: () => string[],
135
306
  ): ProposalHandler {
307
+ this.p2pClient = p2pClient;
136
308
  this.archiver = archiver;
137
309
  this.getOwnValidatorAddresses = getOwnValidatorAddresses;
138
310
 
@@ -153,6 +325,18 @@ export class ProposalHandler {
153
325
  });
154
326
  return true;
155
327
  } else {
328
+ // Track invalid proposals / equivocations so offense observers (the attested-invalid-proposal
329
+ // watcher) work on non-validator nodes too. Validators populate these via their own handlers.
330
+ // Skip invalid-proposal marking while the escape hatch is open, matching the validator path,
331
+ // which intentionally disables invalid-block slashing then.
332
+ if (result.reason === 'checkpoint_proposal_equivocation') {
333
+ this.markProposalEquivocation(slotNumber);
334
+ } else if (
335
+ SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(result.reason) &&
336
+ !(await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber))
337
+ ) {
338
+ this.markInvalidProposalSlot(slotNumber);
339
+ }
156
340
  this.log.warn(
157
341
  `Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`,
158
342
  { blockNumber: result.blockNumber, slotNumber, reason: result.reason },
@@ -167,6 +351,11 @@ export class ProposalHandler {
167
351
 
168
352
  p2pClient.registerBlockProposalHandler(blockHandler);
169
353
 
354
+ // p2p detects duplicate (equivocated) proposals without routing them through the handlers above, so mark
355
+ // the slot as equivocated here. This suppresses false-positive attested-to-invalid-proposal slashing on
356
+ // non-validator offense collectors. Validators overwrite this with their own richer handler.
357
+ p2pClient.registerDuplicateProposalCallback(info => this.markProposalEquivocation(info.slot));
358
+
170
359
  // All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
171
360
  // Runs for all nodes (validators and non-validators). Validators get the cached result in the
172
361
  // validator-specific callback (attestToCheckpointProposal) which runs after this one.
@@ -175,28 +364,58 @@ export class ProposalHandler {
175
364
  _sender: PeerId,
176
365
  ): Promise<CheckpointAttestation[] | undefined> => {
177
366
  try {
367
+ const pipeliningTimer = new Timer();
178
368
  const proposalInfo: LogData = {
179
369
  slot: proposal.slotNumber,
180
370
  archive: proposal.archive.toString(),
181
371
  proposer: proposal.getSender()?.toString(),
182
372
  };
183
373
 
184
- // For own proposals, skip validation — the proposer already built and validated the checkpoint
374
+ if (this.config.skipCheckpointProposalValidation) {
375
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
376
+ return undefined;
377
+ }
378
+
379
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
380
+ this.log.warn(
381
+ `Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`,
382
+ proposalInfo,
383
+ );
384
+ return undefined;
385
+ }
386
+
387
+ // A proposal is "own" when it was signed by a validator key this node also owns. The true local
388
+ // proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
389
+ // proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
390
+ // shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
391
+ // nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
392
+ // proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
185
393
  const proposer = proposal.getSender();
186
394
  const ownAddresses = this.getOwnValidatorAddresses?.();
187
395
  const isOwnProposal = proposer && ownAddresses?.some(addr => addr === proposer.toString());
188
396
 
189
397
  if (isOwnProposal) {
190
- this.log.debug(`Skipping validation for own checkpoint proposal at slot ${proposal.slotNumber}`);
191
- if (this.archiver && this.epochCache.isProposerPipeliningEnabled()) {
192
- await this.setProposedCheckpointFromBlocks(proposal);
398
+ const existing = await this.archiver?.getProposedCheckpointData({ slot: proposal.slotNumber });
399
+ if (existing?.archive.root.equals(proposal.archive)) {
400
+ this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
401
+ return undefined;
193
402
  }
194
- return undefined;
195
403
  }
196
404
 
197
405
  const result = await this.handleCheckpointProposal(proposal, proposalInfo);
198
- if (result.isValid && this.archiver && this.epochCache.isProposerPipeliningEnabled()) {
199
- await this.setProposedCheckpointFromValidation(proposal);
406
+ if (!result.isValid) {
407
+ // Track invalid checkpoint proposals so offense observers (the attested-invalid-proposal watcher)
408
+ // work on non-validator nodes too. This handler runs for all nodes; validators also mark via the
409
+ // failure callback below (idempotent).
410
+ if (SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
411
+ this.markInvalidProposalSlot(proposal.slotNumber);
412
+ }
413
+ await this.checkpointProposalValidationFailureCallback?.(proposal, result, proposalInfo);
414
+ } else if (this.archiver) {
415
+ const set = await this.setProposedCheckpoint(proposal);
416
+ if (set) {
417
+ this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
418
+ }
200
419
  }
201
420
  } catch (err) {
202
421
  this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, { err });
@@ -216,12 +435,11 @@ export class ProposalHandler {
216
435
  ): Promise<BlockProposalValidationResult> {
217
436
  const slotNumber = proposal.slotNumber;
218
437
  const proposer = proposal.getSender();
219
- const config = this.checkpointsBuilder.getConfig();
220
438
 
221
439
  // Reject proposals with invalid signatures
222
440
  if (!proposer) {
223
441
  this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
224
- return { isValid: false, reason: 'invalid_proposal' };
442
+ return { isValid: false, reason: 'invalid_signature' };
225
443
  }
226
444
 
227
445
  const proposalInfo = {
@@ -244,21 +462,20 @@ export class ProposalHandler {
244
462
  return { isValid: false, reason: 'invalid_proposal' };
245
463
  }
246
464
 
247
- // Ensure the block source is synced before checking for existing blocks,
248
- // since a proposed checkpoint prune may remove blocks we'd otherwise find.
249
- // This affects mostly the block_number_already_exists check, since a pending
250
- // checkpoint prune could remove a block that would conflict with this proposal.
251
- // When pipelining is enabled, the proposer builds ahead of L1 submission, so the
252
- // block source won't have synced to the proposed slot yet. Skip the sync wait to
253
- // avoid eating into the attestation window.
254
- if (!this.epochCache.isProposerPipeliningEnabled()) {
255
- const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
256
- if (!blockSourceSync) {
257
- this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
258
- return { isValid: false, reason: 'block_source_not_synced' };
259
- }
465
+ const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
466
+ if (!retainedSlotValidation.isValid) {
467
+ this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
468
+ ...proposalInfo,
469
+ indexWithinCheckpoint: proposal.indexWithinCheckpoint,
470
+ reason: retainedSlotValidation.reason,
471
+ });
472
+ return { isValid: false, blockNumber: proposal.blockNumber, reason: retainedSlotValidation.reason };
260
473
  }
261
474
 
475
+ // The proposer builds ahead of L1 submission under pipelining, so the block source won't have
476
+ // synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
477
+ // eating into the attestation window.
478
+
262
479
  // Check that the parent proposal is a block we know, otherwise reexecution would fail.
263
480
  // If we don't find it immediately, we keep retrying for a while; it may be we still
264
481
  // need to process other block proposals to get to it.
@@ -285,8 +502,12 @@ export class ProposalHandler {
285
502
  : BlockNumber(parentBlock.header.getBlockNumber() + 1);
286
503
  proposalInfo.blockNumber = blockNumber;
287
504
 
288
- // Check that this block number does not exist already
289
- const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
505
+ // Check that this block number does not exist already. During a reorg the archiver can still hold a
506
+ // stale block at this number (a different archive, about to be pruned) while the proposal carries the
507
+ // rebuilt replacement; resolveExistingBlockAtNumber waits for the local prune in that case so the
508
+ // rebuilt block is processed in time to attest, rather than being permanently dropped on a bare
509
+ // number collision.
510
+ const existingBlock = await this.resolveExistingBlockAtNumber(blockNumber, proposal.archive, slotNumber);
290
511
  if (existingBlock) {
291
512
  this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
292
513
  return { isValid: false, blockNumber, reason: 'block_number_already_exists' };
@@ -296,9 +517,12 @@ export class ProposalHandler {
296
517
  // and we do it even if we don't plan to re-execute the txs, so that we have them if another node needs them.
297
518
  const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
298
519
  pinnedPeer: proposalSender,
299
- deadline: this.getReexecutionDeadline(slotNumber, config),
520
+ deadline: this.getReexecutionDeadline(slotNumber),
300
521
  });
301
522
 
523
+ // Record the tx-collection outcome on the re-execution tracker
524
+ this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
525
+
302
526
  // If reexecution is disabled, bail. We were just interested in triggering tx collection.
303
527
  if (!shouldReexecute) {
304
528
  this.log.info(
@@ -335,11 +559,18 @@ export class ProposalHandler {
335
559
  return { isValid: false, blockNumber, reason: 'txs_not_available' };
336
560
  }
337
561
 
338
- // Collect the out hashes of all the checkpoints before this one in the same epoch
562
+ // Collect the out hashes of all the checkpoints before this one in the same epoch.
563
+ // Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
564
+ // yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
339
565
  const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
340
- const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
341
- .filter(c => c.checkpointNumber < checkpointNumber)
342
- .map(c => c.checkpointOutHash);
566
+ const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
567
+ blockSource: this.blockSource,
568
+ epoch,
569
+ checkpointNumber,
570
+ l1Constants: this.epochCache.getL1Constants(),
571
+ pipeliningEnabled: true,
572
+ log: this.log,
573
+ });
343
574
 
344
575
  // Try re-executing the transactions in the proposal if needed
345
576
  let reexecutionResult;
@@ -360,7 +591,7 @@ export class ProposalHandler {
360
591
  }
361
592
 
362
593
  // If we succeeded, push this block into the archiver (unless disabled)
363
- if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
594
+ if (reexecutionResult?.block && !this.config.skipPushProposedBlocksToArchiver) {
364
595
  await this.blockSource.addBlock(reexecutionResult.block);
365
596
  }
366
597
 
@@ -372,29 +603,47 @@ export class ProposalHandler {
372
603
  return { isValid: true, blockNumber, reexecutionResult };
373
604
  }
374
605
 
606
+ private async validateNewBlockInSlot(blockProposal: BlockProposal): Promise<BlockProposalSlotValidationResult> {
607
+ if (!this.p2pClient) {
608
+ return { isValid: true };
609
+ }
610
+
611
+ const { blockProposals, checkpointProposals } = await this.p2pClient.getProposalsForSlot(blockProposal.slotNumber);
612
+
613
+ if (checkpointProposals.length === 0) {
614
+ return { isValid: true };
615
+ } else if (checkpointProposals.length > 1) {
616
+ return { isValid: false, reason: 'checkpoint_proposal_equivocation' };
617
+ } else {
618
+ const checkpointProposal = checkpointProposals[0];
619
+ const terminalBlock = blockProposals.find(block => block.archive.equals(checkpointProposal.archive));
620
+ return terminalBlock !== undefined && blockProposal.indexWithinCheckpoint > terminalBlock.indexWithinCheckpoint
621
+ ? { isValid: false, reason: 'block_proposal_beyond_checkpoint' }
622
+ : { isValid: true };
623
+ }
624
+ }
625
+
375
626
  private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
376
627
  const parentArchive = proposal.blockHeader.lastArchive.root;
377
- const slot = proposal.slotNumber;
378
- const config = this.checkpointsBuilder.getConfig();
379
628
  const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
380
629
 
381
630
  if (parentArchive.equals(genesisArchiveRoot)) {
382
631
  return 'genesis';
383
632
  }
384
633
 
385
- const deadline = this.getReexecutionDeadline(slot, config);
386
- const currentTime = this.dateProvider.now();
387
- const timeoutDurationMs = deadline.getTime() - currentTime;
634
+ const deadline = this.getReexecutionDeadline(proposal.slotNumber);
635
+ const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
388
636
 
389
637
  try {
390
638
  return (
391
- (await this.blockSource.getBlockDataByArchive(parentArchive)) ??
639
+ (await this.blockSource.getBlockData({ archive: parentArchive })) ??
392
640
  (timeoutDurationMs <= 0
393
641
  ? undefined
394
642
  : await retryUntil(
395
- () => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
643
+ () =>
644
+ this.blockSource.syncImmediate().then(() => this.blockSource.getBlockData({ archive: parentArchive })),
396
645
  'force archiver sync',
397
- timeoutDurationMs / 1000,
646
+ { deadline, dateProvider: this.dateProvider },
398
647
  0.5,
399
648
  ))
400
649
  );
@@ -408,6 +657,63 @@ export class ProposalHandler {
408
657
  }
409
658
  }
410
659
 
660
+ /**
661
+ * Resolves whether a block genuinely already exists at `blockNumber`. Returns the existing block only if
662
+ * it is a true duplicate of the proposal (matching archive). During a reorg the archiver can still hold a
663
+ * stale fork at this number (different archive) that is about to be pruned; in that case this forces L1
664
+ * sync and waits, bounded by the re-execution deadline, for the prune to land, then returns `undefined` so
665
+ * the rebuilt block proposal can be processed in time to attest. If the prune does not complete before the
666
+ * deadline it returns the stale block, so the caller falls back to the safe `block_number_already_exists`
667
+ * rejection.
668
+ */
669
+ private async resolveExistingBlockAtNumber(
670
+ blockNumber: BlockNumber,
671
+ proposalArchive: Fr,
672
+ slotNumber: SlotNumber,
673
+ ): Promise<BlockData | undefined> {
674
+ const existingBlock = await this.blockSource.getBlockData({ number: blockNumber });
675
+ if (!existingBlock || existingBlock.archive.root.equals(proposalArchive)) {
676
+ return existingBlock;
677
+ }
678
+
679
+ // A different block already occupies this number: it may be a stale fork being pruned during a reorg, not a
680
+ // genuine duplicate. Wait for the local prune rather than permanently rejecting the proposal.
681
+ const deadline = this.getReexecutionDeadline(slotNumber);
682
+ if (deadline.getTime() - this.dateProvider.now() <= 0) {
683
+ return existingBlock;
684
+ }
685
+
686
+ this.log.warn(`Block number ${blockNumber} already exists, awaiting potential prune`, {
687
+ blockNumber,
688
+ existingArchive: existingBlock.archive.root.toString(),
689
+ proposalArchive: proposalArchive.toString(),
690
+ });
691
+
692
+ try {
693
+ const { block } = await retryUntil(
694
+ async () => {
695
+ await this.blockSource.syncImmediate();
696
+ const block = await this.blockSource.getBlockData({ number: blockNumber });
697
+ // Resolve once the existing block is gone (pruned) or has been replaced by one matching the
698
+ // proposal — the same condition as the early return above. A matching block is returned so the
699
+ // caller still treats it as a genuine duplicate; an `undefined` (pruned) block lets the proposal
700
+ // be processed. Wrap in an object so the `undefined` case is still a truthy retry result.
701
+ return block === undefined || block.archive.root.equals(proposalArchive) ? { block } : undefined;
702
+ },
703
+ `prune of stale block ${blockNumber}`,
704
+ { deadline, dateProvider: this.dateProvider },
705
+ 0.5,
706
+ );
707
+ return block;
708
+ } catch (err) {
709
+ if (err instanceof TimeoutError) {
710
+ this.log.warn(`Timed out waiting for stale block ${blockNumber} to be pruned`, { blockNumber });
711
+ return existingBlock;
712
+ }
713
+ throw err;
714
+ }
715
+ }
716
+
411
717
  private computeCheckpointNumber(
412
718
  proposal: BlockProposal,
413
719
  parentBlock: 'genesis' | BlockData,
@@ -531,45 +837,14 @@ export class ProposalHandler {
531
837
  return undefined;
532
838
  }
533
839
 
534
- private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
535
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
536
- return new Date(nextSlotTimestampSeconds * 1000);
537
- }
538
-
539
- /** Waits for the block source to sync L1 data up to at least the slot before the given one. */
540
- private async waitForBlockSourceSync(slot: SlotNumber): Promise<boolean> {
541
- const deadline = this.getReexecutionDeadline(slot, this.checkpointsBuilder.getConfig());
542
- const timeoutMs = deadline.getTime() - this.dateProvider.now();
543
- if (slot === 0) {
544
- return true;
545
- }
546
-
547
- // Make a quick check before triggering an archiver sync
548
- const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
549
- if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
550
- return true;
551
- }
552
-
553
- try {
554
- // Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
555
- return await retryUntil(
556
- async () => {
557
- await this.blockSource.syncImmediate();
558
- const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
559
- return syncedSlot !== undefined && syncedSlot + 1 >= slot;
560
- },
561
- 'wait for block source sync',
562
- timeoutMs / 1000,
563
- 0.5,
564
- );
565
- } catch (err) {
566
- if (err instanceof TimeoutError) {
567
- this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
568
- return false;
569
- } else {
570
- throw err;
571
- }
572
- }
840
+ /**
841
+ * Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
842
+ * the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
843
+ * checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
844
+ * next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
845
+ */
846
+ private getReexecutionDeadline(slotNumber: SlotNumber): Date {
847
+ return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
573
848
  }
574
849
 
575
850
  private getReexecuteFailureReason(err: any): BlockProposalValidationFailureReason {
@@ -601,7 +876,7 @@ export class ProposalHandler {
601
876
  // If we do not have all of the transactions, then we should fail
602
877
  if (txs.length !== txHashes.length) {
603
878
  const foundTxHashes = txs.map(tx => tx.getTxHash());
604
- const missingTxHashes = txHashes.filter(txHash => !foundTxHashes.includes(txHash));
879
+ const missingTxHashes = txHashes.filter(txHash => !foundTxHashes.some(h => h.equals(txHash)));
605
880
  throw new TransactionsNotAvailableError(missingTxHashes);
606
881
  }
607
882
 
@@ -649,7 +924,7 @@ export class ProposalHandler {
649
924
  );
650
925
 
651
926
  // Build the new block
652
- const deadline = this.getReexecutionDeadline(slot, config);
927
+ const deadline = this.getReexecutionDeadline(slot);
653
928
  const maxBlockGas =
654
929
  this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined
655
930
  ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity)
@@ -722,36 +997,46 @@ export class ProposalHandler {
722
997
  proposalInfo: LogData,
723
998
  ): Promise<CheckpointProposalValidationResult> {
724
999
  const slot = proposal.slotNumber;
1000
+ const payloadHash = proposal.getPayloadHash();
725
1001
 
726
- // Check cache: same archive+slot means we already validated this proposal
727
- if (
728
- this.lastCheckpointValidationResult &&
729
- this.lastCheckpointValidationResult.archive.equals(proposal.archive) &&
730
- this.lastCheckpointValidationResult.slotNumber === slot
731
- ) {
1002
+ // Check cache: same signed-payload hash means we already validated this exact proposal.
1003
+ if (this.lastCheckpointValidationResult && this.lastCheckpointValidationResult.payloadHash === payloadHash) {
732
1004
  this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
733
1005
  return this.lastCheckpointValidationResult.result;
734
1006
  }
735
1007
 
736
1008
  const proposer = proposal.getSender();
1009
+ let result: CheckpointProposalValidationResult;
737
1010
  if (!proposer) {
738
1011
  this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
739
- const result: CheckpointProposalValidationResult = { isValid: false, reason: 'invalid_signature' };
740
- this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
741
- return result;
742
- }
743
-
744
- if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
1012
+ result = { isValid: false as const, reason: 'invalid_signature' };
1013
+ } else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
745
1014
  this.log.warn(
746
1015
  `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`,
747
1016
  );
748
- const result: CheckpointProposalValidationResult = { isValid: false, reason: 'invalid_fee_asset_price_modifier' };
749
- this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
750
- return result;
1017
+ result = { isValid: false, reason: 'invalid_fee_asset_price_modifier' };
1018
+ } else {
1019
+ result = await this.validateCheckpointProposal(proposal, proposalInfo);
751
1020
  }
752
1021
 
753
- const result = await this.validateCheckpointProposal(proposal, proposalInfo);
754
- this.lastCheckpointValidationResult = { archive: proposal.archive, slotNumber: slot, result };
1022
+ this.lastCheckpointValidationResult = { payloadHash, result };
1023
+
1024
+ // Record the outcome on the re-execution tracker.
1025
+ const outcome = result.isValid ? ('valid' as const) : CHECKPOINT_VALIDATION_REASON_TO_OUTCOME[result.reason];
1026
+ if (outcome !== undefined) {
1027
+ this.reexecutionTracker.recordOutcome(slot, proposal.archive, outcome, result.checkpointNumber);
1028
+ }
1029
+
1030
+ // Drop tracker entries for checkpoints that have reached L1 finality.
1031
+ try {
1032
+ const tips = await this.blockSource.getL2Tips();
1033
+ const finalizedCheckpointNumber = tips.finalized.checkpoint.number;
1034
+ if (finalizedCheckpointNumber > 0) {
1035
+ this.reexecutionTracker.removeBefore(CheckpointNumber(finalizedCheckpointNumber + 1));
1036
+ }
1037
+ } catch (err) {
1038
+ this.log.error(`Error pruning reexecution tracker`, err, proposalInfo);
1039
+ }
755
1040
 
756
1041
  // Upload blobs to filestore if validation passed (fire and forget)
757
1042
  if (result.isValid) {
@@ -771,21 +1056,24 @@ export class ProposalHandler {
771
1056
  ): Promise<CheckpointProposalValidationResult> {
772
1057
  const slot = proposal.slotNumber;
773
1058
 
774
- // Timeout block syncing at the start of the next slot
775
- const config = this.checkpointsBuilder.getConfig();
776
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
777
- const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
1059
+ // Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
1060
+ // - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
1061
+ // the target slot. Keeping validation/attestation alive until then lets validators keep attesting
1062
+ // right up to the proposer's real publish cutoff.
1063
+ const deadline = this.getReexecutionDeadline(slot);
778
1064
 
779
- // Wait for last block to sync by archive
780
- let lastBlockHeader;
1065
+ // Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
1066
+ // the remaining budget is derived from the date provider; a deadline already in the past times out
1067
+ // after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
1068
+ let lastBlockData;
781
1069
  try {
782
- lastBlockHeader = await retryUntil(
1070
+ lastBlockData = await retryUntil(
783
1071
  async () => {
784
1072
  await this.blockSource.syncImmediate();
785
- return this.blockSource.getBlockHeaderByArchive(proposal.archive);
1073
+ return await this.blockSource.getBlockData({ archive: proposal.archive });
786
1074
  },
787
1075
  `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
788
- timeoutSeconds,
1076
+ { deadline, dateProvider: this.dateProvider },
789
1077
  0.5,
790
1078
  );
791
1079
  } catch (err) {
@@ -797,22 +1085,55 @@ export class ProposalHandler {
797
1085
  return { isValid: false, reason: 'block_fetch_error' };
798
1086
  }
799
1087
 
800
- if (!lastBlockHeader) {
1088
+ if (!lastBlockData) {
801
1089
  this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
802
1090
  return { isValid: false, reason: 'last_block_not_found' };
803
1091
  }
804
1092
 
1093
+ // Refuse to attest if the block's enclosing checkpoint has already been published to L1.
1094
+ const existingCheckpoint = await this.blockSource.getCheckpointData({ number: lastBlockData.checkpointNumber });
1095
+ if (existingCheckpoint) {
1096
+ this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
1097
+ ...proposalInfo,
1098
+ checkpointNumber: lastBlockData.checkpointNumber,
1099
+ });
1100
+ return {
1101
+ isValid: false,
1102
+ reason: 'checkpoint_already_published',
1103
+ checkpointNumber: lastBlockData.checkpointNumber,
1104
+ };
1105
+ }
1106
+
805
1107
  // Get all full blocks for the slot and checkpoint
806
1108
  const blocks = await this.blockSource.getBlocksForSlot(slot);
807
1109
  if (blocks.length === 0) {
808
1110
  this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
809
- return { isValid: false, reason: 'no_blocks_for_slot' };
1111
+ return { isValid: false, reason: 'no_blocks_for_slot', checkpointNumber: lastBlockData.checkpointNumber };
810
1112
  }
811
1113
 
812
1114
  // Ensure the last block for this slot matches the archive in the checkpoint proposal
813
1115
  if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
814
1116
  this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
815
- return { isValid: false, reason: 'last_block_archive_mismatch' };
1117
+ return {
1118
+ isValid: false,
1119
+ reason: 'last_block_archive_mismatch',
1120
+ checkpointNumber: lastBlockData.checkpointNumber,
1121
+ };
1122
+ }
1123
+
1124
+ // Note this condition should never trigger, since we dont process block proposals that exceed indexWithinCheckpoint
1125
+ const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
1126
+ if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
1127
+ this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
1128
+ ...proposalInfo,
1129
+ blocksInProposal: blocks.length,
1130
+ maxBlocksPerCheckpoint,
1131
+ });
1132
+ return {
1133
+ isValid: false,
1134
+ reason: 'too_many_blocks_in_checkpoint',
1135
+ checkpointNumber: lastBlockData.checkpointNumber,
1136
+ };
816
1137
  }
817
1138
 
818
1139
  this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
@@ -828,11 +1149,17 @@ export class ProposalHandler {
828
1149
  // Get L1-to-L2 messages for this checkpoint
829
1150
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
830
1151
 
831
- // Collect the out hashes of all the checkpoints before this one in the same epoch
1152
+ // Collect the out hashes of all the checkpoints before this one in the same epoch.
1153
+ // See note on the analogous block-proposal site: the helper handles pipelining lag.
832
1154
  const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
833
- const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
834
- .filter(c => c.checkpointNumber < checkpointNumber)
835
- .map(c => c.checkpointOutHash);
1155
+ const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
1156
+ blockSource: this.blockSource,
1157
+ epoch,
1158
+ checkpointNumber,
1159
+ l1Constants: this.epochCache.getL1Constants(),
1160
+ pipeliningEnabled: true,
1161
+ log: this.log,
1162
+ });
836
1163
 
837
1164
  // Fork world state at the block before the first block
838
1165
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
@@ -860,7 +1187,7 @@ export class ProposalHandler {
860
1187
  computed: computedCheckpoint.header.toInspect(),
861
1188
  proposal: proposal.checkpointHeader.toInspect(),
862
1189
  });
863
- return { isValid: false, reason: 'checkpoint_header_mismatch' };
1190
+ return { isValid: false, reason: 'checkpoint_header_mismatch', checkpointNumber };
864
1191
  }
865
1192
 
866
1193
  // Compare archive root with proposal
@@ -870,7 +1197,7 @@ export class ProposalHandler {
870
1197
  computed: computedCheckpoint.archive.root.toString(),
871
1198
  proposal: proposal.archive.toString(),
872
1199
  });
873
- return { isValid: false, reason: 'archive_mismatch' };
1200
+ return { isValid: false, reason: 'archive_mismatch', checkpointNumber };
874
1201
  }
875
1202
 
876
1203
  // Check that the accumulated epoch out hash matches the value in the proposal.
@@ -886,7 +1213,7 @@ export class ProposalHandler {
886
1213
  previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
887
1214
  ...proposalInfo,
888
1215
  });
889
- return { isValid: false, reason: 'out_hash_mismatch' };
1216
+ return { isValid: false, reason: 'out_hash_mismatch', checkpointNumber };
890
1217
  }
891
1218
 
892
1219
  // Final round of validations on the checkpoint, just in case.
@@ -900,11 +1227,12 @@ export class ProposalHandler {
900
1227
  });
901
1228
  } catch (err) {
902
1229
  this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
903
- return { isValid: false, reason: 'checkpoint_validation_failed' };
1230
+ return { isValid: false, reason: 'checkpoint_validation_failed', checkpointNumber };
904
1231
  }
905
1232
 
906
1233
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
907
- return { isValid: true };
1234
+
1235
+ return { isValid: true, checkpointNumber };
908
1236
  }
909
1237
 
910
1238
  /** Extracts checkpoint global variables from a block. */
@@ -931,7 +1259,7 @@ export class ProposalHandler {
931
1259
  /** Uploads blobs for a checkpoint to the filestore. */
932
1260
  protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
933
1261
  try {
934
- const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
1262
+ const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
935
1263
  if (!lastBlockHeader) {
936
1264
  this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
937
1265
  return;
@@ -957,23 +1285,23 @@ export class ProposalHandler {
957
1285
  }
958
1286
 
959
1287
  /**
960
- * Derives proposed checkpoint data from validated blocks and sets it on the archiver.
961
- * Used after successful validation of a foreign proposal.
962
- * Does not retry since we already waited for the block during validation.
1288
+ * Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
1289
+ * pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
1290
+ * last block to sync.
963
1291
  */
964
- private async setProposedCheckpointFromValidation(proposal: CheckpointProposalCore): Promise<void> {
1292
+ private async setProposedCheckpoint(proposal: CheckpointProposalCore): Promise<boolean> {
965
1293
  if (!this.archiver) {
966
- return;
1294
+ return false;
967
1295
  }
968
- const blockData = await this.blockSource.getBlockDataByArchive(proposal.archive);
1296
+ const blockData = await this.blockSource.getBlockData({ archive: proposal.archive });
969
1297
  if (!blockData) {
970
1298
  this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
971
1299
  archive: proposal.archive.toString(),
972
1300
  });
973
- return;
1301
+ return false;
974
1302
  }
975
1303
 
976
- await this.archiver.setProposedCheckpoint({
1304
+ await this.archiver.addProposedCheckpoint({
977
1305
  header: proposal.checkpointHeader,
978
1306
  checkpointNumber: blockData.checkpointNumber,
979
1307
  startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
@@ -981,47 +1309,6 @@ export class ProposalHandler {
981
1309
  totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
982
1310
  feeAssetPriceModifier: proposal.feeAssetPriceModifier,
983
1311
  });
984
- }
985
-
986
- /**
987
- * Sets proposed checkpoint from blocks for own proposals (skips full validation).
988
- * Retries fetching block data since the checkpoint proposal often arrives before the last block
989
- * finishes re-execution.
990
- */
991
- private async setProposedCheckpointFromBlocks(proposal: CheckpointProposalCore): Promise<void> {
992
- if (!this.archiver) {
993
- return;
994
- }
995
- let blockData = await this.blockSource.getBlockDataByArchive(proposal.archive);
996
-
997
- if (!blockData) {
998
- // The checkpoint proposal often arrives before the last block finishes re-execution.
999
- // Retry until we find the data or give up at the end of the slot.
1000
- const nextSlot = this.epochCache.getSlotNow() + 1;
1001
- const timeOfNextSlot = getTimestampForSlot(SlotNumber(nextSlot), await this.archiver.getL1Constants());
1002
- const timeoutSeconds = Math.max(1, Number(timeOfNextSlot) - Math.floor(this.dateProvider.now() / 1000));
1003
-
1004
- blockData = await retryUntil(
1005
- () => this.blockSource.getBlockDataByArchive(proposal.archive),
1006
- 'block data for own checkpoint proposal',
1007
- timeoutSeconds,
1008
- 0.25,
1009
- ).catch(() => undefined);
1010
- }
1011
-
1012
- if (blockData) {
1013
- await this.archiver.setProposedCheckpoint({
1014
- header: proposal.checkpointHeader,
1015
- checkpointNumber: blockData.checkpointNumber,
1016
- startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
1017
- blockCount: blockData.indexWithinCheckpoint + 1,
1018
- totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
1019
- feeAssetPriceModifier: proposal.feeAssetPriceModifier,
1020
- });
1021
- } else {
1022
- this.log.debug(`Block data not found for own checkpoint proposal archive, cannot set proposed checkpoint`, {
1023
- archive: proposal.archive.toString(),
1024
- });
1025
- }
1312
+ return true;
1026
1313
  }
1027
1314
  }