@aztec/sequencer-client 0.0.1-commit.ef17749e1 → 0.0.1-commit.f1b29a41e

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 (53) hide show
  1. package/dest/client/sequencer-client.d.ts +4 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +27 -76
  4. package/dest/config.d.ts +4 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +9 -2
  7. package/dest/global_variable_builder/global_builder.d.ts +15 -9
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +29 -25
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +1 -1
  12. package/dest/publisher/config.d.ts +13 -1
  13. package/dest/publisher/config.d.ts.map +1 -1
  14. package/dest/publisher/config.js +17 -2
  15. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher-factory.js +2 -2
  18. package/dest/publisher/sequencer-publisher.d.ts +52 -25
  19. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  20. package/dest/publisher/sequencer-publisher.js +98 -42
  21. package/dest/sequencer/checkpoint_proposal_job.d.ts +33 -6
  22. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_proposal_job.js +261 -141
  24. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  25. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  26. package/dest/sequencer/checkpoint_voter.js +2 -5
  27. package/dest/sequencer/events.d.ts +2 -1
  28. package/dest/sequencer/events.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.d.ts +5 -1
  30. package/dest/sequencer/metrics.d.ts.map +1 -1
  31. package/dest/sequencer/metrics.js +11 -0
  32. package/dest/sequencer/sequencer.d.ts +19 -7
  33. package/dest/sequencer/sequencer.d.ts.map +1 -1
  34. package/dest/sequencer/sequencer.js +123 -68
  35. package/dest/sequencer/types.d.ts +2 -5
  36. package/dest/sequencer/types.d.ts.map +1 -1
  37. package/dest/test/mock_checkpoint_builder.d.ts +4 -4
  38. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  39. package/package.json +27 -28
  40. package/src/client/sequencer-client.ts +37 -101
  41. package/src/config.ts +12 -1
  42. package/src/global_variable_builder/global_builder.ts +37 -26
  43. package/src/global_variable_builder/index.ts +1 -1
  44. package/src/publisher/config.ts +32 -0
  45. package/src/publisher/sequencer-publisher-factory.ts +3 -3
  46. package/src/publisher/sequencer-publisher.ts +144 -54
  47. package/src/sequencer/checkpoint_proposal_job.ts +340 -147
  48. package/src/sequencer/checkpoint_voter.ts +1 -12
  49. package/src/sequencer/events.ts +1 -1
  50. package/src/sequencer/metrics.ts +14 -0
  51. package/src/sequencer/sequencer.ts +178 -79
  52. package/src/sequencer/types.ts +2 -5
  53. package/src/test/mock_checkpoint_builder.ts +3 -3
@@ -1,4 +1,5 @@
1
1
  import type { EpochCache } from '@aztec/epoch-cache';
2
+ import { type FeeHeader, RollupContract } from '@aztec/ethereum/contracts';
2
3
  import {
3
4
  BlockNumber,
4
5
  CheckpointNumber,
@@ -30,17 +31,22 @@ import {
30
31
  type L2BlockSource,
31
32
  MaliciousCommitteeAttestationsAndSigners,
32
33
  } from '@aztec/stdlib/block';
33
- import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
34
- import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
34
+ import { type Checkpoint, type ProposedCheckpointData, validateCheckpoint } from '@aztec/stdlib/checkpoint';
35
+ import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
35
36
  import { Gas } from '@aztec/stdlib/gas';
36
37
  import {
37
- NoValidTxsError,
38
- type PublicProcessorLimits,
38
+ type BlockBuilderOptions,
39
+ InsufficientValidTxsError,
39
40
  type ResolvedSequencerConfig,
40
41
  type WorldStateSynchronizer,
41
42
  } from '@aztec/stdlib/interfaces/server';
42
43
  import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
43
- import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
44
+ import type {
45
+ BlockProposal,
46
+ BlockProposalOptions,
47
+ CheckpointProposal,
48
+ CheckpointProposalOptions,
49
+ } from '@aztec/stdlib/p2p';
44
50
  import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
45
51
  import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
46
52
  import { type FailedTx, Tx } from '@aztec/stdlib/tx';
@@ -62,6 +68,13 @@ import { SequencerState } from './utils.js';
62
68
  /** How much time to sleep while waiting for min transactions to accumulate for a block */
63
69
  const TXS_POLLING_MS = 500;
64
70
 
71
+ /** Result from proposeCheckpoint when a checkpoint was successfully built and attested. */
72
+ type CheckpointProposalResult = {
73
+ checkpoint: Checkpoint;
74
+ attestations: CommitteeAttestationsAndSigners;
75
+ attestationsSignature: Signature;
76
+ };
77
+
65
78
  /**
66
79
  * Handles the execution of a checkpoint proposal after the initial preparation phase.
67
80
  * This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
@@ -71,9 +84,16 @@ const TXS_POLLING_MS = 500;
71
84
  export class CheckpointProposalJob implements Traceable {
72
85
  protected readonly log: Logger;
73
86
 
87
+ /** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
88
+ private pendingL1Submission: Promise<void> | undefined;
89
+
90
+ /** Fee header override computed during proposeCheckpoint, reused in enqueueCheckpointForSubmission. */
91
+ private computedForceProposedFeeHeader?: { checkpointNumber: CheckpointNumber; feeHeader: FeeHeader };
92
+
74
93
  constructor(
75
- private readonly epoch: EpochNumber,
76
- private readonly slot: SlotNumber,
94
+ private readonly slotNow: SlotNumber,
95
+ private readonly targetSlot: SlotNumber,
96
+ private readonly targetEpoch: EpochNumber,
77
97
  private readonly checkpointNumber: CheckpointNumber,
78
98
  private readonly syncedToBlockNumber: BlockNumber,
79
99
  // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
@@ -100,13 +120,25 @@ export class CheckpointProposalJob implements Traceable {
100
120
  private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
101
121
  public readonly tracer: Tracer,
102
122
  bindings?: LoggerBindings,
123
+ private readonly proposedCheckpointData?: ProposedCheckpointData,
103
124
  ) {
104
- this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
125
+ this.log = createLogger('sequencer:checkpoint-proposal', {
126
+ ...bindings,
127
+ instanceId: `slot-${this.slotNow}`,
128
+ });
129
+ }
130
+
131
+ /** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
132
+ public async awaitPendingSubmission(): Promise<void> {
133
+ this.log.info('Awaiting pending L1 payload submission');
134
+ await this.pendingL1Submission;
105
135
  }
106
136
 
107
137
  /**
108
138
  * Executes the checkpoint proposal job.
109
- * Returns the published checkpoint if successful, undefined otherwise.
139
+ * Builds blocks, collects attestations, enqueues requests, and schedules L1 submission as a
140
+ * background task so the work loop can return to IDLE immediately.
141
+ * Returns the built checkpoint if successful, undefined otherwise.
110
142
  */
111
143
  @trackSpan('CheckpointProposalJob.execute')
112
144
  public async execute(): Promise<Checkpoint | undefined> {
@@ -114,7 +146,7 @@ export class CheckpointProposalJob implements Traceable {
114
146
  // In fisherman mode, we simulate slashing but don't actually publish to L1
115
147
  // These are constant for the whole slot, so we only enqueue them once
116
148
  const votesPromises = new CheckpointVoter(
117
- this.slot,
149
+ this.targetSlot,
118
150
  this.publisher,
119
151
  this.attestorAddress,
120
152
  this.validatorClient,
@@ -125,8 +157,10 @@ export class CheckpointProposalJob implements Traceable {
125
157
  this.log,
126
158
  ).enqueueVotes();
127
159
 
128
- // Build and propose the checkpoint. This will enqueue the request on the publisher if a checkpoint is built.
129
- const checkpoint = await this.proposeCheckpoint();
160
+ // Build and propose the checkpoint. Builds blocks, broadcasts, collects attestations, and signs.
161
+ // Does NOT enqueue to L1 yet — that happens after the pipeline sleep.
162
+ const proposalResult = await this.proposeCheckpoint();
163
+ const checkpoint = proposalResult?.checkpoint;
130
164
 
131
165
  // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
132
166
  await Promise.all(votesPromises);
@@ -141,47 +175,135 @@ export class CheckpointProposalJob implements Traceable {
141
175
  return;
142
176
  }
143
177
 
144
- // Then send everything to L1
145
- const l1Response = await this.publisher.sendRequests();
146
- const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
147
- if (proposedAction) {
148
- this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.slot });
149
- const coinbase = checkpoint?.header.coinbase;
150
- await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
151
- return checkpoint;
152
- } else if (checkpoint) {
153
- this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.slot });
154
- return undefined;
178
+ // Enqueue the checkpoint for L1 submission
179
+ if (proposalResult) {
180
+ try {
181
+ await this.enqueueCheckpointForSubmission(proposalResult);
182
+ } catch (err) {
183
+ this.log.error(`Failed to enqueue checkpoint for L1 submission at slot ${this.targetSlot}`, err);
184
+ // Continue to sendRequestsAt so votes are still sent
185
+ }
155
186
  }
187
+
188
+ // Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
189
+ const submitAfter = this.epochCache.isProposerPipeliningEnabled()
190
+ ? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000)
191
+ : new Date(this.dateProvider.now());
192
+
193
+ // TODO(https://github.com/AztecProtocol/aztec-packages/pull/21250): should discard the pending submission if a reorg occurs underneath
194
+
195
+ // Schedule L1 submission in the background so the work loop returns immediately.
196
+ // The publisher will sleep until submitAfter, then send the bundled requests.
197
+ // The promise is stored so it can be awaited during shutdown.
198
+ this.pendingL1Submission = this.publisher
199
+ .sendRequestsAt(submitAfter)
200
+ .then(async l1Response => {
201
+ const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
202
+ if (proposedAction) {
203
+ this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
204
+ const coinbase = checkpoint?.header.coinbase;
205
+ await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
206
+ } else if (checkpoint) {
207
+ this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
208
+
209
+ if (this.epochCache.isProposerPipeliningEnabled()) {
210
+ this.metrics.recordPipelineDiscard();
211
+ }
212
+ }
213
+ })
214
+ .catch(err => {
215
+ this.log.error(`Background L1 submission failed for slot ${this.targetSlot}`, err);
216
+ if (checkpoint) {
217
+ this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
218
+
219
+ if (this.epochCache.isProposerPipeliningEnabled()) {
220
+ this.metrics.recordPipelineDiscard();
221
+ }
222
+ }
223
+ });
224
+
225
+ // Return the built checkpoint immediately — the work loop is now unblocked
226
+ return checkpoint;
227
+ }
228
+
229
+ /** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
230
+ private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
231
+ const { checkpoint, attestations, attestationsSignature } = result;
232
+
233
+ this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
234
+ const aztecSlotDuration = this.l1Constants.slotDuration;
235
+ const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
236
+ const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
237
+
238
+ // If we have been configured to potentially skip publishing checkpoint then roll the dice here
239
+ if (
240
+ this.config.skipPublishingCheckpointsPercent !== undefined &&
241
+ this.config.skipPublishingCheckpointsPercent > 0
242
+ ) {
243
+ const roll = Math.max(0, randomInt(100));
244
+ if (roll < this.config.skipPublishingCheckpointsPercent) {
245
+ this.log.warn(
246
+ `Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
247
+ );
248
+ return;
249
+ }
250
+ }
251
+
252
+ await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
253
+ txTimeoutAt,
254
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
255
+ forceProposedFeeHeader: this.computedForceProposedFeeHeader,
256
+ });
156
257
  }
157
258
 
158
259
  @trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
159
260
  return {
160
261
  // nullish operator needed for tests
161
262
  [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
162
- [Attributes.SLOT_NUMBER]: this.slot,
263
+ [Attributes.SLOT_NUMBER]: this.targetSlot,
163
264
  };
164
265
  })
165
- private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
266
+ private async proposeCheckpoint(): Promise<CheckpointProposalResult | undefined> {
166
267
  try {
167
268
  // Get operator configured coinbase and fee recipient for this attestor
168
269
  const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
169
270
  const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
170
271
 
171
272
  // Start the checkpoint
172
- this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
173
- this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
273
+ this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
274
+ this.log.info(`Starting checkpoint proposal`, {
275
+ buildSlot: this.slotNow,
276
+ submissionSlot: this.targetSlot,
277
+ pipelining: this.epochCache.isProposerPipeliningEnabled(),
278
+ proposer: this.proposer?.toString(),
279
+ coinbase: coinbase.toString(),
280
+ });
281
+ this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
174
282
 
175
283
  // Enqueues checkpoint invalidation (constant for the whole slot)
176
284
  if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
177
285
  this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
178
286
  }
179
287
 
180
- // Create checkpoint builder for the slot
288
+ // Create checkpoint builder for the slot.
289
+ // When pipelining, force the proposed checkpoint number and fee header to our parent so the
290
+ // fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
291
+ const isPipelining = this.epochCache.isProposerPipeliningEnabled();
292
+ const parentCheckpointNumber = isPipelining ? CheckpointNumber(this.checkpointNumber - 1) : undefined;
293
+
294
+ // Compute the parent's fee header override when pipelining
295
+ if (isPipelining && this.proposedCheckpointData) {
296
+ this.computedForceProposedFeeHeader = await this.computeForceProposedFeeHeader(parentCheckpointNumber!);
297
+ }
298
+
181
299
  const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
182
300
  coinbase,
183
301
  feeRecipient,
184
- this.slot,
302
+ this.targetSlot,
303
+ {
304
+ forcePendingCheckpointNumber: parentCheckpointNumber,
305
+ forceProposedFeeHeader: this.computedForceProposedFeeHeader,
306
+ },
185
307
  );
186
308
 
187
309
  // Collect L1 to L2 messages for the checkpoint and compute their hash
@@ -189,7 +311,7 @@ export class CheckpointProposalJob implements Traceable {
189
311
  const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
190
312
 
191
313
  // Collect the out hashes of all the checkpoints before this one in the same epoch
192
- const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
314
+ const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
193
315
  .filter(c => c.checkpointNumber < this.checkpointNumber)
194
316
  .map(c => c.checkpointOutHash);
195
317
 
@@ -246,8 +368,8 @@ export class CheckpointProposalJob implements Traceable {
246
368
  }
247
369
 
248
370
  if (blocksInCheckpoint.length === 0) {
249
- this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
250
- this.eventEmitter.emit('checkpoint-empty', { slot: this.slot });
371
+ this.log.warn(`No blocks were built for slot ${this.targetSlot}`, { slot: this.targetSlot });
372
+ this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
251
373
  return undefined;
252
374
  }
253
375
 
@@ -255,17 +377,18 @@ export class CheckpointProposalJob implements Traceable {
255
377
  if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
256
378
  this.log.warn(
257
379
  `Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
258
- { slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
380
+ { slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
259
381
  );
260
382
  return undefined;
261
383
  }
262
384
 
263
385
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
264
386
  // broadcasted yet, and wait to collect the committee attestations.
265
- this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
387
+ this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
266
388
  const checkpoint = await checkpointBuilder.completeCheckpoint();
267
389
 
268
- // Final validation round for the checkpoint before we propose it, just for safety
390
+ // Final validation: per-block limits are only checked if the operator set them explicitly.
391
+ // Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
269
392
  try {
270
393
  validateCheckpoint(checkpoint, {
271
394
  rollupManaLimit: this.l1Constants.rollupManaLimit,
@@ -275,7 +398,7 @@ export class CheckpointProposalJob implements Traceable {
275
398
  maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
276
399
  });
277
400
  } catch (err) {
278
- this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
401
+ this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
279
402
  checkpoint: checkpoint.header.toInspect(),
280
403
  });
281
404
  return undefined;
@@ -292,16 +415,20 @@ export class CheckpointProposalJob implements Traceable {
292
415
  // Do not collect attestations nor publish to L1 in fisherman mode
293
416
  if (this.config.fishermanMode) {
294
417
  this.log.info(
295
- `Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` +
418
+ `Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
296
419
  `Skipping proposal in fisherman mode.`,
297
420
  {
298
- slot: this.slot,
421
+ slot: this.targetSlot,
299
422
  checkpoint: checkpoint.header.toInspect(),
300
423
  blocksBuilt: blocksInCheckpoint.length,
301
424
  },
302
425
  );
303
426
  this.metrics.recordCheckpointSuccess();
304
- return checkpoint;
427
+ return {
428
+ checkpoint,
429
+ attestations: CommitteeAttestationsAndSigners.empty(),
430
+ attestationsSignature: Signature.empty(),
431
+ };
305
432
  }
306
433
 
307
434
  // Include the block pending broadcast in the checkpoint proposal if any
@@ -324,7 +451,7 @@ export class CheckpointProposalJob implements Traceable {
324
451
  const blockProposedAt = this.dateProvider.now();
325
452
  await this.p2pClient.broadcastCheckpointProposal(proposal);
326
453
 
327
- this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
454
+ this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
328
455
  const attestations = await this.waitForAttestations(proposal);
329
456
  const blockAttestedAt = this.dateProvider.now();
330
457
 
@@ -337,7 +464,7 @@ export class CheckpointProposalJob implements Traceable {
337
464
  attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
338
465
  attestations,
339
466
  signer,
340
- this.slot,
467
+ this.targetSlot,
341
468
  this.checkpointNumber,
342
469
  );
343
470
  } catch (err) {
@@ -349,39 +476,15 @@ export class CheckpointProposalJob implements Traceable {
349
476
  throw err;
350
477
  }
351
478
 
352
- // Enqueue publishing the checkpoint to L1
353
- this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
354
- const aztecSlotDuration = this.l1Constants.slotDuration;
355
- const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
356
- const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
357
-
358
- // If we have been configured to potentially skip publishing checkpoint then roll the dice here
359
- if (
360
- this.config.skipPublishingCheckpointsPercent !== undefined &&
361
- this.config.skipPublishingCheckpointsPercent > 0
362
- ) {
363
- const result = Math.max(0, randomInt(100));
364
- if (result < this.config.skipPublishingCheckpointsPercent) {
365
- this.log.warn(
366
- `Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
367
- );
368
- return checkpoint;
369
- }
370
- }
371
-
372
- await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
373
- txTimeoutAt,
374
- forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
375
- });
376
-
377
- return checkpoint;
479
+ // Return the result for the caller to enqueue after the pipeline sleep
480
+ return { checkpoint, attestations, attestationsSignature };
378
481
  } catch (err) {
379
482
  if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
380
483
  // swallow this error. It's already been logged by a function deeper in the stack
381
484
  return undefined;
382
485
  }
383
486
 
384
- this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
487
+ this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
385
488
  return undefined;
386
489
  }
387
490
  }
@@ -416,7 +519,7 @@ export class CheckpointProposalJob implements Traceable {
416
519
 
417
520
  if (!timingInfo.canStart) {
418
521
  this.log.debug(`Not enough time left in slot to start another block`, {
419
- slot: this.slot,
522
+ slot: this.targetSlot,
420
523
  blocksBuilt,
421
524
  secondsIntoSlot,
422
525
  });
@@ -451,8 +554,8 @@ export class CheckpointProposalJob implements Traceable {
451
554
  } else if ('error' in buildResult) {
452
555
  // If there was an error building the block, just exit the loop and give up the rest of the slot
453
556
  if (!(buildResult.error instanceof SequencerInterruptedError)) {
454
- this.log.warn(`Halting block building for slot ${this.slot}`, {
455
- slot: this.slot,
557
+ this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
558
+ slot: this.targetSlot,
456
559
  blocksBuilt,
457
560
  error: buildResult.error,
458
561
  });
@@ -462,21 +565,14 @@ export class CheckpointProposalJob implements Traceable {
462
565
 
463
566
  const { block, usedTxs } = buildResult;
464
567
  blocksInCheckpoint.push(block);
465
-
466
- // Sync the proposed block to the archiver to make it available
467
- // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
468
- // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
469
- // Fire and forget - don't block the critical path, but log errors
470
- this.syncProposedBlockToArchiver(block).catch(err => {
471
- this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
472
- });
473
-
474
568
  usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
475
569
 
476
- // If this is the last block, exit the loop now so we start collecting attestations
570
+ // If this is the last block, sync it to the archiver and exit the loop
571
+ // so we can build the checkpoint and start collecting attestations.
477
572
  if (timingInfo.isLastBlock) {
478
- this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
479
- slot: this.slot,
573
+ await this.syncProposedBlockToArchiver(block);
574
+ this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
575
+ slot: this.targetSlot,
480
576
  blockNumber,
481
577
  blocksBuilt,
482
578
  });
@@ -484,38 +580,61 @@ export class CheckpointProposalJob implements Traceable {
484
580
  break;
485
581
  }
486
582
 
487
- // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
488
- // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
489
- if (!this.config.fishermanMode) {
490
- const proposal = await this.validatorClient.createBlockProposal(
491
- block.header,
492
- block.indexWithinCheckpoint,
493
- inHash,
494
- block.archive.root,
495
- usedTxs,
496
- this.proposer,
497
- blockProposalOptions,
498
- );
499
- await this.p2pClient.broadcastProposal(proposal);
500
- }
583
+ // Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
584
+ // in which case we'll broadcast it along with the checkpoint at the end of the loop.
585
+ // Note that we only send the block to the archiver if we manage to create the proposal, so if there's
586
+ // a HA error we don't pollute our archiver with a block that won't make it to the chain.
587
+ const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
588
+
589
+ // Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal.
590
+ // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
591
+ // If this throws, we abort the entire checkpoint.
592
+ await this.syncProposedBlockToArchiver(block);
593
+
594
+ // Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
595
+ proposal && (await this.p2pClient.broadcastProposal(proposal));
501
596
 
502
597
  // Wait until the next block's start time
503
598
  await this.waitUntilNextSubslot(timingInfo.deadline);
504
599
  }
505
600
 
506
- this.log.verbose(`Block building loop completed for slot ${this.slot}`, {
507
- slot: this.slot,
601
+ this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
602
+ slot: this.targetSlot,
508
603
  blocksBuilt: blocksInCheckpoint.length,
509
604
  });
510
605
 
511
606
  return { blocksInCheckpoint, blockPendingBroadcast };
512
607
  }
513
608
 
609
+ /** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
610
+ private createBlockProposal(
611
+ block: L2Block,
612
+ inHash: Fr,
613
+ usedTxs: Tx[],
614
+ blockProposalOptions: BlockProposalOptions,
615
+ ): Promise<BlockProposal | undefined> {
616
+ if (this.config.fishermanMode) {
617
+ this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
618
+ return Promise.resolve(undefined);
619
+ }
620
+ return this.validatorClient.createBlockProposal(
621
+ block.header,
622
+ block.indexWithinCheckpoint,
623
+ inHash,
624
+ block.archive.root,
625
+ usedTxs,
626
+ this.proposer,
627
+ blockProposalOptions,
628
+ );
629
+ }
630
+
514
631
  /** Sleeps until it is time to produce the next block in the slot */
515
632
  @trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
516
633
  private async waitUntilNextSubslot(nextSubslotStart: number) {
517
- this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
518
- this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
634
+ this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
635
+ this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
636
+ slot: this.targetSlot,
637
+ });
519
638
  await this.waitUntilTimeInSlot(nextSubslotStart);
520
639
  }
521
640
 
@@ -536,20 +655,19 @@ export class CheckpointProposalJob implements Traceable {
536
655
  opts;
537
656
 
538
657
  this.log.verbose(
539
- `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
658
+ `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
540
659
  { ...checkpointBuilder.getConstantData(), ...opts },
541
660
  );
542
661
 
543
662
  try {
544
663
  // Wait until we have enough txs to build the block
545
- const minTxs = this.config.minTxsPerBlock;
546
- const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
664
+ const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
547
665
  if (!canStartBuilding) {
548
666
  this.log.warn(
549
- `Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`,
550
- { blockNumber, slot: this.slot, indexWithinCheckpoint },
667
+ `Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
668
+ { blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
551
669
  );
552
- this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.slot });
670
+ this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
553
671
  this.metrics.recordBlockProposalFailed('insufficient_txs');
554
672
  return undefined;
555
673
  }
@@ -562,14 +680,16 @@ export class CheckpointProposalJob implements Traceable {
562
680
  );
563
681
 
564
682
  this.log.debug(
565
- `Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`,
566
- { slot: this.slot, blockNumber, indexWithinCheckpoint },
683
+ `Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
684
+ { slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
567
685
  );
568
- this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
686
+ this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
569
687
 
570
- // Per-block limits derived at startup by computeBlockLimits(), further capped
688
+ // Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
571
689
  // by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
572
- const blockBuilderOptions: PublicProcessorLimits = {
690
+ // minValidTxs is passed into the builder so it can reject the block *before* updating state.
691
+ const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
692
+ const blockBuilderOptions: BlockBuilderOptions = {
573
693
  maxTransactions: this.config.maxTxsPerBlock,
574
694
  maxBlockGas:
575
695
  this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
@@ -577,9 +697,14 @@ export class CheckpointProposalJob implements Traceable {
577
697
  : undefined,
578
698
  deadline: buildDeadline,
579
699
  isBuildingProposal: true,
700
+ minValidTxs,
701
+ maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
702
+ perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
580
703
  };
581
704
 
582
- // Actually build the block by executing txs
705
+ // Actually build the block by executing txs. The builder throws InsufficientValidTxsError
706
+ // if the number of successfully processed txs is below minValidTxs, ensuring state is not
707
+ // updated for blocks that will be discarded.
583
708
  const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
584
709
  checkpointBuilder,
585
710
  pendingTxs,
@@ -591,22 +716,27 @@ export class CheckpointProposalJob implements Traceable {
591
716
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
592
717
  await this.dropFailedTxsFromP2P(buildResult.failedTxs);
593
718
 
594
- // Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
595
- // too long, then we may not get to minTxsPerBlock after executing public functions.
596
- const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
597
- const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
598
- if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
719
+ if (buildResult.status === 'insufficient-valid-txs') {
599
720
  this.log.warn(
600
- `Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
601
- { slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint, minValidTxs, buildResult: buildResult.status },
721
+ `Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
722
+ {
723
+ slot: this.targetSlot,
724
+ blockNumber,
725
+ numTxs: buildResult.processedCount,
726
+ indexWithinCheckpoint,
727
+ minValidTxs,
728
+ },
602
729
  );
603
- this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
730
+ this.eventEmitter.emit('block-build-failed', {
731
+ reason: `Insufficient valid txs`,
732
+ slot: this.targetSlot,
733
+ });
604
734
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
605
735
  return undefined;
606
736
  }
607
737
 
608
738
  // Block creation succeeded, emit stats and metrics
609
- const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
739
+ const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
610
740
 
611
741
  const blockStats = {
612
742
  eventName: 'l2-block-built',
@@ -620,30 +750,39 @@ export class CheckpointProposalJob implements Traceable {
620
750
  const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
621
751
 
622
752
  this.log.info(
623
- `Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
753
+ `Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
624
754
  { blockHash, txHashes, manaPerSec, ...blockStats },
625
755
  );
626
756
 
627
- this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
757
+ // `slot` is the target/submission slot (may be one ahead when pipelining),
758
+ // `buildSlot` is the wall-clock slot during which the block was actually built.
759
+ this.eventEmitter.emit('block-proposed', {
760
+ blockNumber: block.number,
761
+ slot: this.targetSlot,
762
+ buildSlot: this.slotNow,
763
+ });
628
764
  this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
629
765
 
630
766
  return { block, usedTxs };
631
767
  } catch (err: any) {
632
- this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
633
- this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
768
+ this.eventEmitter.emit('block-build-failed', {
769
+ reason: err.message,
770
+ slot: this.targetSlot,
771
+ });
772
+ this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
634
773
  this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
635
774
  this.metrics.recordFailedBlock();
636
775
  return { error: err };
637
776
  }
638
777
  }
639
778
 
640
- /** Uses the checkpoint builder to build a block, catching specific txs */
779
+ /** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */
641
780
  private async buildSingleBlockWithCheckpointBuilder(
642
781
  checkpointBuilder: CheckpointBuilder,
643
782
  pendingTxs: AsyncIterable<Tx>,
644
783
  blockNumber: BlockNumber,
645
784
  blockTimestamp: bigint,
646
- blockBuilderOptions: PublicProcessorLimits,
785
+ blockBuilderOptions: BlockBuilderOptions,
647
786
  ) {
648
787
  try {
649
788
  const workTimer = new Timer();
@@ -651,8 +790,12 @@ export class CheckpointProposalJob implements Traceable {
651
790
  const blockBuildDuration = workTimer.ms();
652
791
  return { ...result, blockBuildDuration, status: 'success' as const };
653
792
  } catch (err: unknown) {
654
- if (isErrorClass(err, NoValidTxsError)) {
655
- return { failedTxs: err.failedTxs, status: 'no-valid-txs' as const };
793
+ if (isErrorClass(err, InsufficientValidTxsError)) {
794
+ return {
795
+ failedTxs: err.failedTxs,
796
+ processedCount: err.processedCount,
797
+ status: 'insufficient-valid-txs' as const,
798
+ };
656
799
  }
657
800
  throw err;
658
801
  }
@@ -665,7 +808,7 @@ export class CheckpointProposalJob implements Traceable {
665
808
  blockNumber: BlockNumber;
666
809
  indexWithinCheckpoint: IndexWithinCheckpoint;
667
810
  buildDeadline: Date | undefined;
668
- }): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
811
+ }): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
669
812
  const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
670
813
 
671
814
  // We only allow a block with 0 txs in the first block of the checkpoint
@@ -682,20 +825,20 @@ export class CheckpointProposalJob implements Traceable {
682
825
  // If we're past deadline, or we have no deadline, give up
683
826
  const now = this.dateProvider.nowAsDate();
684
827
  if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
685
- return { canStartBuilding: false, availableTxs: availableTxs };
828
+ return { canStartBuilding: false, availableTxs, minTxs };
686
829
  }
687
830
 
688
831
  // Wait a bit before checking again
689
- this.setStateFn(SequencerState.WAITING_FOR_TXS, this.slot);
832
+ this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
690
833
  this.log.verbose(
691
- `Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
692
- { blockNumber, slot: this.slot, indexWithinCheckpoint },
834
+ `Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
835
+ { blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
693
836
  );
694
837
  await this.waitForTxsPollingInterval();
695
838
  availableTxs = await this.p2pClient.getPendingTxCount();
696
839
  }
697
840
 
698
- return { canStartBuilding: true, availableTxs };
841
+ return { canStartBuilding: true, availableTxs, minTxs };
699
842
  }
700
843
 
701
844
  /**
@@ -721,7 +864,7 @@ export class CheckpointProposalJob implements Traceable {
721
864
  this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
722
865
  }
723
866
 
724
- const numberOfRequiredAttestations = Math.floor((committee.length * 2) / 3) + 1;
867
+ const numberOfRequiredAttestations = computeQuorum(committee.length);
725
868
 
726
869
  if (this.config.skipCollectingAttestations) {
727
870
  this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
@@ -871,7 +1014,7 @@ export class CheckpointProposalJob implements Traceable {
871
1014
  * would never receive its own block without this explicit sync.
872
1015
  */
873
1016
  private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
874
- if (this.config.skipPushProposedBlocksToArchiver !== false) {
1017
+ if (this.config.skipPushProposedBlocksToArchiver) {
875
1018
  this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
876
1019
  blockNumber: block.number,
877
1020
  slot: block.header.globalVariables.slotNumber,
@@ -889,19 +1032,19 @@ export class CheckpointProposalJob implements Traceable {
889
1032
  private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
890
1033
  // Perform L1 fee analysis before clearing requests
891
1034
  // The callback is invoked asynchronously after the next block is mined
892
- const feeAnalysis = await this.publisher.analyzeL1Fees(this.slot, analysis =>
1035
+ const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
893
1036
  this.metrics.recordFishermanFeeAnalysis(analysis),
894
1037
  );
895
1038
 
896
1039
  if (checkpoint) {
897
- this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.slot}`, {
1040
+ this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
898
1041
  ...checkpoint.toCheckpointInfo(),
899
1042
  ...checkpoint.getStats(),
900
1043
  feeAnalysisId: feeAnalysis?.id,
901
1044
  });
902
1045
  } else {
903
- this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
904
- slot: this.slot,
1046
+ this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
1047
+ slot: this.targetSlot,
905
1048
  feeAnalysisId: feeAnalysis?.id,
906
1049
  });
907
1050
  this.metrics.recordCheckpointProposalFailed('block_build_failed');
@@ -915,15 +1058,15 @@ export class CheckpointProposalJob implements Traceable {
915
1058
  */
916
1059
  private handleHASigningError(err: any, errorContext: string): boolean {
917
1060
  if (err instanceof DutyAlreadySignedError) {
918
- this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
919
- slot: this.slot,
1061
+ this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
1062
+ slot: this.targetSlot,
920
1063
  signedByNode: err.signedByNode,
921
1064
  });
922
1065
  return true;
923
1066
  }
924
1067
  if (err instanceof SlashingProtectionError) {
925
- this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
926
- slot: this.slot,
1068
+ this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
1069
+ slot: this.targetSlot,
927
1070
  existingMessageHash: err.existingMessageHash,
928
1071
  attemptedMessageHash: err.attemptedMessageHash,
929
1072
  });
@@ -932,6 +1075,56 @@ export class CheckpointProposalJob implements Traceable {
932
1075
  return false;
933
1076
  }
934
1077
 
1078
+ /**
1079
+ * In times of congestion we need to simulate using the correct fee header override for the previous block
1080
+ * We calculate the correct fee header values.
1081
+ *
1082
+ * If we are in block 1, or the checkpoint we are querying does not exist, we return undefined. However
1083
+ * If we are pipelining - where this function is called, the grandparentCheckpointNumber should always exist
1084
+ * @param parentCheckpointNumber
1085
+ * @returns
1086
+ */
1087
+ protected async computeForceProposedFeeHeader(parentCheckpointNumber: CheckpointNumber): Promise<
1088
+ | {
1089
+ checkpointNumber: CheckpointNumber;
1090
+ feeHeader: FeeHeader;
1091
+ }
1092
+ | undefined
1093
+ > {
1094
+ if (!this.proposedCheckpointData) {
1095
+ return undefined;
1096
+ }
1097
+
1098
+ const rollup = this.publisher.rollupContract;
1099
+ const grandparentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 2);
1100
+ try {
1101
+ const [grandparentCheckpoint, manaTarget] = await Promise.all([
1102
+ rollup.getCheckpoint(grandparentCheckpointNumber),
1103
+ rollup.getManaTarget(),
1104
+ ]);
1105
+
1106
+ if (!grandparentCheckpoint || !grandparentCheckpoint.feeHeader) {
1107
+ this.log.error(
1108
+ `Grandparent checkpoint or its feeHeader is undefined for checkpointNumber=${grandparentCheckpointNumber.toString()}`,
1109
+ );
1110
+ return undefined;
1111
+ } else {
1112
+ const parentFeeHeader = RollupContract.computeChildFeeHeader(
1113
+ grandparentCheckpoint.feeHeader,
1114
+ this.proposedCheckpointData.totalManaUsed,
1115
+ this.proposedCheckpointData.feeAssetPriceModifier,
1116
+ manaTarget,
1117
+ );
1118
+ return { checkpointNumber: parentCheckpointNumber, feeHeader: parentFeeHeader };
1119
+ }
1120
+ } catch (err) {
1121
+ this.log.error(
1122
+ `Failed to fetch grandparent checkpoint or mana target for checkpointNumber=${grandparentCheckpointNumber.toString()}: ${err}`,
1123
+ );
1124
+ return undefined;
1125
+ }
1126
+ }
1127
+
935
1128
  /** Waits until a specific time within the current slot */
936
1129
  @trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
937
1130
  protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
@@ -946,7 +1139,7 @@ export class CheckpointProposalJob implements Traceable {
946
1139
  }
947
1140
 
948
1141
  private getSlotStartBuildTimestamp(): number {
949
- return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
1142
+ return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
950
1143
  }
951
1144
 
952
1145
  private getSecondsIntoSlot(): number {