@aztec/archiver 0.0.1-commit.e558bd1c → 0.0.1-commit.e588bc7e5

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 (110) hide show
  1. package/README.md +12 -6
  2. package/dest/archiver.d.ts +9 -6
  3. package/dest/archiver.d.ts.map +1 -1
  4. package/dest/archiver.js +78 -113
  5. package/dest/config.d.ts +3 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +2 -1
  8. package/dest/errors.d.ts +34 -10
  9. package/dest/errors.d.ts.map +1 -1
  10. package/dest/errors.js +45 -16
  11. package/dest/factory.d.ts +4 -5
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +31 -26
  14. package/dest/index.d.ts +2 -1
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -0
  17. package/dest/l1/bin/retrieve-calldata.js +32 -28
  18. package/dest/l1/calldata_retriever.d.ts +73 -50
  19. package/dest/l1/calldata_retriever.d.ts.map +1 -1
  20. package/dest/l1/calldata_retriever.js +191 -259
  21. package/dest/l1/data_retrieval.d.ts +10 -10
  22. package/dest/l1/data_retrieval.d.ts.map +1 -1
  23. package/dest/l1/data_retrieval.js +34 -33
  24. package/dest/l1/spire_proposer.d.ts +5 -5
  25. package/dest/l1/spire_proposer.d.ts.map +1 -1
  26. package/dest/l1/spire_proposer.js +9 -17
  27. package/dest/modules/data_source_base.d.ts +14 -7
  28. package/dest/modules/data_source_base.d.ts.map +1 -1
  29. package/dest/modules/data_source_base.js +39 -77
  30. package/dest/modules/data_store_updater.d.ts +25 -12
  31. package/dest/modules/data_store_updater.d.ts.map +1 -1
  32. package/dest/modules/data_store_updater.js +125 -94
  33. package/dest/modules/instrumentation.d.ts +15 -2
  34. package/dest/modules/instrumentation.d.ts.map +1 -1
  35. package/dest/modules/instrumentation.js +19 -2
  36. package/dest/modules/l1_synchronizer.d.ts +7 -9
  37. package/dest/modules/l1_synchronizer.d.ts.map +1 -1
  38. package/dest/modules/l1_synchronizer.js +176 -136
  39. package/dest/modules/validation.d.ts +1 -1
  40. package/dest/modules/validation.d.ts.map +1 -1
  41. package/dest/modules/validation.js +2 -2
  42. package/dest/store/block_store.d.ts +65 -28
  43. package/dest/store/block_store.d.ts.map +1 -1
  44. package/dest/store/block_store.js +311 -134
  45. package/dest/store/contract_class_store.d.ts +2 -3
  46. package/dest/store/contract_class_store.d.ts.map +1 -1
  47. package/dest/store/contract_class_store.js +7 -67
  48. package/dest/store/contract_instance_store.d.ts +1 -1
  49. package/dest/store/contract_instance_store.d.ts.map +1 -1
  50. package/dest/store/contract_instance_store.js +6 -2
  51. package/dest/store/kv_archiver_store.d.ts +61 -24
  52. package/dest/store/kv_archiver_store.d.ts.map +1 -1
  53. package/dest/store/kv_archiver_store.js +75 -27
  54. package/dest/store/l2_tips_cache.d.ts +20 -0
  55. package/dest/store/l2_tips_cache.d.ts.map +1 -0
  56. package/dest/store/l2_tips_cache.js +109 -0
  57. package/dest/store/log_store.d.ts +6 -3
  58. package/dest/store/log_store.d.ts.map +1 -1
  59. package/dest/store/log_store.js +93 -16
  60. package/dest/store/message_store.d.ts +5 -1
  61. package/dest/store/message_store.d.ts.map +1 -1
  62. package/dest/store/message_store.js +21 -9
  63. package/dest/test/fake_l1_state.d.ts +14 -1
  64. package/dest/test/fake_l1_state.d.ts.map +1 -1
  65. package/dest/test/fake_l1_state.js +120 -26
  66. package/dest/test/mock_archiver.d.ts +1 -1
  67. package/dest/test/mock_archiver.d.ts.map +1 -1
  68. package/dest/test/mock_archiver.js +3 -2
  69. package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
  70. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  71. package/dest/test/mock_l1_to_l2_message_source.js +2 -1
  72. package/dest/test/mock_l2_block_source.d.ts +26 -5
  73. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  74. package/dest/test/mock_l2_block_source.js +160 -89
  75. package/dest/test/mock_structs.d.ts +4 -1
  76. package/dest/test/mock_structs.d.ts.map +1 -1
  77. package/dest/test/mock_structs.js +13 -1
  78. package/dest/test/noop_l1_archiver.d.ts +4 -1
  79. package/dest/test/noop_l1_archiver.d.ts.map +1 -1
  80. package/dest/test/noop_l1_archiver.js +5 -1
  81. package/package.json +13 -13
  82. package/src/archiver.ts +97 -133
  83. package/src/config.ts +8 -1
  84. package/src/errors.ts +70 -26
  85. package/src/factory.ts +46 -24
  86. package/src/index.ts +1 -0
  87. package/src/l1/README.md +25 -68
  88. package/src/l1/bin/retrieve-calldata.ts +40 -27
  89. package/src/l1/calldata_retriever.ts +250 -379
  90. package/src/l1/data_retrieval.ts +30 -36
  91. package/src/l1/spire_proposer.ts +7 -15
  92. package/src/modules/data_source_base.ts +78 -98
  93. package/src/modules/data_store_updater.ts +138 -124
  94. package/src/modules/instrumentation.ts +29 -2
  95. package/src/modules/l1_synchronizer.ts +195 -168
  96. package/src/modules/validation.ts +2 -2
  97. package/src/store/block_store.ts +393 -170
  98. package/src/store/contract_class_store.ts +8 -106
  99. package/src/store/contract_instance_store.ts +8 -5
  100. package/src/store/kv_archiver_store.ts +115 -41
  101. package/src/store/l2_tips_cache.ts +128 -0
  102. package/src/store/log_store.ts +126 -27
  103. package/src/store/message_store.ts +27 -10
  104. package/src/structs/inbox_message.ts +1 -1
  105. package/src/test/fake_l1_state.ts +163 -30
  106. package/src/test/mock_archiver.ts +3 -2
  107. package/src/test/mock_l1_to_l2_message_source.ts +1 -0
  108. package/src/test/mock_l2_block_source.ts +209 -82
  109. package/src/test/mock_structs.ts +20 -6
  110. package/src/test/noop_l1_archiver.ts +7 -1
@@ -1 +1 @@
1
- {"version":3,"file":"l1_synchronizer.d.ts","sourceRoot":"","sources":["../../src/modules/l1_synchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD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E,eAAe,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,WAAW,EACR,GAAG,GAAE,MAAyC,EAMhE;IAED,sBAAsB;IACf,SAAS,CAAC,SAAS,EAAE;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,kCAAkC,CAAC,EAAE,OAAO,CAAC;QAC7C,+BAA+B,EAAE,MAAM,CAAC;KACzC,QAEA;IAED,wDAAwD;IACjD,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAE5C;IAED,qDAAqD;IAC9C,cAAc,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED,6HAA6H;IAChH,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAYnD;IAGY,UAAU,CAAC,mBAAmB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFnE;YAGa,yBAAyB;YAwBzB,yBAAyB;YA0CzB,QAAQ;YAeR,gBAAgB;IA+D9B,OAAO,CAAC,SAAS;YAWH,oBAAoB;YA6DpB,iBAAiB;YAWjB,wBAAwB;YAkCxB,sBAAsB;YAgDtB,cAAc;YASd,iBAAiB;YAkXjB,uCAAuC;YA8CvC,mBAAmB;CAOlC"}
@@ -371,20 +371,23 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
371
  return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
372
  }
373
373
  var _dec, _dec1, _dec2, _dec3, _initProto;
374
+ import { asyncPool } from '@aztec/foundation/async-pool';
374
375
  import { maxBigint } from '@aztec/foundation/bigint';
375
376
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
376
- import { Buffer32 } from '@aztec/foundation/buffer';
377
+ import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
377
378
  import { pick } from '@aztec/foundation/collection';
378
379
  import { createLogger } from '@aztec/foundation/log';
380
+ import { retryTimes } from '@aztec/foundation/retry';
379
381
  import { count } from '@aztec/foundation/string';
380
382
  import { Timer, elapsed } from '@aztec/foundation/timer';
381
- import { isDefined } from '@aztec/foundation/types';
383
+ import { isDefined, isErrorClass } from '@aztec/foundation/types';
382
384
  import { L2BlockSourceEvents } from '@aztec/stdlib/block';
383
385
  import { getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
384
386
  import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
385
387
  import { execInSpan, trackSpan } from '@aztec/telemetry-client';
386
388
  import { InitialCheckpointNumberNotSequentialError } from '../errors.js';
387
389
  import { retrieveCheckpointsFromRollup, retrieveL1ToL2Message, retrieveL1ToL2Messages, retrievedToPublishedCheckpoint } from '../l1/data_retrieval.js';
390
+ import { MessageStoreError } from '../store/message_store.js';
388
391
  import { ArchiverDataStoreUpdater } from './data_store_updater.js';
389
392
  import { validateCheckpointAttestations } from './validation.js';
390
393
  _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpochPrune'), _dec2 = trackSpan('Archiver.handleL1ToL2Messages'), _dec3 = trackSpan('Archiver.handleCheckpoints');
@@ -396,7 +399,6 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
396
399
  debugClient;
397
400
  rollup;
398
401
  inbox;
399
- l1Addresses;
400
402
  store;
401
403
  config;
402
404
  blobClient;
@@ -435,12 +437,11 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
435
437
  l1Timestamp;
436
438
  updater;
437
439
  tracer;
438
- constructor(publicClient, debugClient, rollup, inbox, l1Addresses, store, config, blobClient, epochCache, dateProvider, instrumentation, l1Constants, events, tracer, log = createLogger('archiver:l1-sync')){
440
+ constructor(publicClient, debugClient, rollup, inbox, store, config, blobClient, epochCache, dateProvider, instrumentation, l1Constants, events, tracer, l2TipsCache, log = createLogger('archiver:l1-sync')){
439
441
  this.publicClient = publicClient;
440
442
  this.debugClient = debugClient;
441
443
  this.rollup = rollup;
442
444
  this.inbox = inbox;
443
- this.l1Addresses = l1Addresses;
444
445
  this.store = store;
445
446
  this.config = config;
446
447
  this.blobClient = blobClient;
@@ -451,7 +452,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
451
452
  this.events = events;
452
453
  this.log = log;
453
454
  _initProto(this);
454
- this.updater = new ArchiverDataStoreUpdater(this.store);
455
+ this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache, {
456
+ rollupManaLimit: l1Constants.rollupManaLimit
457
+ });
455
458
  this.tracer = tracer;
456
459
  }
457
460
  /** Sets new config */ setConfig(newConfig) {
@@ -477,12 +480,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
477
480
  }
478
481
  }
479
482
  async syncFromL1(initialSyncComplete) {
483
+ // In between the various calls to L1, the block number can move meaning some of the following
484
+ // calls will return data for blocks that were not present during earlier calls. To combat this
485
+ // we ensure that all data retrieval methods only retrieve data up to the currentBlockNumber
486
+ // captured at the top of this function.
480
487
  const currentL1Block = await this.publicClient.getBlock({
481
488
  includeTransactions: false
482
489
  });
483
490
  const currentL1BlockNumber = currentL1Block.number;
484
491
  const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
485
492
  const currentL1Timestamp = currentL1Block.timestamp;
493
+ const currentL1BlockData = {
494
+ l1BlockNumber: currentL1BlockNumber,
495
+ l1BlockHash: currentL1BlockHash
496
+ };
486
497
  if (this.l1BlockHash && currentL1BlockHash.equals(this.l1BlockHash)) {
487
498
  this.log.trace(`No new L1 blocks since last sync at L1 block ${this.l1BlockNumber}`);
488
499
  return;
@@ -498,36 +509,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
498
509
  maxAllowedDelay
499
510
  });
500
511
  }
501
- // Load sync point for blocks and messages defaulting to start block
502
- const { blocksSynchedTo = this.l1Constants.l1StartBlock, messagesSynchedTo = {
503
- l1BlockNumber: this.l1Constants.l1StartBlock,
504
- l1BlockHash: this.l1Constants.l1StartBlockHash
505
- } } = await this.store.getSynchPoint();
512
+ // Load sync point for blocks defaulting to start block
513
+ const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await this.store.getSynchPoint();
506
514
  this.log.debug(`Starting new archiver sync iteration`, {
507
515
  blocksSynchedTo,
508
- messagesSynchedTo,
509
- currentL1BlockNumber,
510
- currentL1BlockHash
516
+ currentL1BlockData
511
517
  });
512
- // ********** Ensuring Consistency of data pulled from L1 **********
513
- /**
514
- * There are a number of calls in this sync operation to L1 for retrieving
515
- * events and transaction data. There are a couple of things we need to bear in mind
516
- * to ensure that data is read exactly once.
517
- *
518
- * The first is the problem of eventually consistent ETH service providers like Infura.
519
- * Each L1 read operation will query data from the last L1 block that it saw emit its kind of data.
520
- * (so pending L1 to L2 messages will read from the last L1 block that emitted a message and so on)
521
- * This will mean the archiver will lag behind L1 and will only advance when there's L2-relevant activity on the chain.
522
- *
523
- * The second is that in between the various calls to L1, the block number can move meaning some
524
- * of the following calls will return data for blocks that were not present during earlier calls.
525
- * To combat this for the time being we simply ensure that all data retrieval methods only retrieve
526
- * data up to the currentBlockNumber captured at the top of this function. We might want to improve on this
527
- * in future but for the time being it should give us the guarantees that we need
528
- */ // ********** Events that are processed per L1 block **********
529
- await this.handleL1ToL2Messages(messagesSynchedTo, currentL1BlockNumber);
530
- // ********** Events that are processed per checkpoint **********
518
+ // Sync L1 to L2 messages. We retry this a few times since there are error conditions that reset the sync point, requiring a new iteration.
519
+ // Note that we cannot just wait for the l1 synchronizer to loop again, since the synchronizer would report as synced up to the current L1
520
+ // block, when that wouldn't be the case, since L1 to L2 messages would need another iteration.
521
+ await retryTimes(()=>this.handleL1ToL2Messages(currentL1BlockData), 'Handling L1 to L2 messages', 3, 0.1);
531
522
  if (currentL1BlockNumber > blocksSynchedTo) {
532
523
  // First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
533
524
  // pending chain validation status, proven checkpoint number, and synched L1 block number.
@@ -555,6 +546,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
555
546
  }
556
547
  this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
557
548
  }
549
+ // Update the finalized L2 checkpoint based on L1 finality.
550
+ await this.updateFinalizedCheckpoint();
558
551
  // After syncing has completed, update the current l1 block number and timestamp,
559
552
  // otherwise we risk announcing to the world that we've synced to a given point,
560
553
  // but the corresponding blocks have not been processed (see #12631).
@@ -568,6 +561,31 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
568
561
  l1BlockNumberAtEnd
569
562
  });
570
563
  }
564
+ /** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
565
+ try {
566
+ const finalizedL1Block = await this.publicClient.getBlock({
567
+ blockTag: 'finalized',
568
+ includeTransactions: false
569
+ });
570
+ const finalizedL1BlockNumber = finalizedL1Block.number;
571
+ const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
572
+ blockNumber: finalizedL1BlockNumber
573
+ });
574
+ const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
575
+ if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
576
+ await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
577
+ this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
578
+ finalizedCheckpointNumber,
579
+ finalizedL1BlockNumber
580
+ });
581
+ }
582
+ } catch (err) {
583
+ // The rollup contract may not exist at the finalized L1 block right after deployment.
584
+ if (!err?.message?.includes('returned no data')) {
585
+ this.log.warn(`Failed to update finalized checkpoint: ${err}`);
586
+ }
587
+ }
588
+ }
571
589
  /** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
572
590
  const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
573
591
  this.store.getCheckpointedL2BlockNumber(),
@@ -578,26 +596,28 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
578
596
  this.log.trace(`No uncheckpointed blocks to prune.`);
579
597
  return;
580
598
  }
581
- // What's the slot of the first uncheckpointed block?
599
+ // What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
600
+ const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
582
601
  const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
602
+ // What's the slot of the first uncheckpointed block?
583
603
  const [firstUncheckpointedBlockHeader] = await this.store.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
584
604
  const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
585
- // What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
586
- const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
587
- // Prune provisional blocks from slots that have ended without being checkpointed
588
- if (firstUncheckpointedBlockSlot !== undefined && firstUncheckpointedBlockSlot < slotAtNextL1Block) {
589
- this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
590
- firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
591
- slotAtNextL1Block
605
+ if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
606
+ return;
607
+ }
608
+ // Prune provisional blocks from slots that have ended without being checkpointed.
609
+ // This also clears any proposed checkpoint whose blocks are being pruned.
610
+ this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
611
+ firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
612
+ slotAtNextL1Block
613
+ });
614
+ const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
615
+ if (prunedBlocks.length > 0) {
616
+ this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
617
+ type: L2BlockSourceEvents.L2PruneUncheckpointed,
618
+ slotNumber: firstUncheckpointedBlockSlot,
619
+ blocks: prunedBlocks
592
620
  });
593
- const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
594
- if (prunedBlocks.length > 0) {
595
- this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
596
- type: L2BlockSourceEvents.L2PruneUncheckpointed,
597
- slotNumber: firstUncheckpointedBlockSlot,
598
- blocks: prunedBlocks
599
- });
600
- }
601
621
  }
602
622
  }
603
623
  /** Queries the rollup contract on whether a prune can be executed on the immediate next L1 block. */ async canPrune(currentL1BlockNumber, currentL1Timestamp) {
@@ -628,12 +648,14 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
628
648
  const pruneFromSlotNumber = header.slotNumber;
629
649
  const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1Constants);
630
650
  const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
631
- const checkpointPromises = Array.from({
651
+ // Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
652
+ // promises when the gap between local pending and proven checkpoint numbers is large.
653
+ const BATCH_SIZE = 10;
654
+ const indices = Array.from({
632
655
  length: checkpointsToUnwind
633
- }).fill(0).map((_, i)=>this.store.getCheckpointData(CheckpointNumber(i + pruneFrom)));
634
- const checkpoints = await Promise.all(checkpointPromises);
635
- const blockPromises = await Promise.all(checkpoints.filter(isDefined).map((cp)=>this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber))));
636
- const newBlocks = blockPromises.filter(isDefined).flat();
656
+ }, (_, i)=>CheckpointNumber(i + pruneFrom));
657
+ const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.store.getCheckpointData(idx))).filter(isDefined);
658
+ const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
637
659
  // Emit an event for listening services to react to the chain prune
638
660
  this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
639
661
  type: L2BlockSourceEvents.L2PruneUnproven,
@@ -667,55 +689,75 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
667
689
  nextEnd
668
690
  ];
669
691
  }
670
- async handleL1ToL2Messages(messagesSyncPoint, currentL1BlockNumber) {
671
- this.log.trace(`Handling L1 to L2 messages from ${messagesSyncPoint.l1BlockNumber} to ${currentL1BlockNumber}.`);
672
- if (currentL1BlockNumber <= messagesSyncPoint.l1BlockNumber) {
673
- return;
692
+ async handleL1ToL2Messages(currentL1Block) {
693
+ // Load the syncpoint, which may have been updated in a previous iteration
694
+ const { messagesSynchedTo = {
695
+ l1BlockNumber: this.l1Constants.l1StartBlock,
696
+ l1BlockHash: this.l1Constants.l1StartBlockHash
697
+ } } = await this.store.getSynchPoint();
698
+ // Nothing to do if L1 block number has not moved forward
699
+ const currentL1BlockNumber = currentL1Block.l1BlockNumber;
700
+ if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
701
+ return true;
674
702
  }
675
- // Load remote and local inbox states.
676
- const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
677
- const localLastMessage = await this.store.getLastL1ToL2Message();
703
+ // Compare local message store state with the remote. If they match, we just advance the match pointer.
678
704
  const remoteMessagesState = await this.inbox.getState({
679
705
  blockNumber: currentL1BlockNumber
680
706
  });
681
- this.log.trace(`Retrieved remote inbox state at L1 block ${currentL1BlockNumber}.`, {
682
- localMessagesInserted,
683
- localLastMessage,
684
- remoteMessagesState
685
- });
686
- // Compare message count and rolling hash. If they match, no need to retrieve anything.
687
- if (remoteMessagesState.totalMessagesInserted === localMessagesInserted && remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer32.ZERO)) {
688
- this.log.trace(`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`);
689
- return;
707
+ const localLastMessage = await this.store.getLastL1ToL2Message();
708
+ if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
709
+ this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
710
+ await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
711
+ return true;
690
712
  }
691
- // Check if our syncpoint is still valid. If not, there was an L1 reorg and we need to re-retrieve messages.
692
- // Note that we need to fetch it from logs and not from inbox state at the syncpoint l1 block number, since it
693
- // could be older than 128 blocks and non-archive nodes cannot resolve it.
694
- if (localLastMessage) {
695
- const remoteLastMessage = await this.retrieveL1ToL2Message(localLastMessage.leaf);
696
- this.log.trace(`Retrieved remote message for local last`, {
697
- remoteLastMessage,
698
- localLastMessage
699
- });
700
- if (!remoteLastMessage || !remoteLastMessage.rollingHash.equals(localLastMessage.rollingHash)) {
701
- this.log.warn(`Rolling back L1 to L2 messages due to hash mismatch or msg not found.`, {
702
- remoteLastMessage,
703
- messagesSyncPoint,
704
- localLastMessage
705
- });
706
- messagesSyncPoint = await this.rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint);
707
- this.log.debug(`Rolled back L1 to L2 messages to L1 block ${messagesSyncPoint.l1BlockNumber}.`, {
708
- messagesSyncPoint
713
+ // If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
714
+ // However, it could also be the case that there was an L1 reorg and our syncpoint is no longer valid.
715
+ // If that's the case, we'd get an exception out of the message store since the rolling hash of the first message
716
+ // we try to insert would not match the one in the db, in which case we rollback to the last common message with L1.
717
+ try {
718
+ await this.retrieveAndStoreMessages(messagesSynchedTo.l1BlockNumber, currentL1BlockNumber);
719
+ } catch (error) {
720
+ if (isErrorClass(error, MessageStoreError)) {
721
+ this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
722
+ inboxMessage: error.inboxMessage
709
723
  });
724
+ await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
725
+ return false;
710
726
  }
727
+ throw error;
711
728
  }
712
- // Retrieve and save messages in batches. Each batch is estimated to acommodate up to L2 'blockBatchSize' blocks,
729
+ // Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
730
+ // we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
731
+ // our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
732
+ const localLastMessageAfterSync = await this.store.getLastL1ToL2Message();
733
+ if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
734
+ this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
735
+ localLastMessageAfterSync,
736
+ remoteMessagesState
737
+ });
738
+ await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
739
+ return false;
740
+ }
741
+ // Advance the syncpoint after a successful sync
742
+ await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
743
+ return true;
744
+ }
745
+ /** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
746
+ const localMessageCount = await this.store.getTotalL1ToL2MessageCount();
747
+ this.log.trace(`Comparing local and remote inbox state`, {
748
+ localMessageCount,
749
+ localLastMessage,
750
+ remoteState
751
+ });
752
+ return remoteState.totalMessagesInserted === localMessageCount && remoteState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO);
753
+ }
754
+ /** Retrieves L1 to L2 messages from L1 in batches and stores them. */ async retrieveAndStoreMessages(fromL1Block, toL1Block) {
713
755
  let searchStartBlock = 0n;
714
- let searchEndBlock = messagesSyncPoint.l1BlockNumber;
756
+ let searchEndBlock = fromL1Block;
715
757
  let lastMessage;
716
758
  let messageCount = 0;
717
759
  do {
718
- [searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
760
+ [searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, toL1Block);
719
761
  this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
720
762
  const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
721
763
  const timer = new Timer();
@@ -730,74 +772,65 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
730
772
  lastMessage = msg;
731
773
  messageCount++;
732
774
  }
733
- }while (searchEndBlock < currentL1BlockNumber)
734
- // Log stats for messages retrieved (if any).
775
+ }while (searchEndBlock < toL1Block)
735
776
  if (messageCount > 0) {
736
777
  this.log.info(`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`, {
737
778
  lastMessage,
738
779
  messageCount
739
780
  });
740
781
  }
741
- // Warn if the resulting rolling hash does not match the remote state we had retrieved.
742
- if (lastMessage && !lastMessage.rollingHash.equals(remoteMessagesState.messagesRollingHash)) {
743
- this.log.warn(`Last message retrieved rolling hash does not match remote state.`, {
744
- lastMessage,
745
- remoteMessagesState
746
- });
747
- }
748
782
  }
749
- async retrieveL1ToL2Message(leaf) {
750
- const currentL1BlockNumber = await this.publicClient.getBlockNumber();
751
- let searchStartBlock = 0n;
752
- let searchEndBlock = this.l1Constants.l1StartBlock - 1n;
753
- do {
754
- [searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
755
- const message = await retrieveL1ToL2Message(this.inbox, leaf, searchStartBlock, searchEndBlock);
756
- if (message) {
757
- return message;
758
- }
759
- }while (searchEndBlock < currentL1BlockNumber)
760
- return undefined;
761
- }
762
- async rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint) {
783
+ /**
784
+ * Rolls back local L1 to L2 messages to the last common message with L1, and updates the syncpoint to the L1 block of that message.
785
+ * If no common message is found, rolls back all messages and sets the syncpoint to the start block.
786
+ */ async rollbackL1ToL2Messages(remoteTreeInProgress) {
763
787
  // Slowly go back through our messages until we find the last common message.
764
788
  // We could query the logs in batch as an optimization, but the depth of the reorg should not be deep, and this
765
789
  // is a very rare case, so it's fine to query one log at a time.
766
790
  let commonMsg;
767
- this.log.verbose(`Searching most recent common L1 to L2 message at or before index ${localLastMessage.index}`);
768
- for await (const msg of this.store.iterateL1ToL2Messages({
769
- reverse: true,
770
- end: localLastMessage.index
791
+ let messagesToDelete = 0;
792
+ this.log.verbose(`Searching most recent common L1 to L2 message`);
793
+ for await (const localMsg of this.store.iterateL1ToL2Messages({
794
+ reverse: true
771
795
  })){
772
- const remoteMsg = await this.retrieveL1ToL2Message(msg.leaf);
796
+ const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
773
797
  const logCtx = {
774
798
  remoteMsg,
775
- localMsg: msg
799
+ localMsg: localMsg
776
800
  };
777
- if (remoteMsg && remoteMsg.rollingHash.equals(msg.rollingHash)) {
778
- this.log.verbose(`Found most recent common L1 to L2 message at index ${msg.index} on L1 block ${msg.l1BlockNumber}`, logCtx);
801
+ if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
802
+ this.log.verbose(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
779
803
  commonMsg = remoteMsg;
780
804
  break;
781
805
  } else if (remoteMsg) {
782
- this.log.debug(`Local L1 to L2 message with index ${msg.index} has different rolling hash`, logCtx);
806
+ this.log.debug(`Local L1 to L2 message with index ${localMsg.index} has different rolling hash`, logCtx);
807
+ messagesToDelete++;
783
808
  } else {
784
- this.log.debug(`Local L1 to L2 message with index ${msg.index} not found on L1`, logCtx);
809
+ this.log.debug(`Local L1 to L2 message with index ${localMsg.index} not found on L1`, logCtx);
810
+ messagesToDelete++;
785
811
  }
786
812
  }
787
- // Delete everything after the common message we found.
788
- const lastGoodIndex = commonMsg?.index;
789
- this.log.warn(`Deleting all local L1 to L2 messages after index ${lastGoodIndex ?? 'undefined'}`);
790
- await this.store.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
813
+ // Delete everything after the common message we found, if anything needs to be deleted.
814
+ // Do not exit early if there are no messages to delete, we still want to update the syncpoint.
815
+ if (messagesToDelete > 0) {
816
+ const lastGoodIndex = commonMsg?.index;
817
+ this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
818
+ await this.store.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
819
+ }
791
820
  // Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
792
821
  // the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
793
822
  // after the last common message.
794
823
  const syncPointL1BlockNumber = commonMsg ? commonMsg.l1BlockNumber - 1n : this.l1Constants.l1StartBlock;
795
824
  const syncPointL1BlockHash = await this.getL1BlockHash(syncPointL1BlockNumber);
796
- messagesSyncPoint = {
825
+ const messagesSyncPoint = {
797
826
  l1BlockNumber: syncPointL1BlockNumber,
798
827
  l1BlockHash: syncPointL1BlockHash
799
828
  };
800
- await this.store.setMessageSynchedL1Block(messagesSyncPoint);
829
+ await this.store.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
830
+ this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
831
+ ...messagesSyncPoint,
832
+ remoteTreeInProgress
833
+ });
801
834
  return messagesSyncPoint;
802
835
  }
803
836
  async getL1BlockHash(l1BlockNumber) {
@@ -837,7 +870,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
837
870
  if (provenCheckpointNumber === 0) {
838
871
  const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
839
872
  if (localProvenCheckpointNumber !== provenCheckpointNumber) {
840
- await this.store.setProvenCheckpointNumber(provenCheckpointNumber);
873
+ await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
841
874
  this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, {
842
875
  provenCheckpointNumber
843
876
  });
@@ -854,20 +887,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
854
887
  if (localCheckpointForDestinationProvenCheckpointNumber && provenArchive.equals(localCheckpointForDestinationProvenCheckpointNumber.archive.root)) {
855
888
  const localProvenCheckpointNumber = await this.store.getProvenCheckpointNumber();
856
889
  if (localProvenCheckpointNumber !== provenCheckpointNumber) {
857
- await this.store.setProvenCheckpointNumber(provenCheckpointNumber);
890
+ await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
858
891
  this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
859
892
  provenCheckpointNumber
860
893
  });
861
894
  const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
862
895
  const provenEpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
863
- const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.numBlocks - 1;
896
+ const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.blockCount - 1;
864
897
  this.events.emit(L2BlockSourceEvents.L2BlockProven, {
865
898
  type: L2BlockSourceEvents.L2BlockProven,
866
899
  blockNumber: BlockNumber(lastBlockNumberInCheckpoint),
867
900
  slotNumber: provenSlotNumber,
868
901
  epochNumber: provenEpochNumber
869
902
  });
870
- this.instrumentation.updateLastProvenBlock(lastBlockNumberInCheckpoint);
903
+ this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
871
904
  } else {
872
905
  this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
873
906
  }
@@ -945,7 +978,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
945
978
  [searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
946
979
  this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
947
980
  // TODO(md): Retrieve from blob client then from consensus client, then from peers
948
- const retrievedCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointsFromRollup', ()=>retrieveCheckpointsFromRollup(this.rollup, this.publicClient, this.debugClient, this.blobClient, searchStartBlock, searchEndBlock, this.l1Addresses, this.instrumentation, this.log, !initialSyncComplete));
981
+ const retrievedCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointsFromRollup', ()=>retrieveCheckpointsFromRollup(this.rollup, this.publicClient, this.debugClient, this.blobClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log, !initialSyncComplete));
949
982
  if (retrievedCheckpoints.length === 0) {
950
983
  // We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
951
984
  // See further details in earlier comments.
@@ -1008,6 +1041,13 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
1008
1041
  blocks: published.checkpoint.blocks.map((b)=>b.getStats())
1009
1042
  });
1010
1043
  }
1044
+ for (const published of validCheckpoints){
1045
+ this.instrumentation.processCheckpointL1Timing({
1046
+ slotNumber: published.checkpoint.header.slotNumber,
1047
+ l1Timestamp: published.l1.timestamp,
1048
+ l1Constants: this.l1Constants
1049
+ });
1050
+ }
1011
1051
  try {
1012
1052
  const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
1013
1053
  const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(validCheckpoints, updatedValidationResult)));
@@ -1016,7 +1056,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
1016
1056
  if (result.prunedBlocks && result.prunedBlocks.length > 0) {
1017
1057
  const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
1018
1058
  const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
1019
- this.log.warn(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
1059
+ this.log.info(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
1020
1060
  prunedBlocks: result.prunedBlocks.map((b)=>b.toBlockInfo()),
1021
1061
  prunedSlotNumber,
1022
1062
  prunedCheckpointNumber
@@ -14,4 +14,4 @@ export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint,
14
14
  * Returns true if the attestations are valid and sufficient, false otherwise.
15
15
  */
16
16
  export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, logger?: Logger): Promise<ValidateCheckpointResult>;
17
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUdyRCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssd0JBQXdCLEVBRTlCLE1BQU0scUJBQXFCLENBQUM7QUFDN0IsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRSxPQUFPLEVBQUUsS0FBSyxpQkFBaUIsRUFBa0IsTUFBTSw2QkFBNkIsQ0FBQztBQUdyRixZQUFZLEVBQUUsd0JBQXdCLEVBQUUsQ0FBQztBQUV6Qzs7O0dBR0c7QUFDSCx3QkFBZ0IseUNBQXlDLENBQUMsRUFDeEQsVUFBVSxFQUNWLFlBQV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w4QkFBOEIsQ0FDbEQsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFNBQVMsRUFBRSxJQUFJLENBQUMsaUJBQWlCLEVBQUUsZUFBZSxDQUFDLEVBQ25ELE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FDZCxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0EyRm5DIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAkB,MAAM,6BAA6B,CAAC;AAGrF,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EACV,YAAY,EACb,EAAE,mBAAmB,GAAG,eAAe,EAAE,CAGzC;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC,CA2FnC"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAiC,MAAM,6BAA6B,CAAC;AAGpG,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EACV,YAAY,EACb,EAAE,mBAAmB,GAAG,eAAe,EAAE,CAGzC;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC,CA2FnC"}
@@ -1,6 +1,6 @@
1
1
  import { compactArray } from '@aztec/foundation/collection';
2
2
  import { getAttestationInfoFromPayload } from '@aztec/stdlib/block';
3
- import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
3
+ import { computeQuorum, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
4
4
  import { ConsensusPayload } from '@aztec/stdlib/p2p';
5
5
  /**
6
6
  * Extracts attestation information from a published checkpoint.
@@ -46,7 +46,7 @@ import { ConsensusPayload } from '@aztec/stdlib/p2p';
46
46
  valid: true
47
47
  };
48
48
  }
49
- const requiredAttestationCount = Math.floor(committee.length * 2 / 3) + 1;
49
+ const requiredAttestationCount = computeQuorum(committee.length);
50
50
  const failedValidationResult = (reason)=>({
51
51
  valid: false,
52
52
  reason,