@aztec/sequencer-client 0.0.1-commit.5914bae → 0.0.1-commit.59a0419c6
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 +2 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +8 -8
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -12
- 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 +3 -8
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +4 -39
- 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 +17 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +25 -5
- 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-publisher-factory.d.ts +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +16 -3
- package/dest/publisher/sequencer-publisher.d.ts +52 -41
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +345 -101
- 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 +38 -8
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +427 -171
- 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 +7 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +11 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +38 -20
- package/dest/sequencer/sequencer.d.ts +17 -5
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +120 -58
- 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/dest/test/mock_checkpoint_builder.d.ts +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +0 -2
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +8 -14
- package/src/config.ts +12 -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 +8 -43
- package/src/global_variable_builder/index.ts +2 -0
- package/src/publisher/config.ts +47 -4
- 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-publisher-factory.ts +18 -6
- package/src/publisher/sequencer-publisher.ts +389 -140
- package/src/sequencer/README.md +83 -13
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +517 -180
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/events.ts +6 -1
- package/src/sequencer/metrics.ts +49 -25
- package/src/sequencer/sequencer.ts +177 -63
- package/src/sequencer/timetable.ts +57 -45
- package/src/test/mock_checkpoint_builder.ts +0 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
2
3
|
import {
|
|
3
4
|
BlockNumber,
|
|
4
5
|
CheckpointNumber,
|
|
@@ -17,6 +18,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
17
18
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
18
19
|
import { filter } from '@aztec/foundation/iterator';
|
|
19
20
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
21
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
20
22
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
21
23
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
22
24
|
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
@@ -29,9 +31,10 @@ import {
|
|
|
29
31
|
type L2BlockSink,
|
|
30
32
|
type L2BlockSource,
|
|
31
33
|
MaliciousCommitteeAttestationsAndSigners,
|
|
34
|
+
type ValidateCheckpointResult,
|
|
32
35
|
} from '@aztec/stdlib/block';
|
|
33
|
-
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
34
|
-
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
36
|
+
import { type Checkpoint, type ProposedCheckpointData, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
37
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
35
38
|
import { Gas } from '@aztec/stdlib/gas';
|
|
36
39
|
import {
|
|
37
40
|
type BlockBuilderOptions,
|
|
@@ -56,6 +59,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
56
59
|
|
|
57
60
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
58
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';
|
|
59
67
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
60
68
|
import { SequencerInterruptedError } from './errors.js';
|
|
61
69
|
import type { SequencerEvents } from './events.js';
|
|
@@ -67,6 +75,20 @@ import { SequencerState } from './utils.js';
|
|
|
67
75
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
68
76
|
const TXS_POLLING_MS = 500;
|
|
69
77
|
|
|
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. */
|
|
86
|
+
type CheckpointProposalResult = {
|
|
87
|
+
checkpoint: Checkpoint;
|
|
88
|
+
attestations: CommitteeAttestationsAndSigners;
|
|
89
|
+
attestationsSignature: Signature;
|
|
90
|
+
};
|
|
91
|
+
|
|
70
92
|
/**
|
|
71
93
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
72
94
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
@@ -76,9 +98,16 @@ const TXS_POLLING_MS = 500;
|
|
|
76
98
|
export class CheckpointProposalJob implements Traceable {
|
|
77
99
|
protected readonly log: Logger;
|
|
78
100
|
|
|
101
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
102
|
+
private pendingL1Submission: Promise<void> | undefined;
|
|
103
|
+
|
|
104
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */
|
|
105
|
+
private pipelinedParentSimulationOverridesPlan?: SimulationOverridesPlan;
|
|
106
|
+
|
|
79
107
|
constructor(
|
|
80
|
-
private readonly
|
|
81
|
-
private readonly
|
|
108
|
+
private readonly slotNow: SlotNumber,
|
|
109
|
+
private readonly targetSlot: SlotNumber,
|
|
110
|
+
private readonly targetEpoch: EpochNumber,
|
|
82
111
|
private readonly checkpointNumber: CheckpointNumber,
|
|
83
112
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
84
113
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
@@ -101,17 +130,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
101
130
|
private readonly epochCache: EpochCache,
|
|
102
131
|
private readonly dateProvider: DateProvider,
|
|
103
132
|
private readonly metrics: SequencerMetrics,
|
|
104
|
-
private readonly
|
|
133
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
134
|
+
protected readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
105
135
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
106
136
|
public readonly tracer: Tracer,
|
|
107
137
|
bindings?: LoggerBindings,
|
|
138
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
108
139
|
) {
|
|
109
|
-
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
140
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
141
|
+
...bindings,
|
|
142
|
+
instanceId: `slot-${this.slotNow}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
|
|
147
|
+
public async awaitPendingSubmission(): Promise<void> {
|
|
148
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
149
|
+
await this.pendingL1Submission;
|
|
110
150
|
}
|
|
111
151
|
|
|
112
152
|
/**
|
|
113
153
|
* Executes the checkpoint proposal job.
|
|
114
|
-
*
|
|
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.
|
|
157
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
115
158
|
*/
|
|
116
159
|
@trackSpan('CheckpointProposalJob.execute')
|
|
117
160
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -119,7 +162,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
119
162
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
120
163
|
// These are constant for the whole slot, so we only enqueue them once
|
|
121
164
|
const votesPromises = new CheckpointVoter(
|
|
122
|
-
this.
|
|
165
|
+
this.targetSlot,
|
|
123
166
|
this.publisher,
|
|
124
167
|
this.attestorAddress,
|
|
125
168
|
this.validatorClient,
|
|
@@ -130,33 +173,271 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
130
173
|
this.log,
|
|
131
174
|
).enqueueVotes();
|
|
132
175
|
|
|
133
|
-
// Build
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
137
|
-
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();
|
|
138
179
|
|
|
139
|
-
if (
|
|
140
|
-
|
|
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;
|
|
141
187
|
}
|
|
142
188
|
|
|
189
|
+
const { checkpoint } = broadcast;
|
|
190
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
191
|
+
|
|
143
192
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
144
193
|
if (this.config.fishermanMode) {
|
|
145
194
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
146
|
-
return;
|
|
195
|
+
return checkpoint;
|
|
147
196
|
}
|
|
148
197
|
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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 });
|
|
227
|
+
}
|
|
228
|
+
|
|
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);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
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
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
273
|
+
private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
|
|
274
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
275
|
+
|
|
276
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
277
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
278
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
279
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
280
|
+
|
|
281
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
282
|
+
if (
|
|
283
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
284
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
285
|
+
) {
|
|
286
|
+
const roll = Math.max(0, randomInt(100));
|
|
287
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
288
|
+
this.log.warn(
|
|
289
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
|
|
290
|
+
);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
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
|
+
|
|
303
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
304
|
+
txTimeoutAt,
|
|
305
|
+
...(submissionSimulationOverridesPlan ? { simulationOverridesPlan: submissionSimulationOverridesPlan } : {}),
|
|
306
|
+
});
|
|
307
|
+
}
|
|
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
|
+
});
|
|
160
441
|
}
|
|
161
442
|
}
|
|
162
443
|
|
|
@@ -164,29 +445,59 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
164
445
|
return {
|
|
165
446
|
// nullish operator needed for tests
|
|
166
447
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
167
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
448
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
168
449
|
};
|
|
169
450
|
})
|
|
170
|
-
private async proposeCheckpoint(): Promise<
|
|
451
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
171
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
|
+
|
|
172
463
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
173
464
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
174
465
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
175
466
|
|
|
176
467
|
// Start the checkpoint
|
|
177
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
178
|
-
this.
|
|
468
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
469
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
470
|
+
buildSlot: this.slotNow,
|
|
471
|
+
submissionSlot: this.targetSlot,
|
|
472
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
473
|
+
proposer: this.proposer?.toString(),
|
|
474
|
+
coinbase: coinbase.toString(),
|
|
475
|
+
});
|
|
476
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
179
477
|
|
|
180
478
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
181
479
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
182
480
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
183
481
|
}
|
|
184
482
|
|
|
185
|
-
// Create checkpoint builder for the slot
|
|
483
|
+
// Create checkpoint builder for the slot.
|
|
484
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
485
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
486
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
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;
|
|
495
|
+
|
|
186
496
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
187
497
|
coinbase,
|
|
188
498
|
feeRecipient,
|
|
189
|
-
this.
|
|
499
|
+
this.targetSlot,
|
|
500
|
+
this.pipelinedParentSimulationOverridesPlan,
|
|
190
501
|
);
|
|
191
502
|
|
|
192
503
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -194,7 +505,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
194
505
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
195
506
|
|
|
196
507
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
197
|
-
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.
|
|
508
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
|
|
198
509
|
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
199
510
|
.map(c => c.checkpointOutHash);
|
|
200
511
|
|
|
@@ -227,7 +538,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
227
538
|
};
|
|
228
539
|
|
|
229
540
|
let blocksInCheckpoint: L2Block[] = [];
|
|
230
|
-
let blockPendingBroadcast:
|
|
541
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
231
542
|
const checkpointBuildTimer = new Timer();
|
|
232
543
|
|
|
233
544
|
try {
|
|
@@ -251,8 +562,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
251
562
|
}
|
|
252
563
|
|
|
253
564
|
if (blocksInCheckpoint.length === 0) {
|
|
254
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
255
|
-
this.eventEmitter.emit('checkpoint-empty', { slot: this.
|
|
565
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, { slot: this.targetSlot });
|
|
566
|
+
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
256
567
|
return undefined;
|
|
257
568
|
}
|
|
258
569
|
|
|
@@ -260,14 +571,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
260
571
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
261
572
|
this.log.warn(
|
|
262
573
|
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
263
|
-
{ slot: this.
|
|
574
|
+
{ slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
264
575
|
);
|
|
265
576
|
return undefined;
|
|
266
577
|
}
|
|
267
578
|
|
|
268
579
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
269
580
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
270
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
581
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
271
582
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
272
583
|
|
|
273
584
|
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
@@ -281,113 +592,60 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
281
592
|
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
282
593
|
});
|
|
283
594
|
} catch (err) {
|
|
284
|
-
this.log.error(`Built an invalid checkpoint at slot ${this.
|
|
595
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
285
596
|
checkpoint: checkpoint.header.toInspect(),
|
|
286
597
|
});
|
|
287
598
|
return undefined;
|
|
288
599
|
}
|
|
289
600
|
|
|
290
601
|
// Record checkpoint-level build metrics
|
|
291
|
-
this.
|
|
602
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
292
603
|
checkpointBuildTimer.ms(),
|
|
293
604
|
blocksInCheckpoint.length,
|
|
294
605
|
checkpoint.getStats().txCount,
|
|
295
606
|
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
296
607
|
);
|
|
297
608
|
|
|
298
|
-
//
|
|
609
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
299
610
|
if (this.config.fishermanMode) {
|
|
300
611
|
this.log.info(
|
|
301
|
-
`Built checkpoint for slot ${this.
|
|
612
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
302
613
|
`Skipping proposal in fisherman mode.`,
|
|
303
614
|
{
|
|
304
|
-
slot: this.
|
|
615
|
+
slot: this.targetSlot,
|
|
305
616
|
checkpoint: checkpoint.header.toInspect(),
|
|
306
617
|
blocksBuilt: blocksInCheckpoint.length,
|
|
307
618
|
},
|
|
308
619
|
);
|
|
309
620
|
this.metrics.recordCheckpointSuccess();
|
|
310
|
-
|
|
621
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
622
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
311
623
|
}
|
|
312
624
|
|
|
313
|
-
// Include the block pending broadcast in the checkpoint proposal if any
|
|
314
|
-
const lastBlock = blockPendingBroadcast && {
|
|
315
|
-
blockHeader: blockPendingBroadcast.block.header,
|
|
316
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
317
|
-
txs: blockPendingBroadcast.txs,
|
|
318
|
-
};
|
|
319
|
-
|
|
320
625
|
// Create the checkpoint proposal and broadcast it
|
|
321
626
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
322
627
|
checkpoint.header,
|
|
323
628
|
checkpoint.archive.root,
|
|
629
|
+
this.checkpointNumber,
|
|
324
630
|
feeAssetPriceModifier,
|
|
325
|
-
|
|
631
|
+
blockPendingBroadcast,
|
|
326
632
|
this.proposer,
|
|
327
633
|
checkpointProposalOptions,
|
|
328
634
|
);
|
|
329
635
|
|
|
330
636
|
const blockProposedAt = this.dateProvider.now();
|
|
331
637
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
638
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
332
639
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const blockAttestedAt = this.dateProvider.now();
|
|
336
|
-
|
|
337
|
-
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
338
|
-
|
|
339
|
-
// Proposer must sign over the attestations before pushing them to L1
|
|
340
|
-
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
341
|
-
let attestationsSignature: Signature;
|
|
342
|
-
try {
|
|
343
|
-
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
344
|
-
attestations,
|
|
345
|
-
signer,
|
|
346
|
-
this.slot,
|
|
347
|
-
this.checkpointNumber,
|
|
348
|
-
);
|
|
349
|
-
} catch (err) {
|
|
350
|
-
// We shouldn't really get here since we yield to another HA node
|
|
351
|
-
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
352
|
-
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
353
|
-
return undefined;
|
|
354
|
-
}
|
|
355
|
-
throw err;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Enqueue publishing the checkpoint to L1
|
|
359
|
-
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
360
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
361
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
362
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
363
|
-
|
|
364
|
-
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
365
|
-
if (
|
|
366
|
-
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
367
|
-
this.config.skipPublishingCheckpointsPercent > 0
|
|
368
|
-
) {
|
|
369
|
-
const result = Math.max(0, randomInt(100));
|
|
370
|
-
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
371
|
-
this.log.warn(
|
|
372
|
-
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
373
|
-
);
|
|
374
|
-
return checkpoint;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
379
|
-
txTimeoutAt,
|
|
380
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
return checkpoint;
|
|
640
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
641
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
384
642
|
} catch (err) {
|
|
385
643
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
386
644
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
387
645
|
return undefined;
|
|
388
646
|
}
|
|
389
647
|
|
|
390
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
648
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
391
649
|
return undefined;
|
|
392
650
|
}
|
|
393
651
|
}
|
|
@@ -403,15 +661,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
403
661
|
blockProposalOptions: BlockProposalOptions,
|
|
404
662
|
): Promise<{
|
|
405
663
|
blocksInCheckpoint: L2Block[];
|
|
406
|
-
blockPendingBroadcast:
|
|
664
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
407
665
|
}> {
|
|
408
666
|
const blocksInCheckpoint: L2Block[] = [];
|
|
409
667
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
410
668
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
411
|
-
const slot = this.slot;
|
|
412
669
|
|
|
413
670
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
414
|
-
let blockPendingBroadcast:
|
|
671
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
415
672
|
|
|
416
673
|
while (true) {
|
|
417
674
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -422,7 +679,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
422
679
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
423
680
|
|
|
424
681
|
if (!timingInfo.canStart) {
|
|
425
|
-
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
682
|
+
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
683
|
+
slot: this.targetSlot,
|
|
684
|
+
blocksBuilt,
|
|
685
|
+
secondsIntoSlot,
|
|
686
|
+
});
|
|
426
687
|
break;
|
|
427
688
|
}
|
|
428
689
|
|
|
@@ -440,49 +701,60 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
440
701
|
txHashesAlreadyIncluded,
|
|
441
702
|
});
|
|
442
703
|
|
|
443
|
-
//
|
|
444
|
-
if (
|
|
445
|
-
// If
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
|
449
711
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
450
712
|
continue;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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) {
|
|
456
718
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
457
|
-
this.log.warn(`Halting block building for slot ${
|
|
719
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
720
|
+
slot: this.targetSlot,
|
|
721
|
+
blocksBuilt,
|
|
722
|
+
error: buildResult.error,
|
|
723
|
+
});
|
|
458
724
|
}
|
|
459
725
|
break;
|
|
460
726
|
}
|
|
461
727
|
|
|
462
728
|
const { block, usedTxs } = buildResult;
|
|
729
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
730
|
+
isFirstBlock: blocksBuilt === 0,
|
|
731
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
732
|
+
});
|
|
733
|
+
|
|
463
734
|
blocksInCheckpoint.push(block);
|
|
464
735
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
465
736
|
|
|
466
|
-
//
|
|
467
|
-
// and exit the loop now so we can build the checkpoint and start collecting attestations.
|
|
468
|
-
if (timingInfo.isLastBlock) {
|
|
469
|
-
await this.syncProposedBlockToArchiver(block);
|
|
470
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${slot}`, { slot, blockNumber, blocksBuilt });
|
|
471
|
-
blockPendingBroadcast = { block, txs: usedTxs };
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
|
|
476
|
-
// in which case we'll broadcast it along with the checkpoint at the end of the loop.
|
|
477
|
-
// Note that we only send the block to the archiver if we manage to create the proposal, so if there's
|
|
478
|
-
// a HA error we don't pollute our archiver with a block that won't make it to the chain.
|
|
737
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
479
738
|
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
480
739
|
|
|
481
|
-
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal
|
|
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.
|
|
482
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.
|
|
483
743
|
// If this throws, we abort the entire checkpoint.
|
|
484
744
|
await this.syncProposedBlockToArchiver(block);
|
|
485
745
|
|
|
746
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
747
|
+
if (timingInfo.isLastBlock) {
|
|
748
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
749
|
+
slot: this.targetSlot,
|
|
750
|
+
blockNumber,
|
|
751
|
+
blocksBuilt,
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
blockPendingBroadcast = proposal;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
|
|
486
758
|
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
487
759
|
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
488
760
|
|
|
@@ -490,8 +762,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
490
762
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
491
763
|
}
|
|
492
764
|
|
|
493
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
494
|
-
slot: this.
|
|
765
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
766
|
+
slot: this.targetSlot,
|
|
495
767
|
blocksBuilt: blocksInCheckpoint.length,
|
|
496
768
|
});
|
|
497
769
|
|
|
@@ -511,6 +783,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
511
783
|
}
|
|
512
784
|
return this.validatorClient.createBlockProposal(
|
|
513
785
|
block.header,
|
|
786
|
+
this.checkpointNumber,
|
|
514
787
|
block.indexWithinCheckpoint,
|
|
515
788
|
inHash,
|
|
516
789
|
block.archive.root,
|
|
@@ -523,8 +796,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
523
796
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
524
797
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
525
798
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
526
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
527
|
-
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
799
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
800
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
801
|
+
slot: this.targetSlot,
|
|
802
|
+
});
|
|
528
803
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
529
804
|
}
|
|
530
805
|
|
|
@@ -540,12 +815,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
540
815
|
buildDeadline: Date | undefined;
|
|
541
816
|
txHashesAlreadyIncluded: Set<string>;
|
|
542
817
|
},
|
|
543
|
-
): Promise<
|
|
818
|
+
): Promise<
|
|
819
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
820
|
+
> {
|
|
544
821
|
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
545
822
|
opts;
|
|
546
823
|
|
|
547
824
|
this.log.verbose(
|
|
548
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
825
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
549
826
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
550
827
|
);
|
|
551
828
|
|
|
@@ -554,12 +831,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
554
831
|
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
555
832
|
if (!canStartBuilding) {
|
|
556
833
|
this.log.warn(
|
|
557
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
558
|
-
{ blockNumber, slot: this.
|
|
834
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
835
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
559
836
|
);
|
|
560
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
837
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
561
838
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
562
|
-
return
|
|
839
|
+
return { failure: 'insufficient-txs' };
|
|
563
840
|
}
|
|
564
841
|
|
|
565
842
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -570,10 +847,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
570
847
|
);
|
|
571
848
|
|
|
572
849
|
this.log.debug(
|
|
573
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
574
|
-
{ slot: this.
|
|
850
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
851
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
575
852
|
);
|
|
576
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
853
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
577
854
|
|
|
578
855
|
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
579
856
|
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
@@ -608,18 +885,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
608
885
|
|
|
609
886
|
if (buildResult.status === 'insufficient-valid-txs') {
|
|
610
887
|
this.log.warn(
|
|
611
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
888
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
612
889
|
{
|
|
613
|
-
slot: this.
|
|
890
|
+
slot: this.targetSlot,
|
|
614
891
|
blockNumber,
|
|
615
892
|
numTxs: buildResult.processedCount,
|
|
616
893
|
indexWithinCheckpoint,
|
|
617
894
|
minValidTxs,
|
|
618
895
|
},
|
|
619
896
|
);
|
|
620
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
897
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
898
|
+
reason: `Insufficient valid txs`,
|
|
899
|
+
slot: this.targetSlot,
|
|
900
|
+
});
|
|
621
901
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
622
|
-
return
|
|
902
|
+
return { failure: 'insufficient-valid-txs' };
|
|
623
903
|
}
|
|
624
904
|
|
|
625
905
|
// Block creation succeeded, emit stats and metrics
|
|
@@ -637,17 +917,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
637
917
|
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
638
918
|
|
|
639
919
|
this.log.info(
|
|
640
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
920
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
641
921
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
642
922
|
);
|
|
643
923
|
|
|
644
|
-
|
|
645
|
-
|
|
924
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
925
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
926
|
+
this.eventEmitter.emit('block-proposed', {
|
|
927
|
+
blockNumber: block.number,
|
|
928
|
+
slot: this.targetSlot,
|
|
929
|
+
buildSlot: this.slotNow,
|
|
930
|
+
});
|
|
931
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
646
932
|
|
|
647
933
|
return { block, usedTxs };
|
|
648
934
|
} catch (err: any) {
|
|
649
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
650
|
-
|
|
935
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
936
|
+
reason: err.message,
|
|
937
|
+
slot: this.targetSlot,
|
|
938
|
+
});
|
|
939
|
+
this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
|
|
651
940
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
652
941
|
this.metrics.recordFailedBlock();
|
|
653
942
|
return { error: err };
|
|
@@ -707,10 +996,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
707
996
|
}
|
|
708
997
|
|
|
709
998
|
// Wait a bit before checking again
|
|
710
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
999
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
711
1000
|
this.log.verbose(
|
|
712
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
713
|
-
{ blockNumber, slot: this.
|
|
1001
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
1002
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
714
1003
|
);
|
|
715
1004
|
await this.waitForTxsPollingInterval();
|
|
716
1005
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -719,12 +1008,44 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
719
1008
|
return { canStartBuilding: true, availableTxs, minTxs };
|
|
720
1009
|
}
|
|
721
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
|
+
|
|
722
1041
|
/**
|
|
723
1042
|
* Waits for enough attestations to be collected via p2p.
|
|
724
1043
|
* This is run after all blocks for the checkpoint have been built.
|
|
725
1044
|
*/
|
|
726
1045
|
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
727
|
-
private async waitForAttestations(
|
|
1046
|
+
private async waitForAttestations(
|
|
1047
|
+
proposal: CheckpointProposal,
|
|
1048
|
+
): Promise<CommitteeAttestationsAndSigners | undefined> {
|
|
728
1049
|
if (this.config.fishermanMode) {
|
|
729
1050
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
730
1051
|
return CommitteeAttestationsAndSigners.empty();
|
|
@@ -742,16 +1063,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
742
1063
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
743
1064
|
}
|
|
744
1065
|
|
|
745
|
-
const numberOfRequiredAttestations =
|
|
1066
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
746
1067
|
|
|
747
1068
|
if (this.config.skipCollectingAttestations) {
|
|
748
1069
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
749
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
1070
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
750
1071
|
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
751
1072
|
}
|
|
752
1073
|
|
|
753
1074
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
754
|
-
? this.timetable.
|
|
1075
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
755
1076
|
: this.l1Constants.slotDuration;
|
|
756
1077
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
757
1078
|
|
|
@@ -764,6 +1085,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
764
1085
|
proposal,
|
|
765
1086
|
numberOfRequiredAttestations,
|
|
766
1087
|
attestationDeadline,
|
|
1088
|
+
this.checkpointNumber,
|
|
767
1089
|
);
|
|
768
1090
|
|
|
769
1091
|
collectedAttestationsCount = attestations.length;
|
|
@@ -797,8 +1119,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
797
1119
|
} catch (err) {
|
|
798
1120
|
if (err && err instanceof AttestationTimeoutError) {
|
|
799
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);
|
|
800
1128
|
}
|
|
801
|
-
|
|
1129
|
+
return undefined;
|
|
802
1130
|
} finally {
|
|
803
1131
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
804
1132
|
}
|
|
@@ -854,11 +1182,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
854
1182
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
855
1183
|
|
|
856
1184
|
const shuffled = [...attestations];
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1185
|
+
|
|
1186
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1187
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1188
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1189
|
+
const swappable: number[] = [];
|
|
1190
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
1191
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1192
|
+
swappable.push(k);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
if (swappable.length >= 2) {
|
|
1196
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
1197
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
1198
|
+
}
|
|
862
1199
|
|
|
863
1200
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
864
1201
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -887,7 +1224,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
887
1224
|
* whenever the real proposer's block arrives from L1.
|
|
888
1225
|
*/
|
|
889
1226
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
890
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1227
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
891
1228
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
892
1229
|
blockNumber: block.number,
|
|
893
1230
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -905,19 +1242,19 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
905
1242
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
906
1243
|
// Perform L1 fee analysis before clearing requests
|
|
907
1244
|
// The callback is invoked asynchronously after the next block is mined
|
|
908
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1245
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
909
1246
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
910
1247
|
);
|
|
911
1248
|
|
|
912
1249
|
if (checkpoint) {
|
|
913
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1250
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
914
1251
|
...checkpoint.toCheckpointInfo(),
|
|
915
1252
|
...checkpoint.getStats(),
|
|
916
1253
|
feeAnalysisId: feeAnalysis?.id,
|
|
917
1254
|
});
|
|
918
1255
|
} else {
|
|
919
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
920
|
-
slot: this.
|
|
1256
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1257
|
+
slot: this.targetSlot,
|
|
921
1258
|
feeAnalysisId: feeAnalysis?.id,
|
|
922
1259
|
});
|
|
923
1260
|
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
@@ -931,15 +1268,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
931
1268
|
*/
|
|
932
1269
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
933
1270
|
if (err instanceof DutyAlreadySignedError) {
|
|
934
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
935
|
-
slot: this.
|
|
1271
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1272
|
+
slot: this.targetSlot,
|
|
936
1273
|
signedByNode: err.signedByNode,
|
|
937
1274
|
});
|
|
938
1275
|
return true;
|
|
939
1276
|
}
|
|
940
1277
|
if (err instanceof SlashingProtectionError) {
|
|
941
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
942
|
-
slot: this.
|
|
1278
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1279
|
+
slot: this.targetSlot,
|
|
943
1280
|
existingMessageHash: err.existingMessageHash,
|
|
944
1281
|
attemptedMessageHash: err.attemptedMessageHash,
|
|
945
1282
|
});
|
|
@@ -962,7 +1299,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
962
1299
|
}
|
|
963
1300
|
|
|
964
1301
|
private getSlotStartBuildTimestamp(): number {
|
|
965
|
-
return getSlotStartBuildTimestamp(this.
|
|
1302
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
966
1303
|
}
|
|
967
1304
|
|
|
968
1305
|
private getSecondsIntoSlot(): number {
|