@aztec/sequencer-client 0.0.1-commit.1142ef1 → 0.0.1-commit.1a99e26c
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.js +1 -1
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -3
- package/dest/global_variable_builder/global_builder.js +2 -2
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- 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/sequencer/checkpoint_proposal_job.d.ts +8 -6
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +97 -17
- package/dest/sequencer/checkpoint_voter.d.ts +3 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -10
- package/dest/sequencer/index.d.ts +1 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -1
- package/dest/sequencer/metrics.d.ts +2 -2
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +27 -17
- package/dest/sequencer/sequencer.d.ts +17 -9
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +67 -11
- package/dest/test/mock_checkpoint_builder.d.ts +17 -13
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +28 -8
- package/dest/test/utils.d.ts +8 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -7
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +1 -1
- package/src/config.ts +1 -3
- package/src/global_variable_builder/global_builder.ts +2 -2
- package/src/index.ts +1 -6
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/sequencer/checkpoint_proposal_job.ts +136 -28
- package/src/sequencer/checkpoint_voter.ts +32 -7
- package/src/sequencer/index.ts +0 -1
- package/src/sequencer/metrics.ts +36 -18
- package/src/sequencer/sequencer.ts +82 -10
- package/src/test/mock_checkpoint_builder.ts +65 -33
- package/src/test/utils.ts +19 -12
- package/dest/sequencer/block_builder.d.ts +0 -26
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -129
- package/src/sequencer/block_builder.ts +0 -216
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
1
2
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
4
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
@@ -6,7 +7,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
6
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
8
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
9
|
import { filter } from '@aztec/foundation/iterator';
|
|
9
|
-
import type
|
|
10
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
10
11
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
11
12
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
12
13
|
import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
|
|
@@ -15,8 +16,9 @@ import type { SlasherClientInterface } from '@aztec/slasher';
|
|
|
15
16
|
import {
|
|
16
17
|
CommitteeAttestation,
|
|
17
18
|
CommitteeAttestationsAndSigners,
|
|
18
|
-
|
|
19
|
+
L2Block,
|
|
19
20
|
type L2BlockSink,
|
|
21
|
+
type L2BlockSource,
|
|
20
22
|
MaliciousCommitteeAttestationsAndSigners,
|
|
21
23
|
} from '@aztec/stdlib/block';
|
|
22
24
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -35,6 +37,7 @@ import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
|
35
37
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
36
38
|
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
37
39
|
import { CheckpointBuilder, type FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
|
|
40
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
38
41
|
|
|
39
42
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
40
43
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
@@ -56,7 +59,10 @@ const TXS_POLLING_MS = 500;
|
|
|
56
59
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
57
60
|
*/
|
|
58
61
|
export class CheckpointProposalJob implements Traceable {
|
|
62
|
+
protected readonly log: Logger;
|
|
63
|
+
|
|
59
64
|
constructor(
|
|
65
|
+
private readonly epoch: EpochNumber,
|
|
60
66
|
private readonly slot: SlotNumber,
|
|
61
67
|
private readonly checkpointNumber: CheckpointNumber,
|
|
62
68
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
@@ -70,6 +76,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
70
76
|
private readonly p2pClient: P2P,
|
|
71
77
|
private readonly worldState: WorldStateSynchronizer,
|
|
72
78
|
private readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
79
|
+
private readonly l2BlockSource: L2BlockSource,
|
|
73
80
|
private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
74
81
|
private readonly blockSink: L2BlockSink,
|
|
75
82
|
private readonly l1Constants: SequencerRollupConstants,
|
|
@@ -81,9 +88,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
81
88
|
private readonly metrics: SequencerMetrics,
|
|
82
89
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
83
90
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
84
|
-
protected readonly log: Logger,
|
|
85
91
|
public readonly tracer: Tracer,
|
|
86
|
-
|
|
92
|
+
bindings?: LoggerBindings,
|
|
93
|
+
) {
|
|
94
|
+
this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
|
|
95
|
+
}
|
|
87
96
|
|
|
88
97
|
/**
|
|
89
98
|
* Executes the checkpoint proposal job.
|
|
@@ -169,6 +178,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
169
178
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
170
179
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
171
180
|
|
|
181
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
182
|
+
const previousCheckpoints = (await this.l2BlockSource.getCheckpointsForEpoch(this.epoch)).filter(
|
|
183
|
+
c => c.number < this.checkpointNumber,
|
|
184
|
+
);
|
|
185
|
+
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
186
|
+
|
|
172
187
|
// Create a long-lived forked world state for the checkpoint builder
|
|
173
188
|
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
174
189
|
|
|
@@ -177,7 +192,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
177
192
|
this.checkpointNumber,
|
|
178
193
|
checkpointGlobalVariables,
|
|
179
194
|
l1ToL2Messages,
|
|
195
|
+
previousCheckpointOutHashes,
|
|
180
196
|
fork,
|
|
197
|
+
this.log.getBindings(),
|
|
181
198
|
);
|
|
182
199
|
|
|
183
200
|
// Options for the validator client when creating block and checkpoint proposals
|
|
@@ -191,13 +208,40 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
191
208
|
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
192
209
|
};
|
|
193
210
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
let blocksInCheckpoint: L2Block[] = [];
|
|
212
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
// Main loop: build blocks for the checkpoint
|
|
216
|
+
const result = await this.buildBlocksForCheckpoint(
|
|
217
|
+
checkpointBuilder,
|
|
218
|
+
checkpointGlobalVariables.timestamp,
|
|
219
|
+
inHash,
|
|
220
|
+
blockProposalOptions,
|
|
221
|
+
);
|
|
222
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
223
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
224
|
+
} catch (err) {
|
|
225
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
226
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
227
|
+
// which is normal for block building (may have picked different txs)
|
|
228
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
229
|
+
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
230
|
+
slot: this.slot,
|
|
231
|
+
signedByNode: err.signedByNode,
|
|
232
|
+
});
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
if (err instanceof SlashingProtectionError) {
|
|
236
|
+
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
237
|
+
slot: this.slot,
|
|
238
|
+
existingMessageHash: err.existingMessageHash,
|
|
239
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
240
|
+
});
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
throw err;
|
|
244
|
+
}
|
|
201
245
|
|
|
202
246
|
if (blocksInCheckpoint.length === 0) {
|
|
203
247
|
this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
|
|
@@ -252,7 +296,34 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
252
296
|
|
|
253
297
|
// Proposer must sign over the attestations before pushing them to L1
|
|
254
298
|
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
255
|
-
|
|
299
|
+
let attestationsSignature: Signature;
|
|
300
|
+
try {
|
|
301
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
302
|
+
attestations,
|
|
303
|
+
signer,
|
|
304
|
+
this.slot,
|
|
305
|
+
this.checkpointNumber,
|
|
306
|
+
);
|
|
307
|
+
} catch (err) {
|
|
308
|
+
// We shouldn't really get here since we yield to another HA node
|
|
309
|
+
// as soon as we see these errors when creating block proposals.
|
|
310
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
311
|
+
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
312
|
+
slot: this.slot,
|
|
313
|
+
signedByNode: err.signedByNode,
|
|
314
|
+
});
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
if (err instanceof SlashingProtectionError) {
|
|
318
|
+
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
319
|
+
slot: this.slot,
|
|
320
|
+
existingMessageHash: err.existingMessageHash,
|
|
321
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
322
|
+
});
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
throw err;
|
|
326
|
+
}
|
|
256
327
|
|
|
257
328
|
// Enqueue publishing the checkpoint to L1
|
|
258
329
|
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
@@ -266,6 +337,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
266
337
|
|
|
267
338
|
return checkpoint;
|
|
268
339
|
} catch (err) {
|
|
340
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
341
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
|
|
269
345
|
this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
|
|
270
346
|
return undefined;
|
|
271
347
|
}
|
|
@@ -281,15 +357,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
281
357
|
inHash: Fr,
|
|
282
358
|
blockProposalOptions: BlockProposalOptions,
|
|
283
359
|
): Promise<{
|
|
284
|
-
blocksInCheckpoint:
|
|
285
|
-
blockPendingBroadcast: { block:
|
|
360
|
+
blocksInCheckpoint: L2Block[];
|
|
361
|
+
blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
|
|
286
362
|
}> {
|
|
287
|
-
const blocksInCheckpoint:
|
|
363
|
+
const blocksInCheckpoint: L2Block[] = [];
|
|
288
364
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
289
365
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
290
366
|
|
|
367
|
+
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
368
|
+
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
369
|
+
|
|
291
370
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
292
|
-
let blockPendingBroadcast: { block:
|
|
371
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
293
372
|
|
|
294
373
|
while (true) {
|
|
295
374
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -320,6 +399,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
320
399
|
blockNumber,
|
|
321
400
|
indexWithinCheckpoint,
|
|
322
401
|
txHashesAlreadyIncluded,
|
|
402
|
+
remainingBlobFields,
|
|
323
403
|
});
|
|
324
404
|
|
|
325
405
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
@@ -344,13 +424,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
344
424
|
break;
|
|
345
425
|
}
|
|
346
426
|
|
|
347
|
-
const { block, usedTxs } = buildResult;
|
|
427
|
+
const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
|
|
348
428
|
blocksInCheckpoint.push(block);
|
|
349
429
|
|
|
430
|
+
// Update remaining blob fields for the next block
|
|
431
|
+
remainingBlobFields = newRemainingBlobFields;
|
|
432
|
+
|
|
350
433
|
// Sync the proposed block to the archiver to make it available
|
|
351
434
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
352
435
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
353
|
-
|
|
436
|
+
// Fire and forget - don't block the critical path, but log errors
|
|
437
|
+
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
438
|
+
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
354
442
|
|
|
355
443
|
// If this is the last block, exit the loop now so we start collecting attestations
|
|
356
444
|
if (timingInfo.isLastBlock) {
|
|
@@ -409,10 +497,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
409
497
|
indexWithinCheckpoint: number;
|
|
410
498
|
buildDeadline: Date | undefined;
|
|
411
499
|
txHashesAlreadyIncluded: Set<string>;
|
|
500
|
+
remainingBlobFields: number;
|
|
412
501
|
},
|
|
413
|
-
): Promise<{ block:
|
|
414
|
-
const {
|
|
415
|
-
|
|
502
|
+
): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
503
|
+
const {
|
|
504
|
+
blockTimestamp,
|
|
505
|
+
forceCreate,
|
|
506
|
+
blockNumber,
|
|
507
|
+
indexWithinCheckpoint,
|
|
508
|
+
buildDeadline,
|
|
509
|
+
txHashesAlreadyIncluded,
|
|
510
|
+
remainingBlobFields,
|
|
511
|
+
} = opts;
|
|
416
512
|
|
|
417
513
|
this.log.verbose(
|
|
418
514
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -445,18 +541,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
445
541
|
{ slot: this.slot, blockNumber, indexWithinCheckpoint },
|
|
446
542
|
);
|
|
447
543
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
544
|
+
|
|
545
|
+
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
546
|
+
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
547
|
+
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
548
|
+
|
|
448
549
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
449
550
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
450
551
|
maxBlockSize: this.config.maxBlockSizeInBytes,
|
|
451
552
|
maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
|
|
452
|
-
maxBlobFields:
|
|
553
|
+
maxBlobFields: maxBlobFieldsForTxs,
|
|
453
554
|
deadline: buildDeadline,
|
|
454
555
|
};
|
|
455
556
|
|
|
456
557
|
// Actually build the block by executing txs
|
|
457
558
|
const workTimer = new Timer();
|
|
458
|
-
const {
|
|
459
|
-
|
|
559
|
+
const {
|
|
560
|
+
publicGas,
|
|
561
|
+
block,
|
|
562
|
+
publicProcessorDuration,
|
|
563
|
+
numTxs,
|
|
564
|
+
blockBuildingTimer,
|
|
565
|
+
usedTxs,
|
|
566
|
+
failedTxs,
|
|
567
|
+
usedTxBlobFields,
|
|
568
|
+
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
460
569
|
const blockBuildDuration = workTimer.ms();
|
|
461
570
|
|
|
462
571
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
@@ -500,7 +609,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
500
609
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
501
610
|
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
502
611
|
|
|
503
|
-
return { block, usedTxs };
|
|
612
|
+
return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
|
|
504
613
|
} catch (err: any) {
|
|
505
614
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
506
615
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -582,7 +691,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
582
691
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
583
692
|
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
|
|
584
693
|
: this.l1Constants.slotDuration;
|
|
585
|
-
const attestationDeadline = new Date(this.
|
|
694
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
586
695
|
|
|
587
696
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
588
697
|
|
|
@@ -678,8 +787,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
678
787
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
679
788
|
* would never receive its own block without this explicit sync.
|
|
680
789
|
*/
|
|
681
|
-
private async syncProposedBlockToArchiver(block:
|
|
682
|
-
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
790
|
+
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
683
791
|
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
684
792
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
685
793
|
blockNumber: block.number,
|
|
@@ -5,6 +5,8 @@ import type { SlasherClientInterface } from '@aztec/slasher';
|
|
|
5
5
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
6
|
import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { ValidatorClient } from '@aztec/validator-client';
|
|
8
|
+
import { DutyAlreadySignedError } from '@aztec/validator-ha-signer/errors';
|
|
9
|
+
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
8
10
|
|
|
9
11
|
import type { TypedDataDefinition } from 'viem';
|
|
10
12
|
|
|
@@ -17,7 +19,8 @@ import type { SequencerRollupConstants } from './types.js';
|
|
|
17
19
|
*/
|
|
18
20
|
export class CheckpointVoter {
|
|
19
21
|
private slotTimestamp: bigint;
|
|
20
|
-
private
|
|
22
|
+
private governanceSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
|
|
23
|
+
private slashingSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
|
|
21
24
|
|
|
22
25
|
constructor(
|
|
23
26
|
private readonly slot: SlotNumber,
|
|
@@ -31,8 +34,16 @@ export class CheckpointVoter {
|
|
|
31
34
|
private readonly log: Logger,
|
|
32
35
|
) {
|
|
33
36
|
this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
|
|
38
|
+
// Create separate signers with appropriate duty contexts for governance and slashing votes
|
|
39
|
+
// These use HA protection to ensure only one node signs per slot/duty
|
|
40
|
+
const governanceContext: SigningContext = { slot: this.slot, dutyType: DutyType.GOVERNANCE_VOTE };
|
|
41
|
+
this.governanceSigner = (msg: TypedDataDefinition) =>
|
|
42
|
+
this.validatorClient.signWithAddress(this.attestorAddress, msg, governanceContext).then(s => s.toString());
|
|
43
|
+
|
|
44
|
+
const slashingContext: SigningContext = { slot: this.slot, dutyType: DutyType.SLASHING_VOTE };
|
|
45
|
+
this.slashingSigner = (msg: TypedDataDefinition) =>
|
|
46
|
+
this.validatorClient.signWithAddress(this.attestorAddress, msg, slashingContext).then(s => s.toString());
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
/**
|
|
@@ -68,10 +79,17 @@ export class CheckpointVoter {
|
|
|
68
79
|
this.slot,
|
|
69
80
|
this.slotTimestamp,
|
|
70
81
|
this.attestorAddress,
|
|
71
|
-
this.
|
|
82
|
+
this.governanceSigner,
|
|
72
83
|
);
|
|
73
84
|
} catch (err) {
|
|
74
|
-
|
|
85
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
86
|
+
this.log.info(`Governance vote already signed by another node`, {
|
|
87
|
+
slot: this.slot,
|
|
88
|
+
signedByNode: err.signedByNode,
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
this.log.error(`Error enqueueing governance vote`, err);
|
|
92
|
+
}
|
|
75
93
|
return false;
|
|
76
94
|
}
|
|
77
95
|
}
|
|
@@ -95,10 +113,17 @@ export class CheckpointVoter {
|
|
|
95
113
|
this.slot,
|
|
96
114
|
this.slotTimestamp,
|
|
97
115
|
this.attestorAddress,
|
|
98
|
-
this.
|
|
116
|
+
this.slashingSigner,
|
|
99
117
|
);
|
|
100
118
|
} catch (err) {
|
|
101
|
-
|
|
119
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
120
|
+
this.log.info(`Slashing vote already signed by another node`, {
|
|
121
|
+
slot: this.slot,
|
|
122
|
+
signedByNode: err.signedByNode,
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
this.log.error(`Error enqueueing slashing vote`, err);
|
|
126
|
+
}
|
|
102
127
|
return false;
|
|
103
128
|
}
|
|
104
129
|
}
|
package/src/sequencer/index.ts
CHANGED
package/src/sequencer/metrics.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type TelemetryClient,
|
|
12
12
|
type Tracer,
|
|
13
13
|
type UpDownCounter,
|
|
14
|
+
createUpDownCounterWithDefault,
|
|
14
15
|
} from '@aztec/telemetry-client';
|
|
15
16
|
|
|
16
17
|
import { type Hex, formatUnits } from 'viem';
|
|
@@ -67,7 +68,9 @@ export class SequencerMetrics {
|
|
|
67
68
|
this.meter = client.getMeter(name);
|
|
68
69
|
this.tracer = client.getTracer(name);
|
|
69
70
|
|
|
70
|
-
this.blockCounter = this.meter
|
|
71
|
+
this.blockCounter = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_BLOCK_COUNT, {
|
|
72
|
+
[Attributes.STATUS]: ['failed', 'built'],
|
|
73
|
+
});
|
|
71
74
|
|
|
72
75
|
this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION);
|
|
73
76
|
|
|
@@ -77,23 +80,15 @@ export class SequencerMetrics {
|
|
|
77
80
|
|
|
78
81
|
this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
|
|
79
82
|
|
|
80
|
-
// Init gauges and counters
|
|
81
|
-
this.blockCounter.add(0, {
|
|
82
|
-
[Attributes.STATUS]: 'failed',
|
|
83
|
-
});
|
|
84
|
-
this.blockCounter.add(0, {
|
|
85
|
-
[Attributes.STATUS]: 'built',
|
|
86
|
-
});
|
|
87
|
-
|
|
88
83
|
this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS);
|
|
89
84
|
|
|
90
|
-
this.slots = this.meter
|
|
85
|
+
this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
|
|
91
86
|
|
|
92
87
|
/**
|
|
93
88
|
* NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
|
|
94
89
|
* Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
|
|
95
90
|
*/
|
|
96
|
-
this.filledSlots = this.meter
|
|
91
|
+
this.filledSlots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_FILLED_SLOT_COUNT);
|
|
97
92
|
|
|
98
93
|
this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION);
|
|
99
94
|
|
|
@@ -103,20 +98,41 @@ export class SequencerMetrics {
|
|
|
103
98
|
|
|
104
99
|
this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT);
|
|
105
100
|
|
|
106
|
-
this.blockProposalFailed =
|
|
101
|
+
this.blockProposalFailed = createUpDownCounterWithDefault(
|
|
102
|
+
this.meter,
|
|
103
|
+
Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT,
|
|
104
|
+
);
|
|
107
105
|
|
|
108
|
-
this.blockProposalSuccess =
|
|
106
|
+
this.blockProposalSuccess = createUpDownCounterWithDefault(
|
|
107
|
+
this.meter,
|
|
108
|
+
Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT,
|
|
109
|
+
);
|
|
109
110
|
|
|
110
|
-
this.checkpointSuccess = this.meter
|
|
111
|
+
this.checkpointSuccess = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
|
|
111
112
|
|
|
112
|
-
this.blockProposalPrecheckFailed =
|
|
113
|
+
this.blockProposalPrecheckFailed = createUpDownCounterWithDefault(
|
|
114
|
+
this.meter,
|
|
113
115
|
Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
|
|
116
|
+
{
|
|
117
|
+
[Attributes.ERROR_TYPE]: [
|
|
118
|
+
'slot_already_taken',
|
|
119
|
+
'rollup_contract_check_failed',
|
|
120
|
+
'slot_mismatch',
|
|
121
|
+
'block_number_mismatch',
|
|
122
|
+
],
|
|
123
|
+
},
|
|
114
124
|
);
|
|
115
125
|
|
|
116
|
-
this.slashingAttempts = this.meter
|
|
126
|
+
this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
|
|
117
127
|
|
|
118
128
|
// Fisherman fee analysis metrics
|
|
119
|
-
this.fishermanWouldBeIncluded =
|
|
129
|
+
this.fishermanWouldBeIncluded = createUpDownCounterWithDefault(
|
|
130
|
+
this.meter,
|
|
131
|
+
Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED,
|
|
132
|
+
{
|
|
133
|
+
[Attributes.OK]: [true, false],
|
|
134
|
+
},
|
|
135
|
+
);
|
|
120
136
|
|
|
121
137
|
this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK);
|
|
122
138
|
|
|
@@ -231,7 +247,9 @@ export class SequencerMetrics {
|
|
|
231
247
|
this.blockProposalSuccess.add(1);
|
|
232
248
|
}
|
|
233
249
|
|
|
234
|
-
recordBlockProposalPrecheckFailed(
|
|
250
|
+
recordBlockProposalPrecheckFailed(
|
|
251
|
+
checkType: 'slot_already_taken' | 'rollup_contract_check_failed' | 'slot_mismatch' | 'block_number_mismatch',
|
|
252
|
+
) {
|
|
235
253
|
this.blockProposalPrecheckFailed.add(1, {
|
|
236
254
|
[Attributes.ERROR_TYPE]: checkType,
|
|
237
255
|
});
|