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