@aztec/archiver 0.0.1-commit.e558bd1c → 0.0.1-commit.e5a3663dd
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 +26 -15
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +161 -153
- 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 +6 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +40 -32
- package/dest/index.d.ts +11 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +10 -2
- package/dest/l1/bin/retrieve-calldata.js +32 -28
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +197 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +42 -47
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- 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/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +42 -0
- package/dest/modules/data_source_base.d.ts +27 -14
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +98 -125
- package/dest/modules/data_store_updater.d.ts +37 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +155 -112
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +41 -8
- package/dest/modules/l1_synchronizer.d.ts +13 -11
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +355 -182
- 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 +107 -31
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +477 -141
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +50 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- 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 +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- 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 +35 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +182 -89
- 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 +7 -4
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +14 -8
- package/package.json +13 -13
- package/src/archiver.ts +199 -174
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +53 -30
- package/src/index.ts +18 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +261 -379
- package/src/l1/data_retrieval.ts +58 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +59 -0
- package/src/modules/data_source_base.ts +142 -144
- package/src/modules/data_store_updater.ts +187 -141
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +463 -218
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +587 -177
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +108 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +230 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +16 -8
- package/dest/store/kv_archiver_store.d.ts +0 -340
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -446
- package/src/store/kv_archiver_store.ts +0 -639
|
@@ -371,20 +371,27 @@ 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 { compactArray, 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 { getArchiverSynchPoint } from '../store/data_stores.js';
|
|
394
|
+
import { MessageStoreError } from '../store/message_store.js';
|
|
388
395
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
389
396
|
import { validateCheckpointAttestations } from './validation.js';
|
|
390
397
|
_dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpochPrune'), _dec2 = trackSpan('Archiver.handleL1ToL2Messages'), _dec3 = trackSpan('Archiver.handleCheckpoints');
|
|
@@ -396,8 +403,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
396
403
|
debugClient;
|
|
397
404
|
rollup;
|
|
398
405
|
inbox;
|
|
399
|
-
|
|
400
|
-
store;
|
|
406
|
+
stores;
|
|
401
407
|
config;
|
|
402
408
|
blobClient;
|
|
403
409
|
epochCache;
|
|
@@ -435,13 +441,12 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
435
441
|
l1Timestamp;
|
|
436
442
|
updater;
|
|
437
443
|
tracer;
|
|
438
|
-
constructor(publicClient, debugClient, rollup, inbox,
|
|
444
|
+
constructor(publicClient, debugClient, rollup, inbox, stores, config, blobClient, epochCache, dateProvider, instrumentation, l1Constants, events, tracer, l2TipsCache, log = createLogger('archiver:l1-sync')){
|
|
439
445
|
this.publicClient = publicClient;
|
|
440
446
|
this.debugClient = debugClient;
|
|
441
447
|
this.rollup = rollup;
|
|
442
448
|
this.inbox = inbox;
|
|
443
|
-
this.
|
|
444
|
-
this.store = store;
|
|
449
|
+
this.stores = stores;
|
|
445
450
|
this.config = config;
|
|
446
451
|
this.blobClient = blobClient;
|
|
447
452
|
this.epochCache = epochCache;
|
|
@@ -451,7 +456,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
451
456
|
this.events = events;
|
|
452
457
|
this.log = log;
|
|
453
458
|
_initProto(this);
|
|
454
|
-
this.updater = new ArchiverDataStoreUpdater(this.
|
|
459
|
+
this.updater = new ArchiverDataStoreUpdater(this.stores, l2TipsCache, {
|
|
460
|
+
rollupManaLimit: l1Constants.rollupManaLimit
|
|
461
|
+
});
|
|
455
462
|
this.tracer = tracer;
|
|
456
463
|
}
|
|
457
464
|
/** Sets new config */ setConfig(newConfig) {
|
|
@@ -463,6 +470,12 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
463
470
|
/** Returns the last L1 timestamp that was synced. */ getL1Timestamp() {
|
|
464
471
|
return this.l1Timestamp;
|
|
465
472
|
}
|
|
473
|
+
getSignatureContext() {
|
|
474
|
+
return {
|
|
475
|
+
chainId: this.publicClient.chain.id,
|
|
476
|
+
rollupAddress: EthAddress.fromString(this.rollup.address)
|
|
477
|
+
};
|
|
478
|
+
}
|
|
466
479
|
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */ async testEthereumNodeSynced() {
|
|
467
480
|
const maxAllowedDelay = this.config.maxAllowedEthClientDriftSeconds;
|
|
468
481
|
if (maxAllowedDelay === 0) {
|
|
@@ -477,12 +490,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
477
490
|
}
|
|
478
491
|
}
|
|
479
492
|
async syncFromL1(initialSyncComplete) {
|
|
493
|
+
// In between the various calls to L1, the block number can move meaning some of the following
|
|
494
|
+
// calls will return data for blocks that were not present during earlier calls. To combat this
|
|
495
|
+
// we ensure that all data retrieval methods only retrieve data up to the currentBlockNumber
|
|
496
|
+
// captured at the top of this function.
|
|
480
497
|
const currentL1Block = await this.publicClient.getBlock({
|
|
481
498
|
includeTransactions: false
|
|
482
499
|
});
|
|
483
500
|
const currentL1BlockNumber = currentL1Block.number;
|
|
484
501
|
const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
|
|
485
502
|
const currentL1Timestamp = currentL1Block.timestamp;
|
|
503
|
+
const currentL1BlockData = {
|
|
504
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
505
|
+
l1BlockHash: currentL1BlockHash
|
|
506
|
+
};
|
|
486
507
|
if (this.l1BlockHash && currentL1BlockHash.equals(this.l1BlockHash)) {
|
|
487
508
|
this.log.trace(`No new L1 blocks since last sync at L1 block ${this.l1BlockNumber}`);
|
|
488
509
|
return;
|
|
@@ -498,36 +519,23 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
498
519
|
maxAllowedDelay
|
|
499
520
|
});
|
|
500
521
|
}
|
|
501
|
-
//
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
522
|
+
// Query finalized block on L1
|
|
523
|
+
const rawFinalizedL1Block = await getFinalizedL1Block(this.publicClient);
|
|
524
|
+
const finalizedL1Block = rawFinalizedL1Block && {
|
|
525
|
+
l1BlockNumber: rawFinalizedL1Block.number,
|
|
526
|
+
l1BlockHash: Buffer32.fromString(rawFinalizedL1Block.hash)
|
|
527
|
+
};
|
|
528
|
+
// Load sync point for blocks defaulting to start block
|
|
529
|
+
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await getArchiverSynchPoint(this.stores);
|
|
506
530
|
this.log.debug(`Starting new archiver sync iteration`, {
|
|
507
531
|
blocksSynchedTo,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
currentL1BlockHash
|
|
532
|
+
currentL1BlockData,
|
|
533
|
+
finalizedL1Block
|
|
511
534
|
});
|
|
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 **********
|
|
535
|
+
// 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.
|
|
536
|
+
// 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
|
|
537
|
+
// block, when that wouldn't be the case, since L1 to L2 messages would need another iteration.
|
|
538
|
+
await retryTimes(()=>this.handleL1ToL2Messages(currentL1BlockData, finalizedL1Block), 'Handling L1 to L2 messages', 3, 0.1);
|
|
531
539
|
if (currentL1BlockNumber > blocksSynchedTo) {
|
|
532
540
|
// First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
|
|
533
541
|
// pending chain validation status, proven checkpoint number, and synched L1 block number.
|
|
@@ -544,7 +552,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
544
552
|
// past it, since otherwise we'll keep downloading it and reprocessing it on every iteration until
|
|
545
553
|
// we get a valid checkpoint to advance the syncpoint.
|
|
546
554
|
if (!rollupStatus.validationResult?.valid && rollupStatus.lastL1BlockWithCheckpoint !== undefined) {
|
|
547
|
-
await this.
|
|
555
|
+
await this.stores.blocks.setSynchedL1BlockNumber(rollupStatus.lastL1BlockWithCheckpoint);
|
|
548
556
|
}
|
|
549
557
|
// And lastly we check if we are missing any checkpoints behind us due to a possible L1 reorg.
|
|
550
558
|
// We only do this if rollup cant prune on the next submission. Otherwise we will end up
|
|
@@ -555,6 +563,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
555
563
|
}
|
|
556
564
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
557
565
|
}
|
|
566
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
567
|
+
await this.updateFinalizedCheckpoint(finalizedL1Block);
|
|
558
568
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
559
569
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
560
570
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -568,36 +578,63 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
568
578
|
l1BlockNumberAtEnd
|
|
569
579
|
});
|
|
570
580
|
}
|
|
581
|
+
/** Updates the finalized checkpoint using the pre-fetched finalized L1 block from the current sync iteration. */ async updateFinalizedCheckpoint(finalizedL1Block) {
|
|
582
|
+
try {
|
|
583
|
+
if (!finalizedL1Block) {
|
|
584
|
+
this.log.trace(`Skipping finalized checkpoint update: L1 has no finalized block yet.`);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const finalizedL1BlockNumber = finalizedL1Block.l1BlockNumber;
|
|
588
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
589
|
+
blockNumber: finalizedL1BlockNumber
|
|
590
|
+
});
|
|
591
|
+
const localFinalizedCheckpointNumber = await this.stores.blocks.getFinalizedCheckpointNumber();
|
|
592
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
593
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
594
|
+
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
595
|
+
finalizedCheckpointNumber,
|
|
596
|
+
finalizedL1BlockNumber
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
} catch (err) {
|
|
600
|
+
// The rollup contract may not exist at the finalized L1 block right after deployment.
|
|
601
|
+
if (!err?.message?.includes('returned no data')) {
|
|
602
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
571
606
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
572
607
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
573
|
-
this.
|
|
574
|
-
this.
|
|
608
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
609
|
+
this.stores.blocks.getLatestL2BlockNumber()
|
|
575
610
|
]);
|
|
576
611
|
// If there are no uncheckpointed blocks, we got nothing to do
|
|
577
612
|
if (lastProposedBlockNumber === lastCheckpointedBlockNumber) {
|
|
578
613
|
this.log.trace(`No uncheckpointed blocks to prune.`);
|
|
579
614
|
return;
|
|
580
615
|
}
|
|
581
|
-
// What's the slot of the first uncheckpointed block?
|
|
582
|
-
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
583
|
-
const [firstUncheckpointedBlockHeader] = await this.store.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
584
|
-
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
585
616
|
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
586
617
|
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
618
|
+
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
619
|
+
// What's the slot of the first uncheckpointed block?
|
|
620
|
+
const [firstUncheckpointedBlockHeader] = await this.stores.blocks.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
621
|
+
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
622
|
+
if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
// Prune provisional blocks from slots that have ended without being checkpointed.
|
|
626
|
+
// This also clears any proposed checkpoint whose blocks are being pruned.
|
|
627
|
+
this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
|
|
628
|
+
firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
|
|
629
|
+
slotAtNextL1Block
|
|
630
|
+
});
|
|
631
|
+
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
632
|
+
if (prunedBlocks.length > 0) {
|
|
633
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
634
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
635
|
+
slotNumber: firstUncheckpointedBlockSlot,
|
|
636
|
+
blocks: prunedBlocks
|
|
592
637
|
});
|
|
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
638
|
}
|
|
602
639
|
}
|
|
603
640
|
/** Queries the rollup contract on whether a prune can be executed on the immediate next L1 block. */ async canPrune(currentL1BlockNumber, currentL1Timestamp) {
|
|
@@ -616,7 +653,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
616
653
|
}
|
|
617
654
|
/** Checks if there'd be a reorg for the next checkpoint submission and start pruning now. */ async handleEpochPrune(provenCheckpointNumber, currentL1BlockNumber, currentL1Timestamp) {
|
|
618
655
|
const rollupCanPrune = await this.canPrune(currentL1BlockNumber, currentL1Timestamp);
|
|
619
|
-
const localPendingCheckpointNumber = await this.
|
|
656
|
+
const localPendingCheckpointNumber = await this.stores.blocks.getLatestCheckpointNumber();
|
|
620
657
|
const canPrune = localPendingCheckpointNumber > provenCheckpointNumber && rollupCanPrune;
|
|
621
658
|
if (canPrune) {
|
|
622
659
|
const timer = new Timer();
|
|
@@ -628,12 +665,14 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
628
665
|
const pruneFromSlotNumber = header.slotNumber;
|
|
629
666
|
const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1Constants);
|
|
630
667
|
const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
|
|
631
|
-
|
|
668
|
+
// Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
|
|
669
|
+
// promises when the gap between local pending and proven checkpoint numbers is large.
|
|
670
|
+
const BATCH_SIZE = 10;
|
|
671
|
+
const indices = Array.from({
|
|
632
672
|
length: checkpointsToUnwind
|
|
633
|
-
}
|
|
634
|
-
const checkpoints = await
|
|
635
|
-
const
|
|
636
|
-
const newBlocks = blockPromises.filter(isDefined).flat();
|
|
673
|
+
}, (_, i)=>CheckpointNumber(i + pruneFrom));
|
|
674
|
+
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.stores.blocks.getCheckpointData(idx))).filter(isDefined);
|
|
675
|
+
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.stores.blocks.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
|
|
637
676
|
// Emit an event for listening services to react to the chain prune
|
|
638
677
|
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
|
|
639
678
|
type: L2BlockSourceEvents.L2PruneUnproven,
|
|
@@ -642,11 +681,11 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
642
681
|
});
|
|
643
682
|
this.log.debug(`L2 prune from ${provenCheckpointNumber + 1} to ${localPendingCheckpointNumber} will occur on next checkpoint submission.`);
|
|
644
683
|
await this.updater.removeCheckpointsAfter(provenCheckpointNumber);
|
|
645
|
-
this.log.warn(`Removed ${count(checkpointsToUnwind, 'checkpoint')} after checkpoint ${provenCheckpointNumber} ` + `due to predicted reorg at L1 block ${currentL1BlockNumber}. ` + `Updated latest checkpoint is ${await this.
|
|
684
|
+
this.log.warn(`Removed ${count(checkpointsToUnwind, 'checkpoint')} after checkpoint ${provenCheckpointNumber} ` + `due to predicted reorg at L1 block ${currentL1BlockNumber}. ` + `Updated latest checkpoint is ${await this.stores.blocks.getLatestCheckpointNumber()}.`);
|
|
646
685
|
this.instrumentation.processPrune(timer.ms());
|
|
647
686
|
// TODO(palla/reorg): Do we need to set the block synched L1 block number here?
|
|
648
687
|
// Seems like the next iteration should handle this.
|
|
649
|
-
// await this.
|
|
688
|
+
// await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
650
689
|
}
|
|
651
690
|
return {
|
|
652
691
|
rollupCanPrune
|
|
@@ -667,59 +706,79 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
667
706
|
nextEnd
|
|
668
707
|
];
|
|
669
708
|
}
|
|
670
|
-
async handleL1ToL2Messages(
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
709
|
+
async handleL1ToL2Messages(currentL1Block, finalizedL1Block) {
|
|
710
|
+
// Load the syncpoint, which may have been updated in a previous iteration
|
|
711
|
+
const { messagesSynchedTo = {
|
|
712
|
+
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
713
|
+
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
714
|
+
} } = await getArchiverSynchPoint(this.stores);
|
|
715
|
+
// Nothing to do if L1 block number has not moved forward
|
|
716
|
+
const currentL1BlockNumber = currentL1Block.l1BlockNumber;
|
|
717
|
+
if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
|
|
718
|
+
return true;
|
|
674
719
|
}
|
|
675
|
-
//
|
|
676
|
-
const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
|
|
677
|
-
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
720
|
+
// Compare local message store state with the remote. If they match, we just advance the match pointer.
|
|
678
721
|
const remoteMessagesState = await this.inbox.getState({
|
|
679
722
|
blockNumber: currentL1BlockNumber
|
|
680
723
|
});
|
|
681
|
-
this.
|
|
682
|
-
|
|
683
|
-
|
|
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;
|
|
724
|
+
const localLastMessage = await this.stores.messages.getLastMessage();
|
|
725
|
+
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
|
|
726
|
+
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
|
|
727
|
+
await this.stores.messages.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress, finalizedL1Block);
|
|
728
|
+
return true;
|
|
690
729
|
}
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
-
//
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
this.
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
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
|
|
730
|
+
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
|
|
731
|
+
// However, it could also be the case that there was an L1 reorg and our syncpoint is no longer valid.
|
|
732
|
+
// If that's the case, we'd get an exception out of the message store since the rolling hash of the first message
|
|
733
|
+
// we try to insert would not match the one in the db, in which case we rollback to the last common message with L1.
|
|
734
|
+
try {
|
|
735
|
+
await this.retrieveAndStoreMessages(messagesSynchedTo.l1BlockNumber, currentL1BlockNumber);
|
|
736
|
+
} catch (error) {
|
|
737
|
+
if (isErrorClass(error, MessageStoreError)) {
|
|
738
|
+
this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
|
|
739
|
+
inboxMessage: error.inboxMessage
|
|
709
740
|
});
|
|
741
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
742
|
+
return false;
|
|
710
743
|
}
|
|
744
|
+
throw error;
|
|
745
|
+
}
|
|
746
|
+
// Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
|
|
747
|
+
// we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
|
|
748
|
+
// our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
|
|
749
|
+
const localLastMessageAfterSync = await this.stores.messages.getLastMessage();
|
|
750
|
+
if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
|
|
751
|
+
this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
|
|
752
|
+
localLastMessageAfterSync,
|
|
753
|
+
remoteMessagesState
|
|
754
|
+
});
|
|
755
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
756
|
+
return false;
|
|
711
757
|
}
|
|
712
|
-
//
|
|
758
|
+
// Advance the syncpoint after a successful sync
|
|
759
|
+
await this.stores.messages.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress, finalizedL1Block);
|
|
760
|
+
return true;
|
|
761
|
+
}
|
|
762
|
+
/** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
|
|
763
|
+
const localMessageCount = await this.stores.messages.getTotalL1ToL2MessageCount();
|
|
764
|
+
this.log.trace(`Comparing local and remote inbox state`, {
|
|
765
|
+
localMessageCount,
|
|
766
|
+
localLastMessage,
|
|
767
|
+
remoteState
|
|
768
|
+
});
|
|
769
|
+
return remoteState.totalMessagesInserted === localMessageCount && remoteState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO);
|
|
770
|
+
}
|
|
771
|
+
/** Retrieves L1 to L2 messages from L1 in batches and stores them. */ async retrieveAndStoreMessages(fromL1Block, toL1Block) {
|
|
713
772
|
let searchStartBlock = 0n;
|
|
714
|
-
let searchEndBlock =
|
|
773
|
+
let searchEndBlock = fromL1Block;
|
|
715
774
|
let lastMessage;
|
|
716
775
|
let messageCount = 0;
|
|
717
776
|
do {
|
|
718
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock,
|
|
777
|
+
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, toL1Block);
|
|
719
778
|
this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
720
779
|
const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
|
|
721
780
|
const timer = new Timer();
|
|
722
|
-
await this.
|
|
781
|
+
await this.stores.messages.addL1ToL2Messages(messages);
|
|
723
782
|
const perMsg = timer.ms() / messages.length;
|
|
724
783
|
this.instrumentation.processNewMessages(messages.length, perMsg);
|
|
725
784
|
for (const msg of messages){
|
|
@@ -730,74 +789,94 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
730
789
|
lastMessage = msg;
|
|
731
790
|
messageCount++;
|
|
732
791
|
}
|
|
733
|
-
}while (searchEndBlock <
|
|
734
|
-
// Log stats for messages retrieved (if any).
|
|
792
|
+
}while (searchEndBlock < toL1Block)
|
|
735
793
|
if (messageCount > 0) {
|
|
736
794
|
this.log.info(`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`, {
|
|
737
795
|
lastMessage,
|
|
738
796
|
messageCount
|
|
739
797
|
});
|
|
740
798
|
}
|
|
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
799
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
}while (searchEndBlock < currentL1BlockNumber)
|
|
760
|
-
return undefined;
|
|
761
|
-
}
|
|
762
|
-
async rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint) {
|
|
763
|
-
// Slowly go back through our messages until we find the last common message.
|
|
764
|
-
// We could query the logs in batch as an optimization, but the depth of the reorg should not be deep, and this
|
|
765
|
-
// is a very rare case, so it's fine to query one log at a time.
|
|
800
|
+
/**
|
|
801
|
+
* 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.
|
|
802
|
+
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
|
|
803
|
+
*/ async rollbackL1ToL2Messages(remoteMessagesState) {
|
|
804
|
+
const { treeInProgress: remoteTreeInProgress, messagesRollingHash: remoteRollingHash } = remoteMessagesState;
|
|
805
|
+
const messagesFinalizedL1Block = await this.stores.messages.getMessagesFinalizedL1Block();
|
|
806
|
+
const finalizedL1BlockNumber = messagesFinalizedL1Block?.l1BlockNumber;
|
|
807
|
+
// Slowly go back through our messages until we find the last common message. We could query the logs in
|
|
808
|
+
// batch as an optimization, but the depth of the reorg should not be deep, and this is a very rare case,
|
|
809
|
+
// so it's fine to query one log at a time.
|
|
766
810
|
let commonMsg;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
811
|
+
let messagesToDelete = 0;
|
|
812
|
+
this.log.verbose(`Searching most recent common L1 to L2 message`);
|
|
813
|
+
for await (const localMsg of this.stores.messages.iterateL1ToL2Messages({
|
|
814
|
+
reverse: true
|
|
771
815
|
})){
|
|
772
|
-
const remoteMsg = await this.retrieveL1ToL2Message(msg.leaf);
|
|
773
816
|
const logCtx = {
|
|
774
|
-
remoteMsg,
|
|
775
|
-
localMsg
|
|
817
|
+
remoteMsg: undefined,
|
|
818
|
+
localMsg,
|
|
819
|
+
remoteMessagesState
|
|
776
820
|
};
|
|
777
|
-
if
|
|
778
|
-
|
|
821
|
+
// First check if the local message rolling hash matches the current rolling hash of the inbox contract,
|
|
822
|
+
// which means we just need to rollback some local messages and we should be back in sync. This means there
|
|
823
|
+
// was an L1 reorg that removed some of the messages we had, but no new messages were added compared.
|
|
824
|
+
if (localMsg.rollingHash.equals(remoteRollingHash)) {
|
|
825
|
+
this.log.info(`Found common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber} matching current remote state`, logCtx);
|
|
826
|
+
commonMsg = localMsg;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
// Messages at or below the finalized L1 block cannot have been reorged — accept as common without querying L1.
|
|
830
|
+
if (finalizedL1BlockNumber !== undefined && localMsg.l1BlockNumber <= finalizedL1BlockNumber) {
|
|
831
|
+
this.log.info(`Found common L1 to L2 message at finalized L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
832
|
+
commonMsg = localMsg;
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
// If there's no match with the current remote state, check if the message exists on the inbox contract at all
|
|
836
|
+
// by looking at the inbox events. If the L1 reorg *added* new messages in addition to deleting existing ones,
|
|
837
|
+
// then the current remote state's rolling hash will not match anything we have locally, so we need to check existence
|
|
838
|
+
// of individual messages via logs. Note we use logs and not historical queries so we don't have to depend on
|
|
839
|
+
// an archival rpc node, since the message could be from a long time ago if we're catching up with syncing.
|
|
840
|
+
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
841
|
+
logCtx.remoteMsg = remoteMsg;
|
|
842
|
+
if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
|
|
843
|
+
this.log.info(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
779
844
|
commonMsg = remoteMsg;
|
|
780
845
|
break;
|
|
781
846
|
} else if (remoteMsg) {
|
|
782
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
847
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} has different rolling hash`, logCtx);
|
|
848
|
+
messagesToDelete++;
|
|
783
849
|
} else {
|
|
784
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
850
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} not found on L1`, logCtx);
|
|
851
|
+
messagesToDelete++;
|
|
785
852
|
}
|
|
786
853
|
}
|
|
787
|
-
// Delete everything after the common message we found.
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
854
|
+
// Delete everything after the common message we found, if anything needs to be deleted.
|
|
855
|
+
// Do not exit early if there are no messages to delete, we still want to update the syncpoint.
|
|
856
|
+
if (messagesToDelete > 0) {
|
|
857
|
+
const lastGoodIndex = commonMsg?.index;
|
|
858
|
+
this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
|
|
859
|
+
await this.stores.messages.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
|
|
860
|
+
}
|
|
791
861
|
// Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
|
|
792
862
|
// the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
|
|
793
|
-
// after the last common message.
|
|
794
|
-
|
|
795
|
-
const
|
|
796
|
-
|
|
863
|
+
// after the last common message. Cap at the finalized L1 block: messages at or below finalized cannot
|
|
864
|
+
// have been reorged, so there is no need to walk back any further than that.
|
|
865
|
+
const syncPointL1BlockNumber = maxBigint(...compactArray([
|
|
866
|
+
commonMsg ? commonMsg.l1BlockNumber - 1n : undefined,
|
|
867
|
+
finalizedL1BlockNumber,
|
|
868
|
+
this.l1Constants.l1StartBlock
|
|
869
|
+
]));
|
|
870
|
+
const syncPointL1BlockHash = syncPointL1BlockNumber === finalizedL1BlockNumber ? messagesFinalizedL1Block.l1BlockHash : await this.getL1BlockHash(syncPointL1BlockNumber);
|
|
871
|
+
const messagesSyncPoint = {
|
|
797
872
|
l1BlockNumber: syncPointL1BlockNumber,
|
|
798
873
|
l1BlockHash: syncPointL1BlockHash
|
|
799
874
|
};
|
|
800
|
-
await this.
|
|
875
|
+
await this.stores.messages.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
|
|
876
|
+
this.log.verbose(`Updated messages syncpoint to L1 block ${messagesSyncPoint.l1BlockNumber}`, {
|
|
877
|
+
...messagesSyncPoint,
|
|
878
|
+
remoteTreeInProgress
|
|
879
|
+
});
|
|
801
880
|
return messagesSyncPoint;
|
|
802
881
|
}
|
|
803
882
|
async getL1BlockHash(l1BlockNumber) {
|
|
@@ -811,8 +890,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
811
890
|
return Buffer32.fromString(block.hash);
|
|
812
891
|
}
|
|
813
892
|
async handleCheckpoints(blocksSynchedTo, currentL1BlockNumber, initialSyncComplete) {
|
|
814
|
-
const localPendingCheckpointNumber = await this.
|
|
815
|
-
const initialValidationResult = await this.
|
|
893
|
+
const localPendingCheckpointNumber = await this.stores.blocks.getLatestCheckpointNumber();
|
|
894
|
+
const initialValidationResult = await this.stores.blocks.getPendingChainValidationStatus();
|
|
816
895
|
const { provenCheckpointNumber, provenArchive, pendingCheckpointNumber, pendingArchive, archiveOfMyCheckpoint: archiveForLocalPendingCheckpointNumber } = await execInSpan(this.tracer, 'Archiver.getRollupStatus', ()=>this.rollup.status(localPendingCheckpointNumber, {
|
|
817
896
|
blockNumber: currentL1BlockNumber
|
|
818
897
|
}));
|
|
@@ -835,39 +914,39 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
835
914
|
// we need to set it to zero. This is an edge case because we dont have a checkpoint zero (initial checkpoint is one),
|
|
836
915
|
// so localCheckpointForDestinationProvenCheckpointNumber would not be found below.
|
|
837
916
|
if (provenCheckpointNumber === 0) {
|
|
838
|
-
const localProvenCheckpointNumber = await this.
|
|
917
|
+
const localProvenCheckpointNumber = await this.stores.blocks.getProvenCheckpointNumber();
|
|
839
918
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
840
|
-
await this.
|
|
919
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
841
920
|
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
842
921
|
provenCheckpointNumber
|
|
843
922
|
});
|
|
844
923
|
}
|
|
845
924
|
}
|
|
846
|
-
const localCheckpointForDestinationProvenCheckpointNumber = await this.
|
|
925
|
+
const localCheckpointForDestinationProvenCheckpointNumber = await this.stores.blocks.getCheckpointData(provenCheckpointNumber);
|
|
847
926
|
// Sanity check. I've hit what seems to be a state where the proven checkpoint is set to a value greater than the latest
|
|
848
927
|
// synched checkpoint when requesting L2Tips from the archiver. This is the only place where the proven checkpoint is set.
|
|
849
|
-
const synched = await this.
|
|
928
|
+
const synched = await this.stores.blocks.getLatestCheckpointNumber();
|
|
850
929
|
if (localCheckpointForDestinationProvenCheckpointNumber && synched < localCheckpointForDestinationProvenCheckpointNumber.checkpointNumber) {
|
|
851
930
|
this.log.error(`Hit local checkpoint greater than last synched checkpoint: ${localCheckpointForDestinationProvenCheckpointNumber.checkpointNumber} > ${synched}`);
|
|
852
931
|
}
|
|
853
932
|
this.log.trace(`Local checkpoint for remote proven checkpoint ${provenCheckpointNumber} is ${localCheckpointForDestinationProvenCheckpointNumber?.archive.root.toString() ?? 'undefined'}`);
|
|
854
933
|
if (localCheckpointForDestinationProvenCheckpointNumber && provenArchive.equals(localCheckpointForDestinationProvenCheckpointNumber.archive.root)) {
|
|
855
|
-
const localProvenCheckpointNumber = await this.
|
|
934
|
+
const localProvenCheckpointNumber = await this.stores.blocks.getProvenCheckpointNumber();
|
|
856
935
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
857
|
-
await this.
|
|
936
|
+
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
858
937
|
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
859
938
|
provenCheckpointNumber
|
|
860
939
|
});
|
|
861
940
|
const provenSlotNumber = localCheckpointForDestinationProvenCheckpointNumber.header.slotNumber;
|
|
862
941
|
const provenEpochNumber = getEpochAtSlot(provenSlotNumber, this.l1Constants);
|
|
863
|
-
const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.
|
|
942
|
+
const lastBlockNumberInCheckpoint = localCheckpointForDestinationProvenCheckpointNumber.startBlock + localCheckpointForDestinationProvenCheckpointNumber.blockCount - 1;
|
|
864
943
|
this.events.emit(L2BlockSourceEvents.L2BlockProven, {
|
|
865
944
|
type: L2BlockSourceEvents.L2BlockProven,
|
|
866
945
|
blockNumber: BlockNumber(lastBlockNumberInCheckpoint),
|
|
867
946
|
slotNumber: provenSlotNumber,
|
|
868
947
|
epochNumber: provenEpochNumber
|
|
869
948
|
});
|
|
870
|
-
this.instrumentation.
|
|
949
|
+
this.instrumentation.updateLastProvenCheckpoint(localCheckpointForDestinationProvenCheckpointNumber);
|
|
871
950
|
} else {
|
|
872
951
|
this.log.trace(`Proven checkpoint ${provenCheckpointNumber} already stored.`);
|
|
873
952
|
}
|
|
@@ -877,7 +956,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
877
956
|
// If we have 0 checkpoints locally and there are no checkpoints onchain there is nothing to do.
|
|
878
957
|
const noCheckpoints = localPendingCheckpointNumber === 0 && pendingCheckpointNumber === 0;
|
|
879
958
|
if (noCheckpoints) {
|
|
880
|
-
await this.
|
|
959
|
+
await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
881
960
|
this.log.debug(`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}, no checkpoints on chain`);
|
|
882
961
|
return rollupStatus;
|
|
883
962
|
}
|
|
@@ -885,7 +964,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
885
964
|
// Related to the L2 reorgs of the pending chain. We are only interested in actually addressing a reorg if there
|
|
886
965
|
// are any state that could be impacted by it. If we have no checkpoints, there is no impact.
|
|
887
966
|
if (localPendingCheckpointNumber > 0) {
|
|
888
|
-
const localPendingCheckpoint = await this.
|
|
967
|
+
const localPendingCheckpoint = await this.stores.blocks.getCheckpointData(localPendingCheckpointNumber);
|
|
889
968
|
if (localPendingCheckpoint === undefined) {
|
|
890
969
|
throw new Error(`Missing checkpoint ${localPendingCheckpointNumber}`);
|
|
891
970
|
}
|
|
@@ -899,7 +978,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
899
978
|
// However, in the re-org scenario, our L1 node is temporarily lying to us and we end up potentially missing checkpoints.
|
|
900
979
|
// We must only set this block number based on actually retrieved logs.
|
|
901
980
|
// TODO(#8621): Tackle this properly when we handle L1 Re-orgs.
|
|
902
|
-
// await this.
|
|
981
|
+
// await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
903
982
|
this.log.debug(`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}`);
|
|
904
983
|
return rollupStatus;
|
|
905
984
|
}
|
|
@@ -916,7 +995,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
916
995
|
});
|
|
917
996
|
let tipAfterUnwind = localPendingCheckpointNumber;
|
|
918
997
|
while(true){
|
|
919
|
-
const candidateCheckpoint = await this.
|
|
998
|
+
const candidateCheckpoint = await this.stores.blocks.getCheckpointData(tipAfterUnwind);
|
|
920
999
|
if (candidateCheckpoint === undefined) {
|
|
921
1000
|
break;
|
|
922
1001
|
}
|
|
@@ -932,7 +1011,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
932
1011
|
}
|
|
933
1012
|
const checkpointsToRemove = localPendingCheckpointNumber - tipAfterUnwind;
|
|
934
1013
|
await this.updater.removeCheckpointsAfter(CheckpointNumber(tipAfterUnwind));
|
|
935
|
-
this.log.warn(`Removed ${count(checkpointsToRemove, 'checkpoint')} after checkpoint ${tipAfterUnwind} ` + `due to mismatched checkpoint hashes at L1 block ${currentL1BlockNumber}. ` + `Updated L2 latest checkpoint is ${await this.
|
|
1014
|
+
this.log.warn(`Removed ${count(checkpointsToRemove, 'checkpoint')} after checkpoint ${tipAfterUnwind} ` + `due to mismatched checkpoint hashes at L1 block ${currentL1BlockNumber}. ` + `Updated L2 latest checkpoint is ${await this.stores.blocks.getLatestCheckpointNumber()}.`);
|
|
936
1015
|
}
|
|
937
1016
|
}
|
|
938
1017
|
// Retrieve checkpoints in batches. Each batch is estimated to accommodate up to 'blockBatchSize' L1 blocks,
|
|
@@ -944,25 +1023,43 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
944
1023
|
do {
|
|
945
1024
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
946
1025
|
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
947
|
-
//
|
|
948
|
-
const
|
|
949
|
-
if (
|
|
1026
|
+
// First fetch calldata only, no blobs yet, since we may be able to just get that data out of the proposed chain
|
|
1027
|
+
const calldataCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointCalldataFromRollup', ()=>retrieveCheckpointCalldataFromRollup(this.rollup, this.publicClient, this.debugClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log));
|
|
1028
|
+
if (calldataCheckpoints.length === 0) {
|
|
950
1029
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
951
1030
|
// See further details in earlier comments.
|
|
952
1031
|
this.log.trace(`Retrieved no new checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
953
1032
|
continue;
|
|
954
1033
|
}
|
|
955
|
-
this.log.debug(`Retrieved ${
|
|
956
|
-
lastProcessedCheckpoint:
|
|
1034
|
+
this.log.debug(`Retrieved ${calldataCheckpoints.length} new checkpoint calldata between L1 blocks ${searchStartBlock} and ${searchEndBlock}`, {
|
|
1035
|
+
lastProcessedCheckpoint: calldataCheckpoints[calldataCheckpoints.length - 1].l1,
|
|
957
1036
|
searchStartBlock,
|
|
958
1037
|
searchEndBlock
|
|
959
1038
|
});
|
|
960
|
-
|
|
1039
|
+
// Check if the last checkpoint matches a local pending entry (so we can skip blob fetch).
|
|
1040
|
+
// We only check the last one; if it matches, the blob fetch is skipped for that entry.
|
|
1041
|
+
// TODO(palla/pipelining): We may have more than a single checkpoint to promote
|
|
1042
|
+
const lastCalldataCheckpoint = calldataCheckpoints[calldataCheckpoints.length - 1];
|
|
1043
|
+
const promoteResult = await this.tryBuildPublishedCheckpointFromProposed(lastCalldataCheckpoint);
|
|
1044
|
+
const checkpointToPromote = promoteResult && !('diverged' in promoteResult) ? promoteResult : undefined;
|
|
1045
|
+
const evictProposedFrom = promoteResult && 'diverged' in promoteResult ? promoteResult.fromCheckpointNumber : undefined;
|
|
1046
|
+
// Then fetch blobs in parallel and build the full published checkpoints
|
|
1047
|
+
const toFetchBlobs = checkpointToPromote ? calldataCheckpoints.slice(0, -1) : calldataCheckpoints;
|
|
1048
|
+
const blobFetched = await asyncPool(10, toFetchBlobs, async (checkpoint)=>retrievedToPublishedCheckpoint({
|
|
1049
|
+
...checkpoint,
|
|
1050
|
+
checkpointBlobData: await getCheckpointBlobDataFromBlobs(this.blobClient, checkpoint.l1.blockHash, checkpoint.blobHashes, checkpoint.checkpointNumber, this.log, !initialSyncComplete, checkpoint.parentBeaconBlockRoot, checkpoint.l1.timestamp)
|
|
1051
|
+
}));
|
|
1052
|
+
// And add the promoted checkpoint to the list of all checkpoints
|
|
1053
|
+
const publishedCheckpoints = checkpointToPromote ? [
|
|
1054
|
+
...blobFetched,
|
|
1055
|
+
checkpointToPromote
|
|
1056
|
+
] : blobFetched;
|
|
961
1057
|
const validCheckpoints = [];
|
|
1058
|
+
// Now loop through all checkpoints and validate their attestations
|
|
962
1059
|
for (const published of publishedCheckpoints){
|
|
963
1060
|
const validationResult = this.config.skipValidateCheckpointAttestations ? {
|
|
964
1061
|
valid: true
|
|
965
|
-
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.log);
|
|
1062
|
+
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.getSignatureContext(), this.log);
|
|
966
1063
|
// Only update the validation result if it has changed, so we can keep track of the first invalid checkpoint
|
|
967
1064
|
// in case there is a sequence of more than one invalid checkpoint, as we need to invalidate the first one.
|
|
968
1065
|
// There is an exception though: if a checkpoint is invalidated and replaced with another invalid checkpoint,
|
|
@@ -987,7 +1084,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
987
1084
|
// Check the inHash of the checkpoint against the l1->l2 messages.
|
|
988
1085
|
// The messages should've been synced up to the currentL1BlockNumber and must be available for the published
|
|
989
1086
|
// checkpoints we just retrieved.
|
|
990
|
-
const l1ToL2Messages = await this.
|
|
1087
|
+
const l1ToL2Messages = await this.stores.messages.getL1ToL2Messages(published.checkpoint.number);
|
|
991
1088
|
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
992
1089
|
const publishedInHash = published.checkpoint.header.inHash;
|
|
993
1090
|
if (!computedInHash.equals(publishedInHash)) {
|
|
@@ -1008,15 +1105,31 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1008
1105
|
blocks: published.checkpoint.blocks.map((b)=>b.getStats())
|
|
1009
1106
|
});
|
|
1010
1107
|
}
|
|
1108
|
+
for (const published of validCheckpoints){
|
|
1109
|
+
this.instrumentation.processCheckpointL1Timing({
|
|
1110
|
+
slotNumber: published.checkpoint.header.slotNumber,
|
|
1111
|
+
l1Timestamp: published.l1.timestamp,
|
|
1112
|
+
l1Constants: this.l1Constants
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1011
1115
|
try {
|
|
1012
1116
|
const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
1013
|
-
|
|
1014
|
-
|
|
1117
|
+
// Split valid checkpoints: the promoted one (if any) is persisted via the proposed-promotion path,
|
|
1118
|
+
// the rest via addCheckpoints. Both paths run within the same store transaction for atomicity.
|
|
1119
|
+
const [[maybeValidCheckpointToPromote], checkpointsToAdd] = partition(validCheckpoints, (c)=>c.checkpoint.number === checkpointToPromote?.checkpoint.number);
|
|
1120
|
+
const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(checkpointsToAdd, updatedValidationResult, maybeValidCheckpointToPromote && {
|
|
1121
|
+
l1: lastCalldataCheckpoint.l1,
|
|
1122
|
+
attestations: lastCalldataCheckpoint.attestations,
|
|
1123
|
+
checkpoint: maybeValidCheckpointToPromote
|
|
1124
|
+
}, evictProposedFrom)));
|
|
1125
|
+
if (checkpointsToAdd.length > 0) {
|
|
1126
|
+
this.instrumentation.processNewCheckpointedBlocks(processDuration / checkpointsToAdd.length, checkpointsToAdd.flatMap((c)=>c.checkpoint.blocks));
|
|
1127
|
+
}
|
|
1015
1128
|
// If blocks were pruned due to conflict with L1 checkpoints, emit event
|
|
1016
1129
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
1017
1130
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
1018
1131
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
1019
|
-
this.log.
|
|
1132
|
+
this.log.info(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
|
|
1020
1133
|
prunedBlocks: result.prunedBlocks.map((b)=>b.toBlockInfo()),
|
|
1021
1134
|
prunedSlotNumber,
|
|
1022
1135
|
prunedCheckpointNumber
|
|
@@ -1033,9 +1146,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1033
1146
|
} catch (err) {
|
|
1034
1147
|
if (err instanceof InitialCheckpointNumberNotSequentialError) {
|
|
1035
1148
|
const { previousCheckpointNumber, newCheckpointNumber } = err;
|
|
1036
|
-
const previousCheckpoint = previousCheckpointNumber ? await this.
|
|
1149
|
+
const previousCheckpoint = previousCheckpointNumber ? await this.stores.blocks.getCheckpointData(CheckpointNumber(previousCheckpointNumber)) : undefined;
|
|
1037
1150
|
const updatedL1SyncPoint = previousCheckpoint?.l1.blockNumber ?? this.l1Constants.l1StartBlock;
|
|
1038
|
-
await this.
|
|
1151
|
+
await this.stores.blocks.setSynchedL1BlockNumber(updatedL1SyncPoint);
|
|
1039
1152
|
this.log.warn(`Attempting to insert checkpoint ${newCheckpointNumber} with previous block ${previousCheckpointNumber}. Rolling back L1 sync point to ${updatedL1SyncPoint} to try and fetch the missing blocks.`, {
|
|
1040
1153
|
previousCheckpointNumber,
|
|
1041
1154
|
newCheckpointNumber,
|
|
@@ -1056,7 +1169,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1056
1169
|
});
|
|
1057
1170
|
}
|
|
1058
1171
|
lastRetrievedCheckpoint = validCheckpoints.at(-1) ?? lastRetrievedCheckpoint;
|
|
1059
|
-
lastL1BlockWithCheckpoint =
|
|
1172
|
+
lastL1BlockWithCheckpoint = calldataCheckpoints.at(-1)?.l1.blockNumber ?? lastL1BlockWithCheckpoint;
|
|
1060
1173
|
}while (searchEndBlock < currentL1BlockNumber)
|
|
1061
1174
|
// Important that we update AFTER inserting the blocks.
|
|
1062
1175
|
await updateProvenCheckpoint();
|
|
@@ -1066,11 +1179,71 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1066
1179
|
lastL1BlockWithCheckpoint
|
|
1067
1180
|
};
|
|
1068
1181
|
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Checks if a specific checkpoint matches a local pending entry, and if so, loads local data to build
|
|
1184
|
+
* a synthetic published checkpoint (skipping blob fetch).
|
|
1185
|
+
*
|
|
1186
|
+
* Returns { diverged: true, fromCheckpointNumber } when the L1 checkpoint does NOT match local pending
|
|
1187
|
+
* data for that number, so the caller can evict the entire pending suffix >= fromCheckpointNumber
|
|
1188
|
+
* (those entries chain off the now-invalid local state) within the same addCheckpoints transaction.
|
|
1189
|
+
*/ async tryBuildPublishedCheckpointFromProposed(calldataCheckpoint) {
|
|
1190
|
+
if (this.config.skipPromoteProposedCheckpointDuringL1Sync || !calldataCheckpoint) {
|
|
1191
|
+
return undefined;
|
|
1192
|
+
}
|
|
1193
|
+
// Look up the specific pending entry for the checkpoint being mined, not just the tip
|
|
1194
|
+
const proposed = await this.stores.blocks.getProposedCheckpointByNumber(calldataCheckpoint.checkpointNumber);
|
|
1195
|
+
if (!proposed) {
|
|
1196
|
+
return undefined;
|
|
1197
|
+
}
|
|
1198
|
+
if (!proposed.header.equals(calldataCheckpoint.header) || !proposed.archive.root.equals(calldataCheckpoint.archiveRoot)) {
|
|
1199
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} does not match checkpoint retrieved from L1, overriding with L1 data`, {
|
|
1200
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1201
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1202
|
+
proposedArchiveRoot: proposed.archive.root.toString(),
|
|
1203
|
+
calldataCheckpointNumber: calldataCheckpoint.checkpointNumber,
|
|
1204
|
+
calldataHeader: calldataCheckpoint.header.toInspect(),
|
|
1205
|
+
calldataArchiveRoot: calldataCheckpoint.archiveRoot.toString()
|
|
1206
|
+
});
|
|
1207
|
+
// Return a divergence signal so the caller can evict pending >= this number
|
|
1208
|
+
return {
|
|
1209
|
+
diverged: true,
|
|
1210
|
+
fromCheckpointNumber: proposed.checkpointNumber
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
this.log.debug(`Building published checkpoint from proposed ${calldataCheckpoint.checkpointNumber} (skipping blob fetch)`, {
|
|
1214
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1215
|
+
proposedArchiveRoot: proposed.archive.root.toString()
|
|
1216
|
+
});
|
|
1217
|
+
const blocks = await this.stores.blocks.getBlocks(BlockNumber(proposed.startBlock), proposed.blockCount);
|
|
1218
|
+
if (blocks.length !== proposed.blockCount) {
|
|
1219
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} has wrong block count (expected ${proposed.blockCount} blocks starting at ${proposed.startBlock} but got ${blocks.length})`, {
|
|
1220
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1221
|
+
proposedStartBlock: proposed.startBlock,
|
|
1222
|
+
proposedBlockCount: proposed.blockCount,
|
|
1223
|
+
retrievedBlocks: blocks.map((b)=>b.number)
|
|
1224
|
+
});
|
|
1225
|
+
return undefined;
|
|
1226
|
+
}
|
|
1227
|
+
const checkpoint = Checkpoint.from({
|
|
1228
|
+
archive: proposed.archive,
|
|
1229
|
+
header: proposed.header,
|
|
1230
|
+
blocks,
|
|
1231
|
+
number: proposed.checkpointNumber,
|
|
1232
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier
|
|
1233
|
+
});
|
|
1234
|
+
const promotedCheckpoint = PublishedCheckpoint.from({
|
|
1235
|
+
checkpoint,
|
|
1236
|
+
l1: calldataCheckpoint.l1,
|
|
1237
|
+
attestations: calldataCheckpoint.attestations
|
|
1238
|
+
});
|
|
1239
|
+
this.instrumentation.processCheckpointPromoted();
|
|
1240
|
+
return promotedCheckpoint;
|
|
1241
|
+
}
|
|
1069
1242
|
async checkForNewCheckpointsBeforeL1SyncPoint(status, blocksSynchedTo, currentL1BlockNumber) {
|
|
1070
1243
|
const { lastRetrievedCheckpoint, pendingCheckpointNumber } = status;
|
|
1071
1244
|
// Compare the last checkpoint we have (either retrieved in this round or loaded from store) with what the
|
|
1072
1245
|
// rollup contract told us was the latest one (pinned at the currentL1BlockNumber).
|
|
1073
|
-
const latestLocalCheckpointNumber = lastRetrievedCheckpoint?.checkpoint.number ?? await this.
|
|
1246
|
+
const latestLocalCheckpointNumber = lastRetrievedCheckpoint?.checkpoint.number ?? await this.stores.blocks.getLatestCheckpointNumber();
|
|
1074
1247
|
if (latestLocalCheckpointNumber < pendingCheckpointNumber) {
|
|
1075
1248
|
// Here we have consumed all logs until the `currentL1Block` we pinned at the beginning of the archiver loop,
|
|
1076
1249
|
// but still haven't reached the pending checkpoint according to the call to the rollup contract.
|
|
@@ -1083,7 +1256,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1083
1256
|
latestLocalCheckpointArchive = lastRetrievedCheckpoint.checkpoint.archive.root.toString();
|
|
1084
1257
|
targetL1BlockNumber = lastRetrievedCheckpoint.l1.blockNumber;
|
|
1085
1258
|
} else if (latestLocalCheckpointNumber > 0) {
|
|
1086
|
-
const checkpoint = await this.
|
|
1259
|
+
const checkpoint = await this.stores.blocks.getRangeOfCheckpoints(latestLocalCheckpointNumber, 1).then(([c])=>c);
|
|
1087
1260
|
latestLocalCheckpointArchive = checkpoint.archive.root.toString();
|
|
1088
1261
|
targetL1BlockNumber = checkpoint.l1.blockNumber;
|
|
1089
1262
|
}
|
|
@@ -1094,7 +1267,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1094
1267
|
currentL1BlockNumber,
|
|
1095
1268
|
...status
|
|
1096
1269
|
});
|
|
1097
|
-
await this.
|
|
1270
|
+
await this.stores.blocks.setSynchedL1BlockNumber(targetL1BlockNumber);
|
|
1098
1271
|
} else {
|
|
1099
1272
|
this.log.trace(`No new checkpoints behind L1 sync point to retrieve.`, {
|
|
1100
1273
|
latestLocalCheckpointNumber,
|
|
@@ -1103,7 +1276,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1103
1276
|
}
|
|
1104
1277
|
}
|
|
1105
1278
|
async getCheckpointHeader(number) {
|
|
1106
|
-
const checkpoint = await this.
|
|
1279
|
+
const checkpoint = await this.stores.blocks.getCheckpointData(number);
|
|
1107
1280
|
if (!checkpoint) {
|
|
1108
1281
|
return undefined;
|
|
1109
1282
|
}
|