@aztec/sequencer-client 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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.
- package/README.md +40 -41
- package/dest/client/sequencer-client.d.ts +16 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +18 -14
- package/dest/config.d.ts +9 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -15
- package/dest/global_variable_builder/fee_predictor.d.ts +1 -1
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_predictor.js +11 -1
- package/dest/global_variable_builder/fee_provider.d.ts +1 -1
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_provider.js +27 -5
- package/dest/global_variable_builder/global_builder.d.ts +3 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -25
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +5 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +11 -1
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +48 -8
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +4 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/index.js +1 -0
- package/dest/publisher/sequencer-publisher.d.ts +39 -10
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +403 -75
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +5 -3
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_factory.js +2 -1
- package/dest/sequencer/automine/automine_sequencer.d.ts +43 -5
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_sequencer.js +209 -19
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +28 -15
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +158 -117
- package/dest/sequencer/events.d.ts +16 -4
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- package/dest/sequencer/missing_committee.d.ts +72 -0
- package/dest/sequencer/missing_committee.d.ts.map +1 -0
- package/dest/sequencer/missing_committee.js +139 -0
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +113 -28
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +352 -162
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +18 -1
- package/package.json +29 -28
- package/src/client/sequencer-client.ts +20 -14
- package/src/config.ts +32 -16
- package/src/global_variable_builder/fee_predictor.ts +11 -1
- package/src/global_variable_builder/fee_provider.ts +27 -5
- package/src/global_variable_builder/global_builder.ts +2 -34
- package/src/index.ts +1 -10
- package/src/publisher/config.ts +22 -1
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +114 -7
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +4 -3
- package/src/publisher/l1_tx_failed_store/index.ts +1 -1
- package/src/publisher/sequencer-publisher.ts +430 -86
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +16 -6
- package/src/sequencer/automine/README.md +18 -4
- package/src/sequencer/automine/automine_factory.ts +8 -1
- package/src/sequencer/automine/automine_sequencer.ts +229 -21
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +177 -132
- package/src/sequencer/events.ts +16 -3
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/missing_committee.ts +192 -0
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +382 -176
- package/src/test/index.ts +2 -2
- package/src/test/utils.ts +33 -0
- package/dest/sequencer/chain_state_overrides.d.ts +0 -61
- package/dest/sequencer/chain_state_overrides.d.ts.map +0 -1
- package/dest/sequencer/chain_state_overrides.js +0 -98
- package/dest/sequencer/timetable.d.ts +0 -101
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -231
- package/src/sequencer/chain_state_overrides.ts +0 -162
- package/src/sequencer/timetable.ts +0 -295
|
@@ -18,9 +18,18 @@ import type {
|
|
|
18
18
|
ProposedCheckpointSink,
|
|
19
19
|
ValidateCheckpointResult,
|
|
20
20
|
} from '@aztec/stdlib/block';
|
|
21
|
-
import
|
|
21
|
+
import {
|
|
22
|
+
type Checkpoint,
|
|
23
|
+
type ProposedCheckpointData,
|
|
24
|
+
buildCheckpointSimulationOverridesPlan,
|
|
25
|
+
} from '@aztec/stdlib/checkpoint';
|
|
22
26
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
23
|
-
import { getEpochAtSlot
|
|
27
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
28
|
+
import {
|
|
29
|
+
MIN_PER_BLOCK_ALLOCATION_MULTIPLIER,
|
|
30
|
+
MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER,
|
|
31
|
+
computeNetworkTxGasLimits,
|
|
32
|
+
} from '@aztec/stdlib/gas';
|
|
24
33
|
import {
|
|
25
34
|
type ResolvedSequencerConfig,
|
|
26
35
|
type SequencerConfig,
|
|
@@ -30,6 +39,7 @@ import {
|
|
|
30
39
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
31
40
|
import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
32
41
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
42
|
+
import { ProposerTimetable, buildProposerTimetable } from '@aztec/stdlib/timetable';
|
|
33
43
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
34
44
|
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
35
45
|
|
|
@@ -39,14 +49,14 @@ import { DefaultSequencerConfig } from '../config.js';
|
|
|
39
49
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
40
50
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
41
51
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
42
|
-
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
43
52
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
44
53
|
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
45
54
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
46
|
-
import { SequencerInterruptedError
|
|
55
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
47
56
|
import type { SequencerEvents } from './events.js';
|
|
48
57
|
import { SequencerMetrics } from './metrics.js';
|
|
49
|
-
import {
|
|
58
|
+
import { logMissingCommittee } from './missing_committee.js';
|
|
59
|
+
import { RequestsTracker } from './requests_tracker.js';
|
|
50
60
|
import type { SequencerRollupConstants } from './types.js';
|
|
51
61
|
import { SequencerState } from './utils.js';
|
|
52
62
|
|
|
@@ -71,22 +81,27 @@ type SequencerSlotContext = {
|
|
|
71
81
|
* - Votes for proposals and slashes on L1
|
|
72
82
|
*/
|
|
73
83
|
export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
|
|
74
|
-
|
|
84
|
+
protected runningPromise?: RunningPromise;
|
|
75
85
|
private state = SequencerState.STOPPED;
|
|
76
86
|
private stateSlotNumber: SlotNumber | undefined;
|
|
77
|
-
|
|
87
|
+
/** Wall-clock time (ms, via the date provider) at which the current state was entered. */
|
|
88
|
+
private stateEnteredAtMs: number;
|
|
78
89
|
private metrics: SequencerMetrics;
|
|
79
90
|
private checkpointProposalJobMetrics: CheckpointProposalJobMetrics;
|
|
80
91
|
private readonly stateLog: Logger;
|
|
81
92
|
|
|
82
|
-
/** The last slot for which we attempted to perform our
|
|
83
|
-
private
|
|
93
|
+
/** The last slot for which we attempted to perform our fallback duties (votes and/or prune) with degraded block production */
|
|
94
|
+
private lastSlotForFallbackAction: SlotNumber | undefined;
|
|
95
|
+
|
|
96
|
+
/** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
|
|
97
|
+
* re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */
|
|
98
|
+
private lastInvalidationAttempt: { slot: SlotNumber; checkpointNumber: CheckpointNumber } | undefined;
|
|
84
99
|
|
|
85
|
-
/** The last
|
|
86
|
-
private
|
|
100
|
+
/** The last epoch for which we logged a "no committee" diagnostic, to avoid per-slot log spam. */
|
|
101
|
+
private lastEpochForNoCommitteeLog: EpochNumber | undefined;
|
|
87
102
|
|
|
88
103
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
89
|
-
|
|
104
|
+
protected lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
90
105
|
|
|
91
106
|
/** Last successful checkpoint proposed */
|
|
92
107
|
private lastCheckpointProposed: Checkpoint | undefined;
|
|
@@ -97,8 +112,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
97
112
|
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */
|
|
98
113
|
protected lastCheckpointProposalJob: CheckpointProposalJob | undefined;
|
|
99
114
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
115
|
+
/**
|
|
116
|
+
* In-flight fire-and-forget requests that {@link stop} interrupts and drains, and {@link pause} awaits
|
|
117
|
+
* untouched: the checkpoint proposal jobs' backgrounded L1 submissions (each job is handed this shared
|
|
118
|
+
* tracker) plus the sequencer's own fallback submissions (votes/prune when we cannot build, or
|
|
119
|
+
* escape-hatch votes). Each fallback send is gated by its wrapper publisher's interruptible target-slot
|
|
120
|
+
* sleep; the tracked interrupt wakes that sleep so the send short-circuits without publishing. A wrapper
|
|
121
|
+
* is created for a single send and is never restarted, so once interrupted its sleeper can never publish
|
|
122
|
+
* a stale-slot tx, even after the pooled publishers are restarted by a later {@link start}.
|
|
123
|
+
*/
|
|
124
|
+
protected readonly pendingRequests = new RequestsTracker();
|
|
125
|
+
|
|
126
|
+
/** Proposer schedule and block sub-slot timetable for the sequencer, rebuilt on every config update. */
|
|
127
|
+
protected timetable!: ProposerTimetable;
|
|
102
128
|
|
|
103
129
|
/** Config for the sequencer */
|
|
104
130
|
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
@@ -124,6 +150,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
124
150
|
) {
|
|
125
151
|
super();
|
|
126
152
|
this.stateLog = log.createChild('state');
|
|
153
|
+
this.stateEnteredAtMs = this.dateProvider.now();
|
|
127
154
|
|
|
128
155
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
129
156
|
if (config.fishermanMode) {
|
|
@@ -139,25 +166,119 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
139
166
|
this.updateConfig(config);
|
|
140
167
|
}
|
|
141
168
|
|
|
142
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Updates sequencer config by the defined values and rebuilds the timetable.
|
|
171
|
+
*
|
|
172
|
+
* The merged config is validated against a candidate before being committed: {@link buildTimetable} may
|
|
173
|
+
* reject the candidate (invalid timing geometry, or per-block allocation multipliers below the network
|
|
174
|
+
* minimums). On rejection we leave `this.config` and `this.timetable` untouched and rethrow, so a bad update
|
|
175
|
+
* never leaves the sequencer running with a rejected config and a stale timetable.
|
|
176
|
+
*/
|
|
143
177
|
public updateConfig(config: Partial<SequencerConfig>) {
|
|
144
178
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
179
|
+
const candidate = merge(this.config, filteredConfig);
|
|
180
|
+
let timetable: ProposerTimetable;
|
|
181
|
+
try {
|
|
182
|
+
timetable = this.buildTimetable(candidate);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
this.log.warn(`Rejecting sequencer config update: ${(err as Error).message}`, {
|
|
185
|
+
rejectedConfig: omit(filteredConfig, 'txPublicSetupAllowListExtend'),
|
|
186
|
+
});
|
|
187
|
+
throw err;
|
|
188
|
+
}
|
|
189
|
+
this.config = candidate;
|
|
190
|
+
this.timetable = timetable;
|
|
145
191
|
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Builds the proposer timetable from the given config and L1 constants via the shared
|
|
196
|
+
* {@link buildProposerTimetable} helper, so the sequencer derives the same blocks-per-checkpoint as the p2p
|
|
197
|
+
* layer and `getNodeInfo`. The fast local/e2e profile and budget clamping happen inside
|
|
198
|
+
* {@link ProposerTimetable}.
|
|
199
|
+
*
|
|
200
|
+
* Throws if the timing geometry is invalid or the per-block allocation multipliers are below the network
|
|
201
|
+
* minimums; callers must treat a throw as a rejected config and not commit it.
|
|
202
|
+
*/
|
|
203
|
+
private buildTimetable(config: ResolvedSequencerConfig): ProposerTimetable {
|
|
204
|
+
const timetable = buildProposerTimetable(config, this.l1Constants);
|
|
205
|
+
|
|
206
|
+
const maxNumberOfBlocks = timetable.getMaxBlocksPerCheckpoint();
|
|
207
|
+
this.log.info(`Sequencer timetable initialized with ${maxNumberOfBlocks} blocks per slot`, {
|
|
208
|
+
aztecSlotDuration: timetable.aztecSlotDuration,
|
|
209
|
+
ethereumSlotDuration: timetable.ethereumSlotDuration,
|
|
210
|
+
blockDuration: timetable.blockDuration,
|
|
211
|
+
minBlockDuration: timetable.minBlockDuration,
|
|
212
|
+
p2pPropagationTime: timetable.p2pPropagationTime,
|
|
213
|
+
checkpointProposalPrepareTime: timetable.checkpointProposalPrepareTime,
|
|
214
|
+
maxNumberOfBlocks,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
this.assertConfigMeetsNetworkTxLimits(config, maxNumberOfBlocks);
|
|
218
|
+
|
|
219
|
+
return timetable;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Checks this node's configured per-block allocation against the network admission limit. A node
|
|
224
|
+
* advertises and admits txs up to the limit derived from the network-minimum multipliers (see
|
|
225
|
+
* {@link computeNetworkTxGasLimits}).
|
|
226
|
+
*
|
|
227
|
+
* Fails startup (and runtime config updates) only when the configured per-block allocation *multipliers*
|
|
228
|
+
* (`perBlockAllocationMultiplier` / `perBlockDAAllocationMultiplier`) are below the network minimums: such
|
|
229
|
+
* a node would accept txs over RPC/gossip that its builder can never pack into a block regardless of block
|
|
230
|
+
* size. Operators may configure a higher (more generous) multiplier, but not a lower one.
|
|
231
|
+
*
|
|
232
|
+
* When the multipliers meet the floor but an absolute per-block gas cap (`maxDABlockGas` / `maxL2BlockGas`)
|
|
233
|
+
* shrinks the builder's effective grant below the network limit, this is legitimate operator
|
|
234
|
+
* restrictiveness — the node simply builds smaller blocks and such txs stay in the pool for other
|
|
235
|
+
* proposers — so we only log a warning rather than failing startup. Restrictive tx-count caps
|
|
236
|
+
* (`maxTxsPerBlock` / `maxTxsPerCheckpoint`) can likewise make the builder skip admitted txs; they are
|
|
237
|
+
* intentionally not modeled here for the same reason.
|
|
238
|
+
*/
|
|
239
|
+
private assertConfigMeetsNetworkTxLimits(config: ResolvedSequencerConfig, maxBlocksPerCheckpoint: number) {
|
|
240
|
+
// Mirror CheckpointBuilder.capLimitsByCheckpointBudgets: DA falls back to the general multiplier.
|
|
241
|
+
const l2Multiplier = config.perBlockAllocationMultiplier;
|
|
242
|
+
const daMultiplier = config.perBlockDAAllocationMultiplier ?? l2Multiplier;
|
|
243
|
+
|
|
244
|
+
// The allocation is monotonic in the multiplier, so a multiplier at or above the network minimum
|
|
245
|
+
// guarantees the builder grants at least the network admission limit. Checking the multipliers directly
|
|
246
|
+
// is sufficient (and strictly more conservative than modeling the resulting gas grant).
|
|
247
|
+
if (daMultiplier < MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`perBlockDAAllocationMultiplier (${daMultiplier}) is below the network minimum ` +
|
|
250
|
+
`${MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (l2Multiplier < MIN_PER_BLOCK_ALLOCATION_MULTIPLIER) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
`perBlockAllocationMultiplier (${l2Multiplier}) is below the network minimum ` +
|
|
256
|
+
`${MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Absolute per-block gas caps below the network admission limit are legitimate operator restrictiveness:
|
|
261
|
+
// the node simply builds smaller blocks and such txs stay in the pool for other proposers. Warn only.
|
|
262
|
+
const networkLimit = computeNetworkTxGasLimits({
|
|
263
|
+
maxBlocksPerCheckpoint,
|
|
264
|
+
manaCheckpointBudget: this.l1Constants.rollupManaLimit,
|
|
265
|
+
});
|
|
266
|
+
if (config.maxDABlockGas !== undefined && config.maxDABlockGas < networkLimit.daGas) {
|
|
267
|
+
this.log.warn(
|
|
268
|
+
`Sequencer maxDABlockGas (${config.maxDABlockGas}) is below the network DA admission limit ` +
|
|
269
|
+
`(${networkLimit.daGas}): txs declaring more DA gas are admitted over RPC/gossip but will be skipped ` +
|
|
270
|
+
`by this proposer's own blocks and left in the pool for other proposers.`,
|
|
271
|
+
{ maxDABlockGas: config.maxDABlockGas, networkDaGas: networkLimit.daGas, maxBlocksPerCheckpoint },
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (config.maxL2BlockGas !== undefined && config.maxL2BlockGas < networkLimit.l2Gas) {
|
|
275
|
+
this.log.warn(
|
|
276
|
+
`Sequencer maxL2BlockGas (${config.maxL2BlockGas}) is below the network L2 admission limit ` +
|
|
277
|
+
`(${networkLimit.l2Gas}): txs declaring more L2 gas are admitted over RPC/gossip but will be skipped ` +
|
|
278
|
+
`by this proposer's own blocks and left in the pool for other proposers.`,
|
|
279
|
+
{ maxL2BlockGas: config.maxL2BlockGas, networkL2Gas: networkLimit.l2Gas, maxBlocksPerCheckpoint },
|
|
280
|
+
);
|
|
281
|
+
}
|
|
161
282
|
}
|
|
162
283
|
|
|
163
284
|
/** Initializes the sequencer (precomputes tables). Takes about 3s. */
|
|
@@ -165,8 +286,22 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
165
286
|
getKzg();
|
|
166
287
|
}
|
|
167
288
|
|
|
168
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* Starts (or restarts) the sequencer and moves it to the IDLE state. Idempotent: a start while already
|
|
291
|
+
* running is a no-op, so it never orphans the previous poll loop. A start while STOPPING throws, since the
|
|
292
|
+
* in-flight stop would mark the fresh loop's state STOPPED and orphan it — silently doing nothing would
|
|
293
|
+
* leave the caller believing the sequencer is running when it is on its way to STOPPED. Safe to call after
|
|
294
|
+
* a previous {@link stop} has resolved; the caller must also restart the publishers (see
|
|
295
|
+
* {@link SequencerClient.start}) so L1 publishing is re-enabled.
|
|
296
|
+
*/
|
|
169
297
|
public start() {
|
|
298
|
+
if (this.state === SequencerState.STOPPING) {
|
|
299
|
+
throw new Error('Cannot start sequencer while it is stopping');
|
|
300
|
+
}
|
|
301
|
+
if (this.runningPromise?.isRunning()) {
|
|
302
|
+
this.log.warn('Attempted to start sequencer that is already running');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
170
305
|
this.runningPromise = new RunningPromise(
|
|
171
306
|
this.safeWork.bind(this),
|
|
172
307
|
this.log,
|
|
@@ -182,33 +317,63 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
182
317
|
return this.runningPromise?.trigger();
|
|
183
318
|
}
|
|
184
319
|
|
|
185
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* Stops the sequencer from building blocks and moves it to STOPPED state, interrupting the in-flight
|
|
322
|
+
* work() iteration and its pending L1 submissions for a fast shutdown, then draining before returning.
|
|
323
|
+
* Idempotent: a second call while already stopped or stopping is a no-op. Lifecycle calls are expected
|
|
324
|
+
* to be serialized by the caller. For a restartable pause that lets in-flight work finish untouched
|
|
325
|
+
* (e.g. around a test clock warp), use {@link pause} instead.
|
|
326
|
+
*/
|
|
186
327
|
public async stop(): Promise<void> {
|
|
328
|
+
if (this.state === SequencerState.STOPPED || this.state === SequencerState.STOPPING) {
|
|
329
|
+
this.log.debug(`Sequencer already ${this.state.toLowerCase()}, ignoring stop`);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
187
332
|
this.log.info(`Stopping sequencer`);
|
|
188
333
|
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
334
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
189
335
|
await this.publisherFactory.stopAll();
|
|
336
|
+
// Stop the poll loop and await the in-flight work() iteration. work() registers its fire-and-forget
|
|
337
|
+
// requests synchronously before returning, so once the loop has stopped, pendingRequests holds every
|
|
338
|
+
// request that will ever exist. Interrupting any earlier could miss a request registered by the last
|
|
339
|
+
// in-flight iteration.
|
|
190
340
|
await this.runningPromise?.stop();
|
|
191
|
-
|
|
341
|
+
this.pendingRequests.interruptRequests();
|
|
342
|
+
await this.pendingRequests.awaitRequests();
|
|
192
343
|
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
193
344
|
this.log.info('Stopped sequencer');
|
|
194
345
|
}
|
|
195
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Gracefully pauses block production so the sequencer can later be resumed with {@link start}: halts the
|
|
349
|
+
* poll loop and waits for the in-flight work() iteration and every pending L1 submission / fallback send
|
|
350
|
+
* to finish, without interrupting them. No interrupt lands mid-build, so no spurious checkpoint-error is
|
|
351
|
+
* emitted and no enqueued checkpoint is dropped. Deliberately does not stop inner services (validator/HA
|
|
352
|
+
* signer, publishers), so the slashing-protection store stays open and the sequencer stays restartable.
|
|
353
|
+
* Used by tests that pause sequencers around an L1 clock warp. Idempotent.
|
|
354
|
+
*/
|
|
355
|
+
public async pause(): Promise<void> {
|
|
356
|
+
if (!this.runningPromise?.isRunning()) {
|
|
357
|
+
this.log.debug('Sequencer not running, ignoring pause');
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this.log.info('Pausing sequencer');
|
|
361
|
+
// Halt the poll loop and let the in-flight iteration finish naturally — no interrupt, and no STOPPING
|
|
362
|
+
// state, since entering STOPPING would make the iteration's own setState calls throw and fail it.
|
|
363
|
+
// work() registers its fire-and-forget requests synchronously before returning, so once the loop has
|
|
364
|
+
// stopped pendingRequests holds every request that will ever exist; awaiting it lets them all finish.
|
|
365
|
+
await this.runningPromise.stop();
|
|
366
|
+
await this.pendingRequests.awaitRequests();
|
|
367
|
+
this.log.info('Paused sequencer');
|
|
368
|
+
}
|
|
369
|
+
|
|
196
370
|
/** Main sequencer loop with a try/catch */
|
|
197
371
|
protected async safeWork() {
|
|
198
372
|
try {
|
|
199
373
|
await this.work();
|
|
200
374
|
} catch (err) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
[SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(err.proposedState)
|
|
204
|
-
) {
|
|
205
|
-
// No need to alert if we just didn't get to start in time
|
|
206
|
-
this.log.debug(err.message, { now: this.dateProvider.nowInSeconds() });
|
|
207
|
-
} else {
|
|
208
|
-
// Re-throw other errors
|
|
209
|
-
this.emit('checkpoint-error', { error: err as Error });
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
375
|
+
this.emit('checkpoint-error', { error: err as Error });
|
|
376
|
+
throw err;
|
|
212
377
|
} finally {
|
|
213
378
|
this.setState(SequencerState.IDLE, undefined);
|
|
214
379
|
}
|
|
@@ -271,9 +436,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
271
436
|
/** Returns slot and target slot from a single clock snapshot. */
|
|
272
437
|
protected getSlotContextInNextL1Slot(): SequencerSlotContext {
|
|
273
438
|
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
274
|
-
const targetSlot = SlotNumber(
|
|
275
|
-
slot + (this.epochCache.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0),
|
|
276
|
-
);
|
|
439
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
277
440
|
return { slot, targetSlot, epoch, targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants), ts, nowSeconds };
|
|
278
441
|
}
|
|
279
442
|
|
|
@@ -291,14 +454,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
291
454
|
ts: bigint,
|
|
292
455
|
nowSeconds: bigint,
|
|
293
456
|
): Promise<CheckpointProposalJob | undefined> {
|
|
294
|
-
// Check we have not already processed this target slot (cheapest check)
|
|
295
|
-
|
|
296
|
-
// running against actual time (eg when we use sandbox-style automining)
|
|
297
|
-
if (
|
|
298
|
-
this.lastSlotForCheckpointProposalJob &&
|
|
299
|
-
this.lastSlotForCheckpointProposalJob >= targetSlot &&
|
|
300
|
-
this.config.enforceTimeTable
|
|
301
|
-
) {
|
|
457
|
+
// Check we have not already processed this target slot (cheapest check).
|
|
458
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot) {
|
|
302
459
|
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
303
460
|
return undefined;
|
|
304
461
|
}
|
|
@@ -320,12 +477,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
320
477
|
return undefined;
|
|
321
478
|
}
|
|
322
479
|
|
|
323
|
-
//
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
480
|
+
// Cheap proposer check first: most nodes are not the proposer for most slots, so gate the
|
|
481
|
+
// expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
|
|
482
|
+
// here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
|
|
483
|
+
// the build-start deadline gate runs only on the proposer build path after a successful checkSync.
|
|
484
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
329
485
|
|
|
330
486
|
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
331
487
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
@@ -333,8 +489,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
333
489
|
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
334
490
|
|
|
335
491
|
if (isEscapeHatchOpen) {
|
|
336
|
-
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
337
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
338
492
|
if (canPropose) {
|
|
339
493
|
await this.tryVoteWhenEscapeHatchOpen({ slot, targetSlot, proposer });
|
|
340
494
|
} else {
|
|
@@ -347,6 +501,50 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
347
501
|
return undefined;
|
|
348
502
|
}
|
|
349
503
|
|
|
504
|
+
// If we are not the proposer, check whether we should invalidate an invalid pending chain (a
|
|
505
|
+
// liveness backstop) and bail before any sync work or build-timing gate. This reads only the
|
|
506
|
+
// archiver's pending-chain validation status, which is authoritative on its own, instead of
|
|
507
|
+
// running the full sync check. Wrapped in try/catch because this leaner path skips the broader
|
|
508
|
+
// proposed-checkpoint/tip coherence screen that checkSync applied, so transient archiver
|
|
509
|
+
// incoherence surfaces as a quiet skip rather than a work-loop error.
|
|
510
|
+
if (!canPropose) {
|
|
511
|
+
try {
|
|
512
|
+
const pendingChainValidationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
513
|
+
await this.considerInvalidatingCheckpoint(pendingChainValidationStatus, slot);
|
|
514
|
+
} catch (err) {
|
|
515
|
+
this.log.warn(`Failed to consider invalidating checkpoint`, { err, slot, targetSlot });
|
|
516
|
+
}
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Explicit build-loop entry gate: if we are past the latest useful block-building start for the
|
|
521
|
+
// target slot, abandon building for this slot. The proposer prioritizes the ideal L1-publish path
|
|
522
|
+
// and does not plan around the late consensus-handoff path. This is the proposer build path's
|
|
523
|
+
// timing gate; it runs only after we know we are the synced proposer, so non-proposer invalidation
|
|
524
|
+
// and escape-hatch voting (which returned above) are never gated by build timing. Vote-only paths
|
|
525
|
+
// still run when block building is abandoned.
|
|
526
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
527
|
+
const nowForStartGate = this.dateProvider.now() / 1000;
|
|
528
|
+
if (nowForStartGate > startDeadline) {
|
|
529
|
+
this.log.debug(`Past start deadline for slot ${targetSlot}, abandoning block building`, {
|
|
530
|
+
targetSlot,
|
|
531
|
+
nowForStartGate,
|
|
532
|
+
startDeadline,
|
|
533
|
+
});
|
|
534
|
+
// Mark the slot as attempted so a deadline abort is not retried within the same slot. Vote-only actions
|
|
535
|
+
// still need to run because sync can succeed even when it is too late to start building a checkpoint.
|
|
536
|
+
await this.tryVoteAndPruneWhenCannotBuild({ slot, targetSlot });
|
|
537
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
538
|
+
return undefined;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// We are the proposer, the escape hatch is closed, and we have time before the build start deadline.
|
|
542
|
+
// Now run the full sync check before building.
|
|
543
|
+
const syncedTo = await this.checkSync({ ts, slot });
|
|
544
|
+
if (!syncedTo) {
|
|
545
|
+
return undefined;
|
|
546
|
+
}
|
|
547
|
+
|
|
350
548
|
// Next checkpoint follows from the last synced one
|
|
351
549
|
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
352
550
|
|
|
@@ -360,15 +558,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
360
558
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
361
559
|
};
|
|
362
560
|
|
|
363
|
-
//
|
|
364
|
-
this.setState(SequencerState.PROPOSER_CHECK,
|
|
365
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
366
|
-
|
|
367
|
-
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
368
|
-
if (!canPropose) {
|
|
369
|
-
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
370
|
-
return undefined;
|
|
371
|
-
}
|
|
561
|
+
// We are the synced proposer within the build window; enter the proposer-check state and build.
|
|
562
|
+
this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
|
|
372
563
|
|
|
373
564
|
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
374
565
|
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
@@ -398,13 +589,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
398
589
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
399
590
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
400
591
|
|
|
401
|
-
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
402
|
-
|
|
403
592
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
404
593
|
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
405
594
|
// will invalidate the currently invalid checkpoint on L1.
|
|
406
595
|
const invalidateCheckpoint =
|
|
407
|
-
|
|
596
|
+
syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid
|
|
408
597
|
? undefined
|
|
409
598
|
: await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
410
599
|
|
|
@@ -413,7 +602,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
413
602
|
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
414
603
|
let archiveForCheck = syncedTo.archive;
|
|
415
604
|
|
|
416
|
-
if (
|
|
605
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
417
606
|
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
418
607
|
this.log.verbose(
|
|
419
608
|
`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`,
|
|
@@ -439,8 +628,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
439
628
|
// plus the parent checkpoint cell and fee header when pipelining.
|
|
440
629
|
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
441
630
|
checkpointNumber,
|
|
442
|
-
proposedCheckpointData:
|
|
443
|
-
isPipelining && syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
631
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
444
632
|
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
445
633
|
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
446
634
|
rollup: this.rollupContract,
|
|
@@ -464,7 +652,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
464
652
|
this.emit('preparing-checkpoint', {
|
|
465
653
|
targetSlot,
|
|
466
654
|
checkpointNumber,
|
|
467
|
-
hadProposedParent:
|
|
655
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
468
656
|
provenOverride,
|
|
469
657
|
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
470
658
|
});
|
|
@@ -526,13 +714,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
526
714
|
...logCtx,
|
|
527
715
|
...proposeContext,
|
|
528
716
|
proposer,
|
|
529
|
-
pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled(),
|
|
530
717
|
},
|
|
531
718
|
);
|
|
532
719
|
|
|
533
720
|
// Create and return the checkpoint proposal job
|
|
534
721
|
return this.createCheckpointProposalJob(
|
|
535
|
-
slot,
|
|
536
722
|
targetSlot,
|
|
537
723
|
targetEpoch,
|
|
538
724
|
checkpointNumber,
|
|
@@ -547,7 +733,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
547
733
|
}
|
|
548
734
|
|
|
549
735
|
protected createCheckpointProposalJob(
|
|
550
|
-
slot: SlotNumber,
|
|
551
736
|
targetSlot: SlotNumber,
|
|
552
737
|
targetEpoch: EpochNumber,
|
|
553
738
|
checkpointNumber: CheckpointNumber,
|
|
@@ -560,7 +745,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
560
745
|
proposedCheckpointData?: ProposedCheckpointData,
|
|
561
746
|
): CheckpointProposalJob {
|
|
562
747
|
return new CheckpointProposalJob(
|
|
563
|
-
slot,
|
|
564
748
|
targetSlot,
|
|
565
749
|
targetEpoch,
|
|
566
750
|
checkpointNumber,
|
|
@@ -588,6 +772,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
588
772
|
this.metrics,
|
|
589
773
|
this.checkpointProposalJobMetrics.createRecorder(),
|
|
590
774
|
this,
|
|
775
|
+
this.pendingRequests,
|
|
591
776
|
this.setState.bind(this),
|
|
592
777
|
this.tracer,
|
|
593
778
|
this.log.getBindings(),
|
|
@@ -603,9 +788,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
603
788
|
}
|
|
604
789
|
|
|
605
790
|
/**
|
|
606
|
-
* Internal helper for setting the sequencer state
|
|
791
|
+
* Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
|
|
792
|
+
* records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
|
|
607
793
|
* @param proposedState - The new state to transition to.
|
|
608
|
-
* @param slotNumber - The
|
|
794
|
+
* @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
|
|
795
|
+
* and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
|
|
609
796
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
610
797
|
*/
|
|
611
798
|
protected setState(
|
|
@@ -621,16 +808,14 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
621
808
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
622
809
|
return;
|
|
623
810
|
}
|
|
624
|
-
|
|
625
|
-
if (slotNumber !== undefined) {
|
|
626
|
-
secondsIntoSlot = this.getSecondsIntoSlot(slotNumber);
|
|
627
|
-
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
628
|
-
}
|
|
811
|
+
const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
|
|
629
812
|
|
|
630
813
|
const oldState = this.state;
|
|
631
814
|
const oldStateSlotNumber = this.stateSlotNumber;
|
|
632
815
|
const stateChanged = proposedState !== oldState;
|
|
633
|
-
|
|
816
|
+
// Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
|
|
817
|
+
// calls, read from the date provider so it tracks simulated time under a test/manual clock.
|
|
818
|
+
const transitionAtMs = this.dateProvider.now();
|
|
634
819
|
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
635
820
|
|
|
636
821
|
const boringStates = [SequencerState.IDLE, SequencerState.SYNCHRONIZING];
|
|
@@ -641,15 +826,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
641
826
|
newState: proposedState,
|
|
642
827
|
slotNumber,
|
|
643
828
|
stateSlotNumber: oldStateSlotNumber,
|
|
644
|
-
|
|
829
|
+
secondsIntoBuildFrame,
|
|
645
830
|
...(stateChanged && { stateDurationMs: Math.ceil(stateDurationMs) }),
|
|
646
831
|
});
|
|
647
832
|
|
|
648
833
|
this.emit('state-changed', {
|
|
649
834
|
oldState,
|
|
650
835
|
newState: proposedState,
|
|
651
|
-
|
|
652
|
-
|
|
836
|
+
secondsIntoBuildFrame,
|
|
837
|
+
targetSlot: slotNumber,
|
|
653
838
|
});
|
|
654
839
|
if (stateChanged) {
|
|
655
840
|
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
@@ -682,9 +867,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
682
867
|
number: syncSummary.latestBlockNumber,
|
|
683
868
|
hash: syncSummary.latestBlockHash,
|
|
684
869
|
})),
|
|
685
|
-
this.l2BlockSource
|
|
686
|
-
.getL2Tips()
|
|
687
|
-
.then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed, proposedCheckpoint: t.proposedCheckpoint })),
|
|
870
|
+
this.l2BlockSource.getL2Tips().then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed })),
|
|
688
871
|
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
689
872
|
this.l1ToL2MessageSource.getL2Tips().then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed })),
|
|
690
873
|
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
@@ -729,46 +912,29 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
729
912
|
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
730
913
|
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
731
914
|
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
915
|
+
// `getProposedCheckpointData()` returns the latest proposed checkpoint payload, which is always
|
|
916
|
+
// the leading one (a proposed entry is only stored beyond the confirmed frontier and is deleted
|
|
917
|
+
// on confirmation). It carries no tip, so there is no tip-vs-payload split read to reconcile.
|
|
732
918
|
if (
|
|
733
919
|
blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number &&
|
|
734
|
-
|
|
735
|
-
proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber)
|
|
920
|
+
proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber
|
|
736
921
|
) {
|
|
737
|
-
|
|
922
|
+
const logCtx = {
|
|
738
923
|
blockCheckpointNumber: blockData.checkpointNumber,
|
|
739
924
|
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
740
|
-
proposedCheckpointTipNumber:
|
|
741
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
925
|
+
proposedCheckpointTipNumber: proposedCheckpointData?.checkpointNumber,
|
|
742
926
|
blockNumber: blockData.header.getBlockNumber(),
|
|
743
927
|
blockSlot: blockData.header.getSlot(),
|
|
744
928
|
syncedL2Slot,
|
|
745
929
|
...args,
|
|
746
|
-
}
|
|
747
|
-
return undefined;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
930
|
+
};
|
|
751
931
|
|
|
752
|
-
|
|
753
|
-
// (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
|
|
754
|
-
// write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
|
|
755
|
-
// no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
|
|
756
|
-
// window — the next checkSync tick will see a coherent snapshot.
|
|
757
|
-
if (
|
|
758
|
-
hasProposedCheckpoint &&
|
|
759
|
-
(!proposedCheckpointData ||
|
|
760
|
-
proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)
|
|
761
|
-
) {
|
|
762
|
-
this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
|
|
763
|
-
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
764
|
-
checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
|
|
765
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
766
|
-
syncedL2Slot,
|
|
767
|
-
...args,
|
|
768
|
-
});
|
|
932
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
769
933
|
return undefined;
|
|
770
934
|
}
|
|
771
935
|
|
|
936
|
+
const hasProposedCheckpoint = proposedCheckpointData !== undefined;
|
|
937
|
+
|
|
772
938
|
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
773
939
|
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
774
940
|
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
@@ -805,9 +971,17 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
805
971
|
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
806
972
|
} catch (e) {
|
|
807
973
|
if (e instanceof NoCommitteeError) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
this.
|
|
974
|
+
const targetEpoch = getEpochAtSlot(targetSlot, this.l1Constants);
|
|
975
|
+
if (this.lastEpochForNoCommitteeLog !== targetEpoch) {
|
|
976
|
+
this.lastEpochForNoCommitteeLog = targetEpoch;
|
|
977
|
+
await logMissingCommittee(targetSlot, targetEpoch, {
|
|
978
|
+
epochCache: this.epochCache,
|
|
979
|
+
rollupContract: this.rollupContract,
|
|
980
|
+
l2BlockSource: this.l2BlockSource,
|
|
981
|
+
l1Constants: this.l1Constants,
|
|
982
|
+
dateProvider: this.dateProvider,
|
|
983
|
+
logger: this.log,
|
|
984
|
+
});
|
|
811
985
|
}
|
|
812
986
|
return [false, undefined];
|
|
813
987
|
}
|
|
@@ -844,36 +1018,29 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
844
1018
|
}
|
|
845
1019
|
|
|
846
1020
|
/**
|
|
847
|
-
* Tries to vote on slashing actions and governance
|
|
848
|
-
* This allows the sequencer to participate in governance/slashing votes even when it
|
|
1021
|
+
* Tries to vote on slashing actions and governance and to prune when we cannot build and are past the
|
|
1022
|
+
* block-building window. This allows the sequencer to participate in governance/slashing votes even when it
|
|
1023
|
+
* cannot build blocks, and to prune the pending chain so it can recover from bad data that is blocking sync.
|
|
849
1024
|
*/
|
|
850
|
-
@trackSpan('
|
|
851
|
-
protected async
|
|
1025
|
+
@trackSpan('Sequencer.tryVoteAndPruneWhenCannotBuild', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
1026
|
+
protected async tryVoteAndPruneWhenCannotBuild(args: { slot: SlotNumber; targetSlot: SlotNumber }): Promise<void> {
|
|
852
1027
|
const { slot, targetSlot } = args;
|
|
853
1028
|
|
|
854
1029
|
// Prevent duplicate attempts in the same slot
|
|
855
|
-
if (this.
|
|
856
|
-
this.log.trace(`Already attempted
|
|
1030
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1031
|
+
this.log.trace(`Already attempted fallback actions in slot ${slot} (skipping)`);
|
|
857
1032
|
return;
|
|
858
1033
|
}
|
|
859
1034
|
|
|
860
|
-
//
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
866
|
-
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
867
|
-
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
868
|
-
secondsIntoSlot,
|
|
869
|
-
maxAllowedTime,
|
|
870
|
-
});
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
1035
|
+
// Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
|
|
1036
|
+
// Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
|
|
1037
|
+
// build-start deadline can miss the whole fallback window when the target advances with the clock.
|
|
1038
|
+
const nowSeconds = this.dateProvider.now() / 1000;
|
|
1039
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
873
1040
|
|
|
874
|
-
this.log.trace(`
|
|
875
|
-
|
|
876
|
-
|
|
1041
|
+
this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
|
|
1042
|
+
nowSeconds,
|
|
1043
|
+
startDeadline,
|
|
877
1044
|
});
|
|
878
1045
|
|
|
879
1046
|
// Check if we're a proposer or proposal is open
|
|
@@ -884,7 +1051,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
884
1051
|
}
|
|
885
1052
|
|
|
886
1053
|
// Mark this slot as attempted
|
|
887
|
-
this.
|
|
1054
|
+
this.lastSlotForFallbackAction = slot;
|
|
888
1055
|
|
|
889
1056
|
// Get a publisher for voting
|
|
890
1057
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
@@ -909,19 +1076,41 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
909
1076
|
const votesPromises = voter.enqueueVotes();
|
|
910
1077
|
const votes = await Promise.all(votesPromises);
|
|
911
1078
|
|
|
912
|
-
if (
|
|
913
|
-
|
|
1079
|
+
// Even if we cannot build, try to prune so a stuck pending chain (e.g. bad data blocking sync) can
|
|
1080
|
+
// recover. prune() is permissionless, so it rides the same fallback multicall as the votes.
|
|
1081
|
+
const pruneEnqueued = await this.tryEnqueuePruneIfPrunable(targetSlot, publisher);
|
|
1082
|
+
|
|
1083
|
+
// Bail if nothing to do
|
|
1084
|
+
if (votes.every(p => !p) && !pruneEnqueued) {
|
|
1085
|
+
this.log.debug(`Nothing to enqueue for slot ${slot} (no votes, not prunable)`);
|
|
914
1086
|
return;
|
|
915
1087
|
}
|
|
916
1088
|
|
|
917
|
-
|
|
1089
|
+
const [governanceVoteEnqueued, slashingVoteEnqueued] = votes;
|
|
1090
|
+
this.log.info(`Submitting fallback requests in slot ${slot} despite sync failure`, {
|
|
1091
|
+
slot,
|
|
1092
|
+
pruneEnqueued,
|
|
1093
|
+
governanceVoteEnqueued: !!governanceVoteEnqueued,
|
|
1094
|
+
slashingVoteEnqueued: !!slashingVoteEnqueued,
|
|
1095
|
+
});
|
|
1096
|
+
|
|
918
1097
|
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
919
1098
|
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
920
1099
|
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
921
|
-
// work loop while waiting for the target slot to start.
|
|
922
|
-
|
|
923
|
-
this.log.error(`Failed to publish
|
|
1100
|
+
// work loop while waiting for the target slot to start, but track it so stop() can drain it.
|
|
1101
|
+
const send = publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
1102
|
+
this.log.error(`Failed to publish fallback requests despite sync failure for slot ${slot}`, err, { slot });
|
|
924
1103
|
});
|
|
1104
|
+
this.pendingRequests.trackRequest(send, () => publisher.interrupt());
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
private async tryEnqueuePruneIfPrunable(targetSlot: SlotNumber, publisher: SequencerPublisher): Promise<boolean> {
|
|
1108
|
+
try {
|
|
1109
|
+
return await publisher.enqueuePruneIfPrunable(targetSlot);
|
|
1110
|
+
} catch (err) {
|
|
1111
|
+
this.log.error(`Failed to enqueue rollup prune for slot ${targetSlot}`, err, { targetSlot });
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
925
1114
|
}
|
|
926
1115
|
|
|
927
1116
|
/**
|
|
@@ -937,13 +1126,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
937
1126
|
const { slot, targetSlot, proposer } = args;
|
|
938
1127
|
|
|
939
1128
|
// Prevent duplicate attempts in the same slot
|
|
940
|
-
if (this.
|
|
1129
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
941
1130
|
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
942
1131
|
return;
|
|
943
1132
|
}
|
|
944
1133
|
|
|
945
1134
|
// Mark this slot as attempted
|
|
946
|
-
this.
|
|
1135
|
+
this.lastSlotForFallbackAction = slot;
|
|
947
1136
|
|
|
948
1137
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
949
1138
|
|
|
@@ -956,8 +1145,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
956
1145
|
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
957
1146
|
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
958
1147
|
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
959
|
-
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
960
|
-
// disabled `targetSlot == slot` and `sendRequestsAt` resolves with no extra sleep.
|
|
1148
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
961
1149
|
const voter = new CheckpointVoter(
|
|
962
1150
|
targetSlot,
|
|
963
1151
|
publisher,
|
|
@@ -983,10 +1171,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
983
1171
|
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
984
1172
|
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
985
1173
|
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
986
|
-
// waiting for the target slot to start, mirroring
|
|
987
|
-
|
|
1174
|
+
// waiting for the target slot to start, mirroring tryVoteAndPruneWhenCannotBuild, but tracked so
|
|
1175
|
+
// stop() can drain it.
|
|
1176
|
+
const send = publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
988
1177
|
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, { slot, targetSlot });
|
|
989
1178
|
});
|
|
1179
|
+
this.pendingRequests.trackRequest(send, () => publisher.interrupt());
|
|
990
1180
|
}
|
|
991
1181
|
|
|
992
1182
|
/**
|
|
@@ -994,17 +1184,34 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
994
1184
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
995
1185
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
996
1186
|
* and if they fail, any sequencer will try as well.
|
|
1187
|
+
* @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
|
|
1188
|
+
* @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
|
|
997
1189
|
*/
|
|
998
1190
|
protected async considerInvalidatingCheckpoint(
|
|
999
|
-
|
|
1191
|
+
pendingChainValidationStatus: ValidateCheckpointResult,
|
|
1000
1192
|
currentSlot: SlotNumber,
|
|
1001
1193
|
): Promise<void> {
|
|
1002
|
-
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
1003
1194
|
if (pendingChainValidationStatus.valid) {
|
|
1004
1195
|
return;
|
|
1005
1196
|
}
|
|
1006
1197
|
|
|
1007
1198
|
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1199
|
+
|
|
1200
|
+
// Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
|
|
1201
|
+
// The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
|
|
1202
|
+
// the same slot is not suppressed — and is set only after a request is successfully simulated below,
|
|
1203
|
+
// so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
|
|
1204
|
+
if (
|
|
1205
|
+
this.lastInvalidationAttempt?.slot === currentSlot &&
|
|
1206
|
+
this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber
|
|
1207
|
+
) {
|
|
1208
|
+
this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
|
|
1209
|
+
currentSlot,
|
|
1210
|
+
invalidCheckpointNumber,
|
|
1211
|
+
});
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1008
1215
|
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1009
1216
|
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
1010
1217
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
@@ -1014,7 +1221,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1014
1221
|
|
|
1015
1222
|
const logData = {
|
|
1016
1223
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1017
|
-
syncedL2Slot,
|
|
1018
1224
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1019
1225
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1020
1226
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -1067,6 +1273,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1067
1273
|
return;
|
|
1068
1274
|
}
|
|
1069
1275
|
|
|
1276
|
+
// We produced a valid invalidation request; record it so further ticks within this slot skip the
|
|
1277
|
+
// committee lookup, simulation, and submission above for this same invalid checkpoint.
|
|
1278
|
+
this.lastInvalidationAttempt = { slot: currentSlot, checkpointNumber: invalidCheckpointNumber };
|
|
1279
|
+
|
|
1070
1280
|
this.log.info(
|
|
1071
1281
|
invalidateAsCommitteeMember
|
|
1072
1282
|
? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member`
|
|
@@ -1113,13 +1323,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1113
1323
|
});
|
|
1114
1324
|
}
|
|
1115
1325
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
private
|
|
1121
|
-
const
|
|
1122
|
-
return Number((this.dateProvider.now() / 1000 -
|
|
1326
|
+
/**
|
|
1327
|
+
* Wall-clock seconds elapsed since the build-frame start of the given target slot
|
|
1328
|
+
* (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
|
|
1329
|
+
*/
|
|
1330
|
+
private getSecondsIntoBuildFrame(targetSlot: SlotNumber): number {
|
|
1331
|
+
const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
|
|
1332
|
+
return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
|
|
1123
1333
|
}
|
|
1124
1334
|
|
|
1125
1335
|
public get aztecSlotDuration() {
|
|
@@ -1150,10 +1360,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1150
1360
|
public getConfig() {
|
|
1151
1361
|
return this.config;
|
|
1152
1362
|
}
|
|
1153
|
-
|
|
1154
|
-
private get l1PublishingTime(): number {
|
|
1155
|
-
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1156
|
-
}
|
|
1157
1363
|
}
|
|
1158
1364
|
|
|
1159
1365
|
type SequencerSyncCheckResult = {
|