@aztec/archiver 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c
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 +7 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +60 -22
- 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 +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 +24 -21
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +3 -3
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +14 -15
- package/dest/modules/data_source_base.d.ts +8 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +11 -5
- package/dest/modules/data_store_updater.d.ts +18 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +87 -77
- package/dest/modules/l1_synchronizer.d.ts +4 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +163 -128
- 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 +50 -16
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +288 -119
- 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 +45 -22
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +57 -27
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +25 -5
- 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 +93 -16
- 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 +16 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +77 -8
- 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 +10 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +35 -7
- 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 +73 -27
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +23 -15
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +8 -12
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +96 -107
- package/src/modules/l1_synchronizer.ts +182 -157
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +370 -140
- 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 +81 -39
- package/src/store/l2_tips_cache.ts +50 -11
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +103 -13
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +52 -5
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -2
package/src/archiver.ts
CHANGED
|
@@ -19,19 +19,18 @@ import {
|
|
|
19
19
|
type L2Tips,
|
|
20
20
|
type ValidateCheckpointResult,
|
|
21
21
|
} from '@aztec/stdlib/block';
|
|
22
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
22
|
+
import { type ProposedCheckpointInput, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
23
23
|
import {
|
|
24
24
|
type L1RollupConstants,
|
|
25
|
-
|
|
25
|
+
getEpochAtSlot,
|
|
26
26
|
getSlotAtNextL1Block,
|
|
27
|
-
getSlotAtTimestamp,
|
|
28
27
|
getSlotRangeForEpoch,
|
|
29
28
|
getTimestampRangeForEpoch,
|
|
30
29
|
} from '@aztec/stdlib/epoch-helpers';
|
|
31
30
|
import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
32
31
|
|
|
33
32
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
34
|
-
import { NoBlobBodiesFoundError } from './errors.js';
|
|
33
|
+
import { BlockAlreadyCheckpointedError, NoBlobBodiesFoundError } from './errors.js';
|
|
35
34
|
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
36
35
|
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
37
36
|
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
@@ -92,11 +91,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
92
91
|
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
93
92
|
* @param rollup - Rollup contract instance.
|
|
94
93
|
* @param inbox - Inbox contract instance.
|
|
95
|
-
* @param l1Addresses - L1 contract addresses (registry, governance proposer,
|
|
94
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
96
95
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
97
96
|
* @param config - Archiver configuration options.
|
|
98
97
|
* @param blobClient - Client for retrieving blob data.
|
|
99
|
-
* @param epochCache - Cache for epoch-related data.
|
|
100
98
|
* @param dateProvider - Provider for current date/time.
|
|
101
99
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
102
100
|
* @param l1Constants - L1 rollup constants.
|
|
@@ -106,10 +104,9 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
106
104
|
private readonly publicClient: ViemPublicClient,
|
|
107
105
|
private readonly debugClient: ViemPublicDebugClient,
|
|
108
106
|
private readonly rollup: RollupContract,
|
|
109
|
-
private readonly l1Addresses: Pick<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
> & { slashingProposerAddress: EthAddress },
|
|
107
|
+
private readonly l1Addresses: Pick<L1ContractAddresses, 'registryAddress' | 'governanceProposerAddress'> & {
|
|
108
|
+
slashingProposerAddress: EthAddress;
|
|
109
|
+
},
|
|
113
110
|
readonly dataStore: KVArchiverDataStore,
|
|
114
111
|
private config: {
|
|
115
112
|
pollingIntervalMs: number;
|
|
@@ -120,7 +117,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
120
117
|
},
|
|
121
118
|
private readonly blobClient: BlobClientInterface,
|
|
122
119
|
instrumentation: ArchiverInstrumentation,
|
|
123
|
-
protected override readonly l1Constants: L1RollupConstants & {
|
|
120
|
+
protected override readonly l1Constants: L1RollupConstants & {
|
|
121
|
+
l1StartBlockHash: Buffer32;
|
|
122
|
+
genesisArchiveRoot: Fr;
|
|
123
|
+
},
|
|
124
124
|
synchronizer: ArchiverL1Synchronizer,
|
|
125
125
|
events: ArchiverEmitter,
|
|
126
126
|
l2TipsCache?: L2TipsCache,
|
|
@@ -133,7 +133,9 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
133
133
|
this.synchronizer = synchronizer;
|
|
134
134
|
this.events = events;
|
|
135
135
|
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
136
|
-
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache
|
|
136
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache, {
|
|
137
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
138
|
+
});
|
|
137
139
|
|
|
138
140
|
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
139
141
|
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
@@ -206,6 +208,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
206
208
|
});
|
|
207
209
|
}
|
|
208
210
|
|
|
211
|
+
public async setProposedCheckpoint(pending: ProposedCheckpointInput): Promise<void> {
|
|
212
|
+
await this.updater.setProposedCheckpoint(pending);
|
|
213
|
+
}
|
|
214
|
+
|
|
209
215
|
/**
|
|
210
216
|
* Processes all queued blocks, adding them to the store.
|
|
211
217
|
* Called at the beginning of each sync iteration.
|
|
@@ -238,10 +244,15 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
238
244
|
}
|
|
239
245
|
|
|
240
246
|
try {
|
|
241
|
-
await this.updater.
|
|
247
|
+
await this.updater.addProposedBlock(block);
|
|
242
248
|
this.log.debug(`Added block ${block.number} to store`);
|
|
243
249
|
resolve();
|
|
244
250
|
} catch (err: any) {
|
|
251
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
252
|
+
this.log.debug(`Proposed block ${block.number} matches already checkpointed block, ignoring late proposal`);
|
|
253
|
+
resolve();
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
245
256
|
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
246
257
|
reject(err);
|
|
247
258
|
}
|
|
@@ -333,16 +344,49 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
333
344
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
334
345
|
}
|
|
335
346
|
|
|
336
|
-
public
|
|
347
|
+
public async getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
348
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
349
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
350
|
+
// we have seen the corresponding checkpoint.
|
|
351
|
+
|
|
352
|
+
let slotFromL1Sync: SlotNumber | undefined;
|
|
337
353
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
338
|
-
|
|
354
|
+
if (l1Timestamp !== undefined) {
|
|
355
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
356
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
357
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let slotFromCheckpoint: SlotNumber | undefined;
|
|
362
|
+
const latestCheckpointNumber = await this.store.getSynchedCheckpointNumber();
|
|
363
|
+
if (latestCheckpointNumber > 0) {
|
|
364
|
+
const checkpointData = await this.store.getCheckpointData(latestCheckpointNumber);
|
|
365
|
+
if (checkpointData) {
|
|
366
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
339
374
|
}
|
|
340
375
|
|
|
341
|
-
public
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
376
|
+
public async getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
377
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
378
|
+
if (syncedSlot === undefined) {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
// An epoch is fully synced when all its slots are synced.
|
|
382
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
383
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
384
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
385
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
386
|
+
if (syncedSlot >= endSlot) {
|
|
387
|
+
return epoch;
|
|
388
|
+
}
|
|
389
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
346
390
|
}
|
|
347
391
|
|
|
348
392
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -445,16 +489,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
445
489
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
446
490
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
447
491
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
448
|
-
await this.store.
|
|
492
|
+
await this.store.setMessageSyncState(
|
|
493
|
+
{ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash },
|
|
494
|
+
undefined,
|
|
495
|
+
);
|
|
449
496
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
450
497
|
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
451
498
|
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
452
499
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
// }
|
|
500
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
501
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
502
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
503
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
504
|
+
}
|
|
459
505
|
}
|
|
460
506
|
}
|
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
|
|
|
@@ -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,
|
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,18 +8,17 @@ 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
|
-
import { type
|
|
17
|
-
import type {
|
|
16
|
+
import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
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';
|
|
@@ -32,14 +32,13 @@ export const ARCHIVER_STORE_NAME = 'archiver';
|
|
|
32
32
|
/** Creates an archiver store. */
|
|
33
33
|
export async function createArchiverStore(
|
|
34
34
|
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
|
|
35
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
36
35
|
) {
|
|
37
36
|
const config = {
|
|
38
37
|
...userConfig,
|
|
39
38
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
40
39
|
};
|
|
41
40
|
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
42
|
-
return new KVArchiverDataStore(store, config.maxLogs
|
|
41
|
+
return new KVArchiverDataStore(store, config.maxLogs);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -54,14 +53,15 @@ export async function createArchiver(
|
|
|
54
53
|
deps: ArchiverDeps,
|
|
55
54
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
56
55
|
): Promise<Archiver> {
|
|
57
|
-
const archiverStore = await createArchiverStore(config
|
|
56
|
+
const archiverStore = await createArchiverStore(config);
|
|
58
57
|
await registerProtocolContracts(archiverStore);
|
|
59
58
|
|
|
60
59
|
// Create Ethereum clients
|
|
61
60
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
61
|
+
const httpTimeout = config.l1HttpTimeoutMS;
|
|
62
62
|
const publicClient = createPublicClient({
|
|
63
63
|
chain: chain.chainInfo,
|
|
64
|
-
transport:
|
|
64
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
|
|
65
65
|
pollingInterval: config.viemPollingIntervalMS,
|
|
66
66
|
});
|
|
67
67
|
|
|
@@ -69,7 +69,7 @@ export async function createArchiver(
|
|
|
69
69
|
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
|
|
70
70
|
const debugClient = createPublicClient({
|
|
71
71
|
chain: chain.chainInfo,
|
|
72
|
-
transport:
|
|
72
|
+
transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
|
|
73
73
|
pollingInterval: config.viemPollingIntervalMS,
|
|
74
74
|
}) as ViemPublicDebugClient;
|
|
75
75
|
|
|
@@ -85,6 +85,7 @@ export async function createArchiver(
|
|
|
85
85
|
genesisArchiveRoot,
|
|
86
86
|
slashingProposerAddress,
|
|
87
87
|
targetCommitteeSize,
|
|
88
|
+
rollupManaLimit,
|
|
88
89
|
] = await Promise.all([
|
|
89
90
|
rollup.getL1StartBlock(),
|
|
90
91
|
rollup.getL1GenesisTime(),
|
|
@@ -92,6 +93,7 @@ export async function createArchiver(
|
|
|
92
93
|
rollup.getGenesisArchiveTreeRoot(),
|
|
93
94
|
rollup.getSlashingProposerAddress(),
|
|
94
95
|
rollup.getTargetCommitteeSize(),
|
|
96
|
+
rollup.getManaLimit(),
|
|
95
97
|
] as const);
|
|
96
98
|
|
|
97
99
|
const l1StartBlockHash = await publicClient
|
|
@@ -110,6 +112,7 @@ export async function createArchiver(
|
|
|
110
112
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
111
113
|
targetCommitteeSize,
|
|
112
114
|
genesisArchiveRoot: Fr.fromString(genesisArchiveRoot.toString()),
|
|
115
|
+
rollupManaLimit: Number(rollupManaLimit),
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
const archiverConfig = merge(
|
|
@@ -170,16 +173,22 @@ export async function createArchiver(
|
|
|
170
173
|
return archiver;
|
|
171
174
|
}
|
|
172
175
|
|
|
173
|
-
/** Registers protocol contracts in the archiver store. */
|
|
176
|
+
/** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
|
|
174
177
|
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
175
178
|
const blockNumber = 0;
|
|
176
179
|
for (const name of protocolContractNames) {
|
|
177
180
|
const provider = new BundledProtocolContractsProvider();
|
|
178
181
|
const contract = await provider.getProtocolContractArtifact(name);
|
|
179
|
-
|
|
182
|
+
|
|
183
|
+
// Skip if already registered (happens on node restart with a persisted store).
|
|
184
|
+
if (await store.getContractClass(contract.contractClass.id)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
|
|
189
|
+
const contractClassPublic: ContractClassPublicWithCommitment = {
|
|
180
190
|
...contract.contractClass,
|
|
181
|
-
|
|
182
|
-
utilityFunctions: [],
|
|
191
|
+
publicBytecodeCommitment,
|
|
183
192
|
};
|
|
184
193
|
|
|
185
194
|
const publicFunctionSignatures = contract.artifact.functions
|
|
@@ -187,8 +196,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
187
196
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
188
197
|
|
|
189
198
|
await store.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
190
|
-
|
|
191
|
-
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
|
|
199
|
+
await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
|
|
192
200
|
await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
193
201
|
}
|
|
194
202
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MULTI_CALL_3_ADDRESS, type ViemCommitteeAttestations, type ViemHeader } from '@aztec/ethereum/contracts';
|
|
2
2
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
3
3
|
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { LruSet } from '@aztec/foundation/collection';
|
|
4
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
@@ -44,7 +45,7 @@ type CheckpointData = {
|
|
|
44
45
|
*/
|
|
45
46
|
export class CalldataRetriever {
|
|
46
47
|
/** Tx hashes we've already logged for trace+debug failure (log once per tx per process). */
|
|
47
|
-
private static readonly traceFailureWarnedTxHashes = new
|
|
48
|
+
private static readonly traceFailureWarnedTxHashes = new LruSet<string>(1000);
|
|
48
49
|
|
|
49
50
|
/** Clears the trace-failure warned set. For testing only. */
|
|
50
51
|
static resetTraceFailureWarnedForTesting(): void {
|
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -144,7 +144,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
144
144
|
* @param blobClient - The blob client client for fetching blob data.
|
|
145
145
|
* @param searchStartBlock - The block number to use for starting the search.
|
|
146
146
|
* @param searchEndBlock - The highest block number that we should search up to.
|
|
147
|
-
* @param contractAddresses - The contract addresses (governanceProposerAddress,
|
|
147
|
+
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashingProposerAddress).
|
|
148
148
|
* @param instrumentation - The archiver instrumentation instance.
|
|
149
149
|
* @param logger - The logger instance.
|
|
150
150
|
* @param isHistoricalSync - Whether this is a historical sync.
|
|
@@ -344,14 +344,10 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
344
344
|
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
|
|
345
345
|
export async function retrieveL1ToL2Message(
|
|
346
346
|
inbox: InboxContract,
|
|
347
|
-
|
|
348
|
-
fromBlock: bigint,
|
|
349
|
-
toBlock: bigint,
|
|
347
|
+
message: InboxMessage,
|
|
350
348
|
): Promise<InboxMessage | undefined> {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
const messages = mapLogsInboxMessage(logs);
|
|
354
|
-
return messages.length > 0 ? messages[0] : undefined;
|
|
349
|
+
const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockHash.toString());
|
|
350
|
+
return log && mapLogInboxMessage(log);
|
|
355
351
|
}
|
|
356
352
|
|
|
357
353
|
/**
|
|
@@ -374,22 +370,22 @@ export async function retrieveL1ToL2Messages(
|
|
|
374
370
|
break;
|
|
375
371
|
}
|
|
376
372
|
|
|
377
|
-
retrievedL1ToL2Messages.push(...
|
|
373
|
+
retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
|
|
378
374
|
searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
|
|
379
375
|
}
|
|
380
376
|
|
|
381
377
|
return retrievedL1ToL2Messages;
|
|
382
378
|
}
|
|
383
379
|
|
|
384
|
-
function
|
|
385
|
-
return
|
|
380
|
+
function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
|
|
381
|
+
return {
|
|
386
382
|
index: log.args.index,
|
|
387
383
|
leaf: log.args.leaf,
|
|
388
384
|
l1BlockNumber: log.l1BlockNumber,
|
|
389
385
|
l1BlockHash: log.l1BlockHash,
|
|
390
386
|
checkpointNumber: log.args.checkpointNumber,
|
|
391
387
|
rollingHash: log.args.rollingHash,
|
|
392
|
-
}
|
|
388
|
+
};
|
|
393
389
|
}
|
|
394
390
|
|
|
395
391
|
/** Retrieves L2ProofVerified events from the rollup contract. */
|
|
@@ -6,7 +6,13 @@ import { isDefined } from '@aztec/foundation/types';
|
|
|
6
6
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
7
7
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
8
|
import { type BlockData, type BlockHash, CheckpointedL2Block, L2Block, type L2Tips } from '@aztec/stdlib/block';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Checkpoint,
|
|
11
|
+
type CheckpointData,
|
|
12
|
+
type CommonCheckpointData,
|
|
13
|
+
type ProposedCheckpointData,
|
|
14
|
+
PublishedCheckpoint,
|
|
15
|
+
} from '@aztec/stdlib/checkpoint';
|
|
10
16
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
11
17
|
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
12
18
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -46,9 +52,9 @@ export abstract class ArchiverDataSourceBase
|
|
|
46
52
|
|
|
47
53
|
abstract getL2Tips(): Promise<L2Tips>;
|
|
48
54
|
|
|
49
|
-
abstract
|
|
55
|
+
abstract getSyncedL2SlotNumber(): Promise<SlotNumber | undefined>;
|
|
50
56
|
|
|
51
|
-
abstract
|
|
57
|
+
abstract getSyncedL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
52
58
|
|
|
53
59
|
abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
|
|
54
60
|
|
|
@@ -154,7 +160,15 @@ export abstract class ArchiverDataSourceBase
|
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
157
|
-
return this.store.getSettledTxReceipt(txHash);
|
|
163
|
+
return this.store.getSettledTxReceipt(txHash, this.l1Constants);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
167
|
+
return this.store.getProposedCheckpoint();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
171
|
+
return this.store.getProposedCheckpointOnly();
|
|
158
172
|
}
|
|
159
173
|
|
|
160
174
|
public isPendingChainInvalid(): Promise<boolean> {
|
|
@@ -165,16 +179,21 @@ export abstract class ArchiverDataSourceBase
|
|
|
165
179
|
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
166
180
|
}
|
|
167
181
|
|
|
168
|
-
public getPrivateLogsByTags(
|
|
169
|
-
|
|
182
|
+
public getPrivateLogsByTags(
|
|
183
|
+
tags: SiloedTag[],
|
|
184
|
+
page?: number,
|
|
185
|
+
upToBlockNumber?: BlockNumber,
|
|
186
|
+
): Promise<TxScopedL2Log[][]> {
|
|
187
|
+
return this.store.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
170
188
|
}
|
|
171
189
|
|
|
172
190
|
public getPublicLogsByTagsFromContract(
|
|
173
191
|
contractAddress: AztecAddress,
|
|
174
192
|
tags: Tag[],
|
|
175
193
|
page?: number,
|
|
194
|
+
upToBlockNumber?: BlockNumber,
|
|
176
195
|
): Promise<TxScopedL2Log[][]> {
|
|
177
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
196
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
178
197
|
}
|
|
179
198
|
|
|
180
199
|
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|