@aztec/archiver 0.0.1-commit.9372f48 → 0.0.1-commit.949a33fd8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dest/archiver.d.ts +22 -11
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +152 -145
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +33 -27
- package/dest/index.d.ts +4 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- 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/data_source_base.d.ts +18 -7
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +51 -77
- package/dest/modules/data_store_updater.d.ts +35 -15
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +139 -96
- 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 +11 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +304 -151
- 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 +98 -28
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +465 -138
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +85 -24
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +106 -27
- 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 +150 -55
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +21 -9
- package/dest/test/fake_l1_state.d.ts +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 +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +9 -3
- package/package.json +13 -13
- package/src/archiver.ts +187 -164
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +47 -24
- package/src/index.ts +3 -1
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- 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/data_source_base.ts +95 -98
- package/src/modules/data_store_updater.ts +168 -126
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +384 -188
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +569 -174
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +167 -41
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +221 -63
- package/src/store/message_store.ts +27 -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 +10 -2
package/README.md
CHANGED
|
@@ -43,14 +43,18 @@ Two independent syncpoints track progress on L1:
|
|
|
43
43
|
|
|
44
44
|
### L1-to-L2 Messages
|
|
45
45
|
|
|
46
|
-
Messages are synced from the Inbox contract
|
|
46
|
+
Messages are synced from the Inbox contract. The sync compares local state (message count and rolling hash) against the Inbox contract state on L1, downloads any missing messages, and verifies consistency afterwards. On success, the syncpoint advances to the current L1 block. On failure (L1 reorg or inconsistency), the syncpoint rolls back to the last known-good message and the operation retries (up to 3 times within the same sync iteration).
|
|
47
47
|
|
|
48
48
|
1. Query Inbox state at the current L1 block (message count + rolling hash)
|
|
49
|
-
2. Compare local
|
|
50
|
-
3. If they match,
|
|
51
|
-
4. If mismatch,
|
|
52
|
-
- If
|
|
53
|
-
5.
|
|
49
|
+
2. Compare local state against remote
|
|
50
|
+
3. If they match, advance syncpoint and return
|
|
51
|
+
4. If mismatch, fetch `MessageSent` events in batches and store them
|
|
52
|
+
- If storing fails due to a rolling hash mismatch (indicating an L1 reorg changed or removed messages), find the last common message with L1, delete everything after, reset the syncpoint, and retry
|
|
53
|
+
5. After storing, verify local state matches the remote state queried in step 1
|
|
54
|
+
- If still mismatched (e.g., messages missed due to a concurrent L1 reorg), rollback and retry
|
|
55
|
+
6. On success, advance the syncpoint
|
|
56
|
+
|
|
57
|
+
The syncpoint and the `inboxTreeInProgress` marker (which tracks which checkpoint's messages are currently being filled on L1) are updated atomically. The marker is only advanced after messages are stored, so concurrent reads don't see an unsealed checkpoint as readable before its messages are available.
|
|
54
58
|
|
|
55
59
|
### Checkpoints
|
|
56
60
|
|
|
@@ -81,6 +85,8 @@ The `blocksSynchedTo` syncpoint is updated:
|
|
|
81
85
|
|
|
82
86
|
Note that the `blocksSynchedTo` pointer is NOT updated during normal sync when there are no new checkpoints. This protects against small L1 reorgs that could add a checkpoint on an L1 block we have flagged as already synced.
|
|
83
87
|
|
|
88
|
+
The `messagesSynchedTo` pointer is always advanced to the current L1 block on success. If a rolling hash mismatch or post-download inconsistency is detected, the pointer rolls back to the last common message and the operation retries. The rolling hash chain and pre/post-sync consistency checks provide the primary reorg protection.
|
|
89
|
+
|
|
84
90
|
### Block Queue
|
|
85
91
|
|
|
86
92
|
The archiver implements `L2BlockSink`, allowing other subsystems to push blocks before they appear on L1:
|
package/dest/archiver.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { type Logger } from '@aztec/foundation/log';
|
|
|
11
11
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
12
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
13
13
|
import { type ArchiverEmitter, L2Block, type L2BlockSink, type L2Tips, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
14
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
14
|
+
import { type ProposedCheckpointInput, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
15
15
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
16
16
|
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
17
17
|
import { type ArchiverConfig } from './config.js';
|
|
@@ -19,6 +19,7 @@ import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
|
19
19
|
import type { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
20
20
|
import type { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
21
21
|
import type { KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
22
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
22
23
|
/** Export ArchiverEmitter for use in factory and tests. */
|
|
23
24
|
export type { ArchiverEmitter };
|
|
24
25
|
export type ArchiverDeps = {
|
|
@@ -53,28 +54,30 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
53
54
|
private readonly synchronizer;
|
|
54
55
|
private initialSyncComplete;
|
|
55
56
|
private initialSyncPromise;
|
|
56
|
-
/** Queue of blocks to be added to the store, processed by the sync loop. */
|
|
57
|
-
private
|
|
57
|
+
/** Queue of blocks and checkpoints to be added to the store, processed by the sync loop. */
|
|
58
|
+
private inboundQueue;
|
|
58
59
|
/** Helper to handle updates to the store */
|
|
59
60
|
private readonly updater;
|
|
61
|
+
/** In-memory cache for L2 chain tips. */
|
|
62
|
+
private readonly l2TipsCache;
|
|
60
63
|
readonly tracer: Tracer;
|
|
64
|
+
private readonly instrumentation;
|
|
61
65
|
/**
|
|
62
66
|
* Creates a new instance of the Archiver.
|
|
63
67
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
64
68
|
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
65
69
|
* @param rollup - Rollup contract instance.
|
|
66
70
|
* @param inbox - Inbox contract instance.
|
|
67
|
-
* @param l1Addresses - L1 contract addresses (registry, governance proposer,
|
|
71
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
68
72
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
69
73
|
* @param config - Archiver configuration options.
|
|
70
74
|
* @param blobClient - Client for retrieving blob data.
|
|
71
|
-
* @param epochCache - Cache for epoch-related data.
|
|
72
75
|
* @param dateProvider - Provider for current date/time.
|
|
73
76
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
74
77
|
* @param l1Constants - L1 rollup constants.
|
|
75
78
|
* @param log - A logger.
|
|
76
79
|
*/
|
|
77
|
-
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, l1Addresses: Pick<L1ContractAddresses, 'registryAddress' | '
|
|
80
|
+
constructor(publicClient: ViemPublicClient, debugClient: ViemPublicDebugClient, rollup: RollupContract, l1Addresses: Pick<L1ContractAddresses, 'rollupAddress' | 'registryAddress' | 'inboxAddress' | 'governanceProposerAddress'> & {
|
|
78
81
|
slashingProposerAddress: EthAddress;
|
|
79
82
|
}, dataStore: KVArchiverDataStore, config: {
|
|
80
83
|
pollingIntervalMs: number;
|
|
@@ -82,10 +85,11 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
82
85
|
skipValidateCheckpointAttestations?: boolean;
|
|
83
86
|
maxAllowedEthClientDriftSeconds: number;
|
|
84
87
|
ethereumAllowNoDebugHosts?: boolean;
|
|
88
|
+
skipHistoricalLogsCheck?: boolean;
|
|
85
89
|
}, blobClient: BlobClientInterface, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
|
|
86
90
|
l1StartBlockHash: Buffer32;
|
|
87
91
|
genesisArchiveRoot: Fr;
|
|
88
|
-
}, synchronizer: ArchiverL1Synchronizer, events: ArchiverEmitter, log?: Logger);
|
|
92
|
+
}, synchronizer: ArchiverL1Synchronizer, events: ArchiverEmitter, l2TipsCache?: L2TipsCache, log?: Logger);
|
|
89
93
|
/** Updates archiver config */
|
|
90
94
|
updateConfig(newConfig: Partial<ArchiverConfig>): void;
|
|
91
95
|
/**
|
|
@@ -94,6 +98,7 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
94
98
|
*/
|
|
95
99
|
start(blockUntilSynced: boolean): Promise<void>;
|
|
96
100
|
syncImmediate(): Promise<void>;
|
|
101
|
+
trySyncImmediate(): Promise<void> | undefined;
|
|
97
102
|
/**
|
|
98
103
|
* Queues a block to be added to the archiver store and triggers processing.
|
|
99
104
|
* The block will be processed by the sync loop.
|
|
@@ -102,7 +107,13 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
102
107
|
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
103
108
|
*/
|
|
104
109
|
addBlock(block: L2Block): Promise<void>;
|
|
105
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Queues a new proposed checkpoint into the archiver store.
|
|
112
|
+
* Checks that the checkpoint is not for an L2 slot already synced from L1.
|
|
113
|
+
* Resolves once the checkpoint has been processed.
|
|
114
|
+
*/
|
|
115
|
+
addProposedCheckpoint(pending: ProposedCheckpointInput): Promise<void>;
|
|
116
|
+
private processInboundQueue;
|
|
106
117
|
waitForInitialSync(): Promise<void>;
|
|
107
118
|
private sync;
|
|
108
119
|
private syncFromL1;
|
|
@@ -122,8 +133,8 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
122
133
|
getRegistryAddress(): Promise<EthAddress>;
|
|
123
134
|
getL1BlockNumber(): bigint | undefined;
|
|
124
135
|
getL1Timestamp(): Promise<bigint | undefined>;
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
|
|
137
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
127
138
|
isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
|
|
128
139
|
/** Returns whether the archiver has completed an initial sync run successfully. */
|
|
129
140
|
isInitialSyncComplete(): boolean;
|
|
@@ -133,4 +144,4 @@ export declare class Archiver extends ArchiverDataSourceBase implements L2BlockS
|
|
|
133
144
|
getL2Tips(): Promise<L2Tips>;
|
|
134
145
|
rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void>;
|
|
135
146
|
}
|
|
136
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
147
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJjaGl2ZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9hcmNoaXZlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ3JFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNoRCxPQUFPLEVBQXVCLGNBQWMsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ2hGLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDakYsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUscUJBQXFCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNyRixPQUFPLEVBQUUsV0FBVyxFQUFFLGdCQUFnQixFQUFFLFdBQVcsRUFBRSxVQUFVLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6RyxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFcEQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sRUFBRSxVQUFVLEV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C,mBAAmB,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA4DvE;CACF"}
|
package/dest/archiver.js
CHANGED
|
@@ -371,23 +371,24 @@ 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, _initProto;
|
|
374
|
-
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
375
374
|
import { BlockTagTooOldError } from '@aztec/ethereum/contracts';
|
|
376
|
-
import { BlockNumber,
|
|
375
|
+
import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
377
376
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
378
377
|
import { merge } from '@aztec/foundation/collection';
|
|
379
378
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
380
379
|
import { createLogger } from '@aztec/foundation/log';
|
|
381
380
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
382
381
|
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
383
|
-
import {
|
|
384
|
-
import {
|
|
382
|
+
import { elapsed } from '@aztec/foundation/timer';
|
|
383
|
+
import { getEpochAtSlot, getSlotAtNextL1Block, getSlotRangeForEpoch, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
385
384
|
import { trackSpan } from '@aztec/telemetry-client';
|
|
386
385
|
import { mapArchiverConfig } from './config.js';
|
|
387
|
-
import { NoBlobBodiesFoundError } from './errors.js';
|
|
386
|
+
import { BlockAlreadyCheckpointedError, BlockOrCheckpointSlotExpiredError, NoBlobBodiesFoundError } from './errors.js';
|
|
387
|
+
import { validateAndLogHistoricalLogsAvailability } from './l1/validate_historical_logs.js';
|
|
388
388
|
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
389
389
|
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
390
390
|
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
391
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
391
392
|
_dec = trackSpan('Archiver.sync');
|
|
392
393
|
/**
|
|
393
394
|
* Pulls checkpoints in a non-blocking manner and provides interface for their retrieval.
|
|
@@ -417,31 +418,36 @@ _dec = trackSpan('Archiver.sync');
|
|
|
417
418
|
/** L1 synchronizer that handles fetching checkpoints and messages from L1. */ synchronizer;
|
|
418
419
|
initialSyncComplete;
|
|
419
420
|
initialSyncPromise;
|
|
420
|
-
/** Queue of blocks to be added to the store, processed by the sync loop. */
|
|
421
|
+
/** Queue of blocks and checkpoints to be added to the store, processed by the sync loop. */ inboundQueue;
|
|
421
422
|
/** Helper to handle updates to the store */ updater;
|
|
423
|
+
/** In-memory cache for L2 chain tips. */ l2TipsCache;
|
|
422
424
|
tracer;
|
|
425
|
+
instrumentation;
|
|
423
426
|
/**
|
|
424
427
|
* Creates a new instance of the Archiver.
|
|
425
428
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
426
429
|
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
427
430
|
* @param rollup - Rollup contract instance.
|
|
428
431
|
* @param inbox - Inbox contract instance.
|
|
429
|
-
* @param l1Addresses - L1 contract addresses (registry, governance proposer,
|
|
432
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
430
433
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
431
434
|
* @param config - Archiver configuration options.
|
|
432
435
|
* @param blobClient - Client for retrieving blob data.
|
|
433
|
-
* @param epochCache - Cache for epoch-related data.
|
|
434
436
|
* @param dateProvider - Provider for current date/time.
|
|
435
437
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
436
438
|
* @param l1Constants - L1 rollup constants.
|
|
437
439
|
* @param log - A logger.
|
|
438
|
-
*/ constructor(publicClient, debugClient, rollup, l1Addresses, dataStore, config, blobClient, instrumentation, l1Constants, synchronizer, events, log = createLogger('archiver')){
|
|
439
|
-
super(dataStore, l1Constants), this.publicClient = publicClient, this.debugClient = debugClient, this.rollup = rollup, this.l1Addresses = l1Addresses, this.dataStore = dataStore, this.config = config, this.blobClient = blobClient, this.l1Constants = l1Constants, this.log = log, this.initialSyncComplete = (_initProto(this), false), this.
|
|
440
|
+
*/ constructor(publicClient, debugClient, rollup, l1Addresses, dataStore, config, blobClient, instrumentation, l1Constants, synchronizer, events, l2TipsCache, log = createLogger('archiver')){
|
|
441
|
+
super(dataStore, l1Constants), this.publicClient = publicClient, this.debugClient = debugClient, this.rollup = rollup, this.l1Addresses = l1Addresses, this.dataStore = dataStore, this.config = config, this.blobClient = blobClient, this.l1Constants = l1Constants, this.log = log, this.initialSyncComplete = (_initProto(this), false), this.inboundQueue = [];
|
|
440
442
|
this.tracer = instrumentation.tracer;
|
|
443
|
+
this.instrumentation = instrumentation;
|
|
441
444
|
this.initialSyncPromise = promiseWithResolvers();
|
|
442
445
|
this.synchronizer = synchronizer;
|
|
443
446
|
this.events = events;
|
|
444
|
-
this.
|
|
447
|
+
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
448
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache, {
|
|
449
|
+
rollupManaLimit: l1Constants.rollupManaLimit
|
|
450
|
+
});
|
|
445
451
|
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
446
452
|
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
447
453
|
this.runningPromise = new RunningPromise(()=>this.sync(), this.log, this.config.pollingIntervalMs / 10, makeLoggingErrorHandler(this.log, NoBlobBodiesFoundError, BlockTagTooOldError));
|
|
@@ -460,6 +466,12 @@ _dec = trackSpan('Archiver.sync');
|
|
|
460
466
|
await this.blobClient.testSources();
|
|
461
467
|
await this.synchronizer.testEthereumNodeSynced();
|
|
462
468
|
await validateAndLogTraceAvailability(this.debugClient, this.config.ethereumAllowNoDebugHosts ?? false, this.log.getBindings());
|
|
469
|
+
await validateAndLogHistoricalLogsAvailability(this.publicClient, {
|
|
470
|
+
rollupAddress: this.l1Addresses.rollupAddress,
|
|
471
|
+
inboxAddress: this.l1Addresses.inboxAddress,
|
|
472
|
+
registryAddress: this.l1Addresses.registryAddress,
|
|
473
|
+
governanceProposerAddress: this.l1Addresses.governanceProposerAddress
|
|
474
|
+
}, this.config.skipHistoricalLogsCheck ?? false, this.log.getBindings());
|
|
463
475
|
// Log initial state for the archiver
|
|
464
476
|
const { l1StartBlock } = this.l1Constants;
|
|
465
477
|
const { blocksSynchedTo = l1StartBlock, messagesSynchedTo = l1StartBlock } = await this.store.getSynchPoint();
|
|
@@ -478,6 +490,13 @@ _dec = trackSpan('Archiver.sync');
|
|
|
478
490
|
syncImmediate() {
|
|
479
491
|
return this.runningPromise.trigger();
|
|
480
492
|
}
|
|
493
|
+
trySyncImmediate() {
|
|
494
|
+
try {
|
|
495
|
+
return this.syncImmediate();
|
|
496
|
+
} catch (err) {
|
|
497
|
+
this.log.error(`Failed to trigger immediate archiver sync: ${err}`, err);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
481
500
|
/**
|
|
482
501
|
* Queues a block to be added to the archiver store and triggers processing.
|
|
483
502
|
* The block will be processed by the sync loop.
|
|
@@ -485,53 +504,84 @@ _dec = trackSpan('Archiver.sync');
|
|
|
485
504
|
* @param block - The L2 block to add.
|
|
486
505
|
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
487
506
|
*/ addBlock(block) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
507
|
+
const promise = promiseWithResolvers();
|
|
508
|
+
this.inboundQueue.push({
|
|
509
|
+
block,
|
|
510
|
+
...promise,
|
|
511
|
+
type: 'block'
|
|
512
|
+
});
|
|
513
|
+
this.log.debug(`Queued block ${block.number} for processing`);
|
|
514
|
+
void this.trySyncImmediate();
|
|
515
|
+
return promise.promise;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Queues a new proposed checkpoint into the archiver store.
|
|
519
|
+
* Checks that the checkpoint is not for an L2 slot already synced from L1.
|
|
520
|
+
* Resolves once the checkpoint has been processed.
|
|
521
|
+
*/ addProposedCheckpoint(pending) {
|
|
522
|
+
const promise = promiseWithResolvers();
|
|
523
|
+
this.inboundQueue.push({
|
|
524
|
+
checkpoint: pending,
|
|
525
|
+
...promise,
|
|
526
|
+
type: 'checkpoint'
|
|
499
527
|
});
|
|
528
|
+
this.log.debug(`Queued checkpoint ${pending.checkpointNumber} for processing`);
|
|
529
|
+
void this.trySyncImmediate();
|
|
530
|
+
return promise.promise;
|
|
500
531
|
}
|
|
501
532
|
/**
|
|
502
|
-
* Processes all queued blocks, adding them to the store.
|
|
533
|
+
* Processes all queued blocks and checkpoints, adding them to the store.
|
|
503
534
|
* Called at the beginning of each sync iteration.
|
|
504
|
-
*
|
|
505
|
-
*/ async
|
|
506
|
-
if (this.
|
|
535
|
+
* Items are processed in the order they were queued.
|
|
536
|
+
*/ async processInboundQueue() {
|
|
537
|
+
if (this.inboundQueue.length === 0) {
|
|
507
538
|
return;
|
|
508
539
|
}
|
|
509
|
-
// Take all
|
|
510
|
-
const queuedItems = this.
|
|
511
|
-
this.log.debug(`Processing ${queuedItems.length} queued
|
|
540
|
+
// Take all items from the queue
|
|
541
|
+
const queuedItems = this.inboundQueue.splice(0, this.inboundQueue.length);
|
|
542
|
+
this.log.debug(`Processing ${queuedItems.length} queued inbound items`);
|
|
512
543
|
// Calculate slot threshold for validation
|
|
513
544
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
514
545
|
const slotAtNextL1Block = l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
515
|
-
//
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
546
|
+
// Helpers for manipulating blocks and checkpoints in the queue
|
|
547
|
+
const getSlot = (item)=>item.type === 'block' ? item.block.header.globalVariables.slotNumber : item.checkpoint.header.slotNumber;
|
|
548
|
+
const getNumber = (item)=>item.type === 'block' ? item.block.number : item.checkpoint.checkpointNumber;
|
|
549
|
+
// Process each item individually to properly resolve/reject each promise
|
|
550
|
+
for (const item of queuedItems){
|
|
551
|
+
const { resolve, reject, type } = item;
|
|
552
|
+
const itemSlot = getSlot(item);
|
|
553
|
+
const itemNumber = getNumber(item);
|
|
554
|
+
if (slotAtNextL1Block !== undefined && itemSlot < slotAtNextL1Block) {
|
|
555
|
+
const nextSlotTimestamp = getTimestampForSlot(slotAtNextL1Block, this.l1Constants);
|
|
556
|
+
this.log.warn(`Rejecting proposed ${type} ${itemNumber} for past slot ${itemSlot} (current ${slotAtNextL1Block})`, {
|
|
557
|
+
number: itemNumber,
|
|
558
|
+
type,
|
|
521
559
|
l1Timestamp,
|
|
522
|
-
slotAtNextL1Block
|
|
560
|
+
slotAtNextL1Block,
|
|
561
|
+
nextSlotTimestamp
|
|
523
562
|
});
|
|
524
|
-
reject(new
|
|
563
|
+
reject(new BlockOrCheckpointSlotExpiredError(itemSlot, nextSlotTimestamp, l1Timestamp));
|
|
525
564
|
continue;
|
|
526
565
|
}
|
|
527
566
|
try {
|
|
528
|
-
|
|
529
|
-
block
|
|
530
|
-
|
|
531
|
-
|
|
567
|
+
if (type === 'block') {
|
|
568
|
+
const [durationMs] = await elapsed(()=>this.updater.addProposedBlock(item.block));
|
|
569
|
+
this.instrumentation.processNewProposedBlock(durationMs, item.block);
|
|
570
|
+
} else {
|
|
571
|
+
await this.updater.addProposedCheckpoint(item.checkpoint);
|
|
572
|
+
}
|
|
573
|
+
this.log.debug(`Added ${type} ${itemNumber} to store`);
|
|
532
574
|
resolve();
|
|
533
575
|
} catch (err) {
|
|
534
|
-
|
|
576
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
577
|
+
this.log.debug(`Proposed block ${itemNumber} matches already checkpointed block, ignoring late proposal`);
|
|
578
|
+
resolve();
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
this.log.error(`Failed to add ${type} ${itemNumber} to store: ${err.message}`, err, {
|
|
582
|
+
number: itemNumber,
|
|
583
|
+
type
|
|
584
|
+
});
|
|
535
585
|
reject(err);
|
|
536
586
|
}
|
|
537
587
|
}
|
|
@@ -543,7 +593,7 @@ _dec = trackSpan('Archiver.sync');
|
|
|
543
593
|
* Fetches logs from L1 contracts and processes them.
|
|
544
594
|
*/ async sync() {
|
|
545
595
|
// Process any queued blocks first, before doing L1 sync
|
|
546
|
-
await this.
|
|
596
|
+
await this.processInboundQueue();
|
|
547
597
|
// Now perform L1 sync
|
|
548
598
|
await this.syncFromL1();
|
|
549
599
|
}
|
|
@@ -605,13 +655,45 @@ _dec = trackSpan('Archiver.sync');
|
|
|
605
655
|
getL1Timestamp() {
|
|
606
656
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
607
657
|
}
|
|
608
|
-
|
|
658
|
+
async getSyncedL2SlotNumber() {
|
|
659
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
660
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
661
|
+
// we have seen the corresponding checkpoint.
|
|
662
|
+
let slotFromL1Sync;
|
|
609
663
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
610
|
-
|
|
664
|
+
if (l1Timestamp !== undefined) {
|
|
665
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
666
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
667
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
let slotFromCheckpoint;
|
|
671
|
+
const latestCheckpointNumber = await this.store.getSynchedCheckpointNumber();
|
|
672
|
+
if (latestCheckpointNumber > 0) {
|
|
673
|
+
const checkpointData = await this.store.getCheckpointData(latestCheckpointNumber);
|
|
674
|
+
if (checkpointData) {
|
|
675
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
611
682
|
}
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
683
|
+
async getSyncedL2EpochNumber() {
|
|
684
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
685
|
+
if (syncedSlot === undefined) {
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
// An epoch is fully synced when all its slots are synced.
|
|
689
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
690
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
691
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
692
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
693
|
+
if (syncedSlot >= endSlot) {
|
|
694
|
+
return epoch;
|
|
695
|
+
}
|
|
696
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
615
697
|
}
|
|
616
698
|
async isEpochComplete(epochNumber) {
|
|
617
699
|
// The epoch is complete if the current checkpointed L2 block is the last one in the epoch (or later).
|
|
@@ -650,94 +732,10 @@ _dec = trackSpan('Archiver.sync');
|
|
|
650
732
|
await this.updater.addCheckpoints(checkpoints, pendingChainValidationStatus);
|
|
651
733
|
return true;
|
|
652
734
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
this.getBlockNumber(),
|
|
656
|
-
this.getProvenBlockNumber(),
|
|
657
|
-
this.getCheckpointedL2BlockNumber(),
|
|
658
|
-
this.getFinalizedL2BlockNumber()
|
|
659
|
-
]);
|
|
660
|
-
const beforeInitialblockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
661
|
-
// Get the latest block header and checkpointed blocks for proven, finalised and checkpointed blocks
|
|
662
|
-
const [latestBlockHeader, provenCheckpointedBlock, finalizedCheckpointedBlock, checkpointedBlock] = await Promise.all([
|
|
663
|
-
latestBlockNumber > beforeInitialblockNumber ? this.getBlockHeader(latestBlockNumber) : undefined,
|
|
664
|
-
provenBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(provenBlockNumber) : undefined,
|
|
665
|
-
finalizedBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(finalizedBlockNumber) : undefined,
|
|
666
|
-
checkpointedBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(checkpointedBlockNumber) : undefined
|
|
667
|
-
]);
|
|
668
|
-
if (latestBlockNumber > beforeInitialblockNumber && !latestBlockHeader) {
|
|
669
|
-
throw new Error(`Failed to retrieve latest block header for block ${latestBlockNumber}`);
|
|
670
|
-
}
|
|
671
|
-
// Checkpointed blocks must exist for proven, finalized and checkpointed tips if they are beyond the initial block number.
|
|
672
|
-
if (checkpointedBlockNumber > beforeInitialblockNumber && !checkpointedBlock?.block.header) {
|
|
673
|
-
throw new Error(`Failed to retrieve checkpointed block header for block ${checkpointedBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
674
|
-
}
|
|
675
|
-
if (provenBlockNumber > beforeInitialblockNumber && !provenCheckpointedBlock?.block.header) {
|
|
676
|
-
throw new Error(`Failed to retrieve proven checkpointed for block ${provenBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
677
|
-
}
|
|
678
|
-
if (finalizedBlockNumber > beforeInitialblockNumber && !finalizedCheckpointedBlock?.block.header) {
|
|
679
|
-
throw new Error(`Failed to retrieve finalized block header for block ${finalizedBlockNumber} (latest block is ${latestBlockNumber})`);
|
|
680
|
-
}
|
|
681
|
-
const latestBlockHeaderHash = await latestBlockHeader?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
682
|
-
const provenBlockHeaderHash = await provenCheckpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
683
|
-
const finalizedBlockHeaderHash = await finalizedCheckpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
684
|
-
const checkpointedBlockHeaderHash = await checkpointedBlock?.block.header?.hash() ?? GENESIS_BLOCK_HEADER_HASH;
|
|
685
|
-
// Now attempt to retrieve checkpoints for proven, finalised and checkpointed blocks
|
|
686
|
-
const [[provenBlockCheckpoint], [finalizedBlockCheckpoint], [checkpointedBlockCheckpoint]] = await Promise.all([
|
|
687
|
-
provenCheckpointedBlock !== undefined ? await this.getCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1) : [
|
|
688
|
-
undefined
|
|
689
|
-
],
|
|
690
|
-
finalizedCheckpointedBlock !== undefined ? await this.getCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1) : [
|
|
691
|
-
undefined
|
|
692
|
-
],
|
|
693
|
-
checkpointedBlock !== undefined ? await this.getCheckpoints(checkpointedBlock?.checkpointNumber, 1) : [
|
|
694
|
-
undefined
|
|
695
|
-
]
|
|
696
|
-
]);
|
|
697
|
-
const initialcheckpointId = {
|
|
698
|
-
number: CheckpointNumber.ZERO,
|
|
699
|
-
hash: GENESIS_CHECKPOINT_HEADER_HASH.toString()
|
|
700
|
-
};
|
|
701
|
-
const makeCheckpointId = (checkpoint)=>{
|
|
702
|
-
if (checkpoint === undefined) {
|
|
703
|
-
return initialcheckpointId;
|
|
704
|
-
}
|
|
705
|
-
return {
|
|
706
|
-
number: checkpoint.checkpoint.number,
|
|
707
|
-
hash: checkpoint.checkpoint.hash().toString()
|
|
708
|
-
};
|
|
709
|
-
};
|
|
710
|
-
const l2Tips = {
|
|
711
|
-
proposed: {
|
|
712
|
-
number: latestBlockNumber,
|
|
713
|
-
hash: latestBlockHeaderHash.toString()
|
|
714
|
-
},
|
|
715
|
-
proven: {
|
|
716
|
-
block: {
|
|
717
|
-
number: provenBlockNumber,
|
|
718
|
-
hash: provenBlockHeaderHash.toString()
|
|
719
|
-
},
|
|
720
|
-
checkpoint: makeCheckpointId(provenBlockCheckpoint)
|
|
721
|
-
},
|
|
722
|
-
finalized: {
|
|
723
|
-
block: {
|
|
724
|
-
number: finalizedBlockNumber,
|
|
725
|
-
hash: finalizedBlockHeaderHash.toString()
|
|
726
|
-
},
|
|
727
|
-
checkpoint: makeCheckpointId(finalizedBlockCheckpoint)
|
|
728
|
-
},
|
|
729
|
-
checkpointed: {
|
|
730
|
-
block: {
|
|
731
|
-
number: checkpointedBlockNumber,
|
|
732
|
-
hash: checkpointedBlockHeaderHash.toString()
|
|
733
|
-
},
|
|
734
|
-
checkpoint: makeCheckpointId(checkpointedBlockCheckpoint)
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
return l2Tips;
|
|
735
|
+
getL2Tips() {
|
|
736
|
+
return this.l2TipsCache.getL2Tips();
|
|
738
737
|
}
|
|
739
738
|
async rollbackTo(targetL2BlockNumber) {
|
|
740
|
-
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
741
739
|
const currentBlocks = await this.getL2Tips();
|
|
742
740
|
const currentL2Block = currentBlocks.proposed.number;
|
|
743
741
|
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
@@ -748,8 +746,17 @@ _dec = trackSpan('Archiver.sync');
|
|
|
748
746
|
if (!targetL2Block) {
|
|
749
747
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
750
748
|
}
|
|
751
|
-
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
752
749
|
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
750
|
+
// Rollback operates at checkpoint granularity: the target block must be the last block of its checkpoint.
|
|
751
|
+
const checkpointData = await this.store.getCheckpointData(targetCheckpointNumber);
|
|
752
|
+
if (checkpointData) {
|
|
753
|
+
const lastBlockInCheckpoint = BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
754
|
+
if (targetL2BlockNumber !== lastBlockInCheckpoint) {
|
|
755
|
+
const previousCheckpointBoundary = checkpointData.startBlock > 1 ? BlockNumber(checkpointData.startBlock - 1) : BlockNumber(0);
|
|
756
|
+
throw new Error(`Target L2 block ${targetL2BlockNumber} is not at a checkpoint boundary. ` + `Checkpoint ${targetCheckpointNumber} spans blocks ${checkpointData.startBlock} to ${lastBlockInCheckpoint}. ` + `Use block ${lastBlockInCheckpoint} to roll back to this checkpoint, ` + `or block ${previousCheckpointBoundary} to roll back to the previous one.`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
753
760
|
const targetL1Block = await this.publicClient.getBlock({
|
|
754
761
|
blockNumber: targetL1BlockNumber,
|
|
755
762
|
includeTransactions: false
|
|
@@ -764,18 +771,18 @@ _dec = trackSpan('Archiver.sync');
|
|
|
764
771
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
765
772
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
766
773
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
767
|
-
await this.store.
|
|
774
|
+
await this.store.setMessageSyncState({
|
|
768
775
|
l1BlockNumber: targetL1BlockNumber,
|
|
769
776
|
l1BlockHash: targetL1BlockHash
|
|
770
|
-
});
|
|
777
|
+
}, undefined);
|
|
771
778
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
772
|
-
this.log.info(`
|
|
773
|
-
await this.
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
779
|
+
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
780
|
+
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
781
|
+
}
|
|
782
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
783
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
784
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
785
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
786
|
+
}
|
|
780
787
|
}
|
|
781
788
|
}
|