@aztec/archiver 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
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 +7 -5
- package/dest/archiver.d.ts +49 -14
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +216 -68
- package/dest/config.d.ts +4 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +11 -16
- package/dest/errors.d.ts +19 -13
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +32 -16
- package/dest/factory.d.ts +12 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +31 -21
- package/dest/index.d.ts +9 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -1
- package/dest/l1/calldata_retriever.d.ts +2 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +13 -4
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +71 -49
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +269 -143
- package/dest/modules/data_store_updater.d.ts +18 -6
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +108 -59
- package/dest/modules/instrumentation.js +3 -1
- package/dest/modules/l1_synchronizer.d.ts +6 -5
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +203 -100
- package/dest/modules/outbox_trees_resolver.d.ts +62 -0
- package/dest/modules/outbox_trees_resolver.d.ts.map +1 -0
- package/dest/modules/outbox_trees_resolver.js +162 -0
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +4 -4
- package/dest/store/block_store.d.ts +155 -98
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +473 -265
- package/dest/store/contract_class_store.d.ts +17 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +17 -1
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +31 -0
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +13 -8
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +13 -96
- package/dest/store/log_store.d.ts +42 -40
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +257 -478
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +9 -3
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +31 -1
- package/dest/test/fake_l1_state.d.ts +2 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +25 -8
- package/dest/test/mock_l2_block_source.d.ts +47 -51
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +223 -185
- package/dest/test/noop_l1_archiver.d.ts +10 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +19 -8
- package/package.json +14 -14
- package/src/archiver.ts +265 -72
- package/src/config.ts +12 -19
- package/src/errors.ts +46 -23
- package/src/factory.ts +38 -20
- package/src/index.ts +16 -1
- package/src/l1/calldata_retriever.ts +14 -4
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +335 -187
- package/src/modules/data_store_updater.ts +118 -61
- package/src/modules/instrumentation.ts +1 -1
- package/src/modules/l1_synchronizer.ts +278 -120
- package/src/modules/outbox_trees_resolver.ts +199 -0
- package/src/modules/validation.ts +8 -7
- package/src/store/block_store.ts +566 -323
- package/src/store/contract_class_store.ts +28 -2
- package/src/store/contract_instance_store.ts +43 -0
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +16 -115
- package/src/store/log_store.ts +296 -650
- package/src/store/log_store_codec.ts +132 -0
- package/src/store/message_store.ts +35 -2
- package/src/test/fake_l1_state.ts +24 -14
- package/src/test/mock_l2_block_source.ts +271 -239
- package/src/test/noop_l1_archiver.ts +39 -8
- package/dest/store/kv_archiver_store.d.ts +0 -383
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -501
- package/src/store/kv_archiver_store.ts +0 -728
package/src/errors.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import type { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { Fr } from '@aztec/foundation/schemas';
|
|
2
3
|
|
|
3
4
|
export class NoBlobBodiesFoundError extends Error {
|
|
4
5
|
constructor(l2BlockNum: number) {
|
|
5
6
|
super(`No blob bodies found for block ${l2BlockNum}`);
|
|
7
|
+
this.name = 'NoBlobBodiesFoundError';
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export class BlockNumberNotSequentialError extends Error {
|
|
10
12
|
constructor(newBlockNumber: number, previous: number | undefined) {
|
|
11
13
|
super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
|
|
14
|
+
this.name = 'BlockNumberNotSequentialError';
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -22,18 +25,35 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
|
|
|
22
25
|
previousCheckpointNumber ?? 'undefined'
|
|
23
26
|
}`,
|
|
24
27
|
);
|
|
28
|
+
this.name = 'InitialCheckpointNumberNotSequentialError';
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export class CheckpointNumberNotSequentialError extends Error {
|
|
29
33
|
constructor(
|
|
30
|
-
newCheckpointNumber:
|
|
31
|
-
|
|
32
|
-
source
|
|
34
|
+
public readonly newCheckpointNumber: CheckpointNumber,
|
|
35
|
+
public readonly previousCheckpointNumber: CheckpointNumber | undefined,
|
|
36
|
+
source?: 'proposed' | 'confirmed',
|
|
33
37
|
) {
|
|
38
|
+
const qualifier = source ? `${source} ` : '';
|
|
34
39
|
super(
|
|
35
|
-
`Cannot insert new checkpoint ${newCheckpointNumber} given previous ${
|
|
40
|
+
`Cannot insert new checkpoint ${newCheckpointNumber} given previous ${qualifier}checkpoint number is ${previousCheckpointNumber ?? 'undefined'}`,
|
|
36
41
|
);
|
|
42
|
+
this.name = 'CheckpointNumberNotSequentialError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Thrown when a proposed block carries a checkpoint number that does not follow the latest one. */
|
|
47
|
+
export class BlockCheckpointNumberNotSequentialError extends Error {
|
|
48
|
+
constructor(
|
|
49
|
+
blockNumber: BlockNumber,
|
|
50
|
+
blockCheckpointNumber: CheckpointNumber,
|
|
51
|
+
previous: CheckpointNumber | undefined,
|
|
52
|
+
) {
|
|
53
|
+
super(
|
|
54
|
+
`Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
|
|
55
|
+
);
|
|
56
|
+
this.name = 'BlockCheckpointNumberNotSequentialError';
|
|
37
57
|
}
|
|
38
58
|
}
|
|
39
59
|
|
|
@@ -42,6 +62,7 @@ export class BlockIndexNotSequentialError extends Error {
|
|
|
42
62
|
super(
|
|
43
63
|
`Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
|
|
44
64
|
);
|
|
65
|
+
this.name = 'BlockIndexNotSequentialError';
|
|
45
66
|
}
|
|
46
67
|
}
|
|
47
68
|
|
|
@@ -55,18 +76,21 @@ export class BlockArchiveNotConsistentError extends Error {
|
|
|
55
76
|
super(
|
|
56
77
|
`Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
|
|
57
78
|
);
|
|
79
|
+
this.name = 'BlockArchiveNotConsistentError';
|
|
58
80
|
}
|
|
59
81
|
}
|
|
60
82
|
|
|
61
83
|
export class CheckpointNotFoundError extends Error {
|
|
62
84
|
constructor(checkpointNumber: number) {
|
|
63
85
|
super(`Failed to find expected checkpoint number ${checkpointNumber}`);
|
|
86
|
+
this.name = 'CheckpointNotFoundError';
|
|
64
87
|
}
|
|
65
88
|
}
|
|
66
89
|
|
|
67
90
|
export class BlockNotFoundError extends Error {
|
|
68
91
|
constructor(blockNumber: number) {
|
|
69
92
|
super(`Failed to find expected block number ${blockNumber}`);
|
|
93
|
+
this.name = 'BlockNotFoundError';
|
|
70
94
|
}
|
|
71
95
|
}
|
|
72
96
|
|
|
@@ -78,22 +102,6 @@ export class BlockAlreadyCheckpointedError extends Error {
|
|
|
78
102
|
}
|
|
79
103
|
}
|
|
80
104
|
|
|
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
105
|
/** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
|
|
98
106
|
export class L1ToL2MessagesNotReadyError extends Error {
|
|
99
107
|
constructor(
|
|
@@ -119,19 +127,34 @@ export class ProposedCheckpointStaleError extends Error {
|
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
/** Thrown when a proposed checkpoint number is not the expected
|
|
130
|
+
/** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
|
|
123
131
|
export class ProposedCheckpointNotSequentialError extends Error {
|
|
124
132
|
constructor(
|
|
125
133
|
public readonly proposedCheckpointNumber: number,
|
|
126
|
-
public readonly
|
|
134
|
+
public readonly latestTipNumber: number,
|
|
127
135
|
) {
|
|
128
136
|
super(
|
|
129
|
-
`Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${
|
|
137
|
+
`Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
|
|
130
138
|
);
|
|
131
139
|
this.name = 'ProposedCheckpointNotSequentialError';
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
142
|
|
|
143
|
+
/** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
|
|
144
|
+
export class BlockOrCheckpointSlotExpiredError extends Error {
|
|
145
|
+
constructor(
|
|
146
|
+
public readonly slot: number,
|
|
147
|
+
public readonly nextSlotStart: bigint,
|
|
148
|
+
public readonly l1TimestampSynced: bigint | undefined,
|
|
149
|
+
) {
|
|
150
|
+
super(
|
|
151
|
+
`Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
|
|
152
|
+
`If the checkpoint still lands via a late L1 tx, the archiver will pick it up via normal L1-sync (not the pending-queue shortcut).`,
|
|
153
|
+
);
|
|
154
|
+
this.name = 'BlockOrCheckpointSlotExpiredError';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
135
158
|
/** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
|
|
136
159
|
export class NoProposedCheckpointToPromoteError extends Error {
|
|
137
160
|
constructor() {
|
package/src/factory.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
2
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
3
3
|
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
4
|
-
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import { InboxContract, OutboxContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
5
6
|
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
6
7
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
@@ -12,9 +13,11 @@ import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
|
12
13
|
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
13
14
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
14
15
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
15
|
-
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
16
|
+
import type { ArchiverEmitter, BlockHash } from '@aztec/stdlib/block';
|
|
16
17
|
import { type ContractClassPublicWithCommitment, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
18
|
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
19
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
20
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
18
21
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
19
22
|
|
|
20
23
|
import { EventEmitter } from 'events';
|
|
@@ -24,21 +27,22 @@ import { Archiver, type ArchiverDeps } from './archiver.js';
|
|
|
24
27
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
25
28
|
import { ArchiverInstrumentation } from './modules/instrumentation.js';
|
|
26
29
|
import { ArchiverL1Synchronizer } from './modules/l1_synchronizer.js';
|
|
27
|
-
import { ARCHIVER_DB_VERSION,
|
|
30
|
+
import { ARCHIVER_DB_VERSION, type ArchiverDataStores, createArchiverDataStores } from './store/data_stores.js';
|
|
28
31
|
import { L2TipsCache } from './store/l2_tips_cache.js';
|
|
29
32
|
|
|
30
33
|
export const ARCHIVER_STORE_NAME = 'archiver';
|
|
31
34
|
|
|
32
35
|
/** Creates an archiver store. */
|
|
33
36
|
export async function createArchiverStore(
|
|
34
|
-
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb'
|
|
35
|
-
|
|
37
|
+
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb'> & DataStoreConfig,
|
|
38
|
+
genesisBlockHash: BlockHash,
|
|
39
|
+
): Promise<ArchiverDataStores> {
|
|
36
40
|
const config = {
|
|
37
41
|
...userConfig,
|
|
38
42
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
39
43
|
};
|
|
40
44
|
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
41
|
-
return
|
|
45
|
+
return createArchiverDataStores(store, genesisBlockHash);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/**
|
|
@@ -46,14 +50,19 @@ export async function createArchiverStore(
|
|
|
46
50
|
* @param config - The archiver configuration.
|
|
47
51
|
* @param deps - The archiver dependencies (blobClient, epochCache, dateProvider, telemetry).
|
|
48
52
|
* @param opts - The options.
|
|
53
|
+
* @param initialHeader - The genesis block header from world-state, used to answer block-0 queries.
|
|
54
|
+
* @param initialBlockHash - Precomputed hash of `initialHeader`. Hoisted to the caller so the archiver
|
|
55
|
+
* can expose `getGenesisBlockHash()` synchronously.
|
|
49
56
|
* @returns The local archiver.
|
|
50
57
|
*/
|
|
51
58
|
export async function createArchiver(
|
|
52
59
|
config: ArchiverConfig & DataStoreConfig,
|
|
53
60
|
deps: ArchiverDeps,
|
|
54
|
-
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
61
|
+
opts: { blockUntilSync: boolean; enableOrphanProposedBlockPruning?: boolean } = { blockUntilSync: true },
|
|
62
|
+
initialHeader: BlockHeader,
|
|
63
|
+
initialBlockHash: BlockHash,
|
|
55
64
|
): Promise<Archiver> {
|
|
56
|
-
const archiverStore = await createArchiverStore(config);
|
|
65
|
+
const archiverStore = await createArchiverStore(config, initialBlockHash);
|
|
57
66
|
await registerProtocolContracts(archiverStore);
|
|
58
67
|
|
|
59
68
|
// Create Ethereum clients
|
|
@@ -74,8 +83,9 @@ export async function createArchiver(
|
|
|
74
83
|
}) as ViemPublicDebugClient;
|
|
75
84
|
|
|
76
85
|
// Create L1 contract instances
|
|
77
|
-
const rollup = new RollupContract(publicClient, config.
|
|
78
|
-
const inbox = new InboxContract(publicClient, config.
|
|
86
|
+
const rollup = new RollupContract(publicClient, config.rollupAddress);
|
|
87
|
+
const inbox = new InboxContract(publicClient, config.inboxAddress);
|
|
88
|
+
const outbox = new OutboxContract(publicClient, config.outboxAddress);
|
|
79
89
|
|
|
80
90
|
// Fetch L1 constants from rollup contract
|
|
81
91
|
const [
|
|
@@ -122,19 +132,23 @@ export async function createArchiver(
|
|
|
122
132
|
maxAllowedEthClientDriftSeconds: 300,
|
|
123
133
|
ethereumAllowNoDebugHosts: false,
|
|
124
134
|
skipHistoricalLogsCheck: false,
|
|
135
|
+
orphanProposedBlockPruneGraceSeconds: MIN_EXECUTION_TIME,
|
|
136
|
+
enableOrphanProposedBlockPruning: opts.enableOrphanProposedBlockPruning ?? true,
|
|
125
137
|
},
|
|
126
138
|
mapArchiverConfig(config),
|
|
127
139
|
);
|
|
128
140
|
|
|
129
|
-
const epochCache = deps.epochCache ?? (await EpochCache.create(config.
|
|
141
|
+
const epochCache = deps.epochCache ?? (await EpochCache.create(config.rollupAddress, config, deps));
|
|
130
142
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
131
|
-
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.estimateSize());
|
|
143
|
+
const instrumentation = await ArchiverInstrumentation.new(telemetry, () => archiverStore.db.estimateSize());
|
|
132
144
|
|
|
133
145
|
// Create the event emitter that will be shared by archiver and synchronizer
|
|
134
146
|
const events = new EventEmitter() as ArchiverEmitter;
|
|
135
147
|
|
|
136
|
-
// Create L2 tips cache shared by archiver and synchronizer
|
|
137
|
-
|
|
148
|
+
// Create L2 tips cache shared by archiver and synchronizer. The genesis block hash is dynamic —
|
|
149
|
+
// it depends on the injected initial header (genesisTimestamp + prefilled state). Hoisted to the
|
|
150
|
+
// caller so we can pass the same value to the archiver and expose it via `getGenesisBlockHash()`.
|
|
151
|
+
const l2TipsCache = new L2TipsCache(archiverStore.blocks, initialBlockHash);
|
|
138
152
|
|
|
139
153
|
// Create the L1 synchronizer
|
|
140
154
|
const synchronizer = new ArchiverL1Synchronizer(
|
|
@@ -159,7 +173,8 @@ export async function createArchiver(
|
|
|
159
173
|
publicClient,
|
|
160
174
|
debugClient,
|
|
161
175
|
rollup,
|
|
162
|
-
|
|
176
|
+
outbox,
|
|
177
|
+
{ ...pickL1ContractAddresses(config), slashingProposerAddress },
|
|
163
178
|
archiverStore,
|
|
164
179
|
archiverConfig,
|
|
165
180
|
deps.blobClient,
|
|
@@ -167,7 +182,10 @@ export async function createArchiver(
|
|
|
167
182
|
l1Constants,
|
|
168
183
|
synchronizer,
|
|
169
184
|
events,
|
|
185
|
+
initialHeader,
|
|
186
|
+
initialBlockHash,
|
|
170
187
|
l2TipsCache,
|
|
188
|
+
deps.dateProvider ?? new DateProvider(),
|
|
171
189
|
);
|
|
172
190
|
|
|
173
191
|
await archiver.start(opts.blockUntilSync);
|
|
@@ -175,14 +193,14 @@ export async function createArchiver(
|
|
|
175
193
|
}
|
|
176
194
|
|
|
177
195
|
/** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
|
|
178
|
-
export async function registerProtocolContracts(
|
|
196
|
+
export async function registerProtocolContracts(stores: ArchiverDataStores) {
|
|
179
197
|
const blockNumber = 0;
|
|
180
198
|
for (const name of protocolContractNames) {
|
|
181
199
|
const provider = new BundledProtocolContractsProvider();
|
|
182
200
|
const contract = await provider.getProtocolContractArtifact(name);
|
|
183
201
|
|
|
184
202
|
// Skip if already registered (happens on node restart with a persisted store).
|
|
185
|
-
if (await
|
|
203
|
+
if (await stores.contractClasses.getContractClass(contract.contractClass.id)) {
|
|
186
204
|
continue;
|
|
187
205
|
}
|
|
188
206
|
|
|
@@ -196,8 +214,8 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
196
214
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
197
215
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
198
216
|
|
|
199
|
-
await
|
|
200
|
-
await
|
|
201
|
-
await
|
|
217
|
+
await stores.functionNames.register(publicFunctionSignatures);
|
|
218
|
+
await stores.contractClasses.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
|
|
219
|
+
await stores.contractInstances.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
202
220
|
}
|
|
203
221
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,24 @@ export * from './archiver.js';
|
|
|
4
4
|
export * from './modules/data_source_base.js';
|
|
5
5
|
export * from './modules/data_store_updater.js';
|
|
6
6
|
export * from './config.js';
|
|
7
|
+
export * from './errors.js';
|
|
7
8
|
|
|
8
9
|
export { type L1PublishedData } from './structs/published.js';
|
|
9
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
ARCHIVER_DB_VERSION,
|
|
12
|
+
type ArchiverDataStores,
|
|
13
|
+
type ArchiverL1SynchPoint,
|
|
14
|
+
backupArchiverDataStores,
|
|
15
|
+
createArchiverDataStores,
|
|
16
|
+
createContractDataSource,
|
|
17
|
+
getArchiverSynchPoint,
|
|
18
|
+
} from './store/data_stores.js';
|
|
19
|
+
export { FunctionNamesCache } from './store/function_names_cache.js';
|
|
20
|
+
export { ArchiverContractDataSourceAdapter } from './modules/contract_data_source_adapter.js';
|
|
21
|
+
export { BlockStore } from './store/block_store.js';
|
|
22
|
+
export { LogStore } from './store/log_store.js';
|
|
23
|
+
export { MessageStore } from './store/message_store.js';
|
|
24
|
+
export { ContractClassStore } from './store/contract_class_store.js';
|
|
10
25
|
export { ContractInstanceStore } from './store/contract_instance_store.js';
|
|
11
26
|
export { L2TipsCache } from './store/l2_tips_cache.js';
|
|
12
27
|
|
|
@@ -7,7 +7,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
7
7
|
import type { Logger } from '@aztec/foundation/log';
|
|
8
8
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
9
9
|
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
10
|
-
import {
|
|
10
|
+
import { computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
|
|
11
11
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
12
12
|
|
|
13
13
|
import {
|
|
@@ -61,6 +61,13 @@ export class CalldataRetriever {
|
|
|
61
61
|
private readonly rollupAddress: EthAddress,
|
|
62
62
|
) {}
|
|
63
63
|
|
|
64
|
+
private getSignatureContext() {
|
|
65
|
+
return {
|
|
66
|
+
chainId: this.publicClient.chain.id,
|
|
67
|
+
rollupAddress: this.rollupAddress,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
64
71
|
/**
|
|
65
72
|
* Gets checkpoint header and metadata from the calldata of an L1 transaction.
|
|
66
73
|
* Tries multicall3 decoding, falls back to trace-based extraction.
|
|
@@ -466,9 +473,12 @@ export class CalldataRetriever {
|
|
|
466
473
|
|
|
467
474
|
/** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
|
|
468
475
|
private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
476
|
+
return computeCheckpointPayloadDigest({
|
|
477
|
+
header,
|
|
478
|
+
archiveRoot,
|
|
479
|
+
feeAssetPriceModifier,
|
|
480
|
+
signatureContext: this.getSignatureContext(),
|
|
481
|
+
}).toString();
|
|
472
482
|
}
|
|
473
483
|
|
|
474
484
|
/**
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
6
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
7
|
+
|
|
8
|
+
import type { ArchiverDataStores } from '../store/data_stores.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Thin {@link ContractDataSource} adapter over {@link ArchiverDataStores}.
|
|
12
|
+
*
|
|
13
|
+
* Used by contexts (e.g. offline epoch re-prover tools) that need a ContractDataSource
|
|
14
|
+
* but do not need a full archiver instance.
|
|
15
|
+
*/
|
|
16
|
+
export class ArchiverContractDataSourceAdapter implements ContractDataSource {
|
|
17
|
+
constructor(private readonly stores: ArchiverDataStores) {}
|
|
18
|
+
|
|
19
|
+
public getBlockNumber(): Promise<BlockNumber> {
|
|
20
|
+
return this.stores.blocks.getLatestL2BlockNumber();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
24
|
+
return this.stores.contractClasses.getContractClass(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
28
|
+
return this.stores.contractClasses.getBytecodeCommitment(id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async getContract(
|
|
32
|
+
address: AztecAddress,
|
|
33
|
+
maybeTimestamp?: UInt64,
|
|
34
|
+
): Promise<ContractInstanceWithAddress | undefined> {
|
|
35
|
+
let timestamp = maybeTimestamp;
|
|
36
|
+
if (timestamp === undefined) {
|
|
37
|
+
const latest = await this.stores.blocks.getLatestL2BlockNumber();
|
|
38
|
+
const blockData = latest > 0 ? await this.stores.blocks.getBlockData({ number: latest }) : undefined;
|
|
39
|
+
timestamp = blockData ? blockData.header.globalVariables.timestamp : 0n;
|
|
40
|
+
}
|
|
41
|
+
return this.stores.contractInstances.getContractInstance(address, timestamp);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getContractClassIds(): Promise<Fr[]> {
|
|
45
|
+
return this.stores.contractClasses.getContractClassIds();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
49
|
+
return Promise.resolve(this.stores.functionNames.get(selector));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
|
|
53
|
+
return this.stores.functionNames.register(signatures);
|
|
54
|
+
}
|
|
55
|
+
}
|