@aztec/sequencer-client 0.0.1-commit.c7c42ec → 0.0.1-commit.d1f2d6c

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.
Files changed (71) hide show
  1. package/dest/client/sequencer-client.d.ts +4 -5
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/config.d.ts +1 -1
  4. package/dest/config.d.ts.map +1 -1
  5. package/dest/config.js +6 -1
  6. package/dest/global_variable_builder/global_builder.d.ts +4 -4
  7. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  8. package/dest/global_variable_builder/global_builder.js +13 -13
  9. package/dest/index.d.ts +2 -3
  10. package/dest/index.d.ts.map +1 -1
  11. package/dest/index.js +1 -2
  12. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  13. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  14. package/dest/publisher/sequencer-publisher-metrics.js +15 -86
  15. package/dest/publisher/sequencer-publisher.d.ts +17 -16
  16. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher.js +442 -49
  18. package/dest/sequencer/checkpoint_proposal_job.d.ts +14 -9
  19. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  20. package/dest/sequencer/checkpoint_proposal_job.js +561 -39
  21. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  22. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_voter.js +34 -10
  24. package/dest/sequencer/index.d.ts +1 -3
  25. package/dest/sequencer/index.d.ts.map +1 -1
  26. package/dest/sequencer/index.js +0 -2
  27. package/dest/sequencer/metrics.d.ts +3 -3
  28. package/dest/sequencer/metrics.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.js +30 -121
  30. package/dest/sequencer/sequencer.d.ts +25 -15
  31. package/dest/sequencer/sequencer.d.ts.map +1 -1
  32. package/dest/sequencer/sequencer.js +486 -42
  33. package/dest/test/index.d.ts +2 -3
  34. package/dest/test/index.d.ts.map +1 -1
  35. package/dest/test/mock_checkpoint_builder.d.ts +19 -10
  36. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  37. package/dest/test/mock_checkpoint_builder.js +32 -3
  38. package/dest/test/utils.d.ts +13 -9
  39. package/dest/test/utils.d.ts.map +1 -1
  40. package/dest/test/utils.js +26 -17
  41. package/package.json +30 -28
  42. package/src/client/sequencer-client.ts +3 -4
  43. package/src/config.ts +5 -0
  44. package/src/global_variable_builder/global_builder.ts +13 -13
  45. package/src/index.ts +1 -9
  46. package/src/publisher/sequencer-publisher-metrics.ts +14 -70
  47. package/src/publisher/sequencer-publisher.ts +84 -73
  48. package/src/sequencer/checkpoint_proposal_job.ts +195 -58
  49. package/src/sequencer/checkpoint_voter.ts +32 -7
  50. package/src/sequencer/index.ts +0 -2
  51. package/src/sequencer/metrics.ts +23 -131
  52. package/src/sequencer/sequencer.ts +124 -41
  53. package/src/test/index.ts +1 -2
  54. package/src/test/mock_checkpoint_builder.ts +70 -22
  55. package/src/test/utils.ts +55 -28
  56. package/dest/sequencer/block_builder.d.ts +0 -26
  57. package/dest/sequencer/block_builder.d.ts.map +0 -1
  58. package/dest/sequencer/block_builder.js +0 -129
  59. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  60. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  61. package/dest/sequencer/checkpoint_builder.js +0 -131
  62. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  63. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  64. package/dest/tx_validator/nullifier_cache.js +0 -24
  65. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  66. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  67. package/dest/tx_validator/tx_validator_factory.js +0 -53
  68. package/src/sequencer/block_builder.ts +0 -217
  69. package/src/sequencer/checkpoint_builder.ts +0 -217
  70. package/src/tx_validator/nullifier_cache.ts +0 -30
  71. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,7 +1,9 @@
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';
4
5
  import { randomInt } from '@aztec/foundation/crypto/random';
6
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
7
  import { EthAddress } from '@aztec/foundation/eth-address';
6
8
  import { Signature } from '@aztec/foundation/eth-signature';
7
9
  import { filter } from '@aztec/foundation/iterator';
@@ -14,7 +16,9 @@ import type { SlasherClientInterface } from '@aztec/slasher';
14
16
  import {
15
17
  CommitteeAttestation,
16
18
  CommitteeAttestationsAndSigners,
17
- L2BlockNew,
19
+ L2Block,
20
+ type L2BlockSink,
21
+ type L2BlockSource,
18
22
  MaliciousCommitteeAttestationsAndSigners,
19
23
  } from '@aztec/stdlib/block';
20
24
  import type { Checkpoint } from '@aztec/stdlib/checkpoint';
@@ -25,18 +29,18 @@ import type {
25
29
  ResolvedSequencerConfig,
26
30
  WorldStateSynchronizer,
27
31
  } from '@aztec/stdlib/interfaces/server';
28
- import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
29
- import type { BlockProposal, BlockProposalOptions } from '@aztec/stdlib/p2p';
32
+ import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
33
+ import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
30
34
  import { orderAttestations } from '@aztec/stdlib/p2p';
31
- import { CheckpointHeader } from '@aztec/stdlib/rollup';
32
35
  import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
33
36
  import { type FailedTx, Tx } from '@aztec/stdlib/tx';
34
37
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
35
- import type { ValidatorClient } from '@aztec/validator-client';
38
+ import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
39
+ import { CheckpointBuilder, type FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
40
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
36
41
 
37
42
  import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
38
- import type { InvalidateBlockRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
39
- import { CheckpointBuilder, type FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
43
+ import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
40
44
  import { CheckpointVoter } from './checkpoint_voter.js';
41
45
  import { SequencerInterruptedError } from './errors.js';
42
46
  import type { SequencerEvents } from './events.js';
@@ -54,8 +58,9 @@ const TXS_POLLING_MS = 500;
54
58
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
55
59
  * the Sequencer once the check for being the proposer for the slot has succeeded.
56
60
  */
57
- export class CheckpointProposalJob {
61
+ export class CheckpointProposalJob implements Traceable {
58
62
  constructor(
63
+ private readonly epoch: EpochNumber,
59
64
  private readonly slot: SlotNumber,
60
65
  private readonly checkpointNumber: CheckpointNumber,
61
66
  private readonly syncedToBlockNumber: BlockNumber,
@@ -63,13 +68,15 @@ export class CheckpointProposalJob {
63
68
  private readonly proposer: EthAddress | undefined,
64
69
  private readonly publisher: SequencerPublisher,
65
70
  private readonly attestorAddress: EthAddress,
66
- private readonly invalidateBlock: InvalidateBlockRequest | undefined,
71
+ private readonly invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
67
72
  private readonly validatorClient: ValidatorClient,
68
73
  private readonly globalsBuilder: GlobalVariableBuilder,
69
74
  private readonly p2pClient: P2P,
70
75
  private readonly worldState: WorldStateSynchronizer,
71
76
  private readonly l1ToL2MessageSource: L1ToL2MessageSource,
77
+ private readonly l2BlockSource: L2BlockSource,
72
78
  private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
79
+ private readonly blockSink: L2BlockSink,
73
80
  private readonly l1Constants: SequencerRollupConstants,
74
81
  protected config: ResolvedSequencerConfig,
75
82
  protected timetable: SequencerTimetable,
@@ -80,12 +87,14 @@ export class CheckpointProposalJob {
80
87
  private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
81
88
  private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
82
89
  protected readonly log: Logger,
90
+ public readonly tracer: Tracer,
83
91
  ) {}
84
92
 
85
93
  /**
86
94
  * Executes the checkpoint proposal job.
87
95
  * Returns the published checkpoint if successful, undefined otherwise.
88
96
  */
97
+ @trackSpan('CheckpointProposalJob.execute')
89
98
  public async execute(): Promise<Checkpoint | undefined> {
90
99
  // Enqueue governance and slashing votes (returns promises that will be awaited later)
91
100
  // In fisherman mode, we simulate slashing but don't actually publish to L1
@@ -132,6 +141,13 @@ export class CheckpointProposalJob {
132
141
  }
133
142
  }
134
143
 
144
+ @trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
145
+ return {
146
+ // nullish operator needed for tests
147
+ [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
148
+ [Attributes.SLOT_NUMBER]: this.slot,
149
+ };
150
+ })
135
151
  private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
136
152
  try {
137
153
  // Get operator configured coinbase and fee recipient for this attestor
@@ -142,9 +158,9 @@ export class CheckpointProposalJob {
142
158
  this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
143
159
  this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
144
160
 
145
- // Enqueues block invalidation (constant for the whole slot)
146
- if (this.invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
147
- this.publisher.enqueueInvalidateBlock(this.invalidateBlock);
161
+ // Enqueues checkpoint invalidation (constant for the whole slot)
162
+ if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
163
+ this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
148
164
  }
149
165
 
150
166
  // Create checkpoint builder for the slot
@@ -154,8 +170,15 @@ export class CheckpointProposalJob {
154
170
  this.slot,
155
171
  );
156
172
 
157
- // Collect L1 to L2 messages for the checkpoint
173
+ // Collect L1 to L2 messages for the checkpoint and compute their hash
158
174
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
175
+ const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
176
+
177
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
178
+ const previousCheckpoints = (await this.l2BlockSource.getCheckpointsForEpoch(this.epoch)).filter(
179
+ c => c.number < this.checkpointNumber,
180
+ );
181
+ const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
159
182
 
160
183
  // Create a long-lived forked world state for the checkpoint builder
161
184
  using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
@@ -165,6 +188,7 @@ export class CheckpointProposalJob {
165
188
  this.checkpointNumber,
166
189
  checkpointGlobalVariables,
167
190
  l1ToL2Messages,
191
+ previousCheckpointOutHashes,
168
192
  fork,
169
193
  );
170
194
 
@@ -174,12 +198,45 @@ export class CheckpointProposalJob {
174
198
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
175
199
  };
176
200
 
177
- // Main loop: build blocks for the checkpoint
178
- const { blocksInCheckpoint, pendingBroadcast } = await this.buildBlocksForCheckpoint(
179
- checkpointBuilder,
180
- checkpointGlobalVariables.timestamp,
181
- blockProposalOptions,
182
- );
201
+ const checkpointProposalOptions: CheckpointProposalOptions = {
202
+ publishFullTxs: !!this.config.publishTxsWithProposals,
203
+ broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
204
+ };
205
+
206
+ let blocksInCheckpoint: L2Block[] = [];
207
+ let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
208
+
209
+ try {
210
+ // Main loop: build blocks for the checkpoint
211
+ const result = await this.buildBlocksForCheckpoint(
212
+ checkpointBuilder,
213
+ checkpointGlobalVariables.timestamp,
214
+ inHash,
215
+ blockProposalOptions,
216
+ );
217
+ blocksInCheckpoint = result.blocksInCheckpoint;
218
+ blockPendingBroadcast = result.blockPendingBroadcast;
219
+ } catch (err) {
220
+ // These errors are expected in HA mode, so we yield and let another HA node handle the slot
221
+ // The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
222
+ // which is normal for block building (may have picked different txs)
223
+ if (err instanceof DutyAlreadySignedError) {
224
+ this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
225
+ slot: this.slot,
226
+ signedByNode: err.signedByNode,
227
+ });
228
+ return undefined;
229
+ }
230
+ if (err instanceof SlashingProtectionError) {
231
+ this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
232
+ slot: this.slot,
233
+ existingMessageHash: err.existingMessageHash,
234
+ attemptedMessageHash: err.attemptedMessageHash,
235
+ });
236
+ return undefined;
237
+ }
238
+ throw err;
239
+ }
183
240
 
184
241
  if (blocksInCheckpoint.length === 0) {
185
242
  this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
@@ -207,26 +264,61 @@ export class CheckpointProposalJob {
207
264
  return checkpoint;
208
265
  }
209
266
 
210
- // TODO(palla/mbps): Wire this to the new p2p API once available, including the pendingBroadcast.block
267
+ // Include the block pending broadcast in the checkpoint proposal if any
268
+ const lastBlock = blockPendingBroadcast && {
269
+ blockHeader: blockPendingBroadcast.block.header,
270
+ indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
271
+ txs: blockPendingBroadcast.txs,
272
+ };
273
+
274
+ // Create the checkpoint proposal and broadcast it
211
275
  const proposal = await this.validatorClient.createCheckpointProposal(
212
276
  checkpoint.header,
213
277
  checkpoint.archive.root,
214
- pendingBroadcast?.txs ?? [],
278
+ lastBlock,
215
279
  this.proposer,
216
- blockProposalOptions,
280
+ checkpointProposalOptions,
217
281
  );
282
+
218
283
  const blockProposedAt = this.dateProvider.now();
219
- await this.p2pClient.broadcastProposal(proposal);
284
+ await this.p2pClient.broadcastCheckpointProposal(proposal);
220
285
 
221
286
  this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
222
287
  const attestations = await this.waitForAttestations(proposal);
223
288
  const blockAttestedAt = this.dateProvider.now();
224
289
 
225
- this.metrics.recordBlockAttestationDelay(blockAttestedAt - blockProposedAt);
290
+ this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
226
291
 
227
292
  // Proposer must sign over the attestations before pushing them to L1
228
293
  const signer = this.proposer ?? this.publisher.getSenderAddress();
229
- const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer);
294
+ let attestationsSignature: Signature;
295
+ try {
296
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
297
+ attestations,
298
+ signer,
299
+ this.slot,
300
+ this.checkpointNumber,
301
+ );
302
+ } catch (err) {
303
+ // We shouldn't really get here since we yield to another HA node
304
+ // as soon as we see these errors when creating block proposals.
305
+ if (err instanceof DutyAlreadySignedError) {
306
+ this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
307
+ slot: this.slot,
308
+ signedByNode: err.signedByNode,
309
+ });
310
+ return undefined;
311
+ }
312
+ if (err instanceof SlashingProtectionError) {
313
+ this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
314
+ slot: this.slot,
315
+ existingMessageHash: err.existingMessageHash,
316
+ attemptedMessageHash: err.attemptedMessageHash,
317
+ });
318
+ return undefined;
319
+ }
320
+ throw err;
321
+ }
230
322
 
231
323
  // Enqueue publishing the checkpoint to L1
232
324
  this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
@@ -235,11 +327,16 @@ export class CheckpointProposalJob {
235
327
  const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
236
328
  await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
237
329
  txTimeoutAt,
238
- forcePendingBlockNumber: this.invalidateBlock?.forcePendingBlockNumber,
330
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
239
331
  });
240
332
 
241
333
  return checkpoint;
242
334
  } catch (err) {
335
+ if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
336
+ // swallow this error. It's already been logged by a function deeper in the stack
337
+ return undefined;
338
+ }
339
+
243
340
  this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
244
341
  return undefined;
245
342
  }
@@ -248,20 +345,25 @@ export class CheckpointProposalJob {
248
345
  /**
249
346
  * Builds blocks for a checkpoint within the current slot.
250
347
  */
348
+ @trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint')
251
349
  private async buildBlocksForCheckpoint(
252
350
  checkpointBuilder: CheckpointBuilder,
253
351
  timestamp: bigint,
352
+ inHash: Fr,
254
353
  blockProposalOptions: BlockProposalOptions,
255
354
  ): Promise<{
256
- blocksInCheckpoint: L2BlockNew[];
257
- pendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined;
355
+ blocksInCheckpoint: L2Block[];
356
+ blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
258
357
  }> {
259
- const blocksInCheckpoint: L2BlockNew[] = [];
358
+ const blocksInCheckpoint: L2Block[] = [];
260
359
  const txHashesAlreadyIncluded = new Set<string>();
261
360
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
262
361
 
362
+ // Remaining blob fields available for blocks (checkpoint end marker already subtracted)
363
+ let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
364
+
263
365
  // Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
264
- let pendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined = undefined;
366
+ let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
265
367
 
266
368
  while (true) {
267
369
  const blocksBuilt = blocksInCheckpoint.length;
@@ -292,6 +394,7 @@ export class CheckpointProposalJob {
292
394
  blockNumber,
293
395
  indexWithinCheckpoint,
294
396
  txHashesAlreadyIncluded,
397
+ remainingBlobFields,
295
398
  });
296
399
 
297
400
  if (!buildResult && timingInfo.isLastBlock) {
@@ -316,13 +419,19 @@ export class CheckpointProposalJob {
316
419
  break;
317
420
  }
318
421
 
319
- const { block, usedTxs } = buildResult;
422
+ const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
320
423
  blocksInCheckpoint.push(block);
321
424
 
425
+ // Update remaining blob fields for the next block
426
+ remainingBlobFields = newRemainingBlobFields;
427
+
322
428
  // Sync the proposed block to the archiver to make it available
323
429
  // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
324
430
  // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
325
- await this.syncProposedBlockToArchiver(block);
431
+ // Fire and forget - don't block the critical path, but log errors
432
+ this.syncProposedBlockToArchiver(block).catch(err => {
433
+ this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
434
+ });
326
435
 
327
436
  // If this is the last block, exit the loop now so we start collecting attestations
328
437
  if (timingInfo.isLastBlock) {
@@ -331,17 +440,17 @@ export class CheckpointProposalJob {
331
440
  blockNumber,
332
441
  blocksBuilt,
333
442
  });
334
- pendingBroadcast = { block, txs: usedTxs };
443
+ blockPendingBroadcast = { block, txs: usedTxs };
335
444
  break;
336
445
  }
337
446
 
338
447
  // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
339
448
  // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
340
449
  if (!this.config.fishermanMode) {
341
- // TODO(palla/mbps): Wire this to the new p2p API once available
342
450
  const proposal = await this.validatorClient.createBlockProposal(
343
- block.header.globalVariables.blockNumber,
344
- (await checkpointBuilder.getCheckpoint()).header,
451
+ block.header,
452
+ block.indexWithinCheckpoint,
453
+ inHash,
345
454
  block.archive.root,
346
455
  usedTxs,
347
456
  this.proposer,
@@ -359,13 +468,11 @@ export class CheckpointProposalJob {
359
468
  blocksBuilt: blocksInCheckpoint.length,
360
469
  });
361
470
 
362
- return {
363
- blocksInCheckpoint,
364
- pendingBroadcast,
365
- };
471
+ return { blocksInCheckpoint, blockPendingBroadcast };
366
472
  }
367
473
 
368
474
  /** Sleeps until it is time to produce the next block in the slot */
475
+ @trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
369
476
  private async waitUntilNextSubslot(nextSubslotStart: number) {
370
477
  this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
371
478
  this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
@@ -373,6 +480,7 @@ export class CheckpointProposalJob {
373
480
  }
374
481
 
375
482
  /** Builds a single block. Called from the main block building loop. */
483
+ @trackSpan('CheckpointProposalJob.buildSingleBlock')
376
484
  private async buildSingleBlock(
377
485
  checkpointBuilder: CheckpointBuilder,
378
486
  opts: {
@@ -382,10 +490,18 @@ export class CheckpointProposalJob {
382
490
  indexWithinCheckpoint: number;
383
491
  buildDeadline: Date | undefined;
384
492
  txHashesAlreadyIncluded: Set<string>;
493
+ remainingBlobFields: number;
385
494
  },
386
- ): Promise<{ block: L2BlockNew; usedTxs: Tx[] } | { error: Error } | undefined> {
387
- const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
388
- opts;
495
+ ): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
496
+ const {
497
+ blockTimestamp,
498
+ forceCreate,
499
+ blockNumber,
500
+ indexWithinCheckpoint,
501
+ buildDeadline,
502
+ txHashesAlreadyIncluded,
503
+ remainingBlobFields,
504
+ } = opts;
389
505
 
390
506
  this.log.verbose(
391
507
  `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
@@ -418,18 +534,31 @@ export class CheckpointProposalJob {
418
534
  { slot: this.slot, blockNumber, indexWithinCheckpoint },
419
535
  );
420
536
  this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
537
+
538
+ // Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
539
+ const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
540
+ const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
541
+
421
542
  const blockBuilderOptions: PublicProcessorLimits = {
422
543
  maxTransactions: this.config.maxTxsPerBlock,
423
544
  maxBlockSize: this.config.maxBlockSizeInBytes,
424
545
  maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
425
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
546
+ maxBlobFields: maxBlobFieldsForTxs,
426
547
  deadline: buildDeadline,
427
548
  };
428
549
 
429
550
  // Actually build the block by executing txs
430
551
  const workTimer = new Timer();
431
- const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs } =
432
- await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
552
+ const {
553
+ publicGas,
554
+ block,
555
+ publicProcessorDuration,
556
+ numTxs,
557
+ blockBuildingTimer,
558
+ usedTxs,
559
+ failedTxs,
560
+ usedTxBlobFields,
561
+ } = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
433
562
  const blockBuildDuration = workTimer.ms();
434
563
 
435
564
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
@@ -473,7 +602,7 @@ export class CheckpointProposalJob {
473
602
  this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
474
603
  this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
475
604
 
476
- return { block, usedTxs };
605
+ return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
477
606
  } catch (err: any) {
478
607
  this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
479
608
  this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
@@ -484,6 +613,7 @@ export class CheckpointProposalJob {
484
613
  }
485
614
 
486
615
  /** Waits until minTxs are available on the pool for building a block. */
616
+ @trackSpan('CheckpointProposalJob.waitForMinTxs')
487
617
  private async waitForMinTxs(opts: {
488
618
  forceCreate?: boolean;
489
619
  blockNumber: BlockNumber;
@@ -524,7 +654,8 @@ export class CheckpointProposalJob {
524
654
  * Waits for enough attestations to be collected via p2p.
525
655
  * This is run after all blocks for the checkpoint have been built.
526
656
  */
527
- private async waitForAttestations(proposal: BlockProposal): Promise<CommitteeAttestationsAndSigners> {
657
+ @trackSpan('CheckpointProposalJob.waitForAttestations')
658
+ private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
528
659
  if (this.config.fishermanMode) {
529
660
  this.log.debug('Skipping attestation collection in fisherman mode');
530
661
  return CommitteeAttestationsAndSigners.empty();
@@ -573,8 +704,7 @@ export class CheckpointProposalJob {
573
704
 
574
705
  // Manipulate the attestations if we've been configured to do so
575
706
  if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
576
- const checkpoint = proposal.payload.header;
577
- return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
707
+ return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
578
708
  }
579
709
 
580
710
  return new CommitteeAttestationsAndSigners(sorted);
@@ -590,7 +720,7 @@ export class CheckpointProposalJob {
590
720
 
591
721
  /** Breaks the attestations before publishing based on attack configs */
592
722
  private manipulateAttestations(
593
- checkpoint: CheckpointHeader,
723
+ slotNumber: SlotNumber,
594
724
  epoch: EpochNumber,
595
725
  seed: bigint,
596
726
  committee: EthAddress[],
@@ -598,7 +728,6 @@ export class CheckpointProposalJob {
598
728
  ) {
599
729
  // Compute the proposer index in the committee, since we dont want to tweak it.
600
730
  // Otherwise, the L1 rollup contract will reject the block outright.
601
- const { slotNumber } = checkpoint;
602
731
  const proposerIndex = Number(
603
732
  this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
604
733
  );
@@ -647,16 +776,23 @@ export class CheckpointProposalJob {
647
776
  }
648
777
 
649
778
  /**
650
- * Placeholder for pushing block to archiver and waiting for sync.
651
- * To be implemented when archiver and world-state support proposed blocks.
779
+ * Adds the proposed block to the archiver so it's available via P2P.
780
+ * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
781
+ * would never receive its own block without this explicit sync.
652
782
  */
653
- private async syncProposedBlockToArchiver(block: L2BlockNew): Promise<void> {
654
- this.log.debug(`Syncing proposed block ${block.number}`, {
783
+ private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
784
+ if (this.config.skipPushProposedBlocksToArchiver !== false) {
785
+ this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
786
+ blockNumber: block.number,
787
+ slot: block.header.globalVariables.slotNumber,
788
+ });
789
+ return;
790
+ }
791
+ this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
655
792
  blockNumber: block.number,
656
793
  slot: block.header.globalVariables.slotNumber,
657
794
  });
658
- // TODO(palla/mbps): Implement actual sync to archiver and world-state
659
- await Promise.resolve();
795
+ await this.blockSink.addBlock(block);
660
796
  }
661
797
 
662
798
  /** Runs fee analysis and logs checkpoint outcome as fisherman */
@@ -685,6 +821,7 @@ export class CheckpointProposalJob {
685
821
  }
686
822
 
687
823
  /** Waits until a specific time within the current slot */
824
+ @trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
688
825
  protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
689
826
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
690
827
  const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
@@ -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 signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
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
- this.signer = (msg: TypedDataDefinition) =>
35
- this.validatorClient.signWithAddress(this.attestorAddress, msg).then(s => s.toString());
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.signer,
82
+ this.governanceSigner,
72
83
  );
73
84
  } catch (err) {
74
- this.log.error(`Error enqueuing governance vote`, err, { slot: this.slot });
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.signer,
116
+ this.slashingSigner,
99
117
  );
100
118
  } catch (err) {
101
- this.log.error(`Error enqueuing slashing vote`, err, { slot: this.slot });
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
  }
@@ -1,5 +1,3 @@
1
- export * from './block_builder.js';
2
- export * from './checkpoint_builder.js';
3
1
  export * from './checkpoint_proposal_job.js';
4
2
  export * from './checkpoint_voter.js';
5
3
  export * from './config.js';