@aztec/sequencer-client 0.0.1-commit.f146247c → 0.0.1-commit.f224bb98b
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 +8 -4
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +132 -79
- 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 +26 -13
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +41 -40
- 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 +2 -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 +171 -86
- package/src/sequencer/metrics.ts +92 -18
- package/src/sequencer/sequencer.ts +52 -46
- package/src/sequencer/timetable.ts +13 -12
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +60 -46
- package/src/test/utils.ts +5 -2
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
|
}
|
|
@@ -12,9 +12,9 @@ import type { DateProvider } from '@aztec/foundation/timer';
|
|
|
12
12
|
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
13
13
|
import type { P2P } from '@aztec/p2p';
|
|
14
14
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
15
|
-
import type {
|
|
15
|
+
import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
16
16
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
-
import {
|
|
17
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
18
18
|
import {
|
|
19
19
|
type ResolvedSequencerConfig,
|
|
20
20
|
type SequencerConfig,
|
|
@@ -25,7 +25,7 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
|
25
25
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
26
26
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
27
27
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
28
|
-
import { FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
|
|
28
|
+
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
29
29
|
|
|
30
30
|
import EventEmitter from 'node:events';
|
|
31
31
|
|
|
@@ -60,6 +60,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
60
60
|
/** The last slot for which we attempted to perform our voting duties with degraded block production */
|
|
61
61
|
private lastSlotForFallbackVote: SlotNumber | undefined;
|
|
62
62
|
|
|
63
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */
|
|
64
|
+
private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
|
|
65
|
+
|
|
63
66
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
64
67
|
private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
65
68
|
|
|
@@ -72,14 +75,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
72
75
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
|
|
73
76
|
protected timetable!: SequencerTimetable;
|
|
74
77
|
|
|
75
|
-
// This shouldn't be here as this gets re-created each time we build/propose a block.
|
|
76
|
-
// But we have a number of tests that abuse/rely on this class having a permanent publisher.
|
|
77
|
-
// As long as those tests only configure a single publisher they will continue to work.
|
|
78
|
-
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
79
|
-
// for the block proposer.
|
|
80
|
-
// TODO(palla/mbps): Remove this field and fix tests
|
|
81
|
-
protected publisher: SequencerPublisher | undefined;
|
|
82
|
-
|
|
83
78
|
/** Config for the sequencer */
|
|
84
79
|
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
85
80
|
|
|
@@ -115,7 +110,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
115
110
|
/** Updates sequencer config by the defined values and updates the timetable */
|
|
116
111
|
public updateConfig(config: Partial<SequencerConfig>) {
|
|
117
112
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
118
|
-
this.log.info(`Updated sequencer config`, omit(filteredConfig, '
|
|
113
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
119
114
|
this.config = merge(this.config, filteredConfig);
|
|
120
115
|
this.timetable = new SequencerTimetable(
|
|
121
116
|
{
|
|
@@ -131,10 +126,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
131
126
|
);
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
/** Initializes the sequencer (precomputes tables
|
|
135
|
-
public
|
|
129
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */
|
|
130
|
+
public init() {
|
|
136
131
|
getKzg();
|
|
137
|
-
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
/** Starts the sequencer and moves to IDLE state. */
|
|
@@ -153,7 +147,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
153
147
|
public async stop(): Promise<void> {
|
|
154
148
|
this.log.info(`Stopping sequencer`);
|
|
155
149
|
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
156
|
-
this.
|
|
150
|
+
this.publisherFactory.interruptAll();
|
|
157
151
|
await this.runningPromise?.stop();
|
|
158
152
|
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
159
153
|
this.log.info('Stopped sequencer');
|
|
@@ -166,7 +160,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
166
160
|
} catch (err) {
|
|
167
161
|
this.emit('checkpoint-error', { error: err as Error });
|
|
168
162
|
if (err instanceof SequencerTooSlowError) {
|
|
169
|
-
// TODO(palla/mbps): Add missing states
|
|
170
163
|
// Log as warn only if we had to abort halfway through the block proposal
|
|
171
164
|
const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
|
|
172
165
|
err.proposedState,
|
|
@@ -288,8 +281,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
288
281
|
|
|
289
282
|
const logCtx = {
|
|
290
283
|
now,
|
|
291
|
-
|
|
292
|
-
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
284
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
293
285
|
slot,
|
|
294
286
|
slotTs: ts,
|
|
295
287
|
checkpointNumber,
|
|
@@ -307,12 +299,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
307
299
|
}
|
|
308
300
|
|
|
309
301
|
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
310
|
-
if (syncedTo.
|
|
302
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
|
|
311
303
|
this.log.warn(
|
|
312
304
|
`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
313
|
-
{ ...logCtx, block: syncedTo.
|
|
305
|
+
{ ...logCtx, block: syncedTo.blockData.header.toInspect() },
|
|
314
306
|
);
|
|
315
|
-
this.metrics.
|
|
307
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
316
308
|
return undefined;
|
|
317
309
|
}
|
|
318
310
|
|
|
@@ -323,7 +315,6 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
323
315
|
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
324
316
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
325
317
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
326
|
-
this.publisher = publisher;
|
|
327
318
|
|
|
328
319
|
// In fisherman mode, set the actual proposer's address for simulations
|
|
329
320
|
if (this.config.fishermanMode && proposer) {
|
|
@@ -348,7 +339,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
348
339
|
logCtx,
|
|
349
340
|
);
|
|
350
341
|
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
|
|
351
|
-
this.metrics.
|
|
342
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
352
343
|
return undefined;
|
|
353
344
|
}
|
|
354
345
|
|
|
@@ -358,7 +349,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
358
349
|
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
359
350
|
);
|
|
360
351
|
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
361
|
-
this.metrics.
|
|
352
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
362
353
|
return undefined;
|
|
363
354
|
}
|
|
364
355
|
|
|
@@ -368,11 +359,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
368
359
|
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
369
360
|
);
|
|
370
361
|
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
|
|
371
|
-
this.metrics.
|
|
362
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
372
363
|
return undefined;
|
|
373
364
|
}
|
|
374
365
|
|
|
375
366
|
this.lastSlotForCheckpointProposalJob = slot;
|
|
367
|
+
await this.p2pClient.prepareForSlot(slot);
|
|
376
368
|
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
|
|
377
369
|
|
|
378
370
|
// Create and return the checkpoint proposal job
|
|
@@ -429,6 +421,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
429
421
|
);
|
|
430
422
|
}
|
|
431
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Returns the current sequencer state.
|
|
426
|
+
*/
|
|
427
|
+
public getState(): SequencerState {
|
|
428
|
+
return this.state;
|
|
429
|
+
}
|
|
430
|
+
|
|
432
431
|
/**
|
|
433
432
|
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
434
433
|
* @param proposedState - The new state to transition to.
|
|
@@ -475,16 +474,15 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
475
474
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
476
475
|
*/
|
|
477
476
|
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
478
|
-
// Check that the archiver
|
|
477
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
479
478
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
480
479
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
481
|
-
const
|
|
482
|
-
const { slot
|
|
483
|
-
if (
|
|
480
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
481
|
+
const { slot } = args;
|
|
482
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
484
483
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
485
484
|
slot,
|
|
486
|
-
|
|
487
|
-
l1Timestamp,
|
|
485
|
+
syncedL2Slot,
|
|
488
486
|
});
|
|
489
487
|
return undefined;
|
|
490
488
|
}
|
|
@@ -524,24 +522,24 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
524
522
|
checkpointNumber: CheckpointNumber.ZERO,
|
|
525
523
|
blockNumber: BlockNumber.ZERO,
|
|
526
524
|
archive,
|
|
527
|
-
|
|
525
|
+
syncedL2Slot,
|
|
528
526
|
pendingChainValidationStatus,
|
|
529
527
|
};
|
|
530
528
|
}
|
|
531
529
|
|
|
532
|
-
const
|
|
533
|
-
if (!
|
|
530
|
+
const blockData = await this.l2BlockSource.getBlockData(blockNumber);
|
|
531
|
+
if (!blockData) {
|
|
534
532
|
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
535
|
-
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
533
|
+
this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
|
|
536
534
|
return undefined;
|
|
537
535
|
}
|
|
538
536
|
|
|
539
537
|
return {
|
|
540
|
-
|
|
541
|
-
blockNumber:
|
|
542
|
-
checkpointNumber:
|
|
543
|
-
archive:
|
|
544
|
-
|
|
538
|
+
blockData,
|
|
539
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
540
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
541
|
+
archive: blockData.archive.root,
|
|
542
|
+
syncedL2Slot,
|
|
545
543
|
pendingChainValidationStatus,
|
|
546
544
|
};
|
|
547
545
|
}
|
|
@@ -557,7 +555,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
557
555
|
proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
|
|
558
556
|
} catch (e) {
|
|
559
557
|
if (e instanceof NoCommitteeError) {
|
|
560
|
-
this.
|
|
558
|
+
if (this.lastSlotForNoCommitteeWarning !== slot) {
|
|
559
|
+
this.lastSlotForNoCommitteeWarning = slot;
|
|
560
|
+
this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
|
|
561
|
+
}
|
|
561
562
|
return [false, undefined];
|
|
562
563
|
}
|
|
563
564
|
this.log.error(`Error getting proposer for slot ${slot}`, e);
|
|
@@ -717,7 +718,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
717
718
|
syncedTo: SequencerSyncCheckResult,
|
|
718
719
|
currentSlot: SlotNumber,
|
|
719
720
|
): Promise<void> {
|
|
720
|
-
const { pendingChainValidationStatus,
|
|
721
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
721
722
|
if (pendingChainValidationStatus.valid) {
|
|
722
723
|
return;
|
|
723
724
|
}
|
|
@@ -732,7 +733,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
732
733
|
|
|
733
734
|
const logData = {
|
|
734
735
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
735
|
-
|
|
736
|
+
syncedL2Slot,
|
|
736
737
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
737
738
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
738
739
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -860,6 +861,11 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
860
861
|
return this.validatorClient?.getValidatorAddresses();
|
|
861
862
|
}
|
|
862
863
|
|
|
864
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */
|
|
865
|
+
public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
|
|
866
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
867
|
+
}
|
|
868
|
+
|
|
863
869
|
public getConfig() {
|
|
864
870
|
return this.config;
|
|
865
871
|
}
|
|
@@ -870,10 +876,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
870
876
|
}
|
|
871
877
|
|
|
872
878
|
type SequencerSyncCheckResult = {
|
|
873
|
-
|
|
879
|
+
blockData?: BlockData;
|
|
874
880
|
checkpointNumber: CheckpointNumber;
|
|
875
881
|
blockNumber: BlockNumber;
|
|
876
882
|
archive: Fr;
|
|
877
|
-
|
|
883
|
+
syncedL2Slot: SlotNumber;
|
|
878
884
|
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
879
885
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import {
|
|
3
|
+
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
|
+
CHECKPOINT_INITIALIZATION_TIME,
|
|
5
|
+
DEFAULT_P2P_PROPAGATION_TIME,
|
|
6
|
+
MIN_EXECUTION_TIME,
|
|
7
|
+
} from '@aztec/stdlib/timetable';
|
|
2
8
|
|
|
3
|
-
import { DEFAULT_ATTESTATION_PROPAGATION_TIME as DEFAULT_P2P_PROPAGATION_TIME } from '../config.js';
|
|
4
9
|
import { SequencerTooSlowError } from './errors.js';
|
|
5
10
|
import type { SequencerMetrics } from './metrics.js';
|
|
6
11
|
import { SequencerState } from './utils.js';
|
|
7
12
|
|
|
8
|
-
export const MIN_EXECUTION_TIME = 2;
|
|
9
|
-
export const CHECKPOINT_INITIALIZATION_TIME = 1;
|
|
10
|
-
export const CHECKPOINT_ASSEMBLE_TIME = 1;
|
|
11
|
-
|
|
12
13
|
export class SequencerTimetable {
|
|
13
14
|
/**
|
|
14
15
|
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
@@ -79,7 +80,7 @@ export class SequencerTimetable {
|
|
|
79
80
|
enforce: boolean;
|
|
80
81
|
},
|
|
81
82
|
private readonly metrics?: SequencerMetrics,
|
|
82
|
-
private readonly log
|
|
83
|
+
private readonly log?: Logger,
|
|
83
84
|
) {
|
|
84
85
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
85
86
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
@@ -131,7 +132,7 @@ export class SequencerTimetable {
|
|
|
131
132
|
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
132
133
|
this.initializeDeadline = initializeDeadline;
|
|
133
134
|
|
|
134
|
-
this.log
|
|
135
|
+
this.log?.info(
|
|
135
136
|
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
136
137
|
{
|
|
137
138
|
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
@@ -205,7 +206,7 @@ export class SequencerTimetable {
|
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
208
|
-
this.log
|
|
209
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
/**
|
|
@@ -241,7 +242,7 @@ export class SequencerTimetable {
|
|
|
241
242
|
const canStart = available >= this.minExecutionTime;
|
|
242
243
|
const deadline = secondsIntoSlot + available;
|
|
243
244
|
|
|
244
|
-
this.log
|
|
245
|
+
this.log?.verbose(
|
|
245
246
|
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
246
247
|
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
247
248
|
);
|
|
@@ -261,7 +262,7 @@ export class SequencerTimetable {
|
|
|
261
262
|
// Found an available sub-slot! Is this the last one?
|
|
262
263
|
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
263
264
|
|
|
264
|
-
this.log
|
|
265
|
+
this.log?.verbose(
|
|
265
266
|
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
266
267
|
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
267
268
|
);
|
|
@@ -271,7 +272,7 @@ export class SequencerTimetable {
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
// No sub-slots available with enough time
|
|
274
|
-
this.log
|
|
275
|
+
this.log?.verbose(`No time left to start any more blocks`, {
|
|
275
276
|
secondsIntoSlot,
|
|
276
277
|
maxBlocks: this.maxNumberOfBlocks,
|
|
277
278
|
initializationOffset: this.initializationOffset,
|
package/src/sequencer/types.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
|
2
2
|
|
|
3
3
|
export type SequencerRollupConstants = Pick<
|
|
4
4
|
L1RollupConstants,
|
|
5
|
-
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
|
|
5
|
+
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit'
|
|
6
6
|
>;
|
package/src/test/index.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
2
2
|
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
3
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
4
|
import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
|
|
5
5
|
|
|
6
6
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
7
7
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
8
|
-
import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
9
8
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
10
9
|
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
11
10
|
|
|
12
11
|
class TestSequencer_ extends Sequencer {
|
|
13
12
|
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
14
13
|
declare public timetable: SequencerTimetable;
|
|
15
|
-
declare public publisher: SequencerPublisher;
|
|
16
14
|
declare public publisherFactory: SequencerPublisherFactory;
|
|
17
15
|
declare public validatorClient: ValidatorClient;
|
|
18
16
|
declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
@@ -22,7 +20,7 @@ export type TestSequencer = TestSequencer_;
|
|
|
22
20
|
|
|
23
21
|
class TestSequencerClient_ extends SequencerClient {
|
|
24
22
|
declare public sequencer: TestSequencer;
|
|
25
|
-
declare public publisherManager: PublisherManager<
|
|
23
|
+
declare public publisherManager: PublisherManager<L1TxUtils>;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
export type TestSequencerClient = TestSequencerClient_;
|