@aztec/archiver 0.0.1-commit.ee80a48 → 0.0.1-commit.f103f88
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 +12 -8
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +83 -114
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -2
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +31 -26
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +35 -34
- 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/modules/data_source_base.d.ts +14 -7
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +39 -77
- package/dest/modules/data_store_updater.d.ts +25 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +125 -94
- package/dest/modules/instrumentation.d.ts +18 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +36 -8
- package/dest/modules/l1_synchronizer.d.ts +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +179 -137
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +66 -28
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +357 -136
- 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 +61 -24
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +75 -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 +21 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- 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 +26 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +160 -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 +5 -2
- package/package.json +13 -13
- package/src/archiver.ts +106 -139
- package/src/config.ts +9 -2
- package/src/errors.ts +70 -26
- package/src/factory.ts +46 -24
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +31 -37
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +78 -98
- package/src/modules/data_store_updater.ts +138 -124
- package/src/modules/instrumentation.ts +48 -9
- package/src/modules/l1_synchronizer.ts +203 -172
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +451 -172
- 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 +115 -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 +178 -30
- 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 +209 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -2
package/src/archiver.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
-
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
3
2
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
4
3
|
import { BlockTagTooOldError, RollupContract } from '@aztec/ethereum/contracts';
|
|
5
4
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
@@ -12,35 +11,33 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
12
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
13
12
|
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
14
13
|
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
15
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
14
|
+
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
16
15
|
import {
|
|
17
16
|
type ArchiverEmitter,
|
|
18
|
-
type CheckpointId,
|
|
19
|
-
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
20
17
|
L2Block,
|
|
21
18
|
type L2BlockSink,
|
|
22
19
|
type L2Tips,
|
|
23
20
|
type ValidateCheckpointResult,
|
|
24
21
|
} from '@aztec/stdlib/block';
|
|
25
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
22
|
+
import { type ProposedCheckpointInput, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
26
23
|
import {
|
|
27
24
|
type L1RollupConstants,
|
|
28
|
-
|
|
25
|
+
getEpochAtSlot,
|
|
29
26
|
getSlotAtNextL1Block,
|
|
30
|
-
getSlotAtTimestamp,
|
|
31
27
|
getSlotRangeForEpoch,
|
|
32
28
|
getTimestampRangeForEpoch,
|
|
33
29
|
} from '@aztec/stdlib/epoch-helpers';
|
|
34
30
|
import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
35
31
|
|
|
36
32
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
37
|
-
import { NoBlobBodiesFoundError } from './errors.js';
|
|
33
|
+
import { BlockAlreadyCheckpointedError, NoBlobBodiesFoundError } from './errors.js';
|
|
38
34
|
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
39
35
|
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
40
36
|
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
41
37
|
import type { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
42
38
|
import type { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
43
39
|
import type { KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
40
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
44
41
|
|
|
45
42
|
/** Export ArchiverEmitter for use in factory and tests. */
|
|
46
43
|
export type { ArchiverEmitter };
|
|
@@ -83,19 +80,23 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
83
80
|
/** Helper to handle updates to the store */
|
|
84
81
|
private readonly updater: ArchiverDataStoreUpdater;
|
|
85
82
|
|
|
83
|
+
/** In-memory cache for L2 chain tips. */
|
|
84
|
+
private readonly l2TipsCache: L2TipsCache;
|
|
85
|
+
|
|
86
86
|
public readonly tracer: Tracer;
|
|
87
87
|
|
|
88
|
+
private readonly instrumentation: ArchiverInstrumentation;
|
|
89
|
+
|
|
88
90
|
/**
|
|
89
91
|
* Creates a new instance of the Archiver.
|
|
90
92
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
91
93
|
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
92
94
|
* @param rollup - Rollup contract instance.
|
|
93
95
|
* @param inbox - Inbox contract instance.
|
|
94
|
-
* @param l1Addresses - L1 contract addresses (registry, governance proposer,
|
|
96
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
95
97
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
96
98
|
* @param config - Archiver configuration options.
|
|
97
99
|
* @param blobClient - Client for retrieving blob data.
|
|
98
|
-
* @param epochCache - Cache for epoch-related data.
|
|
99
100
|
* @param dateProvider - Provider for current date/time.
|
|
100
101
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
101
102
|
* @param l1Constants - L1 rollup constants.
|
|
@@ -105,10 +106,9 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
105
106
|
private readonly publicClient: ViemPublicClient,
|
|
106
107
|
private readonly debugClient: ViemPublicDebugClient,
|
|
107
108
|
private readonly rollup: RollupContract,
|
|
108
|
-
private readonly l1Addresses: Pick<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
> & { slashingProposerAddress: EthAddress },
|
|
109
|
+
private readonly l1Addresses: Pick<L1ContractAddresses, 'registryAddress' | 'governanceProposerAddress'> & {
|
|
110
|
+
slashingProposerAddress: EthAddress;
|
|
111
|
+
},
|
|
112
112
|
readonly dataStore: KVArchiverDataStore,
|
|
113
113
|
private config: {
|
|
114
114
|
pollingIntervalMs: number;
|
|
@@ -119,18 +119,26 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
119
119
|
},
|
|
120
120
|
private readonly blobClient: BlobClientInterface,
|
|
121
121
|
instrumentation: ArchiverInstrumentation,
|
|
122
|
-
protected override readonly l1Constants: L1RollupConstants & {
|
|
122
|
+
protected override readonly l1Constants: L1RollupConstants & {
|
|
123
|
+
l1StartBlockHash: Buffer32;
|
|
124
|
+
genesisArchiveRoot: Fr;
|
|
125
|
+
},
|
|
123
126
|
synchronizer: ArchiverL1Synchronizer,
|
|
124
127
|
events: ArchiverEmitter,
|
|
128
|
+
l2TipsCache?: L2TipsCache,
|
|
125
129
|
private readonly log: Logger = createLogger('archiver'),
|
|
126
130
|
) {
|
|
127
131
|
super(dataStore, l1Constants);
|
|
128
132
|
|
|
129
133
|
this.tracer = instrumentation.tracer;
|
|
134
|
+
this.instrumentation = instrumentation;
|
|
130
135
|
this.initialSyncPromise = promiseWithResolvers();
|
|
131
136
|
this.synchronizer = synchronizer;
|
|
132
137
|
this.events = events;
|
|
133
|
-
this.
|
|
138
|
+
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
139
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache, {
|
|
140
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
141
|
+
});
|
|
134
142
|
|
|
135
143
|
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
136
144
|
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
@@ -203,6 +211,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
203
211
|
});
|
|
204
212
|
}
|
|
205
213
|
|
|
214
|
+
public async setProposedCheckpoint(pending: ProposedCheckpointInput): Promise<void> {
|
|
215
|
+
await this.updater.setProposedCheckpoint(pending);
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
/**
|
|
207
219
|
* Processes all queued blocks, adding them to the store.
|
|
208
220
|
* Called at the beginning of each sync iteration.
|
|
@@ -235,10 +247,16 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
try {
|
|
238
|
-
await this.updater.
|
|
250
|
+
const [durationMs] = await elapsed(() => this.updater.addProposedBlock(block));
|
|
251
|
+
this.instrumentation.processNewProposedBlock(durationMs, block);
|
|
239
252
|
this.log.debug(`Added block ${block.number} to store`);
|
|
240
253
|
resolve();
|
|
241
254
|
} catch (err: any) {
|
|
255
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
256
|
+
this.log.debug(`Proposed block ${block.number} matches already checkpointed block, ignoring late proposal`);
|
|
257
|
+
resolve();
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
242
260
|
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
243
261
|
reject(err);
|
|
244
262
|
}
|
|
@@ -330,16 +348,49 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
330
348
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
331
349
|
}
|
|
332
350
|
|
|
333
|
-
public
|
|
351
|
+
public async getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
352
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
353
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
354
|
+
// we have seen the corresponding checkpoint.
|
|
355
|
+
|
|
356
|
+
let slotFromL1Sync: SlotNumber | undefined;
|
|
334
357
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
335
|
-
|
|
358
|
+
if (l1Timestamp !== undefined) {
|
|
359
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
360
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
361
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
let slotFromCheckpoint: SlotNumber | undefined;
|
|
366
|
+
const latestCheckpointNumber = await this.store.getSynchedCheckpointNumber();
|
|
367
|
+
if (latestCheckpointNumber > 0) {
|
|
368
|
+
const checkpointData = await this.store.getCheckpointData(latestCheckpointNumber);
|
|
369
|
+
if (checkpointData) {
|
|
370
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
336
378
|
}
|
|
337
379
|
|
|
338
|
-
public
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
380
|
+
public async getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
381
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
382
|
+
if (syncedSlot === undefined) {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
// An epoch is fully synced when all its slots are synced.
|
|
386
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
387
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
388
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
389
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
390
|
+
if (syncedSlot >= endSlot) {
|
|
391
|
+
return epoch;
|
|
392
|
+
}
|
|
393
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
343
394
|
}
|
|
344
395
|
|
|
345
396
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -391,115 +442,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
391
442
|
return true;
|
|
392
443
|
}
|
|
393
444
|
|
|
394
|
-
public
|
|
395
|
-
|
|
396
|
-
this.getBlockNumber(),
|
|
397
|
-
this.getProvenBlockNumber(),
|
|
398
|
-
this.getCheckpointedL2BlockNumber(),
|
|
399
|
-
this.getFinalizedL2BlockNumber(),
|
|
400
|
-
] as const);
|
|
401
|
-
|
|
402
|
-
const beforeInitialblockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
403
|
-
|
|
404
|
-
// Get the latest block header and checkpointed blocks for proven, finalised and checkpointed blocks
|
|
405
|
-
const [latestBlockHeader, provenCheckpointedBlock, finalizedCheckpointedBlock, checkpointedBlock] =
|
|
406
|
-
await Promise.all([
|
|
407
|
-
latestBlockNumber > beforeInitialblockNumber ? this.getBlockHeader(latestBlockNumber) : undefined,
|
|
408
|
-
provenBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(provenBlockNumber) : undefined,
|
|
409
|
-
finalizedBlockNumber > beforeInitialblockNumber ? this.getCheckpointedBlock(finalizedBlockNumber) : undefined,
|
|
410
|
-
checkpointedBlockNumber > beforeInitialblockNumber
|
|
411
|
-
? this.getCheckpointedBlock(checkpointedBlockNumber)
|
|
412
|
-
: undefined,
|
|
413
|
-
] as const);
|
|
414
|
-
|
|
415
|
-
if (latestBlockNumber > beforeInitialblockNumber && !latestBlockHeader) {
|
|
416
|
-
throw new Error(`Failed to retrieve latest block header for block ${latestBlockNumber}`);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Checkpointed blocks must exist for proven, finalized and checkpointed tips if they are beyond the initial block number.
|
|
420
|
-
if (checkpointedBlockNumber > beforeInitialblockNumber && !checkpointedBlock?.block.header) {
|
|
421
|
-
throw new Error(
|
|
422
|
-
`Failed to retrieve checkpointed block header for block ${checkpointedBlockNumber} (latest block is ${latestBlockNumber})`,
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (provenBlockNumber > beforeInitialblockNumber && !provenCheckpointedBlock?.block.header) {
|
|
427
|
-
throw new Error(
|
|
428
|
-
`Failed to retrieve proven checkpointed for block ${provenBlockNumber} (latest block is ${latestBlockNumber})`,
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (finalizedBlockNumber > beforeInitialblockNumber && !finalizedCheckpointedBlock?.block.header) {
|
|
433
|
-
throw new Error(
|
|
434
|
-
`Failed to retrieve finalized block header for block ${finalizedBlockNumber} (latest block is ${latestBlockNumber})`,
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
const latestBlockHeaderHash = (await latestBlockHeader?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
439
|
-
const provenBlockHeaderHash = (await provenCheckpointedBlock?.block.header?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
440
|
-
const finalizedBlockHeaderHash =
|
|
441
|
-
(await finalizedCheckpointedBlock?.block.header?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
442
|
-
const checkpointedBlockHeaderHash = (await checkpointedBlock?.block.header?.hash()) ?? GENESIS_BLOCK_HEADER_HASH;
|
|
443
|
-
|
|
444
|
-
// Now attempt to retrieve checkpoints for proven, finalised and checkpointed blocks
|
|
445
|
-
const [[provenBlockCheckpoint], [finalizedBlockCheckpoint], [checkpointedBlockCheckpoint]] = await Promise.all([
|
|
446
|
-
provenCheckpointedBlock !== undefined
|
|
447
|
-
? await this.getCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1)
|
|
448
|
-
: [undefined],
|
|
449
|
-
finalizedCheckpointedBlock !== undefined
|
|
450
|
-
? await this.getCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1)
|
|
451
|
-
: [undefined],
|
|
452
|
-
checkpointedBlock !== undefined ? await this.getCheckpoints(checkpointedBlock?.checkpointNumber, 1) : [undefined],
|
|
453
|
-
]);
|
|
454
|
-
|
|
455
|
-
const initialcheckpointId: CheckpointId = {
|
|
456
|
-
number: CheckpointNumber.ZERO,
|
|
457
|
-
hash: GENESIS_CHECKPOINT_HEADER_HASH.toString(),
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
const makeCheckpointId = (checkpoint: PublishedCheckpoint | undefined) => {
|
|
461
|
-
if (checkpoint === undefined) {
|
|
462
|
-
return initialcheckpointId;
|
|
463
|
-
}
|
|
464
|
-
return {
|
|
465
|
-
number: checkpoint.checkpoint.number,
|
|
466
|
-
hash: checkpoint.checkpoint.hash().toString(),
|
|
467
|
-
};
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
const l2Tips: L2Tips = {
|
|
471
|
-
proposed: {
|
|
472
|
-
number: latestBlockNumber,
|
|
473
|
-
hash: latestBlockHeaderHash.toString(),
|
|
474
|
-
},
|
|
475
|
-
proven: {
|
|
476
|
-
block: {
|
|
477
|
-
number: provenBlockNumber,
|
|
478
|
-
hash: provenBlockHeaderHash.toString(),
|
|
479
|
-
},
|
|
480
|
-
checkpoint: makeCheckpointId(provenBlockCheckpoint),
|
|
481
|
-
},
|
|
482
|
-
finalized: {
|
|
483
|
-
block: {
|
|
484
|
-
number: finalizedBlockNumber,
|
|
485
|
-
hash: finalizedBlockHeaderHash.toString(),
|
|
486
|
-
},
|
|
487
|
-
checkpoint: makeCheckpointId(finalizedBlockCheckpoint),
|
|
488
|
-
},
|
|
489
|
-
checkpointed: {
|
|
490
|
-
block: {
|
|
491
|
-
number: checkpointedBlockNumber,
|
|
492
|
-
hash: checkpointedBlockHeaderHash.toString(),
|
|
493
|
-
},
|
|
494
|
-
checkpoint: makeCheckpointId(checkpointedBlockCheckpoint),
|
|
495
|
-
},
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
return l2Tips;
|
|
445
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
446
|
+
return this.l2TipsCache.getL2Tips();
|
|
499
447
|
}
|
|
500
448
|
|
|
501
449
|
public async rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void> {
|
|
502
|
-
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
503
450
|
const currentBlocks = await this.getL2Tips();
|
|
504
451
|
const currentL2Block = currentBlocks.proposed.number;
|
|
505
452
|
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
@@ -511,8 +458,25 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
511
458
|
if (!targetL2Block) {
|
|
512
459
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
513
460
|
}
|
|
514
|
-
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
515
461
|
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
462
|
+
|
|
463
|
+
// Rollback operates at checkpoint granularity: the target block must be the last block of its checkpoint.
|
|
464
|
+
const checkpointData = await this.store.getCheckpointData(targetCheckpointNumber);
|
|
465
|
+
if (checkpointData) {
|
|
466
|
+
const lastBlockInCheckpoint = BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
467
|
+
if (targetL2BlockNumber !== lastBlockInCheckpoint) {
|
|
468
|
+
const previousCheckpointBoundary =
|
|
469
|
+
checkpointData.startBlock > 1 ? BlockNumber(checkpointData.startBlock - 1) : BlockNumber(0);
|
|
470
|
+
throw new Error(
|
|
471
|
+
`Target L2 block ${targetL2BlockNumber} is not at a checkpoint boundary. ` +
|
|
472
|
+
`Checkpoint ${targetCheckpointNumber} spans blocks ${checkpointData.startBlock} to ${lastBlockInCheckpoint}. ` +
|
|
473
|
+
`Use block ${lastBlockInCheckpoint} to roll back to this checkpoint, ` +
|
|
474
|
+
`or block ${previousCheckpointBoundary} to roll back to the previous one.`,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
516
480
|
const targetL1Block = await this.publicClient.getBlock({
|
|
517
481
|
blockNumber: targetL1BlockNumber,
|
|
518
482
|
includeTransactions: false,
|
|
@@ -529,15 +493,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
529
493
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
530
494
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
531
495
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
532
|
-
await this.store.
|
|
496
|
+
await this.store.setMessageSyncState(
|
|
497
|
+
{ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash },
|
|
498
|
+
undefined,
|
|
499
|
+
);
|
|
533
500
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
534
|
-
this.log.info(`
|
|
535
|
-
await this.
|
|
501
|
+
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
502
|
+
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
503
|
+
}
|
|
504
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
505
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
506
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
507
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
536
508
|
}
|
|
537
|
-
// TODO(palla/reorg): Set the finalized block when we add support for it.
|
|
538
|
-
// if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
539
|
-
// this.log.info(`Clearing finalized L2 block number`);
|
|
540
|
-
// await this.store.setFinalizedL2BlockNumber(0);
|
|
541
|
-
// }
|
|
542
509
|
}
|
|
543
510
|
}
|
package/src/config.ts
CHANGED
|
@@ -8,7 +8,12 @@ import {
|
|
|
8
8
|
getConfigFromMappings,
|
|
9
9
|
numberConfigHelper,
|
|
10
10
|
} from '@aztec/foundation/config';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type ChainConfig,
|
|
13
|
+
type PipelineConfig,
|
|
14
|
+
chainConfigMappings,
|
|
15
|
+
pipelineConfigMappings,
|
|
16
|
+
} from '@aztec/stdlib/config';
|
|
12
17
|
import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
18
|
|
|
14
19
|
/**
|
|
@@ -21,11 +26,13 @@ import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
|
|
|
21
26
|
export type ArchiverConfig = ArchiverSpecificConfig &
|
|
22
27
|
L1ReaderConfig &
|
|
23
28
|
L1ContractsConfig &
|
|
29
|
+
PipelineConfig & // required to pass through to epoch cache
|
|
24
30
|
BlobClientConfig &
|
|
25
31
|
ChainConfig;
|
|
26
32
|
|
|
27
33
|
export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
28
34
|
...blobClientConfigMapping,
|
|
35
|
+
...pipelineConfigMappings,
|
|
29
36
|
archiverPollingIntervalMS: {
|
|
30
37
|
env: 'ARCHIVER_POLLING_INTERVAL_MS',
|
|
31
38
|
description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
|
|
@@ -43,7 +50,7 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
43
50
|
},
|
|
44
51
|
archiverStoreMapSizeKb: {
|
|
45
52
|
env: 'ARCHIVER_STORE_MAP_SIZE_KB',
|
|
46
|
-
parseEnv: (val: string
|
|
53
|
+
parseEnv: (val: string) => +val,
|
|
47
54
|
description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
48
55
|
},
|
|
49
56
|
skipValidateCheckpointAttestations: {
|
package/src/errors.ts
CHANGED
|
@@ -6,24 +6,9 @@ export class NoBlobBodiesFoundError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export class InitialBlockNumberNotSequentialError extends Error {
|
|
10
|
-
constructor(
|
|
11
|
-
public readonly newBlockNumber: number,
|
|
12
|
-
public readonly previousBlockNumber: number | undefined,
|
|
13
|
-
) {
|
|
14
|
-
super(
|
|
15
|
-
`Cannot insert new block ${newBlockNumber} given previous block number in store is ${
|
|
16
|
-
previousBlockNumber ?? 'undefined'
|
|
17
|
-
}`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
9
|
export class BlockNumberNotSequentialError extends Error {
|
|
23
10
|
constructor(newBlockNumber: number, previous: number | undefined) {
|
|
24
|
-
super(
|
|
25
|
-
`Cannot insert new block ${newBlockNumber} given previous block number in batch is ${previous ?? 'undefined'}`,
|
|
26
|
-
);
|
|
11
|
+
super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
|
|
27
12
|
}
|
|
28
13
|
}
|
|
29
14
|
|
|
@@ -41,17 +26,13 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
|
|
|
41
26
|
}
|
|
42
27
|
|
|
43
28
|
export class CheckpointNumberNotSequentialError extends Error {
|
|
44
|
-
constructor(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class CheckpointNumberNotConsistentError extends Error {
|
|
52
|
-
constructor(newCheckpointNumber: number, previous: number | undefined) {
|
|
29
|
+
constructor(
|
|
30
|
+
newCheckpointNumber: number,
|
|
31
|
+
previous: number | undefined,
|
|
32
|
+
source: 'confirmed' | 'proposed' = 'confirmed',
|
|
33
|
+
) {
|
|
53
34
|
super(
|
|
54
|
-
`Cannot insert
|
|
35
|
+
`Cannot insert new checkpoint ${newCheckpointNumber} given previous ${source} checkpoint number is ${previous ?? 'undefined'}`,
|
|
55
36
|
);
|
|
56
37
|
}
|
|
57
38
|
}
|
|
@@ -89,6 +70,69 @@ export class BlockNotFoundError extends Error {
|
|
|
89
70
|
}
|
|
90
71
|
}
|
|
91
72
|
|
|
73
|
+
/** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
|
|
74
|
+
export class BlockAlreadyCheckpointedError extends Error {
|
|
75
|
+
constructor(public readonly blockNumber: number) {
|
|
76
|
+
super(`Block ${blockNumber} has already been checkpointed with the same content`);
|
|
77
|
+
this.name = 'BlockAlreadyCheckpointedError';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
|
|
82
|
+
export class OutOfOrderLogInsertionError extends Error {
|
|
83
|
+
constructor(
|
|
84
|
+
public readonly logType: 'private' | 'public',
|
|
85
|
+
public readonly tag: string,
|
|
86
|
+
public readonly lastBlockNumber: number,
|
|
87
|
+
public readonly newBlockNumber: number,
|
|
88
|
+
) {
|
|
89
|
+
super(
|
|
90
|
+
`Out-of-order ${logType} log insertion for tag ${tag}: ` +
|
|
91
|
+
`last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
|
|
92
|
+
);
|
|
93
|
+
this.name = 'OutOfOrderLogInsertionError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
|
|
98
|
+
export class L1ToL2MessagesNotReadyError extends Error {
|
|
99
|
+
constructor(
|
|
100
|
+
public readonly checkpointNumber: number,
|
|
101
|
+
public readonly inboxTreeInProgress: bigint,
|
|
102
|
+
) {
|
|
103
|
+
super(
|
|
104
|
+
`Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
|
|
105
|
+
`inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
|
|
106
|
+
);
|
|
107
|
+
this.name = 'L1ToL2MessagesNotReadyError';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Thrown when a proposed checkpoint number is stale (already processed). */
|
|
112
|
+
export class ProposedCheckpointStaleError extends Error {
|
|
113
|
+
constructor(
|
|
114
|
+
public readonly proposedCheckpointNumber: number,
|
|
115
|
+
public readonly currentProposedNumber: number,
|
|
116
|
+
) {
|
|
117
|
+
super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
|
|
118
|
+
this.name = 'ProposedCheckpointStaleError';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Thrown when a proposed checkpoint number is not the expected confirmed + 1. */
|
|
123
|
+
export class ProposedCheckpointNotSequentialError extends Error {
|
|
124
|
+
constructor(
|
|
125
|
+
public readonly proposedCheckpointNumber: number,
|
|
126
|
+
public readonly confirmedCheckpointNumber: number,
|
|
127
|
+
) {
|
|
128
|
+
super(
|
|
129
|
+
`Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${confirmedCheckpointNumber + 1} (confirmed + 1)`,
|
|
130
|
+
);
|
|
131
|
+
this.name = 'ProposedCheckpointNotSequentialError';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
|
|
92
136
|
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
93
137
|
constructor(
|
|
94
138
|
public readonly blockNumber: number,
|