@aztec/sequencer-client 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8
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 +24 -7
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +277 -169
- 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 +2 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +9 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +23 -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 +338 -177
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/events.ts +1 -1
- package/src/sequencer/metrics.ts +29 -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,
|
|
@@ -30,8 +31,8 @@ import {
|
|
|
30
31
|
type L2BlockSource,
|
|
31
32
|
MaliciousCommitteeAttestationsAndSigners,
|
|
32
33
|
} from '@aztec/stdlib/block';
|
|
33
|
-
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
34
|
-
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
34
|
+
import { type Checkpoint, type ProposedCheckpointData, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
35
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
35
36
|
import { Gas } from '@aztec/stdlib/gas';
|
|
36
37
|
import {
|
|
37
38
|
type BlockBuilderOptions,
|
|
@@ -56,6 +57,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
56
57
|
|
|
57
58
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
58
59
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
60
|
+
import {
|
|
61
|
+
buildPipelinedParentSimulationOverridesPlan,
|
|
62
|
+
buildSubmissionSimulationOverridesPlan,
|
|
63
|
+
} from './chain_state_overrides.js';
|
|
64
|
+
import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
|
|
59
65
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
60
66
|
import { SequencerInterruptedError } from './errors.js';
|
|
61
67
|
import type { SequencerEvents } from './events.js';
|
|
@@ -67,6 +73,20 @@ import { SequencerState } from './utils.js';
|
|
|
67
73
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
68
74
|
const TXS_POLLING_MS = 500;
|
|
69
75
|
|
|
76
|
+
/** Result from proposeCheckpoint when a checkpoint was successfully built and broadcast. */
|
|
77
|
+
type CheckpointProposalBroadcast = {
|
|
78
|
+
checkpoint: Checkpoint;
|
|
79
|
+
proposal: CheckpointProposal;
|
|
80
|
+
blockProposedAt: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Result after attestation collection and signing, ready for L1 submission. */
|
|
84
|
+
type CheckpointProposalResult = {
|
|
85
|
+
checkpoint: Checkpoint;
|
|
86
|
+
attestations: CommitteeAttestationsAndSigners;
|
|
87
|
+
attestationsSignature: Signature;
|
|
88
|
+
};
|
|
89
|
+
|
|
70
90
|
/**
|
|
71
91
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
72
92
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
@@ -76,9 +96,16 @@ const TXS_POLLING_MS = 500;
|
|
|
76
96
|
export class CheckpointProposalJob implements Traceable {
|
|
77
97
|
protected readonly log: Logger;
|
|
78
98
|
|
|
99
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
100
|
+
private pendingL1Submission: Promise<void> | undefined;
|
|
101
|
+
|
|
102
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */
|
|
103
|
+
private pipelinedParentSimulationOverridesPlan?: SimulationOverridesPlan;
|
|
104
|
+
|
|
79
105
|
constructor(
|
|
80
|
-
private readonly
|
|
81
|
-
private readonly
|
|
106
|
+
private readonly slotNow: SlotNumber,
|
|
107
|
+
private readonly targetSlot: SlotNumber,
|
|
108
|
+
private readonly targetEpoch: EpochNumber,
|
|
82
109
|
private readonly checkpointNumber: CheckpointNumber,
|
|
83
110
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
84
111
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
@@ -101,17 +128,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
101
128
|
private readonly epochCache: EpochCache,
|
|
102
129
|
private readonly dateProvider: DateProvider,
|
|
103
130
|
private readonly metrics: SequencerMetrics,
|
|
131
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
104
132
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
105
133
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
106
134
|
public readonly tracer: Tracer,
|
|
107
135
|
bindings?: LoggerBindings,
|
|
136
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
108
137
|
) {
|
|
109
|
-
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
138
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
139
|
+
...bindings,
|
|
140
|
+
instanceId: `slot-${this.slotNow}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
|
|
145
|
+
public async awaitPendingSubmission(): Promise<void> {
|
|
146
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
147
|
+
await this.pendingL1Submission;
|
|
110
148
|
}
|
|
111
149
|
|
|
112
150
|
/**
|
|
113
151
|
* Executes the checkpoint proposal job.
|
|
114
|
-
*
|
|
152
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
153
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
154
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
155
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
115
156
|
*/
|
|
116
157
|
@trackSpan('CheckpointProposalJob.execute')
|
|
117
158
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -119,7 +160,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
119
160
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
120
161
|
// These are constant for the whole slot, so we only enqueue them once
|
|
121
162
|
const votesPromises = new CheckpointVoter(
|
|
122
|
-
this.
|
|
163
|
+
this.targetSlot,
|
|
123
164
|
this.publisher,
|
|
124
165
|
this.attestorAddress,
|
|
125
166
|
this.validatorClient,
|
|
@@ -130,63 +171,195 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
130
171
|
this.log,
|
|
131
172
|
).enqueueVotes();
|
|
132
173
|
|
|
133
|
-
// Build
|
|
134
|
-
|
|
174
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
175
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
176
|
+
const broadcast = await this.proposeCheckpoint();
|
|
135
177
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
178
|
+
if (!broadcast) {
|
|
179
|
+
await Promise.all(votesPromises);
|
|
180
|
+
// Still submit votes even without a checkpoint
|
|
181
|
+
if (!this.config.fishermanMode) {
|
|
182
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(() => {});
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
141
185
|
}
|
|
142
186
|
|
|
187
|
+
const { checkpoint } = broadcast;
|
|
188
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
189
|
+
|
|
143
190
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
144
191
|
if (this.config.fishermanMode) {
|
|
145
192
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
146
|
-
return;
|
|
193
|
+
return checkpoint;
|
|
147
194
|
}
|
|
148
195
|
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
196
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
197
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
198
|
+
|
|
199
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
200
|
+
return checkpoint;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
205
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
206
|
+
*/
|
|
207
|
+
private async waitForAttestationsAndEnqueueSubmissionAsync(
|
|
208
|
+
broadcast: CheckpointProposalBroadcast,
|
|
209
|
+
votesPromises: Promise<unknown>[],
|
|
210
|
+
): Promise<void> {
|
|
211
|
+
const { checkpoint, proposal, blockProposedAt } = broadcast;
|
|
212
|
+
try {
|
|
213
|
+
await Promise.all(votesPromises);
|
|
214
|
+
|
|
215
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
216
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
217
|
+
|
|
218
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
219
|
+
|
|
220
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
221
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
222
|
+
let attestationsSignature: Signature;
|
|
223
|
+
try {
|
|
224
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
225
|
+
attestations,
|
|
226
|
+
signer,
|
|
227
|
+
this.targetSlot,
|
|
228
|
+
this.checkpointNumber,
|
|
229
|
+
);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
throw err;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Enqueue the checkpoint for L1 submission
|
|
238
|
+
await this.enqueueCheckpointForSubmission({ checkpoint, attestations, attestationsSignature });
|
|
239
|
+
|
|
240
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
241
|
+
const submitAfter = this.epochCache.isProposerPipeliningEnabled()
|
|
242
|
+
? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000)
|
|
243
|
+
: new Date(this.dateProvider.now());
|
|
244
|
+
|
|
245
|
+
const l1Response = await this.publisher.sendRequestsAt(submitAfter);
|
|
246
|
+
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
247
|
+
if (proposedAction) {
|
|
248
|
+
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
249
|
+
const coinbase = checkpoint.header.coinbase;
|
|
250
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
251
|
+
} else {
|
|
252
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
253
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
254
|
+
this.metrics.recordPipelineDiscard();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (err instanceof SequencerInterruptedError) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
|
|
262
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
263
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
264
|
+
this.metrics.recordPipelineDiscard();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
270
|
+
private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
|
|
271
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
272
|
+
|
|
273
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
274
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
275
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
276
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
277
|
+
|
|
278
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
279
|
+
if (
|
|
280
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
281
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
282
|
+
) {
|
|
283
|
+
const roll = Math.max(0, randomInt(100));
|
|
284
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
285
|
+
this.log.warn(
|
|
286
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
|
|
287
|
+
);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
160
290
|
}
|
|
291
|
+
|
|
292
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
293
|
+
const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
|
|
294
|
+
pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
|
|
295
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
296
|
+
lastArchiveRoot: checkpoint.header.lastArchiveRoot,
|
|
297
|
+
pipeliningEnabled: isPipelining,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
301
|
+
txTimeoutAt,
|
|
302
|
+
...(submissionSimulationOverridesPlan ? { simulationOverridesPlan: submissionSimulationOverridesPlan } : {}),
|
|
303
|
+
});
|
|
161
304
|
}
|
|
162
305
|
|
|
163
306
|
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
164
307
|
return {
|
|
165
308
|
// nullish operator needed for tests
|
|
166
309
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
167
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
310
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
168
311
|
};
|
|
169
312
|
})
|
|
170
|
-
private async proposeCheckpoint(): Promise<
|
|
313
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
171
314
|
try {
|
|
315
|
+
const now = this.dateProvider.now();
|
|
316
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
317
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
318
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
319
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
320
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
321
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
322
|
+
}
|
|
323
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
324
|
+
|
|
172
325
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
173
326
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
174
327
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
175
328
|
|
|
176
329
|
// Start the checkpoint
|
|
177
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
178
|
-
this.
|
|
330
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
331
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
332
|
+
buildSlot: this.slotNow,
|
|
333
|
+
submissionSlot: this.targetSlot,
|
|
334
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
335
|
+
proposer: this.proposer?.toString(),
|
|
336
|
+
coinbase: coinbase.toString(),
|
|
337
|
+
});
|
|
338
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
179
339
|
|
|
180
340
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
181
341
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
182
342
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
183
343
|
}
|
|
184
344
|
|
|
185
|
-
// Create checkpoint builder for the slot
|
|
345
|
+
// Create checkpoint builder for the slot.
|
|
346
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
347
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
348
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
349
|
+
this.pipelinedParentSimulationOverridesPlan = isPipelining
|
|
350
|
+
? await buildPipelinedParentSimulationOverridesPlan({
|
|
351
|
+
checkpointNumber: this.checkpointNumber,
|
|
352
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
353
|
+
rollup: this.publisher.rollupContract,
|
|
354
|
+
log: this.log,
|
|
355
|
+
})
|
|
356
|
+
: undefined;
|
|
357
|
+
|
|
186
358
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
187
359
|
coinbase,
|
|
188
360
|
feeRecipient,
|
|
189
|
-
this.
|
|
361
|
+
this.targetSlot,
|
|
362
|
+
this.pipelinedParentSimulationOverridesPlan,
|
|
190
363
|
);
|
|
191
364
|
|
|
192
365
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -194,7 +367,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
194
367
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
195
368
|
|
|
196
369
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
197
|
-
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.
|
|
370
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
|
|
198
371
|
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
199
372
|
.map(c => c.checkpointOutHash);
|
|
200
373
|
|
|
@@ -227,7 +400,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
227
400
|
};
|
|
228
401
|
|
|
229
402
|
let blocksInCheckpoint: L2Block[] = [];
|
|
230
|
-
let blockPendingBroadcast:
|
|
403
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
231
404
|
const checkpointBuildTimer = new Timer();
|
|
232
405
|
|
|
233
406
|
try {
|
|
@@ -251,8 +424,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
251
424
|
}
|
|
252
425
|
|
|
253
426
|
if (blocksInCheckpoint.length === 0) {
|
|
254
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
255
|
-
this.eventEmitter.emit('checkpoint-empty', { slot: this.
|
|
427
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, { slot: this.targetSlot });
|
|
428
|
+
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
256
429
|
return undefined;
|
|
257
430
|
}
|
|
258
431
|
|
|
@@ -260,14 +433,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
260
433
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
261
434
|
this.log.warn(
|
|
262
435
|
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
263
|
-
{ slot: this.
|
|
436
|
+
{ slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
264
437
|
);
|
|
265
438
|
return undefined;
|
|
266
439
|
}
|
|
267
440
|
|
|
268
441
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
269
442
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
270
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
443
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
271
444
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
272
445
|
|
|
273
446
|
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
@@ -281,113 +454,60 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
281
454
|
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
282
455
|
});
|
|
283
456
|
} catch (err) {
|
|
284
|
-
this.log.error(`Built an invalid checkpoint at slot ${this.
|
|
457
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
285
458
|
checkpoint: checkpoint.header.toInspect(),
|
|
286
459
|
});
|
|
287
460
|
return undefined;
|
|
288
461
|
}
|
|
289
462
|
|
|
290
463
|
// Record checkpoint-level build metrics
|
|
291
|
-
this.
|
|
464
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
292
465
|
checkpointBuildTimer.ms(),
|
|
293
466
|
blocksInCheckpoint.length,
|
|
294
467
|
checkpoint.getStats().txCount,
|
|
295
468
|
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
296
469
|
);
|
|
297
470
|
|
|
298
|
-
//
|
|
471
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
299
472
|
if (this.config.fishermanMode) {
|
|
300
473
|
this.log.info(
|
|
301
|
-
`Built checkpoint for slot ${this.
|
|
474
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
302
475
|
`Skipping proposal in fisherman mode.`,
|
|
303
476
|
{
|
|
304
|
-
slot: this.
|
|
477
|
+
slot: this.targetSlot,
|
|
305
478
|
checkpoint: checkpoint.header.toInspect(),
|
|
306
479
|
blocksBuilt: blocksInCheckpoint.length,
|
|
307
480
|
},
|
|
308
481
|
);
|
|
309
482
|
this.metrics.recordCheckpointSuccess();
|
|
310
|
-
|
|
483
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
484
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
311
485
|
}
|
|
312
486
|
|
|
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
487
|
// Create the checkpoint proposal and broadcast it
|
|
321
488
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
322
489
|
checkpoint.header,
|
|
323
490
|
checkpoint.archive.root,
|
|
491
|
+
this.checkpointNumber,
|
|
324
492
|
feeAssetPriceModifier,
|
|
325
|
-
|
|
493
|
+
blockPendingBroadcast,
|
|
326
494
|
this.proposer,
|
|
327
495
|
checkpointProposalOptions,
|
|
328
496
|
);
|
|
329
497
|
|
|
330
498
|
const blockProposedAt = this.dateProvider.now();
|
|
331
499
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
500
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
332
501
|
|
|
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;
|
|
502
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
503
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
384
504
|
} catch (err) {
|
|
385
505
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
386
506
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
387
507
|
return undefined;
|
|
388
508
|
}
|
|
389
509
|
|
|
390
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
510
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
391
511
|
return undefined;
|
|
392
512
|
}
|
|
393
513
|
}
|
|
@@ -403,15 +523,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
403
523
|
blockProposalOptions: BlockProposalOptions,
|
|
404
524
|
): Promise<{
|
|
405
525
|
blocksInCheckpoint: L2Block[];
|
|
406
|
-
blockPendingBroadcast:
|
|
526
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
407
527
|
}> {
|
|
408
528
|
const blocksInCheckpoint: L2Block[] = [];
|
|
409
529
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
410
530
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
411
|
-
const slot = this.slot;
|
|
412
531
|
|
|
413
532
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
414
|
-
let blockPendingBroadcast:
|
|
533
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
415
534
|
|
|
416
535
|
while (true) {
|
|
417
536
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -422,7 +541,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
422
541
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
423
542
|
|
|
424
543
|
if (!timingInfo.canStart) {
|
|
425
|
-
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
544
|
+
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
545
|
+
slot: this.targetSlot,
|
|
546
|
+
blocksBuilt,
|
|
547
|
+
secondsIntoSlot,
|
|
548
|
+
});
|
|
426
549
|
break;
|
|
427
550
|
}
|
|
428
551
|
|
|
@@ -440,49 +563,60 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
440
563
|
txHashesAlreadyIncluded,
|
|
441
564
|
});
|
|
442
565
|
|
|
443
|
-
//
|
|
444
|
-
if (
|
|
445
|
-
// If
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
566
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
567
|
+
if ('failure' in buildResult) {
|
|
568
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
569
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
449
573
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
450
574
|
continue;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
578
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
579
|
+
if ('error' in buildResult) {
|
|
456
580
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
457
|
-
this.log.warn(`Halting block building for slot ${
|
|
581
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
582
|
+
slot: this.targetSlot,
|
|
583
|
+
blocksBuilt,
|
|
584
|
+
error: buildResult.error,
|
|
585
|
+
});
|
|
458
586
|
}
|
|
459
587
|
break;
|
|
460
588
|
}
|
|
461
589
|
|
|
462
590
|
const { block, usedTxs } = buildResult;
|
|
591
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
592
|
+
isFirstBlock: blocksBuilt === 0,
|
|
593
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
594
|
+
});
|
|
595
|
+
|
|
463
596
|
blocksInCheckpoint.push(block);
|
|
464
597
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
465
598
|
|
|
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.
|
|
599
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
479
600
|
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
480
601
|
|
|
481
|
-
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal
|
|
602
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
603
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
482
604
|
// 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
605
|
// If this throws, we abort the entire checkpoint.
|
|
484
606
|
await this.syncProposedBlockToArchiver(block);
|
|
485
607
|
|
|
608
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
609
|
+
if (timingInfo.isLastBlock) {
|
|
610
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
611
|
+
slot: this.targetSlot,
|
|
612
|
+
blockNumber,
|
|
613
|
+
blocksBuilt,
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
blockPendingBroadcast = proposal;
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
|
|
486
620
|
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
487
621
|
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
488
622
|
|
|
@@ -490,8 +624,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
490
624
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
491
625
|
}
|
|
492
626
|
|
|
493
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
494
|
-
slot: this.
|
|
627
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
628
|
+
slot: this.targetSlot,
|
|
495
629
|
blocksBuilt: blocksInCheckpoint.length,
|
|
496
630
|
});
|
|
497
631
|
|
|
@@ -511,6 +645,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
511
645
|
}
|
|
512
646
|
return this.validatorClient.createBlockProposal(
|
|
513
647
|
block.header,
|
|
648
|
+
this.checkpointNumber,
|
|
514
649
|
block.indexWithinCheckpoint,
|
|
515
650
|
inHash,
|
|
516
651
|
block.archive.root,
|
|
@@ -523,8 +658,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
523
658
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
524
659
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
525
660
|
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`, {
|
|
661
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
662
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
663
|
+
slot: this.targetSlot,
|
|
664
|
+
});
|
|
528
665
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
529
666
|
}
|
|
530
667
|
|
|
@@ -540,12 +677,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
540
677
|
buildDeadline: Date | undefined;
|
|
541
678
|
txHashesAlreadyIncluded: Set<string>;
|
|
542
679
|
},
|
|
543
|
-
): Promise<
|
|
680
|
+
): Promise<
|
|
681
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
682
|
+
> {
|
|
544
683
|
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
545
684
|
opts;
|
|
546
685
|
|
|
547
686
|
this.log.verbose(
|
|
548
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
687
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
549
688
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
550
689
|
);
|
|
551
690
|
|
|
@@ -554,12 +693,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
554
693
|
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
555
694
|
if (!canStartBuilding) {
|
|
556
695
|
this.log.warn(
|
|
557
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
558
|
-
{ blockNumber, slot: this.
|
|
696
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
697
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
559
698
|
);
|
|
560
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
699
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
561
700
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
562
|
-
return
|
|
701
|
+
return { failure: 'insufficient-txs' };
|
|
563
702
|
}
|
|
564
703
|
|
|
565
704
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -570,10 +709,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
570
709
|
);
|
|
571
710
|
|
|
572
711
|
this.log.debug(
|
|
573
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
574
|
-
{ slot: this.
|
|
712
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
713
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
575
714
|
);
|
|
576
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
715
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
577
716
|
|
|
578
717
|
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
579
718
|
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
@@ -608,18 +747,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
608
747
|
|
|
609
748
|
if (buildResult.status === 'insufficient-valid-txs') {
|
|
610
749
|
this.log.warn(
|
|
611
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
750
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
612
751
|
{
|
|
613
|
-
slot: this.
|
|
752
|
+
slot: this.targetSlot,
|
|
614
753
|
blockNumber,
|
|
615
754
|
numTxs: buildResult.processedCount,
|
|
616
755
|
indexWithinCheckpoint,
|
|
617
756
|
minValidTxs,
|
|
618
757
|
},
|
|
619
758
|
);
|
|
620
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
759
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
760
|
+
reason: `Insufficient valid txs`,
|
|
761
|
+
slot: this.targetSlot,
|
|
762
|
+
});
|
|
621
763
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
622
|
-
return
|
|
764
|
+
return { failure: 'insufficient-valid-txs' };
|
|
623
765
|
}
|
|
624
766
|
|
|
625
767
|
// Block creation succeeded, emit stats and metrics
|
|
@@ -637,17 +779,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
637
779
|
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
638
780
|
|
|
639
781
|
this.log.info(
|
|
640
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
782
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
641
783
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
642
784
|
);
|
|
643
785
|
|
|
644
|
-
|
|
645
|
-
|
|
786
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
787
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
788
|
+
this.eventEmitter.emit('block-proposed', {
|
|
789
|
+
blockNumber: block.number,
|
|
790
|
+
slot: this.targetSlot,
|
|
791
|
+
buildSlot: this.slotNow,
|
|
792
|
+
});
|
|
793
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
646
794
|
|
|
647
795
|
return { block, usedTxs };
|
|
648
796
|
} catch (err: any) {
|
|
649
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
650
|
-
|
|
797
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
798
|
+
reason: err.message,
|
|
799
|
+
slot: this.targetSlot,
|
|
800
|
+
});
|
|
801
|
+
this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
|
|
651
802
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
652
803
|
this.metrics.recordFailedBlock();
|
|
653
804
|
return { error: err };
|
|
@@ -707,10 +858,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
707
858
|
}
|
|
708
859
|
|
|
709
860
|
// Wait a bit before checking again
|
|
710
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
861
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
711
862
|
this.log.verbose(
|
|
712
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
713
|
-
{ blockNumber, slot: this.
|
|
863
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
864
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
714
865
|
);
|
|
715
866
|
await this.waitForTxsPollingInterval();
|
|
716
867
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -742,16 +893,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
742
893
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
743
894
|
}
|
|
744
895
|
|
|
745
|
-
const numberOfRequiredAttestations =
|
|
896
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
746
897
|
|
|
747
898
|
if (this.config.skipCollectingAttestations) {
|
|
748
899
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
749
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
900
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
750
901
|
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
751
902
|
}
|
|
752
903
|
|
|
753
904
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
754
|
-
? this.timetable.
|
|
905
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
755
906
|
: this.l1Constants.slotDuration;
|
|
756
907
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
757
908
|
|
|
@@ -764,6 +915,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
764
915
|
proposal,
|
|
765
916
|
numberOfRequiredAttestations,
|
|
766
917
|
attestationDeadline,
|
|
918
|
+
this.checkpointNumber,
|
|
767
919
|
);
|
|
768
920
|
|
|
769
921
|
collectedAttestationsCount = attestations.length;
|
|
@@ -854,11 +1006,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
854
1006
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
855
1007
|
|
|
856
1008
|
const shuffled = [...attestations];
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1009
|
+
|
|
1010
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1011
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1012
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1013
|
+
const swappable: number[] = [];
|
|
1014
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
1015
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1016
|
+
swappable.push(k);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (swappable.length >= 2) {
|
|
1020
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
1021
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
1022
|
+
}
|
|
862
1023
|
|
|
863
1024
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
864
1025
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -887,7 +1048,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
887
1048
|
* whenever the real proposer's block arrives from L1.
|
|
888
1049
|
*/
|
|
889
1050
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
890
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1051
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
891
1052
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
892
1053
|
blockNumber: block.number,
|
|
893
1054
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -905,19 +1066,19 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
905
1066
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
906
1067
|
// Perform L1 fee analysis before clearing requests
|
|
907
1068
|
// The callback is invoked asynchronously after the next block is mined
|
|
908
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1069
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
909
1070
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
910
1071
|
);
|
|
911
1072
|
|
|
912
1073
|
if (checkpoint) {
|
|
913
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1074
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
914
1075
|
...checkpoint.toCheckpointInfo(),
|
|
915
1076
|
...checkpoint.getStats(),
|
|
916
1077
|
feeAnalysisId: feeAnalysis?.id,
|
|
917
1078
|
});
|
|
918
1079
|
} else {
|
|
919
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
920
|
-
slot: this.
|
|
1080
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1081
|
+
slot: this.targetSlot,
|
|
921
1082
|
feeAnalysisId: feeAnalysis?.id,
|
|
922
1083
|
});
|
|
923
1084
|
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
@@ -931,15 +1092,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
931
1092
|
*/
|
|
932
1093
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
933
1094
|
if (err instanceof DutyAlreadySignedError) {
|
|
934
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
935
|
-
slot: this.
|
|
1095
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1096
|
+
slot: this.targetSlot,
|
|
936
1097
|
signedByNode: err.signedByNode,
|
|
937
1098
|
});
|
|
938
1099
|
return true;
|
|
939
1100
|
}
|
|
940
1101
|
if (err instanceof SlashingProtectionError) {
|
|
941
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
942
|
-
slot: this.
|
|
1102
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1103
|
+
slot: this.targetSlot,
|
|
943
1104
|
existingMessageHash: err.existingMessageHash,
|
|
944
1105
|
attemptedMessageHash: err.attemptedMessageHash,
|
|
945
1106
|
});
|
|
@@ -962,7 +1123,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
962
1123
|
}
|
|
963
1124
|
|
|
964
1125
|
private getSlotStartBuildTimestamp(): number {
|
|
965
|
-
return getSlotStartBuildTimestamp(this.
|
|
1126
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
966
1127
|
}
|
|
967
1128
|
|
|
968
1129
|
private getSecondsIntoSlot(): number {
|