@aztec/archiver 0.0.1-commit.d117d021b → 0.0.1-commit.d1da697d6
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 +5 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +56 -20
- 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 +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -18
- 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 +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -14
- 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 +14 -11
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +78 -76
- package/dest/modules/l1_synchronizer.d.ts +4 -3
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +160 -127
- 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 +20 -8
- 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 +9 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +32 -7
- 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 +62 -21
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +19 -14
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +7 -11
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +91 -107
- package/src/modules/l1_synchronizer.ts +174 -156
- 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 +26 -9
- 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 +46 -5
- package/src/test/noop_l1_archiver.ts +7 -1
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';
|
|
@@ -96,7 +95,6 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
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.
|
|
@@ -123,7 +121,6 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
123
121
|
protected override readonly l1Constants: L1RollupConstants & {
|
|
124
122
|
l1StartBlockHash: Buffer32;
|
|
125
123
|
genesisArchiveRoot: Fr;
|
|
126
|
-
rollupManaLimit?: number;
|
|
127
124
|
},
|
|
128
125
|
synchronizer: ArchiverL1Synchronizer,
|
|
129
126
|
events: ArchiverEmitter,
|
|
@@ -212,6 +209,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
212
209
|
});
|
|
213
210
|
}
|
|
214
211
|
|
|
212
|
+
public async setProposedCheckpoint(pending: ProposedCheckpointInput): Promise<void> {
|
|
213
|
+
await this.updater.setProposedCheckpoint(pending);
|
|
214
|
+
}
|
|
215
|
+
|
|
215
216
|
/**
|
|
216
217
|
* Processes all queued blocks, adding them to the store.
|
|
217
218
|
* Called at the beginning of each sync iteration.
|
|
@@ -244,10 +245,15 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
try {
|
|
247
|
-
await this.updater.
|
|
248
|
+
await this.updater.addProposedBlock(block);
|
|
248
249
|
this.log.debug(`Added block ${block.number} to store`);
|
|
249
250
|
resolve();
|
|
250
251
|
} catch (err: any) {
|
|
252
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
253
|
+
this.log.debug(`Proposed block ${block.number} matches already checkpointed block, ignoring late proposal`);
|
|
254
|
+
resolve();
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
251
257
|
this.log.error(`Failed to add block ${block.number} to store: ${err.message}`);
|
|
252
258
|
reject(err);
|
|
253
259
|
}
|
|
@@ -339,16 +345,49 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
339
345
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
340
346
|
}
|
|
341
347
|
|
|
342
|
-
public
|
|
348
|
+
public async getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
349
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
350
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
351
|
+
// we have seen the corresponding checkpoint.
|
|
352
|
+
|
|
353
|
+
let slotFromL1Sync: SlotNumber | undefined;
|
|
343
354
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
344
|
-
|
|
355
|
+
if (l1Timestamp !== undefined) {
|
|
356
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
357
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
358
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
let slotFromCheckpoint: SlotNumber | undefined;
|
|
363
|
+
const latestCheckpointNumber = await this.store.getSynchedCheckpointNumber();
|
|
364
|
+
if (latestCheckpointNumber > 0) {
|
|
365
|
+
const checkpointData = await this.store.getCheckpointData(latestCheckpointNumber);
|
|
366
|
+
if (checkpointData) {
|
|
367
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
345
375
|
}
|
|
346
376
|
|
|
347
|
-
public
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
377
|
+
public async getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
378
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
379
|
+
if (syncedSlot === undefined) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
// An epoch is fully synced when all its slots are synced.
|
|
383
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
384
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
385
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
386
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
387
|
+
if (syncedSlot >= endSlot) {
|
|
388
|
+
return epoch;
|
|
389
|
+
}
|
|
390
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
352
391
|
}
|
|
353
392
|
|
|
354
393
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -451,16 +490,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
451
490
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
452
491
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
453
492
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
454
|
-
await this.store.
|
|
493
|
+
await this.store.setMessageSyncState(
|
|
494
|
+
{ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash },
|
|
495
|
+
undefined,
|
|
496
|
+
);
|
|
455
497
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
456
498
|
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
457
499
|
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
458
500
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
// }
|
|
501
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
502
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
503
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
504
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
505
|
+
}
|
|
465
506
|
}
|
|
466
507
|
}
|
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';
|
|
@@ -12,13 +13,12 @@ import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
|
12
13
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
13
14
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
14
15
|
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
15
|
-
import { type
|
|
16
|
-
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
16
|
+
import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
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
|
|
|
@@ -173,16 +173,22 @@ export async function createArchiver(
|
|
|
173
173
|
return archiver;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
/** 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). */
|
|
177
177
|
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
178
178
|
const blockNumber = 0;
|
|
179
179
|
for (const name of protocolContractNames) {
|
|
180
180
|
const provider = new BundledProtocolContractsProvider();
|
|
181
181
|
const contract = await provider.getProtocolContractArtifact(name);
|
|
182
|
-
|
|
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 = {
|
|
183
190
|
...contract.contractClass,
|
|
184
|
-
|
|
185
|
-
utilityFunctions: [],
|
|
191
|
+
publicBytecodeCommitment,
|
|
186
192
|
};
|
|
187
193
|
|
|
188
194
|
const publicFunctionSignatures = contract.artifact.functions
|
|
@@ -190,8 +196,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
190
196
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
191
197
|
|
|
192
198
|
await store.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
193
|
-
|
|
194
|
-
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
|
|
199
|
+
await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
|
|
195
200
|
await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
196
201
|
}
|
|
197
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
|
@@ -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> {
|