@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,20 +1,31 @@
1
1
  import { getKzg } from '@aztec/blob-lib';
2
- import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
3
- import type { EpochCache } from '@aztec/epoch-cache';
2
+ import { type EpochCache, PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec/epoch-cache';
4
3
  import { NoCommitteeError, type RollupContract } from '@aztec/ethereum/contracts';
5
4
  import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
6
5
  import { merge, omit, pick } from '@aztec/foundation/collection';
7
6
  import { Fr } from '@aztec/foundation/curves/bn254';
8
7
  import { EthAddress } from '@aztec/foundation/eth-address';
9
- import { createLogger } from '@aztec/foundation/log';
8
+ import { type Logger, createLogger } from '@aztec/foundation/log';
10
9
  import { RunningPromise } from '@aztec/foundation/running-promise';
11
10
  import type { DateProvider } from '@aztec/foundation/timer';
12
11
  import type { TypedEventEmitter } from '@aztec/foundation/types';
13
12
  import type { P2P } from '@aztec/p2p';
14
13
  import type { SlasherClientInterface } from '@aztec/slasher';
15
- import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
16
- import type { Checkpoint } from '@aztec/stdlib/checkpoint';
17
- import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
14
+ import type {
15
+ BlockData,
16
+ L2BlockSink,
17
+ L2BlockSource,
18
+ ProposedCheckpointSink,
19
+ ValidateCheckpointResult,
20
+ } from '@aztec/stdlib/block';
21
+ import type { Checkpoint, ProposedCheckpointData } from '@aztec/stdlib/checkpoint';
22
+ import type { ChainConfig } from '@aztec/stdlib/config';
23
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
24
+ import {
25
+ MIN_PER_BLOCK_ALLOCATION_MULTIPLIER,
26
+ MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER,
27
+ computeNetworkTxGasLimits,
28
+ } from '@aztec/stdlib/gas';
18
29
  import {
19
30
  type ResolvedSequencerConfig,
20
31
  type SequencerConfig,
@@ -22,8 +33,9 @@ import {
22
33
  type WorldStateSynchronizer,
23
34
  } from '@aztec/stdlib/interfaces/server';
24
35
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
36
+ import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
25
37
  import { pickFromSchema } from '@aztec/stdlib/schemas';
26
- import { MerkleTreeId } from '@aztec/stdlib/trees';
38
+ import { ProposerTimetable, buildProposerTimetable } from '@aztec/stdlib/timetable';
27
39
  import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
28
40
  import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
29
41
 
@@ -33,17 +45,28 @@ import { DefaultSequencerConfig } from '../config.js';
33
45
  import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
34
46
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
35
47
  import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
48
+ import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
36
49
  import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
50
+ import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
37
51
  import { CheckpointVoter } from './checkpoint_voter.js';
38
- import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
52
+ import { SequencerInterruptedError } from './errors.js';
39
53
  import type { SequencerEvents } from './events.js';
40
54
  import { SequencerMetrics } from './metrics.js';
41
- import { SequencerTimetable } from './timetable.js';
42
55
  import type { SequencerRollupConstants } from './types.js';
43
56
  import { SequencerState } from './utils.js';
44
57
 
45
58
  export { SequencerState };
46
59
 
60
+ /** Slot snapshot used to prepare a checkpoint proposal. */
61
+ type SequencerSlotContext = {
62
+ slot: SlotNumber;
63
+ targetSlot: SlotNumber;
64
+ epoch: EpochNumber;
65
+ targetEpoch: EpochNumber;
66
+ ts: bigint;
67
+ nowSeconds: bigint;
68
+ };
69
+
47
70
  /**
48
71
  * Sequencer client
49
72
  * - Checks whether it is elected as proposer for the next slot
@@ -55,16 +78,25 @@ export { SequencerState };
55
78
  export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
56
79
  private runningPromise?: RunningPromise;
57
80
  private state = SequencerState.STOPPED;
81
+ private stateSlotNumber: SlotNumber | undefined;
82
+ /** Wall-clock time (ms, via the date provider) at which the current state was entered. */
83
+ private stateEnteredAtMs: number;
58
84
  private metrics: SequencerMetrics;
85
+ private checkpointProposalJobMetrics: CheckpointProposalJobMetrics;
86
+ private readonly stateLog: Logger;
59
87
 
60
88
  /** The last slot for which we attempted to perform our voting duties with degraded block production */
61
89
  private lastSlotForFallbackVote: SlotNumber | undefined;
62
90
 
91
+ /** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
92
+ * re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */
93
+ private lastInvalidationAttempt: { slot: SlotNumber; checkpointNumber: CheckpointNumber } | undefined;
94
+
63
95
  /** The last slot for which we logged "no committee" warning, to avoid spam */
64
96
  private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
65
97
 
66
98
  /** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
67
- private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
99
+ protected lastSlotForCheckpointProposalJob: SlotNumber | undefined;
68
100
 
69
101
  /** Last successful checkpoint proposed */
70
102
  private lastCheckpointProposed: Checkpoint | undefined;
@@ -72,11 +104,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
72
104
  /** The last epoch for which we logged strategy comparison in fisherman mode. */
73
105
  private lastEpochForStrategyComparison: EpochNumber | undefined;
74
106
 
75
- /** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
76
- protected timetable!: SequencerTimetable;
107
+ /** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */
108
+ protected lastCheckpointProposalJob: CheckpointProposalJob | undefined;
109
+
110
+ /** Proposer schedule and block sub-slot timetable for the sequencer, rebuilt on every config update. */
111
+ protected timetable!: ProposerTimetable;
77
112
 
78
113
  /** Config for the sequencer */
79
114
  protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
115
+ private readonly signatureContext: CoordinationSignatureContext;
80
116
 
81
117
  constructor(
82
118
  protected publisherFactory: SequencerPublisherFactory,
@@ -85,45 +121,148 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
85
121
  protected p2pClient: P2P,
86
122
  protected worldState: WorldStateSynchronizer,
87
123
  protected slasherClient: SlasherClientInterface | undefined,
88
- protected l2BlockSource: L2BlockSource & L2BlockSink,
124
+ protected l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink,
89
125
  protected l1ToL2MessageSource: L1ToL2MessageSource,
90
126
  protected checkpointsBuilder: FullNodeCheckpointsBuilder,
91
127
  protected l1Constants: SequencerRollupConstants,
92
128
  protected dateProvider: DateProvider,
93
129
  protected epochCache: EpochCache,
94
130
  protected rollupContract: RollupContract,
95
- config: SequencerConfig,
131
+ config: SequencerConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>,
96
132
  protected telemetry: TelemetryClient = getTelemetryClient(),
97
133
  protected log = createLogger('sequencer'),
98
134
  ) {
99
135
  super();
136
+ this.stateLog = log.createChild('state');
137
+ this.stateEnteredAtMs = this.dateProvider.now();
100
138
 
101
139
  // Add [FISHERMAN] prefix to logger if in fisherman mode
102
140
  if (config.fishermanMode) {
103
141
  this.log = log.createChild('[FISHERMAN]');
104
142
  }
105
143
 
144
+ this.signatureContext = {
145
+ chainId: config.l1ChainId,
146
+ rollupAddress: config.rollupAddress,
147
+ };
106
148
  this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
149
+ this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
107
150
  this.updateConfig(config);
108
151
  }
109
152
 
110
- /** Updates sequencer config by the defined values and updates the timetable */
153
+ /**
154
+ * Updates sequencer config by the defined values and rebuilds the timetable.
155
+ *
156
+ * The merged config is validated against a candidate before being committed: {@link buildTimetable} may
157
+ * reject the candidate (invalid timing geometry, or per-block allocation multipliers below the network
158
+ * minimums). On rejection we leave `this.config` and `this.timetable` untouched and rethrow, so a bad update
159
+ * never leaves the sequencer running with a rejected config and a stale timetable.
160
+ */
111
161
  public updateConfig(config: Partial<SequencerConfig>) {
112
162
  const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
163
+ const candidate = merge(this.config, filteredConfig);
164
+ let timetable: ProposerTimetable;
165
+ try {
166
+ timetable = this.buildTimetable(candidate);
167
+ } catch (err) {
168
+ this.log.warn(`Rejecting sequencer config update: ${(err as Error).message}`, {
169
+ rejectedConfig: omit(filteredConfig, 'txPublicSetupAllowListExtend'),
170
+ });
171
+ throw err;
172
+ }
173
+ this.config = candidate;
174
+ this.timetable = timetable;
113
175
  this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
114
- this.config = merge(this.config, filteredConfig);
115
- this.timetable = new SequencerTimetable(
116
- {
117
- ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
118
- aztecSlotDuration: this.aztecSlotDuration,
119
- l1PublishingTime: this.l1PublishingTime,
120
- p2pPropagationTime: this.config.attestationPropagationTime,
121
- blockDurationMs: this.config.blockDurationMs,
122
- enforce: this.config.enforceTimeTable,
123
- },
124
- this.metrics,
125
- this.log,
126
- );
176
+ }
177
+
178
+ /**
179
+ * Builds the proposer timetable from the given config and L1 constants via the shared
180
+ * {@link buildProposerTimetable} helper, so the sequencer derives the same blocks-per-checkpoint as the p2p
181
+ * layer and `getNodeInfo`. The fast local/e2e profile and budget clamping happen inside
182
+ * {@link ProposerTimetable}.
183
+ *
184
+ * Throws if the timing geometry is invalid or the per-block allocation multipliers are below the network
185
+ * minimums; callers must treat a throw as a rejected config and not commit it.
186
+ */
187
+ private buildTimetable(config: ResolvedSequencerConfig): ProposerTimetable {
188
+ const timetable = buildProposerTimetable(config, this.l1Constants);
189
+
190
+ const maxNumberOfBlocks = timetable.getMaxBlocksPerCheckpoint();
191
+ this.log.info(`Sequencer timetable initialized with ${maxNumberOfBlocks} blocks per slot`, {
192
+ aztecSlotDuration: timetable.aztecSlotDuration,
193
+ ethereumSlotDuration: timetable.ethereumSlotDuration,
194
+ blockDuration: timetable.blockDuration,
195
+ minBlockDuration: timetable.minBlockDuration,
196
+ p2pPropagationTime: timetable.p2pPropagationTime,
197
+ checkpointProposalPrepareTime: timetable.checkpointProposalPrepareTime,
198
+ maxNumberOfBlocks,
199
+ });
200
+
201
+ this.assertConfigMeetsNetworkTxLimits(config, maxNumberOfBlocks);
202
+
203
+ return timetable;
204
+ }
205
+
206
+ /**
207
+ * Checks this node's configured per-block allocation against the network admission limit. A node
208
+ * advertises and admits txs up to the limit derived from the network-minimum multipliers (see
209
+ * {@link computeNetworkTxGasLimits}).
210
+ *
211
+ * Fails startup (and runtime config updates) only when the configured per-block allocation *multipliers*
212
+ * (`perBlockAllocationMultiplier` / `perBlockDAAllocationMultiplier`) are below the network minimums: such
213
+ * a node would accept txs over RPC/gossip that its builder can never pack into a block regardless of block
214
+ * size. Operators may configure a higher (more generous) multiplier, but not a lower one.
215
+ *
216
+ * When the multipliers meet the floor but an absolute per-block gas cap (`maxDABlockGas` / `maxL2BlockGas`)
217
+ * shrinks the builder's effective grant below the network limit, this is legitimate operator
218
+ * restrictiveness — the node simply builds smaller blocks and such txs stay in the pool for other
219
+ * proposers — so we only log a warning rather than failing startup. Restrictive tx-count caps
220
+ * (`maxTxsPerBlock` / `maxTxsPerCheckpoint`) can likewise make the builder skip admitted txs; they are
221
+ * intentionally not modeled here for the same reason.
222
+ */
223
+ private assertConfigMeetsNetworkTxLimits(config: ResolvedSequencerConfig, maxBlocksPerCheckpoint: number) {
224
+ // Mirror CheckpointBuilder.capLimitsByCheckpointBudgets: DA falls back to the general multiplier.
225
+ const l2Multiplier = config.perBlockAllocationMultiplier;
226
+ const daMultiplier = config.perBlockDAAllocationMultiplier ?? l2Multiplier;
227
+
228
+ // The allocation is monotonic in the multiplier, so a multiplier at or above the network minimum
229
+ // guarantees the builder grants at least the network admission limit. Checking the multipliers directly
230
+ // is sufficient (and strictly more conservative than modeling the resulting gas grant).
231
+ if (daMultiplier < MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER) {
232
+ throw new Error(
233
+ `perBlockDAAllocationMultiplier (${daMultiplier}) is below the network minimum ` +
234
+ `${MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`,
235
+ );
236
+ }
237
+ if (l2Multiplier < MIN_PER_BLOCK_ALLOCATION_MULTIPLIER) {
238
+ throw new Error(
239
+ `perBlockAllocationMultiplier (${l2Multiplier}) is below the network minimum ` +
240
+ `${MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`,
241
+ );
242
+ }
243
+
244
+ // Absolute per-block gas caps below the network admission limit are legitimate operator restrictiveness:
245
+ // the node simply builds smaller blocks and such txs stay in the pool for other proposers. Warn only.
246
+ const networkLimit = computeNetworkTxGasLimits({
247
+ maxBlocksPerCheckpoint,
248
+ manaCheckpointBudget: this.l1Constants.rollupManaLimit,
249
+ });
250
+ if (config.maxDABlockGas !== undefined && config.maxDABlockGas < networkLimit.daGas) {
251
+ this.log.warn(
252
+ `Sequencer maxDABlockGas (${config.maxDABlockGas}) is below the network DA admission limit ` +
253
+ `(${networkLimit.daGas}): txs declaring more DA gas are admitted over RPC/gossip but will be skipped ` +
254
+ `by this proposer's own blocks and left in the pool for other proposers.`,
255
+ { maxDABlockGas: config.maxDABlockGas, networkDaGas: networkLimit.daGas, maxBlocksPerCheckpoint },
256
+ );
257
+ }
258
+ if (config.maxL2BlockGas !== undefined && config.maxL2BlockGas < networkLimit.l2Gas) {
259
+ this.log.warn(
260
+ `Sequencer maxL2BlockGas (${config.maxL2BlockGas}) is below the network L2 admission limit ` +
261
+ `(${networkLimit.l2Gas}): txs declaring more L2 gas are admitted over RPC/gossip but will be skipped ` +
262
+ `by this proposer's own blocks and left in the pool for other proposers.`,
263
+ { maxL2BlockGas: config.maxL2BlockGas, networkL2Gas: networkLimit.l2Gas, maxBlocksPerCheckpoint },
264
+ );
265
+ }
127
266
  }
128
267
 
129
268
  /** Initializes the sequencer (precomputes tables). Takes about 3s. */
@@ -143,12 +282,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
143
282
  this.log.info('Started sequencer');
144
283
  }
145
284
 
285
+ /** Triggers an immediate run of the sequencer, bypassing the polling interval. */
286
+ public trigger() {
287
+ return this.runningPromise?.trigger();
288
+ }
289
+
146
290
  /** Stops the sequencer from building blocks and moves to STOPPED state. */
147
291
  public async stop(): Promise<void> {
148
292
  this.log.info(`Stopping sequencer`);
149
293
  this.setState(SequencerState.STOPPING, undefined, { force: true });
150
- this.publisherFactory.interruptAll();
294
+ this.lastCheckpointProposalJob?.interrupt();
295
+ await this.publisherFactory.stopAll();
151
296
  await this.runningPromise?.stop();
297
+ await this.lastCheckpointProposalJob?.awaitPendingSubmission();
152
298
  this.setState(SequencerState.STOPPED, undefined, { force: true });
153
299
  this.log.info('Stopped sequencer');
154
300
  }
@@ -159,18 +305,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
159
305
  await this.work();
160
306
  } catch (err) {
161
307
  this.emit('checkpoint-error', { error: err as Error });
162
- if (err instanceof SequencerTooSlowError) {
163
- // Log as warn only if we had to abort halfway through the block proposal
164
- const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
165
- err.proposedState,
166
- )
167
- ? ('debug' as const)
168
- : ('warn' as const);
169
- this.log[logLvl](err.message, { now: this.dateProvider.nowInSeconds() });
170
- } else {
171
- // Re-throw other errors
172
- throw err;
173
- }
308
+ throw err;
174
309
  } finally {
175
310
  this.setState(SequencerState.IDLE, undefined);
176
311
  }
@@ -192,14 +327,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
192
327
  @trackSpan('Sequencer.work')
193
328
  protected async work() {
194
329
  this.setState(SequencerState.SYNCHRONIZING, undefined);
195
- const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
330
+ const { slot, targetSlot, epoch, targetEpoch, ts, nowSeconds } = this.getSlotContextInNextL1Slot();
196
331
 
197
332
  // Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
198
- const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
333
+ const checkpointProposalJob = await this.prepareCheckpointProposal(
334
+ slot,
335
+ targetSlot,
336
+ epoch,
337
+ targetEpoch,
338
+ ts,
339
+ nowSeconds,
340
+ );
199
341
  if (!checkpointProposalJob) {
200
342
  return;
201
343
  }
202
344
 
345
+ // Track the job so we can await its pending L1 submission during shutdown
346
+ this.lastCheckpointProposalJob = checkpointProposalJob;
347
+
203
348
  // Execute the checkpoint proposal job
204
349
  const checkpoint = await checkpointProposalJob.execute();
205
350
 
@@ -208,64 +353,76 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
208
353
  this.lastCheckpointProposed = checkpoint;
209
354
  }
210
355
 
211
- // Log fee strategy comparison if on fisherman
356
+ // Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
212
357
  if (
213
358
  this.config.fishermanMode &&
214
- (this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)
359
+ (this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)
215
360
  ) {
216
- this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
217
- this.lastEpochForStrategyComparison = epoch;
361
+ this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
362
+ this.lastEpochForStrategyComparison = targetEpoch;
218
363
  }
219
364
 
220
365
  return checkpoint;
221
366
  }
222
367
 
368
+ /** Returns slot and target slot from a single clock snapshot. */
369
+ protected getSlotContextInNextL1Slot(): SequencerSlotContext {
370
+ const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
371
+ const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
372
+ return { slot, targetSlot, epoch, targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants), ts, nowSeconds };
373
+ }
374
+
223
375
  /**
224
376
  * Prepares the checkpoint proposal by performing all necessary checks and setup.
225
377
  * This is the initial step in the main loop.
226
378
  * @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
227
379
  */
228
380
  @trackSpan('Sequencer.prepareCheckpointProposal')
229
- private async prepareCheckpointProposal(
230
- epoch: EpochNumber,
381
+ protected async prepareCheckpointProposal(
231
382
  slot: SlotNumber,
383
+ targetSlot: SlotNumber,
384
+ epoch: EpochNumber,
385
+ targetEpoch: EpochNumber,
232
386
  ts: bigint,
233
- now: bigint,
387
+ nowSeconds: bigint,
234
388
  ): Promise<CheckpointProposalJob | undefined> {
235
- // Check we have not already processed this slot (cheapest check)
236
- // We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
237
- // running against actual time (eg when we use sandbox-style automining)
238
- if (
239
- this.lastSlotForCheckpointProposalJob &&
240
- this.lastSlotForCheckpointProposalJob >= slot &&
241
- this.config.enforceTimeTable
242
- ) {
243
- this.log.trace(`Slot ${slot} has already been processed`);
389
+ // Check we have not already processed this target slot (cheapest check).
390
+ if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot) {
391
+ this.log.trace(`Target slot ${targetSlot} has already been processed`);
244
392
  return undefined;
245
393
  }
246
394
 
247
- // But if we have already proposed for this slot, the we definitely have to skip it, automining or not
248
- if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
249
- this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
395
+ // But if we have already proposed for this slot, then we definitely have to skip it, automining or not
396
+ if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
397
+ this.log.trace(
398
+ `Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`,
399
+ );
250
400
  return undefined;
251
401
  }
252
402
 
253
- // Check all components are synced to latest as seen by the archiver (queries all subsystems)
254
- const syncedTo = await this.checkSync({ ts, slot });
255
- if (!syncedTo) {
256
- await this.tryVoteWhenSyncFails({ slot, ts });
403
+ // Test-only: skip proposing for explicitly paused slots. Attestation paths run in the validator
404
+ // client and are not gated by this hook, so paused proposers still attest to others' proposals.
405
+ if (this.config.pauseProposingForSlots?.some(s => s === targetSlot)) {
406
+ this.log.warn(`Skipping proposal for paused slot ${targetSlot} (test-only pauseProposingForSlots hook)`, {
407
+ targetSlot,
408
+ });
257
409
  return undefined;
258
410
  }
259
411
 
260
- // If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
412
+ // Cheap proposer check first: most nodes are not the proposer for most slots, so gate the
413
+ // expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
414
+ // here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
415
+ // the build-start deadline gate runs only on the proposer build path after a successful checkSync.
416
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
417
+
418
+ // If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
261
419
  // Still perform governance/slashing voting (as proposer) once per slot.
262
- const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
420
+ // When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
421
+ const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
263
422
 
264
423
  if (isEscapeHatchOpen) {
265
- this.setState(SequencerState.PROPOSER_CHECK, slot);
266
- const [canPropose, proposer] = await this.checkCanPropose(slot);
267
424
  if (canPropose) {
268
- await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
425
+ await this.tryVoteWhenEscapeHatchOpen({ slot, targetSlot, proposer });
269
426
  } else {
270
427
  this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
271
428
  slot,
@@ -276,32 +433,80 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
276
433
  return undefined;
277
434
  }
278
435
 
436
+ // If we are not the proposer, check whether we should invalidate an invalid pending chain (a
437
+ // liveness backstop) and bail before any sync work or build-timing gate. This reads only the
438
+ // archiver's pending-chain validation status, which is authoritative on its own, instead of
439
+ // running the full sync check. Wrapped in try/catch because this leaner path skips the broader
440
+ // proposed-checkpoint/tip coherence screen that checkSync applied, so transient archiver
441
+ // incoherence surfaces as a quiet skip rather than a work-loop error.
442
+ if (!canPropose) {
443
+ try {
444
+ const pendingChainValidationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
445
+ await this.considerInvalidatingCheckpoint(pendingChainValidationStatus, slot);
446
+ } catch (err) {
447
+ this.log.warn(`Failed to consider invalidating checkpoint`, { err, slot, targetSlot });
448
+ }
449
+ return undefined;
450
+ }
451
+
452
+ // We are the proposer and the escape hatch is closed: now run the full sync check before building.
453
+ const syncedTo = await this.checkSync({ ts, slot });
454
+ if (!syncedTo) {
455
+ await this.tryVoteWhenCannotBuild({ slot, targetSlot });
456
+ return undefined;
457
+ }
458
+
459
+ // Explicit build-loop entry gate: if we are past the latest useful block-building start for the
460
+ // target slot, abandon building for this slot. The proposer prioritizes the ideal L1-publish path
461
+ // and does not plan around the late consensus-handoff path. This is the proposer build path's
462
+ // timing gate; it runs only after we know we are the synced proposer, so non-proposer invalidation
463
+ // and escape-hatch voting (which returned above) are never gated by build timing. Vote-only paths
464
+ // still run when block building is abandoned.
465
+ const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
466
+ const nowForStartGate = this.dateProvider.now() / 1000;
467
+ if (nowForStartGate > startDeadline) {
468
+ this.log.debug(`Past start deadline for slot ${targetSlot}, abandoning block building`, {
469
+ targetSlot,
470
+ nowForStartGate,
471
+ startDeadline,
472
+ });
473
+ // Mark the slot as attempted so a deadline abort is not retried within the same slot. Vote-only actions
474
+ // still need to run because sync can succeed even when it is too late to start building a checkpoint.
475
+ await this.tryVoteWhenCannotBuild({ slot, targetSlot });
476
+ this.lastSlotForCheckpointProposalJob = targetSlot;
477
+ return undefined;
478
+ }
479
+
279
480
  // Next checkpoint follows from the last synced one
280
481
  const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
281
482
 
282
483
  const logCtx = {
283
- now,
484
+ nowSeconds,
284
485
  syncedToL2Slot: syncedTo.syncedL2Slot,
285
486
  slot,
487
+ targetSlot,
286
488
  slotTs: ts,
287
489
  checkpointNumber,
288
490
  isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
289
491
  };
290
492
 
291
- // Check that we are a proposer for the next slot
292
- this.setState(SequencerState.PROPOSER_CHECK, slot);
293
- const [canPropose, proposer] = await this.checkCanPropose(slot);
493
+ // We are the synced proposer within the build window; enter the proposer-check state and build.
494
+ this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
294
495
 
295
- // If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
296
- if (!canPropose) {
297
- await this.considerInvalidatingCheckpoint(syncedTo, slot);
496
+ // Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
497
+ // confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
498
+ const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
499
+ if (checkpointNumber > confirmedCkpt + 2) {
500
+ this.log.verbose(
501
+ `Skipping slot ${targetSlot}: checkpoint ${checkpointNumber} exceeds max pipeline depth (confirmed=${confirmedCkpt})`,
502
+ );
298
503
  return undefined;
299
504
  }
300
505
 
301
- // Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
302
- if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
506
+ // Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
507
+ if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
303
508
  this.log.warn(
304
- `Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
509
+ `Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`,
305
510
  { ...logCtx, block: syncedTo.blockData.header.toInspect() },
306
511
  );
307
512
  this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
@@ -316,37 +521,106 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
316
521
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
317
522
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
318
523
 
319
- // In fisherman mode, set the actual proposer's address for simulations
320
- if (this.config.fishermanMode && proposer) {
321
- publisher.setProposerAddressForSimulation(proposer);
322
- this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
524
+ // Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
525
+ // Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
526
+ // will invalidate the currently invalid checkpoint on L1.
527
+ const invalidateCheckpoint =
528
+ syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid
529
+ ? undefined
530
+ : await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
531
+
532
+ // Determine the correct archive and L1 state overrides for the canProposeAt check.
533
+ // The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
534
+ // When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
535
+ let archiveForCheck = syncedTo.archive;
536
+
537
+ if (syncedTo.hasProposedCheckpoint) {
538
+ this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
539
+ this.log.verbose(
540
+ `Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`,
541
+ { targetSlot, parentCheckpointNumber: CheckpointNumber(checkpointNumber - 1) },
542
+ );
543
+ // Match what L1 will see at archives[pending] once the proposed parent lands: the parent's
544
+ // own archive root from the gossiped proposal. `syncedTo.archive` is the world-state-local
545
+ // view and can transiently diverge from the proposed parent (e.g. before the proposed
546
+ // parent's blocks have been applied locally); diverging here would cause the canProposeAt
547
+ // override to set archives[pending] to one value while we present another for comparison.
548
+ archiveForCheck = syncedTo.proposedCheckpointData!.archive.root;
549
+ } else if (invalidateCheckpoint) {
550
+ // After invalidation, L1 will roll back to checkpoint N-1. The archive at N-1 already
551
+ // exists on L1, so we just pass the matching archive (the lastArchive of the invalid checkpoint).
552
+ archiveForCheck = invalidateCheckpoint.lastArchive;
553
+ this.metrics.recordPipelineDepth(0);
554
+ } else {
555
+ this.metrics.recordPipelineDepth(0);
323
556
  }
324
557
 
325
- // Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
326
- const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
558
+ // Build the simulation plan: pending/proven override from pipelining or invalidation (or the
559
+ // current snapshot when neither applies, to short-circuit any pending prune in simulation),
560
+ // plus the parent checkpoint cell and fee header when pipelining.
561
+ const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
562
+ checkpointNumber,
563
+ proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
564
+ invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
565
+ checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
566
+ rollup: this.rollupContract,
567
+ signatureContext: this.signatureContext,
568
+ log: this.log,
569
+ });
327
570
 
328
- // Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
329
- // if all the previous checks are good, but we do it just in case.
330
- const canProposeCheck = await publisher.canProposeAtNextEthBlock(
331
- syncedTo.archive,
571
+ // The plan always pins both pending/proven (to short-circuit `canPruneAtTime` in simulation),
572
+ // so `provenOverride` always reflects the assumed proven checkpoint we are pinning the
573
+ // simulation to. We additionally warn when the pin is load-bearing — i.e. when a prune would
574
+ // actually fire at the target slot without it — so observers can spot "we are building
575
+ // optimistically across a pruning boundary" in the logs.
576
+ const provenOverride = simulationOverridesPlan?.chainTipsOverride?.proven;
577
+ if (provenOverride !== undefined && (await this.l2BlockSource.isPruneDueAtSlot(targetSlot))) {
578
+ this.log.warn(
579
+ `Assuming proof for epoch ending at checkpoint ${provenOverride} lands by target slot ${targetSlot}`,
580
+ { checkpointNumber, slot, targetSlot, provenOverride },
581
+ );
582
+ }
583
+
584
+ this.emit('preparing-checkpoint', {
585
+ targetSlot,
586
+ checkpointNumber,
587
+ hadProposedParent: syncedTo.hasProposedCheckpoint,
588
+ provenOverride,
589
+ simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending,
590
+ });
591
+
592
+ const canProposeCheck = await publisher.canProposeAt(
593
+ archiveForCheck,
332
594
  proposer ?? EthAddress.ZERO,
333
- invalidateCheckpoint,
595
+ simulationOverridesPlan,
334
596
  );
335
597
 
598
+ const proposeContext = {
599
+ hasProposedCheckpoint: syncedTo.hasProposedCheckpoint,
600
+ proposedCheckpointNumber: syncedTo.proposedCheckpointData?.checkpointNumber,
601
+ checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
602
+ isInvalidating: !!invalidateCheckpoint,
603
+ invalidatingCheckpointNumber: invalidateCheckpoint?.checkpointNumber,
604
+ archiveForCheck: archiveForCheck.toString(),
605
+ overridePendingCheckpointNumber: simulationOverridesPlan?.chainTipsOverride?.pending,
606
+ overrideArchive: simulationOverridesPlan?.pendingCheckpointState?.archive,
607
+ overrideFeeHeader: simulationOverridesPlan?.pendingCheckpointState?.feeHeader,
608
+ };
609
+
336
610
  if (canProposeCheck === undefined) {
337
611
  this.log.warn(
338
612
  `Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
339
- logCtx,
613
+ { ...logCtx, ...proposeContext },
340
614
  );
341
615
  this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
342
616
  this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
343
617
  return undefined;
344
618
  }
345
619
 
346
- if (canProposeCheck.slot !== slot) {
620
+ if (canProposeCheck.slot !== targetSlot) {
347
621
  this.log.warn(
348
- `Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${slot} but got ${canProposeCheck.slot}.`,
349
- { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
622
+ `Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`,
623
+ { ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: targetSlot },
350
624
  );
351
625
  this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
352
626
  this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
@@ -356,45 +630,58 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
356
630
  if (canProposeCheck.checkpointNumber !== checkpointNumber) {
357
631
  this.log.warn(
358
632
  `Cannot propose due to block mismatch with rollup contract (this can be caused by a pending archiver sync). Expected checkpoint ${checkpointNumber} but got ${canProposeCheck.checkpointNumber}.`,
359
- { ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
633
+ { ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: slot },
360
634
  );
361
635
  this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
362
636
  this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
363
637
  return undefined;
364
638
  }
365
639
 
366
- this.lastSlotForCheckpointProposalJob = slot;
367
- await this.p2pClient.prepareForSlot(slot);
368
- this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
640
+ this.lastSlotForCheckpointProposalJob = targetSlot;
641
+
642
+ await this.p2pClient.prepareForSlot(targetSlot);
643
+ this.log.info(
644
+ `Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`,
645
+ {
646
+ ...logCtx,
647
+ ...proposeContext,
648
+ proposer,
649
+ },
650
+ );
369
651
 
370
652
  // Create and return the checkpoint proposal job
371
653
  return this.createCheckpointProposalJob(
372
- epoch,
373
- slot,
654
+ targetSlot,
655
+ targetEpoch,
374
656
  checkpointNumber,
375
657
  syncedTo.blockNumber,
658
+ syncedTo.checkpointedCheckpointNumber,
376
659
  proposer,
377
660
  publisher,
378
661
  attestorAddress,
379
662
  invalidateCheckpoint,
663
+ syncedTo.proposedCheckpointData,
380
664
  );
381
665
  }
382
666
 
383
667
  protected createCheckpointProposalJob(
384
- epoch: EpochNumber,
385
- slot: SlotNumber,
668
+ targetSlot: SlotNumber,
669
+ targetEpoch: EpochNumber,
386
670
  checkpointNumber: CheckpointNumber,
387
671
  syncedToBlockNumber: BlockNumber,
672
+ checkpointedCheckpointNumber: CheckpointNumber,
388
673
  proposer: EthAddress | undefined,
389
674
  publisher: SequencerPublisher,
390
675
  attestorAddress: EthAddress,
391
676
  invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
677
+ proposedCheckpointData?: ProposedCheckpointData,
392
678
  ): CheckpointProposalJob {
393
679
  return new CheckpointProposalJob(
394
- epoch,
395
- slot,
680
+ targetSlot,
681
+ targetEpoch,
396
682
  checkpointNumber,
397
683
  syncedToBlockNumber,
684
+ checkpointedCheckpointNumber,
398
685
  proposer,
399
686
  publisher,
400
687
  attestorAddress,
@@ -408,16 +695,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
408
695
  this.checkpointsBuilder,
409
696
  this.l2BlockSource,
410
697
  this.l1Constants,
698
+ this.signatureContext,
411
699
  this.config,
412
700
  this.timetable,
413
701
  this.slasherClient,
414
702
  this.epochCache,
415
703
  this.dateProvider,
416
704
  this.metrics,
705
+ this.checkpointProposalJobMetrics.createRecorder(),
417
706
  this,
418
707
  this.setState.bind(this),
419
708
  this.tracer,
420
709
  this.log.getBindings(),
710
+ proposedCheckpointData,
421
711
  );
422
712
  }
423
713
 
@@ -429,9 +719,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
429
719
  }
430
720
 
431
721
  /**
432
- * Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
722
+ * Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
723
+ * records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
433
724
  * @param proposedState - The new state to transition to.
434
- * @param slotNumber - The current slot number.
725
+ * @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
726
+ * and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
435
727
  * @param force - Whether to force the transition even if the sequencer is stopped.
436
728
  */
437
729
  protected setState(
@@ -447,25 +739,39 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
447
739
  this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
448
740
  return;
449
741
  }
450
- let secondsIntoSlot = undefined;
451
- if (slotNumber !== undefined) {
452
- secondsIntoSlot = this.getSecondsIntoSlot(slotNumber);
453
- this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
454
- }
742
+ const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
743
+
744
+ const oldState = this.state;
745
+ const oldStateSlotNumber = this.stateSlotNumber;
746
+ const stateChanged = proposedState !== oldState;
747
+ // Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
748
+ // calls, read from the date provider so it tracks simulated time under a test/manual clock.
749
+ const transitionAtMs = this.dateProvider.now();
750
+ const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
455
751
 
456
752
  const boringStates = [SequencerState.IDLE, SequencerState.SYNCHRONIZING];
457
753
  const logLevel =
458
- boringStates.includes(proposedState) && boringStates.includes(this.state)
459
- ? ('trace' as const)
460
- : ('debug' as const);
461
- this.log[logLevel](`Transitioning from ${this.state} to ${proposedState}`, { slotNumber, secondsIntoSlot });
754
+ boringStates.includes(proposedState) && boringStates.includes(oldState) ? ('trace' as const) : ('debug' as const);
755
+ this.stateLog[logLevel](`Transitioning from ${oldState} to ${proposedState}`, {
756
+ oldState,
757
+ newState: proposedState,
758
+ slotNumber,
759
+ stateSlotNumber: oldStateSlotNumber,
760
+ secondsIntoBuildFrame,
761
+ ...(stateChanged && { stateDurationMs: Math.ceil(stateDurationMs) }),
762
+ });
462
763
 
463
764
  this.emit('state-changed', {
464
- oldState: this.state,
765
+ oldState,
465
766
  newState: proposedState,
466
- secondsIntoSlot,
467
- slot: slotNumber,
767
+ secondsIntoBuildFrame,
768
+ targetSlot: slotNumber,
468
769
  });
770
+ if (stateChanged) {
771
+ this.metrics.recordStateDuration(stateDurationMs, oldState);
772
+ this.stateEnteredAtMs = transitionAtMs;
773
+ this.stateSlotNumber = slotNumber;
774
+ }
469
775
  this.state = proposedState;
470
776
  }
471
777
 
@@ -475,8 +781,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
475
781
  */
476
782
  protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
477
783
  // Check that the archiver has fully synced the L2 slot before the one we want to propose in.
478
- // TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
479
- // cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
784
+ // The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
785
+ // See getSyncedL2SlotNumber for how missed L1 blocks are handled.
480
786
  const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
481
787
  const { slot } = args;
482
788
  if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
@@ -492,45 +798,104 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
492
798
  number: syncSummary.latestBlockNumber,
493
799
  hash: syncSummary.latestBlockHash,
494
800
  })),
495
- this.l2BlockSource.getL2Tips().then(t => t.proposed),
801
+ this.l2BlockSource
802
+ .getL2Tips()
803
+ .then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed, proposedCheckpoint: t.proposedCheckpoint })),
496
804
  this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
497
- this.l1ToL2MessageSource.getL2Tips().then(t => t.proposed),
805
+ this.l1ToL2MessageSource.getL2Tips().then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed })),
498
806
  this.l2BlockSource.getPendingChainValidationStatus(),
807
+ this.l2BlockSource.getProposedCheckpointData(),
499
808
  ] as const);
500
809
 
501
- const [worldState, l2BlockSource, p2p, l1ToL2MessageSource, pendingChainValidationStatus] = syncedBlocks;
810
+ const [worldState, l2Tips, p2p, l1ToL2MessageSourceTips, pendingChainValidationStatus, proposedCheckpointData] =
811
+ syncedBlocks;
502
812
 
503
- // Handle zero as a special case, since the block hash won't match across services if we're changing the prefilled data for the genesis block,
504
- // as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
505
- // TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
506
813
  const result =
507
- (l2BlockSource.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0) ||
508
- (worldState.hash === l2BlockSource.hash &&
509
- p2p.hash === l2BlockSource.hash &&
510
- l1ToL2MessageSource.hash === l2BlockSource.hash);
814
+ worldState.hash === l2Tips.proposed.hash &&
815
+ p2p.hash === l2Tips.proposed.hash &&
816
+ l1ToL2MessageSourceTips.proposed.hash === l2Tips.proposed.hash &&
817
+ l1ToL2MessageSourceTips.checkpointed.block.hash === l2Tips.checkpointed.block.hash &&
818
+ l1ToL2MessageSourceTips.checkpointed.checkpoint.hash === l2Tips.checkpointed.checkpoint.hash;
511
819
 
512
820
  if (!result) {
513
- this.log.debug(`Sequencer sync check failed`, { worldState, l2BlockSource, p2p, l1ToL2MessageSource });
821
+ this.log.debug(`Sequencer sync check failed`, {
822
+ worldState,
823
+ l2BlockSource: l2Tips.proposed,
824
+ p2p,
825
+ l1ToL2MessageSourceTips,
826
+ });
514
827
  return undefined;
515
828
  }
516
829
 
517
- // Special case for genesis state
518
830
  const blockNumber = worldState.number;
519
- if (blockNumber < INITIAL_L2_BLOCK_NUM) {
520
- const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
521
- return {
522
- checkpointNumber: CheckpointNumber.ZERO,
523
- blockNumber: BlockNumber.ZERO,
524
- archive,
831
+ const blockData = await this.l2BlockSource.getBlockData({ number: blockNumber });
832
+ if (!blockData) {
833
+ this.log.warn(`Sequencer sync check failed: failed to get L2 block data ${blockNumber} from the archiver`, {
834
+ blockNumber,
835
+ l2Tips,
525
836
  syncedL2Slot,
526
- pendingChainValidationStatus,
837
+ ...args,
838
+ });
839
+ return undefined;
840
+ }
841
+
842
+ // Refuse to build a checkpoint on top of a proposed block whose enclosing checkpoint was never
843
+ // proposed. Under pipelining we may have received and reexecuted such a block locally — advancing
844
+ // our world-state tip past the checkpointed tip — while the proposing node never published the
845
+ // matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
846
+ // would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
847
+ // once their build slot ends; this guard is the correctness barrier during the grace window before.
848
+ if (
849
+ blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number &&
850
+ (l2Tips.proposedCheckpoint.checkpoint.number !== blockData.checkpointNumber ||
851
+ proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber)
852
+ ) {
853
+ const logCtx = {
854
+ blockCheckpointNumber: blockData.checkpointNumber,
855
+ checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
856
+ proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
857
+ proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
858
+ blockNumber: blockData.header.getBlockNumber(),
859
+ blockSlot: blockData.header.getSlot(),
860
+ syncedL2Slot,
861
+ ...args,
527
862
  };
863
+
864
+ this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
865
+ return undefined;
528
866
  }
529
867
 
530
- const blockData = await this.l2BlockSource.getBlockData(blockNumber);
531
- if (!blockData) {
532
- // this shouldn't really happen because a moment ago we checked that all components were in sync
533
- this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
868
+ const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
869
+
870
+ // The l2Tips and proposedCheckpointData reads above come from independent archiver snapshots
871
+ // (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
872
+ // write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
873
+ // no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
874
+ // window — the next checkSync tick will see a coherent snapshot.
875
+ if (
876
+ hasProposedCheckpoint &&
877
+ (!proposedCheckpointData ||
878
+ proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)
879
+ ) {
880
+ this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
881
+ proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
882
+ checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
883
+ proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
884
+ syncedL2Slot,
885
+ ...args,
886
+ });
887
+ return undefined;
888
+ }
889
+
890
+ // Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
891
+ // The checkpoint number to build is derived as blockData.checkpointNumber + 1
892
+ if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
893
+ this.log.warn(`Sequencer sync check failed: proposed checkpoint number mismatch`, {
894
+ proposedCheckpointNumber: proposedCheckpointData.checkpointNumber,
895
+ blockCheckpointNumber: blockData.checkpointNumber,
896
+ syncedL2Slot,
897
+ ...args,
898
+ });
534
899
  return undefined;
535
900
  }
536
901
 
@@ -538,7 +903,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
538
903
  blockData,
539
904
  blockNumber: blockData.header.getBlockNumber(),
540
905
  checkpointNumber: blockData.checkpointNumber,
906
+ checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
541
907
  archive: blockData.archive.root,
908
+ hasProposedCheckpoint,
909
+ proposedCheckpointData,
542
910
  syncedL2Slot,
543
911
  pendingChainValidationStatus,
544
912
  };
@@ -548,20 +916,20 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
548
916
  * Checks if we are the proposer for the next slot.
549
917
  * @returns True if we can propose, and the proposer address (undefined if anyone can propose)
550
918
  */
551
- protected async checkCanPropose(slot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
919
+ protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
552
920
  let proposer: EthAddress | undefined;
553
921
 
554
922
  try {
555
- proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
923
+ proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
556
924
  } catch (e) {
557
925
  if (e instanceof NoCommitteeError) {
558
- if (this.lastSlotForNoCommitteeWarning !== slot) {
559
- this.lastSlotForNoCommitteeWarning = slot;
560
- this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
926
+ if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
927
+ this.lastSlotForNoCommitteeWarning = targetSlot;
928
+ this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
561
929
  }
562
930
  return [false, undefined];
563
931
  }
564
- this.log.error(`Error getting proposer for slot ${slot}`, e);
932
+ this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
565
933
  return [false, undefined];
566
934
  }
567
935
 
@@ -578,20 +946,28 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
578
946
  const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
579
947
 
580
948
  if (!weAreProposer) {
581
- this.log.debug(`Cannot propose at slot ${slot} since we are not a proposer`, { validatorAddresses, proposer });
949
+ this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
950
+ targetSlot,
951
+ validatorAddresses,
952
+ proposer,
953
+ });
582
954
  return [false, proposer];
583
955
  }
584
956
 
957
+ this.log.info(`We are the proposer for pipeline slot ${targetSlot}`, {
958
+ targetSlot,
959
+ proposer,
960
+ });
585
961
  return [true, proposer];
586
962
  }
587
963
 
588
964
  /**
589
- * Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
965
+ * Tries to vote on slashing actions and governance when we cannot build and are past the block-building window.
590
966
  * This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
591
967
  */
592
- @trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
593
- protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
594
- const { slot } = args;
968
+ @trackSpan('Sequencer.tryVoteWhenCannotBuild', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
969
+ protected async tryVoteWhenCannotBuild(args: { slot: SlotNumber; targetSlot: SlotNumber }): Promise<void> {
970
+ const { slot, targetSlot } = args;
595
971
 
596
972
  // Prevent duplicate attempts in the same slot
597
973
  if (this.lastSlotForFallbackVote === slot) {
@@ -599,27 +975,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
599
975
  return;
600
976
  }
601
977
 
602
- // Check if we're past the max time for initializing a proposal
603
- const secondsIntoSlot = this.getSecondsIntoSlot(slot);
604
- const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
605
-
606
- // If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
607
- // We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
608
- if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
609
- this.log.trace(`Not attempting to vote since there is still time for block building`, {
610
- secondsIntoSlot,
611
- maxAllowedTime,
612
- });
613
- return;
614
- }
978
+ // Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
979
+ // Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
980
+ // build-start deadline can miss the whole fallback window when the target advances with the clock.
981
+ const nowSeconds = this.dateProvider.now() / 1000;
982
+ const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
615
983
 
616
- this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
617
- secondsIntoSlot,
618
- maxAllowedTime,
984
+ this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
985
+ nowSeconds,
986
+ startDeadline,
619
987
  });
620
988
 
621
989
  // Check if we're a proposer or proposal is open
622
- const [canPropose, proposer] = await this.checkCanPropose(slot);
990
+ const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
623
991
  if (!canPropose) {
624
992
  this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
625
993
  return;
@@ -636,9 +1004,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
636
1004
  slot,
637
1005
  });
638
1006
 
639
- // Enqueue governance and slashing votes
1007
+ // Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
640
1008
  const voter = new CheckpointVoter(
641
- slot,
1009
+ targetSlot,
642
1010
  publisher,
643
1011
  attestorAddress,
644
1012
  this.validatorClient,
@@ -657,7 +1025,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
657
1025
  }
658
1026
 
659
1027
  this.log.info(`Voting in slot ${slot} despite sync failure`, { slot });
660
- await publisher.sendRequests();
1028
+ // Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
1029
+ // expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
1030
+ // slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
1031
+ // work loop while waiting for the target slot to start.
1032
+ void publisher.sendRequestsAt(targetSlot).catch(err => {
1033
+ this.log.error(`Failed to publish votes despite sync failure for slot ${slot}`, err, { slot });
1034
+ });
661
1035
  }
662
1036
 
663
1037
  /**
@@ -667,9 +1041,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
667
1041
  @trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
668
1042
  protected async tryVoteWhenEscapeHatchOpen(args: {
669
1043
  slot: SlotNumber;
1044
+ targetSlot: SlotNumber;
670
1045
  proposer: EthAddress | undefined;
671
1046
  }): Promise<void> {
672
- const { slot, proposer } = args;
1047
+ const { slot, targetSlot, proposer } = args;
673
1048
 
674
1049
  // Prevent duplicate attempts in the same slot
675
1050
  if (this.lastSlotForFallbackVote === slot) {
@@ -682,10 +1057,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
682
1057
 
683
1058
  const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
684
1059
 
685
- this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, { slot, attestorAddress });
1060
+ this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
1061
+ slot,
1062
+ targetSlot,
1063
+ attestorAddress,
1064
+ });
686
1065
 
1066
+ // Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
1067
+ // Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
1068
+ // L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
1069
+ // sign for `targetSlot` and delay submission to the start of `targetSlot`.
687
1070
  const voter = new CheckpointVoter(
688
- slot,
1071
+ targetSlot,
689
1072
  publisher,
690
1073
  attestorAddress,
691
1074
  this.validatorClient,
@@ -704,8 +1087,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
704
1087
  return;
705
1088
  }
706
1089
 
707
- this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot });
708
- await publisher.sendRequests();
1090
+ this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot, targetSlot });
1091
+ // Votes are EIP-712-signed for `targetSlot`. Delay submission to the start of `targetSlot` so
1092
+ // the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
1093
+ // `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
1094
+ // silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
1095
+ // waiting for the target slot to start, mirroring tryVoteWhenCannotBuild.
1096
+ void publisher.sendRequestsAt(targetSlot).catch(err => {
1097
+ this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, { slot, targetSlot });
1098
+ });
709
1099
  }
710
1100
 
711
1101
  /**
@@ -713,17 +1103,34 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
713
1103
  * has been there without being invalidated and whether the sequencer is in the committee or not. We always
714
1104
  * have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
715
1105
  * and if they fail, any sequencer will try as well.
1106
+ * @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
1107
+ * @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
716
1108
  */
717
1109
  protected async considerInvalidatingCheckpoint(
718
- syncedTo: SequencerSyncCheckResult,
1110
+ pendingChainValidationStatus: ValidateCheckpointResult,
719
1111
  currentSlot: SlotNumber,
720
1112
  ): Promise<void> {
721
- const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
722
1113
  if (pendingChainValidationStatus.valid) {
723
1114
  return;
724
1115
  }
725
1116
 
726
1117
  const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
1118
+
1119
+ // Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
1120
+ // The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
1121
+ // the same slot is not suppressed — and is set only after a request is successfully simulated below,
1122
+ // so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
1123
+ if (
1124
+ this.lastInvalidationAttempt?.slot === currentSlot &&
1125
+ this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber
1126
+ ) {
1127
+ this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
1128
+ currentSlot,
1129
+ invalidCheckpointNumber,
1130
+ });
1131
+ return;
1132
+ }
1133
+
727
1134
  const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
728
1135
  const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
729
1136
  const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
@@ -733,7 +1140,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
733
1140
 
734
1141
  const logData = {
735
1142
  invalidL1Timestamp: invalidCheckpointTimestamp,
736
- syncedL2Slot,
737
1143
  invalidCheckpoint: pendingChainValidationStatus.checkpoint,
738
1144
  secondsBeforeInvalidatingBlockAsCommitteeMember,
739
1145
  secondsBeforeInvalidatingBlockAsNonCommitteeMember,
@@ -786,6 +1192,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
786
1192
  return;
787
1193
  }
788
1194
 
1195
+ // We produced a valid invalidation request; record it so further ticks within this slot skip the
1196
+ // committee lookup, simulation, and submission above for this same invalid checkpoint.
1197
+ this.lastInvalidationAttempt = { slot: currentSlot, checkpointNumber: invalidCheckpointNumber };
1198
+
789
1199
  this.log.info(
790
1200
  invalidateAsCommitteeMember
791
1201
  ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member`
@@ -832,13 +1242,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
832
1242
  });
833
1243
  }
834
1244
 
835
- private getSlotStartBuildTimestamp(slotNumber: SlotNumber): number {
836
- return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
837
- }
838
-
839
- private getSecondsIntoSlot(slotNumber: SlotNumber): number {
840
- const slotStartTimestamp = this.getSlotStartBuildTimestamp(slotNumber);
841
- return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
1245
+ /**
1246
+ * Wall-clock seconds elapsed since the build-frame start of the given target slot
1247
+ * (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
1248
+ */
1249
+ private getSecondsIntoBuildFrame(targetSlot: SlotNumber): number {
1250
+ const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
1251
+ return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
842
1252
  }
843
1253
 
844
1254
  public get aztecSlotDuration() {
@@ -869,17 +1279,16 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
869
1279
  public getConfig() {
870
1280
  return this.config;
871
1281
  }
872
-
873
- private get l1PublishingTime(): number {
874
- return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
875
- }
876
1282
  }
877
1283
 
878
1284
  type SequencerSyncCheckResult = {
879
1285
  blockData?: BlockData;
880
1286
  checkpointNumber: CheckpointNumber;
1287
+ checkpointedCheckpointNumber: CheckpointNumber;
881
1288
  blockNumber: BlockNumber;
882
1289
  archive: Fr;
1290
+ hasProposedCheckpoint: boolean;
1291
+ proposedCheckpointData?: ProposedCheckpointData;
883
1292
  syncedL2Slot: SlotNumber;
884
1293
  pendingChainValidationStatus: ValidateCheckpointResult;
885
1294
  };