@aztec/archiver 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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.
- package/README.md +12 -6
- package/dest/archiver.d.ts +7 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +39 -15
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +15 -3
- package/dest/errors.d.ts +44 -2
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +58 -2
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -14
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +19 -10
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +25 -32
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/data_source_base.d.ts +6 -4
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +11 -5
- package/dest/modules/data_store_updater.d.ts +15 -10
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +69 -68
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +22 -6
- package/dest/modules/l1_synchronizer.d.ts +6 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +244 -146
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +49 -6
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +277 -67
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +39 -18
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +45 -20
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +27 -7
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +95 -20
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +20 -8
- package/dest/test/fake_l1_state.d.ts +14 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +63 -10
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +7 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +30 -5
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +4 -2
- package/package.json +13 -13
- package/src/archiver.ts +57 -18
- package/src/config.ts +22 -2
- package/src/errors.ts +94 -2
- package/src/factory.ts +18 -10
- package/src/index.ts +2 -1
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +36 -45
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +24 -5
- package/src/modules/data_store_updater.ts +94 -97
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +314 -177
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +364 -76
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +77 -34
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +26 -9
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +87 -15
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +44 -3
- package/src/test/noop_l1_archiver.ts +3 -1
|
@@ -371,20 +371,25 @@ 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 { getFinalizedL1Block } from '@aztec/ethereum/queries';
|
|
375
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
374
376
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
375
377
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
376
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
377
|
-
import { pick } from '@aztec/foundation/collection';
|
|
378
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
379
|
+
import { partition, pick } from '@aztec/foundation/collection';
|
|
378
380
|
import { createLogger } from '@aztec/foundation/log';
|
|
381
|
+
import { retryTimes } from '@aztec/foundation/retry';
|
|
379
382
|
import { count } from '@aztec/foundation/string';
|
|
380
383
|
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
381
|
-
import { isDefined } from '@aztec/foundation/types';
|
|
384
|
+
import { isDefined, isErrorClass } from '@aztec/foundation/types';
|
|
382
385
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
386
|
+
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
383
387
|
import { getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
384
388
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
385
389
|
import { execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
386
390
|
import { InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
387
|
-
import {
|
|
391
|
+
import { getCheckpointBlobDataFromBlobs, retrieveCheckpointCalldataFromRollup, retrieveL1ToL2Message, retrieveL1ToL2Messages, retrievedToPublishedCheckpoint } from '../l1/data_retrieval.js';
|
|
392
|
+
import { MessageStoreError } from '../store/message_store.js';
|
|
388
393
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
389
394
|
import { validateCheckpointAttestations } from './validation.js';
|
|
390
395
|
_dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpochPrune'), _dec2 = trackSpan('Archiver.handleL1ToL2Messages'), _dec3 = trackSpan('Archiver.handleCheckpoints');
|
|
@@ -477,12 +482,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
477
482
|
}
|
|
478
483
|
}
|
|
479
484
|
async syncFromL1(initialSyncComplete) {
|
|
485
|
+
// In between the various calls to L1, the block number can move meaning some of the following
|
|
486
|
+
// calls will return data for blocks that were not present during earlier calls. To combat this
|
|
487
|
+
// we ensure that all data retrieval methods only retrieve data up to the currentBlockNumber
|
|
488
|
+
// captured at the top of this function.
|
|
480
489
|
const currentL1Block = await this.publicClient.getBlock({
|
|
481
490
|
includeTransactions: false
|
|
482
491
|
});
|
|
483
492
|
const currentL1BlockNumber = currentL1Block.number;
|
|
484
493
|
const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
|
|
485
494
|
const currentL1Timestamp = currentL1Block.timestamp;
|
|
495
|
+
const currentL1BlockData = {
|
|
496
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
497
|
+
l1BlockHash: currentL1BlockHash
|
|
498
|
+
};
|
|
486
499
|
if (this.l1BlockHash && currentL1BlockHash.equals(this.l1BlockHash)) {
|
|
487
500
|
this.log.trace(`No new L1 blocks since last sync at L1 block ${this.l1BlockNumber}`);
|
|
488
501
|
return;
|
|
@@ -498,36 +511,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
498
511
|
maxAllowedDelay
|
|
499
512
|
});
|
|
500
513
|
}
|
|
501
|
-
// Load sync point for blocks
|
|
502
|
-
const { blocksSynchedTo = this.l1Constants.l1StartBlock
|
|
503
|
-
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
504
|
-
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
505
|
-
} } = await this.store.getSynchPoint();
|
|
514
|
+
// Load sync point for blocks defaulting to start block
|
|
515
|
+
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await this.store.getSynchPoint();
|
|
506
516
|
this.log.debug(`Starting new archiver sync iteration`, {
|
|
507
517
|
blocksSynchedTo,
|
|
508
|
-
|
|
509
|
-
currentL1BlockNumber,
|
|
510
|
-
currentL1BlockHash
|
|
518
|
+
currentL1BlockData
|
|
511
519
|
});
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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 **********
|
|
520
|
+
// 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.
|
|
521
|
+
// 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
|
|
522
|
+
// block, when that wouldn't be the case, since L1 to L2 messages would need another iteration.
|
|
523
|
+
await retryTimes(()=>this.handleL1ToL2Messages(currentL1BlockData), 'Handling L1 to L2 messages', 3, 0.1);
|
|
531
524
|
if (currentL1BlockNumber > blocksSynchedTo) {
|
|
532
525
|
// First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
|
|
533
526
|
// pending chain validation status, proven checkpoint number, and synched L1 block number.
|
|
@@ -572,10 +565,11 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
572
565
|
}
|
|
573
566
|
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
|
|
574
567
|
try {
|
|
575
|
-
const finalizedL1Block = await this.publicClient
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
568
|
+
const finalizedL1Block = await getFinalizedL1Block(this.publicClient);
|
|
569
|
+
if (!finalizedL1Block) {
|
|
570
|
+
this.log.trace(`Skipping finalized checkpoint update: L1 has no finalized block yet.`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
579
573
|
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
580
574
|
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
581
575
|
blockNumber: finalizedL1BlockNumber
|
|
@@ -589,7 +583,10 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
589
583
|
});
|
|
590
584
|
}
|
|
591
585
|
} catch (err) {
|
|
592
|
-
|
|
586
|
+
// The rollup contract may not exist at the finalized L1 block right after deployment.
|
|
587
|
+
if (!err?.message?.includes('returned no data')) {
|
|
588
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
589
|
+
}
|
|
593
590
|
}
|
|
594
591
|
}
|
|
595
592
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
@@ -602,26 +599,28 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
602
599
|
this.log.trace(`No uncheckpointed blocks to prune.`);
|
|
603
600
|
return;
|
|
604
601
|
}
|
|
605
|
-
// What's the slot
|
|
602
|
+
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
603
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
606
604
|
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
605
|
+
// What's the slot of the first uncheckpointed block?
|
|
607
606
|
const [firstUncheckpointedBlockHeader] = await this.store.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
608
607
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
608
|
+
if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
// Prune provisional blocks from slots that have ended without being checkpointed.
|
|
612
|
+
// This also clears any proposed checkpoint whose blocks are being pruned.
|
|
613
|
+
this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
|
|
614
|
+
firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
|
|
615
|
+
slotAtNextL1Block
|
|
616
|
+
});
|
|
617
|
+
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
618
|
+
if (prunedBlocks.length > 0) {
|
|
619
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
620
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
621
|
+
slotNumber: firstUncheckpointedBlockSlot,
|
|
622
|
+
blocks: prunedBlocks
|
|
616
623
|
});
|
|
617
|
-
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
618
|
-
if (prunedBlocks.length > 0) {
|
|
619
|
-
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
620
|
-
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
621
|
-
slotNumber: firstUncheckpointedBlockSlot,
|
|
622
|
-
blocks: prunedBlocks
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
624
|
}
|
|
626
625
|
}
|
|
627
626
|
/** Queries the rollup contract on whether a prune can be executed on the immediate next L1 block. */ async canPrune(currentL1BlockNumber, currentL1Timestamp) {
|
|
@@ -652,12 +651,14 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
652
651
|
const pruneFromSlotNumber = header.slotNumber;
|
|
653
652
|
const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1Constants);
|
|
654
653
|
const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
|
|
655
|
-
|
|
654
|
+
// Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
|
|
655
|
+
// promises when the gap between local pending and proven checkpoint numbers is large.
|
|
656
|
+
const BATCH_SIZE = 10;
|
|
657
|
+
const indices = Array.from({
|
|
656
658
|
length: checkpointsToUnwind
|
|
657
|
-
}
|
|
658
|
-
const checkpoints = await
|
|
659
|
-
const
|
|
660
|
-
const newBlocks = blockPromises.filter(isDefined).flat();
|
|
659
|
+
}, (_, i)=>CheckpointNumber(i + pruneFrom));
|
|
660
|
+
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.store.getCheckpointData(idx))).filter(isDefined);
|
|
661
|
+
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
|
|
661
662
|
// Emit an event for listening services to react to the chain prune
|
|
662
663
|
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
|
|
663
664
|
type: L2BlockSourceEvents.L2PruneUnproven,
|
|
@@ -691,55 +692,75 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
691
692
|
nextEnd
|
|
692
693
|
];
|
|
693
694
|
}
|
|
694
|
-
async handleL1ToL2Messages(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
695
|
+
async handleL1ToL2Messages(currentL1Block) {
|
|
696
|
+
// Load the syncpoint, which may have been updated in a previous iteration
|
|
697
|
+
const { messagesSynchedTo = {
|
|
698
|
+
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
699
|
+
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
700
|
+
} } = await this.store.getSynchPoint();
|
|
701
|
+
// Nothing to do if L1 block number has not moved forward
|
|
702
|
+
const currentL1BlockNumber = currentL1Block.l1BlockNumber;
|
|
703
|
+
if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
|
|
704
|
+
return true;
|
|
698
705
|
}
|
|
699
|
-
//
|
|
700
|
-
const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
|
|
701
|
-
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
706
|
+
// Compare local message store state with the remote. If they match, we just advance the match pointer.
|
|
702
707
|
const remoteMessagesState = await this.inbox.getState({
|
|
703
708
|
blockNumber: currentL1BlockNumber
|
|
704
709
|
});
|
|
705
|
-
this.
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
remoteMessagesState
|
|
709
|
-
|
|
710
|
-
// Compare message count and rolling hash. If they match, no need to retrieve anything.
|
|
711
|
-
if (remoteMessagesState.totalMessagesInserted === localMessagesInserted && remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer32.ZERO)) {
|
|
712
|
-
this.log.trace(`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`);
|
|
713
|
-
return;
|
|
710
|
+
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
711
|
+
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
|
|
712
|
+
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
|
|
713
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
714
|
+
return true;
|
|
714
715
|
}
|
|
715
|
-
//
|
|
716
|
-
//
|
|
717
|
-
//
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
this.
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
this.log.warn(`Rolling back L1 to L2 messages due to hash mismatch or msg not found.`, {
|
|
726
|
-
remoteLastMessage,
|
|
727
|
-
messagesSyncPoint,
|
|
728
|
-
localLastMessage
|
|
729
|
-
});
|
|
730
|
-
messagesSyncPoint = await this.rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint);
|
|
731
|
-
this.log.debug(`Rolled back L1 to L2 messages to L1 block ${messagesSyncPoint.l1BlockNumber}.`, {
|
|
732
|
-
messagesSyncPoint
|
|
716
|
+
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
|
|
717
|
+
// However, it could also be the case that there was an L1 reorg and our syncpoint is no longer valid.
|
|
718
|
+
// If that's the case, we'd get an exception out of the message store since the rolling hash of the first message
|
|
719
|
+
// we try to insert would not match the one in the db, in which case we rollback to the last common message with L1.
|
|
720
|
+
try {
|
|
721
|
+
await this.retrieveAndStoreMessages(messagesSynchedTo.l1BlockNumber, currentL1BlockNumber);
|
|
722
|
+
} catch (error) {
|
|
723
|
+
if (isErrorClass(error, MessageStoreError)) {
|
|
724
|
+
this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
|
|
725
|
+
inboxMessage: error.inboxMessage
|
|
733
726
|
});
|
|
727
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
728
|
+
return false;
|
|
734
729
|
}
|
|
730
|
+
throw error;
|
|
731
|
+
}
|
|
732
|
+
// Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
|
|
733
|
+
// we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
|
|
734
|
+
// our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
|
|
735
|
+
const localLastMessageAfterSync = await this.store.getLastL1ToL2Message();
|
|
736
|
+
if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
|
|
737
|
+
this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
|
|
738
|
+
localLastMessageAfterSync,
|
|
739
|
+
remoteMessagesState
|
|
740
|
+
});
|
|
741
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
742
|
+
return false;
|
|
735
743
|
}
|
|
736
|
-
//
|
|
744
|
+
// Advance the syncpoint after a successful sync
|
|
745
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
/** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
|
|
749
|
+
const localMessageCount = await this.store.getTotalL1ToL2MessageCount();
|
|
750
|
+
this.log.trace(`Comparing local and remote inbox state`, {
|
|
751
|
+
localMessageCount,
|
|
752
|
+
localLastMessage,
|
|
753
|
+
remoteState
|
|
754
|
+
});
|
|
755
|
+
return remoteState.totalMessagesInserted === localMessageCount && remoteState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO);
|
|
756
|
+
}
|
|
757
|
+
/** Retrieves L1 to L2 messages from L1 in batches and stores them. */ async retrieveAndStoreMessages(fromL1Block, toL1Block) {
|
|
737
758
|
let searchStartBlock = 0n;
|
|
738
|
-
let searchEndBlock =
|
|
759
|
+
let searchEndBlock = fromL1Block;
|
|
739
760
|
let lastMessage;
|
|
740
761
|
let messageCount = 0;
|
|
741
762
|
do {
|
|
742
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock,
|
|
763
|
+
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, toL1Block);
|
|
743
764
|
this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
744
765
|
const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
|
|
745
766
|
const timer = new Timer();
|
|
@@ -754,74 +775,81 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
754
775
|
lastMessage = msg;
|
|
755
776
|
messageCount++;
|
|
756
777
|
}
|
|
757
|
-
}while (searchEndBlock <
|
|
758
|
-
// Log stats for messages retrieved (if any).
|
|
778
|
+
}while (searchEndBlock < toL1Block)
|
|
759
779
|
if (messageCount > 0) {
|
|
760
780
|
this.log.info(`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`, {
|
|
761
781
|
lastMessage,
|
|
762
782
|
messageCount
|
|
763
783
|
});
|
|
764
784
|
}
|
|
765
|
-
// Warn if the resulting rolling hash does not match the remote state we had retrieved.
|
|
766
|
-
if (lastMessage && !lastMessage.rollingHash.equals(remoteMessagesState.messagesRollingHash)) {
|
|
767
|
-
this.log.warn(`Last message retrieved rolling hash does not match remote state.`, {
|
|
768
|
-
lastMessage,
|
|
769
|
-
remoteMessagesState
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
async retrieveL1ToL2Message(leaf) {
|
|
774
|
-
const currentL1BlockNumber = await this.publicClient.getBlockNumber();
|
|
775
|
-
let searchStartBlock = 0n;
|
|
776
|
-
let searchEndBlock = this.l1Constants.l1StartBlock - 1n;
|
|
777
|
-
do {
|
|
778
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
779
|
-
const message = await retrieveL1ToL2Message(this.inbox, leaf, searchStartBlock, searchEndBlock);
|
|
780
|
-
if (message) {
|
|
781
|
-
return message;
|
|
782
|
-
}
|
|
783
|
-
}while (searchEndBlock < currentL1BlockNumber)
|
|
784
|
-
return undefined;
|
|
785
785
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
786
|
+
/**
|
|
787
|
+
* 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.
|
|
788
|
+
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
|
|
789
|
+
*/ async rollbackL1ToL2Messages(remoteMessagesState) {
|
|
790
|
+
const { treeInProgress: remoteTreeInProgress, messagesRollingHash: remoteRollingHash } = remoteMessagesState;
|
|
791
|
+
// Slowly go back through our messages until we find the last common message. We could query the logs in
|
|
792
|
+
// batch as an optimization, but the depth of the reorg should not be deep, and this is a very rare case,
|
|
793
|
+
// so it's fine to query one log at a time.
|
|
790
794
|
let commonMsg;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
+
let messagesToDelete = 0;
|
|
796
|
+
this.log.verbose(`Searching most recent common L1 to L2 message`);
|
|
797
|
+
for await (const localMsg of this.store.iterateL1ToL2Messages({
|
|
798
|
+
reverse: true
|
|
795
799
|
})){
|
|
796
|
-
const remoteMsg = await this.retrieveL1ToL2Message(msg.leaf);
|
|
797
800
|
const logCtx = {
|
|
798
|
-
remoteMsg,
|
|
799
|
-
localMsg
|
|
801
|
+
remoteMsg: undefined,
|
|
802
|
+
localMsg,
|
|
803
|
+
remoteMessagesState
|
|
800
804
|
};
|
|
801
|
-
if
|
|
802
|
-
|
|
805
|
+
// First check if the local message rolling hash matches the current rolling hash of the inbox contract,
|
|
806
|
+
// which means we just need to rollback some local messages and we should be back in sync. This means there
|
|
807
|
+
// was an L1 reorg that removed some of the messages we had, but no new messages were added compared.
|
|
808
|
+
if (localMsg.rollingHash.equals(remoteRollingHash)) {
|
|
809
|
+
this.log.info(`Found common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber} matching current remote state`, logCtx);
|
|
810
|
+
commonMsg = localMsg;
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
// If there's no match with the current remote state, check if the message exists on the inbox contract at all
|
|
814
|
+
// by looking at the inbox events. If the L1 reorg *added* new messages in addition to deleting existing ones,
|
|
815
|
+
// then the current remote state's rolling hash will not match anything we have locally, so we need to check existence
|
|
816
|
+
// of individual messages via logs. Note we use logs and not historical queries so we don't have to depend on
|
|
817
|
+
// an archival rpc node, since the message could be from a long time ago if we're catching up with syncing.
|
|
818
|
+
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
819
|
+
logCtx.remoteMsg = remoteMsg;
|
|
820
|
+
if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
|
|
821
|
+
this.log.info(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
803
822
|
commonMsg = remoteMsg;
|
|
804
823
|
break;
|
|
805
824
|
} else if (remoteMsg) {
|
|
806
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
825
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} has different rolling hash`, logCtx);
|
|
826
|
+
messagesToDelete++;
|
|
807
827
|
} else {
|
|
808
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
828
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} not found on L1`, logCtx);
|
|
829
|
+
messagesToDelete++;
|
|
809
830
|
}
|
|
810
831
|
}
|
|
811
|
-
// Delete everything after the common message we found.
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
832
|
+
// Delete everything after the common message we found, if anything needs to be deleted.
|
|
833
|
+
// Do not exit early if there are no messages to delete, we still want to update the syncpoint.
|
|
834
|
+
if (messagesToDelete > 0) {
|
|
835
|
+
const lastGoodIndex = commonMsg?.index;
|
|
836
|
+
this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
|
|
837
|
+
await this.store.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
|
|
838
|
+
}
|
|
815
839
|
// Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
|
|
816
840
|
// the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
|
|
817
841
|
// after the last common message.
|
|
818
842
|
const syncPointL1BlockNumber = commonMsg ? commonMsg.l1BlockNumber - 1n : this.l1Constants.l1StartBlock;
|
|
819
843
|
const syncPointL1BlockHash = await this.getL1BlockHash(syncPointL1BlockNumber);
|
|
820
|
-
messagesSyncPoint = {
|
|
844
|
+
const messagesSyncPoint = {
|
|
821
845
|
l1BlockNumber: syncPointL1BlockNumber,
|
|
822
846
|
l1BlockHash: syncPointL1BlockHash
|
|
823
847
|
};
|
|
824
|
-
await this.store.
|
|
848
|
+
await this.store.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
|
|
849
|
+
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
|
|
850
|
+
...messagesSyncPoint,
|
|
851
|
+
remoteTreeInProgress
|
|
852
|
+
});
|
|
825
853
|
return messagesSyncPoint;
|
|
826
854
|
}
|
|
827
855
|
async getL1BlockHash(l1BlockNumber) {
|
|
@@ -968,21 +996,37 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
968
996
|
do {
|
|
969
997
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
970
998
|
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
971
|
-
//
|
|
972
|
-
const
|
|
973
|
-
if (
|
|
999
|
+
// First fetch calldata only, no blobs yet, since we may be able to just get that data out of the proposed chain
|
|
1000
|
+
const calldataCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointCalldataFromRollup', ()=>retrieveCheckpointCalldataFromRollup(this.rollup, this.publicClient, this.debugClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log));
|
|
1001
|
+
if (calldataCheckpoints.length === 0) {
|
|
974
1002
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
975
1003
|
// See further details in earlier comments.
|
|
976
1004
|
this.log.trace(`Retrieved no new checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
977
1005
|
continue;
|
|
978
1006
|
}
|
|
979
|
-
this.log.debug(`Retrieved ${
|
|
980
|
-
lastProcessedCheckpoint:
|
|
1007
|
+
this.log.debug(`Retrieved ${calldataCheckpoints.length} new checkpoint calldata between L1 blocks ${searchStartBlock} and ${searchEndBlock}`, {
|
|
1008
|
+
lastProcessedCheckpoint: calldataCheckpoints[calldataCheckpoints.length - 1].l1,
|
|
981
1009
|
searchStartBlock,
|
|
982
1010
|
searchEndBlock
|
|
983
1011
|
});
|
|
984
|
-
|
|
1012
|
+
// Check if the last checkpoint matches the proposed one (so we can skip blob fetch).
|
|
1013
|
+
// We only check the last one because the proposed checkpoint is always the most recent one,
|
|
1014
|
+
// and if it's in a multi-checkpoint batch it will always be last (sorted by L1 block number).
|
|
1015
|
+
const lastCalldataCheckpoint = calldataCheckpoints[calldataCheckpoints.length - 1];
|
|
1016
|
+
const checkpointToPromote = await this.tryBuildPublishedCheckpointFromProposed(lastCalldataCheckpoint);
|
|
1017
|
+
// Then fetch blobs in parallel and build the full published checkpoints
|
|
1018
|
+
const toFetchBlobs = checkpointToPromote ? calldataCheckpoints.slice(0, -1) : calldataCheckpoints;
|
|
1019
|
+
const blobFetched = await asyncPool(10, toFetchBlobs, async (checkpoint)=>retrievedToPublishedCheckpoint({
|
|
1020
|
+
...checkpoint,
|
|
1021
|
+
checkpointBlobData: await getCheckpointBlobDataFromBlobs(this.blobClient, checkpoint.l1.blockHash, checkpoint.blobHashes, checkpoint.checkpointNumber, this.log, !initialSyncComplete, checkpoint.parentBeaconBlockRoot, checkpoint.l1.timestamp)
|
|
1022
|
+
}));
|
|
1023
|
+
// And add the promoted checkpoint to the list of all checkpoints
|
|
1024
|
+
const publishedCheckpoints = checkpointToPromote ? [
|
|
1025
|
+
...blobFetched,
|
|
1026
|
+
checkpointToPromote
|
|
1027
|
+
] : blobFetched;
|
|
985
1028
|
const validCheckpoints = [];
|
|
1029
|
+
// Now loop through all checkpoints and validate their attestations
|
|
986
1030
|
for (const published of publishedCheckpoints){
|
|
987
1031
|
const validationResult = this.config.skipValidateCheckpointAttestations ? {
|
|
988
1032
|
valid: true
|
|
@@ -1041,8 +1085,17 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1041
1085
|
}
|
|
1042
1086
|
try {
|
|
1043
1087
|
const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
1044
|
-
|
|
1045
|
-
|
|
1088
|
+
// Split valid checkpoints: the promoted one (if any) is persisted via the proposed-promotion path,
|
|
1089
|
+
// the rest via addCheckpoints. Both paths run within the same store transaction for atomicity.
|
|
1090
|
+
const [[maybeValidCheckpointToPromote], checkpointsToAdd] = partition(validCheckpoints, (c)=>c.checkpoint.number === checkpointToPromote?.checkpoint.number);
|
|
1091
|
+
const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(checkpointsToAdd, updatedValidationResult, maybeValidCheckpointToPromote && {
|
|
1092
|
+
l1: lastCalldataCheckpoint.l1,
|
|
1093
|
+
attestations: lastCalldataCheckpoint.attestations,
|
|
1094
|
+
checkpoint: maybeValidCheckpointToPromote
|
|
1095
|
+
})));
|
|
1096
|
+
if (checkpointsToAdd.length > 0) {
|
|
1097
|
+
this.instrumentation.processNewCheckpointedBlocks(processDuration / checkpointsToAdd.length, checkpointsToAdd.flatMap((c)=>c.checkpoint.blocks));
|
|
1098
|
+
}
|
|
1046
1099
|
// If blocks were pruned due to conflict with L1 checkpoints, emit event
|
|
1047
1100
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
1048
1101
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
@@ -1087,7 +1140,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1087
1140
|
});
|
|
1088
1141
|
}
|
|
1089
1142
|
lastRetrievedCheckpoint = validCheckpoints.at(-1) ?? lastRetrievedCheckpoint;
|
|
1090
|
-
lastL1BlockWithCheckpoint =
|
|
1143
|
+
lastL1BlockWithCheckpoint = calldataCheckpoints.at(-1)?.l1.blockNumber ?? lastL1BlockWithCheckpoint;
|
|
1091
1144
|
}while (searchEndBlock < currentL1BlockNumber)
|
|
1092
1145
|
// Important that we update AFTER inserting the blocks.
|
|
1093
1146
|
await updateProvenCheckpoint();
|
|
@@ -1097,6 +1150,51 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1097
1150
|
lastL1BlockWithCheckpoint
|
|
1098
1151
|
};
|
|
1099
1152
|
}
|
|
1153
|
+
/** Checks if this checkpoint matches the local proposed one, and if so, loads local data to build a synthetic published checkpoint. */ async tryBuildPublishedCheckpointFromProposed(calldataCheckpoint) {
|
|
1154
|
+
const proposed = await this.store.getProposedCheckpointOnly();
|
|
1155
|
+
if (this.config.skipPromoteProposedCheckpointDuringL1Sync || !proposed || !calldataCheckpoint || proposed.checkpointNumber !== calldataCheckpoint.checkpointNumber) {
|
|
1156
|
+
return undefined;
|
|
1157
|
+
}
|
|
1158
|
+
if (!proposed.header.equals(calldataCheckpoint.header) || !proposed.archive.root.equals(calldataCheckpoint.archiveRoot)) {
|
|
1159
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} does not match checkpoint retrieved from L1, overriding with L1 data`, {
|
|
1160
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1161
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1162
|
+
proposedArchiveRoot: proposed.archive.root.toString(),
|
|
1163
|
+
calldataCheckpointNumber: calldataCheckpoint.checkpointNumber,
|
|
1164
|
+
calldataHeader: calldataCheckpoint.header.toInspect(),
|
|
1165
|
+
calldataArchiveRoot: calldataCheckpoint.archiveRoot.toString()
|
|
1166
|
+
});
|
|
1167
|
+
return undefined;
|
|
1168
|
+
}
|
|
1169
|
+
this.log.debug(`Building published checkpoint from proposed ${calldataCheckpoint.checkpointNumber} (skipping blob fetch)`, {
|
|
1170
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1171
|
+
proposedArchiveRoot: proposed.archive.root.toString()
|
|
1172
|
+
});
|
|
1173
|
+
const blocks = await this.store.getBlocks(BlockNumber(proposed.startBlock), proposed.blockCount);
|
|
1174
|
+
if (blocks.length !== proposed.blockCount) {
|
|
1175
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} has wrong block count (expected ${proposed.blockCount} blocks starting at ${proposed.startBlock} but got ${blocks.length})`, {
|
|
1176
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1177
|
+
proposedStartBlock: proposed.startBlock,
|
|
1178
|
+
proposedBlockCount: proposed.blockCount,
|
|
1179
|
+
retrievedBlocks: blocks.map((b)=>b.number)
|
|
1180
|
+
});
|
|
1181
|
+
return undefined;
|
|
1182
|
+
}
|
|
1183
|
+
const checkpoint = Checkpoint.from({
|
|
1184
|
+
archive: proposed.archive,
|
|
1185
|
+
header: proposed.header,
|
|
1186
|
+
blocks,
|
|
1187
|
+
number: proposed.checkpointNumber,
|
|
1188
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier
|
|
1189
|
+
});
|
|
1190
|
+
const promotedCheckpoint = PublishedCheckpoint.from({
|
|
1191
|
+
checkpoint,
|
|
1192
|
+
l1: calldataCheckpoint.l1,
|
|
1193
|
+
attestations: calldataCheckpoint.attestations
|
|
1194
|
+
});
|
|
1195
|
+
this.instrumentation.processCheckpointPromoted();
|
|
1196
|
+
return promotedCheckpoint;
|
|
1197
|
+
}
|
|
1100
1198
|
async checkForNewCheckpointsBeforeL1SyncPoint(status, blocksSynchedTo, currentL1BlockNumber) {
|
|
1101
1199
|
const { lastRetrievedCheckpoint, pendingCheckpointNumber } = status;
|
|
1102
1200
|
// Compare the last checkpoint we have (either retrieved in this round or loaded from store) with what the
|
|
@@ -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,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUdyRCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssd0JBQXdCLEVBRTlCLE1BQU0scUJBQXFCLENBQUM7QUFDN0IsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRSxPQUFPLEVBQUUsS0FBSyxpQkFBaUIsRUFBaUMsTUFBTSw2QkFBNkIsQ0FBQztBQUdwRyxZQUFZLEVBQUUsd0JBQXdCLEVBQUUsQ0FBQztBQUV6Qzs7O0dBR0c7QUFDSCx3QkFBZ0IseUNBQXlDLENBQUMsRUFDeEQsVUFBVSxFQUNWLFlBQVksRUFDYixFQUFFLG1CQUFtQixHQUFHLGVBQWUsRUFBRSxDQUd6QztBQUVEOzs7R0FHRztBQUNILHdCQUFzQiw4QkFBOEIsQ0FDbEQsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFNBQVMsRUFBRSxJQUFJLENBQUMsaUJBQWlCLEVBQUUsZUFBZSxDQUFDLEVBQ25ELE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FDZCxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0EyRm5DIn0=
|
|
@@ -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,
|
|
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 =
|
|
49
|
+
const requiredAttestationCount = computeQuorum(committee.length);
|
|
50
50
|
const failedValidationResult = (reason)=>({
|
|
51
51
|
valid: false,
|
|
52
52
|
reason,
|