@aztec/sequencer-client 0.0.1-commit.f5d02921e → 0.0.1-commit.f7ea82942
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/dest/client/sequencer-client.d.ts +3 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +3 -4
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -11
- 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 +4 -9
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +3 -41
- package/dest/global_variable_builder/index.d.ts +3 -1
- 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 +1 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +2 -2
- 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-publisher-factory.d.ts +1 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +0 -1
- package/dest/publisher/sequencer-publisher.d.ts +16 -35
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +60 -92
- package/dest/sequencer/chain_state_overrides.d.ts +25 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +39 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +27 -22
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +294 -155
- 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/events.d.ts +6 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +7 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +27 -20
- package/dest/sequencer/sequencer.d.ts +5 -2
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +31 -23
- package/dest/sequencer/timetable.d.ts +14 -1
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +45 -36
- package/package.json +27 -27
- package/src/client/sequencer-client.ts +5 -7
- package/src/config.ts +8 -11
- 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 +7 -54
- package/src/global_variable_builder/index.ts +2 -0
- package/src/publisher/config.ts +6 -4
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-publisher-factory.ts +0 -3
- package/src/publisher/sequencer-publisher.ts +106 -152
- package/src/sequencer/README.md +83 -13
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +365 -205
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/events.ts +5 -0
- package/src/sequencer/metrics.ts +35 -25
- package/src/sequencer/sequencer.ts +44 -26
- package/src/sequencer/timetable.ts +57 -45
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import
|
|
2
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
3
3
|
import {
|
|
4
4
|
BlockNumber,
|
|
5
5
|
CheckpointNumber,
|
|
@@ -18,6 +18,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
18
18
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
19
19
|
import { filter } from '@aztec/foundation/iterator';
|
|
20
20
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
21
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
21
22
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
22
23
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
23
24
|
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
type L2BlockSink,
|
|
31
32
|
type L2BlockSource,
|
|
32
33
|
MaliciousCommitteeAttestationsAndSigners,
|
|
34
|
+
type ValidateCheckpointResult,
|
|
33
35
|
} from '@aztec/stdlib/block';
|
|
34
36
|
import { type Checkpoint, type ProposedCheckpointData, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
35
37
|
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
@@ -57,6 +59,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
57
59
|
|
|
58
60
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
59
61
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
62
|
+
import {
|
|
63
|
+
buildPipelinedParentSimulationOverridesPlan,
|
|
64
|
+
buildSubmissionSimulationOverridesPlan,
|
|
65
|
+
} from './chain_state_overrides.js';
|
|
66
|
+
import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
|
|
60
67
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
61
68
|
import { SequencerInterruptedError } from './errors.js';
|
|
62
69
|
import type { SequencerEvents } from './events.js';
|
|
@@ -68,7 +75,14 @@ import { SequencerState } from './utils.js';
|
|
|
68
75
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
69
76
|
const TXS_POLLING_MS = 500;
|
|
70
77
|
|
|
71
|
-
/** Result from proposeCheckpoint when a checkpoint was successfully built and
|
|
78
|
+
/** Result from proposeCheckpoint when a checkpoint was successfully built and broadcast. */
|
|
79
|
+
type CheckpointProposalBroadcast = {
|
|
80
|
+
checkpoint: Checkpoint;
|
|
81
|
+
proposal: CheckpointProposal;
|
|
82
|
+
blockProposedAt: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Result after attestation collection and signing, ready for L1 submission. */
|
|
72
86
|
type CheckpointProposalResult = {
|
|
73
87
|
checkpoint: Checkpoint;
|
|
74
88
|
attestations: CommitteeAttestationsAndSigners;
|
|
@@ -87,8 +101,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
87
101
|
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
88
102
|
private pendingL1Submission: Promise<void> | undefined;
|
|
89
103
|
|
|
90
|
-
/**
|
|
91
|
-
private
|
|
104
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */
|
|
105
|
+
private pipelinedParentSimulationOverridesPlan?: SimulationOverridesPlan;
|
|
92
106
|
|
|
93
107
|
constructor(
|
|
94
108
|
private readonly slotNow: SlotNumber,
|
|
@@ -116,7 +130,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
116
130
|
private readonly epochCache: EpochCache,
|
|
117
131
|
private readonly dateProvider: DateProvider,
|
|
118
132
|
private readonly metrics: SequencerMetrics,
|
|
119
|
-
private readonly
|
|
133
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
134
|
+
protected readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
120
135
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
121
136
|
public readonly tracer: Tracer,
|
|
122
137
|
bindings?: LoggerBindings,
|
|
@@ -136,8 +151,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
136
151
|
|
|
137
152
|
/**
|
|
138
153
|
* Executes the checkpoint proposal job.
|
|
139
|
-
* Builds blocks,
|
|
140
|
-
*
|
|
154
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
155
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
156
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
141
157
|
* Returns the built checkpoint if successful, undefined otherwise.
|
|
142
158
|
*/
|
|
143
159
|
@trackSpan('CheckpointProposalJob.execute')
|
|
@@ -157,73 +173,100 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
157
173
|
this.log,
|
|
158
174
|
).enqueueVotes();
|
|
159
175
|
|
|
160
|
-
// Build
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
const checkpoint = proposalResult?.checkpoint;
|
|
164
|
-
|
|
165
|
-
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
166
|
-
await Promise.all(votesPromises);
|
|
176
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
177
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
178
|
+
const broadcast = await this.proposeCheckpoint();
|
|
167
179
|
|
|
168
|
-
if (
|
|
169
|
-
|
|
180
|
+
if (!broadcast) {
|
|
181
|
+
await Promise.all(votesPromises);
|
|
182
|
+
// Still submit votes even without a checkpoint
|
|
183
|
+
if (!this.config.fishermanMode) {
|
|
184
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(() => {});
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
170
187
|
}
|
|
171
188
|
|
|
189
|
+
const { checkpoint } = broadcast;
|
|
190
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
191
|
+
|
|
172
192
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
173
193
|
if (this.config.fishermanMode) {
|
|
174
194
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
175
|
-
return;
|
|
195
|
+
return checkpoint;
|
|
176
196
|
}
|
|
177
197
|
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
198
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
199
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
200
|
+
|
|
201
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
202
|
+
return checkpoint;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
207
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
208
|
+
*/
|
|
209
|
+
private async waitForAttestationsAndEnqueueSubmissionAsync(
|
|
210
|
+
broadcast: CheckpointProposalBroadcast,
|
|
211
|
+
votesPromises: Promise<unknown>[],
|
|
212
|
+
): Promise<void> {
|
|
213
|
+
const { checkpoint } = broadcast;
|
|
214
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
218
|
+
await Promise.all(votesPromises);
|
|
219
|
+
|
|
220
|
+
// Try to collect attestations from the committee
|
|
221
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
222
|
+
|
|
223
|
+
// If pipelining, wait for the previous checkpoint to land on L1 before submitting,
|
|
224
|
+
// so we can check it matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
225
|
+
if (signedAttestations && (!isPipelining || (await this.waitForValidParentCheckpointOnL1()))) {
|
|
226
|
+
await this.enqueueCheckpointForSubmission({ checkpoint, ...signedAttestations });
|
|
185
227
|
}
|
|
186
|
-
}
|
|
187
228
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.pendingL1Submission = this.publisher
|
|
199
|
-
.sendRequestsAt(submitAfter)
|
|
200
|
-
.then(async l1Response => {
|
|
201
|
-
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
202
|
-
if (proposedAction) {
|
|
203
|
-
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
204
|
-
const coinbase = checkpoint?.header.coinbase;
|
|
205
|
-
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
206
|
-
} else if (checkpoint) {
|
|
207
|
-
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
208
|
-
|
|
209
|
-
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
210
|
-
this.metrics.recordPipelineDiscard();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
})
|
|
214
|
-
.catch(err => {
|
|
215
|
-
this.log.error(`Background L1 submission failed for slot ${this.targetSlot}`, err);
|
|
216
|
-
if (checkpoint) {
|
|
217
|
-
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
218
|
-
|
|
219
|
-
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
220
|
-
this.metrics.recordPipelineDiscard();
|
|
221
|
-
}
|
|
229
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
230
|
+
// Note that if we are not pipelining, we enqueued the invalidation at the beginning
|
|
231
|
+
if (!signedAttestations && isPipelining && (await this.waitForSyncedL2SlotNumber(this.slotNow))) {
|
|
232
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
233
|
+
if (!validationStatus.valid) {
|
|
234
|
+
this.log.warn(
|
|
235
|
+
`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`,
|
|
236
|
+
{ checkpoint: validationStatus.checkpoint, reason: validationStatus.reason },
|
|
237
|
+
);
|
|
238
|
+
await this.enqueueInvalidation(validationStatus);
|
|
222
239
|
}
|
|
223
|
-
}
|
|
240
|
+
}
|
|
224
241
|
|
|
225
|
-
|
|
226
|
-
|
|
242
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
243
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
244
|
+
const submitAfter = isPipelining
|
|
245
|
+
? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000)
|
|
246
|
+
: new Date(this.dateProvider.now());
|
|
247
|
+
|
|
248
|
+
const l1Response = await this.publisher.sendRequestsAt(submitAfter);
|
|
249
|
+
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
250
|
+
if (proposedAction) {
|
|
251
|
+
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
252
|
+
const coinbase = checkpoint.header.coinbase;
|
|
253
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
254
|
+
} else {
|
|
255
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
256
|
+
if (isPipelining) {
|
|
257
|
+
this.metrics.recordPipelineDiscard();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} catch (err) {
|
|
261
|
+
if (err instanceof SequencerInterruptedError) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
|
|
265
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
266
|
+
if (isPipelining) {
|
|
267
|
+
this.metrics.recordPipelineDiscard();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
227
270
|
}
|
|
228
271
|
|
|
229
272
|
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
@@ -249,13 +292,155 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
249
292
|
}
|
|
250
293
|
}
|
|
251
294
|
|
|
295
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
296
|
+
const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
|
|
297
|
+
pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
|
|
298
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
299
|
+
lastArchiveRoot: checkpoint.header.lastArchiveRoot,
|
|
300
|
+
pipeliningEnabled: isPipelining,
|
|
301
|
+
});
|
|
302
|
+
|
|
252
303
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
253
304
|
txTimeoutAt,
|
|
254
|
-
|
|
255
|
-
forceProposedFeeHeader: this.computedForceProposedFeeHeader,
|
|
305
|
+
...(submissionSimulationOverridesPlan ? { simulationOverridesPlan: submissionSimulationOverridesPlan } : {}),
|
|
256
306
|
});
|
|
257
307
|
}
|
|
258
308
|
|
|
309
|
+
/**
|
|
310
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
311
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
312
|
+
* L1 submission window and is no longer useful.
|
|
313
|
+
*/
|
|
314
|
+
private async waitForSyncedL2SlotNumber(waitForSlot: SlotNumber): Promise<boolean> {
|
|
315
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
316
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
317
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
318
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
319
|
+
|
|
320
|
+
try {
|
|
321
|
+
return await retryUntil(
|
|
322
|
+
async () => {
|
|
323
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
324
|
+
return syncedSlot !== undefined && syncedSlot >= waitForSlot;
|
|
325
|
+
},
|
|
326
|
+
`archiver sync past slot ${waitForSlot}`,
|
|
327
|
+
timeoutSeconds,
|
|
328
|
+
0.2,
|
|
329
|
+
);
|
|
330
|
+
} catch {
|
|
331
|
+
this.log.warn(
|
|
332
|
+
`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`,
|
|
333
|
+
{ checkpointNumber: this.checkpointNumber },
|
|
334
|
+
);
|
|
335
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
342
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
343
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
344
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
345
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
346
|
+
*/
|
|
347
|
+
protected async waitForValidParentCheckpointOnL1(): Promise<boolean> {
|
|
348
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
349
|
+
|
|
350
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
351
|
+
if (!(await this.waitForSyncedL2SlotNumber(this.slotNow))) {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
356
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
357
|
+
|
|
358
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
359
|
+
if (this.proposedCheckpointData) {
|
|
360
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
361
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
362
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
363
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
364
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
365
|
+
if (!validationStatus.valid) {
|
|
366
|
+
this.log.warn(
|
|
367
|
+
`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`,
|
|
368
|
+
{ checkpointNumber: this.checkpointNumber, reason: validationStatus.reason },
|
|
369
|
+
);
|
|
370
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
371
|
+
await this.enqueueInvalidation(validationStatus);
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
376
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
377
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
378
|
+
checkpointNumber: this.checkpointNumber,
|
|
379
|
+
checkpointedNumber,
|
|
380
|
+
});
|
|
381
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// It landed. But is it the one we were expecting?
|
|
386
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
387
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
388
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
389
|
+
checkpointNumber: this.checkpointNumber,
|
|
390
|
+
expectedHash,
|
|
391
|
+
actualHash: tips.checkpointed.checkpoint.hash,
|
|
392
|
+
});
|
|
393
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return true;
|
|
398
|
+
} else {
|
|
399
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
400
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
401
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
402
|
+
// proposal for the previous slot.
|
|
403
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
404
|
+
this.log.warn(
|
|
405
|
+
`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`,
|
|
406
|
+
{ checkpointNumber: this.checkpointNumber, checkpointedNumber },
|
|
407
|
+
);
|
|
408
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */
|
|
417
|
+
private emitPipelinedCheckpointDiscarded(reason: string): void {
|
|
418
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
419
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
420
|
+
slot: this.targetSlot,
|
|
421
|
+
checkpointNumber: this.checkpointNumber,
|
|
422
|
+
reason,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */
|
|
427
|
+
private async enqueueInvalidation(validationStatus: ValidateCheckpointResult): Promise<void> {
|
|
428
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
429
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
433
|
+
if (invalidateRequest) {
|
|
434
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
435
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
436
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, { txTimeoutAt });
|
|
437
|
+
} else {
|
|
438
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
439
|
+
checkpointNumber: this.checkpointNumber,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
259
444
|
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
260
445
|
return {
|
|
261
446
|
// nullish operator needed for tests
|
|
@@ -263,8 +448,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
263
448
|
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
264
449
|
};
|
|
265
450
|
})
|
|
266
|
-
private async proposeCheckpoint(): Promise<
|
|
451
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
267
452
|
try {
|
|
453
|
+
const now = this.dateProvider.now();
|
|
454
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
455
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
456
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
457
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
458
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
459
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
460
|
+
}
|
|
461
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
462
|
+
|
|
268
463
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
269
464
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
270
465
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
@@ -289,21 +484,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
289
484
|
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
290
485
|
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
291
486
|
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
487
|
+
this.pipelinedParentSimulationOverridesPlan = isPipelining
|
|
488
|
+
? await buildPipelinedParentSimulationOverridesPlan({
|
|
489
|
+
checkpointNumber: this.checkpointNumber,
|
|
490
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
491
|
+
rollup: this.publisher.rollupContract,
|
|
492
|
+
log: this.log,
|
|
493
|
+
})
|
|
494
|
+
: undefined;
|
|
298
495
|
|
|
299
496
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
300
497
|
coinbase,
|
|
301
498
|
feeRecipient,
|
|
302
499
|
this.targetSlot,
|
|
303
|
-
|
|
304
|
-
forcePendingCheckpointNumber: parentCheckpointNumber,
|
|
305
|
-
forceProposedFeeHeader: this.computedForceProposedFeeHeader,
|
|
306
|
-
},
|
|
500
|
+
this.pipelinedParentSimulationOverridesPlan,
|
|
307
501
|
);
|
|
308
502
|
|
|
309
503
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -344,7 +538,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
344
538
|
};
|
|
345
539
|
|
|
346
540
|
let blocksInCheckpoint: L2Block[] = [];
|
|
347
|
-
let blockPendingBroadcast:
|
|
541
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
348
542
|
const checkpointBuildTimer = new Timer();
|
|
349
543
|
|
|
350
544
|
try {
|
|
@@ -405,14 +599,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
405
599
|
}
|
|
406
600
|
|
|
407
601
|
// Record checkpoint-level build metrics
|
|
408
|
-
this.
|
|
602
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
409
603
|
checkpointBuildTimer.ms(),
|
|
410
604
|
blocksInCheckpoint.length,
|
|
411
605
|
checkpoint.getStats().txCount,
|
|
412
606
|
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
413
607
|
);
|
|
414
608
|
|
|
415
|
-
//
|
|
609
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
416
610
|
if (this.config.fishermanMode) {
|
|
417
611
|
this.log.info(
|
|
418
612
|
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
@@ -424,60 +618,27 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
424
618
|
},
|
|
425
619
|
);
|
|
426
620
|
this.metrics.recordCheckpointSuccess();
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
attestations: CommitteeAttestationsAndSigners.empty(),
|
|
430
|
-
attestationsSignature: Signature.empty(),
|
|
431
|
-
};
|
|
621
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
622
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
432
623
|
}
|
|
433
624
|
|
|
434
|
-
// Include the block pending broadcast in the checkpoint proposal if any
|
|
435
|
-
const lastBlock = blockPendingBroadcast && {
|
|
436
|
-
blockHeader: blockPendingBroadcast.block.header,
|
|
437
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
438
|
-
txs: blockPendingBroadcast.txs,
|
|
439
|
-
};
|
|
440
|
-
|
|
441
625
|
// Create the checkpoint proposal and broadcast it
|
|
442
626
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
443
627
|
checkpoint.header,
|
|
444
628
|
checkpoint.archive.root,
|
|
629
|
+
this.checkpointNumber,
|
|
445
630
|
feeAssetPriceModifier,
|
|
446
|
-
|
|
631
|
+
blockPendingBroadcast,
|
|
447
632
|
this.proposer,
|
|
448
633
|
checkpointProposalOptions,
|
|
449
634
|
);
|
|
450
635
|
|
|
451
636
|
const blockProposedAt = this.dateProvider.now();
|
|
452
637
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
638
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
453
639
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const blockAttestedAt = this.dateProvider.now();
|
|
457
|
-
|
|
458
|
-
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
459
|
-
|
|
460
|
-
// Proposer must sign over the attestations before pushing them to L1
|
|
461
|
-
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
462
|
-
let attestationsSignature: Signature;
|
|
463
|
-
try {
|
|
464
|
-
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
465
|
-
attestations,
|
|
466
|
-
signer,
|
|
467
|
-
this.targetSlot,
|
|
468
|
-
this.checkpointNumber,
|
|
469
|
-
);
|
|
470
|
-
} catch (err) {
|
|
471
|
-
// We shouldn't really get here since we yield to another HA node
|
|
472
|
-
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
473
|
-
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
474
|
-
return undefined;
|
|
475
|
-
}
|
|
476
|
-
throw err;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// Return the result for the caller to enqueue after the pipeline sleep
|
|
480
|
-
return { checkpoint, attestations, attestationsSignature };
|
|
640
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
641
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
481
642
|
} catch (err) {
|
|
482
643
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
483
644
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
@@ -500,14 +661,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
500
661
|
blockProposalOptions: BlockProposalOptions,
|
|
501
662
|
): Promise<{
|
|
502
663
|
blocksInCheckpoint: L2Block[];
|
|
503
|
-
blockPendingBroadcast:
|
|
664
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
504
665
|
}> {
|
|
505
666
|
const blocksInCheckpoint: L2Block[] = [];
|
|
506
667
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
507
668
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
508
669
|
|
|
509
670
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
510
|
-
let blockPendingBroadcast:
|
|
671
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
511
672
|
|
|
512
673
|
while (true) {
|
|
513
674
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -540,19 +701,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
540
701
|
txHashesAlreadyIncluded,
|
|
541
702
|
});
|
|
542
703
|
|
|
543
|
-
//
|
|
544
|
-
if (
|
|
545
|
-
// If
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
704
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
705
|
+
if ('failure' in buildResult) {
|
|
706
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
707
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
549
711
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
550
712
|
continue;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
716
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
717
|
+
if ('error' in buildResult) {
|
|
556
718
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
557
719
|
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
558
720
|
slot: this.targetSlot,
|
|
@@ -564,33 +726,35 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
564
726
|
}
|
|
565
727
|
|
|
566
728
|
const { block, usedTxs } = buildResult;
|
|
729
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
730
|
+
isFirstBlock: blocksBuilt === 0,
|
|
731
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
732
|
+
});
|
|
733
|
+
|
|
567
734
|
blocksInCheckpoint.push(block);
|
|
568
735
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
569
736
|
|
|
570
|
-
//
|
|
571
|
-
|
|
737
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
738
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
739
|
+
|
|
740
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
741
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
742
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
743
|
+
// If this throws, we abort the entire checkpoint.
|
|
744
|
+
await this.syncProposedBlockToArchiver(block);
|
|
745
|
+
|
|
746
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
572
747
|
if (timingInfo.isLastBlock) {
|
|
573
|
-
await this.syncProposedBlockToArchiver(block);
|
|
574
748
|
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
575
749
|
slot: this.targetSlot,
|
|
576
750
|
blockNumber,
|
|
577
751
|
blocksBuilt,
|
|
578
752
|
});
|
|
579
|
-
|
|
753
|
+
|
|
754
|
+
blockPendingBroadcast = proposal;
|
|
580
755
|
break;
|
|
581
756
|
}
|
|
582
757
|
|
|
583
|
-
// Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
|
|
584
|
-
// in which case we'll broadcast it along with the checkpoint at the end of the loop.
|
|
585
|
-
// Note that we only send the block to the archiver if we manage to create the proposal, so if there's
|
|
586
|
-
// a HA error we don't pollute our archiver with a block that won't make it to the chain.
|
|
587
|
-
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
588
|
-
|
|
589
|
-
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal.
|
|
590
|
-
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
591
|
-
// If this throws, we abort the entire checkpoint.
|
|
592
|
-
await this.syncProposedBlockToArchiver(block);
|
|
593
|
-
|
|
594
758
|
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
595
759
|
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
596
760
|
|
|
@@ -619,6 +783,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
619
783
|
}
|
|
620
784
|
return this.validatorClient.createBlockProposal(
|
|
621
785
|
block.header,
|
|
786
|
+
this.checkpointNumber,
|
|
622
787
|
block.indexWithinCheckpoint,
|
|
623
788
|
inHash,
|
|
624
789
|
block.archive.root,
|
|
@@ -650,7 +815,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
650
815
|
buildDeadline: Date | undefined;
|
|
651
816
|
txHashesAlreadyIncluded: Set<string>;
|
|
652
817
|
},
|
|
653
|
-
): Promise<
|
|
818
|
+
): Promise<
|
|
819
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
820
|
+
> {
|
|
654
821
|
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
655
822
|
opts;
|
|
656
823
|
|
|
@@ -669,7 +836,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
669
836
|
);
|
|
670
837
|
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
671
838
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
672
|
-
return
|
|
839
|
+
return { failure: 'insufficient-txs' };
|
|
673
840
|
}
|
|
674
841
|
|
|
675
842
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -732,7 +899,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
732
899
|
slot: this.targetSlot,
|
|
733
900
|
});
|
|
734
901
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
735
|
-
return
|
|
902
|
+
return { failure: 'insufficient-valid-txs' };
|
|
736
903
|
}
|
|
737
904
|
|
|
738
905
|
// Block creation succeeded, emit stats and metrics
|
|
@@ -761,7 +928,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
761
928
|
slot: this.targetSlot,
|
|
762
929
|
buildSlot: this.slotNow,
|
|
763
930
|
});
|
|
764
|
-
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
931
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
765
932
|
|
|
766
933
|
return { block, usedTxs };
|
|
767
934
|
} catch (err: any) {
|
|
@@ -841,12 +1008,44 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
841
1008
|
return { canStartBuilding: true, availableTxs, minTxs };
|
|
842
1009
|
}
|
|
843
1010
|
|
|
1011
|
+
private async getSignedCommitteeAttestations(
|
|
1012
|
+
broadcast: CheckpointProposalBroadcast,
|
|
1013
|
+
): Promise<{ attestations: CommitteeAttestationsAndSigners; attestationsSignature: Signature } | undefined> {
|
|
1014
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1015
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
1016
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1017
|
+
if (!attestations) {
|
|
1018
|
+
return undefined;
|
|
1019
|
+
}
|
|
1020
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1021
|
+
|
|
1022
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1023
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1024
|
+
try {
|
|
1025
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
1026
|
+
attestations,
|
|
1027
|
+
signer,
|
|
1028
|
+
this.targetSlot,
|
|
1029
|
+
this.checkpointNumber,
|
|
1030
|
+
);
|
|
1031
|
+
return { attestations, attestationsSignature };
|
|
1032
|
+
} catch (err) {
|
|
1033
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1037
|
+
return undefined;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
844
1041
|
/**
|
|
845
1042
|
* Waits for enough attestations to be collected via p2p.
|
|
846
1043
|
* This is run after all blocks for the checkpoint have been built.
|
|
847
1044
|
*/
|
|
848
1045
|
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
849
|
-
private async waitForAttestations(
|
|
1046
|
+
private async waitForAttestations(
|
|
1047
|
+
proposal: CheckpointProposal,
|
|
1048
|
+
): Promise<CommitteeAttestationsAndSigners | undefined> {
|
|
850
1049
|
if (this.config.fishermanMode) {
|
|
851
1050
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
852
1051
|
return CommitteeAttestationsAndSigners.empty();
|
|
@@ -868,12 +1067,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
868
1067
|
|
|
869
1068
|
if (this.config.skipCollectingAttestations) {
|
|
870
1069
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
871
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
1070
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
872
1071
|
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
873
1072
|
}
|
|
874
1073
|
|
|
875
1074
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
876
|
-
? this.timetable.
|
|
1075
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
877
1076
|
: this.l1Constants.slotDuration;
|
|
878
1077
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
879
1078
|
|
|
@@ -886,6 +1085,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
886
1085
|
proposal,
|
|
887
1086
|
numberOfRequiredAttestations,
|
|
888
1087
|
attestationDeadline,
|
|
1088
|
+
this.checkpointNumber,
|
|
889
1089
|
);
|
|
890
1090
|
|
|
891
1091
|
collectedAttestationsCount = attestations.length;
|
|
@@ -919,8 +1119,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
919
1119
|
} catch (err) {
|
|
920
1120
|
if (err && err instanceof AttestationTimeoutError) {
|
|
921
1121
|
collectedAttestationsCount = err.collectedCount;
|
|
1122
|
+
this.log.error(
|
|
1123
|
+
`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`,
|
|
1124
|
+
err,
|
|
1125
|
+
);
|
|
1126
|
+
} else {
|
|
1127
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
922
1128
|
}
|
|
923
|
-
|
|
1129
|
+
return undefined;
|
|
924
1130
|
} finally {
|
|
925
1131
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
926
1132
|
}
|
|
@@ -1012,9 +1218,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1012
1218
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1013
1219
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1014
1220
|
* would never receive its own block without this explicit sync.
|
|
1221
|
+
*
|
|
1222
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1223
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1224
|
+
* whenever the real proposer's block arrives from L1.
|
|
1015
1225
|
*/
|
|
1016
1226
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
1017
|
-
if (this.config.skipPushProposedBlocksToArchiver) {
|
|
1227
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1018
1228
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1019
1229
|
blockNumber: block.number,
|
|
1020
1230
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -1075,56 +1285,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1075
1285
|
return false;
|
|
1076
1286
|
}
|
|
1077
1287
|
|
|
1078
|
-
/**
|
|
1079
|
-
* In times of congestion we need to simulate using the correct fee header override for the previous block
|
|
1080
|
-
* We calculate the correct fee header values.
|
|
1081
|
-
*
|
|
1082
|
-
* If we are in block 1, or the checkpoint we are querying does not exist, we return undefined. However
|
|
1083
|
-
* If we are pipelining - where this function is called, the grandparentCheckpointNumber should always exist
|
|
1084
|
-
* @param parentCheckpointNumber
|
|
1085
|
-
* @returns
|
|
1086
|
-
*/
|
|
1087
|
-
protected async computeForceProposedFeeHeader(parentCheckpointNumber: CheckpointNumber): Promise<
|
|
1088
|
-
| {
|
|
1089
|
-
checkpointNumber: CheckpointNumber;
|
|
1090
|
-
feeHeader: FeeHeader;
|
|
1091
|
-
}
|
|
1092
|
-
| undefined
|
|
1093
|
-
> {
|
|
1094
|
-
if (!this.proposedCheckpointData) {
|
|
1095
|
-
return undefined;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
const rollup = this.publisher.rollupContract;
|
|
1099
|
-
const grandparentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 2);
|
|
1100
|
-
try {
|
|
1101
|
-
const [grandparentCheckpoint, manaTarget] = await Promise.all([
|
|
1102
|
-
rollup.getCheckpoint(grandparentCheckpointNumber),
|
|
1103
|
-
rollup.getManaTarget(),
|
|
1104
|
-
]);
|
|
1105
|
-
|
|
1106
|
-
if (!grandparentCheckpoint || !grandparentCheckpoint.feeHeader) {
|
|
1107
|
-
this.log.error(
|
|
1108
|
-
`Grandparent checkpoint or its feeHeader is undefined for checkpointNumber=${grandparentCheckpointNumber.toString()}`,
|
|
1109
|
-
);
|
|
1110
|
-
return undefined;
|
|
1111
|
-
} else {
|
|
1112
|
-
const parentFeeHeader = RollupContract.computeChildFeeHeader(
|
|
1113
|
-
grandparentCheckpoint.feeHeader,
|
|
1114
|
-
this.proposedCheckpointData.totalManaUsed,
|
|
1115
|
-
this.proposedCheckpointData.feeAssetPriceModifier,
|
|
1116
|
-
manaTarget,
|
|
1117
|
-
);
|
|
1118
|
-
return { checkpointNumber: parentCheckpointNumber, feeHeader: parentFeeHeader };
|
|
1119
|
-
}
|
|
1120
|
-
} catch (err) {
|
|
1121
|
-
this.log.error(
|
|
1122
|
-
`Failed to fetch grandparent checkpoint or mana target for checkpointNumber=${grandparentCheckpointNumber.toString()}: ${err}`,
|
|
1123
|
-
);
|
|
1124
|
-
return undefined;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
1288
|
/** Waits until a specific time within the current slot */
|
|
1129
1289
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
1130
1290
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|