@aztec/sequencer-client 0.0.1-commit.ee80a48 → 0.0.1-commit.ef17749e1
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 +23 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +99 -16
- package/dest/config.d.ts +24 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +40 -28
- 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 +27 -2
- package/dest/publisher/sequencer-publisher.d.ts +26 -7
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +299 -30
- package/dest/sequencer/checkpoint_proposal_job.d.ts +4 -4
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +104 -48
- package/dest/sequencer/metrics.d.ts +17 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +86 -15
- package/dest/sequencer/sequencer.d.ts +23 -12
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +25 -26
- package/dest/sequencer/timetable.d.ts +4 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +7 -11
- package/dest/sequencer/types.d.ts +5 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- 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 +8 -8
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +45 -34
- 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 +135 -18
- package/src/config.ts +54 -38
- 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 +38 -6
- package/src/publisher/sequencer-publisher.ts +300 -43
- package/src/sequencer/checkpoint_proposal_job.ts +142 -54
- package/src/sequencer/metrics.ts +92 -18
- package/src/sequencer/sequencer.ts +33 -31
- package/src/sequencer/timetable.ts +13 -12
- package/src/sequencer/types.ts +4 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +60 -46
- package/src/test/utils.ts +5 -2
|
@@ -1,5 +1,3 @@
|
|
|
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';
|
|
4
2
|
import {
|
|
5
3
|
BlockNumber,
|
|
@@ -9,6 +7,11 @@ import {
|
|
|
9
7
|
SlotNumber,
|
|
10
8
|
} from '@aztec/foundation/branded-types';
|
|
11
9
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
10
|
+
import {
|
|
11
|
+
flipSignature,
|
|
12
|
+
generateRecoverableSignature,
|
|
13
|
+
generateUnrecoverableSignature,
|
|
14
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
12
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
17
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
@@ -27,7 +30,7 @@ import {
|
|
|
27
30
|
type L2BlockSource,
|
|
28
31
|
MaliciousCommitteeAttestationsAndSigners,
|
|
29
32
|
} from '@aztec/stdlib/block';
|
|
30
|
-
import type
|
|
33
|
+
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
31
34
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
32
35
|
import { Gas } from '@aztec/stdlib/gas';
|
|
33
36
|
import {
|
|
@@ -38,7 +41,7 @@ import {
|
|
|
38
41
|
} from '@aztec/stdlib/interfaces/server';
|
|
39
42
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
40
43
|
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
41
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
44
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
42
45
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
43
46
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
44
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -129,7 +132,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
129
132
|
await Promise.all(votesPromises);
|
|
130
133
|
|
|
131
134
|
if (checkpoint) {
|
|
132
|
-
this.metrics.
|
|
135
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
@@ -186,18 +189,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
186
189
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
187
190
|
|
|
188
191
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
189
|
-
const
|
|
190
|
-
c => c.
|
|
191
|
-
|
|
192
|
-
|
|
192
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
|
|
193
|
+
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
194
|
+
.map(c => c.checkpointOutHash);
|
|
195
|
+
|
|
196
|
+
// Get the fee asset price modifier from the oracle
|
|
197
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
193
198
|
|
|
194
199
|
// Create a long-lived forked world state for the checkpoint builder
|
|
195
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
200
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
196
201
|
|
|
197
202
|
// Create checkpoint builder for the entire slot
|
|
198
203
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
199
204
|
this.checkpointNumber,
|
|
200
205
|
checkpointGlobalVariables,
|
|
206
|
+
feeAssetPriceModifier,
|
|
201
207
|
l1ToL2Messages,
|
|
202
208
|
previousCheckpointOutHashes,
|
|
203
209
|
fork,
|
|
@@ -217,6 +223,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
217
223
|
|
|
218
224
|
let blocksInCheckpoint: L2Block[] = [];
|
|
219
225
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
226
|
+
const checkpointBuildTimer = new Timer();
|
|
220
227
|
|
|
221
228
|
try {
|
|
222
229
|
// Main loop: build blocks for the checkpoint
|
|
@@ -244,11 +251,44 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
244
251
|
return undefined;
|
|
245
252
|
}
|
|
246
253
|
|
|
254
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
255
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
256
|
+
this.log.warn(
|
|
257
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
258
|
+
{ slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
259
|
+
);
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
247
263
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
248
264
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
249
265
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
250
266
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
251
267
|
|
|
268
|
+
// Final validation round for the checkpoint before we propose it, just for safety
|
|
269
|
+
try {
|
|
270
|
+
validateCheckpoint(checkpoint, {
|
|
271
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
272
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
273
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
274
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
275
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
276
|
+
});
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
|
|
279
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
280
|
+
});
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Record checkpoint-level build metrics
|
|
285
|
+
this.metrics.recordCheckpointBuild(
|
|
286
|
+
checkpointBuildTimer.ms(),
|
|
287
|
+
blocksInCheckpoint.length,
|
|
288
|
+
checkpoint.getStats().txCount,
|
|
289
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
290
|
+
);
|
|
291
|
+
|
|
252
292
|
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
253
293
|
if (this.config.fishermanMode) {
|
|
254
294
|
this.log.info(
|
|
@@ -275,6 +315,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
275
315
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
276
316
|
checkpoint.header,
|
|
277
317
|
checkpoint.archive.root,
|
|
318
|
+
feeAssetPriceModifier,
|
|
278
319
|
lastBlock,
|
|
279
320
|
this.proposer,
|
|
280
321
|
checkpointProposalOptions,
|
|
@@ -313,6 +354,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
313
354
|
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
314
355
|
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
315
356
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
357
|
+
|
|
358
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
359
|
+
if (
|
|
360
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
361
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
362
|
+
) {
|
|
363
|
+
const result = Math.max(0, randomInt(100));
|
|
364
|
+
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
365
|
+
this.log.warn(
|
|
366
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
367
|
+
);
|
|
368
|
+
return checkpoint;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
316
372
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
317
373
|
txTimeoutAt,
|
|
318
374
|
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
@@ -347,9 +403,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
347
403
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
348
404
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
349
405
|
|
|
350
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
351
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
352
|
-
|
|
353
406
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
354
407
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
355
408
|
|
|
@@ -382,7 +435,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
382
435
|
blockNumber,
|
|
383
436
|
indexWithinCheckpoint,
|
|
384
437
|
txHashesAlreadyIncluded,
|
|
385
|
-
remainingBlobFields,
|
|
386
438
|
});
|
|
387
439
|
|
|
388
440
|
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
@@ -408,12 +460,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
408
460
|
break;
|
|
409
461
|
}
|
|
410
462
|
|
|
411
|
-
const { block, usedTxs
|
|
463
|
+
const { block, usedTxs } = buildResult;
|
|
412
464
|
blocksInCheckpoint.push(block);
|
|
413
465
|
|
|
414
|
-
// Update remaining blob fields for the next block
|
|
415
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
416
|
-
|
|
417
466
|
// Sync the proposed block to the archiver to make it available
|
|
418
467
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
419
468
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
@@ -481,18 +530,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
481
530
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
482
531
|
buildDeadline: Date | undefined;
|
|
483
532
|
txHashesAlreadyIncluded: Set<string>;
|
|
484
|
-
remainingBlobFields: number;
|
|
485
533
|
},
|
|
486
|
-
): Promise<{ block: L2Block; usedTxs: Tx[]
|
|
487
|
-
const {
|
|
488
|
-
|
|
489
|
-
forceCreate,
|
|
490
|
-
blockNumber,
|
|
491
|
-
indexWithinCheckpoint,
|
|
492
|
-
buildDeadline,
|
|
493
|
-
txHashesAlreadyIncluded,
|
|
494
|
-
remainingBlobFields,
|
|
495
|
-
} = opts;
|
|
534
|
+
): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
535
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
536
|
+
opts;
|
|
496
537
|
|
|
497
538
|
this.log.verbose(
|
|
498
539
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -516,7 +557,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
516
557
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
517
558
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
518
559
|
const pendingTxs = filter(
|
|
519
|
-
this.p2pClient.
|
|
560
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
520
561
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
521
562
|
);
|
|
522
563
|
|
|
@@ -526,16 +567,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
526
567
|
);
|
|
527
568
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
528
569
|
|
|
529
|
-
//
|
|
530
|
-
|
|
531
|
-
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
532
|
-
|
|
570
|
+
// Per-block limits derived at startup by computeBlockLimits(), further capped
|
|
571
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
533
572
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
534
573
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
574
|
+
maxBlockGas:
|
|
575
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
576
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
577
|
+
: undefined,
|
|
538
578
|
deadline: buildDeadline,
|
|
579
|
+
isBuildingProposal: true,
|
|
539
580
|
};
|
|
540
581
|
|
|
541
582
|
// Actually build the block by executing txs
|
|
@@ -565,7 +606,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
565
606
|
}
|
|
566
607
|
|
|
567
608
|
// Block creation succeeded, emit stats and metrics
|
|
568
|
-
const {
|
|
609
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
|
|
569
610
|
|
|
570
611
|
const blockStats = {
|
|
571
612
|
eventName: 'l2-block-built',
|
|
@@ -576,7 +617,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
576
617
|
|
|
577
618
|
const blockHash = await block.hash();
|
|
578
619
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
579
|
-
const manaPerSec =
|
|
620
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
580
621
|
|
|
581
622
|
this.log.info(
|
|
582
623
|
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
|
|
@@ -584,9 +625,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
584
625
|
);
|
|
585
626
|
|
|
586
627
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
587
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
628
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
588
629
|
|
|
589
|
-
return { block, usedTxs
|
|
630
|
+
return { block, usedTxs };
|
|
590
631
|
} catch (err: any) {
|
|
591
632
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
592
633
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -650,7 +691,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
650
691
|
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
|
|
651
692
|
{ blockNumber, slot: this.slot, indexWithinCheckpoint },
|
|
652
693
|
);
|
|
653
|
-
await
|
|
694
|
+
await this.waitForTxsPollingInterval();
|
|
654
695
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
655
696
|
}
|
|
656
697
|
|
|
@@ -706,11 +747,28 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
706
747
|
|
|
707
748
|
collectedAttestationsCount = attestations.length;
|
|
708
749
|
|
|
750
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
751
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
752
|
+
const trimmed = trimAttestations(
|
|
753
|
+
attestations,
|
|
754
|
+
numberOfRequiredAttestations,
|
|
755
|
+
this.attestorAddress,
|
|
756
|
+
localAddresses,
|
|
757
|
+
);
|
|
758
|
+
if (trimmed.length < attestations.length) {
|
|
759
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
760
|
+
}
|
|
761
|
+
|
|
709
762
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
710
|
-
const sorted = orderAttestations(
|
|
763
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
711
764
|
|
|
712
765
|
// Manipulate the attestations if we've been configured to do so
|
|
713
|
-
if (
|
|
766
|
+
if (
|
|
767
|
+
this.config.injectFakeAttestation ||
|
|
768
|
+
this.config.injectHighSValueAttestation ||
|
|
769
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
770
|
+
this.config.shuffleAttestationOrdering
|
|
771
|
+
) {
|
|
714
772
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
715
773
|
}
|
|
716
774
|
|
|
@@ -739,7 +797,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
739
797
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
740
798
|
);
|
|
741
799
|
|
|
742
|
-
if (
|
|
800
|
+
if (
|
|
801
|
+
this.config.injectFakeAttestation ||
|
|
802
|
+
this.config.injectHighSValueAttestation ||
|
|
803
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
804
|
+
) {
|
|
743
805
|
// Find non-empty attestations that are not from the proposer
|
|
744
806
|
const nonProposerIndices: number[] = [];
|
|
745
807
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -749,8 +811,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
749
811
|
}
|
|
750
812
|
if (nonProposerIndices.length > 0) {
|
|
751
813
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
752
|
-
this.
|
|
753
|
-
|
|
814
|
+
if (this.config.injectHighSValueAttestation) {
|
|
815
|
+
this.log.warn(
|
|
816
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
817
|
+
);
|
|
818
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
819
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
820
|
+
this.log.warn(
|
|
821
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
822
|
+
);
|
|
823
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
824
|
+
} else {
|
|
825
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
826
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
827
|
+
}
|
|
754
828
|
}
|
|
755
829
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
756
830
|
}
|
|
@@ -759,11 +833,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
759
833
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
760
834
|
|
|
761
835
|
const shuffled = [...attestations];
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
836
|
+
|
|
837
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
838
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
839
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
840
|
+
const swappable: number[] = [];
|
|
841
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
842
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
843
|
+
swappable.push(k);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (swappable.length >= 2) {
|
|
847
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
848
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
849
|
+
}
|
|
767
850
|
|
|
768
851
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
769
852
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -779,7 +862,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
779
862
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
780
863
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
781
864
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
782
|
-
await this.p2pClient.
|
|
865
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
783
866
|
}
|
|
784
867
|
|
|
785
868
|
/**
|
|
@@ -821,7 +904,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
821
904
|
slot: this.slot,
|
|
822
905
|
feeAnalysisId: feeAnalysis?.id,
|
|
823
906
|
});
|
|
824
|
-
this.metrics.
|
|
907
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
825
908
|
}
|
|
826
909
|
|
|
827
910
|
this.publisher.clearPendingRequests();
|
|
@@ -857,6 +940,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
857
940
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
858
941
|
}
|
|
859
942
|
|
|
943
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */
|
|
944
|
+
protected async waitForTxsPollingInterval(): Promise<void> {
|
|
945
|
+
await sleep(TXS_POLLING_MS);
|
|
946
|
+
}
|
|
947
|
+
|
|
860
948
|
private getSlotStartBuildTimestamp(): number {
|
|
861
949
|
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
862
950
|
}
|
package/src/sequencer/metrics.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { type Hex, formatUnits } from 'viem';
|
|
|
18
18
|
|
|
19
19
|
import type { SequencerState } from './utils.js';
|
|
20
20
|
|
|
21
|
-
// TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
|
|
22
21
|
export class SequencerMetrics {
|
|
23
22
|
public readonly tracer: Tracer;
|
|
24
23
|
private meter: Meter;
|
|
@@ -40,17 +39,26 @@ export class SequencerMetrics {
|
|
|
40
39
|
private filledSlots: UpDownCounter;
|
|
41
40
|
|
|
42
41
|
private blockProposalFailed: UpDownCounter;
|
|
43
|
-
private
|
|
44
|
-
private
|
|
42
|
+
private checkpointProposalSuccess: UpDownCounter;
|
|
43
|
+
private checkpointPrecheckFailed: UpDownCounter;
|
|
44
|
+
private checkpointProposalFailed: UpDownCounter;
|
|
45
45
|
private checkpointSuccess: UpDownCounter;
|
|
46
46
|
private slashingAttempts: UpDownCounter;
|
|
47
47
|
private checkpointAttestationDelay: Histogram;
|
|
48
|
+
private checkpointBuildDuration: Histogram;
|
|
49
|
+
private checkpointBlockCount: Gauge;
|
|
50
|
+
private checkpointTxCount: Gauge;
|
|
51
|
+
private checkpointTotalMana: Gauge;
|
|
48
52
|
|
|
49
53
|
// Fisherman fee analysis metrics
|
|
50
54
|
private fishermanWouldBeIncluded: UpDownCounter;
|
|
51
55
|
private fishermanTimeBeforeBlock: Histogram;
|
|
52
56
|
private fishermanPendingBlobTxCount: Histogram;
|
|
53
57
|
private fishermanIncludedBlobTxCount: Histogram;
|
|
58
|
+
private fishermanPendingBlobCount: Histogram;
|
|
59
|
+
private fishermanIncludedBlobCount: Histogram;
|
|
60
|
+
private fishermanBlockBlobsFull: UpDownCounter;
|
|
61
|
+
private fishermanMaxBlobCapacity: Histogram;
|
|
54
62
|
private fishermanCalculatedPriorityFee: Histogram;
|
|
55
63
|
private fishermanPriorityFeeDelta: Histogram;
|
|
56
64
|
private fishermanEstimatedCost: Histogram;
|
|
@@ -80,7 +88,7 @@ export class SequencerMetrics {
|
|
|
80
88
|
|
|
81
89
|
this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
|
|
82
90
|
|
|
83
|
-
this.rewards = this.meter.createGauge(Metrics.
|
|
91
|
+
this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_SLOT_REWARDS);
|
|
84
92
|
|
|
85
93
|
this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
|
|
86
94
|
|
|
@@ -103,16 +111,16 @@ export class SequencerMetrics {
|
|
|
103
111
|
Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT,
|
|
104
112
|
);
|
|
105
113
|
|
|
106
|
-
this.
|
|
114
|
+
this.checkpointProposalSuccess = createUpDownCounterWithDefault(
|
|
107
115
|
this.meter,
|
|
108
|
-
Metrics.
|
|
116
|
+
Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_SUCCESS_COUNT,
|
|
109
117
|
);
|
|
110
118
|
|
|
111
119
|
this.checkpointSuccess = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
|
|
112
120
|
|
|
113
|
-
this.
|
|
121
|
+
this.checkpointPrecheckFailed = createUpDownCounterWithDefault(
|
|
114
122
|
this.meter,
|
|
115
|
-
Metrics.
|
|
123
|
+
Metrics.SEQUENCER_CHECKPOINT_PRECHECK_FAILED_COUNT,
|
|
116
124
|
{
|
|
117
125
|
[Attributes.ERROR_TYPE]: [
|
|
118
126
|
'slot_already_taken',
|
|
@@ -123,6 +131,16 @@ export class SequencerMetrics {
|
|
|
123
131
|
},
|
|
124
132
|
);
|
|
125
133
|
|
|
134
|
+
this.checkpointProposalFailed = createUpDownCounterWithDefault(
|
|
135
|
+
this.meter,
|
|
136
|
+
Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_FAILED_COUNT,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
this.checkpointBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_BUILD_DURATION);
|
|
140
|
+
this.checkpointBlockCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_BLOCK_COUNT);
|
|
141
|
+
this.checkpointTxCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TX_COUNT);
|
|
142
|
+
this.checkpointTotalMana = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TOTAL_MANA);
|
|
143
|
+
|
|
126
144
|
this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
|
|
127
145
|
|
|
128
146
|
// Fisherman fee analysis metrics
|
|
@@ -131,6 +149,7 @@ export class SequencerMetrics {
|
|
|
131
149
|
Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED,
|
|
132
150
|
{
|
|
133
151
|
[Attributes.OK]: [true, false],
|
|
152
|
+
[Attributes.BLOCK_FULL]: ['true', 'false'],
|
|
134
153
|
},
|
|
135
154
|
);
|
|
136
155
|
|
|
@@ -161,6 +180,20 @@ export class SequencerMetrics {
|
|
|
161
180
|
this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
|
|
162
181
|
Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
|
|
163
182
|
);
|
|
183
|
+
|
|
184
|
+
this.fishermanPendingBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_COUNT);
|
|
185
|
+
|
|
186
|
+
this.fishermanIncludedBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_COUNT);
|
|
187
|
+
|
|
188
|
+
this.fishermanBlockBlobsFull = createUpDownCounterWithDefault(
|
|
189
|
+
this.meter,
|
|
190
|
+
Metrics.FISHERMAN_FEE_ANALYSIS_BLOCK_BLOBS_FULL,
|
|
191
|
+
{
|
|
192
|
+
[Attributes.OK]: [true, false],
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
this.fishermanMaxBlobCapacity = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_MAX_BLOB_CAPACITY);
|
|
164
197
|
}
|
|
165
198
|
|
|
166
199
|
public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
|
|
@@ -243,18 +276,30 @@ export class SequencerMetrics {
|
|
|
243
276
|
});
|
|
244
277
|
}
|
|
245
278
|
|
|
246
|
-
|
|
247
|
-
this.
|
|
279
|
+
recordCheckpointProposalSuccess() {
|
|
280
|
+
this.checkpointProposalSuccess.add(1);
|
|
248
281
|
}
|
|
249
282
|
|
|
250
|
-
|
|
283
|
+
recordCheckpointPrecheckFailed(
|
|
251
284
|
checkType: 'slot_already_taken' | 'rollup_contract_check_failed' | 'slot_mismatch' | 'block_number_mismatch',
|
|
252
285
|
) {
|
|
253
|
-
this.
|
|
254
|
-
|
|
286
|
+
this.checkpointPrecheckFailed.add(1, { [Attributes.ERROR_TYPE]: checkType });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
recordCheckpointProposalFailed(reason?: string) {
|
|
290
|
+
this.checkpointProposalFailed.add(1, {
|
|
291
|
+
...(reason && { [Attributes.ERROR_TYPE]: reason }),
|
|
255
292
|
});
|
|
256
293
|
}
|
|
257
294
|
|
|
295
|
+
/** Records aggregate metrics for a completed checkpoint build. */
|
|
296
|
+
recordCheckpointBuild(durationMs: number, blockCount: number, txCount: number, totalMana: number) {
|
|
297
|
+
this.checkpointBuildDuration.record(Math.ceil(durationMs));
|
|
298
|
+
this.checkpointBlockCount.record(blockCount);
|
|
299
|
+
this.checkpointTxCount.record(txCount);
|
|
300
|
+
this.checkpointTotalMana.record(totalMana);
|
|
301
|
+
}
|
|
302
|
+
|
|
258
303
|
recordSlashingAttempt(actionCount: number) {
|
|
259
304
|
this.slashingAttempts.add(actionCount);
|
|
260
305
|
}
|
|
@@ -281,10 +326,12 @@ export class SequencerMetrics {
|
|
|
281
326
|
|
|
282
327
|
// Record pending block snapshot data (once per strategy for comparison)
|
|
283
328
|
this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
|
|
329
|
+
this.fishermanPendingBlobCount.record(analysis.pendingSnapshot.pendingBlobCount, strategyAttributes);
|
|
284
330
|
|
|
285
331
|
// Record mined block data if available
|
|
286
332
|
if (analysis.minedBlock) {
|
|
287
333
|
this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
|
|
334
|
+
this.fishermanIncludedBlobCount.record(analysis.minedBlock.includedBlobCount, strategyAttributes);
|
|
288
335
|
|
|
289
336
|
// Record actual fees from blob transactions in the mined block
|
|
290
337
|
for (const blobTx of analysis.minedBlock.includedBlobTxs) {
|
|
@@ -318,13 +365,28 @@ export class SequencerMetrics {
|
|
|
318
365
|
if (analysis.analysis) {
|
|
319
366
|
this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
|
|
320
367
|
|
|
368
|
+
// Record whether the block reached 100% blob capacity
|
|
369
|
+
if (analysis.analysis.blockBlobsFull) {
|
|
370
|
+
this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: true });
|
|
371
|
+
} else {
|
|
372
|
+
this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: false });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Record the max blob capacity for this block
|
|
376
|
+
this.fishermanMaxBlobCapacity.record(analysis.analysis.maxBlobCapacity, strategyAttributes);
|
|
377
|
+
|
|
321
378
|
// Record strategy-specific inclusion result
|
|
322
379
|
if (strategyResult.wouldBeIncluded !== undefined) {
|
|
380
|
+
const inclusionAttributes = {
|
|
381
|
+
...strategyAttributes,
|
|
382
|
+
[Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
|
|
383
|
+
};
|
|
384
|
+
|
|
323
385
|
if (strategyResult.wouldBeIncluded) {
|
|
324
|
-
this.fishermanWouldBeIncluded.add(1, { ...
|
|
386
|
+
this.fishermanWouldBeIncluded.add(1, { ...inclusionAttributes, [Attributes.OK]: true });
|
|
325
387
|
} else {
|
|
326
388
|
this.fishermanWouldBeIncluded.add(1, {
|
|
327
|
-
...
|
|
389
|
+
...inclusionAttributes,
|
|
328
390
|
[Attributes.OK]: false,
|
|
329
391
|
...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
|
|
330
392
|
});
|
|
@@ -334,17 +396,29 @@ export class SequencerMetrics {
|
|
|
334
396
|
// Record strategy-specific priority fee delta
|
|
335
397
|
if (strategyResult.priorityFeeDelta !== undefined) {
|
|
336
398
|
const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
|
|
337
|
-
|
|
399
|
+
const deltaAttributes = {
|
|
400
|
+
...strategyAttributes,
|
|
401
|
+
[Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
|
|
402
|
+
};
|
|
403
|
+
this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, deltaAttributes);
|
|
338
404
|
}
|
|
339
405
|
|
|
340
406
|
// Record estimated cost if available
|
|
341
407
|
if (strategyResult.estimatedCostEth !== undefined) {
|
|
342
|
-
|
|
408
|
+
const costAttributes = {
|
|
409
|
+
...strategyAttributes,
|
|
410
|
+
[Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
|
|
411
|
+
};
|
|
412
|
+
this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, costAttributes);
|
|
343
413
|
}
|
|
344
414
|
|
|
345
415
|
// Record estimated overpayment if available
|
|
346
416
|
if (strategyResult.estimatedOverpaymentEth !== undefined) {
|
|
347
|
-
|
|
417
|
+
const overpaymentAttributes = {
|
|
418
|
+
...strategyAttributes,
|
|
419
|
+
[Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
|
|
420
|
+
};
|
|
421
|
+
this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, overpaymentAttributes);
|
|
348
422
|
}
|
|
349
423
|
}
|
|
350
424
|
}
|