@aztec/archiver 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8
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 +18 -10
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +146 -57
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +26 -22
- 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 +2 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +11 -5
- package/dest/l1/data_retrieval.d.ts +24 -12
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +36 -37
- 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 +12 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +24 -6
- package/dest/modules/data_store_updater.d.ts +28 -15
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +102 -80
- 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 +8 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +292 -144
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +83 -17
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +399 -124
- 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 +70 -23
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +88 -27
- 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 +21 -9
- package/dest/test/fake_l1_state.d.ts +20 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +114 -18
- 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 +19 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +57 -7
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +9 -3
- package/package.json +13 -13
- package/src/archiver.ts +179 -56
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +24 -15
- package/src/index.ts +2 -1
- package/src/l1/calldata_retriever.ts +17 -5
- package/src/l1/data_retrieval.ts +52 -53
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +43 -7
- package/src/modules/data_store_updater.ts +126 -109
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +371 -178
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +489 -143
- 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 +133 -39
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +142 -29
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +73 -5
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +10 -2
|
@@ -371,20 +371,26 @@ 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';
|
|
380
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
378
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
382
|
+
import { retryTimes } from '@aztec/foundation/retry';
|
|
379
383
|
import { count } from '@aztec/foundation/string';
|
|
380
384
|
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
381
|
-
import { isDefined } from '@aztec/foundation/types';
|
|
385
|
+
import { isDefined, isErrorClass } from '@aztec/foundation/types';
|
|
382
386
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
387
|
+
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
383
388
|
import { getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
384
389
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
385
390
|
import { execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
386
391
|
import { InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
387
|
-
import {
|
|
392
|
+
import { getCheckpointBlobDataFromBlobs, retrieveCheckpointCalldataFromRollup, retrieveL1ToL2Message, retrieveL1ToL2Messages, retrievedToPublishedCheckpoint } from '../l1/data_retrieval.js';
|
|
393
|
+
import { MessageStoreError } from '../store/message_store.js';
|
|
388
394
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
389
395
|
import { validateCheckpointAttestations } from './validation.js';
|
|
390
396
|
_dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpochPrune'), _dec2 = trackSpan('Archiver.handleL1ToL2Messages'), _dec3 = trackSpan('Archiver.handleCheckpoints');
|
|
@@ -449,7 +455,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
449
455
|
this.events = events;
|
|
450
456
|
this.log = log;
|
|
451
457
|
_initProto(this);
|
|
452
|
-
this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache
|
|
458
|
+
this.updater = new ArchiverDataStoreUpdater(this.store, l2TipsCache, {
|
|
459
|
+
rollupManaLimit: l1Constants.rollupManaLimit
|
|
460
|
+
});
|
|
453
461
|
this.tracer = tracer;
|
|
454
462
|
}
|
|
455
463
|
/** Sets new config */ setConfig(newConfig) {
|
|
@@ -461,6 +469,12 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
461
469
|
/** Returns the last L1 timestamp that was synced. */ getL1Timestamp() {
|
|
462
470
|
return this.l1Timestamp;
|
|
463
471
|
}
|
|
472
|
+
getSignatureContext() {
|
|
473
|
+
return {
|
|
474
|
+
chainId: this.publicClient.chain.id,
|
|
475
|
+
rollupAddress: EthAddress.fromString(this.rollup.address)
|
|
476
|
+
};
|
|
477
|
+
}
|
|
464
478
|
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */ async testEthereumNodeSynced() {
|
|
465
479
|
const maxAllowedDelay = this.config.maxAllowedEthClientDriftSeconds;
|
|
466
480
|
if (maxAllowedDelay === 0) {
|
|
@@ -475,12 +489,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
475
489
|
}
|
|
476
490
|
}
|
|
477
491
|
async syncFromL1(initialSyncComplete) {
|
|
492
|
+
// In between the various calls to L1, the block number can move meaning some of the following
|
|
493
|
+
// calls will return data for blocks that were not present during earlier calls. To combat this
|
|
494
|
+
// we ensure that all data retrieval methods only retrieve data up to the currentBlockNumber
|
|
495
|
+
// captured at the top of this function.
|
|
478
496
|
const currentL1Block = await this.publicClient.getBlock({
|
|
479
497
|
includeTransactions: false
|
|
480
498
|
});
|
|
481
499
|
const currentL1BlockNumber = currentL1Block.number;
|
|
482
500
|
const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
|
|
483
501
|
const currentL1Timestamp = currentL1Block.timestamp;
|
|
502
|
+
const currentL1BlockData = {
|
|
503
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
504
|
+
l1BlockHash: currentL1BlockHash
|
|
505
|
+
};
|
|
484
506
|
if (this.l1BlockHash && currentL1BlockHash.equals(this.l1BlockHash)) {
|
|
485
507
|
this.log.trace(`No new L1 blocks since last sync at L1 block ${this.l1BlockNumber}`);
|
|
486
508
|
return;
|
|
@@ -496,36 +518,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
496
518
|
maxAllowedDelay
|
|
497
519
|
});
|
|
498
520
|
}
|
|
499
|
-
// Load sync point for blocks
|
|
500
|
-
const { blocksSynchedTo = this.l1Constants.l1StartBlock
|
|
501
|
-
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
502
|
-
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
503
|
-
} } = await this.store.getSynchPoint();
|
|
521
|
+
// Load sync point for blocks defaulting to start block
|
|
522
|
+
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await this.store.getSynchPoint();
|
|
504
523
|
this.log.debug(`Starting new archiver sync iteration`, {
|
|
505
524
|
blocksSynchedTo,
|
|
506
|
-
|
|
507
|
-
currentL1BlockNumber,
|
|
508
|
-
currentL1BlockHash
|
|
525
|
+
currentL1BlockData
|
|
509
526
|
});
|
|
510
|
-
//
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
* to ensure that data is read exactly once.
|
|
515
|
-
*
|
|
516
|
-
* The first is the problem of eventually consistent ETH service providers like Infura.
|
|
517
|
-
* Each L1 read operation will query data from the last L1 block that it saw emit its kind of data.
|
|
518
|
-
* (so pending L1 to L2 messages will read from the last L1 block that emitted a message and so on)
|
|
519
|
-
* This will mean the archiver will lag behind L1 and will only advance when there's L2-relevant activity on the chain.
|
|
520
|
-
*
|
|
521
|
-
* The second is that in between the various calls to L1, the block number can move meaning some
|
|
522
|
-
* of the following calls will return data for blocks that were not present during earlier calls.
|
|
523
|
-
* To combat this for the time being we simply ensure that all data retrieval methods only retrieve
|
|
524
|
-
* data up to the currentBlockNumber captured at the top of this function. We might want to improve on this
|
|
525
|
-
* in future but for the time being it should give us the guarantees that we need
|
|
526
|
-
*/ // ********** Events that are processed per L1 block **********
|
|
527
|
-
await this.handleL1ToL2Messages(messagesSynchedTo, currentL1BlockNumber);
|
|
528
|
-
// ********** Events that are processed per checkpoint **********
|
|
527
|
+
// 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.
|
|
528
|
+
// 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
|
|
529
|
+
// block, when that wouldn't be the case, since L1 to L2 messages would need another iteration.
|
|
530
|
+
await retryTimes(()=>this.handleL1ToL2Messages(currentL1BlockData), 'Handling L1 to L2 messages', 3, 0.1);
|
|
529
531
|
if (currentL1BlockNumber > blocksSynchedTo) {
|
|
530
532
|
// First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
|
|
531
533
|
// pending chain validation status, proven checkpoint number, and synched L1 block number.
|
|
@@ -553,6 +555,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
553
555
|
}
|
|
554
556
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
555
557
|
}
|
|
558
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
559
|
+
await this.updateFinalizedCheckpoint();
|
|
556
560
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
557
561
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
558
562
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -566,6 +570,32 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
566
570
|
l1BlockNumberAtEnd
|
|
567
571
|
});
|
|
568
572
|
}
|
|
573
|
+
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
|
|
574
|
+
try {
|
|
575
|
+
const finalizedL1Block = await getFinalizedL1Block(this.publicClient);
|
|
576
|
+
if (!finalizedL1Block) {
|
|
577
|
+
this.log.trace(`Skipping finalized checkpoint update: L1 has no finalized block yet.`);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
581
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
582
|
+
blockNumber: finalizedL1BlockNumber
|
|
583
|
+
});
|
|
584
|
+
const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
|
|
585
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
586
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
587
|
+
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
588
|
+
finalizedCheckpointNumber,
|
|
589
|
+
finalizedL1BlockNumber
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
} catch (err) {
|
|
593
|
+
// The rollup contract may not exist at the finalized L1 block right after deployment.
|
|
594
|
+
if (!err?.message?.includes('returned no data')) {
|
|
595
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
569
599
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
570
600
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
571
601
|
this.store.getCheckpointedL2BlockNumber(),
|
|
@@ -576,26 +606,28 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
576
606
|
this.log.trace(`No uncheckpointed blocks to prune.`);
|
|
577
607
|
return;
|
|
578
608
|
}
|
|
579
|
-
// What's the slot
|
|
609
|
+
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
610
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
580
611
|
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
612
|
+
// What's the slot of the first uncheckpointed block?
|
|
581
613
|
const [firstUncheckpointedBlockHeader] = await this.store.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
582
614
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
615
|
+
if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
// Prune provisional blocks from slots that have ended without being checkpointed.
|
|
619
|
+
// This also clears any proposed checkpoint whose blocks are being pruned.
|
|
620
|
+
this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
|
|
621
|
+
firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
|
|
622
|
+
slotAtNextL1Block
|
|
623
|
+
});
|
|
624
|
+
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
625
|
+
if (prunedBlocks.length > 0) {
|
|
626
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
627
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
628
|
+
slotNumber: firstUncheckpointedBlockSlot,
|
|
629
|
+
blocks: prunedBlocks
|
|
590
630
|
});
|
|
591
|
-
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
592
|
-
if (prunedBlocks.length > 0) {
|
|
593
|
-
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
594
|
-
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
595
|
-
slotNumber: firstUncheckpointedBlockSlot,
|
|
596
|
-
blocks: prunedBlocks
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
631
|
}
|
|
600
632
|
}
|
|
601
633
|
/** Queries the rollup contract on whether a prune can be executed on the immediate next L1 block. */ async canPrune(currentL1BlockNumber, currentL1Timestamp) {
|
|
@@ -626,12 +658,14 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
626
658
|
const pruneFromSlotNumber = header.slotNumber;
|
|
627
659
|
const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1Constants);
|
|
628
660
|
const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
|
|
629
|
-
|
|
661
|
+
// Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
|
|
662
|
+
// promises when the gap between local pending and proven checkpoint numbers is large.
|
|
663
|
+
const BATCH_SIZE = 10;
|
|
664
|
+
const indices = Array.from({
|
|
630
665
|
length: checkpointsToUnwind
|
|
631
|
-
}
|
|
632
|
-
const checkpoints = await
|
|
633
|
-
const
|
|
634
|
-
const newBlocks = blockPromises.filter(isDefined).flat();
|
|
666
|
+
}, (_, i)=>CheckpointNumber(i + pruneFrom));
|
|
667
|
+
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.store.getCheckpointData(idx))).filter(isDefined);
|
|
668
|
+
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
|
|
635
669
|
// Emit an event for listening services to react to the chain prune
|
|
636
670
|
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
|
|
637
671
|
type: L2BlockSourceEvents.L2PruneUnproven,
|
|
@@ -665,55 +699,75 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
665
699
|
nextEnd
|
|
666
700
|
];
|
|
667
701
|
}
|
|
668
|
-
async handleL1ToL2Messages(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
702
|
+
async handleL1ToL2Messages(currentL1Block) {
|
|
703
|
+
// Load the syncpoint, which may have been updated in a previous iteration
|
|
704
|
+
const { messagesSynchedTo = {
|
|
705
|
+
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
706
|
+
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
707
|
+
} } = await this.store.getSynchPoint();
|
|
708
|
+
// Nothing to do if L1 block number has not moved forward
|
|
709
|
+
const currentL1BlockNumber = currentL1Block.l1BlockNumber;
|
|
710
|
+
if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
|
|
711
|
+
return true;
|
|
672
712
|
}
|
|
673
|
-
//
|
|
674
|
-
const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
|
|
675
|
-
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
713
|
+
// Compare local message store state with the remote. If they match, we just advance the match pointer.
|
|
676
714
|
const remoteMessagesState = await this.inbox.getState({
|
|
677
715
|
blockNumber: currentL1BlockNumber
|
|
678
716
|
});
|
|
679
|
-
this.
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
remoteMessagesState
|
|
683
|
-
|
|
684
|
-
// Compare message count and rolling hash. If they match, no need to retrieve anything.
|
|
685
|
-
if (remoteMessagesState.totalMessagesInserted === localMessagesInserted && remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer32.ZERO)) {
|
|
686
|
-
this.log.trace(`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`);
|
|
687
|
-
return;
|
|
717
|
+
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
718
|
+
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
|
|
719
|
+
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
|
|
720
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
721
|
+
return true;
|
|
688
722
|
}
|
|
689
|
-
//
|
|
690
|
-
//
|
|
691
|
-
//
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
this.
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
this.log.warn(`Rolling back L1 to L2 messages due to hash mismatch or msg not found.`, {
|
|
700
|
-
remoteLastMessage,
|
|
701
|
-
messagesSyncPoint,
|
|
702
|
-
localLastMessage
|
|
703
|
-
});
|
|
704
|
-
messagesSyncPoint = await this.rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint);
|
|
705
|
-
this.log.debug(`Rolled back L1 to L2 messages to L1 block ${messagesSyncPoint.l1BlockNumber}.`, {
|
|
706
|
-
messagesSyncPoint
|
|
723
|
+
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
|
|
724
|
+
// However, it could also be the case that there was an L1 reorg and our syncpoint is no longer valid.
|
|
725
|
+
// If that's the case, we'd get an exception out of the message store since the rolling hash of the first message
|
|
726
|
+
// we try to insert would not match the one in the db, in which case we rollback to the last common message with L1.
|
|
727
|
+
try {
|
|
728
|
+
await this.retrieveAndStoreMessages(messagesSynchedTo.l1BlockNumber, currentL1BlockNumber);
|
|
729
|
+
} catch (error) {
|
|
730
|
+
if (isErrorClass(error, MessageStoreError)) {
|
|
731
|
+
this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
|
|
732
|
+
inboxMessage: error.inboxMessage
|
|
707
733
|
});
|
|
734
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
735
|
+
return false;
|
|
708
736
|
}
|
|
737
|
+
throw error;
|
|
709
738
|
}
|
|
710
|
-
//
|
|
739
|
+
// Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
|
|
740
|
+
// we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
|
|
741
|
+
// our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
|
|
742
|
+
const localLastMessageAfterSync = await this.store.getLastL1ToL2Message();
|
|
743
|
+
if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
|
|
744
|
+
this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
|
|
745
|
+
localLastMessageAfterSync,
|
|
746
|
+
remoteMessagesState
|
|
747
|
+
});
|
|
748
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
// Advance the syncpoint after a successful sync
|
|
752
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
/** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
|
|
756
|
+
const localMessageCount = await this.store.getTotalL1ToL2MessageCount();
|
|
757
|
+
this.log.trace(`Comparing local and remote inbox state`, {
|
|
758
|
+
localMessageCount,
|
|
759
|
+
localLastMessage,
|
|
760
|
+
remoteState
|
|
761
|
+
});
|
|
762
|
+
return remoteState.totalMessagesInserted === localMessageCount && remoteState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO);
|
|
763
|
+
}
|
|
764
|
+
/** Retrieves L1 to L2 messages from L1 in batches and stores them. */ async retrieveAndStoreMessages(fromL1Block, toL1Block) {
|
|
711
765
|
let searchStartBlock = 0n;
|
|
712
|
-
let searchEndBlock =
|
|
766
|
+
let searchEndBlock = fromL1Block;
|
|
713
767
|
let lastMessage;
|
|
714
768
|
let messageCount = 0;
|
|
715
769
|
do {
|
|
716
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock,
|
|
770
|
+
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, toL1Block);
|
|
717
771
|
this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
718
772
|
const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
|
|
719
773
|
const timer = new Timer();
|
|
@@ -728,74 +782,81 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
728
782
|
lastMessage = msg;
|
|
729
783
|
messageCount++;
|
|
730
784
|
}
|
|
731
|
-
}while (searchEndBlock <
|
|
732
|
-
// Log stats for messages retrieved (if any).
|
|
785
|
+
}while (searchEndBlock < toL1Block)
|
|
733
786
|
if (messageCount > 0) {
|
|
734
787
|
this.log.info(`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`, {
|
|
735
788
|
lastMessage,
|
|
736
789
|
messageCount
|
|
737
790
|
});
|
|
738
791
|
}
|
|
739
|
-
// Warn if the resulting rolling hash does not match the remote state we had retrieved.
|
|
740
|
-
if (lastMessage && !lastMessage.rollingHash.equals(remoteMessagesState.messagesRollingHash)) {
|
|
741
|
-
this.log.warn(`Last message retrieved rolling hash does not match remote state.`, {
|
|
742
|
-
lastMessage,
|
|
743
|
-
remoteMessagesState
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
async retrieveL1ToL2Message(leaf) {
|
|
748
|
-
const currentL1BlockNumber = await this.publicClient.getBlockNumber();
|
|
749
|
-
let searchStartBlock = 0n;
|
|
750
|
-
let searchEndBlock = this.l1Constants.l1StartBlock - 1n;
|
|
751
|
-
do {
|
|
752
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
753
|
-
const message = await retrieveL1ToL2Message(this.inbox, leaf, searchStartBlock, searchEndBlock);
|
|
754
|
-
if (message) {
|
|
755
|
-
return message;
|
|
756
|
-
}
|
|
757
|
-
}while (searchEndBlock < currentL1BlockNumber)
|
|
758
|
-
return undefined;
|
|
759
792
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
793
|
+
/**
|
|
794
|
+
* 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.
|
|
795
|
+
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
|
|
796
|
+
*/ async rollbackL1ToL2Messages(remoteMessagesState) {
|
|
797
|
+
const { treeInProgress: remoteTreeInProgress, messagesRollingHash: remoteRollingHash } = remoteMessagesState;
|
|
798
|
+
// Slowly go back through our messages until we find the last common message. We could query the logs in
|
|
799
|
+
// batch as an optimization, but the depth of the reorg should not be deep, and this is a very rare case,
|
|
800
|
+
// so it's fine to query one log at a time.
|
|
764
801
|
let commonMsg;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
802
|
+
let messagesToDelete = 0;
|
|
803
|
+
this.log.verbose(`Searching most recent common L1 to L2 message`);
|
|
804
|
+
for await (const localMsg of this.store.iterateL1ToL2Messages({
|
|
805
|
+
reverse: true
|
|
769
806
|
})){
|
|
770
|
-
const remoteMsg = await this.retrieveL1ToL2Message(msg.leaf);
|
|
771
807
|
const logCtx = {
|
|
772
|
-
remoteMsg,
|
|
773
|
-
localMsg
|
|
808
|
+
remoteMsg: undefined,
|
|
809
|
+
localMsg,
|
|
810
|
+
remoteMessagesState
|
|
774
811
|
};
|
|
775
|
-
if
|
|
776
|
-
|
|
812
|
+
// First check if the local message rolling hash matches the current rolling hash of the inbox contract,
|
|
813
|
+
// which means we just need to rollback some local messages and we should be back in sync. This means there
|
|
814
|
+
// was an L1 reorg that removed some of the messages we had, but no new messages were added compared.
|
|
815
|
+
if (localMsg.rollingHash.equals(remoteRollingHash)) {
|
|
816
|
+
this.log.info(`Found common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber} matching current remote state`, logCtx);
|
|
817
|
+
commonMsg = localMsg;
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
// If there's no match with the current remote state, check if the message exists on the inbox contract at all
|
|
821
|
+
// by looking at the inbox events. If the L1 reorg *added* new messages in addition to deleting existing ones,
|
|
822
|
+
// then the current remote state's rolling hash will not match anything we have locally, so we need to check existence
|
|
823
|
+
// of individual messages via logs. Note we use logs and not historical queries so we don't have to depend on
|
|
824
|
+
// an archival rpc node, since the message could be from a long time ago if we're catching up with syncing.
|
|
825
|
+
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
826
|
+
logCtx.remoteMsg = remoteMsg;
|
|
827
|
+
if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
|
|
828
|
+
this.log.info(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
777
829
|
commonMsg = remoteMsg;
|
|
778
830
|
break;
|
|
779
831
|
} else if (remoteMsg) {
|
|
780
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
832
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} has different rolling hash`, logCtx);
|
|
833
|
+
messagesToDelete++;
|
|
781
834
|
} else {
|
|
782
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
835
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} not found on L1`, logCtx);
|
|
836
|
+
messagesToDelete++;
|
|
783
837
|
}
|
|
784
838
|
}
|
|
785
|
-
// Delete everything after the common message we found.
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
839
|
+
// Delete everything after the common message we found, if anything needs to be deleted.
|
|
840
|
+
// Do not exit early if there are no messages to delete, we still want to update the syncpoint.
|
|
841
|
+
if (messagesToDelete > 0) {
|
|
842
|
+
const lastGoodIndex = commonMsg?.index;
|
|
843
|
+
this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
|
|
844
|
+
await this.store.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
|
|
845
|
+
}
|
|
789
846
|
// Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
|
|
790
847
|
// the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
|
|
791
848
|
// after the last common message.
|
|
792
849
|
const syncPointL1BlockNumber = commonMsg ? commonMsg.l1BlockNumber - 1n : this.l1Constants.l1StartBlock;
|
|
793
850
|
const syncPointL1BlockHash = await this.getL1BlockHash(syncPointL1BlockNumber);
|
|
794
|
-
messagesSyncPoint = {
|
|
851
|
+
const messagesSyncPoint = {
|
|
795
852
|
l1BlockNumber: syncPointL1BlockNumber,
|
|
796
853
|
l1BlockHash: syncPointL1BlockHash
|
|
797
854
|
};
|
|
798
|
-
await this.store.
|
|
855
|
+
await this.store.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
|
|
856
|
+
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
|
|
857
|
+
...messagesSyncPoint,
|
|
858
|
+
remoteTreeInProgress
|
|
859
|
+
});
|
|
799
860
|
return messagesSyncPoint;
|
|
800
861
|
}
|
|
801
862
|
async getL1BlockHash(l1BlockNumber) {
|
|
@@ -942,25 +1003,43 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
942
1003
|
do {
|
|
943
1004
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
944
1005
|
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
945
|
-
//
|
|
946
|
-
const
|
|
947
|
-
if (
|
|
1006
|
+
// First fetch calldata only, no blobs yet, since we may be able to just get that data out of the proposed chain
|
|
1007
|
+
const calldataCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointCalldataFromRollup', ()=>retrieveCheckpointCalldataFromRollup(this.rollup, this.publicClient, this.debugClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log));
|
|
1008
|
+
if (calldataCheckpoints.length === 0) {
|
|
948
1009
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
949
1010
|
// See further details in earlier comments.
|
|
950
1011
|
this.log.trace(`Retrieved no new checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
951
1012
|
continue;
|
|
952
1013
|
}
|
|
953
|
-
this.log.debug(`Retrieved ${
|
|
954
|
-
lastProcessedCheckpoint:
|
|
1014
|
+
this.log.debug(`Retrieved ${calldataCheckpoints.length} new checkpoint calldata between L1 blocks ${searchStartBlock} and ${searchEndBlock}`, {
|
|
1015
|
+
lastProcessedCheckpoint: calldataCheckpoints[calldataCheckpoints.length - 1].l1,
|
|
955
1016
|
searchStartBlock,
|
|
956
1017
|
searchEndBlock
|
|
957
1018
|
});
|
|
958
|
-
|
|
1019
|
+
// Check if the last checkpoint matches a local pending entry (so we can skip blob fetch).
|
|
1020
|
+
// We only check the last one; if it matches, the blob fetch is skipped for that entry.
|
|
1021
|
+
// TODO(palla/pipelining): We may have more than a single checkpoint to promote
|
|
1022
|
+
const lastCalldataCheckpoint = calldataCheckpoints[calldataCheckpoints.length - 1];
|
|
1023
|
+
const promoteResult = await this.tryBuildPublishedCheckpointFromProposed(lastCalldataCheckpoint);
|
|
1024
|
+
const checkpointToPromote = promoteResult && !('diverged' in promoteResult) ? promoteResult : undefined;
|
|
1025
|
+
const evictProposedFrom = promoteResult && 'diverged' in promoteResult ? promoteResult.fromCheckpointNumber : undefined;
|
|
1026
|
+
// Then fetch blobs in parallel and build the full published checkpoints
|
|
1027
|
+
const toFetchBlobs = checkpointToPromote ? calldataCheckpoints.slice(0, -1) : calldataCheckpoints;
|
|
1028
|
+
const blobFetched = await asyncPool(10, toFetchBlobs, async (checkpoint)=>retrievedToPublishedCheckpoint({
|
|
1029
|
+
...checkpoint,
|
|
1030
|
+
checkpointBlobData: await getCheckpointBlobDataFromBlobs(this.blobClient, checkpoint.l1.blockHash, checkpoint.blobHashes, checkpoint.checkpointNumber, this.log, !initialSyncComplete, checkpoint.parentBeaconBlockRoot, checkpoint.l1.timestamp)
|
|
1031
|
+
}));
|
|
1032
|
+
// And add the promoted checkpoint to the list of all checkpoints
|
|
1033
|
+
const publishedCheckpoints = checkpointToPromote ? [
|
|
1034
|
+
...blobFetched,
|
|
1035
|
+
checkpointToPromote
|
|
1036
|
+
] : blobFetched;
|
|
959
1037
|
const validCheckpoints = [];
|
|
1038
|
+
// Now loop through all checkpoints and validate their attestations
|
|
960
1039
|
for (const published of publishedCheckpoints){
|
|
961
1040
|
const validationResult = this.config.skipValidateCheckpointAttestations ? {
|
|
962
1041
|
valid: true
|
|
963
|
-
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.log);
|
|
1042
|
+
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.getSignatureContext(), this.log);
|
|
964
1043
|
// Only update the validation result if it has changed, so we can keep track of the first invalid checkpoint
|
|
965
1044
|
// in case there is a sequence of more than one invalid checkpoint, as we need to invalidate the first one.
|
|
966
1045
|
// There is an exception though: if a checkpoint is invalidated and replaced with another invalid checkpoint,
|
|
@@ -1015,13 +1094,22 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1015
1094
|
}
|
|
1016
1095
|
try {
|
|
1017
1096
|
const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
1018
|
-
|
|
1019
|
-
|
|
1097
|
+
// Split valid checkpoints: the promoted one (if any) is persisted via the proposed-promotion path,
|
|
1098
|
+
// the rest via addCheckpoints. Both paths run within the same store transaction for atomicity.
|
|
1099
|
+
const [[maybeValidCheckpointToPromote], checkpointsToAdd] = partition(validCheckpoints, (c)=>c.checkpoint.number === checkpointToPromote?.checkpoint.number);
|
|
1100
|
+
const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(checkpointsToAdd, updatedValidationResult, maybeValidCheckpointToPromote && {
|
|
1101
|
+
l1: lastCalldataCheckpoint.l1,
|
|
1102
|
+
attestations: lastCalldataCheckpoint.attestations,
|
|
1103
|
+
checkpoint: maybeValidCheckpointToPromote
|
|
1104
|
+
}, evictProposedFrom)));
|
|
1105
|
+
if (checkpointsToAdd.length > 0) {
|
|
1106
|
+
this.instrumentation.processNewCheckpointedBlocks(processDuration / checkpointsToAdd.length, checkpointsToAdd.flatMap((c)=>c.checkpoint.blocks));
|
|
1107
|
+
}
|
|
1020
1108
|
// If blocks were pruned due to conflict with L1 checkpoints, emit event
|
|
1021
1109
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
1022
1110
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
1023
1111
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
1024
|
-
this.log.
|
|
1112
|
+
this.log.info(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
|
|
1025
1113
|
prunedBlocks: result.prunedBlocks.map((b)=>b.toBlockInfo()),
|
|
1026
1114
|
prunedSlotNumber,
|
|
1027
1115
|
prunedCheckpointNumber
|
|
@@ -1061,7 +1149,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1061
1149
|
});
|
|
1062
1150
|
}
|
|
1063
1151
|
lastRetrievedCheckpoint = validCheckpoints.at(-1) ?? lastRetrievedCheckpoint;
|
|
1064
|
-
lastL1BlockWithCheckpoint =
|
|
1152
|
+
lastL1BlockWithCheckpoint = calldataCheckpoints.at(-1)?.l1.blockNumber ?? lastL1BlockWithCheckpoint;
|
|
1065
1153
|
}while (searchEndBlock < currentL1BlockNumber)
|
|
1066
1154
|
// Important that we update AFTER inserting the blocks.
|
|
1067
1155
|
await updateProvenCheckpoint();
|
|
@@ -1071,6 +1159,66 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1071
1159
|
lastL1BlockWithCheckpoint
|
|
1072
1160
|
};
|
|
1073
1161
|
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Checks if a specific checkpoint matches a local pending entry, and if so, loads local data to build
|
|
1164
|
+
* a synthetic published checkpoint (skipping blob fetch).
|
|
1165
|
+
*
|
|
1166
|
+
* Returns { diverged: true, fromCheckpointNumber } when the L1 checkpoint does NOT match local pending
|
|
1167
|
+
* data for that number, so the caller can evict the entire pending suffix >= fromCheckpointNumber
|
|
1168
|
+
* (those entries chain off the now-invalid local state) within the same addCheckpoints transaction.
|
|
1169
|
+
*/ async tryBuildPublishedCheckpointFromProposed(calldataCheckpoint) {
|
|
1170
|
+
if (this.config.skipPromoteProposedCheckpointDuringL1Sync || !calldataCheckpoint) {
|
|
1171
|
+
return undefined;
|
|
1172
|
+
}
|
|
1173
|
+
// Look up the specific pending entry for the checkpoint being mined, not just the tip
|
|
1174
|
+
const proposed = await this.store.getProposedCheckpointByNumber(calldataCheckpoint.checkpointNumber);
|
|
1175
|
+
if (!proposed) {
|
|
1176
|
+
return undefined;
|
|
1177
|
+
}
|
|
1178
|
+
if (!proposed.header.equals(calldataCheckpoint.header) || !proposed.archive.root.equals(calldataCheckpoint.archiveRoot)) {
|
|
1179
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} does not match checkpoint retrieved from L1, overriding with L1 data`, {
|
|
1180
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1181
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1182
|
+
proposedArchiveRoot: proposed.archive.root.toString(),
|
|
1183
|
+
calldataCheckpointNumber: calldataCheckpoint.checkpointNumber,
|
|
1184
|
+
calldataHeader: calldataCheckpoint.header.toInspect(),
|
|
1185
|
+
calldataArchiveRoot: calldataCheckpoint.archiveRoot.toString()
|
|
1186
|
+
});
|
|
1187
|
+
// Return a divergence signal so the caller can evict pending >= this number
|
|
1188
|
+
return {
|
|
1189
|
+
diverged: true,
|
|
1190
|
+
fromCheckpointNumber: proposed.checkpointNumber
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
this.log.debug(`Building published checkpoint from proposed ${calldataCheckpoint.checkpointNumber} (skipping blob fetch)`, {
|
|
1194
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1195
|
+
proposedArchiveRoot: proposed.archive.root.toString()
|
|
1196
|
+
});
|
|
1197
|
+
const blocks = await this.store.getBlocks(BlockNumber(proposed.startBlock), proposed.blockCount);
|
|
1198
|
+
if (blocks.length !== proposed.blockCount) {
|
|
1199
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} has wrong block count (expected ${proposed.blockCount} blocks starting at ${proposed.startBlock} but got ${blocks.length})`, {
|
|
1200
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1201
|
+
proposedStartBlock: proposed.startBlock,
|
|
1202
|
+
proposedBlockCount: proposed.blockCount,
|
|
1203
|
+
retrievedBlocks: blocks.map((b)=>b.number)
|
|
1204
|
+
});
|
|
1205
|
+
return undefined;
|
|
1206
|
+
}
|
|
1207
|
+
const checkpoint = Checkpoint.from({
|
|
1208
|
+
archive: proposed.archive,
|
|
1209
|
+
header: proposed.header,
|
|
1210
|
+
blocks,
|
|
1211
|
+
number: proposed.checkpointNumber,
|
|
1212
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier
|
|
1213
|
+
});
|
|
1214
|
+
const promotedCheckpoint = PublishedCheckpoint.from({
|
|
1215
|
+
checkpoint,
|
|
1216
|
+
l1: calldataCheckpoint.l1,
|
|
1217
|
+
attestations: calldataCheckpoint.attestations
|
|
1218
|
+
});
|
|
1219
|
+
this.instrumentation.processCheckpointPromoted();
|
|
1220
|
+
return promotedCheckpoint;
|
|
1221
|
+
}
|
|
1074
1222
|
async checkForNewCheckpointsBeforeL1SyncPoint(status, blocksSynchedTo, currentL1BlockNumber) {
|
|
1075
1223
|
const { lastRetrievedCheckpoint, pendingCheckpointNumber } = status;
|
|
1076
1224
|
// Compare the last checkpoint we have (either retrieved in this round or loaded from store) with what the
|