@aztec/sequencer-client 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c

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 +562 -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 +23 -11
  36. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  37. package/dest/test/mock_checkpoint_builder.js +50 -7
  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 +197 -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 +92 -28
  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,21 @@ 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
+ });
435
+
436
+ usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
326
437
 
327
438
  // If this is the last block, exit the loop now so we start collecting attestations
328
439
  if (timingInfo.isLastBlock) {
@@ -331,17 +442,17 @@ export class CheckpointProposalJob {
331
442
  blockNumber,
332
443
  blocksBuilt,
333
444
  });
334
- pendingBroadcast = { block, txs: usedTxs };
445
+ blockPendingBroadcast = { block, txs: usedTxs };
335
446
  break;
336
447
  }
337
448
 
338
449
  // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
339
450
  // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
340
451
  if (!this.config.fishermanMode) {
341
- // TODO(palla/mbps): Wire this to the new p2p API once available
342
452
  const proposal = await this.validatorClient.createBlockProposal(
343
- block.header.globalVariables.blockNumber,
344
- (await checkpointBuilder.getCheckpoint()).header,
453
+ block.header,
454
+ block.indexWithinCheckpoint,
455
+ inHash,
345
456
  block.archive.root,
346
457
  usedTxs,
347
458
  this.proposer,
@@ -359,13 +470,11 @@ export class CheckpointProposalJob {
359
470
  blocksBuilt: blocksInCheckpoint.length,
360
471
  });
361
472
 
362
- return {
363
- blocksInCheckpoint,
364
- pendingBroadcast,
365
- };
473
+ return { blocksInCheckpoint, blockPendingBroadcast };
366
474
  }
367
475
 
368
476
  /** Sleeps until it is time to produce the next block in the slot */
477
+ @trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
369
478
  private async waitUntilNextSubslot(nextSubslotStart: number) {
370
479
  this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
371
480
  this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
@@ -373,6 +482,7 @@ export class CheckpointProposalJob {
373
482
  }
374
483
 
375
484
  /** Builds a single block. Called from the main block building loop. */
485
+ @trackSpan('CheckpointProposalJob.buildSingleBlock')
376
486
  private async buildSingleBlock(
377
487
  checkpointBuilder: CheckpointBuilder,
378
488
  opts: {
@@ -382,10 +492,18 @@ export class CheckpointProposalJob {
382
492
  indexWithinCheckpoint: number;
383
493
  buildDeadline: Date | undefined;
384
494
  txHashesAlreadyIncluded: Set<string>;
495
+ remainingBlobFields: number;
385
496
  },
386
- ): Promise<{ block: L2BlockNew; usedTxs: Tx[] } | { error: Error } | undefined> {
387
- const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
388
- opts;
497
+ ): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
498
+ const {
499
+ blockTimestamp,
500
+ forceCreate,
501
+ blockNumber,
502
+ indexWithinCheckpoint,
503
+ buildDeadline,
504
+ txHashesAlreadyIncluded,
505
+ remainingBlobFields,
506
+ } = opts;
389
507
 
390
508
  this.log.verbose(
391
509
  `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
@@ -418,18 +536,31 @@ export class CheckpointProposalJob {
418
536
  { slot: this.slot, blockNumber, indexWithinCheckpoint },
419
537
  );
420
538
  this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
539
+
540
+ // Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
541
+ const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
542
+ const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
543
+
421
544
  const blockBuilderOptions: PublicProcessorLimits = {
422
545
  maxTransactions: this.config.maxTxsPerBlock,
423
546
  maxBlockSize: this.config.maxBlockSizeInBytes,
424
547
  maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
425
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
548
+ maxBlobFields: maxBlobFieldsForTxs,
426
549
  deadline: buildDeadline,
427
550
  };
428
551
 
429
552
  // Actually build the block by executing txs
430
553
  const workTimer = new Timer();
431
- const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs } =
432
- await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
554
+ const {
555
+ publicGas,
556
+ block,
557
+ publicProcessorDuration,
558
+ numTxs,
559
+ blockBuildingTimer,
560
+ usedTxs,
561
+ failedTxs,
562
+ usedTxBlobFields,
563
+ } = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
433
564
  const blockBuildDuration = workTimer.ms();
434
565
 
435
566
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
@@ -473,7 +604,7 @@ export class CheckpointProposalJob {
473
604
  this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
474
605
  this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
475
606
 
476
- return { block, usedTxs };
607
+ return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
477
608
  } catch (err: any) {
478
609
  this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
479
610
  this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
@@ -484,6 +615,7 @@ export class CheckpointProposalJob {
484
615
  }
485
616
 
486
617
  /** Waits until minTxs are available on the pool for building a block. */
618
+ @trackSpan('CheckpointProposalJob.waitForMinTxs')
487
619
  private async waitForMinTxs(opts: {
488
620
  forceCreate?: boolean;
489
621
  blockNumber: BlockNumber;
@@ -524,7 +656,8 @@ export class CheckpointProposalJob {
524
656
  * Waits for enough attestations to be collected via p2p.
525
657
  * This is run after all blocks for the checkpoint have been built.
526
658
  */
527
- private async waitForAttestations(proposal: BlockProposal): Promise<CommitteeAttestationsAndSigners> {
659
+ @trackSpan('CheckpointProposalJob.waitForAttestations')
660
+ private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
528
661
  if (this.config.fishermanMode) {
529
662
  this.log.debug('Skipping attestation collection in fisherman mode');
530
663
  return CommitteeAttestationsAndSigners.empty();
@@ -573,8 +706,7 @@ export class CheckpointProposalJob {
573
706
 
574
707
  // Manipulate the attestations if we've been configured to do so
575
708
  if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
576
- const checkpoint = proposal.payload.header;
577
- return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
709
+ return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
578
710
  }
579
711
 
580
712
  return new CommitteeAttestationsAndSigners(sorted);
@@ -590,7 +722,7 @@ export class CheckpointProposalJob {
590
722
 
591
723
  /** Breaks the attestations before publishing based on attack configs */
592
724
  private manipulateAttestations(
593
- checkpoint: CheckpointHeader,
725
+ slotNumber: SlotNumber,
594
726
  epoch: EpochNumber,
595
727
  seed: bigint,
596
728
  committee: EthAddress[],
@@ -598,7 +730,6 @@ export class CheckpointProposalJob {
598
730
  ) {
599
731
  // Compute the proposer index in the committee, since we dont want to tweak it.
600
732
  // Otherwise, the L1 rollup contract will reject the block outright.
601
- const { slotNumber } = checkpoint;
602
733
  const proposerIndex = Number(
603
734
  this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
604
735
  );
@@ -647,16 +778,23 @@ export class CheckpointProposalJob {
647
778
  }
648
779
 
649
780
  /**
650
- * Placeholder for pushing block to archiver and waiting for sync.
651
- * To be implemented when archiver and world-state support proposed blocks.
781
+ * Adds the proposed block to the archiver so it's available via P2P.
782
+ * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
783
+ * would never receive its own block without this explicit sync.
652
784
  */
653
- private async syncProposedBlockToArchiver(block: L2BlockNew): Promise<void> {
654
- this.log.debug(`Syncing proposed block ${block.number}`, {
785
+ private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
786
+ if (this.config.skipPushProposedBlocksToArchiver !== false) {
787
+ this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
788
+ blockNumber: block.number,
789
+ slot: block.header.globalVariables.slotNumber,
790
+ });
791
+ return;
792
+ }
793
+ this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
655
794
  blockNumber: block.number,
656
795
  slot: block.header.globalVariables.slotNumber,
657
796
  });
658
- // TODO(palla/mbps): Implement actual sync to archiver and world-state
659
- await Promise.resolve();
797
+ await this.blockSink.addBlock(block);
660
798
  }
661
799
 
662
800
  /** Runs fee analysis and logs checkpoint outcome as fisherman */
@@ -685,6 +823,7 @@ export class CheckpointProposalJob {
685
823
  }
686
824
 
687
825
  /** Waits until a specific time within the current slot */
826
+ @trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
688
827
  protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
689
828
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
690
829
  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';