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