@aztec/sequencer-client 5.0.0-private.20260318 → 5.0.0-rc.1

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 (108) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +8 -15
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +35 -96
  5. package/dest/config.d.ts +8 -2
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +48 -26
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +128 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +67 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +14 -14
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +16 -51
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/publisher/config.d.ts +15 -3
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +19 -4
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  25. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  26. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  27. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  28. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  29. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  30. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  31. package/dest/publisher/sequencer-publisher.d.ts +73 -65
  32. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  33. package/dest/publisher/sequencer-publisher.js +317 -532
  34. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  35. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  36. package/dest/sequencer/automine/automine_factory.js +85 -0
  37. package/dest/sequencer/automine/automine_sequencer.d.ts +184 -0
  38. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  39. package/dest/sequencer/automine/automine_sequencer.js +677 -0
  40. package/dest/sequencer/automine/index.d.ts +3 -0
  41. package/dest/sequencer/automine/index.d.ts.map +1 -0
  42. package/dest/sequencer/automine/index.js +2 -0
  43. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  44. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  45. package/dest/sequencer/chain_state_overrides.js +98 -0
  46. package/dest/sequencer/checkpoint_proposal_job.d.ts +77 -17
  47. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  48. package/dest/sequencer/checkpoint_proposal_job.js +768 -209
  49. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  50. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  51. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  52. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  53. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  54. package/dest/sequencer/checkpoint_voter.js +2 -5
  55. package/dest/sequencer/errors.d.ts +1 -8
  56. package/dest/sequencer/errors.d.ts.map +1 -1
  57. package/dest/sequencer/errors.js +0 -9
  58. package/dest/sequencer/events.d.ts +62 -4
  59. package/dest/sequencer/events.d.ts.map +1 -1
  60. package/dest/sequencer/metrics.d.ts +13 -10
  61. package/dest/sequencer/metrics.d.ts.map +1 -1
  62. package/dest/sequencer/metrics.js +45 -20
  63. package/dest/sequencer/sequencer.d.ts +115 -30
  64. package/dest/sequencer/sequencer.d.ts.map +1 -1
  65. package/dest/sequencer/sequencer.js +506 -174
  66. package/dest/sequencer/types.d.ts +2 -2
  67. package/dest/sequencer/types.d.ts.map +1 -1
  68. package/dest/test/index.d.ts +3 -3
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/mock_checkpoint_builder.d.ts +4 -8
  71. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  72. package/dest/test/utils.d.ts +15 -1
  73. package/dest/test/utils.d.ts.map +1 -1
  74. package/dest/test/utils.js +23 -6
  75. package/package.json +28 -27
  76. package/src/client/sequencer-client.ts +53 -123
  77. package/src/config.ts +57 -23
  78. package/src/global_variable_builder/README.md +44 -0
  79. package/src/global_variable_builder/fee_predictor.ts +172 -0
  80. package/src/global_variable_builder/fee_provider.ts +80 -0
  81. package/src/global_variable_builder/global_builder.ts +25 -63
  82. package/src/global_variable_builder/index.ts +3 -1
  83. package/src/publisher/config.ts +40 -6
  84. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
  85. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  86. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  87. package/src/publisher/sequencer-publisher.ts +376 -577
  88. package/src/sequencer/automine/README.md +60 -0
  89. package/src/sequencer/automine/automine_factory.ts +152 -0
  90. package/src/sequencer/automine/automine_sequencer.ts +783 -0
  91. package/src/sequencer/automine/index.ts +6 -0
  92. package/src/sequencer/chain_state_overrides.ts +169 -0
  93. package/src/sequencer/checkpoint_proposal_job.ts +917 -241
  94. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  95. package/src/sequencer/checkpoint_voter.ts +1 -12
  96. package/src/sequencer/errors.ts +0 -15
  97. package/src/sequencer/events.ts +65 -4
  98. package/src/sequencer/metrics.ts +57 -24
  99. package/src/sequencer/sequencer.ts +604 -195
  100. package/src/sequencer/types.ts +1 -1
  101. package/src/test/index.ts +2 -2
  102. package/src/test/mock_checkpoint_builder.ts +3 -3
  103. package/src/test/utils.ts +59 -10
  104. package/dest/sequencer/timetable.d.ts +0 -88
  105. package/dest/sequencer/timetable.d.ts.map +0 -1
  106. package/dest/sequencer/timetable.js +0 -222
  107. package/src/sequencer/README.md +0 -531
  108. package/src/sequencer/timetable.ts +0 -283
@@ -1,4 +1,5 @@
1
- import type { EpochCache } from '@aztec/epoch-cache';
1
+ import { type EpochCache, PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec/epoch-cache';
2
+ import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
2
3
  import {
3
4
  BlockNumber,
4
5
  CheckpointNumber,
@@ -13,11 +14,12 @@ import {
13
14
  generateUnrecoverableSignature,
14
15
  } from '@aztec/foundation/crypto/secp256k1-signer';
15
16
  import { Fr } from '@aztec/foundation/curves/bn254';
17
+ import { InterruptError, TimeoutError } from '@aztec/foundation/error';
16
18
  import { EthAddress } from '@aztec/foundation/eth-address';
17
19
  import { Signature } from '@aztec/foundation/eth-signature';
18
20
  import { filter } from '@aztec/foundation/iterator';
19
21
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
20
- import { sleep, sleepUntil } from '@aztec/foundation/sleep';
22
+ import { InterruptibleSleep } from '@aztec/foundation/sleep';
21
23
  import { type DateProvider, Timer } from '@aztec/foundation/timer';
22
24
  import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
23
25
  import type { P2P } from '@aztec/p2p';
@@ -29,20 +31,35 @@ import {
29
31
  type L2BlockSink,
30
32
  type L2BlockSource,
31
33
  MaliciousCommitteeAttestationsAndSigners,
34
+ type ProposedCheckpointSink,
35
+ type ValidateCheckpointResult,
32
36
  } from '@aztec/stdlib/block';
33
- import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
34
- import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
37
+ import {
38
+ type Checkpoint,
39
+ type ProposedCheckpointData,
40
+ getPreviousCheckpointOutHashes,
41
+ validateCheckpoint,
42
+ } from '@aztec/stdlib/checkpoint';
43
+ import { computeQuorum, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
35
44
  import { Gas } from '@aztec/stdlib/gas';
36
45
  import {
46
+ type BlockBuilderOptions,
37
47
  InsufficientValidTxsError,
38
- type PublicProcessorLimits,
39
48
  type ResolvedSequencerConfig,
40
49
  type WorldStateSynchronizer,
41
50
  } from '@aztec/stdlib/interfaces/server';
42
51
  import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
43
- import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
52
+ import type {
53
+ BlockProposal,
54
+ BlockProposalOptions,
55
+ CheckpointAttestation,
56
+ CheckpointProposal,
57
+ CheckpointProposalOptions,
58
+ CoordinationSignatureContext,
59
+ } from '@aztec/stdlib/p2p';
44
60
  import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
45
61
  import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
62
+ import type { ProposerTimetable } from '@aztec/stdlib/timetable';
46
63
  import { type FailedTx, Tx } from '@aztec/stdlib/tx';
47
64
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
48
65
  import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
@@ -51,16 +68,32 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
51
68
 
52
69
  import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
53
70
  import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
71
+ import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
72
+ import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
54
73
  import { CheckpointVoter } from './checkpoint_voter.js';
55
74
  import { SequencerInterruptedError } from './errors.js';
56
75
  import type { SequencerEvents } from './events.js';
57
76
  import type { SequencerMetrics } from './metrics.js';
58
- import type { SequencerTimetable } from './timetable.js';
59
77
  import type { SequencerRollupConstants } from './types.js';
60
78
  import { SequencerState } from './utils.js';
61
79
 
62
80
  /** How much time to sleep while waiting for min transactions to accumulate for a block */
63
81
  const TXS_POLLING_MS = 500;
82
+ const ARCHIVER_SYNC_POLLING_MS = 200;
83
+
84
+ /** Result from proposeCheckpoint when a checkpoint was successfully built and broadcast. */
85
+ type CheckpointProposalBroadcast = {
86
+ checkpoint: Checkpoint;
87
+ proposal: CheckpointProposal;
88
+ blockProposedAt: number;
89
+ };
90
+
91
+ /** Result after attestation collection and signing, ready for L1 submission. */
92
+ type CheckpointProposalResult = {
93
+ checkpoint: Checkpoint;
94
+ attestations: CommitteeAttestationsAndSigners;
95
+ attestationsSignature: Signature;
96
+ };
64
97
 
65
98
  /**
66
99
  * Handles the execution of a checkpoint proposal after the initial preparation phase.
@@ -70,12 +103,31 @@ const TXS_POLLING_MS = 500;
70
103
  */
71
104
  export class CheckpointProposalJob implements Traceable {
72
105
  protected readonly log: Logger;
106
+ private readonly checkpointEventLog: Logger;
107
+
108
+ /** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
109
+ private pendingL1Submission: Promise<void> | undefined;
110
+ private readonly interruptibleSleep = new InterruptibleSleep();
111
+ private interrupted = false;
112
+
113
+ /**
114
+ * Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
115
+ * complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
116
+ * or the invalidation pending override when rolling back. Consumed by
117
+ * publisher.validateBlockHeader before broadcast.
118
+ */
119
+ private checkpointSimulationOverridesPlan?: SimulationOverridesPlan;
120
+
121
+ private getSignatureContext(): CoordinationSignatureContext {
122
+ return this.signatureContext;
123
+ }
73
124
 
74
125
  constructor(
75
- private readonly epoch: EpochNumber,
76
- private readonly slot: SlotNumber,
126
+ private readonly targetSlot: SlotNumber,
127
+ private readonly targetEpoch: EpochNumber,
77
128
  private readonly checkpointNumber: CheckpointNumber,
78
129
  private readonly syncedToBlockNumber: BlockNumber,
130
+ private readonly checkpointedCheckpointNumber: CheckpointNumber,
79
131
  // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
80
132
  private readonly proposer: EthAddress | undefined,
81
133
  private readonly publisher: SequencerPublisher,
@@ -88,25 +140,92 @@ export class CheckpointProposalJob implements Traceable {
88
140
  private readonly l1ToL2MessageSource: L1ToL2MessageSource,
89
141
  private readonly l2BlockSource: L2BlockSource,
90
142
  private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
91
- private readonly blockSink: L2BlockSink,
143
+ private readonly blockSink: L2BlockSink & ProposedCheckpointSink,
92
144
  private readonly l1Constants: SequencerRollupConstants,
145
+ private readonly signatureContext: CoordinationSignatureContext,
93
146
  protected config: ResolvedSequencerConfig,
94
- protected timetable: SequencerTimetable,
147
+ protected timetable: ProposerTimetable,
95
148
  private readonly slasherClient: SlasherClientInterface | undefined,
96
149
  private readonly epochCache: EpochCache,
97
150
  private readonly dateProvider: DateProvider,
98
151
  private readonly metrics: SequencerMetrics,
99
- private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
100
- private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
152
+ private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
153
+ protected readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
154
+ private readonly setStateFn: (state: SequencerState, slot: SlotNumber) => void,
101
155
  public readonly tracer: Tracer,
102
156
  bindings?: LoggerBindings,
157
+ private readonly proposedCheckpointData?: ProposedCheckpointData,
103
158
  ) {
104
- this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
159
+ this.log = createLogger('sequencer:checkpoint-proposal', {
160
+ ...bindings,
161
+ instanceId: `slot-${this.getBuildSlot()}`,
162
+ });
163
+ this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
164
+ ...bindings,
165
+ instanceId: `slot-${this.getBuildSlot()}`,
166
+ });
167
+ }
168
+
169
+ /**
170
+ * The wall-clock slot during which this job builds, i.e. the slot one before {@link targetSlot} under
171
+ * proposer pipelining. Also the slot of the parent checkpoint this job builds on top of.
172
+ */
173
+ private getBuildSlot(): SlotNumber {
174
+ return SlotNumber(this.targetSlot - PROPOSER_PIPELINING_SLOT_OFFSET);
175
+ }
176
+
177
+ /**
178
+ * Sets the sequencer state for this job, reporting the target slot the checkpoint is being proposed for
179
+ * (not the wall-clock build slot). The slot is informational on the event payload/metrics; the job knows
180
+ * its own target slot, so callers only pass the state.
181
+ */
182
+ private setState(state: SequencerState): void {
183
+ this.setStateFn(state, this.targetSlot);
184
+ }
185
+
186
+ /** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
187
+ public async awaitPendingSubmission(): Promise<void> {
188
+ this.log.info('Awaiting pending L1 payload submission');
189
+ await this.pendingL1Submission;
190
+ }
191
+
192
+ /** Interrupts job-owned waits, including the publisher's send-at-slot sleep, so shutdown can finish. */
193
+ public interrupt(): void {
194
+ this.interrupted = true;
195
+ this.interruptibleSleep.interrupt(true);
196
+ this.publisher.interrupt();
197
+ }
198
+
199
+ private async awaitInterruptibleSleep(ms: number): Promise<void> {
200
+ if (this.interrupted) {
201
+ throw new SequencerInterruptedError();
202
+ }
203
+ if (ms <= 0) {
204
+ return;
205
+ }
206
+ try {
207
+ await this.interruptibleSleep.sleep(ms);
208
+ } catch (err) {
209
+ if (err instanceof InterruptError) {
210
+ throw new SequencerInterruptedError();
211
+ }
212
+ throw err;
213
+ }
214
+ }
215
+
216
+ private logCheckpointEvent(eventName: string, message: string, fields: Record<string, unknown>): void {
217
+ this.checkpointEventLog.debug(message, {
218
+ eventName: `sequencer-checkpoint-${eventName}`,
219
+ ...fields,
220
+ });
105
221
  }
106
222
 
107
223
  /**
108
224
  * Executes the checkpoint proposal job.
109
- * Returns the published checkpoint if successful, undefined otherwise.
225
+ * Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
226
+ * Attestation collection, signing, and L1 submission are backgrounded so the
227
+ * work loop can return to IDLE immediately for consecutive slot proposals.
228
+ * Returns the built checkpoint if successful, undefined otherwise.
110
229
  */
111
230
  @trackSpan('CheckpointProposalJob.execute')
112
231
  public async execute(): Promise<Checkpoint | undefined> {
@@ -114,7 +233,7 @@ export class CheckpointProposalJob implements Traceable {
114
233
  // In fisherman mode, we simulate slashing but don't actually publish to L1
115
234
  // These are constant for the whole slot, so we only enqueue them once
116
235
  const votesPromises = new CheckpointVoter(
117
- this.slot,
236
+ this.targetSlot,
118
237
  this.publisher,
119
238
  this.attestorAddress,
120
239
  this.validatorClient,
@@ -125,33 +244,309 @@ export class CheckpointProposalJob implements Traceable {
125
244
  this.log,
126
245
  ).enqueueVotes();
127
246
 
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();
130
-
131
- // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
132
- await Promise.all(votesPromises);
133
-
134
- if (checkpoint) {
135
- this.metrics.recordCheckpointProposalSuccess();
247
+ // Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
248
+ // Returns after broadcast — attestation collection is deferred.
249
+ const broadcast = await this.proposeCheckpoint();
250
+
251
+ if (!broadcast) {
252
+ await Promise.all(votesPromises);
253
+ // Still submit votes even without a checkpoint.
254
+ // Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
255
+ // (the pipelined slot in which the multicall is expected to mine). Submitting at the
256
+ // wall-clock time would let the multicall mine in a different L2 slot, causing
257
+ // signature verification to fail silently inside Multicall3. Delay submission to the
258
+ // start of `targetSlot` so the tx mines in the slot the vote was signed for.
259
+ if (!this.config.fishermanMode) {
260
+ this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(() => {});
261
+ }
262
+ return undefined;
136
263
  }
137
264
 
265
+ const { checkpoint } = broadcast;
266
+ this.metrics.recordCheckpointProposalSuccess();
267
+
138
268
  // Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
139
269
  if (this.config.fishermanMode) {
140
270
  await this.handleCheckpointEndAsFisherman(checkpoint);
141
- return;
271
+ return checkpoint;
142
272
  }
143
273
 
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;
274
+ // Background the attestation signing → L1 pipeline so the work loop is unblocked
275
+ this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
276
+
277
+ // Return the built checkpoint immediately — the work loop is now unblocked
278
+ return checkpoint;
279
+ }
280
+
281
+ /**
282
+ * Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
283
+ * Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
284
+ */
285
+ private async waitForAttestationsAndEnqueueSubmissionAsync(
286
+ broadcast: CheckpointProposalBroadcast,
287
+ votesPromises: Promise<unknown>[],
288
+ ): Promise<void> {
289
+ const { checkpoint } = broadcast;
290
+
291
+ try {
292
+ // Wait for all votes actions, enqueued at the beginning, to resolve
293
+ await Promise.all(votesPromises);
294
+
295
+ // Try to collect attestations from the committee
296
+ const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
297
+
298
+ // Wait for the previous checkpoint to land on L1 before submitting, so we can check it
299
+ // matches the proposed checkpoint we used as parent, and has valid attestations.
300
+ if (signedAttestations && (await this.waitForValidParentCheckpointOnL1())) {
301
+ await this.enqueueCheckpointForSubmission({ checkpoint, ...signedAttestations });
302
+ }
303
+
304
+ // If we failed to collect attestations, at least check if we need to issue an invalidation
305
+ if (!signedAttestations && (await this.waitForSyncedL2SlotNumber(this.getBuildSlot()))) {
306
+ const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
307
+ if (!validationStatus.valid) {
308
+ this.log.warn(
309
+ `Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`,
310
+ { checkpoint: validationStatus.checkpoint, reason: validationStatus.reason },
311
+ );
312
+ await this.enqueueInvalidation(validationStatus);
313
+ }
314
+ }
315
+
316
+ // Send whatever was enqueued: votes + (propose | invalidation | nothing).
317
+ const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
318
+ const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
319
+ if (proposedAction) {
320
+ this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
321
+ slot: this.targetSlot,
322
+ checkpointNumber: this.checkpointNumber,
323
+ successfulActions: l1Response?.successfulActions,
324
+ sentActions: l1Response?.sentActions,
325
+ });
326
+ this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
327
+ const coinbase = checkpoint.header.coinbase;
328
+ await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
329
+ } else {
330
+ this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
331
+ slot: this.targetSlot,
332
+ checkpointNumber: this.checkpointNumber,
333
+ successfulActions: l1Response?.successfulActions,
334
+ failedActions: l1Response?.failedActions,
335
+ sentActions: l1Response?.sentActions,
336
+ expiredActions: l1Response?.expiredActions,
337
+ reason: 'propose_action_not_successful',
338
+ });
339
+ this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
340
+ slot: this.targetSlot,
341
+ checkpointNumber: this.checkpointNumber,
342
+ successfulActions: l1Response?.successfulActions,
343
+ failedActions: l1Response?.failedActions,
344
+ sentActions: l1Response?.sentActions,
345
+ expiredActions: l1Response?.expiredActions,
346
+ reason: 'propose_action_not_successful',
347
+ });
348
+ this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
349
+ this.metrics.recordPipelineDiscard();
350
+ }
351
+ } catch (err) {
352
+ if (err instanceof SequencerInterruptedError) {
353
+ return;
354
+ }
355
+ this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
356
+ slot: this.targetSlot,
357
+ checkpointNumber: this.checkpointNumber,
358
+ reason: err instanceof Error ? err.message : String(err),
359
+ });
360
+ this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
361
+ slot: this.targetSlot,
362
+ checkpointNumber: this.checkpointNumber,
363
+ reason: err instanceof Error ? err.message : String(err),
364
+ });
365
+ this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
366
+ this.metrics.recordPipelineDiscard();
367
+ }
368
+ }
369
+
370
+ /** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
371
+ private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
372
+ const { checkpoint, attestations, attestationsSignature } = result;
373
+
374
+ this.setState(SequencerState.PUBLISHING_CHECKPOINT);
375
+ // Latest L1 block the propose can still land in for the target slot: the last Ethereum block inside
376
+ // the target slot (`target_slot_start + S - E`). This is one ethereum slot later than
377
+ // `attestation_deadline` (= last_ethereum_block_in_target_slot - E), which bounds when validators must
378
+ // have signed, not when the proposer must have sent. Using the attestation deadline here is too tight:
379
+ // attestations are collected up to (and, when not enforcing, past) it, so the propose tx would be
380
+ // enqueued already expired and time out before it can mine.
381
+ const lastL1BlockInTargetSlot =
382
+ Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) +
383
+ this.l1Constants.slotDuration -
384
+ this.l1Constants.ethereumSlotDuration;
385
+ const txTimeoutAt = new Date(lastL1BlockInTargetSlot * 1000);
386
+
387
+ // If we have been configured to potentially skip publishing checkpoint then roll the dice here
388
+ if (
389
+ this.config.skipPublishingCheckpointsPercent !== undefined &&
390
+ this.config.skipPublishingCheckpointsPercent > 0
391
+ ) {
392
+ const roll = Math.max(0, randomInt(100));
393
+ if (roll < this.config.skipPublishingCheckpointsPercent) {
394
+ this.log.warn(
395
+ `Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
396
+ );
397
+ return;
398
+ }
399
+ }
400
+
401
+ await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
402
+ txTimeoutAt,
403
+ });
404
+ }
405
+
406
+ /**
407
+ * Wait until the archiver syncs past the given L2 slot number.
408
+ * The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
409
+ * L1 submission window and is no longer useful.
410
+ */
411
+ private async waitForSyncedL2SlotNumber(waitForSlot: SlotNumber): Promise<boolean> {
412
+ const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
413
+ const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
414
+ const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
415
+ const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
416
+
417
+ try {
418
+ const timer = new Timer();
419
+ while (true) {
420
+ const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
421
+ if (syncedSlot !== undefined && syncedSlot >= waitForSlot) {
422
+ return true;
423
+ }
424
+ if (timeoutSeconds && timer.s() > timeoutSeconds) {
425
+ throw new TimeoutError(`Timeout awaiting archiver sync past slot ${waitForSlot}`);
426
+ }
427
+ await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
428
+ }
429
+ } catch (err) {
430
+ if (err instanceof SequencerInterruptedError) {
431
+ throw err;
432
+ }
433
+ this.log.warn(
434
+ `Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`,
435
+ { checkpointNumber: this.checkpointNumber },
436
+ );
437
+ this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
438
+ return false;
439
+ }
440
+ }
441
+
442
+ /**
443
+ * Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
444
+ * Polls until the archiver has synced L1 past the parent's slot, then verifies:
445
+ * - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
446
+ * - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
447
+ * If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
448
+ */
449
+ protected async waitForValidParentCheckpointOnL1(): Promise<boolean> {
450
+ if (this.config.skipWaitForValidParentCheckpointOnL1) {
451
+ this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
452
+ checkpointNumber: this.checkpointNumber,
453
+ });
454
+ return true;
455
+ }
456
+
457
+ const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
458
+
459
+ // Wait until archiver has synced L1 past the parent's slot (the build slot, one before targetSlot)
460
+ if (!(await this.waitForSyncedL2SlotNumber(this.getBuildSlot()))) {
461
+ return false;
462
+ }
463
+
464
+ const tips = await this.l2BlockSource.getL2Tips();
465
+ const checkpointedNumber = tips.checkpointed.checkpoint.number;
466
+
467
+ // We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
468
+ if (this.proposedCheckpointData) {
469
+ // After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
470
+ // with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
471
+ // Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
472
+ // invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
473
+ const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
474
+ if (!validationStatus.valid) {
475
+ this.log.warn(
476
+ `Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`,
477
+ { checkpointNumber: this.checkpointNumber, reason: validationStatus.reason },
478
+ );
479
+ this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
480
+ await this.enqueueInvalidation(validationStatus);
481
+ return false;
482
+ }
483
+
484
+ // The pending chain is valid. But did the parent checkpoint land on L1 at all?
485
+ if (checkpointedNumber < parentCheckpointNumber) {
486
+ this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
487
+ checkpointNumber: this.checkpointNumber,
488
+ checkpointedNumber,
489
+ });
490
+ this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
491
+ return false;
492
+ }
493
+
494
+ // It landed. But is it the one we were expecting?
495
+ const expectedHash = this.proposedCheckpointData.header.hash().toString();
496
+ if (tips.checkpointed.checkpoint.hash !== expectedHash) {
497
+ this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
498
+ checkpointNumber: this.checkpointNumber,
499
+ expectedHash,
500
+ actualHash: tips.checkpointed.checkpoint.hash,
501
+ });
502
+ this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
503
+ return false;
504
+ }
505
+
506
+ return true;
507
+ } else {
508
+ // We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
509
+ // But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
510
+ // so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
511
+ // proposal for the previous slot.
512
+ if (checkpointedNumber > parentCheckpointNumber) {
513
+ this.log.warn(
514
+ `Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`,
515
+ { checkpointNumber: this.checkpointNumber, checkpointedNumber },
516
+ );
517
+ this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
518
+ return false;
519
+ }
520
+
521
+ return true;
522
+ }
523
+ }
524
+
525
+ /** Emits the pipelined-checkpoint-discarded event and records the metric. */
526
+ private emitPipelinedCheckpointDiscarded(reason: string): void {
527
+ this.metrics.recordPipelineParentCheckpointMismatch(reason);
528
+ this.eventEmitter.emit('pipelined-checkpoint-discarded', {
529
+ slot: this.targetSlot,
530
+ checkpointNumber: this.checkpointNumber,
531
+ reason,
532
+ });
533
+ }
534
+
535
+ /** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */
536
+ private async enqueueInvalidation(validationStatus: ValidateCheckpointResult): Promise<void> {
537
+ if (this.config.skipInvalidateBlockAsProposer) {
538
+ this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
539
+ return;
540
+ }
541
+ const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
542
+ if (invalidateRequest) {
543
+ const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
544
+ const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
545
+ this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, { txTimeoutAt });
546
+ } else {
547
+ this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
548
+ checkpointNumber: this.checkpointNumber,
549
+ });
155
550
  }
156
551
  }
157
552
 
@@ -159,42 +554,89 @@ export class CheckpointProposalJob implements Traceable {
159
554
  return {
160
555
  // nullish operator needed for tests
161
556
  [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
162
- [Attributes.SLOT_NUMBER]: this.slot,
557
+ [Attributes.SLOT_NUMBER]: this.targetSlot,
163
558
  };
164
559
  })
165
- private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
560
+ private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
166
561
  try {
562
+ const now = this.dateProvider.now();
563
+ if (this.proposedCheckpointData) {
564
+ // Measure against the wall-clock slot whose build window we are currently using.
565
+ // In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
566
+ // target-slot boundary a full slot away from the actual build start time.
567
+ const slotBoundaryMs = Number(getTimestampForSlot(this.getBuildSlot(), this.l1Constants)) * 1000;
568
+ this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
569
+ }
570
+ this.checkpointMetrics.startCheckpointTiming(now);
571
+
167
572
  // Get operator configured coinbase and fee recipient for this attestor
168
573
  const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
169
574
  const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
170
575
 
171
576
  // Start the checkpoint
172
- this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
173
- this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
577
+ this.setState(SequencerState.INITIALIZING_CHECKPOINT);
578
+ this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
579
+ buildSlot: this.getBuildSlot(),
580
+ submissionSlot: this.targetSlot,
581
+ slot: this.targetSlot,
582
+ checkpointNumber: this.checkpointNumber,
583
+ proposer: this.proposer?.toString(),
584
+ attestorAddress: this.attestorAddress.toString(),
585
+ publisherAddress: this.publisher.getSenderAddress().toString(),
586
+ coinbase: coinbase.toString(),
587
+ });
588
+ this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
174
589
 
175
590
  // Enqueues checkpoint invalidation (constant for the whole slot)
176
591
  if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
177
592
  this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
178
593
  }
179
594
 
180
- // Create checkpoint builder for the slot
595
+ // Build the simulation plan for this slot. When pipelining, this overrides L1's view of
596
+ // pending/archive/fee-header to "as if the proposed parent had landed", so both the
597
+ // mana-min-fee simulation (in the globals builder) and the pre-broadcast
598
+ // validateBlockHeader see the chain tip the eventual L1 send will see.
599
+ this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
600
+ checkpointNumber: this.checkpointNumber,
601
+ proposedCheckpointData: this.proposedCheckpointData,
602
+ invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
603
+ checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
604
+ rollup: this.publisher.rollupContract,
605
+ signatureContext: this.signatureContext,
606
+ log: this.log,
607
+ });
608
+
181
609
  const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
182
610
  coinbase,
183
611
  feeRecipient,
184
- this.slot,
612
+ this.targetSlot,
613
+ this.checkpointSimulationOverridesPlan,
185
614
  );
186
615
 
187
616
  // Collect L1 to L2 messages for the checkpoint and compute their hash
188
617
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
189
618
  const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
190
619
 
191
- // Collect the out hashes of all the checkpoints before this one in the same epoch
192
- const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
193
- .filter(c => c.checkpointNumber < this.checkpointNumber)
194
- .map(c => c.checkpointOutHash);
620
+ // Collect the out hashes of all the checkpoints before this one in the same epoch.
621
+ // Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
622
+ // splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
623
+ // the resulting `epochOutHash` matches what validators (and L1) compute once the parent
624
+ // lands on L1.
625
+ const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
626
+ blockSource: this.l2BlockSource,
627
+ epoch: this.targetEpoch,
628
+ checkpointNumber: this.checkpointNumber,
629
+ l1Constants: this.epochCache.getL1Constants(),
630
+ pipeliningEnabled: true,
631
+ proposedCheckpointData: this.proposedCheckpointData,
632
+ log: this.log,
633
+ });
195
634
 
196
- // Get the fee asset price modifier from the oracle
197
- const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
635
+ // Anchor the modifier to the predicted parent fee header: L1 will apply it against
636
+ // that, not against the latest published checkpoint (which lags by one under pipelining).
637
+ const predictedParentEthPerFeeAssetE12 =
638
+ this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
639
+ const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
198
640
 
199
641
  // Create a long-lived forked world state for the checkpoint builder
200
642
  await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
@@ -218,11 +660,12 @@ export class CheckpointProposalJob implements Traceable {
218
660
 
219
661
  const checkpointProposalOptions: CheckpointProposalOptions = {
220
662
  publishFullTxs: !!this.config.publishTxsWithProposals,
221
- broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
663
+ broadcastInvalidCheckpointProposal:
664
+ this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal,
222
665
  };
223
666
 
224
667
  let blocksInCheckpoint: L2Block[] = [];
225
- let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
668
+ let blockPendingBroadcast: BlockProposal | undefined = undefined;
226
669
  const checkpointBuildTimer = new Timer();
227
670
 
228
671
  try {
@@ -246,26 +689,49 @@ export class CheckpointProposalJob implements Traceable {
246
689
  }
247
690
 
248
691
  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 });
692
+ this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
693
+ slot: this.targetSlot,
694
+ checkpointNumber: this.checkpointNumber,
695
+ reason: 'no_blocks_built',
696
+ });
697
+ this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
698
+ slot: this.targetSlot,
699
+ checkpointNumber: this.checkpointNumber,
700
+ reason: 'no_blocks_built',
701
+ });
702
+ this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
251
703
  return undefined;
252
704
  }
253
705
 
254
706
  const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
255
707
  if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
708
+ this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
709
+ slot: this.targetSlot,
710
+ checkpointNumber: this.checkpointNumber,
711
+ blocksBuilt: blocksInCheckpoint.length,
712
+ minBlocksForCheckpoint,
713
+ reason: 'min_blocks_not_met',
714
+ });
256
715
  this.log.warn(
257
716
  `Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
258
- { slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
717
+ {
718
+ slot: this.targetSlot,
719
+ checkpointNumber: this.checkpointNumber,
720
+ blocksBuilt: blocksInCheckpoint.length,
721
+ minBlocksForCheckpoint,
722
+ reason: 'min_blocks_not_met',
723
+ },
259
724
  );
260
725
  return undefined;
261
726
  }
262
727
 
263
728
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
264
729
  // broadcasted yet, and wait to collect the committee attestations.
265
- this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
730
+ this.setState(SequencerState.ASSEMBLING_CHECKPOINT);
266
731
  const checkpoint = await checkpointBuilder.completeCheckpoint();
267
732
 
268
- // Final validation round for the checkpoint before we propose it, just for safety
733
+ // Final validation: per-block limits are only checked if the operator set them explicitly.
734
+ // Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
269
735
  try {
270
736
  validateCheckpoint(checkpoint, {
271
737
  rollupManaLimit: this.l1Constants.rollupManaLimit,
@@ -275,113 +741,118 @@ export class CheckpointProposalJob implements Traceable {
275
741
  maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
276
742
  });
277
743
  } catch (err) {
278
- this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
744
+ this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
745
+ slot: this.targetSlot,
746
+ checkpointNumber: this.checkpointNumber,
747
+ blocksBuilt: blocksInCheckpoint.length,
748
+ reason: 'invalid_checkpoint',
749
+ checkpoint: checkpoint.header.toInspect(),
750
+ });
751
+ this.log.error(`Built an invalid checkpoint at slot ${this.targetSlot} (skipping proposal)`, err, {
752
+ slot: this.targetSlot,
753
+ checkpointNumber: this.checkpointNumber,
754
+ blocksBuilt: blocksInCheckpoint.length,
755
+ reason: 'invalid_checkpoint',
279
756
  checkpoint: checkpoint.header.toInspect(),
280
757
  });
281
758
  return undefined;
282
759
  }
283
760
 
284
761
  // Record checkpoint-level build metrics
285
- this.metrics.recordCheckpointBuild(
762
+ this.checkpointMetrics.recordCheckpointBuild(
286
763
  checkpointBuildTimer.ms(),
287
764
  blocksInCheckpoint.length,
288
765
  checkpoint.getStats().txCount,
289
766
  Number(checkpoint.header.totalManaUsed.toBigInt()),
290
767
  );
768
+ this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
769
+ slot: this.targetSlot,
770
+ buildSlot: this.getBuildSlot(),
771
+ checkpointNumber: this.checkpointNumber,
772
+ proposer: this.proposer?.toString(),
773
+ attestorAddress: this.attestorAddress.toString(),
774
+ publisherAddress: this.publisher.getSenderAddress().toString(),
775
+ blocksBuilt: blocksInCheckpoint.length,
776
+ txCount: checkpoint.getStats().txCount,
777
+ totalMana: Number(checkpoint.header.totalManaUsed.toBigInt()),
778
+ });
291
779
 
292
- // Do not collect attestations nor publish to L1 in fisherman mode
780
+ // In fisherman mode, return the checkpoint without broadcasting or collecting attestations
293
781
  if (this.config.fishermanMode) {
294
782
  this.log.info(
295
- `Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` +
783
+ `Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
296
784
  `Skipping proposal in fisherman mode.`,
297
785
  {
298
- slot: this.slot,
786
+ slot: this.targetSlot,
299
787
  checkpoint: checkpoint.header.toInspect(),
300
788
  blocksBuilt: blocksInCheckpoint.length,
301
789
  },
302
790
  );
303
791
  this.metrics.recordCheckpointSuccess();
304
- return checkpoint;
792
+ // Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
793
+ return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
305
794
  }
306
795
 
307
- // Include the block pending broadcast in the checkpoint proposal if any
308
- const lastBlock = blockPendingBroadcast && {
309
- blockHeader: blockPendingBroadcast.block.header,
310
- indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
311
- txs: blockPendingBroadcast.txs,
312
- };
796
+ // Validate the header against L1 state before broadcasting.
797
+ // If this fails the slot is aborted before any gossip work; state drift between here
798
+ // and the eventual L1 send is caught by the bundle simulate at send time.
799
+ try {
800
+ await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
801
+ } catch (err) {
802
+ this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
803
+ slot: this.targetSlot,
804
+ checkpointNumber: this.checkpointNumber,
805
+ });
806
+ this.metrics.recordCheckpointProposalFailed('header_validation_failed');
807
+ this.eventEmitter.emit('header-validation-failed', {
808
+ slot: this.targetSlot,
809
+ checkpointNumber: this.checkpointNumber,
810
+ reason: err instanceof Error ? err.message : String(err),
811
+ });
812
+ return undefined;
813
+ }
313
814
 
314
815
  // Create the checkpoint proposal and broadcast it
315
816
  const proposal = await this.validatorClient.createCheckpointProposal(
316
817
  checkpoint.header,
317
818
  checkpoint.archive.root,
819
+ this.checkpointNumber,
318
820
  feeAssetPriceModifier,
319
- lastBlock,
821
+ blockPendingBroadcast,
320
822
  this.proposer,
321
823
  checkpointProposalOptions,
322
824
  );
323
825
 
324
- const blockProposedAt = this.dateProvider.now();
325
- await this.p2pClient.broadcastCheckpointProposal(proposal);
826
+ // Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
827
+ // doesn't echo our own messages back, so this is how the proposer makes its own proposed
828
+ // checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
829
+ // from the broadcast proposal archive, which may be deliberately corrupted under test flags.
830
+ // Fail closed: if this throws, the outer catch aborts the slot before gossiping.
831
+ await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
326
832
 
327
- this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
328
- const attestations = await this.waitForAttestations(proposal);
329
- const blockAttestedAt = this.dateProvider.now();
330
-
331
- this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
332
-
333
- // Proposer must sign over the attestations before pushing them to L1
334
- const signer = this.proposer ?? this.publisher.getSenderAddress();
335
- let attestationsSignature: Signature;
336
- try {
337
- attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
338
- attestations,
339
- signer,
340
- this.slot,
341
- this.checkpointNumber,
342
- );
343
- } catch (err) {
344
- // We shouldn't really get here since we yield to another HA node
345
- // as soon as we see these errors when creating block or checkpoint proposals.
346
- if (this.handleHASigningError(err, 'Attestations signature')) {
347
- return undefined;
348
- }
349
- throw err;
350
- }
351
-
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;
833
+ const blockProposedAt = this.dateProvider.now();
834
+ if (this.config.skipBroadcastCheckpointProposal) {
835
+ // Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
836
+ // this slot, but still broadcast the held last block standalone so peers' archivers ingest
837
+ // it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
838
+ // pruneOrphanProposedBlocks / checkSync must handle.
839
+ if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
840
+ await this.p2pClient.broadcastProposal(blockPendingBroadcast);
369
841
  }
842
+ } else if (!this.config.skipBroadcastProposals) {
843
+ await this.p2pClient.broadcastCheckpointProposal(proposal);
844
+ this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
370
845
  }
371
846
 
372
- await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
373
- txTimeoutAt,
374
- forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
375
- });
376
-
377
- return checkpoint;
847
+ // Return immediately after broadcast — attestation collection happens in the background
848
+ return { checkpoint, proposal, blockProposedAt };
378
849
  } catch (err) {
379
850
  if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
380
851
  // swallow this error. It's already been logged by a function deeper in the stack
381
852
  return undefined;
382
853
  }
383
854
 
384
- this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
855
+ this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
385
856
  return undefined;
386
857
  }
387
858
  }
@@ -397,28 +868,37 @@ export class CheckpointProposalJob implements Traceable {
397
868
  blockProposalOptions: BlockProposalOptions,
398
869
  ): Promise<{
399
870
  blocksInCheckpoint: L2Block[];
400
- blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
871
+ blockPendingBroadcast: BlockProposal | undefined;
401
872
  }> {
402
873
  const blocksInCheckpoint: L2Block[] = [];
403
874
  const txHashesAlreadyIncluded = new Set<string>();
404
875
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
405
876
 
406
877
  // Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
407
- let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
878
+ let blockPendingBroadcast: BlockProposal | undefined = undefined;
408
879
 
409
880
  while (true) {
410
881
  const blocksBuilt = blocksInCheckpoint.length;
411
882
  const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
412
883
  const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
413
884
 
414
- const secondsIntoSlot = this.getSecondsIntoSlot();
415
- const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
885
+ if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
886
+ this.log.debug(`Reached max blocks per checkpoint`, {
887
+ slot: this.targetSlot,
888
+ blocksBuilt,
889
+ maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
890
+ });
891
+ break;
892
+ }
893
+
894
+ const nowSeconds = this.dateProvider.now() / 1000;
895
+ const timingInfo = this.timetable.selectNextSubslot(this.targetSlot, nowSeconds);
416
896
 
417
897
  if (!timingInfo.canStart) {
418
898
  this.log.debug(`Not enough time left in slot to start another block`, {
419
- slot: this.slot,
899
+ slot: this.targetSlot,
420
900
  blocksBuilt,
421
- secondsIntoSlot,
901
+ nowSeconds,
422
902
  });
423
903
  break;
424
904
  }
@@ -428,31 +908,29 @@ export class CheckpointProposalJob implements Traceable {
428
908
  blockTimestamp: timestamp,
429
909
  // Create an empty block if we haven't already and this is the last one
430
910
  forceCreate: timingInfo.isLastBlock && blocksBuilt === 0 && this.config.buildCheckpointIfEmpty,
431
- // Build deadline is only set if we are enforcing the timetable
432
- buildDeadline: timingInfo.deadline
433
- ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000)
434
- : undefined,
911
+ buildDeadline: new Date(timingInfo.deadline * 1000),
435
912
  blockNumber,
436
913
  indexWithinCheckpoint,
437
914
  txHashesAlreadyIncluded,
438
915
  });
439
916
 
440
- // TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
441
- if (!buildResult && timingInfo.isLastBlock) {
442
- // If no block was produced due to not enough txs and this was the last subslot, exit
443
- break;
444
- } else if (!buildResult && timingInfo.deadline !== undefined) {
445
- // But if there is still time for more blocks, wait until the next subslot and try again
917
+ // If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
918
+ if ('failure' in buildResult) {
919
+ // If this was the last subslot, we're done.
920
+ if (timingInfo.isLastBlock) {
921
+ break;
922
+ }
923
+ // Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
446
924
  await this.waitUntilNextSubslot(timingInfo.deadline);
447
925
  continue;
448
- } else if (!buildResult) {
449
- // Exit if there is no possibility of building more blocks
450
- break;
451
- } else if ('error' in buildResult) {
452
- // If there was an error building the block, just exit the loop and give up the rest of the slot
926
+ }
927
+
928
+ // If there was an error building the block, we just exit the loop and give up the rest of the slot.
929
+ // We don't want to risk building more blocks if something went wrong.
930
+ if ('error' in buildResult) {
453
931
  if (!(buildResult.error instanceof SequencerInterruptedError)) {
454
- this.log.warn(`Halting block building for slot ${this.slot}`, {
455
- slot: this.slot,
932
+ this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
933
+ slot: this.targetSlot,
456
934
  blocksBuilt,
457
935
  error: buildResult.error,
458
936
  });
@@ -461,38 +939,42 @@ export class CheckpointProposalJob implements Traceable {
461
939
  }
462
940
 
463
941
  const { block, usedTxs } = buildResult;
942
+ this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
943
+ isFirstBlock: blocksBuilt === 0,
944
+ isLastBlock: timingInfo.isLastBlock,
945
+ });
946
+
464
947
  blocksInCheckpoint.push(block);
948
+ usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
465
949
 
466
- // Sync the proposed block to the archiver to make it available
467
- // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building
468
- // If this throws, we abort the entire checkpoint
469
- await this.syncProposedBlockToArchiver(block);
950
+ // Sign the block proposal. This will throw if HA signing fails.
951
+ const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
952
+ ...blockProposalOptions,
953
+ broadcastInvalidBlockProposal:
954
+ blockProposalOptions.broadcastInvalidBlockProposal ||
955
+ block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint,
956
+ });
470
957
 
471
- usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
958
+ // Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
959
+ // so we avoid polluting our archive with a block that would fail.
960
+ // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
961
+ // If this throws, we abort the entire checkpoint.
962
+ await this.syncProposedBlockToArchiver(block);
472
963
 
473
- // If this is the last block, exit the loop now so we start collecting attestations
964
+ // If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
474
965
  if (timingInfo.isLastBlock) {
475
- this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
476
- slot: this.slot,
966
+ this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
967
+ slot: this.targetSlot,
477
968
  blockNumber,
478
969
  blocksBuilt,
479
970
  });
480
- blockPendingBroadcast = { block, txs: usedTxs };
971
+
972
+ blockPendingBroadcast = proposal;
481
973
  break;
482
974
  }
483
975
 
484
- // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
485
- // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
486
- if (!this.config.fishermanMode) {
487
- const proposal = await this.validatorClient.createBlockProposal(
488
- block.header,
489
- block.indexWithinCheckpoint,
490
- inHash,
491
- block.archive.root,
492
- usedTxs,
493
- this.proposer,
494
- blockProposalOptions,
495
- );
976
+ // Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
977
+ if (proposal && !this.config.skipBroadcastProposals) {
496
978
  await this.p2pClient.broadcastProposal(proposal);
497
979
  }
498
980
 
@@ -500,20 +982,48 @@ export class CheckpointProposalJob implements Traceable {
500
982
  await this.waitUntilNextSubslot(timingInfo.deadline);
501
983
  }
502
984
 
503
- this.log.verbose(`Block building loop completed for slot ${this.slot}`, {
504
- slot: this.slot,
985
+ this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
986
+ slot: this.targetSlot,
505
987
  blocksBuilt: blocksInCheckpoint.length,
506
988
  });
507
989
 
508
990
  return { blocksInCheckpoint, blockPendingBroadcast };
509
991
  }
510
992
 
511
- /** Sleeps until it is time to produce the next block in the slot */
993
+ /** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
994
+ private createBlockProposal(
995
+ block: L2Block,
996
+ inHash: Fr,
997
+ usedTxs: Tx[],
998
+ blockProposalOptions: BlockProposalOptions,
999
+ ): Promise<BlockProposal | undefined> {
1000
+ if (this.config.fishermanMode) {
1001
+ this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
1002
+ return Promise.resolve(undefined);
1003
+ }
1004
+ return this.validatorClient.createBlockProposal(
1005
+ block.header,
1006
+ this.checkpointNumber,
1007
+ block.indexWithinCheckpoint,
1008
+ inHash,
1009
+ block.archive.root,
1010
+ usedTxs,
1011
+ this.proposer,
1012
+ blockProposalOptions,
1013
+ );
1014
+ }
1015
+
1016
+ /**
1017
+ * Sleeps until it is time to produce the next block in the slot.
1018
+ * @param nextSubslotStart - Absolute wall-clock timestamp in seconds of the previous sub-slot deadline.
1019
+ */
512
1020
  @trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
513
- private async waitUntilNextSubslot(nextSubslotStart: number) {
514
- this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
515
- this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
516
- await this.waitUntilTimeInSlot(nextSubslotStart);
1021
+ protected async waitUntilNextSubslot(nextSubslotStart: number) {
1022
+ this.setState(SequencerState.WAITING_UNTIL_NEXT_BLOCK);
1023
+ this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s`, {
1024
+ slot: this.targetSlot,
1025
+ });
1026
+ await this.awaitInterruptibleSleep(Math.max(0, nextSubslotStart * 1000 - this.dateProvider.now()));
517
1027
  }
518
1028
 
519
1029
  /** Builds a single block. Called from the main block building loop. */
@@ -528,12 +1038,14 @@ export class CheckpointProposalJob implements Traceable {
528
1038
  buildDeadline: Date | undefined;
529
1039
  txHashesAlreadyIncluded: Set<string>;
530
1040
  },
531
- ): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
1041
+ ): Promise<
1042
+ { block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
1043
+ > {
532
1044
  const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
533
1045
  opts;
534
1046
 
535
1047
  this.log.verbose(
536
- `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
1048
+ `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
537
1049
  { ...checkpointBuilder.getConstantData(), ...opts },
538
1050
  );
539
1051
 
@@ -541,33 +1053,52 @@ export class CheckpointProposalJob implements Traceable {
541
1053
  // Wait until we have enough txs to build the block
542
1054
  const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
543
1055
  if (!canStartBuilding) {
1056
+ this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
1057
+ reason: 'insufficient_txs',
1058
+ blockNumber,
1059
+ slot: this.targetSlot,
1060
+ checkpointNumber: this.checkpointNumber,
1061
+ indexWithinCheckpoint,
1062
+ availableTxs,
1063
+ minTxs,
1064
+ });
544
1065
  this.log.warn(
545
- `Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`,
546
- { blockNumber, slot: this.slot, indexWithinCheckpoint },
1066
+ `Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
1067
+ {
1068
+ reason: 'insufficient_txs',
1069
+ blockNumber,
1070
+ slot: this.targetSlot,
1071
+ checkpointNumber: this.checkpointNumber,
1072
+ indexWithinCheckpoint,
1073
+ availableTxs,
1074
+ minTxs,
1075
+ },
547
1076
  );
548
- this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.slot });
1077
+ this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
549
1078
  this.metrics.recordBlockProposalFailed('insufficient_txs');
550
- return undefined;
1079
+ return { failure: 'insufficient-txs' };
551
1080
  }
552
1081
 
553
1082
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
554
1083
  // just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
1084
+ // Block building only executes txs, so we skip loading their proofs unless these same tx objects get attached
1085
+ // to the broadcasted proposals via publishTxsWithProposals.
555
1086
  const pendingTxs = filter(
556
- this.p2pClient.iterateEligiblePendingTxs(),
1087
+ this.p2pClient.iterateEligiblePendingTxs({ includeProof: !!this.config.publishTxsWithProposals }),
557
1088
  tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
558
1089
  );
559
1090
 
560
1091
  this.log.debug(
561
- `Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`,
562
- { slot: this.slot, blockNumber, indexWithinCheckpoint },
1092
+ `Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
1093
+ { slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
563
1094
  );
564
- this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
1095
+ this.setState(SequencerState.CREATING_BLOCK);
565
1096
 
566
- // Per-block limits derived at startup by computeBlockLimits(), further capped
1097
+ // Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
567
1098
  // by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
568
1099
  // minValidTxs is passed into the builder so it can reject the block *before* updating state.
569
1100
  const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
570
- const blockBuilderOptions: PublicProcessorLimits & { minValidTxs?: number } = {
1101
+ const blockBuilderOptions: BlockBuilderOptions = {
571
1102
  maxTransactions: this.config.maxTxsPerBlock,
572
1103
  maxBlockGas:
573
1104
  this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
@@ -576,6 +1107,9 @@ export class CheckpointProposalJob implements Traceable {
576
1107
  deadline: buildDeadline,
577
1108
  isBuildingProposal: true,
578
1109
  minValidTxs,
1110
+ maxBlocksPerCheckpoint: this.timetable.getMaxBlocksPerCheckpoint(),
1111
+ perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
1112
+ perBlockDAAllocationMultiplier: this.config.perBlockDAAllocationMultiplier,
579
1113
  };
580
1114
 
581
1115
  // Actually build the block by executing txs. The builder throws InsufficientValidTxsError
@@ -593,19 +1127,33 @@ export class CheckpointProposalJob implements Traceable {
593
1127
  await this.dropFailedTxsFromP2P(buildResult.failedTxs);
594
1128
 
595
1129
  if (buildResult.status === 'insufficient-valid-txs') {
1130
+ this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
1131
+ reason: 'insufficient_valid_txs',
1132
+ slot: this.targetSlot,
1133
+ checkpointNumber: this.checkpointNumber,
1134
+ blockNumber,
1135
+ numTxs: buildResult.processedCount,
1136
+ indexWithinCheckpoint,
1137
+ minValidTxs,
1138
+ });
596
1139
  this.log.warn(
597
- `Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
1140
+ `Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
598
1141
  {
599
- slot: this.slot,
1142
+ reason: 'insufficient_valid_txs',
1143
+ slot: this.targetSlot,
1144
+ checkpointNumber: this.checkpointNumber,
600
1145
  blockNumber,
601
1146
  numTxs: buildResult.processedCount,
602
1147
  indexWithinCheckpoint,
603
1148
  minValidTxs,
604
1149
  },
605
1150
  );
606
- this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
1151
+ this.eventEmitter.emit('block-build-failed', {
1152
+ reason: `Insufficient valid txs`,
1153
+ slot: this.targetSlot,
1154
+ });
607
1155
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
608
- return undefined;
1156
+ return { failure: 'insufficient-valid-txs' };
609
1157
  }
610
1158
 
611
1159
  // Block creation succeeded, emit stats and metrics
@@ -623,17 +1171,40 @@ export class CheckpointProposalJob implements Traceable {
623
1171
  const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
624
1172
 
625
1173
  this.log.info(
626
- `Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
1174
+ `Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
627
1175
  { blockHash, txHashes, manaPerSec, ...blockStats },
628
1176
  );
629
1177
 
630
- this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
631
- this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
1178
+ // `slot` is the target/submission slot (may be one ahead when pipelining),
1179
+ // `buildSlot` is the wall-clock slot during which the block was actually built.
1180
+ this.eventEmitter.emit('block-proposed', {
1181
+ blockNumber: block.number,
1182
+ blockHash,
1183
+ checkpointNumber: this.checkpointNumber,
1184
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
1185
+ slot: this.targetSlot,
1186
+ buildSlot: this.getBuildSlot(),
1187
+ });
1188
+ this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
632
1189
 
633
1190
  return { block, usedTxs };
634
1191
  } catch (err: any) {
635
- this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
636
- this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
1192
+ this.eventEmitter.emit('block-build-failed', {
1193
+ reason: err.message,
1194
+ slot: this.targetSlot,
1195
+ });
1196
+ this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
1197
+ reason: err instanceof Error ? err.message : String(err),
1198
+ slot: this.targetSlot,
1199
+ checkpointNumber: this.checkpointNumber,
1200
+ blockNumber,
1201
+ });
1202
+ this.log.error(`Error building block`, err, {
1203
+ reason: err instanceof Error ? err.message : String(err),
1204
+ slot: this.targetSlot,
1205
+ checkpointNumber: this.checkpointNumber,
1206
+ blockNumber,
1207
+ });
637
1208
  this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
638
1209
  this.metrics.recordFailedBlock();
639
1210
  return { error: err };
@@ -646,7 +1217,7 @@ export class CheckpointProposalJob implements Traceable {
646
1217
  pendingTxs: AsyncIterable<Tx>,
647
1218
  blockNumber: BlockNumber,
648
1219
  blockTimestamp: bigint,
649
- blockBuilderOptions: PublicProcessorLimits & { minValidTxs?: number },
1220
+ blockBuilderOptions: BlockBuilderOptions,
650
1221
  ) {
651
1222
  try {
652
1223
  const workTimer = new Timer();
@@ -678,9 +1249,9 @@ export class CheckpointProposalJob implements Traceable {
678
1249
  // We only allow a block with 0 txs in the first block of the checkpoint
679
1250
  const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
680
1251
 
681
- // Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
1252
+ // Latest time to keep waiting for txs: wait_for_txs_deadline = block_build_deadline(k) - min_block_duration.
682
1253
  const startBuildingDeadline = buildDeadline
683
- ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
1254
+ ? new Date(buildDeadline.getTime() - this.timetable.minBlockDuration * 1000)
684
1255
  : undefined;
685
1256
 
686
1257
  let availableTxs = await this.p2pClient.getPendingTxCount();
@@ -693,10 +1264,10 @@ export class CheckpointProposalJob implements Traceable {
693
1264
  }
694
1265
 
695
1266
  // Wait a bit before checking again
696
- this.setStateFn(SequencerState.WAITING_FOR_TXS, this.slot);
1267
+ this.setState(SequencerState.WAITING_FOR_TXS);
697
1268
  this.log.verbose(
698
- `Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
699
- { blockNumber, slot: this.slot, indexWithinCheckpoint },
1269
+ `Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
1270
+ { blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
700
1271
  );
701
1272
  await this.waitForTxsPollingInterval();
702
1273
  availableTxs = await this.p2pClient.getPendingTxCount();
@@ -705,15 +1276,47 @@ export class CheckpointProposalJob implements Traceable {
705
1276
  return { canStartBuilding: true, availableTxs, minTxs };
706
1277
  }
707
1278
 
1279
+ private async getSignedCommitteeAttestations(
1280
+ broadcast: CheckpointProposalBroadcast,
1281
+ ): Promise<{ attestations: CommitteeAttestationsAndSigners; attestationsSignature: Signature } | undefined> {
1282
+ const { proposal, blockProposedAt } = broadcast;
1283
+ this.setState(SequencerState.COLLECTING_ATTESTATIONS);
1284
+ const attestations = await this.waitForAttestations(proposal);
1285
+ if (!attestations) {
1286
+ return undefined;
1287
+ }
1288
+ this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
1289
+
1290
+ // Proposer must sign over the attestations before pushing them to L1
1291
+ const signer = this.proposer ?? this.publisher.getSenderAddress();
1292
+ try {
1293
+ const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
1294
+ attestations,
1295
+ signer,
1296
+ this.targetSlot,
1297
+ this.checkpointNumber,
1298
+ );
1299
+ return { attestations, attestationsSignature };
1300
+ } catch (err) {
1301
+ if (this.handleHASigningError(err, 'Attestations signature')) {
1302
+ return;
1303
+ }
1304
+ this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
1305
+ return undefined;
1306
+ }
1307
+ }
1308
+
708
1309
  /**
709
1310
  * Waits for enough attestations to be collected via p2p.
710
1311
  * This is run after all blocks for the checkpoint have been built.
711
1312
  */
712
1313
  @trackSpan('CheckpointProposalJob.waitForAttestations')
713
- private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
1314
+ private async waitForAttestations(
1315
+ proposal: CheckpointProposal,
1316
+ ): Promise<CommitteeAttestationsAndSigners | undefined> {
714
1317
  if (this.config.fishermanMode) {
715
1318
  this.log.debug('Skipping attestation collection in fisherman mode');
716
- return CommitteeAttestationsAndSigners.empty();
1319
+ return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
717
1320
  }
718
1321
 
719
1322
  const slotNumber = proposal.slotNumber;
@@ -723,25 +1326,33 @@ export class CheckpointProposalJob implements Traceable {
723
1326
  throw new Error('No committee when collecting attestations');
724
1327
  } else if (committee.length === 0) {
725
1328
  this.log.verbose(`Attesting committee is empty`);
726
- return CommitteeAttestationsAndSigners.empty();
1329
+ return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
727
1330
  } else {
728
1331
  this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
729
1332
  }
730
1333
 
731
- const numberOfRequiredAttestations = Math.floor((committee.length * 2) / 3) + 1;
1334
+ const numberOfRequiredAttestations = computeQuorum(committee.length);
732
1335
 
733
1336
  if (this.config.skipCollectingAttestations) {
734
1337
  this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
735
- const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
736
- return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
1338
+ const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
1339
+ this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
1340
+ reason: 'collect_own_only',
1341
+ });
1342
+ return new CommitteeAttestationsAndSigners(
1343
+ orderAttestations(attestations ?? [], committee),
1344
+ this.getSignatureContext(),
1345
+ );
737
1346
  }
738
1347
 
739
- const attestationTimeAllowed = this.config.enforceTimeTable
740
- ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
741
- : this.l1Constants.slotDuration;
742
- const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
1348
+ // Hard attestation-collection cutoff = the single consensus attestation_deadline (target_slot_start + S - 2E).
1349
+ const attestationDeadlineSeconds = this.timetable.getAttestationDeadline(this.targetSlot);
1350
+ const attestationDeadline = new Date(attestationDeadlineSeconds * 1000);
743
1351
 
744
- this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
1352
+ this.metrics.recordRequiredAttestations(
1353
+ numberOfRequiredAttestations,
1354
+ Math.max(0, attestationDeadline.getTime() - this.dateProvider.now()),
1355
+ );
745
1356
 
746
1357
  const collectAttestationsTimer = new Timer();
747
1358
  let collectedAttestationsCount: number = 0;
@@ -750,6 +1361,7 @@ export class CheckpointProposalJob implements Traceable {
750
1361
  proposal,
751
1362
  numberOfRequiredAttestations,
752
1363
  attestationDeadline,
1364
+ this.checkpointNumber,
753
1365
  );
754
1366
 
755
1367
  collectedAttestationsCount = attestations.length;
@@ -768,6 +1380,9 @@ export class CheckpointProposalJob implements Traceable {
768
1380
 
769
1381
  // Rollup contract requires that the signatures are provided in the order of the committee
770
1382
  const sorted = orderAttestations(trimmed, committee);
1383
+ this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
1384
+ submittedCount: trimmed.length,
1385
+ });
771
1386
 
772
1387
  // Manipulate the attestations if we've been configured to do so
773
1388
  if (
@@ -779,17 +1394,56 @@ export class CheckpointProposalJob implements Traceable {
779
1394
  return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
780
1395
  }
781
1396
 
782
- return new CommitteeAttestationsAndSigners(sorted);
1397
+ return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
783
1398
  } catch (err) {
784
1399
  if (err && err instanceof AttestationTimeoutError) {
785
1400
  collectedAttestationsCount = err.collectedCount;
1401
+ this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
1402
+ collectedCount: collectedAttestationsCount,
1403
+ reason: 'timeout',
1404
+ });
1405
+ this.log.error(
1406
+ `Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`,
1407
+ err,
1408
+ );
1409
+ } else {
1410
+ this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
1411
+ collectedCount: collectedAttestationsCount,
1412
+ reason: err instanceof Error ? err.message : String(err),
1413
+ });
1414
+ this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
786
1415
  }
787
- throw err;
1416
+ return undefined;
788
1417
  } finally {
789
1418
  this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
790
1419
  }
791
1420
  }
792
1421
 
1422
+ private logCheckpointAttestations(
1423
+ status: 'collected' | 'failed',
1424
+ committee: EthAddress[],
1425
+ attestations: CheckpointAttestation[] | undefined,
1426
+ requiredAttestations: number,
1427
+ opts: { collectedCount?: number; submittedCount?: number; reason?: string } = {},
1428
+ ) {
1429
+ const signedValidators =
1430
+ attestations
1431
+ ?.map(attestation => attestation.getSender()?.toString())
1432
+ .filter((address): address is `0x${string}` => address !== undefined) ?? [];
1433
+ const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
1434
+ const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
1435
+ this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
1436
+ slot: this.targetSlot,
1437
+ checkpointNumber: this.checkpointNumber,
1438
+ committeeSize: committee.length,
1439
+ requiredAttestations,
1440
+ collectedAttestations: collectedCount,
1441
+ ...(opts.submittedCount !== undefined && { submittedAttestations: opts.submittedCount }),
1442
+ ...(missingValidatorCount !== undefined && { missingValidatorCount }),
1443
+ ...(opts.reason !== undefined && { reason: opts.reason }),
1444
+ });
1445
+ }
1446
+
793
1447
  /** Breaks the attestations before publishing based on attack configs */
794
1448
  private manipulateAttestations(
795
1449
  slotNumber: SlotNumber,
@@ -833,7 +1487,7 @@ export class CheckpointProposalJob implements Traceable {
833
1487
  unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
834
1488
  }
835
1489
  }
836
- return new CommitteeAttestationsAndSigners(attestations);
1490
+ return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
837
1491
  }
838
1492
 
839
1493
  if (this.config.shuffleAttestationOrdering) {
@@ -855,11 +1509,11 @@ export class CheckpointProposalJob implements Traceable {
855
1509
  [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
856
1510
  }
857
1511
 
858
- const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
859
- return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
1512
+ const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
1513
+ return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
860
1514
  }
861
1515
 
862
- return new CommitteeAttestationsAndSigners(attestations);
1516
+ return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
863
1517
  }
864
1518
 
865
1519
  private async dropFailedTxsFromP2P(failedTxs: FailedTx[]) {
@@ -876,9 +1530,13 @@ export class CheckpointProposalJob implements Traceable {
876
1530
  * Adds the proposed block to the archiver so it's available via P2P.
877
1531
  * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
878
1532
  * would never receive its own block without this explicit sync.
1533
+ *
1534
+ * In fisherman mode we skip this push: the fisherman builds blocks locally for validation
1535
+ * and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
1536
+ * whenever the real proposer's block arrives from L1.
879
1537
  */
880
1538
  private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
881
- if (this.config.skipPushProposedBlocksToArchiver !== false) {
1539
+ if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
882
1540
  this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
883
1541
  blockNumber: block.number,
884
1542
  slot: block.header.globalVariables.slotNumber,
@@ -892,23 +1550,58 @@ export class CheckpointProposalJob implements Traceable {
892
1550
  await this.blockSink.addBlock(block);
893
1551
  }
894
1552
 
1553
+ /**
1554
+ * Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
1555
+ * tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
1556
+ * would never see its own proposed checkpoint and couldn't pipeline the next slot.
1557
+ *
1558
+ * Skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
1559
+ * mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
1560
+ * push would fail. All blocks were already added (and awaited) during block building, so this
1561
+ * needs no retry — they are guaranteed present by the time we get here.
1562
+ */
1563
+ private async syncProposedCheckpointToArchiver(
1564
+ checkpoint: Checkpoint,
1565
+ blockCount: number,
1566
+ feeAssetPriceModifier: bigint,
1567
+ ): Promise<void> {
1568
+ if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
1569
+ return;
1570
+ }
1571
+ const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
1572
+ this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
1573
+ checkpointNumber: this.checkpointNumber,
1574
+ slot: this.targetSlot,
1575
+ startBlock,
1576
+ blockCount,
1577
+ });
1578
+ await this.blockSink.addProposedCheckpoint({
1579
+ header: checkpoint.header,
1580
+ checkpointNumber: this.checkpointNumber,
1581
+ startBlock,
1582
+ blockCount,
1583
+ totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
1584
+ feeAssetPriceModifier,
1585
+ });
1586
+ }
1587
+
895
1588
  /** Runs fee analysis and logs checkpoint outcome as fisherman */
896
1589
  private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
897
1590
  // Perform L1 fee analysis before clearing requests
898
1591
  // The callback is invoked asynchronously after the next block is mined
899
- const feeAnalysis = await this.publisher.analyzeL1Fees(this.slot, analysis =>
1592
+ const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
900
1593
  this.metrics.recordFishermanFeeAnalysis(analysis),
901
1594
  );
902
1595
 
903
1596
  if (checkpoint) {
904
- this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.slot}`, {
1597
+ this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
905
1598
  ...checkpoint.toCheckpointInfo(),
906
1599
  ...checkpoint.getStats(),
907
1600
  feeAnalysisId: feeAnalysis?.id,
908
1601
  });
909
1602
  } else {
910
- this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
911
- slot: this.slot,
1603
+ this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
1604
+ slot: this.targetSlot,
912
1605
  feeAnalysisId: feeAnalysis?.id,
913
1606
  });
914
1607
  this.metrics.recordCheckpointProposalFailed('block_build_failed');
@@ -922,15 +1615,15 @@ export class CheckpointProposalJob implements Traceable {
922
1615
  */
923
1616
  private handleHASigningError(err: any, errorContext: string): boolean {
924
1617
  if (err instanceof DutyAlreadySignedError) {
925
- this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
926
- slot: this.slot,
1618
+ this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
1619
+ slot: this.targetSlot,
927
1620
  signedByNode: err.signedByNode,
928
1621
  });
929
1622
  return true;
930
1623
  }
931
1624
  if (err instanceof SlashingProtectionError) {
932
- this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
933
- slot: this.slot,
1625
+ this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
1626
+ slot: this.targetSlot,
934
1627
  existingMessageHash: err.existingMessageHash,
935
1628
  attemptedMessageHash: err.attemptedMessageHash,
936
1629
  });
@@ -939,26 +1632,9 @@ export class CheckpointProposalJob implements Traceable {
939
1632
  return false;
940
1633
  }
941
1634
 
942
- /** Waits until a specific time within the current slot */
943
- @trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
944
- protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
945
- const slotStartTimestamp = this.getSlotStartBuildTimestamp();
946
- const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
947
- await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
948
- }
949
-
950
1635
  /** Waits the polling interval for transactions. Extracted for test overriding. */
951
1636
  protected async waitForTxsPollingInterval(): Promise<void> {
952
- await sleep(TXS_POLLING_MS);
953
- }
954
-
955
- private getSlotStartBuildTimestamp(): number {
956
- return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
957
- }
958
-
959
- private getSecondsIntoSlot(): number {
960
- const slotStartTimestamp = this.getSlotStartBuildTimestamp();
961
- return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
1637
+ await this.awaitInterruptibleSleep(TXS_POLLING_MS);
962
1638
  }
963
1639
 
964
1640
  public getPublisher() {