@aztec/sequencer-client 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8

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 (89) hide show
  1. package/dest/client/sequencer-client.d.ts +2 -1
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +8 -8
  4. package/dest/config.d.ts +3 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +10 -12
  7. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  8. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  9. package/dest/global_variable_builder/fee_predictor.js +128 -0
  10. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  12. package/dest/global_variable_builder/fee_provider.js +58 -0
  13. package/dest/global_variable_builder/global_builder.d.ts +3 -8
  14. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  15. package/dest/global_variable_builder/global_builder.js +4 -39
  16. package/dest/global_variable_builder/index.d.ts +3 -1
  17. package/dest/global_variable_builder/index.d.ts.map +1 -1
  18. package/dest/global_variable_builder/index.js +2 -0
  19. package/dest/publisher/config.d.ts +17 -1
  20. package/dest/publisher/config.d.ts.map +1 -1
  21. package/dest/publisher/config.js +25 -5
  22. package/dest/publisher/index.d.ts +2 -1
  23. package/dest/publisher/index.d.ts.map +1 -1
  24. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  25. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  26. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  27. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  28. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  30. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  31. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  32. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  33. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  34. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  35. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  36. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  37. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher-factory.js +16 -3
  39. package/dest/publisher/sequencer-publisher.d.ts +52 -41
  40. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  41. package/dest/publisher/sequencer-publisher.js +345 -101
  42. package/dest/sequencer/chain_state_overrides.d.ts +25 -0
  43. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  44. package/dest/sequencer/chain_state_overrides.js +39 -0
  45. package/dest/sequencer/checkpoint_proposal_job.d.ts +24 -7
  46. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  47. package/dest/sequencer/checkpoint_proposal_job.js +277 -169
  48. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  49. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  50. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  51. package/dest/sequencer/events.d.ts +2 -1
  52. package/dest/sequencer/events.d.ts.map +1 -1
  53. package/dest/sequencer/metrics.d.ts +9 -10
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +23 -20
  56. package/dest/sequencer/sequencer.d.ts +17 -5
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +120 -58
  59. package/dest/sequencer/timetable.d.ts +14 -1
  60. package/dest/sequencer/timetable.d.ts.map +1 -1
  61. package/dest/sequencer/timetable.js +45 -36
  62. package/dest/test/mock_checkpoint_builder.d.ts +1 -1
  63. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  64. package/dest/test/mock_checkpoint_builder.js +0 -2
  65. package/package.json +27 -28
  66. package/src/client/sequencer-client.ts +8 -14
  67. package/src/config.ts +12 -11
  68. package/src/global_variable_builder/README.md +44 -0
  69. package/src/global_variable_builder/fee_predictor.ts +172 -0
  70. package/src/global_variable_builder/fee_provider.ts +75 -0
  71. package/src/global_variable_builder/global_builder.ts +8 -43
  72. package/src/global_variable_builder/index.ts +2 -0
  73. package/src/publisher/config.ts +47 -4
  74. package/src/publisher/index.ts +3 -0
  75. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  76. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  77. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  78. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  79. package/src/publisher/sequencer-publisher-factory.ts +18 -6
  80. package/src/publisher/sequencer-publisher.ts +389 -140
  81. package/src/sequencer/README.md +83 -13
  82. package/src/sequencer/chain_state_overrides.ts +87 -0
  83. package/src/sequencer/checkpoint_proposal_job.ts +338 -177
  84. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  85. package/src/sequencer/events.ts +1 -1
  86. package/src/sequencer/metrics.ts +29 -25
  87. package/src/sequencer/sequencer.ts +177 -63
  88. package/src/sequencer/timetable.ts +57 -45
  89. package/src/test/mock_checkpoint_builder.ts +0 -2
@@ -446,7 +446,7 @@ import { Timer } from '@aztec/foundation/timer';
446
446
  import { isErrorClass, unfreeze } from '@aztec/foundation/types';
447
447
  import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
448
448
  import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
449
- import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
449
+ import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
450
450
  import { Gas } from '@aztec/stdlib/gas';
451
451
  import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
452
452
  import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
@@ -454,6 +454,7 @@ import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
454
454
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
455
455
  import { Attributes, trackSpan } from '@aztec/telemetry-client';
456
456
  import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
457
+ import { buildPipelinedParentSimulationOverridesPlan, buildSubmissionSimulationOverridesPlan } from './chain_state_overrides.js';
457
458
  import { CheckpointVoter } from './checkpoint_voter.js';
458
459
  import { SequencerInterruptedError } from './errors.js';
459
460
  import { SequencerState } from './utils.js';
@@ -462,7 +463,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
462
463
  return {
463
464
  // nullish operator needed for tests
464
465
  [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
465
- [Attributes.SLOT_NUMBER]: this.slot
466
+ [Attributes.SLOT_NUMBER]: this.targetSlot
466
467
  };
467
468
  }), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
468
469
  /**
@@ -471,8 +472,9 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
471
472
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
472
473
  * the Sequencer once the check for being the proposer for the slot has succeeded.
473
474
  */ export class CheckpointProposalJob {
474
- epoch;
475
- slot;
475
+ slotNow;
476
+ targetSlot;
477
+ targetEpoch;
476
478
  checkpointNumber;
477
479
  syncedToBlockNumber;
478
480
  proposer;
@@ -494,9 +496,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
494
496
  epochCache;
495
497
  dateProvider;
496
498
  metrics;
499
+ checkpointMetrics;
497
500
  eventEmitter;
498
501
  setStateFn;
499
502
  tracer;
503
+ proposedCheckpointData;
500
504
  static{
501
505
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
502
506
  [
@@ -542,10 +546,13 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
542
546
  ], []));
543
547
  }
544
548
  log;
545
- constructor(epoch, slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
546
- proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, tracer, bindings){
547
- this.epoch = epoch;
548
- this.slot = slot;
549
+ /** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
550
+ /** Pipelined parent chain state used while building and later submitting this checkpoint. */ pipelinedParentSimulationOverridesPlan;
551
+ constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
552
+ proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
553
+ this.slotNow = slotNow;
554
+ this.targetSlot = targetSlot;
555
+ this.targetEpoch = targetEpoch;
549
556
  this.checkpointNumber = checkpointNumber;
550
557
  this.syncedToBlockNumber = syncedToBlockNumber;
551
558
  this.proposer = proposer;
@@ -567,53 +574,142 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
567
574
  this.epochCache = epochCache;
568
575
  this.dateProvider = dateProvider;
569
576
  this.metrics = metrics;
577
+ this.checkpointMetrics = checkpointMetrics;
570
578
  this.eventEmitter = eventEmitter;
571
579
  this.setStateFn = setStateFn;
572
580
  this.tracer = tracer;
581
+ this.proposedCheckpointData = proposedCheckpointData;
573
582
  _initProto(this);
574
583
  this.log = createLogger('sequencer:checkpoint-proposal', {
575
584
  ...bindings,
576
- instanceId: `slot-${slot}`
585
+ instanceId: `slot-${this.slotNow}`
577
586
  });
578
587
  }
588
+ /** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
589
+ this.log.info('Awaiting pending L1 payload submission');
590
+ await this.pendingL1Submission;
591
+ }
579
592
  /**
580
593
  * Executes the checkpoint proposal job.
581
- * Returns the published checkpoint if successful, undefined otherwise.
594
+ * Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
595
+ * Attestation collection, signing, and L1 submission are backgrounded so the
596
+ * work loop can return to IDLE immediately for consecutive slot proposals.
597
+ * Returns the built checkpoint if successful, undefined otherwise.
582
598
  */ async execute() {
583
599
  // Enqueue governance and slashing votes (returns promises that will be awaited later)
584
600
  // In fisherman mode, we simulate slashing but don't actually publish to L1
585
601
  // These are constant for the whole slot, so we only enqueue them once
586
- const votesPromises = new CheckpointVoter(this.slot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
587
- // Build and propose the checkpoint. This will enqueue the request on the publisher if a checkpoint is built.
588
- const checkpoint = await this.proposeCheckpoint();
589
- // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
590
- await Promise.all(votesPromises);
591
- if (checkpoint) {
592
- this.metrics.recordCheckpointProposalSuccess();
602
+ const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
603
+ // Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
604
+ // Returns after broadcast — attestation collection is deferred.
605
+ const broadcast = await this.proposeCheckpoint();
606
+ if (!broadcast) {
607
+ await Promise.all(votesPromises);
608
+ // Still submit votes even without a checkpoint
609
+ if (!this.config.fishermanMode) {
610
+ this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(()=>{});
611
+ }
612
+ return undefined;
593
613
  }
614
+ const { checkpoint } = broadcast;
615
+ this.metrics.recordCheckpointProposalSuccess();
594
616
  // Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
595
617
  if (this.config.fishermanMode) {
596
618
  await this.handleCheckpointEndAsFisherman(checkpoint);
597
- return;
619
+ return checkpoint;
598
620
  }
599
- // Then send everything to L1
600
- const l1Response = await this.publisher.sendRequests();
601
- const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
602
- if (proposedAction) {
603
- this.eventEmitter.emit('checkpoint-published', {
604
- checkpoint: this.checkpointNumber,
605
- slot: this.slot
621
+ // Background the attestation signing → L1 pipeline so the work loop is unblocked
622
+ this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
623
+ // Return the built checkpoint immediately — the work loop is now unblocked
624
+ return checkpoint;
625
+ }
626
+ /**
627
+ * Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
628
+ * Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
629
+ */ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
630
+ const { checkpoint, proposal, blockProposedAt } = broadcast;
631
+ try {
632
+ await Promise.all(votesPromises);
633
+ this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
634
+ const attestations = await this.waitForAttestations(proposal);
635
+ this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
636
+ // Proposer must sign over the attestations before pushing them to L1
637
+ const signer = this.proposer ?? this.publisher.getSenderAddress();
638
+ let attestationsSignature;
639
+ try {
640
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
641
+ } catch (err) {
642
+ if (this.handleHASigningError(err, 'Attestations signature')) {
643
+ return;
644
+ }
645
+ throw err;
646
+ }
647
+ // Enqueue the checkpoint for L1 submission
648
+ await this.enqueueCheckpointForSubmission({
649
+ checkpoint,
650
+ attestations,
651
+ attestationsSignature
606
652
  });
607
- const coinbase = checkpoint?.header.coinbase;
608
- await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
609
- return checkpoint;
610
- } else if (checkpoint) {
653
+ // Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
654
+ const submitAfter = this.epochCache.isProposerPipeliningEnabled() ? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000) : new Date(this.dateProvider.now());
655
+ const l1Response = await this.publisher.sendRequestsAt(submitAfter);
656
+ const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
657
+ if (proposedAction) {
658
+ this.eventEmitter.emit('checkpoint-published', {
659
+ checkpoint: this.checkpointNumber,
660
+ slot: this.targetSlot
661
+ });
662
+ const coinbase = checkpoint.header.coinbase;
663
+ await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
664
+ } else {
665
+ this.eventEmitter.emit('checkpoint-publish-failed', {
666
+ ...l1Response,
667
+ slot: this.targetSlot
668
+ });
669
+ if (this.epochCache.isProposerPipeliningEnabled()) {
670
+ this.metrics.recordPipelineDiscard();
671
+ }
672
+ }
673
+ } catch (err) {
674
+ if (err instanceof SequencerInterruptedError) {
675
+ return;
676
+ }
677
+ this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
611
678
  this.eventEmitter.emit('checkpoint-publish-failed', {
612
- ...l1Response,
613
- slot: this.slot
679
+ slot: this.targetSlot
614
680
  });
615
- return undefined;
681
+ if (this.epochCache.isProposerPipeliningEnabled()) {
682
+ this.metrics.recordPipelineDiscard();
683
+ }
684
+ }
685
+ }
686
+ /** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
687
+ const { checkpoint, attestations, attestationsSignature } = result;
688
+ this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
689
+ const aztecSlotDuration = this.l1Constants.slotDuration;
690
+ const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
691
+ const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
692
+ // If we have been configured to potentially skip publishing checkpoint then roll the dice here
693
+ if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
694
+ const roll = Math.max(0, randomInt(100));
695
+ if (roll < this.config.skipPublishingCheckpointsPercent) {
696
+ this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
697
+ return;
698
+ }
616
699
  }
700
+ const isPipelining = this.epochCache.isProposerPipeliningEnabled();
701
+ const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
702
+ pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
703
+ invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
704
+ lastArchiveRoot: checkpoint.header.lastArchiveRoot,
705
+ pipeliningEnabled: isPipelining
706
+ });
707
+ await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
708
+ txTimeoutAt,
709
+ ...submissionSimulationOverridesPlan ? {
710
+ simulationOverridesPlan: submissionSimulationOverridesPlan
711
+ } : {}
712
+ });
617
713
  }
618
714
  async proposeCheckpoint() {
619
715
  try {
@@ -623,23 +719,48 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
623
719
  hasError: false
624
720
  };
625
721
  try {
722
+ const now = this.dateProvider.now();
723
+ if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
724
+ // Measure against the wall-clock slot whose build window we are currently using.
725
+ // In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
726
+ // target-slot boundary a full slot away from the actual build start time.
727
+ const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
728
+ this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
729
+ }
730
+ this.checkpointMetrics.startCheckpointTiming(now);
626
731
  // Get operator configured coinbase and fee recipient for this attestor
627
732
  const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
628
733
  const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
629
734
  // Start the checkpoint
630
- this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
631
- this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
735
+ this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
736
+ this.log.info(`Starting checkpoint proposal`, {
737
+ buildSlot: this.slotNow,
738
+ submissionSlot: this.targetSlot,
739
+ pipelining: this.epochCache.isProposerPipeliningEnabled(),
740
+ proposer: this.proposer?.toString(),
741
+ coinbase: coinbase.toString()
742
+ });
743
+ this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
632
744
  // Enqueues checkpoint invalidation (constant for the whole slot)
633
745
  if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
634
746
  this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
635
747
  }
636
- // Create checkpoint builder for the slot
637
- const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.slot);
748
+ // Create checkpoint builder for the slot.
749
+ // When pipelining, force the proposed checkpoint number and fee header to our parent so the
750
+ // fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
751
+ const isPipelining = this.epochCache.isProposerPipeliningEnabled();
752
+ this.pipelinedParentSimulationOverridesPlan = isPipelining ? await buildPipelinedParentSimulationOverridesPlan({
753
+ checkpointNumber: this.checkpointNumber,
754
+ proposedCheckpointData: this.proposedCheckpointData,
755
+ rollup: this.publisher.rollupContract,
756
+ log: this.log
757
+ }) : undefined;
758
+ const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.pipelinedParentSimulationOverridesPlan);
638
759
  // Collect L1 to L2 messages for the checkpoint and compute their hash
639
760
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
640
761
  const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
641
762
  // Collect the out hashes of all the checkpoints before this one in the same epoch
642
- const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
763
+ const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
643
764
  // Get the fee asset price modifier from the oracle
644
765
  const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
645
766
  const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
@@ -674,18 +795,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
674
795
  throw err;
675
796
  }
676
797
  if (blocksInCheckpoint.length === 0) {
677
- this.log.warn(`No blocks were built for slot ${this.slot}`, {
678
- slot: this.slot
798
+ this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
799
+ slot: this.targetSlot
679
800
  });
680
801
  this.eventEmitter.emit('checkpoint-empty', {
681
- slot: this.slot
802
+ slot: this.targetSlot
682
803
  });
683
804
  return undefined;
684
805
  }
685
806
  const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
686
807
  if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
687
808
  this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
688
- slot: this.slot,
809
+ slot: this.targetSlot,
689
810
  blocksBuilt: blocksInCheckpoint.length,
690
811
  minBlocksForCheckpoint
691
812
  });
@@ -693,7 +814,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
693
814
  }
694
815
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
695
816
  // broadcasted yet, and wait to collect the committee attestations.
696
- this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
817
+ this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
697
818
  const checkpoint = await checkpointBuilder.completeCheckpoint();
698
819
  // Final validation: per-block limits are only checked if the operator set them explicitly.
699
820
  // Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
@@ -706,68 +827,39 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
706
827
  maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
707
828
  });
708
829
  } catch (err) {
709
- this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
830
+ this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
710
831
  checkpoint: checkpoint.header.toInspect()
711
832
  });
712
833
  return undefined;
713
834
  }
714
835
  // Record checkpoint-level build metrics
715
- this.metrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
716
- // Do not collect attestations nor publish to L1 in fisherman mode
836
+ this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
837
+ // In fisherman mode, return the checkpoint without broadcasting or collecting attestations
717
838
  if (this.config.fishermanMode) {
718
- this.log.info(`Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
719
- slot: this.slot,
839
+ this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
840
+ slot: this.targetSlot,
720
841
  checkpoint: checkpoint.header.toInspect(),
721
842
  blocksBuilt: blocksInCheckpoint.length
722
843
  });
723
844
  this.metrics.recordCheckpointSuccess();
724
- return checkpoint;
845
+ // Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
846
+ return {
847
+ checkpoint,
848
+ proposal: undefined,
849
+ blockProposedAt: this.dateProvider.now()
850
+ };
725
851
  }
726
- // Include the block pending broadcast in the checkpoint proposal if any
727
- const lastBlock = blockPendingBroadcast && {
728
- blockHeader: blockPendingBroadcast.block.header,
729
- indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
730
- txs: blockPendingBroadcast.txs
731
- };
732
852
  // Create the checkpoint proposal and broadcast it
733
- const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, feeAssetPriceModifier, lastBlock, this.proposer, checkpointProposalOptions);
853
+ const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
734
854
  const blockProposedAt = this.dateProvider.now();
735
855
  await this.p2pClient.broadcastCheckpointProposal(proposal);
736
- this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
737
- const attestations = await this.waitForAttestations(proposal);
738
- const blockAttestedAt = this.dateProvider.now();
739
- this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
740
- // Proposer must sign over the attestations before pushing them to L1
741
- const signer = this.proposer ?? this.publisher.getSenderAddress();
742
- let attestationsSignature;
743
- try {
744
- attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
745
- } catch (err) {
746
- // We shouldn't really get here since we yield to another HA node
747
- // as soon as we see these errors when creating block or checkpoint proposals.
748
- if (this.handleHASigningError(err, 'Attestations signature')) {
749
- return undefined;
750
- }
751
- throw err;
752
- }
753
- // Enqueue publishing the checkpoint to L1
754
- this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
755
- const aztecSlotDuration = this.l1Constants.slotDuration;
756
- const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
757
- const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
758
- // If we have been configured to potentially skip publishing checkpoint then roll the dice here
759
- if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
760
- const result = Math.max(0, randomInt(100));
761
- if (result < this.config.skipPublishingCheckpointsPercent) {
762
- this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`);
763
- return checkpoint;
764
- }
765
- }
766
- await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
767
- txTimeoutAt,
768
- forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
769
- });
770
- return checkpoint;
856
+ this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
857
+ // Return immediately after broadcast — attestation collection happens in the background
858
+ return {
859
+ checkpoint,
860
+ proposal,
861
+ blockProposedAt
862
+ };
771
863
  } catch (e) {
772
864
  env.error = e;
773
865
  env.hasError = true;
@@ -780,7 +872,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
780
872
  // swallow this error. It's already been logged by a function deeper in the stack
781
873
  return undefined;
782
874
  }
783
- this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
875
+ this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
784
876
  return undefined;
785
877
  }
786
878
  }
@@ -790,7 +882,6 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
790
882
  const blocksInCheckpoint = [];
791
883
  const txHashesAlreadyIncluded = new Set();
792
884
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
793
- const slot = this.slot;
794
885
  // Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
795
886
  let blockPendingBroadcast = undefined;
796
887
  while(true){
@@ -801,7 +892,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
801
892
  const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
802
893
  if (!timingInfo.canStart) {
803
894
  this.log.debug(`Not enough time left in slot to start another block`, {
804
- slot,
895
+ slot: this.targetSlot,
805
896
  blocksBuilt,
806
897
  secondsIntoSlot
807
898
  });
@@ -818,20 +909,22 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
818
909
  indexWithinCheckpoint,
819
910
  txHashesAlreadyIncluded
820
911
  });
821
- // TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
822
- if (!buildResult && timingInfo.isLastBlock) {
823
- break;
824
- } else if (!buildResult && timingInfo.deadline !== undefined) {
825
- // But if there is still time for more blocks, wait until the next subslot and try again
912
+ // If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
913
+ if ('failure' in buildResult) {
914
+ // If this was the last subslot, or we're running with a single block per slot, we're done
915
+ if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
916
+ break;
917
+ }
918
+ // Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
826
919
  await this.waitUntilNextSubslot(timingInfo.deadline);
827
920
  continue;
828
- } else if (!buildResult) {
829
- break;
830
- } else if ('error' in buildResult) {
831
- // If there was an error building the block, just exit the loop and give up the rest of the slot
921
+ }
922
+ // If there was an error building the block, we just exit the loop and give up the rest of the slot.
923
+ // We don't want to risk building more blocks if something went wrong.
924
+ if ('error' in buildResult) {
832
925
  if (!(buildResult.error instanceof SequencerInterruptedError)) {
833
- this.log.warn(`Halting block building for slot ${slot}`, {
834
- slot,
926
+ this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
927
+ slot: this.targetSlot,
835
928
  blocksBuilt,
836
929
  error: buildResult.error
837
930
  });
@@ -839,39 +932,36 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
839
932
  break;
840
933
  }
841
934
  const { block, usedTxs } = buildResult;
935
+ this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
936
+ isFirstBlock: blocksBuilt === 0,
937
+ isLastBlock: timingInfo.isLastBlock
938
+ });
842
939
  blocksInCheckpoint.push(block);
843
940
  usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
844
- // If this is the last block, send the proposed block to the archiver,
845
- // and exit the loop now so we can build the checkpoint and start collecting attestations.
941
+ // Sign the block proposal. This will throw if HA signing fails.
942
+ const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
943
+ // Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
944
+ // so we avoid polluting our archive with a block that would fail.
945
+ // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
946
+ // If this throws, we abort the entire checkpoint.
947
+ await this.syncProposedBlockToArchiver(block);
948
+ // If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
846
949
  if (timingInfo.isLastBlock) {
847
- await this.syncProposedBlockToArchiver(block);
848
- this.log.verbose(`Completed final block ${blockNumber} for slot ${slot}`, {
849
- slot,
950
+ this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
951
+ slot: this.targetSlot,
850
952
  blockNumber,
851
953
  blocksBuilt
852
954
  });
853
- blockPendingBroadcast = {
854
- block,
855
- txs: usedTxs
856
- };
955
+ blockPendingBroadcast = proposal;
857
956
  break;
858
957
  }
859
- // Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
860
- // in which case we'll broadcast it along with the checkpoint at the end of the loop.
861
- // Note that we only send the block to the archiver if we manage to create the proposal, so if there's
862
- // a HA error we don't pollute our archiver with a block that won't make it to the chain.
863
- const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
864
- // Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal.
865
- // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
866
- // If this throws, we abort the entire checkpoint.
867
- await this.syncProposedBlockToArchiver(block);
868
958
  // Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
869
959
  proposal && await this.p2pClient.broadcastProposal(proposal);
870
960
  // Wait until the next block's start time
871
961
  await this.waitUntilNextSubslot(timingInfo.deadline);
872
962
  }
873
- this.log.verbose(`Block building loop completed for slot ${this.slot}`, {
874
- slot: this.slot,
963
+ this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
964
+ slot: this.targetSlot,
875
965
  blocksBuilt: blocksInCheckpoint.length
876
966
  });
877
967
  return {
@@ -884,18 +974,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
884
974
  this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
885
975
  return Promise.resolve(undefined);
886
976
  }
887
- return this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
977
+ return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
888
978
  }
889
979
  /** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
890
- this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
980
+ this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
891
981
  this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
892
- slot: this.slot
982
+ slot: this.targetSlot
893
983
  });
894
984
  await this.waitUntilTimeInSlot(nextSubslotStart);
895
985
  }
896
986
  /** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
897
987
  const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
898
- this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`, {
988
+ this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
899
989
  ...checkpointBuilder.getConstantData(),
900
990
  ...opts
901
991
  });
@@ -903,28 +993,30 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
903
993
  // Wait until we have enough txs to build the block
904
994
  const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
905
995
  if (!canStartBuilding) {
906
- this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`, {
996
+ this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
907
997
  blockNumber,
908
- slot: this.slot,
998
+ slot: this.targetSlot,
909
999
  indexWithinCheckpoint
910
1000
  });
911
1001
  this.eventEmitter.emit('block-tx-count-check-failed', {
912
1002
  minTxs,
913
1003
  availableTxs,
914
- slot: this.slot
1004
+ slot: this.targetSlot
915
1005
  });
916
1006
  this.metrics.recordBlockProposalFailed('insufficient_txs');
917
- return undefined;
1007
+ return {
1008
+ failure: 'insufficient-txs'
1009
+ };
918
1010
  }
919
1011
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
920
1012
  // just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
921
1013
  const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
922
- this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
923
- slot: this.slot,
1014
+ this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
1015
+ slot: this.targetSlot,
924
1016
  blockNumber,
925
1017
  indexWithinCheckpoint
926
1018
  });
927
- this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
1019
+ this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
928
1020
  // Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
929
1021
  // by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
930
1022
  // minValidTxs is passed into the builder so it can reject the block *before* updating state.
@@ -945,8 +1037,8 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
945
1037
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
946
1038
  await this.dropFailedTxsFromP2P(buildResult.failedTxs);
947
1039
  if (buildResult.status === 'insufficient-valid-txs') {
948
- this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`, {
949
- slot: this.slot,
1040
+ this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
1041
+ slot: this.targetSlot,
950
1042
  blockNumber,
951
1043
  numTxs: buildResult.processedCount,
952
1044
  indexWithinCheckpoint,
@@ -954,10 +1046,12 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
954
1046
  });
955
1047
  this.eventEmitter.emit('block-build-failed', {
956
1048
  reason: `Insufficient valid txs`,
957
- slot: this.slot
1049
+ slot: this.targetSlot
958
1050
  });
959
1051
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
960
- return undefined;
1052
+ return {
1053
+ failure: 'insufficient-valid-txs'
1054
+ };
961
1055
  }
962
1056
  // Block creation succeeded, emit stats and metrics
963
1057
  const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
@@ -970,17 +1064,20 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
970
1064
  const blockHash = await block.hash();
971
1065
  const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
972
1066
  const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
973
- this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`, {
1067
+ this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
974
1068
  blockHash,
975
1069
  txHashes,
976
1070
  manaPerSec,
977
1071
  ...blockStats
978
1072
  });
1073
+ // `slot` is the target/submission slot (may be one ahead when pipelining),
1074
+ // `buildSlot` is the wall-clock slot during which the block was actually built.
979
1075
  this.eventEmitter.emit('block-proposed', {
980
1076
  blockNumber: block.number,
981
- slot: this.slot
1077
+ slot: this.targetSlot,
1078
+ buildSlot: this.slotNow
982
1079
  });
983
- this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
1080
+ this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
984
1081
  return {
985
1082
  block,
986
1083
  usedTxs
@@ -988,11 +1085,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
988
1085
  } catch (err) {
989
1086
  this.eventEmitter.emit('block-build-failed', {
990
1087
  reason: err.message,
991
- slot: this.slot
1088
+ slot: this.targetSlot
992
1089
  });
993
1090
  this.log.error(`Error building block`, err, {
994
1091
  blockNumber,
995
- slot: this.slot
1092
+ slot: this.targetSlot
996
1093
  });
997
1094
  this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
998
1095
  this.metrics.recordFailedBlock();
@@ -1040,10 +1137,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1040
1137
  };
1041
1138
  }
1042
1139
  // Wait a bit before checking again
1043
- this.setStateFn(SequencerState.WAITING_FOR_TXS, this.slot);
1044
- this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`, {
1140
+ this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
1141
+ this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
1045
1142
  blockNumber,
1046
- slot: this.slot,
1143
+ slot: this.targetSlot,
1047
1144
  indexWithinCheckpoint
1048
1145
  });
1049
1146
  await this.waitForTxsPollingInterval();
@@ -1075,19 +1172,19 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1075
1172
  committee
1076
1173
  });
1077
1174
  }
1078
- const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
1175
+ const numberOfRequiredAttestations = computeQuorum(committee.length);
1079
1176
  if (this.config.skipCollectingAttestations) {
1080
1177
  this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
1081
- const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
1178
+ const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
1082
1179
  return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
1083
1180
  }
1084
- const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT) : this.l1Constants.slotDuration;
1181
+ const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
1085
1182
  const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
1086
1183
  this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
1087
1184
  const collectAttestationsTimer = new Timer();
1088
1185
  let collectedAttestationsCount = 0;
1089
1186
  try {
1090
- const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
1187
+ const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
1091
1188
  collectedAttestationsCount = attestations.length;
1092
1189
  // Trim attestations to minimum required to save L1 calldata gas
1093
1190
  const localAddresses = this.validatorClient.getValidatorAddresses();
@@ -1143,14 +1240,25 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1143
1240
  const shuffled = [
1144
1241
  ...attestations
1145
1242
  ];
1146
- const [i, j] = [
1147
- (proposerIndex + 1) % shuffled.length,
1148
- (proposerIndex + 2) % shuffled.length
1149
- ];
1150
- const valueI = shuffled[i];
1151
- const valueJ = shuffled[j];
1152
- shuffled[i] = valueJ;
1153
- shuffled[j] = valueI;
1243
+ // Find two non-proposer positions that both have non-empty signatures to swap.
1244
+ // This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
1245
+ // signers array stays correctly aligned with L1's committee reconstruction.
1246
+ const swappable = [];
1247
+ for(let k = 0; k < shuffled.length; k++){
1248
+ if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
1249
+ swappable.push(k);
1250
+ }
1251
+ }
1252
+ if (swappable.length >= 2) {
1253
+ const [i, j] = [
1254
+ swappable[0],
1255
+ swappable[1]
1256
+ ];
1257
+ [shuffled[i], shuffled[j]] = [
1258
+ shuffled[j],
1259
+ shuffled[i]
1260
+ ];
1261
+ }
1154
1262
  const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
1155
1263
  return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
1156
1264
  }
@@ -1174,7 +1282,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1174
1282
  * and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
1175
1283
  * whenever the real proposer's block arrives from L1.
1176
1284
  */ async syncProposedBlockToArchiver(block) {
1177
- if (this.config.skipPushProposedBlocksToArchiver !== false || this.config.fishermanMode) {
1285
+ if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
1178
1286
  this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
1179
1287
  blockNumber: block.number,
1180
1288
  slot: block.header.globalVariables.slotNumber
@@ -1190,16 +1298,16 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1190
1298
  /** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
1191
1299
  // Perform L1 fee analysis before clearing requests
1192
1300
  // The callback is invoked asynchronously after the next block is mined
1193
- const feeAnalysis = await this.publisher.analyzeL1Fees(this.slot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
1301
+ const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
1194
1302
  if (checkpoint) {
1195
- this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.slot}`, {
1303
+ this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
1196
1304
  ...checkpoint.toCheckpointInfo(),
1197
1305
  ...checkpoint.getStats(),
1198
1306
  feeAnalysisId: feeAnalysis?.id
1199
1307
  });
1200
1308
  } else {
1201
- this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
1202
- slot: this.slot,
1309
+ this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
1310
+ slot: this.targetSlot,
1203
1311
  feeAnalysisId: feeAnalysis?.id
1204
1312
  });
1205
1313
  this.metrics.recordCheckpointProposalFailed('block_build_failed');
@@ -1210,15 +1318,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1210
1318
  * Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
1211
1319
  */ handleHASigningError(err, errorContext) {
1212
1320
  if (err instanceof DutyAlreadySignedError) {
1213
- this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
1214
- slot: this.slot,
1321
+ this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
1322
+ slot: this.targetSlot,
1215
1323
  signedByNode: err.signedByNode
1216
1324
  });
1217
1325
  return true;
1218
1326
  }
1219
1327
  if (err instanceof SlashingProtectionError) {
1220
- this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
1221
- slot: this.slot,
1328
+ this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
1329
+ slot: this.targetSlot,
1222
1330
  existingMessageHash: err.existingMessageHash,
1223
1331
  attemptedMessageHash: err.attemptedMessageHash
1224
1332
  });
@@ -1235,7 +1343,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1235
1343
  await sleep(TXS_POLLING_MS);
1236
1344
  }
1237
1345
  getSlotStartBuildTimestamp() {
1238
- return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
1346
+ return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
1239
1347
  }
1240
1348
  getSecondsIntoSlot() {
1241
1349
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();