@aztec/archiver 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8
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 +18 -10
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +146 -57
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -4
- package/dest/errors.d.ts +61 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +88 -14
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +26 -22
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -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 +11 -5
- package/dest/l1/data_retrieval.d.ts +24 -12
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +36 -37
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/data_source_base.d.ts +12 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +24 -6
- package/dest/modules/data_store_updater.d.ts +28 -15
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +102 -80
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +22 -6
- package/dest/modules/l1_synchronizer.d.ts +8 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +292 -144
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +6 -6
- package/dest/store/block_store.d.ts +83 -17
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +399 -124
- 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 +70 -23
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +88 -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 +27 -7
- 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 +95 -20
- 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 +20 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +114 -18
- 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 +19 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +57 -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 +9 -3
- package/package.json +13 -13
- package/src/archiver.ts +179 -56
- package/src/config.ts +23 -2
- package/src/errors.ts +133 -22
- package/src/factory.ts +24 -15
- package/src/index.ts +2 -1
- package/src/l1/calldata_retriever.ts +17 -5
- package/src/l1/data_retrieval.ts +52 -53
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +43 -7
- package/src/modules/data_store_updater.ts +126 -109
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +371 -178
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +489 -143
- 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 +133 -39
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +142 -29
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +73 -5
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +10 -2
package/src/errors.ts
CHANGED
|
@@ -1,29 +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}`);
|
|
6
|
-
|
|
7
|
-
}
|
|
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
|
-
);
|
|
7
|
+
this.name = 'NoBlobBodiesFoundError';
|
|
19
8
|
}
|
|
20
9
|
}
|
|
21
10
|
|
|
22
11
|
export class BlockNumberNotSequentialError extends Error {
|
|
23
12
|
constructor(newBlockNumber: number, previous: number | undefined) {
|
|
24
|
-
super(
|
|
25
|
-
|
|
26
|
-
);
|
|
13
|
+
super(`Cannot insert new block ${newBlockNumber} given previous block number is ${previous ?? 'undefined'}`);
|
|
14
|
+
this.name = 'BlockNumberNotSequentialError';
|
|
27
15
|
}
|
|
28
16
|
}
|
|
29
17
|
|
|
@@ -37,22 +25,29 @@ export class InitialCheckpointNumberNotSequentialError extends Error {
|
|
|
37
25
|
previousCheckpointNumber ?? 'undefined'
|
|
38
26
|
}`,
|
|
39
27
|
);
|
|
28
|
+
this.name = 'InitialCheckpointNumberNotSequentialError';
|
|
40
29
|
}
|
|
41
30
|
}
|
|
42
31
|
|
|
43
|
-
export class
|
|
44
|
-
constructor(
|
|
32
|
+
export class BlockCheckpointNumberNotSequentialError extends Error {
|
|
33
|
+
constructor(
|
|
34
|
+
blockNumber: BlockNumber,
|
|
35
|
+
blockCheckpointNumber: CheckpointNumber,
|
|
36
|
+
previous: CheckpointNumber | undefined,
|
|
37
|
+
) {
|
|
45
38
|
super(
|
|
46
|
-
`Cannot insert new checkpoint ${
|
|
39
|
+
`Cannot insert new block ${blockNumber} for checkpoint ${blockCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
|
|
47
40
|
);
|
|
41
|
+
this.name = 'BlockCheckpointNumberNotSequentialError';
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
export class
|
|
52
|
-
constructor(newCheckpointNumber:
|
|
45
|
+
export class CheckpointNumberNotSequentialError extends Error {
|
|
46
|
+
constructor(newCheckpointNumber: CheckpointNumber, previous: CheckpointNumber | undefined) {
|
|
53
47
|
super(
|
|
54
|
-
`Cannot insert
|
|
48
|
+
`Cannot insert new checkpoint ${newCheckpointNumber} given previous checkpoint number is ${previous ?? 'undefined'}`,
|
|
55
49
|
);
|
|
50
|
+
this.name = 'CheckpointNumberNotSequentialError';
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
|
|
@@ -61,6 +56,7 @@ export class BlockIndexNotSequentialError extends Error {
|
|
|
61
56
|
super(
|
|
62
57
|
`Cannot insert new block at checkpoint index ${newBlockIndex} given previous block index is ${previousBlockIndex ?? 'undefined'}`,
|
|
63
58
|
);
|
|
59
|
+
this.name = 'BlockIndexNotSequentialError';
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
|
|
@@ -74,21 +70,136 @@ export class BlockArchiveNotConsistentError extends Error {
|
|
|
74
70
|
super(
|
|
75
71
|
`Cannot insert new block number ${newBlockNumber} with archive ${newBlockArchive.toString()} previous block number is ${previousBlockNumber ?? 'undefined'}, previous archive is ${previousBlockArchive?.toString() ?? 'undefined'}`,
|
|
76
72
|
);
|
|
73
|
+
this.name = 'BlockArchiveNotConsistentError';
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
export class CheckpointNotFoundError extends Error {
|
|
81
78
|
constructor(checkpointNumber: number) {
|
|
82
79
|
super(`Failed to find expected checkpoint number ${checkpointNumber}`);
|
|
80
|
+
this.name = 'CheckpointNotFoundError';
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
export class BlockNotFoundError extends Error {
|
|
87
85
|
constructor(blockNumber: number) {
|
|
88
86
|
super(`Failed to find expected block number ${blockNumber}`);
|
|
87
|
+
this.name = 'BlockNotFoundError';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Thrown when a proposed block matches a block that was already checkpointed. This is expected for late proposals. */
|
|
92
|
+
export class BlockAlreadyCheckpointedError extends Error {
|
|
93
|
+
constructor(public readonly blockNumber: number) {
|
|
94
|
+
super(`Block ${blockNumber} has already been checkpointed with the same content`);
|
|
95
|
+
this.name = 'BlockAlreadyCheckpointedError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Thrown when logs are added for a tag whose last stored log has a higher block number than the new log. */
|
|
100
|
+
export class OutOfOrderLogInsertionError extends Error {
|
|
101
|
+
constructor(
|
|
102
|
+
public readonly logType: 'private' | 'public',
|
|
103
|
+
public readonly tag: string,
|
|
104
|
+
public readonly lastBlockNumber: number,
|
|
105
|
+
public readonly newBlockNumber: number,
|
|
106
|
+
) {
|
|
107
|
+
super(
|
|
108
|
+
`Out-of-order ${logType} log insertion for tag ${tag}: ` +
|
|
109
|
+
`last existing log is from block ${lastBlockNumber} but new log is from block ${newBlockNumber}`,
|
|
110
|
+
);
|
|
111
|
+
this.name = 'OutOfOrderLogInsertionError';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Thrown when L1 to L2 messages are requested for a checkpoint whose message tree hasn't been sealed yet. */
|
|
116
|
+
export class L1ToL2MessagesNotReadyError extends Error {
|
|
117
|
+
constructor(
|
|
118
|
+
public readonly checkpointNumber: number,
|
|
119
|
+
public readonly inboxTreeInProgress: bigint,
|
|
120
|
+
) {
|
|
121
|
+
super(
|
|
122
|
+
`Cannot get L1 to L2 messages for checkpoint ${checkpointNumber}: ` +
|
|
123
|
+
`inbox tree in progress is ${inboxTreeInProgress}, messages not yet sealed`,
|
|
124
|
+
);
|
|
125
|
+
this.name = 'L1ToL2MessagesNotReadyError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Thrown when a proposed checkpoint number is stale (already processed). */
|
|
130
|
+
export class ProposedCheckpointStaleError extends Error {
|
|
131
|
+
constructor(
|
|
132
|
+
public readonly proposedCheckpointNumber: number,
|
|
133
|
+
public readonly currentProposedNumber: number,
|
|
134
|
+
) {
|
|
135
|
+
super(`Stale proposed checkpoint ${proposedCheckpointNumber}: current proposed is ${currentProposedNumber}`);
|
|
136
|
+
this.name = 'ProposedCheckpointStaleError';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Thrown when a proposed checkpoint number is not the expected latestTip + 1. */
|
|
141
|
+
export class ProposedCheckpointNotSequentialError extends Error {
|
|
142
|
+
constructor(
|
|
143
|
+
public readonly proposedCheckpointNumber: number,
|
|
144
|
+
public readonly latestTipNumber: number,
|
|
145
|
+
) {
|
|
146
|
+
super(
|
|
147
|
+
`Proposed checkpoint ${proposedCheckpointNumber} is not sequential: expected ${latestTipNumber + 1} (latest tip + 1, where tip is highest of confirmed or pending)`,
|
|
148
|
+
);
|
|
149
|
+
this.name = 'ProposedCheckpointNotSequentialError';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Thrown when a proposed checkpoint or block L2 slot has already expired on L1. */
|
|
154
|
+
export class BlockOrCheckpointSlotExpiredError extends Error {
|
|
155
|
+
constructor(
|
|
156
|
+
public readonly slot: number,
|
|
157
|
+
public readonly nextSlotStart: bigint,
|
|
158
|
+
public readonly l1TimestampSynced: bigint | undefined,
|
|
159
|
+
) {
|
|
160
|
+
super(
|
|
161
|
+
`Checkpoint or block for slot ${slot} is expired: L1 synced to ${l1TimestampSynced} which is past the next slot start ${nextSlotStart}. ` +
|
|
162
|
+
`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).`,
|
|
163
|
+
);
|
|
164
|
+
this.name = 'BlockOrCheckpointSlotExpiredError';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
|
|
169
|
+
export class NoProposedCheckpointToPromoteError extends Error {
|
|
170
|
+
constructor() {
|
|
171
|
+
super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
|
|
172
|
+
this.name = 'NoProposedCheckpointToPromoteError';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
|
|
177
|
+
export class ProposedCheckpointArchiveRootMismatchError extends Error {
|
|
178
|
+
constructor(
|
|
179
|
+
public readonly expectedArchiveRoot: Fr,
|
|
180
|
+
public readonly actualArchiveRoot: Fr,
|
|
181
|
+
) {
|
|
182
|
+
super(
|
|
183
|
+
`Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
|
|
184
|
+
);
|
|
185
|
+
this.name = 'ProposedCheckpointArchiveRootMismatchError';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
|
|
190
|
+
export class ProposedCheckpointPromotionNotSequentialError extends Error {
|
|
191
|
+
constructor(
|
|
192
|
+
public readonly proposedCheckpointNumber: number,
|
|
193
|
+
public readonly latestCheckpointNumber: number,
|
|
194
|
+
) {
|
|
195
|
+
super(
|
|
196
|
+
`Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
|
|
197
|
+
);
|
|
198
|
+
this.name = 'ProposedCheckpointPromotionNotSequentialError';
|
|
89
199
|
}
|
|
90
200
|
}
|
|
91
201
|
|
|
202
|
+
/** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
|
|
92
203
|
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
93
204
|
constructor(
|
|
94
205
|
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(
|
|
@@ -118,6 +121,7 @@ export async function createArchiver(
|
|
|
118
121
|
batchSize: 100,
|
|
119
122
|
maxAllowedEthClientDriftSeconds: 300,
|
|
120
123
|
ethereumAllowNoDebugHosts: false,
|
|
124
|
+
skipHistoricalLogsCheck: false,
|
|
121
125
|
},
|
|
122
126
|
mapArchiverConfig(config),
|
|
123
127
|
);
|
|
@@ -170,16 +174,22 @@ export async function createArchiver(
|
|
|
170
174
|
return archiver;
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
/** Registers protocol contracts in the archiver store. */
|
|
177
|
+
/** Registers protocol contracts in the archiver store. Idempotent — skips contracts that already exist (e.g. on node restart). */
|
|
174
178
|
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
175
179
|
const blockNumber = 0;
|
|
176
180
|
for (const name of protocolContractNames) {
|
|
177
181
|
const provider = new BundledProtocolContractsProvider();
|
|
178
182
|
const contract = await provider.getProtocolContractArtifact(name);
|
|
179
|
-
|
|
183
|
+
|
|
184
|
+
// Skip if already registered (happens on node restart with a persisted store).
|
|
185
|
+
if (await store.getContractClass(contract.contractClass.id)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const publicBytecodeCommitment = await computePublicBytecodeCommitment(contract.contractClass.packedBytecode);
|
|
190
|
+
const contractClassPublic: ContractClassPublicWithCommitment = {
|
|
180
191
|
...contract.contractClass,
|
|
181
|
-
|
|
182
|
-
utilityFunctions: [],
|
|
192
|
+
publicBytecodeCommitment,
|
|
183
193
|
};
|
|
184
194
|
|
|
185
195
|
const publicFunctionSignatures = contract.artifact.functions
|
|
@@ -187,8 +197,7 @@ export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
|
187
197
|
.map(fn => decodeFunctionSignature(fn.name, fn.parameters));
|
|
188
198
|
|
|
189
199
|
await store.registerContractFunctionSignatures(publicFunctionSignatures);
|
|
190
|
-
|
|
191
|
-
await store.addContractClasses([contractClassPublic], [bytecodeCommitment], BlockNumber(blockNumber));
|
|
200
|
+
await store.addContractClasses([contractClassPublic], BlockNumber(blockNumber));
|
|
192
201
|
await store.addContractInstances([contract.instance], BlockNumber(blockNumber));
|
|
193
202
|
}
|
|
194
203
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,4 +10,5 @@ export { KVArchiverDataStore, ARCHIVER_DB_VERSION } from './store/kv_archiver_st
|
|
|
10
10
|
export { ContractInstanceStore } from './store/contract_instance_store.js';
|
|
11
11
|
export { L2TipsCache } from './store/l2_tips_cache.js';
|
|
12
12
|
|
|
13
|
-
export {
|
|
13
|
+
export { retrieveL2ProofVerifiedEvents } from './l1/data_retrieval.js';
|
|
14
|
+
export { CalldataRetriever } from './l1/calldata_retriever.js';
|
|
@@ -1,12 +1,13 @@
|
|
|
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';
|
|
7
8
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
8
9
|
import { CommitteeAttestation } from '@aztec/stdlib/block';
|
|
9
|
-
import { ConsensusPayload,
|
|
10
|
+
import { ConsensusPayload, getHashedSignaturePayloadTypedData } from '@aztec/stdlib/p2p';
|
|
10
11
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
11
12
|
|
|
12
13
|
import {
|
|
@@ -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 {
|
|
@@ -60,6 +61,13 @@ export class CalldataRetriever {
|
|
|
60
61
|
private readonly rollupAddress: EthAddress,
|
|
61
62
|
) {}
|
|
62
63
|
|
|
64
|
+
private getSignatureContext() {
|
|
65
|
+
return {
|
|
66
|
+
chainId: this.publicClient.chain.id,
|
|
67
|
+
rollupAddress: this.rollupAddress,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
63
71
|
/**
|
|
64
72
|
* Gets checkpoint header and metadata from the calldata of an L1 transaction.
|
|
65
73
|
* Tries multicall3 decoding, falls back to trace-based extraction.
|
|
@@ -465,9 +473,13 @@ export class CalldataRetriever {
|
|
|
465
473
|
|
|
466
474
|
/** Computes the keccak256 payload digest from the checkpoint header, archive root, and fee asset price modifier. */
|
|
467
475
|
private computePayloadDigest(header: CheckpointHeader, archiveRoot: Fr, feeAssetPriceModifier: bigint): Hex {
|
|
468
|
-
const consensusPayload = new ConsensusPayload(
|
|
469
|
-
|
|
470
|
-
|
|
476
|
+
const consensusPayload = new ConsensusPayload(
|
|
477
|
+
header,
|
|
478
|
+
archiveRoot,
|
|
479
|
+
feeAssetPriceModifier,
|
|
480
|
+
this.getSignatureContext(),
|
|
481
|
+
);
|
|
482
|
+
return getHashedSignaturePayloadTypedData(consensusPayload).toString();
|
|
471
483
|
}
|
|
472
484
|
|
|
473
485
|
/**
|
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -35,18 +35,28 @@ import type { DataRetrieval } from '../structs/data_retrieval.js';
|
|
|
35
35
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
36
36
|
import { CalldataRetriever } from './calldata_retriever.js';
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
type RetrievedCheckpointBase = {
|
|
39
39
|
checkpointNumber: CheckpointNumber;
|
|
40
40
|
archiveRoot: Fr;
|
|
41
41
|
feeAssetPriceModifier: bigint;
|
|
42
42
|
header: CheckpointHeader;
|
|
43
|
-
checkpointBlobData: CheckpointBlobData;
|
|
44
43
|
l1: L1PublishedData;
|
|
45
44
|
chainId: Fr;
|
|
46
45
|
version: Fr;
|
|
47
46
|
attestations: CommitteeAttestation[];
|
|
48
47
|
};
|
|
49
48
|
|
|
49
|
+
/** Checkpoint data as retrieved from L1 calldata and blob data. */
|
|
50
|
+
export type RetrievedCheckpoint = RetrievedCheckpointBase & { checkpointBlobData: CheckpointBlobData };
|
|
51
|
+
|
|
52
|
+
/** Checkpoint data retrieved from L1 calldata only, without blob data. */
|
|
53
|
+
export type RetrievedCheckpointFromCalldata = RetrievedCheckpointBase & {
|
|
54
|
+
/** Versioned blob hashes from the checkpoint proposed event. */
|
|
55
|
+
blobHashes: Buffer[];
|
|
56
|
+
/** Parent beacon block root from the L1 block, used for blob fetching. */
|
|
57
|
+
parentBeaconBlockRoot: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
|
|
50
60
|
export async function retrievedToPublishedCheckpoint({
|
|
51
61
|
checkpointNumber,
|
|
52
62
|
archiveRoot,
|
|
@@ -137,31 +147,27 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
137
147
|
}
|
|
138
148
|
|
|
139
149
|
/**
|
|
140
|
-
* Fetches
|
|
150
|
+
* Fetches checkpoint calldata from the rollup contract without fetching blob data.
|
|
151
|
+
* Returns RetrievedCheckpointFromCalldata objects that preserve the information needed for deferred blob fetching.
|
|
141
152
|
* @param rollup - The rollup contract wrapper.
|
|
142
153
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
143
154
|
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
144
|
-
* @param blobClient - The blob client client for fetching blob data.
|
|
145
155
|
* @param searchStartBlock - The block number to use for starting the search.
|
|
146
156
|
* @param searchEndBlock - The highest block number that we should search up to.
|
|
147
|
-
* @param contractAddresses - The contract addresses (governanceProposerAddress, slashFactoryAddress, slashingProposerAddress).
|
|
148
157
|
* @param instrumentation - The archiver instrumentation instance.
|
|
149
158
|
* @param logger - The logger instance.
|
|
150
|
-
* @
|
|
151
|
-
* @returns An array of retrieved checkpoints.
|
|
159
|
+
* @returns An array of calldata-only checkpoints.
|
|
152
160
|
*/
|
|
153
|
-
export async function
|
|
161
|
+
export async function retrieveCheckpointCalldataFromRollup(
|
|
154
162
|
rollup: RollupContract,
|
|
155
163
|
publicClient: ViemPublicClient,
|
|
156
164
|
debugClient: ViemPublicDebugClient,
|
|
157
|
-
blobClient: BlobClientInterface,
|
|
158
165
|
searchStartBlock: bigint,
|
|
159
166
|
searchEndBlock: bigint,
|
|
160
167
|
instrumentation: ArchiverInstrumentation,
|
|
161
168
|
logger: Logger = createLogger('archiver'),
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const retrievedCheckpoints: RetrievedCheckpoint[] = [];
|
|
169
|
+
): Promise<RetrievedCheckpointFromCalldata[]> {
|
|
170
|
+
const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
|
|
165
171
|
|
|
166
172
|
let rollupConstants: { chainId: Fr; version: Fr; targetCommitteeSize: number } | undefined;
|
|
167
173
|
|
|
@@ -197,46 +203,39 @@ export async function retrieveCheckpointsFromRollup(
|
|
|
197
203
|
rollup,
|
|
198
204
|
publicClient,
|
|
199
205
|
debugClient,
|
|
200
|
-
blobClient,
|
|
201
206
|
checkpointProposedLogs,
|
|
202
207
|
rollupConstants,
|
|
203
208
|
instrumentation,
|
|
204
209
|
logger,
|
|
205
|
-
isHistoricalSync,
|
|
206
210
|
);
|
|
207
211
|
retrievedCheckpoints.push(...newCheckpoints);
|
|
208
212
|
searchStartBlock = lastLog.l1BlockNumber + 1n;
|
|
209
213
|
} while (searchStartBlock <= searchEndBlock);
|
|
210
214
|
|
|
211
|
-
// The asyncPool from processCheckpointProposedLogs will not necessarily return the checkpoints in order, so we sort them before returning.
|
|
212
215
|
return retrievedCheckpoints.sort((a, b) => Number(a.l1.blockNumber - b.l1.blockNumber));
|
|
213
216
|
}
|
|
214
217
|
|
|
215
218
|
/**
|
|
216
|
-
* Processes
|
|
219
|
+
* Processes CheckpointProposed logs, fetching only calldata (no blobs).
|
|
217
220
|
* @param rollup - The rollup contract wrapper.
|
|
218
221
|
* @param publicClient - The viem public client to use for transaction retrieval.
|
|
219
222
|
* @param debugClient - The viem debug client to use for trace/debug RPC methods (optional).
|
|
220
|
-
* @param blobClient - The blob client client for fetching blob data.
|
|
221
223
|
* @param logs - CheckpointProposed logs.
|
|
222
224
|
* @param rollupConstants - The rollup constants (chainId, version, targetCommitteeSize).
|
|
223
225
|
* @param instrumentation - The archiver instrumentation instance.
|
|
224
226
|
* @param logger - The logger instance.
|
|
225
|
-
* @
|
|
226
|
-
* @returns An array of retrieved checkpoints.
|
|
227
|
+
* @returns An array of calldata-only checkpoints.
|
|
227
228
|
*/
|
|
228
229
|
async function processCheckpointProposedLogs(
|
|
229
230
|
rollup: RollupContract,
|
|
230
231
|
publicClient: ViemPublicClient,
|
|
231
232
|
debugClient: ViemPublicDebugClient,
|
|
232
|
-
blobClient: BlobClientInterface,
|
|
233
233
|
logs: CheckpointProposedLog[],
|
|
234
234
|
{ chainId, version, targetCommitteeSize }: { chainId: Fr; version: Fr; targetCommitteeSize: number },
|
|
235
235
|
instrumentation: ArchiverInstrumentation,
|
|
236
236
|
logger: Logger,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const retrievedCheckpoints: RetrievedCheckpoint[] = [];
|
|
237
|
+
): Promise<RetrievedCheckpointFromCalldata[]> {
|
|
238
|
+
const retrievedCheckpoints: RetrievedCheckpointFromCalldata[] = [];
|
|
240
239
|
const calldataRetriever = new CalldataRetriever(
|
|
241
240
|
publicClient,
|
|
242
241
|
debugClient,
|
|
@@ -252,7 +251,6 @@ async function processCheckpointProposedLogs(
|
|
|
252
251
|
const archiveFromChain = await rollup.archiveAt(checkpointNumber);
|
|
253
252
|
const blobHashes = log.args.versionedBlobHashes;
|
|
254
253
|
|
|
255
|
-
// The value from the event and contract will match only if the checkpoint is in the chain.
|
|
256
254
|
if (archive.equals(archiveFromChain)) {
|
|
257
255
|
const expectedHashes = {
|
|
258
256
|
attestationsHash: log.args.attestationsHash.toString() as Hex,
|
|
@@ -265,23 +263,19 @@ async function processCheckpointProposedLogs(
|
|
|
265
263
|
checkpointNumber,
|
|
266
264
|
expectedHashes,
|
|
267
265
|
);
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
|
|
267
|
+
const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
|
|
268
|
+
|
|
269
|
+
retrievedCheckpoints.push({
|
|
270
|
+
...checkpoint,
|
|
271
|
+
l1,
|
|
272
|
+
chainId,
|
|
273
|
+
version,
|
|
271
274
|
blobHashes,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
isHistoricalSync,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
const l1 = new L1PublishedData(
|
|
278
|
-
log.l1BlockNumber,
|
|
279
|
-
await getL1BlockTime(publicClient, log.l1BlockNumber),
|
|
280
|
-
log.l1BlockHash.toString(),
|
|
281
|
-
);
|
|
275
|
+
parentBeaconBlockRoot,
|
|
276
|
+
});
|
|
282
277
|
|
|
283
|
-
|
|
284
|
-
logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
278
|
+
logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
285
279
|
l1BlockNumber: log.l1BlockNumber,
|
|
286
280
|
checkpointNumber,
|
|
287
281
|
archive: archive.toString(),
|
|
@@ -298,9 +292,12 @@ async function processCheckpointProposedLogs(
|
|
|
298
292
|
return retrievedCheckpoints;
|
|
299
293
|
}
|
|
300
294
|
|
|
301
|
-
export async function
|
|
295
|
+
export async function getL1Block(
|
|
296
|
+
publicClient: ViemPublicClient,
|
|
297
|
+
blockNumber: bigint,
|
|
298
|
+
): Promise<{ timestamp: bigint; parentBeaconBlockRoot: string | undefined }> {
|
|
302
299
|
const block = await publicClient.getBlock({ blockNumber, includeTransactions: false });
|
|
303
|
-
return block.timestamp;
|
|
300
|
+
return { timestamp: block.timestamp, parentBeaconBlockRoot: block.parentBeaconBlockRoot };
|
|
304
301
|
}
|
|
305
302
|
|
|
306
303
|
export async function getCheckpointBlobDataFromBlobs(
|
|
@@ -310,8 +307,14 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
310
307
|
checkpointNumber: CheckpointNumber,
|
|
311
308
|
logger: Logger,
|
|
312
309
|
isHistoricalSync: boolean,
|
|
310
|
+
parentBeaconBlockRoot?: string,
|
|
311
|
+
l1BlockTimestamp?: bigint,
|
|
313
312
|
): Promise<CheckpointBlobData> {
|
|
314
|
-
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
313
|
+
const blobBodies = await blobClient.getBlobSidecar(blockHash, blobHashes, {
|
|
314
|
+
isHistoricalSync,
|
|
315
|
+
parentBeaconBlockRoot,
|
|
316
|
+
l1BlockTimestamp,
|
|
317
|
+
});
|
|
315
318
|
if (blobBodies.length === 0) {
|
|
316
319
|
throw new NoBlobBodiesFoundError(checkpointNumber);
|
|
317
320
|
}
|
|
@@ -336,14 +339,10 @@ export async function getCheckpointBlobDataFromBlobs(
|
|
|
336
339
|
/** Given an L1 to L2 message, retrieves its corresponding event from the Inbox within a specific block range. */
|
|
337
340
|
export async function retrieveL1ToL2Message(
|
|
338
341
|
inbox: InboxContract,
|
|
339
|
-
|
|
340
|
-
fromBlock: bigint,
|
|
341
|
-
toBlock: bigint,
|
|
342
|
+
message: InboxMessage,
|
|
342
343
|
): Promise<InboxMessage | undefined> {
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
const messages = mapLogsInboxMessage(logs);
|
|
346
|
-
return messages.length > 0 ? messages[0] : undefined;
|
|
344
|
+
const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
|
|
345
|
+
return log && mapLogInboxMessage(log);
|
|
347
346
|
}
|
|
348
347
|
|
|
349
348
|
/**
|
|
@@ -366,22 +365,22 @@ export async function retrieveL1ToL2Messages(
|
|
|
366
365
|
break;
|
|
367
366
|
}
|
|
368
367
|
|
|
369
|
-
retrievedL1ToL2Messages.push(...
|
|
368
|
+
retrievedL1ToL2Messages.push(...messageSentLogs.map(mapLogInboxMessage));
|
|
370
369
|
searchStartBlock = messageSentLogs.at(-1)!.l1BlockNumber + 1n;
|
|
371
370
|
}
|
|
372
371
|
|
|
373
372
|
return retrievedL1ToL2Messages;
|
|
374
373
|
}
|
|
375
374
|
|
|
376
|
-
function
|
|
377
|
-
return
|
|
375
|
+
function mapLogInboxMessage(log: MessageSentLog): InboxMessage {
|
|
376
|
+
return {
|
|
378
377
|
index: log.args.index,
|
|
379
378
|
leaf: log.args.leaf,
|
|
380
379
|
l1BlockNumber: log.l1BlockNumber,
|
|
381
380
|
l1BlockHash: log.l1BlockHash,
|
|
382
381
|
checkpointNumber: log.args.checkpointNumber,
|
|
383
382
|
rollingHash: log.args.rollingHash,
|
|
384
|
-
}
|
|
383
|
+
};
|
|
385
384
|
}
|
|
386
385
|
|
|
387
386
|
/** Retrieves L2ProofVerified events from the rollup contract. */
|