@aztec/sequencer-client 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
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 +19 -9
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +65 -32
- package/dest/config.d.ts +28 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +76 -37
- 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 +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- 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/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- 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 +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +94 -68
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +448 -363
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -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 +85 -14
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +882 -254
- 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/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +23 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +142 -36
- package/dest/sequencer/sequencer.d.ts +85 -22
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +380 -137
- package/dest/sequencer/timetable.d.ts +14 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +47 -46
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +12 -12
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +45 -36
- package/dest/test/utils.d.ts +3 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -8
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +91 -35
- package/src/config.ts +98 -46
- 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 +75 -0
- package/src/global_variable_builder/global_builder.ts +26 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +542 -460
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1078 -290
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +164 -39
- package/src/sequencer/sequencer.ts +471 -157
- package/src/sequencer/timetable.ts +62 -56
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +65 -53
- package/src/test/utils.ts +31 -10
|
@@ -1,20 +1,26 @@
|
|
|
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, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
18
24
|
import {
|
|
19
25
|
type ResolvedSequencerConfig,
|
|
20
26
|
type SequencerConfig,
|
|
@@ -22,10 +28,11 @@ import {
|
|
|
22
28
|
type WorldStateSynchronizer,
|
|
23
29
|
} from '@aztec/stdlib/interfaces/server';
|
|
24
30
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
31
|
+
import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
25
32
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
26
|
-
import {
|
|
33
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
27
34
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
28
|
-
import { FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
|
|
35
|
+
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
29
36
|
|
|
30
37
|
import EventEmitter from 'node:events';
|
|
31
38
|
|
|
@@ -33,7 +40,9 @@ import { DefaultSequencerConfig } from '../config.js';
|
|
|
33
40
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
34
41
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
35
42
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
43
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
36
44
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
45
|
+
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
37
46
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
38
47
|
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
39
48
|
import type { SequencerEvents } from './events.js';
|
|
@@ -44,6 +53,16 @@ import { SequencerState } from './utils.js';
|
|
|
44
53
|
|
|
45
54
|
export { SequencerState };
|
|
46
55
|
|
|
56
|
+
/** Slot snapshot used to prepare a checkpoint proposal. */
|
|
57
|
+
type SequencerSlotContext = {
|
|
58
|
+
slot: SlotNumber;
|
|
59
|
+
targetSlot: SlotNumber;
|
|
60
|
+
epoch: EpochNumber;
|
|
61
|
+
targetEpoch: EpochNumber;
|
|
62
|
+
ts: bigint;
|
|
63
|
+
nowSeconds: bigint;
|
|
64
|
+
};
|
|
65
|
+
|
|
47
66
|
/**
|
|
48
67
|
* Sequencer client
|
|
49
68
|
* - Checks whether it is elected as proposer for the next slot
|
|
@@ -55,11 +74,18 @@ export { SequencerState };
|
|
|
55
74
|
export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
|
|
56
75
|
private runningPromise?: RunningPromise;
|
|
57
76
|
private state = SequencerState.STOPPED;
|
|
77
|
+
private stateSlotNumber: SlotNumber | undefined;
|
|
78
|
+
private stateEnteredAtMs = performance.now();
|
|
58
79
|
private metrics: SequencerMetrics;
|
|
80
|
+
private checkpointProposalJobMetrics: CheckpointProposalJobMetrics;
|
|
81
|
+
private readonly stateLog: Logger;
|
|
59
82
|
|
|
60
83
|
/** The last slot for which we attempted to perform our voting duties with degraded block production */
|
|
61
84
|
private lastSlotForFallbackVote: SlotNumber | undefined;
|
|
62
85
|
|
|
86
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */
|
|
87
|
+
private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
|
|
88
|
+
|
|
63
89
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
64
90
|
private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
65
91
|
|
|
@@ -69,19 +95,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
69
95
|
/** The last epoch for which we logged strategy comparison in fisherman mode. */
|
|
70
96
|
private lastEpochForStrategyComparison: EpochNumber | undefined;
|
|
71
97
|
|
|
98
|
+
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */
|
|
99
|
+
protected lastCheckpointProposalJob: CheckpointProposalJob | undefined;
|
|
100
|
+
|
|
72
101
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
|
|
73
102
|
protected timetable!: SequencerTimetable;
|
|
74
103
|
|
|
75
|
-
// This shouldn't be here as this gets re-created each time we build/propose a block.
|
|
76
|
-
// But we have a number of tests that abuse/rely on this class having a permanent publisher.
|
|
77
|
-
// As long as those tests only configure a single publisher they will continue to work.
|
|
78
|
-
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
79
|
-
// for the block proposer.
|
|
80
|
-
// TODO(palla/mbps): Remove this field and fix tests
|
|
81
|
-
protected publisher: SequencerPublisher | undefined;
|
|
82
|
-
|
|
83
104
|
/** Config for the sequencer */
|
|
84
105
|
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
106
|
+
private readonly signatureContext: CoordinationSignatureContext;
|
|
85
107
|
|
|
86
108
|
constructor(
|
|
87
109
|
protected publisherFactory: SequencerPublisherFactory,
|
|
@@ -90,39 +112,46 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
90
112
|
protected p2pClient: P2P,
|
|
91
113
|
protected worldState: WorldStateSynchronizer,
|
|
92
114
|
protected slasherClient: SlasherClientInterface | undefined,
|
|
93
|
-
protected l2BlockSource: L2BlockSource & L2BlockSink,
|
|
115
|
+
protected l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink,
|
|
94
116
|
protected l1ToL2MessageSource: L1ToL2MessageSource,
|
|
95
117
|
protected checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
96
118
|
protected l1Constants: SequencerRollupConstants,
|
|
97
119
|
protected dateProvider: DateProvider,
|
|
98
120
|
protected epochCache: EpochCache,
|
|
99
121
|
protected rollupContract: RollupContract,
|
|
100
|
-
config: SequencerConfig,
|
|
122
|
+
config: SequencerConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>,
|
|
101
123
|
protected telemetry: TelemetryClient = getTelemetryClient(),
|
|
102
124
|
protected log = createLogger('sequencer'),
|
|
103
125
|
) {
|
|
104
126
|
super();
|
|
127
|
+
this.stateLog = log.createChild('state');
|
|
105
128
|
|
|
106
129
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
107
130
|
if (config.fishermanMode) {
|
|
108
131
|
this.log = log.createChild('[FISHERMAN]');
|
|
109
132
|
}
|
|
110
133
|
|
|
134
|
+
this.signatureContext = {
|
|
135
|
+
chainId: config.l1ChainId,
|
|
136
|
+
rollupAddress: config.rollupAddress,
|
|
137
|
+
};
|
|
111
138
|
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
139
|
+
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
112
140
|
this.updateConfig(config);
|
|
113
141
|
}
|
|
114
142
|
|
|
115
143
|
/** Updates sequencer config by the defined values and updates the timetable */
|
|
116
144
|
public updateConfig(config: Partial<SequencerConfig>) {
|
|
117
145
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
118
|
-
this.log.info(`Updated sequencer config`, omit(filteredConfig, '
|
|
146
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
119
147
|
this.config = merge(this.config, filteredConfig);
|
|
148
|
+
const p2pPropagationTime = this.config.attestationPropagationTime;
|
|
120
149
|
this.timetable = new SequencerTimetable(
|
|
121
150
|
{
|
|
122
151
|
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
123
152
|
aztecSlotDuration: this.aztecSlotDuration,
|
|
124
153
|
l1PublishingTime: this.l1PublishingTime,
|
|
125
|
-
p2pPropagationTime
|
|
154
|
+
p2pPropagationTime,
|
|
126
155
|
blockDurationMs: this.config.blockDurationMs,
|
|
127
156
|
enforce: this.config.enforceTimeTable,
|
|
128
157
|
},
|
|
@@ -131,10 +160,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
131
160
|
);
|
|
132
161
|
}
|
|
133
162
|
|
|
134
|
-
/** Initializes the sequencer (precomputes tables
|
|
135
|
-
public
|
|
163
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */
|
|
164
|
+
public init() {
|
|
136
165
|
getKzg();
|
|
137
|
-
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
138
166
|
}
|
|
139
167
|
|
|
140
168
|
/** Starts the sequencer and moves to IDLE state. */
|
|
@@ -149,12 +177,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
149
177
|
this.log.info('Started sequencer');
|
|
150
178
|
}
|
|
151
179
|
|
|
180
|
+
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */
|
|
181
|
+
public trigger() {
|
|
182
|
+
return this.runningPromise?.trigger();
|
|
183
|
+
}
|
|
184
|
+
|
|
152
185
|
/** Stops the sequencer from building blocks and moves to STOPPED state. */
|
|
153
186
|
public async stop(): Promise<void> {
|
|
154
187
|
this.log.info(`Stopping sequencer`);
|
|
155
188
|
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
156
|
-
this.
|
|
189
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
190
|
+
await this.publisherFactory.stopAll();
|
|
157
191
|
await this.runningPromise?.stop();
|
|
192
|
+
await this.lastCheckpointProposalJob?.awaitPendingSubmission();
|
|
158
193
|
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
159
194
|
this.log.info('Stopped sequencer');
|
|
160
195
|
}
|
|
@@ -164,18 +199,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
164
199
|
try {
|
|
165
200
|
await this.work();
|
|
166
201
|
} catch (err) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
174
|
-
? ('debug' as const)
|
|
175
|
-
: ('warn' as const);
|
|
176
|
-
this.log[logLvl](err.message, { now: this.dateProvider.nowInSeconds() });
|
|
202
|
+
if (
|
|
203
|
+
err instanceof SequencerTooSlowError &&
|
|
204
|
+
[SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(err.proposedState)
|
|
205
|
+
) {
|
|
206
|
+
// No need to alert if we just didn't get to start in time
|
|
207
|
+
this.log.debug(err.message, { now: this.dateProvider.nowInSeconds() });
|
|
177
208
|
} else {
|
|
178
209
|
// Re-throw other errors
|
|
210
|
+
this.emit('checkpoint-error', { error: err as Error });
|
|
179
211
|
throw err;
|
|
180
212
|
}
|
|
181
213
|
} finally {
|
|
@@ -199,14 +231,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
199
231
|
@trackSpan('Sequencer.work')
|
|
200
232
|
protected async work() {
|
|
201
233
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
202
|
-
const { slot,
|
|
234
|
+
const { slot, targetSlot, epoch, targetEpoch, ts, nowSeconds } = this.getSlotContextInNextL1Slot();
|
|
203
235
|
|
|
204
236
|
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
205
|
-
const checkpointProposalJob = await this.prepareCheckpointProposal(
|
|
237
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(
|
|
238
|
+
slot,
|
|
239
|
+
targetSlot,
|
|
240
|
+
epoch,
|
|
241
|
+
targetEpoch,
|
|
242
|
+
ts,
|
|
243
|
+
nowSeconds,
|
|
244
|
+
);
|
|
206
245
|
if (!checkpointProposalJob) {
|
|
207
246
|
return;
|
|
208
247
|
}
|
|
209
248
|
|
|
249
|
+
// Track the job so we can await its pending L1 submission during shutdown
|
|
250
|
+
this.lastCheckpointProposalJob = checkpointProposalJob;
|
|
251
|
+
|
|
210
252
|
// Execute the checkpoint proposal job
|
|
211
253
|
const checkpoint = await checkpointProposalJob.execute();
|
|
212
254
|
|
|
@@ -215,64 +257,85 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
215
257
|
this.lastCheckpointProposed = checkpoint;
|
|
216
258
|
}
|
|
217
259
|
|
|
218
|
-
// Log fee strategy comparison if on fisherman
|
|
260
|
+
// Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
|
|
219
261
|
if (
|
|
220
262
|
this.config.fishermanMode &&
|
|
221
|
-
(this.lastEpochForStrategyComparison === undefined ||
|
|
263
|
+
(this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)
|
|
222
264
|
) {
|
|
223
|
-
this.logStrategyComparison(
|
|
224
|
-
this.lastEpochForStrategyComparison =
|
|
265
|
+
this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
|
|
266
|
+
this.lastEpochForStrategyComparison = targetEpoch;
|
|
225
267
|
}
|
|
226
268
|
|
|
227
269
|
return checkpoint;
|
|
228
270
|
}
|
|
229
271
|
|
|
272
|
+
/** Returns slot and target slot from a single clock snapshot. */
|
|
273
|
+
protected getSlotContextInNextL1Slot(): SequencerSlotContext {
|
|
274
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
275
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
276
|
+
return { slot, targetSlot, epoch, targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants), ts, nowSeconds };
|
|
277
|
+
}
|
|
278
|
+
|
|
230
279
|
/**
|
|
231
280
|
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
232
281
|
* This is the initial step in the main loop.
|
|
233
282
|
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
234
283
|
*/
|
|
235
284
|
@trackSpan('Sequencer.prepareCheckpointProposal')
|
|
236
|
-
|
|
237
|
-
epoch: EpochNumber,
|
|
285
|
+
protected async prepareCheckpointProposal(
|
|
238
286
|
slot: SlotNumber,
|
|
287
|
+
targetSlot: SlotNumber,
|
|
288
|
+
epoch: EpochNumber,
|
|
289
|
+
targetEpoch: EpochNumber,
|
|
239
290
|
ts: bigint,
|
|
240
|
-
|
|
291
|
+
nowSeconds: bigint,
|
|
241
292
|
): Promise<CheckpointProposalJob | undefined> {
|
|
242
|
-
// Check we have not already processed this slot (cheapest check)
|
|
293
|
+
// Check we have not already processed this target slot (cheapest check)
|
|
243
294
|
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
244
295
|
// running against actual time (eg when we use sandbox-style automining)
|
|
245
296
|
if (
|
|
246
297
|
this.lastSlotForCheckpointProposalJob &&
|
|
247
|
-
this.lastSlotForCheckpointProposalJob >=
|
|
298
|
+
this.lastSlotForCheckpointProposalJob >= targetSlot &&
|
|
248
299
|
this.config.enforceTimeTable
|
|
249
300
|
) {
|
|
250
|
-
this.log.trace(`
|
|
301
|
+
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// But if we have already proposed for this slot, then we definitely have to skip it, automining or not
|
|
306
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
|
|
307
|
+
this.log.trace(
|
|
308
|
+
`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`,
|
|
309
|
+
);
|
|
251
310
|
return undefined;
|
|
252
311
|
}
|
|
253
312
|
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
313
|
+
// Test-only: skip proposing for explicitly paused slots. Attestation paths run in the validator
|
|
314
|
+
// client and are not gated by this hook, so paused proposers still attest to others' proposals.
|
|
315
|
+
if (this.config.pauseProposingForSlots?.some(s => s === targetSlot)) {
|
|
316
|
+
this.log.warn(`Skipping proposal for paused slot ${targetSlot} (test-only pauseProposingForSlots hook)`, {
|
|
317
|
+
targetSlot,
|
|
318
|
+
});
|
|
257
319
|
return undefined;
|
|
258
320
|
}
|
|
259
321
|
|
|
260
322
|
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
261
323
|
const syncedTo = await this.checkSync({ ts, slot });
|
|
262
324
|
if (!syncedTo) {
|
|
263
|
-
await this.tryVoteWhenSyncFails({ slot, ts });
|
|
325
|
+
await this.tryVoteWhenSyncFails({ slot, targetSlot, ts });
|
|
264
326
|
return undefined;
|
|
265
327
|
}
|
|
266
328
|
|
|
267
|
-
// If escape hatch is open for
|
|
329
|
+
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
268
330
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
269
|
-
|
|
331
|
+
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
332
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
270
333
|
|
|
271
334
|
if (isEscapeHatchOpen) {
|
|
272
335
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
273
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
336
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
274
337
|
if (canPropose) {
|
|
275
|
-
await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
|
|
338
|
+
await this.tryVoteWhenEscapeHatchOpen({ slot, targetSlot, proposer });
|
|
276
339
|
} else {
|
|
277
340
|
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
278
341
|
slot,
|
|
@@ -287,18 +350,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
287
350
|
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
288
351
|
|
|
289
352
|
const logCtx = {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
353
|
+
nowSeconds,
|
|
354
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
293
355
|
slot,
|
|
356
|
+
targetSlot,
|
|
294
357
|
slotTs: ts,
|
|
295
358
|
checkpointNumber,
|
|
296
359
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
297
360
|
};
|
|
298
361
|
|
|
299
|
-
// Check that we are a proposer for the
|
|
362
|
+
// Check that we are a proposer for the target slot.
|
|
300
363
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
301
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
364
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
302
365
|
|
|
303
366
|
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
304
367
|
if (!canPropose) {
|
|
@@ -306,13 +369,23 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
306
369
|
return undefined;
|
|
307
370
|
}
|
|
308
371
|
|
|
309
|
-
//
|
|
310
|
-
|
|
372
|
+
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
373
|
+
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
374
|
+
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
375
|
+
if (checkpointNumber > confirmedCkpt + 2) {
|
|
376
|
+
this.log.verbose(
|
|
377
|
+
`Skipping slot ${targetSlot}: checkpoint ${checkpointNumber} exceeds max pipeline depth (confirmed=${confirmedCkpt})`,
|
|
378
|
+
);
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
383
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
|
|
311
384
|
this.log.warn(
|
|
312
|
-
`Cannot propose block at
|
|
313
|
-
{ ...logCtx, block: syncedTo.
|
|
385
|
+
`Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
386
|
+
{ ...logCtx, block: syncedTo.blockData.header.toInspect() },
|
|
314
387
|
);
|
|
315
|
-
this.metrics.
|
|
388
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
316
389
|
return undefined;
|
|
317
390
|
}
|
|
318
391
|
|
|
@@ -323,86 +396,171 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
323
396
|
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
324
397
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
325
398
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
326
|
-
this.publisher = publisher;
|
|
327
399
|
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
400
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
401
|
+
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
402
|
+
// will invalidate the currently invalid checkpoint on L1.
|
|
403
|
+
const invalidateCheckpoint =
|
|
404
|
+
syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid
|
|
405
|
+
? undefined
|
|
406
|
+
: await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
407
|
+
|
|
408
|
+
// Determine the correct archive and L1 state overrides for the canProposeAt check.
|
|
409
|
+
// The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
|
|
410
|
+
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
411
|
+
let archiveForCheck = syncedTo.archive;
|
|
412
|
+
|
|
413
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
414
|
+
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
415
|
+
this.log.verbose(
|
|
416
|
+
`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`,
|
|
417
|
+
{ targetSlot, parentCheckpointNumber: CheckpointNumber(checkpointNumber - 1) },
|
|
418
|
+
);
|
|
419
|
+
// Match what L1 will see at archives[pending] once the proposed parent lands: the parent's
|
|
420
|
+
// own archive root from the gossiped proposal. `syncedTo.archive` is the world-state-local
|
|
421
|
+
// view and can transiently diverge from the proposed parent (e.g. before the proposed
|
|
422
|
+
// parent's blocks have been applied locally); diverging here would cause the canProposeAt
|
|
423
|
+
// override to set archives[pending] to one value while we present another for comparison.
|
|
424
|
+
archiveForCheck = syncedTo.proposedCheckpointData!.archive.root;
|
|
425
|
+
} else if (invalidateCheckpoint) {
|
|
426
|
+
// After invalidation, L1 will roll back to checkpoint N-1. The archive at N-1 already
|
|
427
|
+
// exists on L1, so we just pass the matching archive (the lastArchive of the invalid checkpoint).
|
|
428
|
+
archiveForCheck = invalidateCheckpoint.lastArchive;
|
|
429
|
+
this.metrics.recordPipelineDepth(0);
|
|
430
|
+
} else {
|
|
431
|
+
this.metrics.recordPipelineDepth(0);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Build the simulation plan: pending/proven override from pipelining or invalidation (or the
|
|
435
|
+
// current snapshot when neither applies, to short-circuit any pending prune in simulation),
|
|
436
|
+
// plus the parent checkpoint cell and fee header when pipelining.
|
|
437
|
+
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
438
|
+
checkpointNumber,
|
|
439
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
440
|
+
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
441
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
442
|
+
rollup: this.rollupContract,
|
|
443
|
+
signatureContext: this.signatureContext,
|
|
444
|
+
log: this.log,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// The plan always pins both pending/proven (to short-circuit `canPruneAtTime` in simulation),
|
|
448
|
+
// so `provenOverride` always reflects the assumed proven checkpoint we are pinning the
|
|
449
|
+
// simulation to. We additionally warn when the pin is load-bearing — i.e. when a prune would
|
|
450
|
+
// actually fire at the target slot without it — so observers can spot "we are building
|
|
451
|
+
// optimistically across a pruning boundary" in the logs.
|
|
452
|
+
const provenOverride = simulationOverridesPlan?.chainTipsOverride?.proven;
|
|
453
|
+
if (provenOverride !== undefined && (await this.l2BlockSource.isPruneDueAtSlot(targetSlot))) {
|
|
454
|
+
this.log.warn(
|
|
455
|
+
`Assuming proof for epoch ending at checkpoint ${provenOverride} lands by target slot ${targetSlot}`,
|
|
456
|
+
{ checkpointNumber, slot, targetSlot, provenOverride },
|
|
457
|
+
);
|
|
332
458
|
}
|
|
333
459
|
|
|
334
|
-
|
|
335
|
-
|
|
460
|
+
this.emit('preparing-checkpoint', {
|
|
461
|
+
targetSlot,
|
|
462
|
+
checkpointNumber,
|
|
463
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
464
|
+
provenOverride,
|
|
465
|
+
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
466
|
+
});
|
|
336
467
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const canProposeCheck = await publisher.canProposeAtNextEthBlock(
|
|
340
|
-
syncedTo.archive,
|
|
468
|
+
const canProposeCheck = await publisher.canProposeAt(
|
|
469
|
+
archiveForCheck,
|
|
341
470
|
proposer ?? EthAddress.ZERO,
|
|
342
|
-
|
|
471
|
+
simulationOverridesPlan,
|
|
343
472
|
);
|
|
344
473
|
|
|
474
|
+
const proposeContext = {
|
|
475
|
+
hasProposedCheckpoint: syncedTo.hasProposedCheckpoint,
|
|
476
|
+
proposedCheckpointNumber: syncedTo.proposedCheckpointData?.checkpointNumber,
|
|
477
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
478
|
+
isInvalidating: !!invalidateCheckpoint,
|
|
479
|
+
invalidatingCheckpointNumber: invalidateCheckpoint?.checkpointNumber,
|
|
480
|
+
archiveForCheck: archiveForCheck.toString(),
|
|
481
|
+
overridePendingCheckpointNumber: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
482
|
+
overrideArchive: simulationOverridesPlan?.pendingCheckpointState?.archive,
|
|
483
|
+
overrideFeeHeader: simulationOverridesPlan?.pendingCheckpointState?.feeHeader,
|
|
484
|
+
};
|
|
485
|
+
|
|
345
486
|
if (canProposeCheck === undefined) {
|
|
346
487
|
this.log.warn(
|
|
347
488
|
`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
|
|
348
|
-
logCtx,
|
|
489
|
+
{ ...logCtx, ...proposeContext },
|
|
349
490
|
);
|
|
350
491
|
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
|
|
351
|
-
this.metrics.
|
|
492
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
352
493
|
return undefined;
|
|
353
494
|
}
|
|
354
495
|
|
|
355
|
-
if (canProposeCheck.slot !==
|
|
496
|
+
if (canProposeCheck.slot !== targetSlot) {
|
|
356
497
|
this.log.warn(
|
|
357
|
-
`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${
|
|
358
|
-
{ ...logCtx, rollup: canProposeCheck, expectedSlot:
|
|
498
|
+
`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}.`,
|
|
499
|
+
{ ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: targetSlot },
|
|
359
500
|
);
|
|
360
501
|
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
361
|
-
this.metrics.
|
|
502
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
362
503
|
return undefined;
|
|
363
504
|
}
|
|
364
505
|
|
|
365
506
|
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
366
507
|
this.log.warn(
|
|
367
508
|
`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}.`,
|
|
368
|
-
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
509
|
+
{ ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: slot },
|
|
369
510
|
);
|
|
370
511
|
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
|
|
371
|
-
this.metrics.
|
|
512
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
372
513
|
return undefined;
|
|
373
514
|
}
|
|
374
515
|
|
|
375
|
-
this.lastSlotForCheckpointProposalJob =
|
|
376
|
-
|
|
516
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
517
|
+
|
|
518
|
+
await this.p2pClient.prepareForSlot(targetSlot);
|
|
519
|
+
this.log.info(
|
|
520
|
+
`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`,
|
|
521
|
+
{
|
|
522
|
+
...logCtx,
|
|
523
|
+
...proposeContext,
|
|
524
|
+
proposer,
|
|
525
|
+
},
|
|
526
|
+
);
|
|
377
527
|
|
|
378
528
|
// Create and return the checkpoint proposal job
|
|
379
529
|
return this.createCheckpointProposalJob(
|
|
380
|
-
epoch,
|
|
381
530
|
slot,
|
|
531
|
+
targetSlot,
|
|
532
|
+
targetEpoch,
|
|
382
533
|
checkpointNumber,
|
|
383
534
|
syncedTo.blockNumber,
|
|
535
|
+
syncedTo.checkpointedCheckpointNumber,
|
|
384
536
|
proposer,
|
|
385
537
|
publisher,
|
|
386
538
|
attestorAddress,
|
|
387
539
|
invalidateCheckpoint,
|
|
540
|
+
syncedTo.proposedCheckpointData,
|
|
388
541
|
);
|
|
389
542
|
}
|
|
390
543
|
|
|
391
544
|
protected createCheckpointProposalJob(
|
|
392
|
-
epoch: EpochNumber,
|
|
393
545
|
slot: SlotNumber,
|
|
546
|
+
targetSlot: SlotNumber,
|
|
547
|
+
targetEpoch: EpochNumber,
|
|
394
548
|
checkpointNumber: CheckpointNumber,
|
|
395
549
|
syncedToBlockNumber: BlockNumber,
|
|
550
|
+
checkpointedCheckpointNumber: CheckpointNumber,
|
|
396
551
|
proposer: EthAddress | undefined,
|
|
397
552
|
publisher: SequencerPublisher,
|
|
398
553
|
attestorAddress: EthAddress,
|
|
399
554
|
invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
555
|
+
proposedCheckpointData?: ProposedCheckpointData,
|
|
400
556
|
): CheckpointProposalJob {
|
|
401
557
|
return new CheckpointProposalJob(
|
|
402
|
-
epoch,
|
|
403
558
|
slot,
|
|
559
|
+
targetSlot,
|
|
560
|
+
targetEpoch,
|
|
404
561
|
checkpointNumber,
|
|
405
562
|
syncedToBlockNumber,
|
|
563
|
+
checkpointedCheckpointNumber,
|
|
406
564
|
proposer,
|
|
407
565
|
publisher,
|
|
408
566
|
attestorAddress,
|
|
@@ -416,29 +574,40 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
416
574
|
this.checkpointsBuilder,
|
|
417
575
|
this.l2BlockSource,
|
|
418
576
|
this.l1Constants,
|
|
577
|
+
this.signatureContext,
|
|
419
578
|
this.config,
|
|
420
579
|
this.timetable,
|
|
421
580
|
this.slasherClient,
|
|
422
581
|
this.epochCache,
|
|
423
582
|
this.dateProvider,
|
|
424
583
|
this.metrics,
|
|
584
|
+
this.checkpointProposalJobMetrics.createRecorder(),
|
|
425
585
|
this,
|
|
426
|
-
this.setState
|
|
427
|
-
this.log,
|
|
586
|
+
(state, slot, timeReferenceSlot) => this.setState(state, slot, { timeReferenceSlot }),
|
|
428
587
|
this.tracer,
|
|
588
|
+
this.log.getBindings(),
|
|
589
|
+
proposedCheckpointData,
|
|
429
590
|
);
|
|
430
591
|
}
|
|
431
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Returns the current sequencer state.
|
|
595
|
+
*/
|
|
596
|
+
public getState(): SequencerState {
|
|
597
|
+
return this.state;
|
|
598
|
+
}
|
|
599
|
+
|
|
432
600
|
/**
|
|
433
601
|
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
434
602
|
* @param proposedState - The new state to transition to.
|
|
435
|
-
* @param slotNumber - The
|
|
603
|
+
* @param slotNumber - The logical slot associated with the new state.
|
|
436
604
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
605
|
+
* @param timeReferenceSlot - The slot to use for deadline checks when it differs from the logical slot.
|
|
437
606
|
*/
|
|
438
607
|
protected setState(
|
|
439
608
|
proposedState: SequencerState,
|
|
440
609
|
slotNumber: SlotNumber | undefined,
|
|
441
|
-
opts: { force?: boolean } = {},
|
|
610
|
+
opts: { force?: boolean; timeReferenceSlot?: SlotNumber } = {},
|
|
442
611
|
): void {
|
|
443
612
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
444
613
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
@@ -449,24 +618,43 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
449
618
|
return;
|
|
450
619
|
}
|
|
451
620
|
let secondsIntoSlot = undefined;
|
|
452
|
-
|
|
453
|
-
|
|
621
|
+
const timeReferenceSlot = opts.timeReferenceSlot ?? slotNumber;
|
|
622
|
+
if (timeReferenceSlot !== undefined) {
|
|
623
|
+
secondsIntoSlot = this.getSecondsIntoSlot(timeReferenceSlot);
|
|
454
624
|
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
455
625
|
}
|
|
456
626
|
|
|
627
|
+
const oldState = this.state;
|
|
628
|
+
const oldStateSlotNumber = this.stateSlotNumber;
|
|
629
|
+
const stateChanged = proposedState !== oldState;
|
|
630
|
+
const transitionAtMs = performance.now();
|
|
631
|
+
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
632
|
+
|
|
457
633
|
const boringStates = [SequencerState.IDLE, SequencerState.SYNCHRONIZING];
|
|
458
634
|
const logLevel =
|
|
459
|
-
boringStates.includes(proposedState) && boringStates.includes(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
635
|
+
boringStates.includes(proposedState) && boringStates.includes(oldState) ? ('trace' as const) : ('debug' as const);
|
|
636
|
+
this.stateLog[logLevel](`Transitioning from ${oldState} to ${proposedState}`, {
|
|
637
|
+
oldState,
|
|
638
|
+
newState: proposedState,
|
|
639
|
+
slotNumber,
|
|
640
|
+
timeReferenceSlot,
|
|
641
|
+
stateSlotNumber: oldStateSlotNumber,
|
|
642
|
+
secondsIntoSlot,
|
|
643
|
+
...(stateChanged && { stateDurationMs: Math.ceil(stateDurationMs) }),
|
|
644
|
+
});
|
|
463
645
|
|
|
464
646
|
this.emit('state-changed', {
|
|
465
|
-
oldState
|
|
647
|
+
oldState,
|
|
466
648
|
newState: proposedState,
|
|
467
649
|
secondsIntoSlot,
|
|
468
650
|
slot: slotNumber,
|
|
651
|
+
timeReferenceSlot,
|
|
469
652
|
});
|
|
653
|
+
if (stateChanged) {
|
|
654
|
+
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
655
|
+
this.stateEnteredAtMs = transitionAtMs;
|
|
656
|
+
this.stateSlotNumber = slotNumber;
|
|
657
|
+
}
|
|
470
658
|
this.state = proposedState;
|
|
471
659
|
}
|
|
472
660
|
|
|
@@ -475,16 +663,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
475
663
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
476
664
|
*/
|
|
477
665
|
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
478
|
-
// Check that the archiver
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
const
|
|
482
|
-
const { slot
|
|
483
|
-
if (
|
|
666
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
667
|
+
// The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
|
|
668
|
+
// See getSyncedL2SlotNumber for how missed L1 blocks are handled.
|
|
669
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
670
|
+
const { slot } = args;
|
|
671
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
484
672
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
485
673
|
slot,
|
|
486
|
-
|
|
487
|
-
l1Timestamp,
|
|
674
|
+
syncedL2Slot,
|
|
488
675
|
});
|
|
489
676
|
return undefined;
|
|
490
677
|
}
|
|
@@ -494,73 +681,162 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
494
681
|
number: syncSummary.latestBlockNumber,
|
|
495
682
|
hash: syncSummary.latestBlockHash,
|
|
496
683
|
})),
|
|
497
|
-
this.l2BlockSource
|
|
684
|
+
this.l2BlockSource
|
|
685
|
+
.getL2Tips()
|
|
686
|
+
.then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed, proposedCheckpoint: t.proposedCheckpoint })),
|
|
498
687
|
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
499
|
-
this.l1ToL2MessageSource.getL2Tips().then(t => t.proposed),
|
|
688
|
+
this.l1ToL2MessageSource.getL2Tips().then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed })),
|
|
500
689
|
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
690
|
+
this.l2BlockSource.getProposedCheckpointData(),
|
|
501
691
|
] as const);
|
|
502
692
|
|
|
503
|
-
const [worldState,
|
|
693
|
+
const [worldState, l2Tips, p2p, l1ToL2MessageSourceTips, pendingChainValidationStatus, proposedCheckpointData] =
|
|
694
|
+
syncedBlocks;
|
|
504
695
|
|
|
505
|
-
// 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,
|
|
506
|
-
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
507
|
-
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
508
696
|
const result =
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
697
|
+
worldState.hash === l2Tips.proposed.hash &&
|
|
698
|
+
p2p.hash === l2Tips.proposed.hash &&
|
|
699
|
+
l1ToL2MessageSourceTips.proposed.hash === l2Tips.proposed.hash &&
|
|
700
|
+
l1ToL2MessageSourceTips.checkpointed.block.hash === l2Tips.checkpointed.block.hash &&
|
|
701
|
+
l1ToL2MessageSourceTips.checkpointed.checkpoint.hash === l2Tips.checkpointed.checkpoint.hash;
|
|
513
702
|
|
|
514
703
|
if (!result) {
|
|
515
|
-
this.log.debug(`Sequencer sync check failed`, {
|
|
704
|
+
this.log.debug(`Sequencer sync check failed`, {
|
|
705
|
+
worldState,
|
|
706
|
+
l2BlockSource: l2Tips.proposed,
|
|
707
|
+
p2p,
|
|
708
|
+
l1ToL2MessageSourceTips,
|
|
709
|
+
});
|
|
516
710
|
return undefined;
|
|
517
711
|
}
|
|
518
712
|
|
|
519
|
-
// Special case for genesis state
|
|
520
713
|
const blockNumber = worldState.number;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
714
|
+
const blockData = await this.l2BlockSource.getBlockData({ number: blockNumber });
|
|
715
|
+
if (!blockData) {
|
|
716
|
+
this.log.warn(`Sequencer sync check failed: failed to get L2 block data ${blockNumber} from the archiver`, {
|
|
717
|
+
blockNumber,
|
|
718
|
+
l2Tips,
|
|
719
|
+
syncedL2Slot,
|
|
720
|
+
...args,
|
|
721
|
+
});
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// Refuse to build a checkpoint on top of a proposed block whose enclosing checkpoint was never
|
|
726
|
+
// proposed. Under pipelining we may have received and reexecuted such a block locally — advancing
|
|
727
|
+
// our world-state tip past the checkpointed tip — while the proposing node never published the
|
|
728
|
+
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
729
|
+
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
730
|
+
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
731
|
+
if (
|
|
732
|
+
blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number &&
|
|
733
|
+
(l2Tips.proposedCheckpoint.checkpoint.number !== blockData.checkpointNumber ||
|
|
734
|
+
proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber)
|
|
735
|
+
) {
|
|
736
|
+
const logCtx = {
|
|
737
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
738
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
739
|
+
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
740
|
+
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
741
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
742
|
+
blockSlot: blockData.header.getSlot(),
|
|
743
|
+
syncedL2Slot,
|
|
744
|
+
...args,
|
|
529
745
|
};
|
|
746
|
+
|
|
747
|
+
// Under pipelining the block proposal for a checkpoint leads its checkpoint proposal by up to one
|
|
748
|
+
// slot, so a world-state tip sitting in an as-yet-unproposed checkpoint is the expected steady state
|
|
749
|
+
// until that checkpoint is due. Only treat it as abnormal — and warn — once the checkpoint is overdue
|
|
750
|
+
// by the same deadline the archiver uses to prune the orphan block (see pruneOrphanProposedBlocks).
|
|
751
|
+
// Before then this is normal pipelining and we wait it out quietly.
|
|
752
|
+
if (this.isProposedCheckpointOverdue(blockData.header.getSlot())) {
|
|
753
|
+
this.log.warn(`Sequencer sync check failed: proposed block has no matching proposed checkpoint`, logCtx);
|
|
754
|
+
} else {
|
|
755
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
756
|
+
}
|
|
757
|
+
return undefined;
|
|
530
758
|
}
|
|
531
759
|
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
760
|
+
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
761
|
+
|
|
762
|
+
// The l2Tips and proposedCheckpointData reads above come from independent archiver snapshots
|
|
763
|
+
// (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
|
|
764
|
+
// write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
|
|
765
|
+
// no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
|
|
766
|
+
// window — the next checkSync tick will see a coherent snapshot.
|
|
767
|
+
if (
|
|
768
|
+
hasProposedCheckpoint &&
|
|
769
|
+
(!proposedCheckpointData ||
|
|
770
|
+
proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)
|
|
771
|
+
) {
|
|
772
|
+
this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
|
|
773
|
+
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
774
|
+
checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
|
|
775
|
+
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
776
|
+
syncedL2Slot,
|
|
777
|
+
...args,
|
|
778
|
+
});
|
|
779
|
+
return undefined;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
783
|
+
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
784
|
+
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
785
|
+
this.log.warn(`Sequencer sync check failed: proposed checkpoint number mismatch`, {
|
|
786
|
+
proposedCheckpointNumber: proposedCheckpointData.checkpointNumber,
|
|
787
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
788
|
+
syncedL2Slot,
|
|
789
|
+
...args,
|
|
790
|
+
});
|
|
536
791
|
return undefined;
|
|
537
792
|
}
|
|
538
793
|
|
|
539
794
|
return {
|
|
540
|
-
|
|
541
|
-
blockNumber:
|
|
542
|
-
checkpointNumber:
|
|
543
|
-
|
|
544
|
-
|
|
795
|
+
blockData,
|
|
796
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
797
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
798
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
799
|
+
archive: blockData.archive.root,
|
|
800
|
+
hasProposedCheckpoint,
|
|
801
|
+
proposedCheckpointData,
|
|
802
|
+
syncedL2Slot,
|
|
545
803
|
pendingChainValidationStatus,
|
|
546
804
|
};
|
|
547
805
|
}
|
|
548
806
|
|
|
807
|
+
/**
|
|
808
|
+
* Whether the enclosing checkpoint of a reexecuted block is overdue: past the deadline by which a
|
|
809
|
+
* well-behaved proposer should have published it. Mirrors the archiver's orphan-prune deadline (the
|
|
810
|
+
* start of the slot after the block's build slot, plus a grace period) so the sequencer only warns
|
|
811
|
+
* about a missing proposed checkpoint once the archiver itself would prune the orphan block. The grace
|
|
812
|
+
* is derived from the block build duration the same way the archiver defaults it at node wiring.
|
|
813
|
+
*/
|
|
814
|
+
private isProposedCheckpointOverdue(blockSlot: SlotNumber): boolean {
|
|
815
|
+
const expectedBySlot = SlotNumber(Number(blockSlot) - PROPOSER_PIPELINING_SLOT_OFFSET + 1);
|
|
816
|
+
const graceSeconds =
|
|
817
|
+
this.config.blockDurationMs !== undefined ? Math.ceil(this.config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
818
|
+
const expectedByTime = getTimestampForSlot(expectedBySlot, this.l1Constants) + BigInt(graceSeconds);
|
|
819
|
+
return BigInt(this.dateProvider.nowInSeconds()) >= expectedByTime;
|
|
820
|
+
}
|
|
821
|
+
|
|
549
822
|
/**
|
|
550
823
|
* Checks if we are the proposer for the next slot.
|
|
551
824
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
552
825
|
*/
|
|
553
|
-
protected async checkCanPropose(
|
|
826
|
+
protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
|
|
554
827
|
let proposer: EthAddress | undefined;
|
|
555
828
|
|
|
556
829
|
try {
|
|
557
|
-
proposer = await this.epochCache.getProposerAttesterAddressInSlot(
|
|
830
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
558
831
|
} catch (e) {
|
|
559
832
|
if (e instanceof NoCommitteeError) {
|
|
560
|
-
this.
|
|
833
|
+
if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
|
|
834
|
+
this.lastSlotForNoCommitteeWarning = targetSlot;
|
|
835
|
+
this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
|
|
836
|
+
}
|
|
561
837
|
return [false, undefined];
|
|
562
838
|
}
|
|
563
|
-
this.log.error(`Error getting proposer for slot ${
|
|
839
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
564
840
|
return [false, undefined];
|
|
565
841
|
}
|
|
566
842
|
|
|
@@ -577,10 +853,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
577
853
|
const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
|
|
578
854
|
|
|
579
855
|
if (!weAreProposer) {
|
|
580
|
-
this.log.debug(`Cannot propose at slot ${
|
|
856
|
+
this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
|
|
857
|
+
targetSlot,
|
|
858
|
+
validatorAddresses,
|
|
859
|
+
proposer,
|
|
860
|
+
});
|
|
581
861
|
return [false, proposer];
|
|
582
862
|
}
|
|
583
863
|
|
|
864
|
+
this.log.info(`We are the proposer for pipeline slot ${targetSlot}`, {
|
|
865
|
+
targetSlot,
|
|
866
|
+
proposer,
|
|
867
|
+
});
|
|
584
868
|
return [true, proposer];
|
|
585
869
|
}
|
|
586
870
|
|
|
@@ -589,8 +873,8 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
589
873
|
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
590
874
|
*/
|
|
591
875
|
@trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
592
|
-
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
|
|
593
|
-
const { slot } = args;
|
|
876
|
+
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; targetSlot: SlotNumber; ts: bigint }): Promise<void> {
|
|
877
|
+
const { slot, targetSlot } = args;
|
|
594
878
|
|
|
595
879
|
// Prevent duplicate attempts in the same slot
|
|
596
880
|
if (this.lastSlotForFallbackVote === slot) {
|
|
@@ -618,7 +902,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
618
902
|
});
|
|
619
903
|
|
|
620
904
|
// Check if we're a proposer or proposal is open
|
|
621
|
-
const [canPropose, proposer] = await this.checkCanPropose(
|
|
905
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
622
906
|
if (!canPropose) {
|
|
623
907
|
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
624
908
|
return;
|
|
@@ -635,9 +919,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
635
919
|
slot,
|
|
636
920
|
});
|
|
637
921
|
|
|
638
|
-
// Enqueue governance and slashing votes
|
|
922
|
+
// Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
|
|
639
923
|
const voter = new CheckpointVoter(
|
|
640
|
-
|
|
924
|
+
targetSlot,
|
|
641
925
|
publisher,
|
|
642
926
|
attestorAddress,
|
|
643
927
|
this.validatorClient,
|
|
@@ -656,7 +940,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
656
940
|
}
|
|
657
941
|
|
|
658
942
|
this.log.info(`Voting in slot ${slot} despite sync failure`, { slot });
|
|
659
|
-
|
|
943
|
+
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
944
|
+
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
945
|
+
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
946
|
+
// work loop while waiting for the target slot to start.
|
|
947
|
+
void publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
948
|
+
this.log.error(`Failed to publish votes despite sync failure for slot ${slot}`, err, { slot });
|
|
949
|
+
});
|
|
660
950
|
}
|
|
661
951
|
|
|
662
952
|
/**
|
|
@@ -666,9 +956,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
666
956
|
@trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
667
957
|
protected async tryVoteWhenEscapeHatchOpen(args: {
|
|
668
958
|
slot: SlotNumber;
|
|
959
|
+
targetSlot: SlotNumber;
|
|
669
960
|
proposer: EthAddress | undefined;
|
|
670
961
|
}): Promise<void> {
|
|
671
|
-
const { slot, proposer } = args;
|
|
962
|
+
const { slot, targetSlot, proposer } = args;
|
|
672
963
|
|
|
673
964
|
// Prevent duplicate attempts in the same slot
|
|
674
965
|
if (this.lastSlotForFallbackVote === slot) {
|
|
@@ -681,10 +972,18 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
681
972
|
|
|
682
973
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
683
974
|
|
|
684
|
-
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
975
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
976
|
+
slot,
|
|
977
|
+
targetSlot,
|
|
978
|
+
attestorAddress,
|
|
979
|
+
});
|
|
685
980
|
|
|
981
|
+
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
982
|
+
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
983
|
+
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
984
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
686
985
|
const voter = new CheckpointVoter(
|
|
687
|
-
|
|
986
|
+
targetSlot,
|
|
688
987
|
publisher,
|
|
689
988
|
attestorAddress,
|
|
690
989
|
this.validatorClient,
|
|
@@ -703,8 +1002,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
703
1002
|
return;
|
|
704
1003
|
}
|
|
705
1004
|
|
|
706
|
-
this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot });
|
|
707
|
-
|
|
1005
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot, targetSlot });
|
|
1006
|
+
// Votes are EIP-712-signed for `targetSlot`. Delay submission to the start of `targetSlot` so
|
|
1007
|
+
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1008
|
+
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1009
|
+
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1010
|
+
// waiting for the target slot to start, mirroring tryVoteWhenSyncFails.
|
|
1011
|
+
void publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
1012
|
+
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, { slot, targetSlot });
|
|
1013
|
+
});
|
|
708
1014
|
}
|
|
709
1015
|
|
|
710
1016
|
/**
|
|
@@ -717,7 +1023,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
717
1023
|
syncedTo: SequencerSyncCheckResult,
|
|
718
1024
|
currentSlot: SlotNumber,
|
|
719
1025
|
): Promise<void> {
|
|
720
|
-
const { pendingChainValidationStatus,
|
|
1026
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
721
1027
|
if (pendingChainValidationStatus.valid) {
|
|
722
1028
|
return;
|
|
723
1029
|
}
|
|
@@ -732,7 +1038,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
732
1038
|
|
|
733
1039
|
const logData = {
|
|
734
1040
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
735
|
-
|
|
1041
|
+
syncedL2Slot,
|
|
736
1042
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
737
1043
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
738
1044
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -860,6 +1166,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
860
1166
|
return this.validatorClient?.getValidatorAddresses();
|
|
861
1167
|
}
|
|
862
1168
|
|
|
1169
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */
|
|
1170
|
+
public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
|
|
1171
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
863
1174
|
public getConfig() {
|
|
864
1175
|
return this.config;
|
|
865
1176
|
}
|
|
@@ -870,10 +1181,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
870
1181
|
}
|
|
871
1182
|
|
|
872
1183
|
type SequencerSyncCheckResult = {
|
|
873
|
-
|
|
1184
|
+
blockData?: BlockData;
|
|
874
1185
|
checkpointNumber: CheckpointNumber;
|
|
1186
|
+
checkpointedCheckpointNumber: CheckpointNumber;
|
|
875
1187
|
blockNumber: BlockNumber;
|
|
876
1188
|
archive: Fr;
|
|
877
|
-
|
|
1189
|
+
hasProposedCheckpoint: boolean;
|
|
1190
|
+
proposedCheckpointData?: ProposedCheckpointData;
|
|
1191
|
+
syncedL2Slot: SlotNumber;
|
|
878
1192
|
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
879
1193
|
};
|