@aztec/archiver 0.0.1-commit.2b2662070 → 0.0.1-commit.2c0ee1788
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/dest/archiver.d.ts +17 -10
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +92 -53
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -3
- package/dest/errors.d.ts +32 -5
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +51 -6
- package/dest/factory.d.ts +4 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -10
- package/dest/index.d.ts +10 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -2
- 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 +9 -4
- package/dest/l1/data_retrieval.d.ts +18 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -19
- 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 +16 -10
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +71 -60
- package/dest/modules/data_store_updater.d.ts +16 -9
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +52 -40
- package/dest/modules/instrumentation.d.ts +4 -1
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +5 -0
- package/dest/modules/l1_synchronizer.d.ts +8 -4
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +182 -70
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +4 -4
- package/dest/store/block_store.d.ts +59 -21
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +181 -66
- package/dest/store/contract_class_store.d.ts +17 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +17 -1
- 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 +31 -0
- 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.js +1 -1
- package/dest/test/fake_l1_state.d.ts +7 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +42 -15
- package/dest/test/mock_l2_block_source.d.ts +12 -3
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +24 -2
- package/dest/test/noop_l1_archiver.d.ts +4 -4
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +9 -6
- package/package.json +13 -13
- package/src/archiver.ts +108 -50
- package/src/config.ts +15 -1
- package/src/errors.ts +75 -8
- package/src/factory.ts +11 -10
- package/src/index.ts +17 -2
- package/src/l1/calldata_retriever.ts +15 -4
- package/src/l1/data_retrieval.ts +30 -35
- 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 +75 -57
- package/src/modules/data_store_updater.ts +71 -39
- package/src/modules/instrumentation.ts +8 -0
- package/src/modules/l1_synchronizer.ts +241 -71
- package/src/modules/validation.ts +8 -7
- package/src/store/block_store.ts +204 -73
- package/src/store/contract_class_store.ts +28 -2
- package/src/store/contract_instance_store.ts +43 -0
- package/src/store/data_stores.ts +108 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +1 -1
- package/src/test/fake_l1_state.ts +47 -24
- package/src/test/mock_l2_block_source.ts +23 -2
- package/src/test/noop_l1_archiver.ts +9 -6
- package/dest/store/kv_archiver_store.d.ts +0 -377
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -494
- package/src/store/kv_archiver_store.ts +0 -713
|
@@ -371,22 +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';
|
|
374
375
|
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
375
376
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
376
377
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
377
378
|
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
378
|
-
import { pick } from '@aztec/foundation/collection';
|
|
379
|
+
import { partition, pick } from '@aztec/foundation/collection';
|
|
380
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
379
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
380
382
|
import { retryTimes } from '@aztec/foundation/retry';
|
|
381
383
|
import { count } from '@aztec/foundation/string';
|
|
382
384
|
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
383
385
|
import { isDefined, isErrorClass } from '@aztec/foundation/types';
|
|
384
386
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
387
|
+
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
385
388
|
import { getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
386
389
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
387
390
|
import { execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
388
391
|
import { InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
389
|
-
import {
|
|
392
|
+
import { getCheckpointBlobDataFromBlobs, retrieveCheckpointCalldataFromRollup, retrieveL1ToL2Message, retrieveL1ToL2Messages, retrievedToPublishedCheckpoint } from '../l1/data_retrieval.js';
|
|
393
|
+
import { getArchiverSynchPoint } from '../store/data_stores.js';
|
|
390
394
|
import { MessageStoreError } from '../store/message_store.js';
|
|
391
395
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
392
396
|
import { validateCheckpointAttestations } from './validation.js';
|
|
@@ -399,7 +403,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
399
403
|
debugClient;
|
|
400
404
|
rollup;
|
|
401
405
|
inbox;
|
|
402
|
-
|
|
406
|
+
stores;
|
|
403
407
|
config;
|
|
404
408
|
blobClient;
|
|
405
409
|
epochCache;
|
|
@@ -437,12 +441,12 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
437
441
|
l1Timestamp;
|
|
438
442
|
updater;
|
|
439
443
|
tracer;
|
|
440
|
-
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')){
|
|
441
445
|
this.publicClient = publicClient;
|
|
442
446
|
this.debugClient = debugClient;
|
|
443
447
|
this.rollup = rollup;
|
|
444
448
|
this.inbox = inbox;
|
|
445
|
-
this.
|
|
449
|
+
this.stores = stores;
|
|
446
450
|
this.config = config;
|
|
447
451
|
this.blobClient = blobClient;
|
|
448
452
|
this.epochCache = epochCache;
|
|
@@ -452,7 +456,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
452
456
|
this.events = events;
|
|
453
457
|
this.log = log;
|
|
454
458
|
_initProto(this);
|
|
455
|
-
this.updater = new ArchiverDataStoreUpdater(this.
|
|
459
|
+
this.updater = new ArchiverDataStoreUpdater(this.stores, l2TipsCache, {
|
|
456
460
|
rollupManaLimit: l1Constants.rollupManaLimit
|
|
457
461
|
});
|
|
458
462
|
this.tracer = tracer;
|
|
@@ -466,6 +470,12 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
466
470
|
/** Returns the last L1 timestamp that was synced. */ getL1Timestamp() {
|
|
467
471
|
return this.l1Timestamp;
|
|
468
472
|
}
|
|
473
|
+
getSignatureContext() {
|
|
474
|
+
return {
|
|
475
|
+
chainId: this.publicClient.chain.id,
|
|
476
|
+
rollupAddress: EthAddress.fromString(this.rollup.address)
|
|
477
|
+
};
|
|
478
|
+
}
|
|
469
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() {
|
|
470
480
|
const maxAllowedDelay = this.config.maxAllowedEthClientDriftSeconds;
|
|
471
481
|
if (maxAllowedDelay === 0) {
|
|
@@ -510,7 +520,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
510
520
|
});
|
|
511
521
|
}
|
|
512
522
|
// Load sync point for blocks defaulting to start block
|
|
513
|
-
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await this.
|
|
523
|
+
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await getArchiverSynchPoint(this.stores);
|
|
514
524
|
this.log.debug(`Starting new archiver sync iteration`, {
|
|
515
525
|
blocksSynchedTo,
|
|
516
526
|
currentL1BlockData
|
|
@@ -535,7 +545,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
535
545
|
// past it, since otherwise we'll keep downloading it and reprocessing it on every iteration until
|
|
536
546
|
// we get a valid checkpoint to advance the syncpoint.
|
|
537
547
|
if (!rollupStatus.validationResult?.valid && rollupStatus.lastL1BlockWithCheckpoint !== undefined) {
|
|
538
|
-
await this.
|
|
548
|
+
await this.stores.blocks.setSynchedL1BlockNumber(rollupStatus.lastL1BlockWithCheckpoint);
|
|
539
549
|
}
|
|
540
550
|
// And lastly we check if we are missing any checkpoints behind us due to a possible L1 reorg.
|
|
541
551
|
// We only do this if rollup cant prune on the next submission. Otherwise we will end up
|
|
@@ -563,15 +573,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
563
573
|
}
|
|
564
574
|
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
|
|
565
575
|
try {
|
|
566
|
-
const finalizedL1Block = await this.publicClient
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
576
|
+
const finalizedL1Block = await getFinalizedL1Block(this.publicClient);
|
|
577
|
+
if (!finalizedL1Block) {
|
|
578
|
+
this.log.trace(`Skipping finalized checkpoint update: L1 has no finalized block yet.`);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
570
581
|
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
571
582
|
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
572
583
|
blockNumber: finalizedL1BlockNumber
|
|
573
584
|
});
|
|
574
|
-
const localFinalizedCheckpointNumber = await this.
|
|
585
|
+
const localFinalizedCheckpointNumber = await this.stores.blocks.getFinalizedCheckpointNumber();
|
|
575
586
|
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
576
587
|
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
577
588
|
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
@@ -588,8 +599,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
588
599
|
}
|
|
589
600
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
590
601
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
591
|
-
this.
|
|
592
|
-
this.
|
|
602
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
603
|
+
this.stores.blocks.getLatestL2BlockNumber()
|
|
593
604
|
]);
|
|
594
605
|
// If there are no uncheckpointed blocks, we got nothing to do
|
|
595
606
|
if (lastProposedBlockNumber === lastCheckpointedBlockNumber) {
|
|
@@ -600,7 +611,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
600
611
|
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
601
612
|
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
602
613
|
// What's the slot of the first uncheckpointed block?
|
|
603
|
-
const [firstUncheckpointedBlockHeader] = await this.
|
|
614
|
+
const [firstUncheckpointedBlockHeader] = await this.stores.blocks.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
604
615
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
605
616
|
if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
|
|
606
617
|
return;
|
|
@@ -636,7 +647,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
636
647
|
}
|
|
637
648
|
/** Checks if there'd be a reorg for the next checkpoint submission and start pruning now. */ async handleEpochPrune(provenCheckpointNumber, currentL1BlockNumber, currentL1Timestamp) {
|
|
638
649
|
const rollupCanPrune = await this.canPrune(currentL1BlockNumber, currentL1Timestamp);
|
|
639
|
-
const localPendingCheckpointNumber = await this.
|
|
650
|
+
const localPendingCheckpointNumber = await this.stores.blocks.getLatestCheckpointNumber();
|
|
640
651
|
const canPrune = localPendingCheckpointNumber > provenCheckpointNumber && rollupCanPrune;
|
|
641
652
|
if (canPrune) {
|
|
642
653
|
const timer = new Timer();
|
|
@@ -654,8 +665,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
654
665
|
const indices = Array.from({
|
|
655
666
|
length: checkpointsToUnwind
|
|
656
667
|
}, (_, i)=>CheckpointNumber(i + pruneFrom));
|
|
657
|
-
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.
|
|
658
|
-
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.
|
|
668
|
+
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.stores.blocks.getCheckpointData(idx))).filter(isDefined);
|
|
669
|
+
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.stores.blocks.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
|
|
659
670
|
// Emit an event for listening services to react to the chain prune
|
|
660
671
|
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
|
|
661
672
|
type: L2BlockSourceEvents.L2PruneUnproven,
|
|
@@ -664,11 +675,11 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
664
675
|
});
|
|
665
676
|
this.log.debug(`L2 prune from ${provenCheckpointNumber + 1} to ${localPendingCheckpointNumber} will occur on next checkpoint submission.`);
|
|
666
677
|
await this.updater.removeCheckpointsAfter(provenCheckpointNumber);
|
|
667
|
-
this.log.warn(`Removed ${count(checkpointsToUnwind, 'checkpoint')} after checkpoint ${provenCheckpointNumber} ` + `due to predicted reorg at L1 block ${currentL1BlockNumber}. ` + `Updated latest checkpoint is ${await this.
|
|
678
|
+
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()}.`);
|
|
668
679
|
this.instrumentation.processPrune(timer.ms());
|
|
669
680
|
// TODO(palla/reorg): Do we need to set the block synched L1 block number here?
|
|
670
681
|
// Seems like the next iteration should handle this.
|
|
671
|
-
// await this.
|
|
682
|
+
// await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
672
683
|
}
|
|
673
684
|
return {
|
|
674
685
|
rollupCanPrune
|
|
@@ -694,7 +705,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
694
705
|
const { messagesSynchedTo = {
|
|
695
706
|
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
696
707
|
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
697
|
-
} } = await this.
|
|
708
|
+
} } = await getArchiverSynchPoint(this.stores);
|
|
698
709
|
// Nothing to do if L1 block number has not moved forward
|
|
699
710
|
const currentL1BlockNumber = currentL1Block.l1BlockNumber;
|
|
700
711
|
if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
|
|
@@ -704,10 +715,10 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
704
715
|
const remoteMessagesState = await this.inbox.getState({
|
|
705
716
|
blockNumber: currentL1BlockNumber
|
|
706
717
|
});
|
|
707
|
-
const localLastMessage = await this.
|
|
718
|
+
const localLastMessage = await this.stores.messages.getLastMessage();
|
|
708
719
|
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
|
|
709
720
|
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
|
|
710
|
-
await this.
|
|
721
|
+
await this.stores.messages.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
711
722
|
return true;
|
|
712
723
|
}
|
|
713
724
|
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
|
|
@@ -721,7 +732,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
721
732
|
this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
|
|
722
733
|
inboxMessage: error.inboxMessage
|
|
723
734
|
});
|
|
724
|
-
await this.rollbackL1ToL2Messages(remoteMessagesState
|
|
735
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
725
736
|
return false;
|
|
726
737
|
}
|
|
727
738
|
throw error;
|
|
@@ -729,21 +740,21 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
729
740
|
// Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
|
|
730
741
|
// we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
|
|
731
742
|
// our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
|
|
732
|
-
const localLastMessageAfterSync = await this.
|
|
743
|
+
const localLastMessageAfterSync = await this.stores.messages.getLastMessage();
|
|
733
744
|
if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
|
|
734
745
|
this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
|
|
735
746
|
localLastMessageAfterSync,
|
|
736
747
|
remoteMessagesState
|
|
737
748
|
});
|
|
738
|
-
await this.rollbackL1ToL2Messages(remoteMessagesState
|
|
749
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState);
|
|
739
750
|
return false;
|
|
740
751
|
}
|
|
741
752
|
// Advance the syncpoint after a successful sync
|
|
742
|
-
await this.
|
|
753
|
+
await this.stores.messages.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
743
754
|
return true;
|
|
744
755
|
}
|
|
745
756
|
/** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
|
|
746
|
-
const localMessageCount = await this.
|
|
757
|
+
const localMessageCount = await this.stores.messages.getTotalL1ToL2MessageCount();
|
|
747
758
|
this.log.trace(`Comparing local and remote inbox state`, {
|
|
748
759
|
localMessageCount,
|
|
749
760
|
localLastMessage,
|
|
@@ -761,7 +772,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
761
772
|
this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
762
773
|
const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
|
|
763
774
|
const timer = new Timer();
|
|
764
|
-
await this.
|
|
775
|
+
await this.stores.messages.addL1ToL2Messages(messages);
|
|
765
776
|
const perMsg = timer.ms() / messages.length;
|
|
766
777
|
this.instrumentation.processNewMessages(messages.length, perMsg);
|
|
767
778
|
for (const msg of messages){
|
|
@@ -783,23 +794,39 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
783
794
|
/**
|
|
784
795
|
* Rolls back local L1 to L2 messages to the last common message with L1, and updates the syncpoint to the L1 block of that message.
|
|
785
796
|
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
|
|
786
|
-
*/ async rollbackL1ToL2Messages(
|
|
787
|
-
|
|
788
|
-
//
|
|
789
|
-
//
|
|
797
|
+
*/ async rollbackL1ToL2Messages(remoteMessagesState) {
|
|
798
|
+
const { treeInProgress: remoteTreeInProgress, messagesRollingHash: remoteRollingHash } = remoteMessagesState;
|
|
799
|
+
// Slowly go back through our messages until we find the last common message. We could query the logs in
|
|
800
|
+
// batch as an optimization, but the depth of the reorg should not be deep, and this is a very rare case,
|
|
801
|
+
// so it's fine to query one log at a time.
|
|
790
802
|
let commonMsg;
|
|
791
803
|
let messagesToDelete = 0;
|
|
792
804
|
this.log.verbose(`Searching most recent common L1 to L2 message`);
|
|
793
|
-
for await (const localMsg of this.
|
|
805
|
+
for await (const localMsg of this.stores.messages.iterateL1ToL2Messages({
|
|
794
806
|
reverse: true
|
|
795
807
|
})){
|
|
796
|
-
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
797
808
|
const logCtx = {
|
|
798
|
-
remoteMsg,
|
|
799
|
-
localMsg
|
|
809
|
+
remoteMsg: undefined,
|
|
810
|
+
localMsg,
|
|
811
|
+
remoteMessagesState
|
|
800
812
|
};
|
|
813
|
+
// First check if the local message rolling hash matches the current rolling hash of the inbox contract,
|
|
814
|
+
// which means we just need to rollback some local messages and we should be back in sync. This means there
|
|
815
|
+
// was an L1 reorg that removed some of the messages we had, but no new messages were added compared.
|
|
816
|
+
if (localMsg.rollingHash.equals(remoteRollingHash)) {
|
|
817
|
+
this.log.info(`Found common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber} matching current remote state`, logCtx);
|
|
818
|
+
commonMsg = localMsg;
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
// If there's no match with the current remote state, check if the message exists on the inbox contract at all
|
|
822
|
+
// by looking at the inbox events. If the L1 reorg *added* new messages in addition to deleting existing ones,
|
|
823
|
+
// then the current remote state's rolling hash will not match anything we have locally, so we need to check existence
|
|
824
|
+
// of individual messages via logs. Note we use logs and not historical queries so we don't have to depend on
|
|
825
|
+
// an archival rpc node, since the message could be from a long time ago if we're catching up with syncing.
|
|
826
|
+
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
827
|
+
logCtx.remoteMsg = remoteMsg;
|
|
801
828
|
if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
|
|
802
|
-
this.log.
|
|
829
|
+
this.log.info(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
803
830
|
commonMsg = remoteMsg;
|
|
804
831
|
break;
|
|
805
832
|
} else if (remoteMsg) {
|
|
@@ -815,7 +842,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
815
842
|
if (messagesToDelete > 0) {
|
|
816
843
|
const lastGoodIndex = commonMsg?.index;
|
|
817
844
|
this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
|
|
818
|
-
await this.
|
|
845
|
+
await this.stores.messages.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
|
|
819
846
|
}
|
|
820
847
|
// Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
|
|
821
848
|
// the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
|
|
@@ -826,7 +853,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
826
853
|
l1BlockNumber: syncPointL1BlockNumber,
|
|
827
854
|
l1BlockHash: syncPointL1BlockHash
|
|
828
855
|
};
|
|
829
|
-
await this.
|
|
856
|
+
await this.stores.messages.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
|
|
830
857
|
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
|
|
831
858
|
...messagesSyncPoint,
|
|
832
859
|
remoteTreeInProgress
|
|
@@ -844,8 +871,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
844
871
|
return Buffer32.fromString(block.hash);
|
|
845
872
|
}
|
|
846
873
|
async handleCheckpoints(blocksSynchedTo, currentL1BlockNumber, initialSyncComplete) {
|
|
847
|
-
const localPendingCheckpointNumber = await this.
|
|
848
|
-
const initialValidationResult = await this.
|
|
874
|
+
const localPendingCheckpointNumber = await this.stores.blocks.getLatestCheckpointNumber();
|
|
875
|
+
const initialValidationResult = await this.stores.blocks.getPendingChainValidationStatus();
|
|
849
876
|
const { provenCheckpointNumber, provenArchive, pendingCheckpointNumber, pendingArchive, archiveOfMyCheckpoint: archiveForLocalPendingCheckpointNumber } = await execInSpan(this.tracer, 'Archiver.getRollupStatus', ()=>this.rollup.status(localPendingCheckpointNumber, {
|
|
850
877
|
blockNumber: currentL1BlockNumber
|
|
851
878
|
}));
|
|
@@ -868,7 +895,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
868
895
|
// we need to set it to zero. This is an edge case because we dont have a checkpoint zero (initial checkpoint is one),
|
|
869
896
|
// so localCheckpointForDestinationProvenCheckpointNumber would not be found below.
|
|
870
897
|
if (provenCheckpointNumber === 0) {
|
|
871
|
-
const localProvenCheckpointNumber = await this.
|
|
898
|
+
const localProvenCheckpointNumber = await this.stores.blocks.getProvenCheckpointNumber();
|
|
872
899
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
873
900
|
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
874
901
|
this.log.info(`Rolled back proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
@@ -876,16 +903,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
876
903
|
});
|
|
877
904
|
}
|
|
878
905
|
}
|
|
879
|
-
const localCheckpointForDestinationProvenCheckpointNumber = await this.
|
|
906
|
+
const localCheckpointForDestinationProvenCheckpointNumber = await this.stores.blocks.getCheckpointData(provenCheckpointNumber);
|
|
880
907
|
// Sanity check. I've hit what seems to be a state where the proven checkpoint is set to a value greater than the latest
|
|
881
908
|
// synched checkpoint when requesting L2Tips from the archiver. This is the only place where the proven checkpoint is set.
|
|
882
|
-
const synched = await this.
|
|
909
|
+
const synched = await this.stores.blocks.getLatestCheckpointNumber();
|
|
883
910
|
if (localCheckpointForDestinationProvenCheckpointNumber && synched < localCheckpointForDestinationProvenCheckpointNumber.checkpointNumber) {
|
|
884
911
|
this.log.error(`Hit local checkpoint greater than last synched checkpoint: ${localCheckpointForDestinationProvenCheckpointNumber.checkpointNumber} > ${synched}`);
|
|
885
912
|
}
|
|
886
913
|
this.log.trace(`Local checkpoint for remote proven checkpoint ${provenCheckpointNumber} is ${localCheckpointForDestinationProvenCheckpointNumber?.archive.root.toString() ?? 'undefined'}`);
|
|
887
914
|
if (localCheckpointForDestinationProvenCheckpointNumber && provenArchive.equals(localCheckpointForDestinationProvenCheckpointNumber.archive.root)) {
|
|
888
|
-
const localProvenCheckpointNumber = await this.
|
|
915
|
+
const localProvenCheckpointNumber = await this.stores.blocks.getProvenCheckpointNumber();
|
|
889
916
|
if (localProvenCheckpointNumber !== provenCheckpointNumber) {
|
|
890
917
|
await this.updater.setProvenCheckpointNumber(provenCheckpointNumber);
|
|
891
918
|
this.log.info(`Updated proven chain to checkpoint ${provenCheckpointNumber}`, {
|
|
@@ -910,7 +937,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
910
937
|
// If we have 0 checkpoints locally and there are no checkpoints onchain there is nothing to do.
|
|
911
938
|
const noCheckpoints = localPendingCheckpointNumber === 0 && pendingCheckpointNumber === 0;
|
|
912
939
|
if (noCheckpoints) {
|
|
913
|
-
await this.
|
|
940
|
+
await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
914
941
|
this.log.debug(`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}, no checkpoints on chain`);
|
|
915
942
|
return rollupStatus;
|
|
916
943
|
}
|
|
@@ -918,7 +945,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
918
945
|
// Related to the L2 reorgs of the pending chain. We are only interested in actually addressing a reorg if there
|
|
919
946
|
// are any state that could be impacted by it. If we have no checkpoints, there is no impact.
|
|
920
947
|
if (localPendingCheckpointNumber > 0) {
|
|
921
|
-
const localPendingCheckpoint = await this.
|
|
948
|
+
const localPendingCheckpoint = await this.stores.blocks.getCheckpointData(localPendingCheckpointNumber);
|
|
922
949
|
if (localPendingCheckpoint === undefined) {
|
|
923
950
|
throw new Error(`Missing checkpoint ${localPendingCheckpointNumber}`);
|
|
924
951
|
}
|
|
@@ -932,7 +959,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
932
959
|
// However, in the re-org scenario, our L1 node is temporarily lying to us and we end up potentially missing checkpoints.
|
|
933
960
|
// We must only set this block number based on actually retrieved logs.
|
|
934
961
|
// TODO(#8621): Tackle this properly when we handle L1 Re-orgs.
|
|
935
|
-
// await this.
|
|
962
|
+
// await this.stores.blocks.setSynchedL1BlockNumber(currentL1BlockNumber);
|
|
936
963
|
this.log.debug(`No checkpoints to retrieve from ${blocksSynchedTo + 1n} to ${currentL1BlockNumber}`);
|
|
937
964
|
return rollupStatus;
|
|
938
965
|
}
|
|
@@ -949,7 +976,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
949
976
|
});
|
|
950
977
|
let tipAfterUnwind = localPendingCheckpointNumber;
|
|
951
978
|
while(true){
|
|
952
|
-
const candidateCheckpoint = await this.
|
|
979
|
+
const candidateCheckpoint = await this.stores.blocks.getCheckpointData(tipAfterUnwind);
|
|
953
980
|
if (candidateCheckpoint === undefined) {
|
|
954
981
|
break;
|
|
955
982
|
}
|
|
@@ -965,7 +992,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
965
992
|
}
|
|
966
993
|
const checkpointsToRemove = localPendingCheckpointNumber - tipAfterUnwind;
|
|
967
994
|
await this.updater.removeCheckpointsAfter(CheckpointNumber(tipAfterUnwind));
|
|
968
|
-
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.
|
|
995
|
+
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()}.`);
|
|
969
996
|
}
|
|
970
997
|
}
|
|
971
998
|
// Retrieve checkpoints in batches. Each batch is estimated to accommodate up to 'blockBatchSize' L1 blocks,
|
|
@@ -977,25 +1004,43 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
977
1004
|
do {
|
|
978
1005
|
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
979
1006
|
this.log.trace(`Retrieving checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
980
|
-
//
|
|
981
|
-
const
|
|
982
|
-
if (
|
|
1007
|
+
// First fetch calldata only, no blobs yet, since we may be able to just get that data out of the proposed chain
|
|
1008
|
+
const calldataCheckpoints = await execInSpan(this.tracer, 'Archiver.retrieveCheckpointCalldataFromRollup', ()=>retrieveCheckpointCalldataFromRollup(this.rollup, this.publicClient, this.debugClient, searchStartBlock, searchEndBlock, this.instrumentation, this.log));
|
|
1009
|
+
if (calldataCheckpoints.length === 0) {
|
|
983
1010
|
// We are not calling `setBlockSynchedL1BlockNumber` because it may cause sync issues if based off infura.
|
|
984
1011
|
// See further details in earlier comments.
|
|
985
1012
|
this.log.trace(`Retrieved no new checkpoints from L1 block ${searchStartBlock} to ${searchEndBlock}`);
|
|
986
1013
|
continue;
|
|
987
1014
|
}
|
|
988
|
-
this.log.debug(`Retrieved ${
|
|
989
|
-
lastProcessedCheckpoint:
|
|
1015
|
+
this.log.debug(`Retrieved ${calldataCheckpoints.length} new checkpoint calldata between L1 blocks ${searchStartBlock} and ${searchEndBlock}`, {
|
|
1016
|
+
lastProcessedCheckpoint: calldataCheckpoints[calldataCheckpoints.length - 1].l1,
|
|
990
1017
|
searchStartBlock,
|
|
991
1018
|
searchEndBlock
|
|
992
1019
|
});
|
|
993
|
-
|
|
1020
|
+
// Check if the last checkpoint matches a local pending entry (so we can skip blob fetch).
|
|
1021
|
+
// We only check the last one; if it matches, the blob fetch is skipped for that entry.
|
|
1022
|
+
// TODO(palla/pipelining): We may have more than a single checkpoint to promote
|
|
1023
|
+
const lastCalldataCheckpoint = calldataCheckpoints[calldataCheckpoints.length - 1];
|
|
1024
|
+
const promoteResult = await this.tryBuildPublishedCheckpointFromProposed(lastCalldataCheckpoint);
|
|
1025
|
+
const checkpointToPromote = promoteResult && !('diverged' in promoteResult) ? promoteResult : undefined;
|
|
1026
|
+
const evictProposedFrom = promoteResult && 'diverged' in promoteResult ? promoteResult.fromCheckpointNumber : undefined;
|
|
1027
|
+
// Then fetch blobs in parallel and build the full published checkpoints
|
|
1028
|
+
const toFetchBlobs = checkpointToPromote ? calldataCheckpoints.slice(0, -1) : calldataCheckpoints;
|
|
1029
|
+
const blobFetched = await asyncPool(10, toFetchBlobs, async (checkpoint)=>retrievedToPublishedCheckpoint({
|
|
1030
|
+
...checkpoint,
|
|
1031
|
+
checkpointBlobData: await getCheckpointBlobDataFromBlobs(this.blobClient, checkpoint.l1.blockHash, checkpoint.blobHashes, checkpoint.checkpointNumber, this.log, !initialSyncComplete, checkpoint.parentBeaconBlockRoot, checkpoint.l1.timestamp)
|
|
1032
|
+
}));
|
|
1033
|
+
// And add the promoted checkpoint to the list of all checkpoints
|
|
1034
|
+
const publishedCheckpoints = checkpointToPromote ? [
|
|
1035
|
+
...blobFetched,
|
|
1036
|
+
checkpointToPromote
|
|
1037
|
+
] : blobFetched;
|
|
994
1038
|
const validCheckpoints = [];
|
|
1039
|
+
// Now loop through all checkpoints and validate their attestations
|
|
995
1040
|
for (const published of publishedCheckpoints){
|
|
996
1041
|
const validationResult = this.config.skipValidateCheckpointAttestations ? {
|
|
997
1042
|
valid: true
|
|
998
|
-
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.log);
|
|
1043
|
+
} : await validateCheckpointAttestations(published, this.epochCache, this.l1Constants, this.getSignatureContext(), this.log);
|
|
999
1044
|
// Only update the validation result if it has changed, so we can keep track of the first invalid checkpoint
|
|
1000
1045
|
// in case there is a sequence of more than one invalid checkpoint, as we need to invalidate the first one.
|
|
1001
1046
|
// There is an exception though: if a checkpoint is invalidated and replaced with another invalid checkpoint,
|
|
@@ -1020,7 +1065,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1020
1065
|
// Check the inHash of the checkpoint against the l1->l2 messages.
|
|
1021
1066
|
// The messages should've been synced up to the currentL1BlockNumber and must be available for the published
|
|
1022
1067
|
// checkpoints we just retrieved.
|
|
1023
|
-
const l1ToL2Messages = await this.
|
|
1068
|
+
const l1ToL2Messages = await this.stores.messages.getL1ToL2Messages(published.checkpoint.number);
|
|
1024
1069
|
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
1025
1070
|
const publishedInHash = published.checkpoint.header.inHash;
|
|
1026
1071
|
if (!computedInHash.equals(publishedInHash)) {
|
|
@@ -1050,9 +1095,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1050
1095
|
}
|
|
1051
1096
|
try {
|
|
1052
1097
|
const updatedValidationResult = rollupStatus.validationResult === initialValidationResult ? undefined : rollupStatus.validationResult;
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1098
|
+
// Split valid checkpoints: the promoted one (if any) is persisted via the proposed-promotion path,
|
|
1099
|
+
// the rest via addCheckpoints. Both paths run within the same store transaction for atomicity.
|
|
1100
|
+
const [[maybeValidCheckpointToPromote], checkpointsToAdd] = partition(validCheckpoints, (c)=>c.checkpoint.number === checkpointToPromote?.checkpoint.number);
|
|
1101
|
+
const [processDuration, result] = await elapsed(()=>execInSpan(this.tracer, 'Archiver.addCheckpoints', ()=>this.updater.addCheckpoints(checkpointsToAdd, updatedValidationResult, maybeValidCheckpointToPromote && {
|
|
1102
|
+
l1: lastCalldataCheckpoint.l1,
|
|
1103
|
+
attestations: lastCalldataCheckpoint.attestations,
|
|
1104
|
+
checkpoint: maybeValidCheckpointToPromote
|
|
1105
|
+
}, evictProposedFrom)));
|
|
1106
|
+
if (checkpointsToAdd.length > 0) {
|
|
1107
|
+
this.instrumentation.processNewCheckpointedBlocks(processDuration / checkpointsToAdd.length, checkpointsToAdd.flatMap((c)=>c.checkpoint.blocks));
|
|
1056
1108
|
}
|
|
1057
1109
|
// If blocks were pruned due to conflict with L1 checkpoints, emit event
|
|
1058
1110
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
@@ -1075,9 +1127,9 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1075
1127
|
} catch (err) {
|
|
1076
1128
|
if (err instanceof InitialCheckpointNumberNotSequentialError) {
|
|
1077
1129
|
const { previousCheckpointNumber, newCheckpointNumber } = err;
|
|
1078
|
-
const previousCheckpoint = previousCheckpointNumber ? await this.
|
|
1130
|
+
const previousCheckpoint = previousCheckpointNumber ? await this.stores.blocks.getCheckpointData(CheckpointNumber(previousCheckpointNumber)) : undefined;
|
|
1079
1131
|
const updatedL1SyncPoint = previousCheckpoint?.l1.blockNumber ?? this.l1Constants.l1StartBlock;
|
|
1080
|
-
await this.
|
|
1132
|
+
await this.stores.blocks.setSynchedL1BlockNumber(updatedL1SyncPoint);
|
|
1081
1133
|
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.`, {
|
|
1082
1134
|
previousCheckpointNumber,
|
|
1083
1135
|
newCheckpointNumber,
|
|
@@ -1098,7 +1150,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1098
1150
|
});
|
|
1099
1151
|
}
|
|
1100
1152
|
lastRetrievedCheckpoint = validCheckpoints.at(-1) ?? lastRetrievedCheckpoint;
|
|
1101
|
-
lastL1BlockWithCheckpoint =
|
|
1153
|
+
lastL1BlockWithCheckpoint = calldataCheckpoints.at(-1)?.l1.blockNumber ?? lastL1BlockWithCheckpoint;
|
|
1102
1154
|
}while (searchEndBlock < currentL1BlockNumber)
|
|
1103
1155
|
// Important that we update AFTER inserting the blocks.
|
|
1104
1156
|
await updateProvenCheckpoint();
|
|
@@ -1108,11 +1160,71 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1108
1160
|
lastL1BlockWithCheckpoint
|
|
1109
1161
|
};
|
|
1110
1162
|
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Checks if a specific checkpoint matches a local pending entry, and if so, loads local data to build
|
|
1165
|
+
* a synthetic published checkpoint (skipping blob fetch).
|
|
1166
|
+
*
|
|
1167
|
+
* Returns { diverged: true, fromCheckpointNumber } when the L1 checkpoint does NOT match local pending
|
|
1168
|
+
* data for that number, so the caller can evict the entire pending suffix >= fromCheckpointNumber
|
|
1169
|
+
* (those entries chain off the now-invalid local state) within the same addCheckpoints transaction.
|
|
1170
|
+
*/ async tryBuildPublishedCheckpointFromProposed(calldataCheckpoint) {
|
|
1171
|
+
if (this.config.skipPromoteProposedCheckpointDuringL1Sync || !calldataCheckpoint) {
|
|
1172
|
+
return undefined;
|
|
1173
|
+
}
|
|
1174
|
+
// Look up the specific pending entry for the checkpoint being mined, not just the tip
|
|
1175
|
+
const proposed = await this.stores.blocks.getProposedCheckpointByNumber(calldataCheckpoint.checkpointNumber);
|
|
1176
|
+
if (!proposed) {
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1179
|
+
if (!proposed.header.equals(calldataCheckpoint.header) || !proposed.archive.root.equals(calldataCheckpoint.archiveRoot)) {
|
|
1180
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} does not match checkpoint retrieved from L1, overriding with L1 data`, {
|
|
1181
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1182
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1183
|
+
proposedArchiveRoot: proposed.archive.root.toString(),
|
|
1184
|
+
calldataCheckpointNumber: calldataCheckpoint.checkpointNumber,
|
|
1185
|
+
calldataHeader: calldataCheckpoint.header.toInspect(),
|
|
1186
|
+
calldataArchiveRoot: calldataCheckpoint.archiveRoot.toString()
|
|
1187
|
+
});
|
|
1188
|
+
// Return a divergence signal so the caller can evict pending >= this number
|
|
1189
|
+
return {
|
|
1190
|
+
diverged: true,
|
|
1191
|
+
fromCheckpointNumber: proposed.checkpointNumber
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
this.log.debug(`Building published checkpoint from proposed ${calldataCheckpoint.checkpointNumber} (skipping blob fetch)`, {
|
|
1195
|
+
proposedHeader: proposed.header.toInspect(),
|
|
1196
|
+
proposedArchiveRoot: proposed.archive.root.toString()
|
|
1197
|
+
});
|
|
1198
|
+
const blocks = await this.stores.blocks.getBlocks(BlockNumber(proposed.startBlock), proposed.blockCount);
|
|
1199
|
+
if (blocks.length !== proposed.blockCount) {
|
|
1200
|
+
this.log.warn(`Local proposed checkpoint ${proposed.checkpointNumber} has wrong block count (expected ${proposed.blockCount} blocks starting at ${proposed.startBlock} but got ${blocks.length})`, {
|
|
1201
|
+
proposedCheckpointNumber: proposed.checkpointNumber,
|
|
1202
|
+
proposedStartBlock: proposed.startBlock,
|
|
1203
|
+
proposedBlockCount: proposed.blockCount,
|
|
1204
|
+
retrievedBlocks: blocks.map((b)=>b.number)
|
|
1205
|
+
});
|
|
1206
|
+
return undefined;
|
|
1207
|
+
}
|
|
1208
|
+
const checkpoint = Checkpoint.from({
|
|
1209
|
+
archive: proposed.archive,
|
|
1210
|
+
header: proposed.header,
|
|
1211
|
+
blocks,
|
|
1212
|
+
number: proposed.checkpointNumber,
|
|
1213
|
+
feeAssetPriceModifier: proposed.feeAssetPriceModifier
|
|
1214
|
+
});
|
|
1215
|
+
const promotedCheckpoint = PublishedCheckpoint.from({
|
|
1216
|
+
checkpoint,
|
|
1217
|
+
l1: calldataCheckpoint.l1,
|
|
1218
|
+
attestations: calldataCheckpoint.attestations
|
|
1219
|
+
});
|
|
1220
|
+
this.instrumentation.processCheckpointPromoted();
|
|
1221
|
+
return promotedCheckpoint;
|
|
1222
|
+
}
|
|
1111
1223
|
async checkForNewCheckpointsBeforeL1SyncPoint(status, blocksSynchedTo, currentL1BlockNumber) {
|
|
1112
1224
|
const { lastRetrievedCheckpoint, pendingCheckpointNumber } = status;
|
|
1113
1225
|
// Compare the last checkpoint we have (either retrieved in this round or loaded from store) with what the
|
|
1114
1226
|
// rollup contract told us was the latest one (pinned at the currentL1BlockNumber).
|
|
1115
|
-
const latestLocalCheckpointNumber = lastRetrievedCheckpoint?.checkpoint.number ?? await this.
|
|
1227
|
+
const latestLocalCheckpointNumber = lastRetrievedCheckpoint?.checkpoint.number ?? await this.stores.blocks.getLatestCheckpointNumber();
|
|
1116
1228
|
if (latestLocalCheckpointNumber < pendingCheckpointNumber) {
|
|
1117
1229
|
// Here we have consumed all logs until the `currentL1Block` we pinned at the beginning of the archiver loop,
|
|
1118
1230
|
// but still haven't reached the pending checkpoint according to the call to the rollup contract.
|
|
@@ -1125,7 +1237,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1125
1237
|
latestLocalCheckpointArchive = lastRetrievedCheckpoint.checkpoint.archive.root.toString();
|
|
1126
1238
|
targetL1BlockNumber = lastRetrievedCheckpoint.l1.blockNumber;
|
|
1127
1239
|
} else if (latestLocalCheckpointNumber > 0) {
|
|
1128
|
-
const checkpoint = await this.
|
|
1240
|
+
const checkpoint = await this.stores.blocks.getRangeOfCheckpoints(latestLocalCheckpointNumber, 1).then(([c])=>c);
|
|
1129
1241
|
latestLocalCheckpointArchive = checkpoint.archive.root.toString();
|
|
1130
1242
|
targetL1BlockNumber = checkpoint.l1.blockNumber;
|
|
1131
1243
|
}
|
|
@@ -1136,7 +1248,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1136
1248
|
currentL1BlockNumber,
|
|
1137
1249
|
...status
|
|
1138
1250
|
});
|
|
1139
|
-
await this.
|
|
1251
|
+
await this.stores.blocks.setSynchedL1BlockNumber(targetL1BlockNumber);
|
|
1140
1252
|
} else {
|
|
1141
1253
|
this.log.trace(`No new checkpoints behind L1 sync point to retrieve.`, {
|
|
1142
1254
|
latestLocalCheckpointNumber,
|
|
@@ -1145,7 +1257,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1145
1257
|
}
|
|
1146
1258
|
}
|
|
1147
1259
|
async getCheckpointHeader(number) {
|
|
1148
|
-
const checkpoint = await this.
|
|
1260
|
+
const checkpoint = await this.stores.blocks.getCheckpointData(number);
|
|
1149
1261
|
if (!checkpoint) {
|
|
1150
1262
|
return undefined;
|
|
1151
1263
|
}
|
|
@@ -3,15 +3,16 @@ import type { Logger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { type AttestationInfo, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
4
4
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
5
5
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
6
7
|
export type { ValidateCheckpointResult };
|
|
7
8
|
/**
|
|
8
9
|
* Extracts attestation information from a published checkpoint.
|
|
9
10
|
* Returns info for each attestation, preserving array indices.
|
|
10
11
|
*/
|
|
11
|
-
export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }: PublishedCheckpoint): AttestationInfo[];
|
|
12
|
+
export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint, attestations }: PublishedCheckpoint, signatureContext: CoordinationSignatureContext): AttestationInfo[];
|
|
12
13
|
/**
|
|
13
14
|
* Validates the attestations submitted for the given checkpoint.
|
|
14
15
|
* Returns true if the attestations are valid and sufficient, false otherwise.
|
|
15
16
|
*/
|
|
16
|
-
export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, logger?: Logger): Promise<ValidateCheckpointResult>;
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, signatureContext: CoordinationSignatureContext, logger?: Logger): Promise<ValidateCheckpointResult>;
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUdyRCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssd0JBQXdCLEVBRTlCLE1BQU0scUJBQXFCLENBQUM7QUFDN0IsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRSxPQUFPLEVBQUUsS0FBSyxpQkFBaUIsRUFBaUMsTUFBTSw2QkFBNkIsQ0FBQztBQUNwRyxPQUFPLEVBQW9CLEtBQUssNEJBQTRCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUV4RixZQUFZLEVBQUUsd0JBQXdCLEVBQUUsQ0FBQztBQUV6Qzs7O0dBR0c7QUFDSCx3QkFBZ0IseUNBQXlDLENBQ3ZELEVBQUUsVUFBVSxFQUFFLFlBQVksRUFBRSxFQUFFLG1CQUFtQixFQUNqRCxnQkFBZ0IsRUFBRSw0QkFBNEIsR0FDN0MsZUFBZSxFQUFFLENBR25CO0FBRUQ7OztHQUdHO0FBQ0gsd0JBQXNCLDhCQUE4QixDQUNsRCxtQkFBbUIsRUFBRSxtQkFBbUIsRUFDeEMsVUFBVSxFQUFFLFVBQVUsRUFDdEIsU0FBUyxFQUFFLElBQUksQ0FBQyxpQkFBaUIsRUFBRSxlQUFlLENBQUMsRUFDbkQsZ0JBQWdCLEVBQUUsNEJBQTRCLEVBQzlDLE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FDZCxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0EyRm5DIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAiC,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAiC,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAoB,KAAK,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAExF,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,yCAAyC,CACvD,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,mBAAmB,EACjD,gBAAgB,EAAE,4BAA4B,GAC7C,eAAe,EAAE,CAGnB;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,gBAAgB,EAAE,4BAA4B,EAC9C,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC,CA2FnC"}
|