@aztec/archiver 0.0.1-commit.8afd444 → 0.0.1-commit.8ee97c858
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 +7 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +62 -111
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +21 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +27 -14
- package/dest/factory.d.ts +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +24 -20
- 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 +190 -259
- package/dest/l1/data_retrieval.d.ts +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +21 -19
- 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 +12 -7
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +33 -77
- package/dest/modules/data_store_updater.d.ts +22 -7
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +70 -30
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +19 -2
- package/dest/modules/l1_synchronizer.d.ts +5 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +50 -15
- package/dest/store/block_store.d.ts +29 -26
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +130 -78
- package/dest/store/kv_archiver_store.d.ts +40 -13
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +48 -13
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -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 +148 -51
- 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 +14 -1
- package/dest/test/fake_l1_state.d.ts +13 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +95 -23
- 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_l2_block_source.d.ts +21 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +132 -86
- 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 -1
- package/package.json +13 -13
- package/src/archiver.ts +74 -131
- package/src/config.ts +8 -1
- package/src/errors.ts +40 -24
- package/src/factory.ts +34 -17
- 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 +249 -379
- package/src/l1/data_retrieval.ts +23 -25
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +64 -98
- package/src/modules/data_store_updater.ts +72 -31
- package/src/modules/instrumentation.ts +29 -2
- package/src/modules/l1_synchronizer.ts +61 -24
- package/src/store/block_store.ts +157 -105
- package/src/store/kv_archiver_store.ts +73 -15
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +219 -58
- package/src/store/message_store.ts +20 -1
- package/src/test/fake_l1_state.ts +125 -26
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +173 -81
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -1
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';
|
|
@@ -15,8 +14,6 @@ import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/runni
|
|
|
15
14
|
import { DateProvider } 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,
|
|
@@ -25,22 +22,22 @@ import {
|
|
|
25
22
|
import { 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,6 +80,9 @@ 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
88
|
/**
|
|
@@ -95,7 +95,6 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
95
95
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
96
96
|
* @param config - Archiver configuration options.
|
|
97
97
|
* @param blobClient - Client for retrieving blob data.
|
|
98
|
-
* @param epochCache - Cache for epoch-related data.
|
|
99
98
|
* @param dateProvider - Provider for current date/time.
|
|
100
99
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
101
100
|
* @param l1Constants - L1 rollup constants.
|
|
@@ -119,9 +118,13 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
119
118
|
},
|
|
120
119
|
private readonly blobClient: BlobClientInterface,
|
|
121
120
|
instrumentation: ArchiverInstrumentation,
|
|
122
|
-
protected override readonly l1Constants: L1RollupConstants & {
|
|
121
|
+
protected override readonly l1Constants: L1RollupConstants & {
|
|
122
|
+
l1StartBlockHash: Buffer32;
|
|
123
|
+
genesisArchiveRoot: Fr;
|
|
124
|
+
},
|
|
123
125
|
synchronizer: ArchiverL1Synchronizer,
|
|
124
126
|
events: ArchiverEmitter,
|
|
127
|
+
l2TipsCache?: L2TipsCache,
|
|
125
128
|
private readonly log: Logger = createLogger('archiver'),
|
|
126
129
|
) {
|
|
127
130
|
super(dataStore, l1Constants);
|
|
@@ -130,7 +133,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
130
133
|
this.initialSyncPromise = promiseWithResolvers();
|
|
131
134
|
this.synchronizer = synchronizer;
|
|
132
135
|
this.events = events;
|
|
133
|
-
this.
|
|
136
|
+
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
137
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache, {
|
|
138
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
139
|
+
});
|
|
134
140
|
|
|
135
141
|
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
136
142
|
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
@@ -235,10 +241,15 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
235
241
|
}
|
|
236
242
|
|
|
237
243
|
try {
|
|
238
|
-
await this.updater.
|
|
244
|
+
await this.updater.addProposedBlock(block);
|
|
239
245
|
this.log.debug(`Added block ${block.number} to store`);
|
|
240
246
|
resolve();
|
|
241
247
|
} catch (err: any) {
|
|
248
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
249
|
+
this.log.debug(`Proposed block ${block.number} matches already checkpointed block, ignoring late proposal`);
|
|
250
|
+
resolve();
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
242
253
|
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
243
254
|
reject(err);
|
|
244
255
|
}
|
|
@@ -330,16 +341,35 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
330
341
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
331
342
|
}
|
|
332
343
|
|
|
333
|
-
public
|
|
344
|
+
public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
334
345
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
335
|
-
|
|
346
|
+
if (l1Timestamp === undefined) {
|
|
347
|
+
return Promise.resolve(undefined);
|
|
348
|
+
}
|
|
349
|
+
// The synced slot is the last L2 slot whose all L1 blocks have been processed.
|
|
350
|
+
// If the next L1 block (at l1Timestamp + ethereumSlotDuration) falls in slot N,
|
|
351
|
+
// then we've fully synced slot N-1.
|
|
352
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
353
|
+
if (Number(nextL1BlockSlot) === 0) {
|
|
354
|
+
return Promise.resolve(undefined);
|
|
355
|
+
}
|
|
356
|
+
return Promise.resolve(SlotNumber(nextL1BlockSlot - 1));
|
|
336
357
|
}
|
|
337
358
|
|
|
338
|
-
public
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
359
|
+
public async getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
360
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
361
|
+
if (syncedSlot === undefined) {
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
// An epoch is fully synced when all its slots are synced.
|
|
365
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
366
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
367
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
368
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
369
|
+
if (syncedSlot >= endSlot) {
|
|
370
|
+
return epoch;
|
|
371
|
+
}
|
|
372
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
343
373
|
}
|
|
344
374
|
|
|
345
375
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -391,115 +421,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
391
421
|
return true;
|
|
392
422
|
}
|
|
393
423
|
|
|
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;
|
|
424
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
425
|
+
return this.l2TipsCache.getL2Tips();
|
|
499
426
|
}
|
|
500
427
|
|
|
501
428
|
public async rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void> {
|
|
502
|
-
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
503
429
|
const currentBlocks = await this.getL2Tips();
|
|
504
430
|
const currentL2Block = currentBlocks.proposed.number;
|
|
505
431
|
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
@@ -511,8 +437,25 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
511
437
|
if (!targetL2Block) {
|
|
512
438
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
513
439
|
}
|
|
514
|
-
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
515
440
|
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
441
|
+
|
|
442
|
+
// Rollback operates at checkpoint granularity: the target block must be the last block of its checkpoint.
|
|
443
|
+
const checkpointData = await this.store.getCheckpointData(targetCheckpointNumber);
|
|
444
|
+
if (checkpointData) {
|
|
445
|
+
const lastBlockInCheckpoint = BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
446
|
+
if (targetL2BlockNumber !== lastBlockInCheckpoint) {
|
|
447
|
+
const previousCheckpointBoundary =
|
|
448
|
+
checkpointData.startBlock > 1 ? BlockNumber(checkpointData.startBlock - 1) : BlockNumber(0);
|
|
449
|
+
throw new Error(
|
|
450
|
+
`Target L2 block ${targetL2BlockNumber} is not at a checkpoint boundary. ` +
|
|
451
|
+
`Checkpoint ${targetCheckpointNumber} spans blocks ${checkpointData.startBlock} to ${lastBlockInCheckpoint}. ` +
|
|
452
|
+
`Use block ${lastBlockInCheckpoint} to roll back to this checkpoint, ` +
|
|
453
|
+
`or block ${previousCheckpointBoundary} to roll back to the previous one.`,
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
516
459
|
const targetL1Block = await this.publicClient.getBlock({
|
|
517
460
|
blockNumber: targetL1BlockNumber,
|
|
518
461
|
includeTransactions: false,
|
|
@@ -531,13 +474,13 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
531
474
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
532
475
|
await this.store.setMessageSynchedL1Block({ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash });
|
|
533
476
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
534
|
-
this.log.info(`
|
|
535
|
-
await this.
|
|
477
|
+
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
478
|
+
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
479
|
+
}
|
|
480
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
481
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
482
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
483
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
536
484
|
}
|
|
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
485
|
}
|
|
543
486
|
}
|
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.',
|
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
|
|
|
@@ -48,14 +33,6 @@ export class CheckpointNumberNotSequentialError extends Error {
|
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
35
|
|
|
51
|
-
export class CheckpointNumberNotConsistentError extends Error {
|
|
52
|
-
constructor(newCheckpointNumber: number, previous: number | undefined) {
|
|
53
|
-
super(
|
|
54
|
-
`Cannot insert block for new checkpoint ${newCheckpointNumber} given previous block was checkpoint ${previous ?? 'undefined'}`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
36
|
export class BlockIndexNotSequentialError extends Error {
|
|
60
37
|
constructor(newBlockIndex: number, previousBlockIndex: number | undefined) {
|
|
61
38
|
super(
|
|
@@ -89,6 +66,45 @@ export class BlockNotFoundError extends Error {
|
|
|
89
66
|
}
|
|
90
67
|
}
|
|
91
68
|
|
|
69
|
+
/** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
|
|
70
|
+
export class BlockAlreadyCheckpointedError extends Error {
|
|
71
|
+
constructor(public readonly blockNumber: number) {
|
|
72
|
+
super(`Block ${blockNumber} has already been checkpointed with the same content`);
|
|
73
|
+
this.name = 'BlockAlreadyCheckpointedError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
|
|
78
|
+
export class OutOfOrderLogInsertionError extends Error {
|
|
79
|
+
constructor(
|
|
80
|
+
public readonly logType: 'private' | 'public',
|
|
81
|
+
public readonly tag: string,
|
|
82
|
+
public readonly lastBlockNumber: number,
|
|
83
|
+
public readonly newBlockNumber: number,
|
|
84
|
+
) {
|
|
85
|
+
super(
|
|
86
|
+
`Out-of-order ${logType} log insertion for tag ${tag}: ` +
|
|
87
|
+
`last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
|
|
88
|
+
);
|
|
89
|
+
this.name = 'OutOfOrderLogInsertionError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
|
|
94
|
+
export class L1ToL2MessagesNotReadyError extends Error {
|
|
95
|
+
constructor(
|
|
96
|
+
public readonly checkpointNumber: number,
|
|
97
|
+
public readonly inboxTreeInProgress: bigint,
|
|
98
|
+
) {
|
|
99
|
+
super(
|
|
100
|
+
`Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
|
|
101
|
+
`inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
|
|
102
|
+
);
|
|
103
|
+
this.name = 'L1ToL2MessagesNotReadyError';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
|
|
92
108
|
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
93
109
|
constructor(
|
|
94
110
|
public readonly blockNumber: number,
|
package/src/factory.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
2
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
|
+
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
3
4
|
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
5
|
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
5
6
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
@@ -7,38 +8,37 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
7
8
|
import { merge } from '@aztec/foundation/collection';
|
|
8
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
10
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
10
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
11
11
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
12
12
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
13
13
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
14
14
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
15
15
|
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
16
16
|
import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
|
-
import type {
|
|
17
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
18
18
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
19
19
|
|
|
20
20
|
import { EventEmitter } from 'events';
|
|
21
|
-
import { createPublicClient
|
|
21
|
+
import { createPublicClient } from 'viem';
|
|
22
22
|
|
|
23
23
|
import { Archiver, type ArchiverDeps } from './archiver.js';
|
|
24
24
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
25
25
|
import { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
26
26
|
import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
27
27
|
import { ARCHIVER_DB_VERSION, KVArchiverDataStore } from './store/kv_archiver_store.js';
|
|
28
|
+
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
28
29
|
|
|
29
30
|
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
30
31
|
|
|
31
32
|
/** Creates an archiver store. */
|
|
32
33
|
export async function createArchiverStore(
|
|
33
34
|
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
|
|
34
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
35
35
|
) {
|
|
36
36
|
const config = {
|
|
37
37
|
...userConfig,
|
|
38
38
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
39
39
|
};
|
|
40
40
|
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
41
|
-
return new KVArchiverDataStore(store, config.maxLogs
|
|
41
|
+
return new KVArchiverDataStore(store, config.maxLogs);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -53,14 +53,15 @@ export async function createArchiver(
|
|
|
53
53
|
deps: ArchiverDeps,
|
|
54
54
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
55
55
|
): Promise<Archiver> {
|
|
56
|
-
const archiverStore = await createArchiverStore(config
|
|
56
|
+
const archiverStore = await createArchiverStore(config);
|
|
57
57
|
await registerProtocolContracts(archiverStore);
|
|
58
58
|
|
|
59
59
|
// Create Ethereum clients
|
|
60
60
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
61
|
+
const httpTimeout = config.l1HttpTimeoutMS;
|
|
61
62
|
const publicClient = createPublicClient({
|
|
62
63
|
chain: chain.chainInfo,
|
|
63
|
-
transport:
|
|
64
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
|
|
64
65
|
pollingInterval: config.viemPollingIntervalMS,
|
|
65
66
|
});
|
|
66
67
|
|
|
@@ -68,7 +69,7 @@ export async function createArchiver(
|
|
|
68
69
|
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
69
70
|
const debugClient = createPublicClient({
|
|
70
71
|
chain: chain.chainInfo,
|
|
71
|
-
transport:
|
|
72
|
+
transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
|
|
72
73
|
pollingInterval: config.viemPollingIntervalMS,
|
|
73
74
|
}) as ViemPublicDebugClient;
|
|
74
75
|
|
|
@@ -77,14 +78,23 @@ export async function createArchiver(
|
|
|
77
78
|
const inbox = new InboxContract(publicClient, config.l1Contracts.inboxAddress);
|
|
78
79
|
|
|
79
80
|
// Fetch L1 constants from rollup contract
|
|
80
|
-
const [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
const [
|
|
82
|
+
l1StartBlock,
|
|
83
|
+
l1GenesisTime,
|
|
84
|
+
proofSubmissionEpochs,
|
|
85
|
+
genesisArchiveRoot,
|
|
86
|
+
slashingProposerAddress,
|
|
87
|
+
targetCommitteeSize,
|
|
88
|
+
rollupManaLimit,
|
|
89
|
+
] = await Promise.all([
|
|
90
|
+
rollup.getL1StartBlock(),
|
|
91
|
+
rollup.getL1GenesisTime(),
|
|
92
|
+
rollup.getProofSubmissionEpochs(),
|
|
93
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
94
|
+
rollup.getSlashingProposerAddress(),
|
|
95
|
+
rollup.getTargetCommitteeSize(),
|
|
96
|
+
rollup.getManaLimit(),
|
|
97
|
+
] as const);
|
|
88
98
|
|
|
89
99
|
const l1StartBlockHash = await publicClient
|
|
90
100
|
.getBlock({ blockNumber: l1StartBlock, includeTransactions: false })
|
|
@@ -100,7 +110,9 @@ export async function createArchiver(
|
|
|
100
110
|
slotDuration,
|
|
101
111
|
ethereumSlotDuration,
|
|
102
112
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
113
|
+
targetCommitteeSize,
|
|
103
114
|
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
|
|
115
|
+
rollupManaLimit: Number(rollupManaLimit),
|
|
104
116
|
};
|
|
105
117
|
|
|
106
118
|
const archiverConfig = merge(
|
|
@@ -120,13 +132,15 @@ export async function createArchiver(
|
|
|
120
132
|
// Create the event emitter that will be shared by archiver and synchronizer
|
|
121
133
|
const events = new EventEmitter() as ArchiverEmitter;
|
|
122
134
|
|
|
135
|
+
// Create L2 tips cache shared by archiver and synchronizer
|
|
136
|
+
const l2TipsCache = new L2TipsCache(archiverStore.blockStore);
|
|
137
|
+
|
|
123
138
|
// Create the L1 synchronizer
|
|
124
139
|
const synchronizer = new ArchiverL1Synchronizer(
|
|
125
140
|
publicClient,
|
|
126
141
|
debugClient,
|
|
127
142
|
rollup,
|
|
128
143
|
inbox,
|
|
129
|
-
{ ...config.l1Contracts, slashingProposerAddress },
|
|
130
144
|
archiverStore,
|
|
131
145
|
archiverConfig,
|
|
132
146
|
deps.blobClient,
|
|
@@ -136,6 +150,8 @@ export async function createArchiver(
|
|
|
136
150
|
l1Constants,
|
|
137
151
|
events,
|
|
138
152
|
instrumentation.tracer,
|
|
153
|
+
l2TipsCache,
|
|
154
|
+
undefined, // log (use default)
|
|
139
155
|
);
|
|
140
156
|
|
|
141
157
|
const archiver = new Archiver(
|
|
@@ -150,6 +166,7 @@ export async function createArchiver(
|
|
|
150
166
|
l1Constants,
|
|
151
167
|
synchronizer,
|
|
152
168
|
events,
|
|
169
|
+
l2TipsCache,
|
|
153
170
|
);
|
|
154
171
|
|
|
155
172
|
await archiver.start(opts.blockUntilSync);
|
package/src/index.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './config.js';
|
|
|
8
8
|
export { type L1PublishedData } from './structs/published.js';
|
|
9
9
|
export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_store.js';
|
|
10
10
|
export { ContractInstanceStore } from './store/contract_instance_store.js';
|
|
11
|
+
export { L2TipsCache } from './store/l2_tips_cache.js';
|
|
11
12
|
|
|
12
13
|
export { retrieveCheckpointsFromRollup, retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
|