@aztec/sequencer-client 0.0.1-commit.f504929 → 0.0.1-commit.f5d02921e
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 +4 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +46 -23
- package/dest/config.d.ts +25 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +21 -12
- package/dest/global_variable_builder/global_builder.d.ts +15 -9
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +29 -25
- package/dest/global_variable_builder/index.d.ts +2 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- 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 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +2 -2
- package/dest/publisher/sequencer-publisher.d.ts +52 -25
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +98 -42
- package/dest/sequencer/checkpoint_proposal_job.d.ts +33 -8
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +284 -158
- 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 +5 -1
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +11 -0
- package/dest/sequencer/sequencer.d.ts +23 -10
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +123 -68
- package/dest/sequencer/timetable.d.ts +4 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +6 -7
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +56 -21
- package/src/config.ts +28 -14
- package/src/global_variable_builder/global_builder.ts +37 -26
- package/src/global_variable_builder/index.ts +1 -1
- package/src/publisher/config.ts +32 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -3
- package/src/publisher/sequencer-publisher.ts +144 -54
- package/src/sequencer/checkpoint_proposal_job.ts +367 -175
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +1 -1
- package/src/sequencer/metrics.ts +14 -0
- package/src/sequencer/sequencer.ts +178 -79
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import { type FeeHeader, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
3
|
import {
|
|
5
4
|
BlockNumber,
|
|
6
5
|
CheckpointNumber,
|
|
@@ -32,17 +31,22 @@ import {
|
|
|
32
31
|
type L2BlockSource,
|
|
33
32
|
MaliciousCommitteeAttestationsAndSigners,
|
|
34
33
|
} from '@aztec/stdlib/block';
|
|
35
|
-
import type
|
|
36
|
-
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';
|
|
37
36
|
import { Gas } from '@aztec/stdlib/gas';
|
|
38
37
|
import {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
type BlockBuilderOptions,
|
|
39
|
+
InsufficientValidTxsError,
|
|
41
40
|
type ResolvedSequencerConfig,
|
|
42
41
|
type WorldStateSynchronizer,
|
|
43
42
|
} from '@aztec/stdlib/interfaces/server';
|
|
44
43
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
45
|
-
import type {
|
|
44
|
+
import type {
|
|
45
|
+
BlockProposal,
|
|
46
|
+
BlockProposalOptions,
|
|
47
|
+
CheckpointProposal,
|
|
48
|
+
CheckpointProposalOptions,
|
|
49
|
+
} from '@aztec/stdlib/p2p';
|
|
46
50
|
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
47
51
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
48
52
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
@@ -64,6 +68,13 @@ import { SequencerState } from './utils.js';
|
|
|
64
68
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
65
69
|
const TXS_POLLING_MS = 500;
|
|
66
70
|
|
|
71
|
+
/** Result from proposeCheckpoint when a checkpoint was successfully built and attested. */
|
|
72
|
+
type CheckpointProposalResult = {
|
|
73
|
+
checkpoint: Checkpoint;
|
|
74
|
+
attestations: CommitteeAttestationsAndSigners;
|
|
75
|
+
attestationsSignature: Signature;
|
|
76
|
+
};
|
|
77
|
+
|
|
67
78
|
/**
|
|
68
79
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
69
80
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
@@ -73,9 +84,16 @@ const TXS_POLLING_MS = 500;
|
|
|
73
84
|
export class CheckpointProposalJob implements Traceable {
|
|
74
85
|
protected readonly log: Logger;
|
|
75
86
|
|
|
87
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
88
|
+
private pendingL1Submission: Promise<void> | undefined;
|
|
89
|
+
|
|
90
|
+
/** Fee header override computed during proposeCheckpoint, reused in enqueueCheckpointForSubmission. */
|
|
91
|
+
private computedForceProposedFeeHeader?: { checkpointNumber: CheckpointNumber; feeHeader: FeeHeader };
|
|
92
|
+
|
|
76
93
|
constructor(
|
|
77
|
-
private readonly
|
|
78
|
-
private readonly
|
|
94
|
+
private readonly slotNow: SlotNumber,
|
|
95
|
+
private readonly targetSlot: SlotNumber,
|
|
96
|
+
private readonly targetEpoch: EpochNumber,
|
|
79
97
|
private readonly checkpointNumber: CheckpointNumber,
|
|
80
98
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
81
99
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
@@ -102,13 +120,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
102
120
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
103
121
|
public readonly tracer: Tracer,
|
|
104
122
|
bindings?: LoggerBindings,
|
|
123
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
105
124
|
) {
|
|
106
|
-
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
125
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
126
|
+
...bindings,
|
|
127
|
+
instanceId: `slot-${this.slotNow}`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
|
|
132
|
+
public async awaitPendingSubmission(): Promise<void> {
|
|
133
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
134
|
+
await this.pendingL1Submission;
|
|
107
135
|
}
|
|
108
136
|
|
|
109
137
|
/**
|
|
110
138
|
* Executes the checkpoint proposal job.
|
|
111
|
-
*
|
|
139
|
+
* Builds blocks, collects attestations, enqueues requests, and schedules L1 submission as a
|
|
140
|
+
* background task so the work loop can return to IDLE immediately.
|
|
141
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
112
142
|
*/
|
|
113
143
|
@trackSpan('CheckpointProposalJob.execute')
|
|
114
144
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -116,7 +146,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
116
146
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
117
147
|
// These are constant for the whole slot, so we only enqueue them once
|
|
118
148
|
const votesPromises = new CheckpointVoter(
|
|
119
|
-
this.
|
|
149
|
+
this.targetSlot,
|
|
120
150
|
this.publisher,
|
|
121
151
|
this.attestorAddress,
|
|
122
152
|
this.validatorClient,
|
|
@@ -127,8 +157,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
127
157
|
this.log,
|
|
128
158
|
).enqueueVotes();
|
|
129
159
|
|
|
130
|
-
// Build and propose the checkpoint.
|
|
131
|
-
|
|
160
|
+
// Build and propose the checkpoint. Builds blocks, broadcasts, collects attestations, and signs.
|
|
161
|
+
// Does NOT enqueue to L1 yet — that happens after the pipeline sleep.
|
|
162
|
+
const proposalResult = await this.proposeCheckpoint();
|
|
163
|
+
const checkpoint = proposalResult?.checkpoint;
|
|
132
164
|
|
|
133
165
|
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
134
166
|
await Promise.all(votesPromises);
|
|
@@ -143,47 +175,135 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
143
175
|
return;
|
|
144
176
|
}
|
|
145
177
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
178
|
+
// Enqueue the checkpoint for L1 submission
|
|
179
|
+
if (proposalResult) {
|
|
180
|
+
try {
|
|
181
|
+
await this.enqueueCheckpointForSubmission(proposalResult);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
this.log.error(`Failed to enqueue checkpoint for L1 submission at slot ${this.targetSlot}`, err);
|
|
184
|
+
// Continue to sendRequestsAt so votes are still sent
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
189
|
+
const submitAfter = this.epochCache.isProposerPipeliningEnabled()
|
|
190
|
+
? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000)
|
|
191
|
+
: new Date(this.dateProvider.now());
|
|
192
|
+
|
|
193
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/pull/21250): should discard the pending submission if a reorg occurs underneath
|
|
194
|
+
|
|
195
|
+
// Schedule L1 submission in the background so the work loop returns immediately.
|
|
196
|
+
// The publisher will sleep until submitAfter, then send the bundled requests.
|
|
197
|
+
// The promise is stored so it can be awaited during shutdown.
|
|
198
|
+
this.pendingL1Submission = this.publisher
|
|
199
|
+
.sendRequestsAt(submitAfter)
|
|
200
|
+
.then(async l1Response => {
|
|
201
|
+
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
202
|
+
if (proposedAction) {
|
|
203
|
+
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
204
|
+
const coinbase = checkpoint?.header.coinbase;
|
|
205
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
206
|
+
} else if (checkpoint) {
|
|
207
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
208
|
+
|
|
209
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
210
|
+
this.metrics.recordPipelineDiscard();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
.catch(err => {
|
|
215
|
+
this.log.error(`Background L1 submission failed for slot ${this.targetSlot}`, err);
|
|
216
|
+
if (checkpoint) {
|
|
217
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
218
|
+
|
|
219
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
220
|
+
this.metrics.recordPipelineDiscard();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
226
|
+
return checkpoint;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
230
|
+
private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
|
|
231
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
232
|
+
|
|
233
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
234
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
235
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
236
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
237
|
+
|
|
238
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
239
|
+
if (
|
|
240
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
241
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
242
|
+
) {
|
|
243
|
+
const roll = Math.max(0, randomInt(100));
|
|
244
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
245
|
+
this.log.warn(
|
|
246
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
|
|
247
|
+
);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
157
250
|
}
|
|
251
|
+
|
|
252
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
253
|
+
txTimeoutAt,
|
|
254
|
+
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
255
|
+
forceProposedFeeHeader: this.computedForceProposedFeeHeader,
|
|
256
|
+
});
|
|
158
257
|
}
|
|
159
258
|
|
|
160
259
|
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
161
260
|
return {
|
|
162
261
|
// nullish operator needed for tests
|
|
163
262
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
164
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
263
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
165
264
|
};
|
|
166
265
|
})
|
|
167
|
-
private async proposeCheckpoint(): Promise<
|
|
266
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalResult | undefined> {
|
|
168
267
|
try {
|
|
169
268
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
170
269
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
171
270
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
172
271
|
|
|
173
272
|
// Start the checkpoint
|
|
174
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
175
|
-
this.
|
|
273
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
274
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
275
|
+
buildSlot: this.slotNow,
|
|
276
|
+
submissionSlot: this.targetSlot,
|
|
277
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
278
|
+
proposer: this.proposer?.toString(),
|
|
279
|
+
coinbase: coinbase.toString(),
|
|
280
|
+
});
|
|
281
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
176
282
|
|
|
177
283
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
178
284
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
179
285
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
180
286
|
}
|
|
181
287
|
|
|
182
|
-
// Create checkpoint builder for the slot
|
|
288
|
+
// Create checkpoint builder for the slot.
|
|
289
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
290
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
291
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
292
|
+
const parentCheckpointNumber = isPipelining ? CheckpointNumber(this.checkpointNumber - 1) : undefined;
|
|
293
|
+
|
|
294
|
+
// Compute the parent's fee header override when pipelining
|
|
295
|
+
if (isPipelining && this.proposedCheckpointData) {
|
|
296
|
+
this.computedForceProposedFeeHeader = await this.computeForceProposedFeeHeader(parentCheckpointNumber!);
|
|
297
|
+
}
|
|
298
|
+
|
|
183
299
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
184
300
|
coinbase,
|
|
185
301
|
feeRecipient,
|
|
186
|
-
this.
|
|
302
|
+
this.targetSlot,
|
|
303
|
+
{
|
|
304
|
+
forcePendingCheckpointNumber: parentCheckpointNumber,
|
|
305
|
+
forceProposedFeeHeader: this.computedForceProposedFeeHeader,
|
|
306
|
+
},
|
|
187
307
|
);
|
|
188
308
|
|
|
189
309
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -191,7 +311,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
191
311
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
192
312
|
|
|
193
313
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
194
|
-
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.
|
|
314
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
|
|
195
315
|
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
196
316
|
.map(c => c.checkpointOutHash);
|
|
197
317
|
|
|
@@ -248,8 +368,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
248
368
|
}
|
|
249
369
|
|
|
250
370
|
if (blocksInCheckpoint.length === 0) {
|
|
251
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
252
|
-
this.eventEmitter.emit('checkpoint-empty', { slot: this.
|
|
371
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, { slot: this.targetSlot });
|
|
372
|
+
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
253
373
|
return undefined;
|
|
254
374
|
}
|
|
255
375
|
|
|
@@ -257,16 +377,33 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
257
377
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
258
378
|
this.log.warn(
|
|
259
379
|
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
260
|
-
{ slot: this.
|
|
380
|
+
{ slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
261
381
|
);
|
|
262
382
|
return undefined;
|
|
263
383
|
}
|
|
264
384
|
|
|
265
385
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
266
386
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
267
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
387
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
268
388
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
269
389
|
|
|
390
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
391
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
392
|
+
try {
|
|
393
|
+
validateCheckpoint(checkpoint, {
|
|
394
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
395
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
396
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
397
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
398
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
399
|
+
});
|
|
400
|
+
} catch (err) {
|
|
401
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
402
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
403
|
+
});
|
|
404
|
+
return undefined;
|
|
405
|
+
}
|
|
406
|
+
|
|
270
407
|
// Record checkpoint-level build metrics
|
|
271
408
|
this.metrics.recordCheckpointBuild(
|
|
272
409
|
checkpointBuildTimer.ms(),
|
|
@@ -278,16 +415,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
278
415
|
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
279
416
|
if (this.config.fishermanMode) {
|
|
280
417
|
this.log.info(
|
|
281
|
-
`Built checkpoint for slot ${this.
|
|
418
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
282
419
|
`Skipping proposal in fisherman mode.`,
|
|
283
420
|
{
|
|
284
|
-
slot: this.
|
|
421
|
+
slot: this.targetSlot,
|
|
285
422
|
checkpoint: checkpoint.header.toInspect(),
|
|
286
423
|
blocksBuilt: blocksInCheckpoint.length,
|
|
287
424
|
},
|
|
288
425
|
);
|
|
289
426
|
this.metrics.recordCheckpointSuccess();
|
|
290
|
-
return
|
|
427
|
+
return {
|
|
428
|
+
checkpoint,
|
|
429
|
+
attestations: CommitteeAttestationsAndSigners.empty(),
|
|
430
|
+
attestationsSignature: Signature.empty(),
|
|
431
|
+
};
|
|
291
432
|
}
|
|
292
433
|
|
|
293
434
|
// Include the block pending broadcast in the checkpoint proposal if any
|
|
@@ -310,7 +451,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
310
451
|
const blockProposedAt = this.dateProvider.now();
|
|
311
452
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
312
453
|
|
|
313
|
-
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.
|
|
454
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
314
455
|
const attestations = await this.waitForAttestations(proposal);
|
|
315
456
|
const blockAttestedAt = this.dateProvider.now();
|
|
316
457
|
|
|
@@ -323,7 +464,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
323
464
|
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
324
465
|
attestations,
|
|
325
466
|
signer,
|
|
326
|
-
this.
|
|
467
|
+
this.targetSlot,
|
|
327
468
|
this.checkpointNumber,
|
|
328
469
|
);
|
|
329
470
|
} catch (err) {
|
|
@@ -335,39 +476,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
335
476
|
throw err;
|
|
336
477
|
}
|
|
337
478
|
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
341
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
342
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
343
|
-
|
|
344
|
-
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
345
|
-
if (
|
|
346
|
-
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
347
|
-
this.config.skipPublishingCheckpointsPercent > 0
|
|
348
|
-
) {
|
|
349
|
-
const result = Math.max(0, randomInt(100));
|
|
350
|
-
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
351
|
-
this.log.warn(
|
|
352
|
-
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
353
|
-
);
|
|
354
|
-
return checkpoint;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
359
|
-
txTimeoutAt,
|
|
360
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
return checkpoint;
|
|
479
|
+
// Return the result for the caller to enqueue after the pipeline sleep
|
|
480
|
+
return { checkpoint, attestations, attestationsSignature };
|
|
364
481
|
} catch (err) {
|
|
365
482
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
366
483
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
367
484
|
return undefined;
|
|
368
485
|
}
|
|
369
486
|
|
|
370
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
487
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
371
488
|
return undefined;
|
|
372
489
|
}
|
|
373
490
|
}
|
|
@@ -389,9 +506,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
389
506
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
390
507
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
391
508
|
|
|
392
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
393
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
394
|
-
|
|
395
509
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
396
510
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
397
511
|
|
|
@@ -405,7 +519,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
405
519
|
|
|
406
520
|
if (!timingInfo.canStart) {
|
|
407
521
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
408
|
-
slot: this.
|
|
522
|
+
slot: this.targetSlot,
|
|
409
523
|
blocksBuilt,
|
|
410
524
|
secondsIntoSlot,
|
|
411
525
|
});
|
|
@@ -424,7 +538,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
424
538
|
blockNumber,
|
|
425
539
|
indexWithinCheckpoint,
|
|
426
540
|
txHashesAlreadyIncluded,
|
|
427
|
-
remainingBlobFields,
|
|
428
541
|
});
|
|
429
542
|
|
|
430
543
|
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
@@ -441,8 +554,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
441
554
|
} else if ('error' in buildResult) {
|
|
442
555
|
// If there was an error building the block, just exit the loop and give up the rest of the slot
|
|
443
556
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
444
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
445
|
-
slot: this.
|
|
557
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
558
|
+
slot: this.targetSlot,
|
|
446
559
|
blocksBuilt,
|
|
447
560
|
error: buildResult.error,
|
|
448
561
|
});
|
|
@@ -450,26 +563,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
450
563
|
break;
|
|
451
564
|
}
|
|
452
565
|
|
|
453
|
-
const { block, usedTxs
|
|
566
|
+
const { block, usedTxs } = buildResult;
|
|
454
567
|
blocksInCheckpoint.push(block);
|
|
455
|
-
|
|
456
|
-
// Update remaining blob fields for the next block
|
|
457
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
458
|
-
|
|
459
|
-
// Sync the proposed block to the archiver to make it available
|
|
460
|
-
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
461
|
-
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
462
|
-
// Fire and forget - don't block the critical path, but log errors
|
|
463
|
-
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
464
|
-
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
465
|
-
});
|
|
466
|
-
|
|
467
568
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
468
569
|
|
|
469
|
-
// If this is the last block,
|
|
570
|
+
// If this is the last block, sync it to the archiver and exit the loop
|
|
571
|
+
// so we can build the checkpoint and start collecting attestations.
|
|
470
572
|
if (timingInfo.isLastBlock) {
|
|
471
|
-
this.
|
|
472
|
-
|
|
573
|
+
await this.syncProposedBlockToArchiver(block);
|
|
574
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
575
|
+
slot: this.targetSlot,
|
|
473
576
|
blockNumber,
|
|
474
577
|
blocksBuilt,
|
|
475
578
|
});
|
|
@@ -477,38 +580,61 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
477
580
|
break;
|
|
478
581
|
}
|
|
479
582
|
|
|
480
|
-
//
|
|
481
|
-
//
|
|
482
|
-
if
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
583
|
+
// Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
|
|
584
|
+
// in which case we'll broadcast it along with the checkpoint at the end of the loop.
|
|
585
|
+
// Note that we only send the block to the archiver if we manage to create the proposal, so if there's
|
|
586
|
+
// a HA error we don't pollute our archiver with a block that won't make it to the chain.
|
|
587
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
588
|
+
|
|
589
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal.
|
|
590
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
591
|
+
// If this throws, we abort the entire checkpoint.
|
|
592
|
+
await this.syncProposedBlockToArchiver(block);
|
|
593
|
+
|
|
594
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
595
|
+
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
494
596
|
|
|
495
597
|
// Wait until the next block's start time
|
|
496
598
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
497
599
|
}
|
|
498
600
|
|
|
499
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
500
|
-
slot: this.
|
|
601
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
602
|
+
slot: this.targetSlot,
|
|
501
603
|
blocksBuilt: blocksInCheckpoint.length,
|
|
502
604
|
});
|
|
503
605
|
|
|
504
606
|
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
505
607
|
}
|
|
506
608
|
|
|
609
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
|
|
610
|
+
private createBlockProposal(
|
|
611
|
+
block: L2Block,
|
|
612
|
+
inHash: Fr,
|
|
613
|
+
usedTxs: Tx[],
|
|
614
|
+
blockProposalOptions: BlockProposalOptions,
|
|
615
|
+
): Promise<BlockProposal | undefined> {
|
|
616
|
+
if (this.config.fishermanMode) {
|
|
617
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
618
|
+
return Promise.resolve(undefined);
|
|
619
|
+
}
|
|
620
|
+
return this.validatorClient.createBlockProposal(
|
|
621
|
+
block.header,
|
|
622
|
+
block.indexWithinCheckpoint,
|
|
623
|
+
inHash,
|
|
624
|
+
block.archive.root,
|
|
625
|
+
usedTxs,
|
|
626
|
+
this.proposer,
|
|
627
|
+
blockProposalOptions,
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
507
631
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
508
632
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
509
633
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
510
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
511
|
-
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
634
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
635
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
636
|
+
slot: this.targetSlot,
|
|
637
|
+
});
|
|
512
638
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
513
639
|
}
|
|
514
640
|
|
|
@@ -523,34 +649,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
523
649
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
524
650
|
buildDeadline: Date | undefined;
|
|
525
651
|
txHashesAlreadyIncluded: Set<string>;
|
|
526
|
-
remainingBlobFields: number;
|
|
527
652
|
},
|
|
528
|
-
): Promise<{ block: L2Block; usedTxs: Tx[]
|
|
529
|
-
const {
|
|
530
|
-
|
|
531
|
-
forceCreate,
|
|
532
|
-
blockNumber,
|
|
533
|
-
indexWithinCheckpoint,
|
|
534
|
-
buildDeadline,
|
|
535
|
-
txHashesAlreadyIncluded,
|
|
536
|
-
remainingBlobFields,
|
|
537
|
-
} = opts;
|
|
653
|
+
): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
654
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
655
|
+
opts;
|
|
538
656
|
|
|
539
657
|
this.log.verbose(
|
|
540
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
658
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
541
659
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
542
660
|
);
|
|
543
661
|
|
|
544
662
|
try {
|
|
545
663
|
// Wait until we have enough txs to build the block
|
|
546
|
-
const minTxs = this.
|
|
547
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
664
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
548
665
|
if (!canStartBuilding) {
|
|
549
666
|
this.log.warn(
|
|
550
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
551
|
-
{ blockNumber, slot: this.
|
|
667
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
668
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
552
669
|
);
|
|
553
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
670
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
554
671
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
555
672
|
return undefined;
|
|
556
673
|
}
|
|
@@ -563,24 +680,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
563
680
|
);
|
|
564
681
|
|
|
565
682
|
this.log.debug(
|
|
566
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
567
|
-
{ slot: this.
|
|
683
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
684
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
568
685
|
);
|
|
569
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
686
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
570
687
|
|
|
571
|
-
//
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
const blockBuilderOptions:
|
|
688
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
689
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
690
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
691
|
+
const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
|
|
692
|
+
const blockBuilderOptions: BlockBuilderOptions = {
|
|
576
693
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
694
|
+
maxBlockGas:
|
|
695
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
696
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
697
|
+
: undefined,
|
|
580
698
|
deadline: buildDeadline,
|
|
699
|
+
isBuildingProposal: true,
|
|
700
|
+
minValidTxs,
|
|
701
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
702
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
|
|
581
703
|
};
|
|
582
704
|
|
|
583
|
-
// Actually build the block by executing txs
|
|
705
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
706
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
707
|
+
// updated for blocks that will be discarded.
|
|
584
708
|
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
585
709
|
checkpointBuilder,
|
|
586
710
|
pendingTxs,
|
|
@@ -592,22 +716,27 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
592
716
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
593
717
|
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
594
718
|
|
|
595
|
-
|
|
596
|
-
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
597
|
-
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
598
|
-
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
599
|
-
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
719
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
600
720
|
this.log.warn(
|
|
601
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
602
|
-
{
|
|
721
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
722
|
+
{
|
|
723
|
+
slot: this.targetSlot,
|
|
724
|
+
blockNumber,
|
|
725
|
+
numTxs: buildResult.processedCount,
|
|
726
|
+
indexWithinCheckpoint,
|
|
727
|
+
minValidTxs,
|
|
728
|
+
},
|
|
603
729
|
);
|
|
604
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
730
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
731
|
+
reason: `Insufficient valid txs`,
|
|
732
|
+
slot: this.targetSlot,
|
|
733
|
+
});
|
|
605
734
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
606
735
|
return undefined;
|
|
607
736
|
}
|
|
608
737
|
|
|
609
738
|
// Block creation succeeded, emit stats and metrics
|
|
610
|
-
const {
|
|
739
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
611
740
|
|
|
612
741
|
const blockStats = {
|
|
613
742
|
eventName: 'l2-block-built',
|
|
@@ -618,33 +747,42 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
618
747
|
|
|
619
748
|
const blockHash = await block.hash();
|
|
620
749
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
621
|
-
const manaPerSec =
|
|
750
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
622
751
|
|
|
623
752
|
this.log.info(
|
|
624
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
753
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
625
754
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
626
755
|
);
|
|
627
756
|
|
|
628
|
-
|
|
629
|
-
|
|
757
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
758
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
759
|
+
this.eventEmitter.emit('block-proposed', {
|
|
760
|
+
blockNumber: block.number,
|
|
761
|
+
slot: this.targetSlot,
|
|
762
|
+
buildSlot: this.slotNow,
|
|
763
|
+
});
|
|
764
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
630
765
|
|
|
631
|
-
return { block, usedTxs
|
|
766
|
+
return { block, usedTxs };
|
|
632
767
|
} catch (err: any) {
|
|
633
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
634
|
-
|
|
768
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
769
|
+
reason: err.message,
|
|
770
|
+
slot: this.targetSlot,
|
|
771
|
+
});
|
|
772
|
+
this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
|
|
635
773
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
636
774
|
this.metrics.recordFailedBlock();
|
|
637
775
|
return { error: err };
|
|
638
776
|
}
|
|
639
777
|
}
|
|
640
778
|
|
|
641
|
-
/** Uses the checkpoint builder to build a block, catching
|
|
779
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */
|
|
642
780
|
private async buildSingleBlockWithCheckpointBuilder(
|
|
643
781
|
checkpointBuilder: CheckpointBuilder,
|
|
644
782
|
pendingTxs: AsyncIterable<Tx>,
|
|
645
783
|
blockNumber: BlockNumber,
|
|
646
784
|
blockTimestamp: bigint,
|
|
647
|
-
blockBuilderOptions:
|
|
785
|
+
blockBuilderOptions: BlockBuilderOptions,
|
|
648
786
|
) {
|
|
649
787
|
try {
|
|
650
788
|
const workTimer = new Timer();
|
|
@@ -652,8 +790,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
652
790
|
const blockBuildDuration = workTimer.ms();
|
|
653
791
|
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
654
792
|
} catch (err: unknown) {
|
|
655
|
-
if (isErrorClass(err,
|
|
656
|
-
return {
|
|
793
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
794
|
+
return {
|
|
795
|
+
failedTxs: err.failedTxs,
|
|
796
|
+
processedCount: err.processedCount,
|
|
797
|
+
status: 'insufficient-valid-txs' as const,
|
|
798
|
+
};
|
|
657
799
|
}
|
|
658
800
|
throw err;
|
|
659
801
|
}
|
|
@@ -666,7 +808,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
666
808
|
blockNumber: BlockNumber;
|
|
667
809
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
668
810
|
buildDeadline: Date | undefined;
|
|
669
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
811
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
670
812
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
671
813
|
|
|
672
814
|
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
@@ -683,20 +825,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
683
825
|
// If we're past deadline, or we have no deadline, give up
|
|
684
826
|
const now = this.dateProvider.nowAsDate();
|
|
685
827
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
686
|
-
return { canStartBuilding: false, availableTxs
|
|
828
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
687
829
|
}
|
|
688
830
|
|
|
689
831
|
// Wait a bit before checking again
|
|
690
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
832
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
691
833
|
this.log.verbose(
|
|
692
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
693
|
-
{ blockNumber, slot: this.
|
|
834
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
835
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
694
836
|
);
|
|
695
837
|
await this.waitForTxsPollingInterval();
|
|
696
838
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
697
839
|
}
|
|
698
840
|
|
|
699
|
-
return { canStartBuilding: true, availableTxs };
|
|
841
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
700
842
|
}
|
|
701
843
|
|
|
702
844
|
/**
|
|
@@ -722,7 +864,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
722
864
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
723
865
|
}
|
|
724
866
|
|
|
725
|
-
const numberOfRequiredAttestations =
|
|
867
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
726
868
|
|
|
727
869
|
if (this.config.skipCollectingAttestations) {
|
|
728
870
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
@@ -872,7 +1014,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
872
1014
|
* would never receive its own block without this explicit sync.
|
|
873
1015
|
*/
|
|
874
1016
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
875
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1017
|
+
if (this.config.skipPushProposedBlocksToArchiver) {
|
|
876
1018
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
877
1019
|
blockNumber: block.number,
|
|
878
1020
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -890,19 +1032,19 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
890
1032
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
891
1033
|
// Perform L1 fee analysis before clearing requests
|
|
892
1034
|
// The callback is invoked asynchronously after the next block is mined
|
|
893
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1035
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
894
1036
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
895
1037
|
);
|
|
896
1038
|
|
|
897
1039
|
if (checkpoint) {
|
|
898
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1040
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
899
1041
|
...checkpoint.toCheckpointInfo(),
|
|
900
1042
|
...checkpoint.getStats(),
|
|
901
1043
|
feeAnalysisId: feeAnalysis?.id,
|
|
902
1044
|
});
|
|
903
1045
|
} else {
|
|
904
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
905
|
-
slot: this.
|
|
1046
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1047
|
+
slot: this.targetSlot,
|
|
906
1048
|
feeAnalysisId: feeAnalysis?.id,
|
|
907
1049
|
});
|
|
908
1050
|
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
@@ -916,15 +1058,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
916
1058
|
*/
|
|
917
1059
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
918
1060
|
if (err instanceof DutyAlreadySignedError) {
|
|
919
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
920
|
-
slot: this.
|
|
1061
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1062
|
+
slot: this.targetSlot,
|
|
921
1063
|
signedByNode: err.signedByNode,
|
|
922
1064
|
});
|
|
923
1065
|
return true;
|
|
924
1066
|
}
|
|
925
1067
|
if (err instanceof SlashingProtectionError) {
|
|
926
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
927
|
-
slot: this.
|
|
1068
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1069
|
+
slot: this.targetSlot,
|
|
928
1070
|
existingMessageHash: err.existingMessageHash,
|
|
929
1071
|
attemptedMessageHash: err.attemptedMessageHash,
|
|
930
1072
|
});
|
|
@@ -933,6 +1075,56 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
933
1075
|
return false;
|
|
934
1076
|
}
|
|
935
1077
|
|
|
1078
|
+
/**
|
|
1079
|
+
* In times of congestion we need to simulate using the correct fee header override for the previous block
|
|
1080
|
+
* We calculate the correct fee header values.
|
|
1081
|
+
*
|
|
1082
|
+
* If we are in block 1, or the checkpoint we are querying does not exist, we return undefined. However
|
|
1083
|
+
* If we are pipelining - where this function is called, the grandparentCheckpointNumber should always exist
|
|
1084
|
+
* @param parentCheckpointNumber
|
|
1085
|
+
* @returns
|
|
1086
|
+
*/
|
|
1087
|
+
protected async computeForceProposedFeeHeader(parentCheckpointNumber: CheckpointNumber): Promise<
|
|
1088
|
+
| {
|
|
1089
|
+
checkpointNumber: CheckpointNumber;
|
|
1090
|
+
feeHeader: FeeHeader;
|
|
1091
|
+
}
|
|
1092
|
+
| undefined
|
|
1093
|
+
> {
|
|
1094
|
+
if (!this.proposedCheckpointData) {
|
|
1095
|
+
return undefined;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
const rollup = this.publisher.rollupContract;
|
|
1099
|
+
const grandparentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 2);
|
|
1100
|
+
try {
|
|
1101
|
+
const [grandparentCheckpoint, manaTarget] = await Promise.all([
|
|
1102
|
+
rollup.getCheckpoint(grandparentCheckpointNumber),
|
|
1103
|
+
rollup.getManaTarget(),
|
|
1104
|
+
]);
|
|
1105
|
+
|
|
1106
|
+
if (!grandparentCheckpoint || !grandparentCheckpoint.feeHeader) {
|
|
1107
|
+
this.log.error(
|
|
1108
|
+
`Grandparent checkpoint or its feeHeader is undefined for checkpointNumber=${grandparentCheckpointNumber.toString()}`,
|
|
1109
|
+
);
|
|
1110
|
+
return undefined;
|
|
1111
|
+
} else {
|
|
1112
|
+
const parentFeeHeader = RollupContract.computeChildFeeHeader(
|
|
1113
|
+
grandparentCheckpoint.feeHeader,
|
|
1114
|
+
this.proposedCheckpointData.totalManaUsed,
|
|
1115
|
+
this.proposedCheckpointData.feeAssetPriceModifier,
|
|
1116
|
+
manaTarget,
|
|
1117
|
+
);
|
|
1118
|
+
return { checkpointNumber: parentCheckpointNumber, feeHeader: parentFeeHeader };
|
|
1119
|
+
}
|
|
1120
|
+
} catch (err) {
|
|
1121
|
+
this.log.error(
|
|
1122
|
+
`Failed to fetch grandparent checkpoint or mana target for checkpointNumber=${grandparentCheckpointNumber.toString()}: ${err}`,
|
|
1123
|
+
);
|
|
1124
|
+
return undefined;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
936
1128
|
/** Waits until a specific time within the current slot */
|
|
937
1129
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
938
1130
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
@@ -947,7 +1139,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
947
1139
|
}
|
|
948
1140
|
|
|
949
1141
|
private getSlotStartBuildTimestamp(): number {
|
|
950
|
-
return getSlotStartBuildTimestamp(this.
|
|
1142
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
951
1143
|
}
|
|
952
1144
|
|
|
953
1145
|
private getSecondsIntoSlot(): number {
|