@aztec/sequencer-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d52e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -7
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +15 -4
  4. package/dest/config.d.ts +3 -4
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +28 -20
  7. package/dest/global_variable_builder/global_builder.d.ts +2 -4
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +2 -2
  10. package/dest/index.d.ts +2 -2
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -1
  13. package/dest/publisher/config.d.ts +31 -17
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +101 -42
  16. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
  17. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher-factory.js +13 -2
  19. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  20. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-metrics.js +12 -4
  22. package/dest/publisher/sequencer-publisher.d.ts +16 -8
  23. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.js +80 -39
  25. package/dest/sequencer/checkpoint_proposal_job.d.ts +34 -9
  26. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  27. package/dest/sequencer/checkpoint_proposal_job.js +184 -46
  28. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  29. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  30. package/dest/sequencer/checkpoint_voter.js +34 -10
  31. package/dest/sequencer/index.d.ts +1 -2
  32. package/dest/sequencer/index.d.ts.map +1 -1
  33. package/dest/sequencer/index.js +0 -1
  34. package/dest/sequencer/metrics.d.ts +17 -5
  35. package/dest/sequencer/metrics.d.ts.map +1 -1
  36. package/dest/sequencer/metrics.js +111 -30
  37. package/dest/sequencer/sequencer.d.ts +33 -13
  38. package/dest/sequencer/sequencer.d.ts.map +1 -1
  39. package/dest/sequencer/sequencer.js +95 -36
  40. package/dest/sequencer/timetable.d.ts +1 -4
  41. package/dest/sequencer/timetable.d.ts.map +1 -1
  42. package/dest/sequencer/timetable.js +1 -4
  43. package/dest/test/index.d.ts +3 -5
  44. package/dest/test/index.d.ts.map +1 -1
  45. package/dest/test/mock_checkpoint_builder.d.ts +19 -13
  46. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  47. package/dest/test/mock_checkpoint_builder.js +31 -11
  48. package/dest/test/utils.d.ts +8 -8
  49. package/dest/test/utils.d.ts.map +1 -1
  50. package/dest/test/utils.js +12 -11
  51. package/package.json +30 -28
  52. package/src/client/sequencer-client.ts +25 -7
  53. package/src/config.ts +39 -28
  54. package/src/global_variable_builder/global_builder.ts +3 -3
  55. package/src/index.ts +1 -6
  56. package/src/publisher/config.ts +112 -43
  57. package/src/publisher/sequencer-publisher-factory.ts +23 -6
  58. package/src/publisher/sequencer-publisher-metrics.ts +7 -3
  59. package/src/publisher/sequencer-publisher.ts +96 -45
  60. package/src/sequencer/checkpoint_proposal_job.ts +273 -63
  61. package/src/sequencer/checkpoint_voter.ts +32 -7
  62. package/src/sequencer/index.ts +0 -1
  63. package/src/sequencer/metrics.ts +124 -32
  64. package/src/sequencer/sequencer.ts +118 -38
  65. package/src/sequencer/timetable.ts +6 -5
  66. package/src/test/index.ts +2 -4
  67. package/src/test/mock_checkpoint_builder.ts +75 -34
  68. package/src/test/utils.ts +24 -14
  69. package/dest/sequencer/block_builder.d.ts +0 -26
  70. package/dest/sequencer/block_builder.d.ts.map +0 -1
  71. package/dest/sequencer/block_builder.js +0 -129
  72. package/src/sequencer/block_builder.ts +0 -216
@@ -436,21 +436,25 @@ 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 { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
439
440
  import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
440
- import { BlockNumber } from '@aztec/foundation/branded-types';
441
+ import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
441
442
  import { randomInt } from '@aztec/foundation/crypto/random';
442
- import { Signature } from '@aztec/foundation/eth-signature';
443
+ import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
443
444
  import { filter } from '@aztec/foundation/iterator';
445
+ import { createLogger } from '@aztec/foundation/log';
444
446
  import { sleep, sleepUntil } from '@aztec/foundation/sleep';
445
447
  import { Timer } from '@aztec/foundation/timer';
446
- import { unfreeze } from '@aztec/foundation/types';
448
+ import { isErrorClass, unfreeze } from '@aztec/foundation/types';
447
449
  import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
448
450
  import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
449
451
  import { Gas } from '@aztec/stdlib/gas';
452
+ import { NoValidTxsError } from '@aztec/stdlib/interfaces/server';
450
453
  import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
451
- import { orderAttestations } from '@aztec/stdlib/p2p';
454
+ import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
452
455
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
453
456
  import { Attributes, trackSpan } from '@aztec/telemetry-client';
457
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
454
458
  import { CheckpointVoter } from './checkpoint_voter.js';
455
459
  import { SequencerInterruptedError } from './errors.js';
456
460
  import { SequencerState } from './utils.js';
@@ -468,6 +472,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
468
472
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
469
473
  * the Sequencer once the check for being the proposer for the slot has succeeded.
470
474
  */ export class CheckpointProposalJob {
475
+ epoch;
471
476
  slot;
472
477
  checkpointNumber;
473
478
  syncedToBlockNumber;
@@ -480,6 +485,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
480
485
  p2pClient;
481
486
  worldState;
482
487
  l1ToL2MessageSource;
488
+ l2BlockSource;
483
489
  checkpointsBuilder;
484
490
  blockSink;
485
491
  l1Constants;
@@ -491,7 +497,6 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
491
497
  metrics;
492
498
  eventEmitter;
493
499
  setStateFn;
494
- log;
495
500
  tracer;
496
501
  static{
497
502
  ({ e: [_initProto] } = _apply_decs_2203_r(this, [
@@ -537,8 +542,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
537
542
  ]
538
543
  ], []));
539
544
  }
540
- constructor(slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
541
- proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, log, tracer){
545
+ log;
546
+ constructor(epoch, slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
547
+ proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, tracer, bindings){
548
+ this.epoch = epoch;
542
549
  this.slot = slot;
543
550
  this.checkpointNumber = checkpointNumber;
544
551
  this.syncedToBlockNumber = syncedToBlockNumber;
@@ -551,6 +558,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
551
558
  this.p2pClient = p2pClient;
552
559
  this.worldState = worldState;
553
560
  this.l1ToL2MessageSource = l1ToL2MessageSource;
561
+ this.l2BlockSource = l2BlockSource;
554
562
  this.checkpointsBuilder = checkpointsBuilder;
555
563
  this.blockSink = blockSink;
556
564
  this.l1Constants = l1Constants;
@@ -562,9 +570,12 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
562
570
  this.metrics = metrics;
563
571
  this.eventEmitter = eventEmitter;
564
572
  this.setStateFn = setStateFn;
565
- this.log = log;
566
573
  this.tracer = tracer;
567
574
  _initProto(this);
575
+ this.log = createLogger('sequencer:checkpoint-proposal', {
576
+ ...bindings,
577
+ instanceId: `slot-${slot}`
578
+ });
568
579
  }
569
580
  /**
570
581
  * Executes the checkpoint proposal job.
@@ -579,7 +590,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
579
590
  // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
580
591
  await Promise.all(votesPromises);
581
592
  if (checkpoint) {
582
- this.metrics.recordBlockProposalSuccess();
593
+ this.metrics.recordCheckpointProposalSuccess();
583
594
  }
584
595
  // Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
585
596
  if (this.config.fishermanMode) {
@@ -628,11 +639,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
628
639
  // Collect L1 to L2 messages for the checkpoint and compute their hash
629
640
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
630
641
  const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
642
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
643
+ const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
644
+ // Get the fee asset price modifier from the oracle
645
+ const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
631
646
  const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
632
647
  closeDelayMs: 12_000
633
- }), false);
648
+ }), true);
634
649
  // Create checkpoint builder for the entire slot
635
- const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, fork);
650
+ const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
636
651
  // Options for the validator client when creating block and checkpoint proposals
637
652
  const blockProposalOptions = {
638
653
  publishFullTxs: !!this.config.publishTxsWithProposals,
@@ -642,8 +657,23 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
642
657
  publishFullTxs: !!this.config.publishTxsWithProposals,
643
658
  broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
644
659
  };
645
- // Main loop: build blocks for the checkpoint
646
- const { blocksInCheckpoint, blockPendingBroadcast } = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
660
+ let blocksInCheckpoint = [];
661
+ let blockPendingBroadcast = undefined;
662
+ const checkpointBuildTimer = new Timer();
663
+ try {
664
+ // Main loop: build blocks for the checkpoint
665
+ const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
666
+ blocksInCheckpoint = result.blocksInCheckpoint;
667
+ blockPendingBroadcast = result.blockPendingBroadcast;
668
+ } catch (err) {
669
+ // These errors are expected in HA mode, so we yield and let another HA node handle the slot
670
+ // The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
671
+ // which is normal for block building (may have picked different txs)
672
+ if (this.handleHASigningError(err, 'Block proposal')) {
673
+ return undefined;
674
+ }
675
+ throw err;
676
+ }
647
677
  if (blocksInCheckpoint.length === 0) {
648
678
  this.log.warn(`No blocks were built for slot ${this.slot}`, {
649
679
  slot: this.slot
@@ -653,10 +683,21 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
653
683
  });
654
684
  return undefined;
655
685
  }
686
+ const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
687
+ if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
688
+ this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
689
+ slot: this.slot,
690
+ blocksBuilt: blocksInCheckpoint.length,
691
+ minBlocksForCheckpoint
692
+ });
693
+ return undefined;
694
+ }
656
695
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
657
696
  // broadcasted yet, and wait to collect the committee attestations.
658
697
  this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
659
698
  const checkpoint = await checkpointBuilder.completeCheckpoint();
699
+ // Record checkpoint-level build metrics
700
+ this.metrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
660
701
  // Do not collect attestations nor publish to L1 in fisherman mode
661
702
  if (this.config.fishermanMode) {
662
703
  this.log.info(`Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
@@ -674,7 +715,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
674
715
  txs: blockPendingBroadcast.txs
675
716
  };
676
717
  // Create the checkpoint proposal and broadcast it
677
- const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, lastBlock, this.proposer, checkpointProposalOptions);
718
+ const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, feeAssetPriceModifier, lastBlock, this.proposer, checkpointProposalOptions);
678
719
  const blockProposedAt = this.dateProvider.now();
679
720
  await this.p2pClient.broadcastCheckpointProposal(proposal);
680
721
  this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
@@ -683,12 +724,30 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
683
724
  this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
684
725
  // Proposer must sign over the attestations before pushing them to L1
685
726
  const signer = this.proposer ?? this.publisher.getSenderAddress();
686
- const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer);
727
+ let attestationsSignature;
728
+ try {
729
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
730
+ } catch (err) {
731
+ // We shouldn't really get here since we yield to another HA node
732
+ // as soon as we see these errors when creating block or checkpoint proposals.
733
+ if (this.handleHASigningError(err, 'Attestations signature')) {
734
+ return undefined;
735
+ }
736
+ throw err;
737
+ }
687
738
  // Enqueue publishing the checkpoint to L1
688
739
  this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
689
740
  const aztecSlotDuration = this.l1Constants.slotDuration;
690
741
  const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
691
742
  const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
743
+ // If we have been configured to potentially skip publishing checkpoint then roll the dice here
744
+ if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
745
+ const result = Math.max(0, randomInt(100));
746
+ if (result < this.config.skipPublishingCheckpointsPercent) {
747
+ this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`);
748
+ return checkpoint;
749
+ }
750
+ }
692
751
  await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
693
752
  txTimeoutAt,
694
753
  forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
@@ -698,9 +757,14 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
698
757
  env.error = e;
699
758
  env.hasError = true;
700
759
  } finally{
701
- _ts_dispose_resources(env);
760
+ const result = _ts_dispose_resources(env);
761
+ if (result) await result;
702
762
  }
703
763
  } catch (err) {
764
+ if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
765
+ // swallow this error. It's already been logged by a function deeper in the stack
766
+ return undefined;
767
+ }
704
768
  this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
705
769
  return undefined;
706
770
  }
@@ -711,11 +775,13 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
711
775
  const blocksInCheckpoint = [];
712
776
  const txHashesAlreadyIncluded = new Set();
713
777
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
778
+ // Remaining blob fields available for blocks (checkpoint end marker already subtracted)
779
+ let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
714
780
  // Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
715
781
  let blockPendingBroadcast = undefined;
716
782
  while(true){
717
783
  const blocksBuilt = blocksInCheckpoint.length;
718
- const indexWithinCheckpoint = blocksBuilt;
784
+ const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
719
785
  const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
720
786
  const secondsIntoSlot = this.getSecondsIntoSlot();
721
787
  const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
@@ -736,8 +802,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
736
802
  buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
737
803
  blockNumber,
738
804
  indexWithinCheckpoint,
739
- txHashesAlreadyIncluded
805
+ txHashesAlreadyIncluded,
806
+ remainingBlobFields
740
807
  });
808
+ // TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
741
809
  if (!buildResult && timingInfo.isLastBlock) {
742
810
  break;
743
811
  } else if (!buildResult && timingInfo.deadline !== undefined) {
@@ -757,12 +825,21 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
757
825
  }
758
826
  break;
759
827
  }
760
- const { block, usedTxs } = buildResult;
828
+ const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
761
829
  blocksInCheckpoint.push(block);
830
+ // Update remaining blob fields for the next block
831
+ remainingBlobFields = newRemainingBlobFields;
762
832
  // Sync the proposed block to the archiver to make it available
763
833
  // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
764
834
  // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
765
- await this.syncProposedBlockToArchiver(block);
835
+ // Fire and forget - don't block the critical path, but log errors
836
+ this.syncProposedBlockToArchiver(block).catch((err)=>{
837
+ this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
838
+ blockNumber: block.number,
839
+ err
840
+ });
841
+ });
842
+ usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
766
843
  // If this is the last block, exit the loop now so we start collecting attestations
767
844
  if (timingInfo.isLastBlock) {
768
845
  this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
@@ -802,7 +879,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
802
879
  await this.waitUntilTimeInSlot(nextSubslotStart);
803
880
  }
804
881
  /** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
805
- const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
882
+ const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded, remainingBlobFields } = opts;
806
883
  this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`, {
807
884
  ...checkpointBuilder.getConstantData(),
808
885
  ...opts
@@ -827,50 +904,53 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
827
904
  }
828
905
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
829
906
  // just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
830
- const pendingTxs = filter(this.p2pClient.iteratePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
907
+ const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
831
908
  this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
832
909
  slot: this.slot,
833
910
  blockNumber,
834
911
  indexWithinCheckpoint
835
912
  });
836
913
  this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
914
+ // Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
915
+ const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
916
+ const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
837
917
  const blockBuilderOptions = {
838
918
  maxTransactions: this.config.maxTxsPerBlock,
839
919
  maxBlockSize: this.config.maxBlockSizeInBytes,
840
920
  maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
841
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
921
+ maxBlobFields: maxBlobFieldsForTxs,
842
922
  deadline: buildDeadline
843
923
  };
844
924
  // Actually build the block by executing txs
845
- const workTimer = new Timer();
846
- const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs } = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
847
- const blockBuildDuration = workTimer.ms();
925
+ const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
848
926
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
849
- await this.dropFailedTxsFromP2P(failedTxs);
927
+ await this.dropFailedTxsFromP2P(buildResult.failedTxs);
850
928
  // Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
851
929
  // too long, then we may not get to minTxsPerBlock after executing public functions.
852
930
  const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
853
- if (!forceCreate && numTxs < minValidTxs) {
854
- this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed (got ${numTxs} but required ${minValidTxs})`, {
931
+ const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
932
+ if (buildResult.status === 'no-valid-txs' || !forceCreate && numTxs < minValidTxs) {
933
+ this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`, {
855
934
  slot: this.slot,
856
935
  blockNumber,
857
936
  numTxs,
858
- indexWithinCheckpoint
937
+ indexWithinCheckpoint,
938
+ minValidTxs,
939
+ buildResult: buildResult.status
859
940
  });
860
- this.eventEmitter.emit('block-tx-count-check-failed', {
861
- minTxs: minValidTxs,
862
- availableTxs: numTxs,
941
+ this.eventEmitter.emit('block-build-failed', {
942
+ reason: `Insufficient valid txs`,
863
943
  slot: this.slot
864
944
  });
865
945
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
866
946
  return undefined;
867
947
  }
868
948
  // Block creation succeeded, emit stats and metrics
949
+ const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
869
950
  const blockStats = {
870
951
  eventName: 'l2-block-built',
871
952
  duration: blockBuildDuration,
872
953
  publicProcessDuration: publicProcessorDuration,
873
- rollupCircuitsDuration: blockBuildingTimer.ms(),
874
954
  ...block.getStats()
875
955
  };
876
956
  const blockHash = await block.hash();
@@ -889,7 +969,8 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
889
969
  this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
890
970
  return {
891
971
  block,
892
- usedTxs
972
+ usedTxs,
973
+ remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields
893
974
  };
894
975
  } catch (err) {
895
976
  this.eventEmitter.emit('block-build-failed', {
@@ -907,9 +988,30 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
907
988
  };
908
989
  }
909
990
  }
991
+ /** Uses the checkpoint builder to build a block, catching specific txs */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
992
+ try {
993
+ const workTimer = new Timer();
994
+ const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
995
+ const blockBuildDuration = workTimer.ms();
996
+ return {
997
+ ...result,
998
+ blockBuildDuration,
999
+ status: 'success'
1000
+ };
1001
+ } catch (err) {
1002
+ if (isErrorClass(err, NoValidTxsError)) {
1003
+ return {
1004
+ failedTxs: err.failedTxs,
1005
+ status: 'no-valid-txs'
1006
+ };
1007
+ }
1008
+ throw err;
1009
+ }
1010
+ }
910
1011
  /** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
911
- const minTxs = this.config.minTxsPerBlock;
912
1012
  const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
1013
+ // We only allow a block with 0 txs in the first block of the checkpoint
1014
+ const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
913
1015
  // Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
914
1016
  const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
915
1017
  let availableTxs = await this.p2pClient.getPendingTxCount();
@@ -929,7 +1031,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
929
1031
  slot: this.slot,
930
1032
  indexWithinCheckpoint
931
1033
  });
932
- await sleep(TXS_POLLING_MS);
1034
+ await this.waitForTxsPollingInterval();
933
1035
  availableTxs = await this.p2pClient.getPendingTxCount();
934
1036
  }
935
1037
  return {
@@ -964,17 +1066,23 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
964
1066
  return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
965
1067
  }
966
1068
  const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT) : this.l1Constants.slotDuration;
967
- const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
1069
+ const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
968
1070
  this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
969
1071
  const collectAttestationsTimer = new Timer();
970
1072
  let collectedAttestationsCount = 0;
971
1073
  try {
972
1074
  const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
973
1075
  collectedAttestationsCount = attestations.length;
1076
+ // Trim attestations to minimum required to save L1 calldata gas
1077
+ const localAddresses = this.validatorClient.getValidatorAddresses();
1078
+ const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
1079
+ if (trimmed.length < attestations.length) {
1080
+ this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
1081
+ }
974
1082
  // Rollup contract requires that the signatures are provided in the order of the committee
975
- const sorted = orderAttestations(attestations, committee);
1083
+ const sorted = orderAttestations(trimmed, committee);
976
1084
  // Manipulate the attestations if we've been configured to do so
977
- if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
1085
+ if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
978
1086
  return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
979
1087
  }
980
1088
  return new CommitteeAttestationsAndSigners(sorted);
@@ -991,7 +1099,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
991
1099
  // Compute the proposer index in the committee, since we dont want to tweak it.
992
1100
  // Otherwise, the L1 rollup contract will reject the block outright.
993
1101
  const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
994
- if (this.config.injectFakeAttestation) {
1102
+ if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
995
1103
  // Find non-empty attestations that are not from the proposer
996
1104
  const nonProposerIndices = [];
997
1105
  for(let i = 0; i < attestations.length; i++){
@@ -1001,8 +1109,16 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1001
1109
  }
1002
1110
  if (nonProposerIndices.length > 0) {
1003
1111
  const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
1004
- this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1005
- unfreeze(attestations[targetIndex]).signature = Signature.random();
1112
+ if (this.config.injectHighSValueAttestation) {
1113
+ this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1114
+ unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
1115
+ } else if (this.config.injectUnrecoverableSignatureAttestation) {
1116
+ this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1117
+ unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
1118
+ } else {
1119
+ this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1120
+ unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
1121
+ }
1006
1122
  }
1007
1123
  return new CommitteeAttestationsAndSigners(attestations);
1008
1124
  }
@@ -1031,14 +1147,13 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1031
1147
  const failedTxData = failedTxs.map((fail)=>fail.tx);
1032
1148
  const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
1033
1149
  this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
1034
- await this.p2pClient.deleteTxs(failedTxHashes);
1150
+ await this.p2pClient.handleFailedExecution(failedTxHashes);
1035
1151
  }
1036
1152
  /**
1037
1153
  * Adds the proposed block to the archiver so it's available via P2P.
1038
1154
  * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
1039
1155
  * would never receive its own block without this explicit sync.
1040
1156
  */ async syncProposedBlockToArchiver(block) {
1041
- // TODO(palla/mbps): Change default to false once block sync is stable.
1042
1157
  if (this.config.skipPushProposedBlocksToArchiver !== false) {
1043
1158
  this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
1044
1159
  blockNumber: block.number,
@@ -1067,15 +1182,38 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
1067
1182
  slot: this.slot,
1068
1183
  feeAnalysisId: feeAnalysis?.id
1069
1184
  });
1070
- this.metrics.recordBlockProposalFailed('block_build_failed');
1185
+ this.metrics.recordCheckpointProposalFailed('block_build_failed');
1071
1186
  }
1072
1187
  this.publisher.clearPendingRequests();
1073
1188
  }
1189
+ /**
1190
+ * Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
1191
+ */ handleHASigningError(err, errorContext) {
1192
+ if (err instanceof DutyAlreadySignedError) {
1193
+ this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
1194
+ slot: this.slot,
1195
+ signedByNode: err.signedByNode
1196
+ });
1197
+ return true;
1198
+ }
1199
+ if (err instanceof SlashingProtectionError) {
1200
+ this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
1201
+ slot: this.slot,
1202
+ existingMessageHash: err.existingMessageHash,
1203
+ attemptedMessageHash: err.attemptedMessageHash
1204
+ });
1205
+ return true;
1206
+ }
1207
+ return false;
1208
+ }
1074
1209
  /** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
1075
1210
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
1076
1211
  const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
1077
1212
  await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
1078
1213
  }
1214
+ /** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
1215
+ await sleep(TXS_POLLING_MS);
1216
+ }
1079
1217
  getSlotStartBuildTimestamp() {
1080
1218
  return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
1081
1219
  }
@@ -21,7 +21,8 @@ export declare class CheckpointVoter {
21
21
  private readonly metrics;
22
22
  private readonly log;
23
23
  private slotTimestamp;
24
- private signer;
24
+ private governanceSigner;
25
+ private slashingSigner;
25
26
  constructor(slot: SlotNumber, publisher: SequencerPublisher, attestorAddress: EthAddress, validatorClient: ValidatorClient, slasherClient: SlasherClientInterface | undefined, l1Constants: SequencerRollupConstants, config: ResolvedSequencerConfig, metrics: SequencerMetrics, log: Logger);
26
27
  /**
27
28
  * Enqueues governance and slashing votes with the publisher.
@@ -31,4 +32,4 @@ export declare class CheckpointVoter {
31
32
  private enqueueGovernanceVote;
32
33
  private enqueueSlashingVote;
33
34
  }
34
-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EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D;;GAEG;AACH,qBAAa,eAAe;IAMxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbtB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAAuD;IAC/E,OAAO,CAAC,cAAc,CAAuD;IAE7E,YACmB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,kBAAkB,EAC7B,eAAe,EAAE,UAAU,EAC3B,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,sBAAsB,GAAG,SAAS,EACjD,WAAW,EAAE,wBAAwB,EACrC,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EAa7B;IAED;;;OAGG;IACH,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAU3E;YAEa,qBAAqB;YAgCrB,mBAAmB;CAiClC"}
@@ -1,4 +1,6 @@
1
1
  import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
2
+ import { DutyAlreadySignedError } from '@aztec/validator-ha-signer/errors';
3
+ import { DutyType } from '@aztec/validator-ha-signer/types';
2
4
  /**
3
5
  * Handles governance and slashing voting for a given slot.
4
6
  */ export class CheckpointVoter {
@@ -12,7 +14,8 @@ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
12
14
  metrics;
13
15
  log;
14
16
  slotTimestamp;
15
- signer;
17
+ governanceSigner;
18
+ slashingSigner;
16
19
  constructor(slot, publisher, attestorAddress, validatorClient, slasherClient, l1Constants, config, metrics, log){
17
20
  this.slot = slot;
18
21
  this.publisher = publisher;
@@ -24,7 +27,18 @@ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
24
27
  this.metrics = metrics;
25
28
  this.log = log;
26
29
  this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
27
- this.signer = (msg)=>this.validatorClient.signWithAddress(this.attestorAddress, msg).then((s)=>s.toString());
30
+ // Create separate signers with appropriate duty contexts for governance and slashing votes
31
+ // These use HA protection to ensure only one node signs per slot/duty
32
+ const governanceContext = {
33
+ slot: this.slot,
34
+ dutyType: DutyType.GOVERNANCE_VOTE
35
+ };
36
+ this.governanceSigner = (msg)=>this.validatorClient.signWithAddress(this.attestorAddress, msg, governanceContext).then((s)=>s.toString());
37
+ const slashingContext = {
38
+ slot: this.slot,
39
+ dutyType: DutyType.SLASHING_VOTE
40
+ };
41
+ this.slashingSigner = (msg)=>this.validatorClient.signWithAddress(this.attestorAddress, msg, slashingContext).then((s)=>s.toString());
28
42
  }
29
43
  /**
30
44
  * Enqueues governance and slashing votes with the publisher.
@@ -55,11 +69,16 @@ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
55
69
  governanceProposerPayload: governanceProposerPayload.toString()
56
70
  });
57
71
  try {
58
- return await this.publisher.enqueueGovernanceCastSignal(governanceProposerPayload, this.slot, this.slotTimestamp, this.attestorAddress, this.signer);
72
+ return await this.publisher.enqueueGovernanceCastSignal(governanceProposerPayload, this.slot, this.slotTimestamp, this.attestorAddress, this.governanceSigner);
59
73
  } catch (err) {
60
- this.log.error(`Error enqueuing governance vote`, err, {
61
- slot: this.slot
62
- });
74
+ if (err instanceof DutyAlreadySignedError) {
75
+ this.log.info(`Governance vote already signed by another node`, {
76
+ slot: this.slot,
77
+ signedByNode: err.signedByNode
78
+ });
79
+ } else {
80
+ this.log.error(`Error enqueueing governance vote`, err);
81
+ }
63
82
  return false;
64
83
  }
65
84
  }
@@ -74,11 +93,16 @@ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
74
93
  actionCount: actions.length
75
94
  });
76
95
  this.metrics.recordSlashingAttempt(actions.length);
77
- return await this.publisher.enqueueSlashingActions(actions, this.slot, this.slotTimestamp, this.attestorAddress, this.signer);
96
+ return await this.publisher.enqueueSlashingActions(actions, this.slot, this.slotTimestamp, this.attestorAddress, this.slashingSigner);
78
97
  } catch (err) {
79
- this.log.error(`Error enqueuing slashing vote`, err, {
80
- slot: this.slot
81
- });
98
+ if (err instanceof DutyAlreadySignedError) {
99
+ this.log.info(`Slashing vote already signed by another node`, {
100
+ slot: this.slot,
101
+ signedByNode: err.signedByNode
102
+ });
103
+ } else {
104
+ this.log.error(`Error enqueueing slashing vote`, err);
105
+ }
82
106
  return false;
83
107
  }
84
108
  }
@@ -1,7 +1,6 @@
1
- export * from './block_builder.js';
2
1
  export * from './checkpoint_proposal_job.js';
3
2
  export * from './checkpoint_voter.js';
4
3
  export * from './config.js';
5
4
  export * from './events.js';
6
5
  export * from './sequencer.js';
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXF1ZW5jZXIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxvQkFBb0IsQ0FBQztBQUNuQyxjQUFjLDhCQUE4QixDQUFDO0FBQzdDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyxhQUFhLENBQUM7QUFDNUIsY0FBYyxhQUFhLENBQUM7QUFDNUIsY0FBYyxnQkFBZ0IsQ0FBQyJ9
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXF1ZW5jZXIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyw4QkFBOEIsQ0FBQztBQUM3QyxjQUFjLHVCQUF1QixDQUFDO0FBQ3RDLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsZ0JBQWdCLENBQUMifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sequencer/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sequencer/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
@@ -1,4 +1,3 @@
1
- export * from './block_builder.js';
2
1
  export * from './checkpoint_proposal_job.js';
3
2
  export * from './checkpoint_voter.js';
4
3
  export * from './config.js';