@aztec/sequencer-client 0.0.1-commit.e61ad554 → 0.0.1-commit.ec5f612
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 -12
- 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/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 +113 -59
- 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 +7 -5
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +6 -6
- package/dest/test/utils.d.ts +3 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +5 -4
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +25 -7
- package/src/config.ts +26 -19
- package/src/global_variable_builder/global_builder.ts +1 -1
- 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 +157 -76
- 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 +14 -5
- package/src/test/utils.ts +5 -2
|
@@ -1,16 +1,22 @@
|
|
|
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 {
|
|
@@ -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
|
|
@@ -205,6 +220,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
205
220
|
|
|
206
221
|
let blocksInCheckpoint: L2Block[] = [];
|
|
207
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,
|
|
@@ -367,7 +392,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
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;
|
|
@@ -483,13 +509,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
483
509
|
|
|
484
510
|
/** Builds a single block. Called from the main block building loop. */
|
|
485
511
|
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
486
|
-
|
|
512
|
+
protected async buildSingleBlock(
|
|
487
513
|
checkpointBuilder: CheckpointBuilder,
|
|
488
514
|
opts: {
|
|
489
515
|
forceCreate?: boolean;
|
|
490
516
|
blockTimestamp: bigint;
|
|
491
517
|
blockNumber: BlockNumber;
|
|
492
|
-
indexWithinCheckpoint:
|
|
518
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
493
519
|
buildDeadline: Date | undefined;
|
|
494
520
|
txHashesAlreadyIncluded: Set<string>;
|
|
495
521
|
remainingBlobFields: number;
|
|
@@ -527,7 +553,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
527
553
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
528
554
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
529
555
|
const pendingTxs = filter(
|
|
530
|
-
this.p2pClient.
|
|
556
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
531
557
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
532
558
|
);
|
|
533
559
|
|
|
@@ -550,45 +576,38 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
550
576
|
};
|
|
551
577
|
|
|
552
578
|
// Actually build the block by executing txs
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
usedTxs,
|
|
561
|
-
failedTxs,
|
|
562
|
-
usedTxBlobFields,
|
|
563
|
-
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
564
|
-
const blockBuildDuration = workTimer.ms();
|
|
579
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
580
|
+
checkpointBuilder,
|
|
581
|
+
pendingTxs,
|
|
582
|
+
blockNumber,
|
|
583
|
+
blockTimestamp,
|
|
584
|
+
blockBuilderOptions,
|
|
585
|
+
);
|
|
565
586
|
|
|
566
587
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
567
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
588
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
568
589
|
|
|
569
590
|
// Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
|
|
570
591
|
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
571
592
|
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
572
|
-
|
|
593
|
+
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
594
|
+
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
573
595
|
this.log.warn(
|
|
574
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed
|
|
575
|
-
{ 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 },
|
|
576
598
|
);
|
|
577
|
-
this.eventEmitter.emit('block-
|
|
578
|
-
minTxs: minValidTxs,
|
|
579
|
-
availableTxs: numTxs,
|
|
580
|
-
slot: this.slot,
|
|
581
|
-
});
|
|
599
|
+
this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
|
|
582
600
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
583
601
|
return undefined;
|
|
584
602
|
}
|
|
585
603
|
|
|
586
604
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
+
const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
|
|
606
|
+
|
|
587
607
|
const blockStats = {
|
|
588
608
|
eventName: 'l2-block-built',
|
|
589
609
|
duration: blockBuildDuration,
|
|
590
610
|
publicProcessDuration: publicProcessorDuration,
|
|
591
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
592
611
|
...block.getStats(),
|
|
593
612
|
} satisfies L2BlockBuiltStats;
|
|
594
613
|
|
|
@@ -614,17 +633,40 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
614
633
|
}
|
|
615
634
|
}
|
|
616
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
|
+
|
|
617
657
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
618
658
|
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
619
659
|
private async waitForMinTxs(opts: {
|
|
620
660
|
forceCreate?: boolean;
|
|
621
661
|
blockNumber: BlockNumber;
|
|
622
|
-
indexWithinCheckpoint:
|
|
662
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
623
663
|
buildDeadline: Date | undefined;
|
|
624
664
|
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
625
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
626
665
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
627
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
|
+
|
|
628
670
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
629
671
|
const startBuildingDeadline = buildDeadline
|
|
630
672
|
? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
|
|
@@ -645,7 +687,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
645
687
|
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
|
|
646
688
|
{ blockNumber, slot: this.slot, indexWithinCheckpoint },
|
|
647
689
|
);
|
|
648
|
-
await
|
|
690
|
+
await this.waitForTxsPollingInterval();
|
|
649
691
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
650
692
|
}
|
|
651
693
|
|
|
@@ -686,7 +728,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
686
728
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
687
729
|
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
|
|
688
730
|
: this.l1Constants.slotDuration;
|
|
689
|
-
const attestationDeadline = new Date(this.
|
|
731
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
690
732
|
|
|
691
733
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
692
734
|
|
|
@@ -701,8 +743,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
701
743
|
|
|
702
744
|
collectedAttestationsCount = attestations.length;
|
|
703
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
|
+
|
|
704
758
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
705
|
-
const sorted = orderAttestations(
|
|
759
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
706
760
|
|
|
707
761
|
// Manipulate the attestations if we've been configured to do so
|
|
708
762
|
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
@@ -774,7 +828,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
774
828
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
775
829
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
776
830
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
777
|
-
await this.p2pClient.
|
|
831
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
778
832
|
}
|
|
779
833
|
|
|
780
834
|
/**
|
|
@@ -816,12 +870,34 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
816
870
|
slot: this.slot,
|
|
817
871
|
feeAnalysisId: feeAnalysis?.id,
|
|
818
872
|
});
|
|
819
|
-
this.metrics.
|
|
873
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
820
874
|
}
|
|
821
875
|
|
|
822
876
|
this.publisher.clearPendingRequests();
|
|
823
877
|
}
|
|
824
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
|
+
|
|
825
901
|
/** Waits until a specific time within the current slot */
|
|
826
902
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
827
903
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
@@ -830,6 +906,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
830
906
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
831
907
|
}
|
|
832
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
|
+
|
|
833
914
|
private getSlotStartBuildTimestamp(): number {
|
|
834
915
|
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
835
916
|
}
|