@aztec/sequencer-client 0.0.1-commit.3e3d0c9cd → 0.0.1-commit.3f5453c7b
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 +6 -13
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +32 -84
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -9
- 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 +15 -14
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -51
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/publisher/config.d.ts +13 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +17 -2
- package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +2 -3
- package/dest/publisher/sequencer-publisher.d.ts +51 -43
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +124 -110
- 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 +26 -7
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +274 -159
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +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 +20 -7
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +125 -60
- 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 +4 -8
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/package.json +27 -27
- package/src/client/sequencer-client.ts +44 -110
- package/src/config.ts +4 -8
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +26 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +32 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -6
- package/src/publisher/sequencer-publisher.ts +191 -157
- package/src/sequencer/README.md +83 -13
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +353 -186
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +1 -1
- package/src/sequencer/metrics.ts +29 -25
- package/src/sequencer/sequencer.ts +185 -66
- package/src/sequencer/timetable.ts +57 -45
- package/src/test/mock_checkpoint_builder.ts +3 -3
|
@@ -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,17 +31,22 @@ 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 {
|
|
38
|
+
type BlockBuilderOptions,
|
|
37
39
|
InsufficientValidTxsError,
|
|
38
|
-
type PublicProcessorLimits,
|
|
39
40
|
type ResolvedSequencerConfig,
|
|
40
41
|
type WorldStateSynchronizer,
|
|
41
42
|
} from '@aztec/stdlib/interfaces/server';
|
|
42
43
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
43
|
-
import type {
|
|
44
|
+
import type {
|
|
45
|
+
BlockProposal,
|
|
46
|
+
BlockProposalOptions,
|
|
47
|
+
CheckpointProposal,
|
|
48
|
+
CheckpointProposalOptions,
|
|
49
|
+
} from '@aztec/stdlib/p2p';
|
|
44
50
|
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
45
51
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
46
52
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
@@ -51,6 +57,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
51
57
|
|
|
52
58
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
53
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';
|
|
54
65
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
55
66
|
import { SequencerInterruptedError } from './errors.js';
|
|
56
67
|
import type { SequencerEvents } from './events.js';
|
|
@@ -62,6 +73,20 @@ import { SequencerState } from './utils.js';
|
|
|
62
73
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
63
74
|
const TXS_POLLING_MS = 500;
|
|
64
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
|
+
|
|
65
90
|
/**
|
|
66
91
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
67
92
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
@@ -71,9 +96,16 @@ const TXS_POLLING_MS = 500;
|
|
|
71
96
|
export class CheckpointProposalJob implements Traceable {
|
|
72
97
|
protected readonly log: Logger;
|
|
73
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
|
+
|
|
74
105
|
constructor(
|
|
75
|
-
private readonly
|
|
76
|
-
private readonly
|
|
106
|
+
private readonly slotNow: SlotNumber,
|
|
107
|
+
private readonly targetSlot: SlotNumber,
|
|
108
|
+
private readonly targetEpoch: EpochNumber,
|
|
77
109
|
private readonly checkpointNumber: CheckpointNumber,
|
|
78
110
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
79
111
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
@@ -96,17 +128,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
96
128
|
private readonly epochCache: EpochCache,
|
|
97
129
|
private readonly dateProvider: DateProvider,
|
|
98
130
|
private readonly metrics: SequencerMetrics,
|
|
131
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
99
132
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
100
133
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
101
134
|
public readonly tracer: Tracer,
|
|
102
135
|
bindings?: LoggerBindings,
|
|
136
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
103
137
|
) {
|
|
104
|
-
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;
|
|
105
148
|
}
|
|
106
149
|
|
|
107
150
|
/**
|
|
108
151
|
* Executes the checkpoint proposal job.
|
|
109
|
-
*
|
|
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.
|
|
110
156
|
*/
|
|
111
157
|
@trackSpan('CheckpointProposalJob.execute')
|
|
112
158
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -114,7 +160,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
114
160
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
115
161
|
// These are constant for the whole slot, so we only enqueue them once
|
|
116
162
|
const votesPromises = new CheckpointVoter(
|
|
117
|
-
this.
|
|
163
|
+
this.targetSlot,
|
|
118
164
|
this.publisher,
|
|
119
165
|
this.attestorAddress,
|
|
120
166
|
this.validatorClient,
|
|
@@ -125,63 +171,195 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
125
171
|
this.log,
|
|
126
172
|
).enqueueVotes();
|
|
127
173
|
|
|
128
|
-
// Build
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
132
|
-
await Promise.all(votesPromises);
|
|
174
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
175
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
176
|
+
const broadcast = await this.proposeCheckpoint();
|
|
133
177
|
|
|
134
|
-
if (
|
|
135
|
-
|
|
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;
|
|
136
185
|
}
|
|
137
186
|
|
|
187
|
+
const { checkpoint } = broadcast;
|
|
188
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
189
|
+
|
|
138
190
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
139
191
|
if (this.config.fishermanMode) {
|
|
140
192
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
141
|
-
return;
|
|
193
|
+
return checkpoint;
|
|
142
194
|
}
|
|
143
195
|
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
|
155
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
|
+
});
|
|
156
304
|
}
|
|
157
305
|
|
|
158
306
|
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
159
307
|
return {
|
|
160
308
|
// nullish operator needed for tests
|
|
161
309
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
162
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
310
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
163
311
|
};
|
|
164
312
|
})
|
|
165
|
-
private async proposeCheckpoint(): Promise<
|
|
313
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
166
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
|
+
|
|
167
325
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
168
326
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
169
327
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
170
328
|
|
|
171
329
|
// Start the checkpoint
|
|
172
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
173
|
-
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');
|
|
174
339
|
|
|
175
340
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
176
341
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
177
342
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
178
343
|
}
|
|
179
344
|
|
|
180
|
-
// 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
|
+
|
|
181
358
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
182
359
|
coinbase,
|
|
183
360
|
feeRecipient,
|
|
184
|
-
this.
|
|
361
|
+
this.targetSlot,
|
|
362
|
+
this.pipelinedParentSimulationOverridesPlan,
|
|
185
363
|
);
|
|
186
364
|
|
|
187
365
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -189,7 +367,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
189
367
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
190
368
|
|
|
191
369
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
192
|
-
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.
|
|
370
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
|
|
193
371
|
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
194
372
|
.map(c => c.checkpointOutHash);
|
|
195
373
|
|
|
@@ -222,7 +400,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
222
400
|
};
|
|
223
401
|
|
|
224
402
|
let blocksInCheckpoint: L2Block[] = [];
|
|
225
|
-
let blockPendingBroadcast:
|
|
403
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
226
404
|
const checkpointBuildTimer = new Timer();
|
|
227
405
|
|
|
228
406
|
try {
|
|
@@ -246,8 +424,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
246
424
|
}
|
|
247
425
|
|
|
248
426
|
if (blocksInCheckpoint.length === 0) {
|
|
249
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
250
|
-
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 });
|
|
251
429
|
return undefined;
|
|
252
430
|
}
|
|
253
431
|
|
|
@@ -255,17 +433,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
255
433
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
256
434
|
this.log.warn(
|
|
257
435
|
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
258
|
-
{ slot: this.
|
|
436
|
+
{ slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
259
437
|
);
|
|
260
438
|
return undefined;
|
|
261
439
|
}
|
|
262
440
|
|
|
263
441
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
264
442
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
265
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
443
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
266
444
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
267
445
|
|
|
268
|
-
// Final validation
|
|
446
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
447
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
269
448
|
try {
|
|
270
449
|
validateCheckpoint(checkpoint, {
|
|
271
450
|
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
@@ -275,113 +454,59 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
275
454
|
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
276
455
|
});
|
|
277
456
|
} catch (err) {
|
|
278
|
-
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, {
|
|
279
458
|
checkpoint: checkpoint.header.toInspect(),
|
|
280
459
|
});
|
|
281
460
|
return undefined;
|
|
282
461
|
}
|
|
283
462
|
|
|
284
463
|
// Record checkpoint-level build metrics
|
|
285
|
-
this.
|
|
464
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
286
465
|
checkpointBuildTimer.ms(),
|
|
287
466
|
blocksInCheckpoint.length,
|
|
288
467
|
checkpoint.getStats().txCount,
|
|
289
468
|
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
290
469
|
);
|
|
291
470
|
|
|
292
|
-
//
|
|
471
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
293
472
|
if (this.config.fishermanMode) {
|
|
294
473
|
this.log.info(
|
|
295
|
-
`Built checkpoint for slot ${this.
|
|
474
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
296
475
|
`Skipping proposal in fisherman mode.`,
|
|
297
476
|
{
|
|
298
|
-
slot: this.
|
|
477
|
+
slot: this.targetSlot,
|
|
299
478
|
checkpoint: checkpoint.header.toInspect(),
|
|
300
479
|
blocksBuilt: blocksInCheckpoint.length,
|
|
301
480
|
},
|
|
302
481
|
);
|
|
303
482
|
this.metrics.recordCheckpointSuccess();
|
|
304
|
-
|
|
483
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
484
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
305
485
|
}
|
|
306
486
|
|
|
307
|
-
// Include the block pending broadcast in the checkpoint proposal if any
|
|
308
|
-
const lastBlock = blockPendingBroadcast && {
|
|
309
|
-
blockHeader: blockPendingBroadcast.block.header,
|
|
310
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
311
|
-
txs: blockPendingBroadcast.txs,
|
|
312
|
-
};
|
|
313
|
-
|
|
314
487
|
// Create the checkpoint proposal and broadcast it
|
|
315
488
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
316
489
|
checkpoint.header,
|
|
317
490
|
checkpoint.archive.root,
|
|
318
491
|
feeAssetPriceModifier,
|
|
319
|
-
|
|
492
|
+
blockPendingBroadcast,
|
|
320
493
|
this.proposer,
|
|
321
494
|
checkpointProposalOptions,
|
|
322
495
|
);
|
|
323
496
|
|
|
324
497
|
const blockProposedAt = this.dateProvider.now();
|
|
325
498
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
499
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
326
500
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const blockAttestedAt = this.dateProvider.now();
|
|
330
|
-
|
|
331
|
-
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
332
|
-
|
|
333
|
-
// Proposer must sign over the attestations before pushing them to L1
|
|
334
|
-
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
335
|
-
let attestationsSignature: Signature;
|
|
336
|
-
try {
|
|
337
|
-
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
338
|
-
attestations,
|
|
339
|
-
signer,
|
|
340
|
-
this.slot,
|
|
341
|
-
this.checkpointNumber,
|
|
342
|
-
);
|
|
343
|
-
} catch (err) {
|
|
344
|
-
// We shouldn't really get here since we yield to another HA node
|
|
345
|
-
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
346
|
-
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
347
|
-
return undefined;
|
|
348
|
-
}
|
|
349
|
-
throw err;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Enqueue publishing the checkpoint to L1
|
|
353
|
-
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
354
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
355
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
356
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
357
|
-
|
|
358
|
-
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
359
|
-
if (
|
|
360
|
-
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
361
|
-
this.config.skipPublishingCheckpointsPercent > 0
|
|
362
|
-
) {
|
|
363
|
-
const result = Math.max(0, randomInt(100));
|
|
364
|
-
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
365
|
-
this.log.warn(
|
|
366
|
-
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
367
|
-
);
|
|
368
|
-
return checkpoint;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
373
|
-
txTimeoutAt,
|
|
374
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
return checkpoint;
|
|
501
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
502
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
378
503
|
} catch (err) {
|
|
379
504
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
380
505
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
381
506
|
return undefined;
|
|
382
507
|
}
|
|
383
508
|
|
|
384
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
509
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
385
510
|
return undefined;
|
|
386
511
|
}
|
|
387
512
|
}
|
|
@@ -397,14 +522,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
397
522
|
blockProposalOptions: BlockProposalOptions,
|
|
398
523
|
): Promise<{
|
|
399
524
|
blocksInCheckpoint: L2Block[];
|
|
400
|
-
blockPendingBroadcast:
|
|
525
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
401
526
|
}> {
|
|
402
527
|
const blocksInCheckpoint: L2Block[] = [];
|
|
403
528
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
404
529
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
405
530
|
|
|
406
531
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
407
|
-
let blockPendingBroadcast:
|
|
532
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
408
533
|
|
|
409
534
|
while (true) {
|
|
410
535
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -416,7 +541,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
416
541
|
|
|
417
542
|
if (!timingInfo.canStart) {
|
|
418
543
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
419
|
-
slot: this.
|
|
544
|
+
slot: this.targetSlot,
|
|
420
545
|
blocksBuilt,
|
|
421
546
|
secondsIntoSlot,
|
|
422
547
|
});
|
|
@@ -437,22 +562,23 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
437
562
|
txHashesAlreadyIncluded,
|
|
438
563
|
});
|
|
439
564
|
|
|
440
|
-
//
|
|
441
|
-
if (
|
|
442
|
-
// If
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
565
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
566
|
+
if ('failure' in buildResult) {
|
|
567
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
568
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
446
572
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
447
573
|
continue;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
577
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
578
|
+
if ('error' in buildResult) {
|
|
453
579
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
454
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
455
|
-
slot: this.
|
|
580
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
581
|
+
slot: this.targetSlot,
|
|
456
582
|
blocksBuilt,
|
|
457
583
|
error: buildResult.error,
|
|
458
584
|
});
|
|
@@ -461,58 +587,79 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
461
587
|
}
|
|
462
588
|
|
|
463
589
|
const { block, usedTxs } = buildResult;
|
|
590
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
591
|
+
isFirstBlock: blocksBuilt === 0,
|
|
592
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
593
|
+
});
|
|
594
|
+
|
|
464
595
|
blocksInCheckpoint.push(block);
|
|
596
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
465
597
|
|
|
466
|
-
//
|
|
467
|
-
|
|
468
|
-
// If this throws, we abort the entire checkpoint
|
|
469
|
-
await this.syncProposedBlockToArchiver(block);
|
|
598
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
599
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
470
600
|
|
|
471
|
-
|
|
601
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
602
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
603
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
604
|
+
// If this throws, we abort the entire checkpoint.
|
|
605
|
+
await this.syncProposedBlockToArchiver(block);
|
|
472
606
|
|
|
473
|
-
// If this is the last block,
|
|
607
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
474
608
|
if (timingInfo.isLastBlock) {
|
|
475
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
476
|
-
slot: this.
|
|
609
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
610
|
+
slot: this.targetSlot,
|
|
477
611
|
blockNumber,
|
|
478
612
|
blocksBuilt,
|
|
479
613
|
});
|
|
480
|
-
|
|
614
|
+
|
|
615
|
+
blockPendingBroadcast = proposal;
|
|
481
616
|
break;
|
|
482
617
|
}
|
|
483
618
|
|
|
484
|
-
//
|
|
485
|
-
|
|
486
|
-
if (!this.config.fishermanMode) {
|
|
487
|
-
const proposal = await this.validatorClient.createBlockProposal(
|
|
488
|
-
block.header,
|
|
489
|
-
block.indexWithinCheckpoint,
|
|
490
|
-
inHash,
|
|
491
|
-
block.archive.root,
|
|
492
|
-
usedTxs,
|
|
493
|
-
this.proposer,
|
|
494
|
-
blockProposalOptions,
|
|
495
|
-
);
|
|
496
|
-
await this.p2pClient.broadcastProposal(proposal);
|
|
497
|
-
}
|
|
619
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
620
|
+
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
498
621
|
|
|
499
622
|
// Wait until the next block's start time
|
|
500
623
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
501
624
|
}
|
|
502
625
|
|
|
503
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
504
|
-
slot: this.
|
|
626
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
627
|
+
slot: this.targetSlot,
|
|
505
628
|
blocksBuilt: blocksInCheckpoint.length,
|
|
506
629
|
});
|
|
507
630
|
|
|
508
631
|
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
509
632
|
}
|
|
510
633
|
|
|
634
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
|
|
635
|
+
private createBlockProposal(
|
|
636
|
+
block: L2Block,
|
|
637
|
+
inHash: Fr,
|
|
638
|
+
usedTxs: Tx[],
|
|
639
|
+
blockProposalOptions: BlockProposalOptions,
|
|
640
|
+
): Promise<BlockProposal | undefined> {
|
|
641
|
+
if (this.config.fishermanMode) {
|
|
642
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
643
|
+
return Promise.resolve(undefined);
|
|
644
|
+
}
|
|
645
|
+
return this.validatorClient.createBlockProposal(
|
|
646
|
+
block.header,
|
|
647
|
+
block.indexWithinCheckpoint,
|
|
648
|
+
inHash,
|
|
649
|
+
block.archive.root,
|
|
650
|
+
usedTxs,
|
|
651
|
+
this.proposer,
|
|
652
|
+
blockProposalOptions,
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
511
656
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
512
657
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
513
658
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
514
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
515
|
-
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
659
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
660
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
661
|
+
slot: this.targetSlot,
|
|
662
|
+
});
|
|
516
663
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
517
664
|
}
|
|
518
665
|
|
|
@@ -528,12 +675,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
528
675
|
buildDeadline: Date | undefined;
|
|
529
676
|
txHashesAlreadyIncluded: Set<string>;
|
|
530
677
|
},
|
|
531
|
-
): Promise<
|
|
678
|
+
): Promise<
|
|
679
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
680
|
+
> {
|
|
532
681
|
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
533
682
|
opts;
|
|
534
683
|
|
|
535
684
|
this.log.verbose(
|
|
536
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
685
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
537
686
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
538
687
|
);
|
|
539
688
|
|
|
@@ -542,12 +691,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
542
691
|
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
543
692
|
if (!canStartBuilding) {
|
|
544
693
|
this.log.warn(
|
|
545
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
546
|
-
{ blockNumber, slot: this.
|
|
694
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
695
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
547
696
|
);
|
|
548
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
697
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
549
698
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
550
|
-
return
|
|
699
|
+
return { failure: 'insufficient-txs' };
|
|
551
700
|
}
|
|
552
701
|
|
|
553
702
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -558,16 +707,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
558
707
|
);
|
|
559
708
|
|
|
560
709
|
this.log.debug(
|
|
561
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
562
|
-
{ slot: this.
|
|
710
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
711
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
563
712
|
);
|
|
564
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
713
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
565
714
|
|
|
566
|
-
// Per-block limits
|
|
715
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
567
716
|
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
568
717
|
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
569
718
|
const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
|
|
570
|
-
const blockBuilderOptions:
|
|
719
|
+
const blockBuilderOptions: BlockBuilderOptions = {
|
|
571
720
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
572
721
|
maxBlockGas:
|
|
573
722
|
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
@@ -576,6 +725,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
576
725
|
deadline: buildDeadline,
|
|
577
726
|
isBuildingProposal: true,
|
|
578
727
|
minValidTxs,
|
|
728
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
729
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
|
|
579
730
|
};
|
|
580
731
|
|
|
581
732
|
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
@@ -594,18 +745,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
594
745
|
|
|
595
746
|
if (buildResult.status === 'insufficient-valid-txs') {
|
|
596
747
|
this.log.warn(
|
|
597
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
748
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
598
749
|
{
|
|
599
|
-
slot: this.
|
|
750
|
+
slot: this.targetSlot,
|
|
600
751
|
blockNumber,
|
|
601
752
|
numTxs: buildResult.processedCount,
|
|
602
753
|
indexWithinCheckpoint,
|
|
603
754
|
minValidTxs,
|
|
604
755
|
},
|
|
605
756
|
);
|
|
606
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
757
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
758
|
+
reason: `Insufficient valid txs`,
|
|
759
|
+
slot: this.targetSlot,
|
|
760
|
+
});
|
|
607
761
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
608
|
-
return
|
|
762
|
+
return { failure: 'insufficient-valid-txs' };
|
|
609
763
|
}
|
|
610
764
|
|
|
611
765
|
// Block creation succeeded, emit stats and metrics
|
|
@@ -623,17 +777,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
623
777
|
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
624
778
|
|
|
625
779
|
this.log.info(
|
|
626
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
780
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
627
781
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
628
782
|
);
|
|
629
783
|
|
|
630
|
-
|
|
631
|
-
|
|
784
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
785
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
786
|
+
this.eventEmitter.emit('block-proposed', {
|
|
787
|
+
blockNumber: block.number,
|
|
788
|
+
slot: this.targetSlot,
|
|
789
|
+
buildSlot: this.slotNow,
|
|
790
|
+
});
|
|
791
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
632
792
|
|
|
633
793
|
return { block, usedTxs };
|
|
634
794
|
} catch (err: any) {
|
|
635
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
636
|
-
|
|
795
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
796
|
+
reason: err.message,
|
|
797
|
+
slot: this.targetSlot,
|
|
798
|
+
});
|
|
799
|
+
this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
|
|
637
800
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
638
801
|
this.metrics.recordFailedBlock();
|
|
639
802
|
return { error: err };
|
|
@@ -646,7 +809,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
646
809
|
pendingTxs: AsyncIterable<Tx>,
|
|
647
810
|
blockNumber: BlockNumber,
|
|
648
811
|
blockTimestamp: bigint,
|
|
649
|
-
blockBuilderOptions:
|
|
812
|
+
blockBuilderOptions: BlockBuilderOptions,
|
|
650
813
|
) {
|
|
651
814
|
try {
|
|
652
815
|
const workTimer = new Timer();
|
|
@@ -693,10 +856,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
693
856
|
}
|
|
694
857
|
|
|
695
858
|
// Wait a bit before checking again
|
|
696
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
859
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
697
860
|
this.log.verbose(
|
|
698
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
699
|
-
{ blockNumber, slot: this.
|
|
861
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
862
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
700
863
|
);
|
|
701
864
|
await this.waitForTxsPollingInterval();
|
|
702
865
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -728,7 +891,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
728
891
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
729
892
|
}
|
|
730
893
|
|
|
731
|
-
const numberOfRequiredAttestations =
|
|
894
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
732
895
|
|
|
733
896
|
if (this.config.skipCollectingAttestations) {
|
|
734
897
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
@@ -737,7 +900,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
737
900
|
}
|
|
738
901
|
|
|
739
902
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
740
|
-
? this.timetable.
|
|
903
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
741
904
|
: this.l1Constants.slotDuration;
|
|
742
905
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
743
906
|
|
|
@@ -876,9 +1039,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
876
1039
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
877
1040
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
878
1041
|
* would never receive its own block without this explicit sync.
|
|
1042
|
+
*
|
|
1043
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1044
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1045
|
+
* whenever the real proposer's block arrives from L1.
|
|
879
1046
|
*/
|
|
880
1047
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
881
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1048
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
882
1049
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
883
1050
|
blockNumber: block.number,
|
|
884
1051
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -896,19 +1063,19 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
896
1063
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
897
1064
|
// Perform L1 fee analysis before clearing requests
|
|
898
1065
|
// The callback is invoked asynchronously after the next block is mined
|
|
899
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1066
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
900
1067
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
901
1068
|
);
|
|
902
1069
|
|
|
903
1070
|
if (checkpoint) {
|
|
904
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1071
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
905
1072
|
...checkpoint.toCheckpointInfo(),
|
|
906
1073
|
...checkpoint.getStats(),
|
|
907
1074
|
feeAnalysisId: feeAnalysis?.id,
|
|
908
1075
|
});
|
|
909
1076
|
} else {
|
|
910
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
911
|
-
slot: this.
|
|
1077
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1078
|
+
slot: this.targetSlot,
|
|
912
1079
|
feeAnalysisId: feeAnalysis?.id,
|
|
913
1080
|
});
|
|
914
1081
|
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
@@ -922,15 +1089,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
922
1089
|
*/
|
|
923
1090
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
924
1091
|
if (err instanceof DutyAlreadySignedError) {
|
|
925
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
926
|
-
slot: this.
|
|
1092
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1093
|
+
slot: this.targetSlot,
|
|
927
1094
|
signedByNode: err.signedByNode,
|
|
928
1095
|
});
|
|
929
1096
|
return true;
|
|
930
1097
|
}
|
|
931
1098
|
if (err instanceof SlashingProtectionError) {
|
|
932
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
933
|
-
slot: this.
|
|
1099
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1100
|
+
slot: this.targetSlot,
|
|
934
1101
|
existingMessageHash: err.existingMessageHash,
|
|
935
1102
|
attemptedMessageHash: err.attemptedMessageHash,
|
|
936
1103
|
});
|
|
@@ -953,7 +1120,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
953
1120
|
}
|
|
954
1121
|
|
|
955
1122
|
private getSlotStartBuildTimestamp(): number {
|
|
956
|
-
return getSlotStartBuildTimestamp(this.
|
|
1123
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
957
1124
|
}
|
|
958
1125
|
|
|
959
1126
|
private getSecondsIntoSlot(): number {
|