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

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 (72) 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/client/sequencer-client.js +1 -1
  4. package/dest/config.d.ts +1 -1
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +6 -1
  7. package/dest/global_variable_builder/global_builder.d.ts +4 -4
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +13 -13
  10. package/dest/index.d.ts +2 -3
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  14. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  15. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  16. package/dest/publisher/sequencer-publisher.d.ts +17 -16
  17. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher.js +442 -49
  19. package/dest/sequencer/checkpoint_proposal_job.d.ts +15 -10
  20. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  21. package/dest/sequencer/checkpoint_proposal_job.js +568 -41
  22. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  23. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  24. package/dest/sequencer/checkpoint_voter.js +34 -10
  25. package/dest/sequencer/index.d.ts +1 -3
  26. package/dest/sequencer/index.d.ts.map +1 -1
  27. package/dest/sequencer/index.js +0 -2
  28. package/dest/sequencer/metrics.d.ts +4 -4
  29. package/dest/sequencer/metrics.d.ts.map +1 -1
  30. package/dest/sequencer/metrics.js +48 -129
  31. package/dest/sequencer/sequencer.d.ts +25 -15
  32. package/dest/sequencer/sequencer.d.ts.map +1 -1
  33. package/dest/sequencer/sequencer.js +486 -42
  34. package/dest/test/index.d.ts +2 -3
  35. package/dest/test/index.d.ts.map +1 -1
  36. package/dest/test/mock_checkpoint_builder.d.ts +23 -11
  37. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  38. package/dest/test/mock_checkpoint_builder.js +50 -7
  39. package/dest/test/utils.d.ts +13 -9
  40. package/dest/test/utils.d.ts.map +1 -1
  41. package/dest/test/utils.js +26 -17
  42. package/package.json +30 -28
  43. package/src/client/sequencer-client.ts +4 -5
  44. package/src/config.ts +5 -0
  45. package/src/global_variable_builder/global_builder.ts +13 -13
  46. package/src/index.ts +1 -9
  47. package/src/publisher/sequencer-publisher-metrics.ts +17 -69
  48. package/src/publisher/sequencer-publisher.ts +84 -73
  49. package/src/sequencer/checkpoint_proposal_job.ts +206 -62
  50. package/src/sequencer/checkpoint_voter.ts +32 -7
  51. package/src/sequencer/index.ts +0 -2
  52. package/src/sequencer/metrics.ts +48 -138
  53. package/src/sequencer/sequencer.ts +125 -42
  54. package/src/test/index.ts +1 -2
  55. package/src/test/mock_checkpoint_builder.ts +92 -28
  56. package/src/test/utils.ts +55 -28
  57. package/dest/sequencer/block_builder.d.ts +0 -26
  58. package/dest/sequencer/block_builder.d.ts.map +0 -1
  59. package/dest/sequencer/block_builder.js +0 -129
  60. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  61. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  62. package/dest/sequencer/checkpoint_builder.js +0 -131
  63. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  64. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  65. package/dest/tx_validator/nullifier_cache.js +0 -24
  66. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  67. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  68. package/dest/tx_validator/tx_validator_factory.js +0 -53
  69. package/src/sequencer/block_builder.ts +0 -217
  70. package/src/sequencer/checkpoint_builder.ts +0 -217
  71. package/src/tx_validator/nullifier_cache.ts +0 -30
  72. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,11 +1,13 @@
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';
8
- import type { Logger } from '@aztec/foundation/log';
10
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
9
11
  import { sleep, sleepUntil } from '@aztec/foundation/sleep';
10
12
  import { type DateProvider, Timer } from '@aztec/foundation/timer';
11
13
  import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
@@ -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,11 @@ 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 {
62
+ protected readonly log: Logger;
63
+
58
64
  constructor(
65
+ private readonly epoch: EpochNumber,
59
66
  private readonly slot: SlotNumber,
60
67
  private readonly checkpointNumber: CheckpointNumber,
61
68
  private readonly syncedToBlockNumber: BlockNumber,
@@ -63,13 +70,15 @@ export class CheckpointProposalJob {
63
70
  private readonly proposer: EthAddress | undefined,
64
71
  private readonly publisher: SequencerPublisher,
65
72
  private readonly attestorAddress: EthAddress,
66
- private readonly invalidateBlock: InvalidateBlockRequest | undefined,
73
+ private readonly invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
67
74
  private readonly validatorClient: ValidatorClient,
68
75
  private readonly globalsBuilder: GlobalVariableBuilder,
69
76
  private readonly p2pClient: P2P,
70
77
  private readonly worldState: WorldStateSynchronizer,
71
78
  private readonly l1ToL2MessageSource: L1ToL2MessageSource,
79
+ private readonly l2BlockSource: L2BlockSource,
72
80
  private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
81
+ private readonly blockSink: L2BlockSink,
73
82
  private readonly l1Constants: SequencerRollupConstants,
74
83
  protected config: ResolvedSequencerConfig,
75
84
  protected timetable: SequencerTimetable,
@@ -79,13 +88,17 @@ export class CheckpointProposalJob {
79
88
  private readonly metrics: SequencerMetrics,
80
89
  private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
81
90
  private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
82
- protected readonly log: Logger,
83
- ) {}
91
+ public readonly tracer: Tracer,
92
+ bindings?: LoggerBindings,
93
+ ) {
94
+ this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
95
+ }
84
96
 
85
97
  /**
86
98
  * Executes the checkpoint proposal job.
87
99
  * Returns the published checkpoint if successful, undefined otherwise.
88
100
  */
101
+ @trackSpan('CheckpointProposalJob.execute')
89
102
  public async execute(): Promise<Checkpoint | undefined> {
90
103
  // Enqueue governance and slashing votes (returns promises that will be awaited later)
91
104
  // In fisherman mode, we simulate slashing but don't actually publish to L1
@@ -132,6 +145,13 @@ export class CheckpointProposalJob {
132
145
  }
133
146
  }
134
147
 
148
+ @trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
149
+ return {
150
+ // nullish operator needed for tests
151
+ [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
152
+ [Attributes.SLOT_NUMBER]: this.slot,
153
+ };
154
+ })
135
155
  private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
136
156
  try {
137
157
  // Get operator configured coinbase and fee recipient for this attestor
@@ -142,9 +162,9 @@ export class CheckpointProposalJob {
142
162
  this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
143
163
  this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
144
164
 
145
- // Enqueues block invalidation (constant for the whole slot)
146
- if (this.invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
147
- this.publisher.enqueueInvalidateBlock(this.invalidateBlock);
165
+ // Enqueues checkpoint invalidation (constant for the whole slot)
166
+ if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
167
+ this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
148
168
  }
149
169
 
150
170
  // Create checkpoint builder for the slot
@@ -154,8 +174,15 @@ export class CheckpointProposalJob {
154
174
  this.slot,
155
175
  );
156
176
 
157
- // Collect L1 to L2 messages for the checkpoint
177
+ // Collect L1 to L2 messages for the checkpoint and compute their hash
158
178
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
179
+ const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
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());
159
186
 
160
187
  // Create a long-lived forked world state for the checkpoint builder
161
188
  using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
@@ -165,7 +192,9 @@ export class CheckpointProposalJob {
165
192
  this.checkpointNumber,
166
193
  checkpointGlobalVariables,
167
194
  l1ToL2Messages,
195
+ previousCheckpointOutHashes,
168
196
  fork,
197
+ this.log.getBindings(),
169
198
  );
170
199
 
171
200
  // Options for the validator client when creating block and checkpoint proposals
@@ -174,12 +203,45 @@ export class CheckpointProposalJob {
174
203
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
175
204
  };
176
205
 
177
- // Main loop: build blocks for the checkpoint
178
- const { blocksInCheckpoint, pendingBroadcast } = await this.buildBlocksForCheckpoint(
179
- checkpointBuilder,
180
- checkpointGlobalVariables.timestamp,
181
- blockProposalOptions,
182
- );
206
+ const checkpointProposalOptions: CheckpointProposalOptions = {
207
+ publishFullTxs: !!this.config.publishTxsWithProposals,
208
+ broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
209
+ };
210
+
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
+ }
183
245
 
184
246
  if (blocksInCheckpoint.length === 0) {
185
247
  this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
@@ -207,26 +269,61 @@ export class CheckpointProposalJob {
207
269
  return checkpoint;
208
270
  }
209
271
 
210
- // TODO(palla/mbps): Wire this to the new p2p API once available, including the pendingBroadcast.block
272
+ // Include the block pending broadcast in the checkpoint proposal if any
273
+ const lastBlock = blockPendingBroadcast && {
274
+ blockHeader: blockPendingBroadcast.block.header,
275
+ indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
276
+ txs: blockPendingBroadcast.txs,
277
+ };
278
+
279
+ // Create the checkpoint proposal and broadcast it
211
280
  const proposal = await this.validatorClient.createCheckpointProposal(
212
281
  checkpoint.header,
213
282
  checkpoint.archive.root,
214
- pendingBroadcast?.txs ?? [],
283
+ lastBlock,
215
284
  this.proposer,
216
- blockProposalOptions,
285
+ checkpointProposalOptions,
217
286
  );
287
+
218
288
  const blockProposedAt = this.dateProvider.now();
219
- await this.p2pClient.broadcastProposal(proposal);
289
+ await this.p2pClient.broadcastCheckpointProposal(proposal);
220
290
 
221
291
  this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
222
292
  const attestations = await this.waitForAttestations(proposal);
223
293
  const blockAttestedAt = this.dateProvider.now();
224
294
 
225
- this.metrics.recordBlockAttestationDelay(blockAttestedAt - blockProposedAt);
295
+ this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
226
296
 
227
297
  // Proposer must sign over the attestations before pushing them to L1
228
298
  const signer = this.proposer ?? this.publisher.getSenderAddress();
229
- const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer);
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
+ }
230
327
 
231
328
  // Enqueue publishing the checkpoint to L1
232
329
  this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
@@ -235,11 +332,16 @@ export class CheckpointProposalJob {
235
332
  const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
236
333
  await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
237
334
  txTimeoutAt,
238
- forcePendingBlockNumber: this.invalidateBlock?.forcePendingBlockNumber,
335
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
239
336
  });
240
337
 
241
338
  return checkpoint;
242
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
+
243
345
  this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
244
346
  return undefined;
245
347
  }
@@ -248,20 +350,25 @@ export class CheckpointProposalJob {
248
350
  /**
249
351
  * Builds blocks for a checkpoint within the current slot.
250
352
  */
353
+ @trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint')
251
354
  private async buildBlocksForCheckpoint(
252
355
  checkpointBuilder: CheckpointBuilder,
253
356
  timestamp: bigint,
357
+ inHash: Fr,
254
358
  blockProposalOptions: BlockProposalOptions,
255
359
  ): Promise<{
256
- blocksInCheckpoint: L2BlockNew[];
257
- pendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined;
360
+ blocksInCheckpoint: L2Block[];
361
+ blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
258
362
  }> {
259
- const blocksInCheckpoint: L2BlockNew[] = [];
363
+ const blocksInCheckpoint: L2Block[] = [];
260
364
  const txHashesAlreadyIncluded = new Set<string>();
261
365
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
262
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
+
263
370
  // 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;
371
+ let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
265
372
 
266
373
  while (true) {
267
374
  const blocksBuilt = blocksInCheckpoint.length;
@@ -292,6 +399,7 @@ export class CheckpointProposalJob {
292
399
  blockNumber,
293
400
  indexWithinCheckpoint,
294
401
  txHashesAlreadyIncluded,
402
+ remainingBlobFields,
295
403
  });
296
404
 
297
405
  if (!buildResult && timingInfo.isLastBlock) {
@@ -316,13 +424,21 @@ export class CheckpointProposalJob {
316
424
  break;
317
425
  }
318
426
 
319
- const { block, usedTxs } = buildResult;
427
+ const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
320
428
  blocksInCheckpoint.push(block);
321
429
 
430
+ // Update remaining blob fields for the next block
431
+ remainingBlobFields = newRemainingBlobFields;
432
+
322
433
  // Sync the proposed block to the archiver to make it available
323
434
  // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
324
435
  // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
325
- await this.syncProposedBlockToArchiver(block);
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()));
326
442
 
327
443
  // If this is the last block, exit the loop now so we start collecting attestations
328
444
  if (timingInfo.isLastBlock) {
@@ -331,17 +447,17 @@ export class CheckpointProposalJob {
331
447
  blockNumber,
332
448
  blocksBuilt,
333
449
  });
334
- pendingBroadcast = { block, txs: usedTxs };
450
+ blockPendingBroadcast = { block, txs: usedTxs };
335
451
  break;
336
452
  }
337
453
 
338
454
  // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
339
455
  // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
340
456
  if (!this.config.fishermanMode) {
341
- // TODO(palla/mbps): Wire this to the new p2p API once available
342
457
  const proposal = await this.validatorClient.createBlockProposal(
343
- block.header.globalVariables.blockNumber,
344
- (await checkpointBuilder.getCheckpoint()).header,
458
+ block.header,
459
+ block.indexWithinCheckpoint,
460
+ inHash,
345
461
  block.archive.root,
346
462
  usedTxs,
347
463
  this.proposer,
@@ -359,13 +475,11 @@ export class CheckpointProposalJob {
359
475
  blocksBuilt: blocksInCheckpoint.length,
360
476
  });
361
477
 
362
- return {
363
- blocksInCheckpoint,
364
- pendingBroadcast,
365
- };
478
+ return { blocksInCheckpoint, blockPendingBroadcast };
366
479
  }
367
480
 
368
481
  /** Sleeps until it is time to produce the next block in the slot */
482
+ @trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
369
483
  private async waitUntilNextSubslot(nextSubslotStart: number) {
370
484
  this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
371
485
  this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
@@ -373,6 +487,7 @@ export class CheckpointProposalJob {
373
487
  }
374
488
 
375
489
  /** Builds a single block. Called from the main block building loop. */
490
+ @trackSpan('CheckpointProposalJob.buildSingleBlock')
376
491
  private async buildSingleBlock(
377
492
  checkpointBuilder: CheckpointBuilder,
378
493
  opts: {
@@ -382,10 +497,18 @@ export class CheckpointProposalJob {
382
497
  indexWithinCheckpoint: number;
383
498
  buildDeadline: Date | undefined;
384
499
  txHashesAlreadyIncluded: Set<string>;
500
+ remainingBlobFields: number;
385
501
  },
386
- ): Promise<{ block: L2BlockNew; usedTxs: Tx[] } | { error: Error } | undefined> {
387
- const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
388
- opts;
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;
389
512
 
390
513
  this.log.verbose(
391
514
  `Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
@@ -418,18 +541,31 @@ export class CheckpointProposalJob {
418
541
  { slot: this.slot, blockNumber, indexWithinCheckpoint },
419
542
  );
420
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
+
421
549
  const blockBuilderOptions: PublicProcessorLimits = {
422
550
  maxTransactions: this.config.maxTxsPerBlock,
423
551
  maxBlockSize: this.config.maxBlockSizeInBytes,
424
552
  maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
425
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
553
+ maxBlobFields: maxBlobFieldsForTxs,
426
554
  deadline: buildDeadline,
427
555
  };
428
556
 
429
557
  // Actually build the block by executing txs
430
558
  const workTimer = new Timer();
431
- const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs } =
432
- await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
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);
433
569
  const blockBuildDuration = workTimer.ms();
434
570
 
435
571
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
@@ -473,7 +609,7 @@ export class CheckpointProposalJob {
473
609
  this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
474
610
  this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
475
611
 
476
- return { block, usedTxs };
612
+ return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
477
613
  } catch (err: any) {
478
614
  this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
479
615
  this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
@@ -484,6 +620,7 @@ export class CheckpointProposalJob {
484
620
  }
485
621
 
486
622
  /** Waits until minTxs are available on the pool for building a block. */
623
+ @trackSpan('CheckpointProposalJob.waitForMinTxs')
487
624
  private async waitForMinTxs(opts: {
488
625
  forceCreate?: boolean;
489
626
  blockNumber: BlockNumber;
@@ -524,7 +661,8 @@ export class CheckpointProposalJob {
524
661
  * Waits for enough attestations to be collected via p2p.
525
662
  * This is run after all blocks for the checkpoint have been built.
526
663
  */
527
- private async waitForAttestations(proposal: BlockProposal): Promise<CommitteeAttestationsAndSigners> {
664
+ @trackSpan('CheckpointProposalJob.waitForAttestations')
665
+ private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
528
666
  if (this.config.fishermanMode) {
529
667
  this.log.debug('Skipping attestation collection in fisherman mode');
530
668
  return CommitteeAttestationsAndSigners.empty();
@@ -553,7 +691,7 @@ export class CheckpointProposalJob {
553
691
  const attestationTimeAllowed = this.config.enforceTimeTable
554
692
  ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
555
693
  : this.l1Constants.slotDuration;
556
- const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
694
+ const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
557
695
 
558
696
  this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
559
697
 
@@ -573,8 +711,7 @@ export class CheckpointProposalJob {
573
711
 
574
712
  // Manipulate the attestations if we've been configured to do so
575
713
  if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
576
- const checkpoint = proposal.payload.header;
577
- return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
714
+ return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
578
715
  }
579
716
 
580
717
  return new CommitteeAttestationsAndSigners(sorted);
@@ -590,7 +727,7 @@ export class CheckpointProposalJob {
590
727
 
591
728
  /** Breaks the attestations before publishing based on attack configs */
592
729
  private manipulateAttestations(
593
- checkpoint: CheckpointHeader,
730
+ slotNumber: SlotNumber,
594
731
  epoch: EpochNumber,
595
732
  seed: bigint,
596
733
  committee: EthAddress[],
@@ -598,7 +735,6 @@ export class CheckpointProposalJob {
598
735
  ) {
599
736
  // Compute the proposer index in the committee, since we dont want to tweak it.
600
737
  // Otherwise, the L1 rollup contract will reject the block outright.
601
- const { slotNumber } = checkpoint;
602
738
  const proposerIndex = Number(
603
739
  this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
604
740
  );
@@ -647,16 +783,23 @@ export class CheckpointProposalJob {
647
783
  }
648
784
 
649
785
  /**
650
- * Placeholder for pushing block to archiver and waiting for sync.
651
- * To be implemented when archiver and world-state support proposed blocks.
786
+ * Adds the proposed block to the archiver so it's available via P2P.
787
+ * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
788
+ * would never receive its own block without this explicit sync.
652
789
  */
653
- private async syncProposedBlockToArchiver(block: L2BlockNew): Promise<void> {
654
- this.log.debug(`Syncing proposed block ${block.number}`, {
790
+ private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
791
+ if (this.config.skipPushProposedBlocksToArchiver !== false) {
792
+ this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
793
+ blockNumber: block.number,
794
+ slot: block.header.globalVariables.slotNumber,
795
+ });
796
+ return;
797
+ }
798
+ this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
655
799
  blockNumber: block.number,
656
800
  slot: block.header.globalVariables.slotNumber,
657
801
  });
658
- // TODO(palla/mbps): Implement actual sync to archiver and world-state
659
- await Promise.resolve();
802
+ await this.blockSink.addBlock(block);
660
803
  }
661
804
 
662
805
  /** Runs fee analysis and logs checkpoint outcome as fisherman */
@@ -685,6 +828,7 @@ export class CheckpointProposalJob {
685
828
  }
686
829
 
687
830
  /** Waits until a specific time within the current slot */
831
+ @trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
688
832
  protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
689
833
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
690
834
  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';