@aztec/sequencer-client 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec
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 +12 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +15 -4
- package/dest/config.d.ts +3 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +17 -14
- package/dest/global_variable_builder/global_builder.d.ts +2 -4
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -2
- package/dest/publisher/config.d.ts +35 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +106 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +13 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +22 -8
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +297 -47
- package/dest/sequencer/checkpoint_proposal_job.d.ts +32 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +121 -61
- package/dest/sequencer/metrics.d.ts +17 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +111 -30
- package/dest/sequencer/sequencer.d.ts +17 -7
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +30 -27
- package/dest/sequencer/timetable.d.ts +1 -4
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +2 -5
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +14 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +24 -10
- package/dest/test/utils.d.ts +8 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -9
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +25 -7
- package/src/config.ts +27 -22
- package/src/global_variable_builder/global_builder.ts +3 -3
- package/src/publisher/config.ts +121 -43
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +23 -6
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +274 -53
- package/src/sequencer/checkpoint_proposal_job.ts +172 -87
- package/src/sequencer/metrics.ts +124 -32
- package/src/sequencer/sequencer.ts +40 -32
- package/src/sequencer/timetable.ts +7 -6
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +44 -19
- package/src/test/utils.ts +22 -13
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
2
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BlockNumber,
|
|
6
|
+
CheckpointNumber,
|
|
7
|
+
EpochNumber,
|
|
8
|
+
IndexWithinCheckpoint,
|
|
9
|
+
SlotNumber,
|
|
10
|
+
} from '@aztec/foundation/branded-types';
|
|
5
11
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
6
12
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
13
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
14
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
9
15
|
import { filter } from '@aztec/foundation/iterator';
|
|
10
|
-
import type
|
|
16
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
17
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
12
18
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
13
|
-
import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
|
|
19
|
+
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
14
20
|
import type { P2P } from '@aztec/p2p';
|
|
15
21
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
16
22
|
import {
|
|
17
23
|
CommitteeAttestation,
|
|
18
24
|
CommitteeAttestationsAndSigners,
|
|
19
|
-
|
|
25
|
+
L2Block,
|
|
20
26
|
type L2BlockSink,
|
|
21
27
|
type L2BlockSource,
|
|
22
28
|
MaliciousCommitteeAttestationsAndSigners,
|
|
@@ -24,14 +30,15 @@ import {
|
|
|
24
30
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
25
31
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
26
32
|
import { Gas } from '@aztec/stdlib/gas';
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
import {
|
|
34
|
+
NoValidTxsError,
|
|
35
|
+
type PublicProcessorLimits,
|
|
36
|
+
type ResolvedSequencerConfig,
|
|
37
|
+
type WorldStateSynchronizer,
|
|
31
38
|
} from '@aztec/stdlib/interfaces/server';
|
|
32
39
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
33
40
|
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
34
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
41
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
35
42
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
36
43
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
37
44
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -59,6 +66,8 @@ const TXS_POLLING_MS = 500;
|
|
|
59
66
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
60
67
|
*/
|
|
61
68
|
export class CheckpointProposalJob implements Traceable {
|
|
69
|
+
protected readonly log: Logger;
|
|
70
|
+
|
|
62
71
|
constructor(
|
|
63
72
|
private readonly epoch: EpochNumber,
|
|
64
73
|
private readonly slot: SlotNumber,
|
|
@@ -86,9 +95,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
86
95
|
private readonly metrics: SequencerMetrics,
|
|
87
96
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
88
97
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
89
|
-
protected readonly log: Logger,
|
|
90
98
|
public readonly tracer: Tracer,
|
|
91
|
-
|
|
99
|
+
bindings?: LoggerBindings,
|
|
100
|
+
) {
|
|
101
|
+
this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
|
|
102
|
+
}
|
|
92
103
|
|
|
93
104
|
/**
|
|
94
105
|
* Executes the checkpoint proposal job.
|
|
@@ -118,7 +129,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
118
129
|
await Promise.all(votesPromises);
|
|
119
130
|
|
|
120
131
|
if (checkpoint) {
|
|
121
|
-
this.metrics.
|
|
132
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
122
133
|
}
|
|
123
134
|
|
|
124
135
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
@@ -175,21 +186,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
175
186
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
176
187
|
|
|
177
188
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
178
|
-
const
|
|
179
|
-
c => c.
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
|
|
190
|
+
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
191
|
+
.map(c => c.checkpointOutHash);
|
|
192
|
+
|
|
193
|
+
// Get the fee asset price modifier from the oracle
|
|
194
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
182
195
|
|
|
183
196
|
// Create a long-lived forked world state for the checkpoint builder
|
|
184
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
197
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
185
198
|
|
|
186
199
|
// Create checkpoint builder for the entire slot
|
|
187
200
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
188
201
|
this.checkpointNumber,
|
|
189
202
|
checkpointGlobalVariables,
|
|
203
|
+
feeAssetPriceModifier,
|
|
190
204
|
l1ToL2Messages,
|
|
191
205
|
previousCheckpointOutHashes,
|
|
192
206
|
fork,
|
|
207
|
+
this.log.getBindings(),
|
|
193
208
|
);
|
|
194
209
|
|
|
195
210
|
// Options for the validator client when creating block and checkpoint proposals
|
|
@@ -203,8 +218,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
203
218
|
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
204
219
|
};
|
|
205
220
|
|
|
206
|
-
let blocksInCheckpoint:
|
|
207
|
-
let blockPendingBroadcast: { block:
|
|
221
|
+
let blocksInCheckpoint: L2Block[] = [];
|
|
222
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
223
|
+
const checkpointBuildTimer = new Timer();
|
|
208
224
|
|
|
209
225
|
try {
|
|
210
226
|
// Main loop: build blocks for the checkpoint
|
|
@@ -220,19 +236,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
220
236
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
221
237
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
222
238
|
// which is normal for block building (may have picked different txs)
|
|
223
|
-
if (err
|
|
224
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
225
|
-
slot: this.slot,
|
|
226
|
-
signedByNode: err.signedByNode,
|
|
227
|
-
});
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
if (err instanceof SlashingProtectionError) {
|
|
231
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
232
|
-
slot: this.slot,
|
|
233
|
-
existingMessageHash: err.existingMessageHash,
|
|
234
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
235
|
-
});
|
|
239
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
236
240
|
return undefined;
|
|
237
241
|
}
|
|
238
242
|
throw err;
|
|
@@ -244,11 +248,28 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
244
248
|
return undefined;
|
|
245
249
|
}
|
|
246
250
|
|
|
251
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
252
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
253
|
+
this.log.warn(
|
|
254
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
255
|
+
{ slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
256
|
+
);
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
247
260
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
248
261
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
249
262
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
250
263
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
251
264
|
|
|
265
|
+
// Record checkpoint-level build metrics
|
|
266
|
+
this.metrics.recordCheckpointBuild(
|
|
267
|
+
checkpointBuildTimer.ms(),
|
|
268
|
+
blocksInCheckpoint.length,
|
|
269
|
+
checkpoint.getStats().txCount,
|
|
270
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
271
|
+
);
|
|
272
|
+
|
|
252
273
|
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
253
274
|
if (this.config.fishermanMode) {
|
|
254
275
|
this.log.info(
|
|
@@ -275,6 +296,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
275
296
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
276
297
|
checkpoint.header,
|
|
277
298
|
checkpoint.archive.root,
|
|
299
|
+
feeAssetPriceModifier,
|
|
278
300
|
lastBlock,
|
|
279
301
|
this.proposer,
|
|
280
302
|
checkpointProposalOptions,
|
|
@@ -301,20 +323,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
301
323
|
);
|
|
302
324
|
} catch (err) {
|
|
303
325
|
// We shouldn't really get here since we yield to another HA node
|
|
304
|
-
// as soon as we see these errors when creating block proposals.
|
|
305
|
-
if (err
|
|
306
|
-
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
307
|
-
slot: this.slot,
|
|
308
|
-
signedByNode: err.signedByNode,
|
|
309
|
-
});
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
if (err instanceof SlashingProtectionError) {
|
|
313
|
-
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
314
|
-
slot: this.slot,
|
|
315
|
-
existingMessageHash: err.existingMessageHash,
|
|
316
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
317
|
-
});
|
|
326
|
+
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
327
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
318
328
|
return undefined;
|
|
319
329
|
}
|
|
320
330
|
throw err;
|
|
@@ -325,6 +335,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
325
335
|
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
326
336
|
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
327
337
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
338
|
+
|
|
339
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
340
|
+
if (
|
|
341
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
342
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
343
|
+
) {
|
|
344
|
+
const result = Math.max(0, randomInt(100));
|
|
345
|
+
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
346
|
+
this.log.warn(
|
|
347
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
348
|
+
);
|
|
349
|
+
return checkpoint;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
328
353
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
329
354
|
txTimeoutAt,
|
|
330
355
|
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
@@ -352,10 +377,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
352
377
|
inHash: Fr,
|
|
353
378
|
blockProposalOptions: BlockProposalOptions,
|
|
354
379
|
): Promise<{
|
|
355
|
-
blocksInCheckpoint:
|
|
356
|
-
blockPendingBroadcast: { block:
|
|
380
|
+
blocksInCheckpoint: L2Block[];
|
|
381
|
+
blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
|
|
357
382
|
}> {
|
|
358
|
-
const blocksInCheckpoint:
|
|
383
|
+
const blocksInCheckpoint: L2Block[] = [];
|
|
359
384
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
360
385
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
361
386
|
|
|
@@ -363,11 +388,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
363
388
|
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
364
389
|
|
|
365
390
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
366
|
-
let blockPendingBroadcast: { block:
|
|
391
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
367
392
|
|
|
368
393
|
while (true) {
|
|
369
394
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
370
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
395
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
371
396
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
372
397
|
|
|
373
398
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
@@ -397,6 +422,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
397
422
|
remainingBlobFields,
|
|
398
423
|
});
|
|
399
424
|
|
|
425
|
+
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
400
426
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
401
427
|
// If no block was produced due to not enough txs and this was the last subslot, exit
|
|
402
428
|
break;
|
|
@@ -428,7 +454,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
428
454
|
// Sync the proposed block to the archiver to make it available
|
|
429
455
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
430
456
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
431
|
-
|
|
457
|
+
// Fire and forget - don't block the critical path, but log errors
|
|
458
|
+
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
459
|
+
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
432
463
|
|
|
433
464
|
// If this is the last block, exit the loop now so we start collecting attestations
|
|
434
465
|
if (timingInfo.isLastBlock) {
|
|
@@ -478,18 +509,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
478
509
|
|
|
479
510
|
/** Builds a single block. Called from the main block building loop. */
|
|
480
511
|
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
481
|
-
|
|
512
|
+
protected async buildSingleBlock(
|
|
482
513
|
checkpointBuilder: CheckpointBuilder,
|
|
483
514
|
opts: {
|
|
484
515
|
forceCreate?: boolean;
|
|
485
516
|
blockTimestamp: bigint;
|
|
486
517
|
blockNumber: BlockNumber;
|
|
487
|
-
indexWithinCheckpoint:
|
|
518
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
488
519
|
buildDeadline: Date | undefined;
|
|
489
520
|
txHashesAlreadyIncluded: Set<string>;
|
|
490
521
|
remainingBlobFields: number;
|
|
491
522
|
},
|
|
492
|
-
): Promise<{ block:
|
|
523
|
+
): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
493
524
|
const {
|
|
494
525
|
blockTimestamp,
|
|
495
526
|
forceCreate,
|
|
@@ -522,7 +553,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
522
553
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
523
554
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
524
555
|
const pendingTxs = filter(
|
|
525
|
-
this.p2pClient.
|
|
556
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
526
557
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
527
558
|
);
|
|
528
559
|
|
|
@@ -545,45 +576,38 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
545
576
|
};
|
|
546
577
|
|
|
547
578
|
// Actually build the block by executing txs
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
usedTxs,
|
|
556
|
-
failedTxs,
|
|
557
|
-
usedTxBlobFields,
|
|
558
|
-
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
559
|
-
const blockBuildDuration = workTimer.ms();
|
|
579
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
580
|
+
checkpointBuilder,
|
|
581
|
+
pendingTxs,
|
|
582
|
+
blockNumber,
|
|
583
|
+
blockTimestamp,
|
|
584
|
+
blockBuilderOptions,
|
|
585
|
+
);
|
|
560
586
|
|
|
561
587
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
562
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
588
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
563
589
|
|
|
564
590
|
// Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
|
|
565
591
|
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
566
592
|
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
567
|
-
|
|
593
|
+
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
594
|
+
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
568
595
|
this.log.warn(
|
|
569
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed
|
|
570
|
-
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint },
|
|
596
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
|
|
597
|
+
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint, minValidTxs, buildResult: buildResult.status },
|
|
571
598
|
);
|
|
572
|
-
this.eventEmitter.emit('block-
|
|
573
|
-
minTxs: minValidTxs,
|
|
574
|
-
availableTxs: numTxs,
|
|
575
|
-
slot: this.slot,
|
|
576
|
-
});
|
|
599
|
+
this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
|
|
577
600
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
578
601
|
return undefined;
|
|
579
602
|
}
|
|
580
603
|
|
|
581
604
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
+
const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
|
|
606
|
+
|
|
582
607
|
const blockStats = {
|
|
583
608
|
eventName: 'l2-block-built',
|
|
584
609
|
duration: blockBuildDuration,
|
|
585
610
|
publicProcessDuration: publicProcessorDuration,
|
|
586
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
587
611
|
...block.getStats(),
|
|
588
612
|
} satisfies L2BlockBuiltStats;
|
|
589
613
|
|
|
@@ -609,17 +633,40 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
609
633
|
}
|
|
610
634
|
}
|
|
611
635
|
|
|
636
|
+
/** Uses the checkpoint builder to build a block, catching specific txs */
|
|
637
|
+
private async buildSingleBlockWithCheckpointBuilder(
|
|
638
|
+
checkpointBuilder: CheckpointBuilder,
|
|
639
|
+
pendingTxs: AsyncIterable<Tx>,
|
|
640
|
+
blockNumber: BlockNumber,
|
|
641
|
+
blockTimestamp: bigint,
|
|
642
|
+
blockBuilderOptions: PublicProcessorLimits,
|
|
643
|
+
) {
|
|
644
|
+
try {
|
|
645
|
+
const workTimer = new Timer();
|
|
646
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
647
|
+
const blockBuildDuration = workTimer.ms();
|
|
648
|
+
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
649
|
+
} catch (err: unknown) {
|
|
650
|
+
if (isErrorClass(err, NoValidTxsError)) {
|
|
651
|
+
return { failedTxs: err.failedTxs, status: 'no-valid-txs' as const };
|
|
652
|
+
}
|
|
653
|
+
throw err;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
612
657
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
613
658
|
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
614
659
|
private async waitForMinTxs(opts: {
|
|
615
660
|
forceCreate?: boolean;
|
|
616
661
|
blockNumber: BlockNumber;
|
|
617
|
-
indexWithinCheckpoint:
|
|
662
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
618
663
|
buildDeadline: Date | undefined;
|
|
619
664
|
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
620
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
621
665
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
622
666
|
|
|
667
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
668
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
669
|
+
|
|
623
670
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
624
671
|
const startBuildingDeadline = buildDeadline
|
|
625
672
|
? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
|
|
@@ -640,7 +687,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
640
687
|
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
|
|
641
688
|
{ blockNumber, slot: this.slot, indexWithinCheckpoint },
|
|
642
689
|
);
|
|
643
|
-
await
|
|
690
|
+
await this.waitForTxsPollingInterval();
|
|
644
691
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
645
692
|
}
|
|
646
693
|
|
|
@@ -681,7 +728,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
681
728
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
682
729
|
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
|
|
683
730
|
: this.l1Constants.slotDuration;
|
|
684
|
-
const attestationDeadline = new Date(this.
|
|
731
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
685
732
|
|
|
686
733
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
687
734
|
|
|
@@ -696,8 +743,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
696
743
|
|
|
697
744
|
collectedAttestationsCount = attestations.length;
|
|
698
745
|
|
|
746
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
747
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
748
|
+
const trimmed = trimAttestations(
|
|
749
|
+
attestations,
|
|
750
|
+
numberOfRequiredAttestations,
|
|
751
|
+
this.attestorAddress,
|
|
752
|
+
localAddresses,
|
|
753
|
+
);
|
|
754
|
+
if (trimmed.length < attestations.length) {
|
|
755
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
756
|
+
}
|
|
757
|
+
|
|
699
758
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
700
|
-
const sorted = orderAttestations(
|
|
759
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
701
760
|
|
|
702
761
|
// Manipulate the attestations if we've been configured to do so
|
|
703
762
|
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
@@ -769,7 +828,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
769
828
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
770
829
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
771
830
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
772
|
-
await this.p2pClient.
|
|
831
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
773
832
|
}
|
|
774
833
|
|
|
775
834
|
/**
|
|
@@ -777,8 +836,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
777
836
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
778
837
|
* would never receive its own block without this explicit sync.
|
|
779
838
|
*/
|
|
780
|
-
private async syncProposedBlockToArchiver(block:
|
|
781
|
-
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
839
|
+
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
782
840
|
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
783
841
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
784
842
|
blockNumber: block.number,
|
|
@@ -812,12 +870,34 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
812
870
|
slot: this.slot,
|
|
813
871
|
feeAnalysisId: feeAnalysis?.id,
|
|
814
872
|
});
|
|
815
|
-
this.metrics.
|
|
873
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
816
874
|
}
|
|
817
875
|
|
|
818
876
|
this.publisher.clearPendingRequests();
|
|
819
877
|
}
|
|
820
878
|
|
|
879
|
+
/**
|
|
880
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
881
|
+
*/
|
|
882
|
+
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
883
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
884
|
+
this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
885
|
+
slot: this.slot,
|
|
886
|
+
signedByNode: err.signedByNode,
|
|
887
|
+
});
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
if (err instanceof SlashingProtectionError) {
|
|
891
|
+
this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
892
|
+
slot: this.slot,
|
|
893
|
+
existingMessageHash: err.existingMessageHash,
|
|
894
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
895
|
+
});
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
|
|
821
901
|
/** Waits until a specific time within the current slot */
|
|
822
902
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
823
903
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
@@ -826,6 +906,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
826
906
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
827
907
|
}
|
|
828
908
|
|
|
909
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */
|
|
910
|
+
protected async waitForTxsPollingInterval(): Promise<void> {
|
|
911
|
+
await sleep(TXS_POLLING_MS);
|
|
912
|
+
}
|
|
913
|
+
|
|
829
914
|
private getSlotStartBuildTimestamp(): number {
|
|
830
915
|
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
831
916
|
}
|