@aztec/sequencer-client 0.0.1-commit.ef17749e1 → 0.0.1-commit.f1b29a41e

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 (53) hide show
  1. package/dest/client/sequencer-client.d.ts +4 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +27 -76
  4. package/dest/config.d.ts +4 -3
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +9 -2
  7. package/dest/global_variable_builder/global_builder.d.ts +15 -9
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +29 -25
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +1 -1
  12. package/dest/publisher/config.d.ts +13 -1
  13. package/dest/publisher/config.d.ts.map +1 -1
  14. package/dest/publisher/config.js +17 -2
  15. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher-factory.js +2 -2
  18. package/dest/publisher/sequencer-publisher.d.ts +52 -25
  19. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  20. package/dest/publisher/sequencer-publisher.js +98 -42
  21. package/dest/sequencer/checkpoint_proposal_job.d.ts +33 -6
  22. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_proposal_job.js +261 -141
  24. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  25. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  26. package/dest/sequencer/checkpoint_voter.js +2 -5
  27. package/dest/sequencer/events.d.ts +2 -1
  28. package/dest/sequencer/events.d.ts.map +1 -1
  29. package/dest/sequencer/metrics.d.ts +5 -1
  30. package/dest/sequencer/metrics.d.ts.map +1 -1
  31. package/dest/sequencer/metrics.js +11 -0
  32. package/dest/sequencer/sequencer.d.ts +19 -7
  33. package/dest/sequencer/sequencer.d.ts.map +1 -1
  34. package/dest/sequencer/sequencer.js +123 -68
  35. package/dest/sequencer/types.d.ts +2 -5
  36. package/dest/sequencer/types.d.ts.map +1 -1
  37. package/dest/test/mock_checkpoint_builder.d.ts +4 -4
  38. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  39. package/package.json +27 -28
  40. package/src/client/sequencer-client.ts +37 -101
  41. package/src/config.ts +12 -1
  42. package/src/global_variable_builder/global_builder.ts +37 -26
  43. package/src/global_variable_builder/index.ts +1 -1
  44. package/src/publisher/config.ts +32 -0
  45. package/src/publisher/sequencer-publisher-factory.ts +3 -3
  46. package/src/publisher/sequencer-publisher.ts +144 -54
  47. package/src/sequencer/checkpoint_proposal_job.ts +340 -147
  48. package/src/sequencer/checkpoint_voter.ts +1 -12
  49. package/src/sequencer/events.ts +1 -1
  50. package/src/sequencer/metrics.ts +14 -0
  51. package/src/sequencer/sequencer.ts +178 -79
  52. package/src/sequencer/types.ts +2 -5
  53. package/src/test/mock_checkpoint_builder.ts +3 -3
@@ -436,9 +436,11 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
436
436
  return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
437
437
  }
438
438
  var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
439
- import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
439
+ import { RollupContract } from '@aztec/ethereum/contracts';
440
+ import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
440
441
  import { randomInt } from '@aztec/foundation/crypto/random';
441
442
  import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
443
+ import { Signature } from '@aztec/foundation/eth-signature';
442
444
  import { filter } from '@aztec/foundation/iterator';
443
445
  import { createLogger } from '@aztec/foundation/log';
444
446
  import { sleep, sleepUntil } from '@aztec/foundation/sleep';
@@ -446,9 +448,9 @@ import { Timer } from '@aztec/foundation/timer';
446
448
  import { isErrorClass, unfreeze } from '@aztec/foundation/types';
447
449
  import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
448
450
  import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
449
- import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
451
+ import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
450
452
  import { Gas } from '@aztec/stdlib/gas';
451
- import { NoValidTxsError } from '@aztec/stdlib/interfaces/server';
453
+ import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
452
454
  import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
453
455
  import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
454
456
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
@@ -462,7 +464,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
462
464
  return {
463
465
  // nullish operator needed for tests
464
466
  [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
465
- [Attributes.SLOT_NUMBER]: this.slot
467
+ [Attributes.SLOT_NUMBER]: this.targetSlot
466
468
  };
467
469
  }), _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
470
  /**
@@ -471,8 +473,9 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
471
473
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
472
474
  * the Sequencer once the check for being the proposer for the slot has succeeded.
473
475
  */ export class CheckpointProposalJob {
474
- epoch;
475
- slot;
476
+ slotNow;
477
+ targetSlot;
478
+ targetEpoch;
476
479
  checkpointNumber;
477
480
  syncedToBlockNumber;
478
481
  proposer;
@@ -497,6 +500,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
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
+ /** Fee header override computed during proposeCheckpoint, reused in enqueueCheckpointForSubmission. */ computedForceProposedFeeHeader;
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, 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;
@@ -570,22 +577,31 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
570
577
  this.eventEmitter = eventEmitter;
571
578
  this.setStateFn = setStateFn;
572
579
  this.tracer = tracer;
580
+ this.proposedCheckpointData = proposedCheckpointData;
573
581
  _initProto(this);
574
582
  this.log = createLogger('sequencer:checkpoint-proposal', {
575
583
  ...bindings,
576
- instanceId: `slot-${slot}`
584
+ instanceId: `slot-${this.slotNow}`
577
585
  });
578
586
  }
587
+ /** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
588
+ this.log.info('Awaiting pending L1 payload submission');
589
+ await this.pendingL1Submission;
590
+ }
579
591
  /**
580
592
  * Executes the checkpoint proposal job.
581
- * Returns the published checkpoint if successful, undefined otherwise.
593
+ * Builds blocks, collects attestations, enqueues requests, and schedules L1 submission as a
594
+ * background task so the work loop can return to IDLE immediately.
595
+ * Returns the built checkpoint if successful, undefined otherwise.
582
596
  */ async execute() {
583
597
  // Enqueue governance and slashing votes (returns promises that will be awaited later)
584
598
  // In fisherman mode, we simulate slashing but don't actually publish to L1
585
599
  // 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();
600
+ const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
601
+ // Build and propose the checkpoint. Builds blocks, broadcasts, collects attestations, and signs.
602
+ // Does NOT enqueue to L1 yet — that happens after the pipeline sleep.
603
+ const proposalResult = await this.proposeCheckpoint();
604
+ const checkpoint = proposalResult?.checkpoint;
589
605
  // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
590
606
  await Promise.all(votesPromises);
591
607
  if (checkpoint) {
@@ -596,24 +612,72 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
596
612
  await this.handleCheckpointEndAsFisherman(checkpoint);
597
613
  return;
598
614
  }
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
606
- });
607
- const coinbase = checkpoint?.header.coinbase;
608
- await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
609
- return checkpoint;
610
- } else if (checkpoint) {
611
- this.eventEmitter.emit('checkpoint-publish-failed', {
612
- ...l1Response,
613
- slot: this.slot
614
- });
615
- return undefined;
615
+ // Enqueue the checkpoint for L1 submission
616
+ if (proposalResult) {
617
+ try {
618
+ await this.enqueueCheckpointForSubmission(proposalResult);
619
+ } catch (err) {
620
+ this.log.error(`Failed to enqueue checkpoint for L1 submission at slot ${this.targetSlot}`, err);
621
+ // Continue to sendRequestsAt so votes are still sent
622
+ }
623
+ }
624
+ // Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
625
+ const submitAfter = this.epochCache.isProposerPipeliningEnabled() ? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000) : new Date(this.dateProvider.now());
626
+ // TODO(https://github.com/AztecProtocol/aztec-packages/pull/21250): should discard the pending submission if a reorg occurs underneath
627
+ // Schedule L1 submission in the background so the work loop returns immediately.
628
+ // The publisher will sleep until submitAfter, then send the bundled requests.
629
+ // The promise is stored so it can be awaited during shutdown.
630
+ this.pendingL1Submission = this.publisher.sendRequestsAt(submitAfter).then(async (l1Response)=>{
631
+ const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
632
+ if (proposedAction) {
633
+ this.eventEmitter.emit('checkpoint-published', {
634
+ checkpoint: this.checkpointNumber,
635
+ slot: this.targetSlot
636
+ });
637
+ const coinbase = checkpoint?.header.coinbase;
638
+ await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
639
+ } else if (checkpoint) {
640
+ this.eventEmitter.emit('checkpoint-publish-failed', {
641
+ ...l1Response,
642
+ slot: this.targetSlot
643
+ });
644
+ if (this.epochCache.isProposerPipeliningEnabled()) {
645
+ this.metrics.recordPipelineDiscard();
646
+ }
647
+ }
648
+ }).catch((err)=>{
649
+ this.log.error(`Background L1 submission failed for slot ${this.targetSlot}`, err);
650
+ if (checkpoint) {
651
+ this.eventEmitter.emit('checkpoint-publish-failed', {
652
+ slot: this.targetSlot
653
+ });
654
+ if (this.epochCache.isProposerPipeliningEnabled()) {
655
+ this.metrics.recordPipelineDiscard();
656
+ }
657
+ }
658
+ });
659
+ // Return the built checkpoint immediately — the work loop is now unblocked
660
+ return checkpoint;
661
+ }
662
+ /** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
663
+ const { checkpoint, attestations, attestationsSignature } = result;
664
+ this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
665
+ const aztecSlotDuration = this.l1Constants.slotDuration;
666
+ const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
667
+ const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
668
+ // If we have been configured to potentially skip publishing checkpoint then roll the dice here
669
+ if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
670
+ const roll = Math.max(0, randomInt(100));
671
+ if (roll < this.config.skipPublishingCheckpointsPercent) {
672
+ this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
673
+ return;
674
+ }
616
675
  }
676
+ await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
677
+ txTimeoutAt,
678
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
679
+ forceProposedFeeHeader: this.computedForceProposedFeeHeader
680
+ });
617
681
  }
618
682
  async proposeCheckpoint() {
619
683
  try {
@@ -627,19 +691,37 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
627
691
  const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
628
692
  const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
629
693
  // Start the checkpoint
630
- this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
631
- this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
694
+ this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
695
+ this.log.info(`Starting checkpoint proposal`, {
696
+ buildSlot: this.slotNow,
697
+ submissionSlot: this.targetSlot,
698
+ pipelining: this.epochCache.isProposerPipeliningEnabled(),
699
+ proposer: this.proposer?.toString(),
700
+ coinbase: coinbase.toString()
701
+ });
702
+ this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
632
703
  // Enqueues checkpoint invalidation (constant for the whole slot)
633
704
  if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
634
705
  this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
635
706
  }
636
- // Create checkpoint builder for the slot
637
- const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.slot);
707
+ // Create checkpoint builder for the slot.
708
+ // When pipelining, force the proposed checkpoint number and fee header to our parent so the
709
+ // fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
710
+ const isPipelining = this.epochCache.isProposerPipeliningEnabled();
711
+ const parentCheckpointNumber = isPipelining ? CheckpointNumber(this.checkpointNumber - 1) : undefined;
712
+ // Compute the parent's fee header override when pipelining
713
+ if (isPipelining && this.proposedCheckpointData) {
714
+ this.computedForceProposedFeeHeader = await this.computeForceProposedFeeHeader(parentCheckpointNumber);
715
+ }
716
+ const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, {
717
+ forcePendingCheckpointNumber: parentCheckpointNumber,
718
+ forceProposedFeeHeader: this.computedForceProposedFeeHeader
719
+ });
638
720
  // Collect L1 to L2 messages for the checkpoint and compute their hash
639
721
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
640
722
  const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
641
723
  // 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);
724
+ const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
643
725
  // Get the fee asset price modifier from the oracle
644
726
  const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
645
727
  const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
@@ -674,18 +756,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
674
756
  throw err;
675
757
  }
676
758
  if (blocksInCheckpoint.length === 0) {
677
- this.log.warn(`No blocks were built for slot ${this.slot}`, {
678
- slot: this.slot
759
+ this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
760
+ slot: this.targetSlot
679
761
  });
680
762
  this.eventEmitter.emit('checkpoint-empty', {
681
- slot: this.slot
763
+ slot: this.targetSlot
682
764
  });
683
765
  return undefined;
684
766
  }
685
767
  const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
686
768
  if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
687
769
  this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
688
- slot: this.slot,
770
+ slot: this.targetSlot,
689
771
  blocksBuilt: blocksInCheckpoint.length,
690
772
  minBlocksForCheckpoint
691
773
  });
@@ -693,9 +775,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
693
775
  }
694
776
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
695
777
  // broadcasted yet, and wait to collect the committee attestations.
696
- this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
778
+ this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
697
779
  const checkpoint = await checkpointBuilder.completeCheckpoint();
698
- // Final validation round for the checkpoint before we propose it, just for safety
780
+ // Final validation: per-block limits are only checked if the operator set them explicitly.
781
+ // Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
699
782
  try {
700
783
  validateCheckpoint(checkpoint, {
701
784
  rollupManaLimit: this.l1Constants.rollupManaLimit,
@@ -705,7 +788,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
705
788
  maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
706
789
  });
707
790
  } catch (err) {
708
- this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
791
+ this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
709
792
  checkpoint: checkpoint.header.toInspect()
710
793
  });
711
794
  return undefined;
@@ -714,13 +797,17 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
714
797
  this.metrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
715
798
  // Do not collect attestations nor publish to L1 in fisherman mode
716
799
  if (this.config.fishermanMode) {
717
- this.log.info(`Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
718
- slot: this.slot,
800
+ this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
801
+ slot: this.targetSlot,
719
802
  checkpoint: checkpoint.header.toInspect(),
720
803
  blocksBuilt: blocksInCheckpoint.length
721
804
  });
722
805
  this.metrics.recordCheckpointSuccess();
723
- return checkpoint;
806
+ return {
807
+ checkpoint,
808
+ attestations: CommitteeAttestationsAndSigners.empty(),
809
+ attestationsSignature: Signature.empty()
810
+ };
724
811
  }
725
812
  // Include the block pending broadcast in the checkpoint proposal if any
726
813
  const lastBlock = blockPendingBroadcast && {
@@ -732,7 +819,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
732
819
  const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, feeAssetPriceModifier, lastBlock, this.proposer, checkpointProposalOptions);
733
820
  const blockProposedAt = this.dateProvider.now();
734
821
  await this.p2pClient.broadcastCheckpointProposal(proposal);
735
- this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
822
+ this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
736
823
  const attestations = await this.waitForAttestations(proposal);
737
824
  const blockAttestedAt = this.dateProvider.now();
738
825
  this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
@@ -740,7 +827,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
740
827
  const signer = this.proposer ?? this.publisher.getSenderAddress();
741
828
  let attestationsSignature;
742
829
  try {
743
- attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
830
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
744
831
  } catch (err) {
745
832
  // We shouldn't really get here since we yield to another HA node
746
833
  // as soon as we see these errors when creating block or checkpoint proposals.
@@ -749,24 +836,12 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
749
836
  }
750
837
  throw err;
751
838
  }
752
- // Enqueue publishing the checkpoint to L1
753
- this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
754
- const aztecSlotDuration = this.l1Constants.slotDuration;
755
- const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
756
- const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
757
- // If we have been configured to potentially skip publishing checkpoint then roll the dice here
758
- if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
759
- const result = Math.max(0, randomInt(100));
760
- if (result < this.config.skipPublishingCheckpointsPercent) {
761
- this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`);
762
- return checkpoint;
763
- }
764
- }
765
- await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
766
- txTimeoutAt,
767
- forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
768
- });
769
- return checkpoint;
839
+ // Return the result for the caller to enqueue after the pipeline sleep
840
+ return {
841
+ checkpoint,
842
+ attestations,
843
+ attestationsSignature
844
+ };
770
845
  } catch (e) {
771
846
  env.error = e;
772
847
  env.hasError = true;
@@ -779,7 +854,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
779
854
  // swallow this error. It's already been logged by a function deeper in the stack
780
855
  return undefined;
781
856
  }
782
- this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
857
+ this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
783
858
  return undefined;
784
859
  }
785
860
  }
@@ -799,7 +874,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
799
874
  const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
800
875
  if (!timingInfo.canStart) {
801
876
  this.log.debug(`Not enough time left in slot to start another block`, {
802
- slot: this.slot,
877
+ slot: this.targetSlot,
803
878
  blocksBuilt,
804
879
  secondsIntoSlot
805
880
  });
@@ -828,8 +903,8 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
828
903
  } else if ('error' in buildResult) {
829
904
  // If there was an error building the block, just exit the loop and give up the rest of the slot
830
905
  if (!(buildResult.error instanceof SequencerInterruptedError)) {
831
- this.log.warn(`Halting block building for slot ${this.slot}`, {
832
- slot: this.slot,
906
+ this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
907
+ slot: this.targetSlot,
833
908
  blocksBuilt,
834
909
  error: buildResult.error
835
910
  });
@@ -838,21 +913,13 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
838
913
  }
839
914
  const { block, usedTxs } = buildResult;
840
915
  blocksInCheckpoint.push(block);
841
- // Sync the proposed block to the archiver to make it available
842
- // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
843
- // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
844
- // Fire and forget - don't block the critical path, but log errors
845
- this.syncProposedBlockToArchiver(block).catch((err)=>{
846
- this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
847
- blockNumber: block.number,
848
- err
849
- });
850
- });
851
916
  usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
852
- // If this is the last block, exit the loop now so we start collecting attestations
917
+ // If this is the last block, sync it to the archiver and exit the loop
918
+ // so we can build the checkpoint and start collecting attestations.
853
919
  if (timingInfo.isLastBlock) {
854
- this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
855
- slot: this.slot,
920
+ await this.syncProposedBlockToArchiver(block);
921
+ this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
922
+ slot: this.targetSlot,
856
923
  blockNumber,
857
924
  blocksBuilt
858
925
  });
@@ -862,17 +929,22 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
862
929
  };
863
930
  break;
864
931
  }
865
- // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
866
- // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
867
- if (!this.config.fishermanMode) {
868
- const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
869
- await this.p2pClient.broadcastProposal(proposal);
870
- }
932
+ // Broadcast the block proposal (unless we're in fisherman mode) unless the block is the last one,
933
+ // in which case we'll broadcast it along with the checkpoint at the end of the loop.
934
+ // Note that we only send the block to the archiver if we manage to create the proposal, so if there's
935
+ // a HA error we don't pollute our archiver with a block that won't make it to the chain.
936
+ const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
937
+ // Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal.
938
+ // We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
939
+ // If this throws, we abort the entire checkpoint.
940
+ await this.syncProposedBlockToArchiver(block);
941
+ // Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
942
+ proposal && await this.p2pClient.broadcastProposal(proposal);
871
943
  // Wait until the next block's start time
872
944
  await this.waitUntilNextSubslot(timingInfo.deadline);
873
945
  }
874
- this.log.verbose(`Block building loop completed for slot ${this.slot}`, {
875
- slot: this.slot,
946
+ this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
947
+ slot: this.targetSlot,
876
948
  blocksBuilt: blocksInCheckpoint.length
877
949
  });
878
950
  return {
@@ -880,33 +952,39 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
880
952
  blockPendingBroadcast
881
953
  };
882
954
  }
955
+ /** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
956
+ if (this.config.fishermanMode) {
957
+ this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
958
+ return Promise.resolve(undefined);
959
+ }
960
+ return this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
961
+ }
883
962
  /** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
884
- this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
963
+ this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
885
964
  this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
886
- slot: this.slot
965
+ slot: this.targetSlot
887
966
  });
888
967
  await this.waitUntilTimeInSlot(nextSubslotStart);
889
968
  }
890
969
  /** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
891
970
  const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
892
- this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`, {
971
+ this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
893
972
  ...checkpointBuilder.getConstantData(),
894
973
  ...opts
895
974
  });
896
975
  try {
897
976
  // Wait until we have enough txs to build the block
898
- const minTxs = this.config.minTxsPerBlock;
899
- const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
977
+ const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
900
978
  if (!canStartBuilding) {
901
- this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`, {
979
+ this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
902
980
  blockNumber,
903
- slot: this.slot,
981
+ slot: this.targetSlot,
904
982
  indexWithinCheckpoint
905
983
  });
906
984
  this.eventEmitter.emit('block-tx-count-check-failed', {
907
985
  minTxs,
908
986
  availableTxs,
909
- slot: this.slot
987
+ slot: this.targetSlot
910
988
  });
911
989
  this.metrics.recordBlockProposalFailed('insufficient_txs');
912
990
  return undefined;
@@ -914,46 +992,48 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
914
992
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
915
993
  // just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
916
994
  const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
917
- this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
918
- slot: this.slot,
995
+ this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
996
+ slot: this.targetSlot,
919
997
  blockNumber,
920
998
  indexWithinCheckpoint
921
999
  });
922
- this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
923
- // Per-block limits derived at startup by computeBlockLimits(), further capped
1000
+ this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
1001
+ // Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
924
1002
  // by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
1003
+ // minValidTxs is passed into the builder so it can reject the block *before* updating state.
1004
+ const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
925
1005
  const blockBuilderOptions = {
926
1006
  maxTransactions: this.config.maxTxsPerBlock,
927
1007
  maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
928
1008
  deadline: buildDeadline,
929
- isBuildingProposal: true
1009
+ isBuildingProposal: true,
1010
+ minValidTxs,
1011
+ maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
1012
+ perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
930
1013
  };
931
- // Actually build the block by executing txs
1014
+ // Actually build the block by executing txs. The builder throws InsufficientValidTxsError
1015
+ // if the number of successfully processed txs is below minValidTxs, ensuring state is not
1016
+ // updated for blocks that will be discarded.
932
1017
  const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
933
1018
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
934
1019
  await this.dropFailedTxsFromP2P(buildResult.failedTxs);
935
- // Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
936
- // too long, then we may not get to minTxsPerBlock after executing public functions.
937
- const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
938
- const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
939
- if (buildResult.status === 'no-valid-txs' || !forceCreate && numTxs < minValidTxs) {
940
- this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`, {
941
- slot: this.slot,
1020
+ if (buildResult.status === 'insufficient-valid-txs') {
1021
+ this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
1022
+ slot: this.targetSlot,
942
1023
  blockNumber,
943
- numTxs,
1024
+ numTxs: buildResult.processedCount,
944
1025
  indexWithinCheckpoint,
945
- minValidTxs,
946
- buildResult: buildResult.status
1026
+ minValidTxs
947
1027
  });
948
1028
  this.eventEmitter.emit('block-build-failed', {
949
1029
  reason: `Insufficient valid txs`,
950
- slot: this.slot
1030
+ slot: this.targetSlot
951
1031
  });
952
1032
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
953
1033
  return undefined;
954
1034
  }
955
1035
  // Block creation succeeded, emit stats and metrics
956
- const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
1036
+ const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
957
1037
  const blockStats = {
958
1038
  eventName: 'l2-block-built',
959
1039
  duration: blockBuildDuration,
@@ -963,15 +1043,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
963
1043
  const blockHash = await block.hash();
964
1044
  const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
965
1045
  const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
966
- this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`, {
1046
+ this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
967
1047
  blockHash,
968
1048
  txHashes,
969
1049
  manaPerSec,
970
1050
  ...blockStats
971
1051
  });
1052
+ // `slot` is the target/submission slot (may be one ahead when pipelining),
1053
+ // `buildSlot` is the wall-clock slot during which the block was actually built.
972
1054
  this.eventEmitter.emit('block-proposed', {
973
1055
  blockNumber: block.number,
974
- slot: this.slot
1056
+ slot: this.targetSlot,
1057
+ buildSlot: this.slotNow
975
1058
  });
976
1059
  this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
977
1060
  return {
@@ -981,11 +1064,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
981
1064
  } catch (err) {
982
1065
  this.eventEmitter.emit('block-build-failed', {
983
1066
  reason: err.message,
984
- slot: this.slot
1067
+ slot: this.targetSlot
985
1068
  });
986
1069
  this.log.error(`Error building block`, err, {
987
1070
  blockNumber,
988
- slot: this.slot
1071
+ slot: this.targetSlot
989
1072
  });
990
1073
  this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
991
1074
  this.metrics.recordFailedBlock();
@@ -994,7 +1077,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
994
1077
  };
995
1078
  }
996
1079
  }
997
- /** Uses the checkpoint builder to build a block, catching specific txs */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
1080
+ /** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
998
1081
  try {
999
1082
  const workTimer = new Timer();
1000
1083
  const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
@@ -1005,10 +1088,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1005
1088
  status: 'success'
1006
1089
  };
1007
1090
  } catch (err) {
1008
- if (isErrorClass(err, NoValidTxsError)) {
1091
+ if (isErrorClass(err, InsufficientValidTxsError)) {
1009
1092
  return {
1010
1093
  failedTxs: err.failedTxs,
1011
- status: 'no-valid-txs'
1094
+ processedCount: err.processedCount,
1095
+ status: 'insufficient-valid-txs'
1012
1096
  };
1013
1097
  }
1014
1098
  throw err;
@@ -1027,14 +1111,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1027
1111
  if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
1028
1112
  return {
1029
1113
  canStartBuilding: false,
1030
- availableTxs: availableTxs
1114
+ availableTxs,
1115
+ minTxs
1031
1116
  };
1032
1117
  }
1033
1118
  // Wait a bit before checking again
1034
- this.setStateFn(SequencerState.WAITING_FOR_TXS, this.slot);
1035
- this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`, {
1119
+ this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
1120
+ this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
1036
1121
  blockNumber,
1037
- slot: this.slot,
1122
+ slot: this.targetSlot,
1038
1123
  indexWithinCheckpoint
1039
1124
  });
1040
1125
  await this.waitForTxsPollingInterval();
@@ -1042,7 +1127,8 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1042
1127
  }
1043
1128
  return {
1044
1129
  canStartBuilding: true,
1045
- availableTxs
1130
+ availableTxs,
1131
+ minTxs
1046
1132
  };
1047
1133
  }
1048
1134
  /**
@@ -1065,7 +1151,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1065
1151
  committee
1066
1152
  });
1067
1153
  }
1068
- const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
1154
+ const numberOfRequiredAttestations = computeQuorum(committee.length);
1069
1155
  if (this.config.skipCollectingAttestations) {
1070
1156
  this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
1071
1157
  const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
@@ -1171,7 +1257,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1171
1257
  * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
1172
1258
  * would never receive its own block without this explicit sync.
1173
1259
  */ async syncProposedBlockToArchiver(block) {
1174
- if (this.config.skipPushProposedBlocksToArchiver !== false) {
1260
+ if (this.config.skipPushProposedBlocksToArchiver) {
1175
1261
  this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
1176
1262
  blockNumber: block.number,
1177
1263
  slot: block.header.globalVariables.slotNumber
@@ -1187,16 +1273,16 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1187
1273
  /** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
1188
1274
  // Perform L1 fee analysis before clearing requests
1189
1275
  // The callback is invoked asynchronously after the next block is mined
1190
- const feeAnalysis = await this.publisher.analyzeL1Fees(this.slot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
1276
+ const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
1191
1277
  if (checkpoint) {
1192
- this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.slot}`, {
1278
+ this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
1193
1279
  ...checkpoint.toCheckpointInfo(),
1194
1280
  ...checkpoint.getStats(),
1195
1281
  feeAnalysisId: feeAnalysis?.id
1196
1282
  });
1197
1283
  } else {
1198
- this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
1199
- slot: this.slot,
1284
+ this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
1285
+ slot: this.targetSlot,
1200
1286
  feeAnalysisId: feeAnalysis?.id
1201
1287
  });
1202
1288
  this.metrics.recordCheckpointProposalFailed('block_build_failed');
@@ -1207,15 +1293,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1207
1293
  * Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
1208
1294
  */ handleHASigningError(err, errorContext) {
1209
1295
  if (err instanceof DutyAlreadySignedError) {
1210
- this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
1211
- slot: this.slot,
1296
+ this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
1297
+ slot: this.targetSlot,
1212
1298
  signedByNode: err.signedByNode
1213
1299
  });
1214
1300
  return true;
1215
1301
  }
1216
1302
  if (err instanceof SlashingProtectionError) {
1217
- this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
1218
- slot: this.slot,
1303
+ this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
1304
+ slot: this.targetSlot,
1219
1305
  existingMessageHash: err.existingMessageHash,
1220
1306
  attemptedMessageHash: err.attemptedMessageHash
1221
1307
  });
@@ -1223,6 +1309,40 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1223
1309
  }
1224
1310
  return false;
1225
1311
  }
1312
+ /**
1313
+ * In times of congestion we need to simulate using the correct fee header override for the previous block
1314
+ * We calculate the correct fee header values.
1315
+ *
1316
+ * If we are in block 1, or the checkpoint we are querying does not exist, we return undefined. However
1317
+ * If we are pipelining - where this function is called, the grandparentCheckpointNumber should always exist
1318
+ * @param parentCheckpointNumber
1319
+ * @returns
1320
+ */ async computeForceProposedFeeHeader(parentCheckpointNumber) {
1321
+ if (!this.proposedCheckpointData) {
1322
+ return undefined;
1323
+ }
1324
+ const rollup = this.publisher.rollupContract;
1325
+ const grandparentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 2);
1326
+ try {
1327
+ const [grandparentCheckpoint, manaTarget] = await Promise.all([
1328
+ rollup.getCheckpoint(grandparentCheckpointNumber),
1329
+ rollup.getManaTarget()
1330
+ ]);
1331
+ if (!grandparentCheckpoint || !grandparentCheckpoint.feeHeader) {
1332
+ this.log.error(`Grandparent checkpoint or its feeHeader is undefined for checkpointNumber=${grandparentCheckpointNumber.toString()}`);
1333
+ return undefined;
1334
+ } else {
1335
+ const parentFeeHeader = RollupContract.computeChildFeeHeader(grandparentCheckpoint.feeHeader, this.proposedCheckpointData.totalManaUsed, this.proposedCheckpointData.feeAssetPriceModifier, manaTarget);
1336
+ return {
1337
+ checkpointNumber: parentCheckpointNumber,
1338
+ feeHeader: parentFeeHeader
1339
+ };
1340
+ }
1341
+ } catch (err) {
1342
+ this.log.error(`Failed to fetch grandparent checkpoint or mana target for checkpointNumber=${grandparentCheckpointNumber.toString()}: ${err}`);
1343
+ return undefined;
1344
+ }
1345
+ }
1226
1346
  /** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
1227
1347
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
1228
1348
  const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
@@ -1232,7 +1352,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1232
1352
  await sleep(TXS_POLLING_MS);
1233
1353
  }
1234
1354
  getSlotStartBuildTimestamp() {
1235
- return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
1355
+ return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
1236
1356
  }
1237
1357
  getSecondsIntoSlot() {
1238
1358
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();