@aztec/archiver 0.0.1-commit.f650c0a5c → 0.0.1-commit.f7ea82942
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/archiver.d.ts +4 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +12 -1
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -2
- package/dest/errors.d.ts +17 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +22 -0
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -1
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/l1/data_retrieval.d.ts +18 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -19
- 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_store_updater.d.ts +12 -5
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +13 -3
- 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 +4 -1
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +114 -25
- package/dest/store/block_store.d.ts +10 -3
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +41 -3
- package/dest/store/kv_archiver_store.d.ts +9 -3
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +7 -0
- package/dest/store/l2_tips_cache.d.ts +1 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +2 -2
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +2 -4
- package/dest/test/fake_l1_state.d.ts +6 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +17 -7
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +4 -1
- package/package.json +13 -13
- package/src/archiver.ts +23 -3
- package/src/config.ts +14 -1
- package/src/errors.ts +34 -0
- package/src/factory.ts +1 -0
- package/src/index.ts +2 -1
- package/src/l1/data_retrieval.ts +30 -35
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_store_updater.ts +27 -3
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +168 -27
- package/src/store/block_store.ts +53 -1
- package/src/store/kv_archiver_store.ts +15 -0
- package/src/store/l2_tips_cache.ts +8 -2
- package/src/store/log_store.ts +2 -5
- package/src/test/fake_l1_state.ts +23 -10
- package/src/test/noop_l1_archiver.ts +3 -0
package/src/archiver.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
11
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
12
|
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec/foundation/promise';
|
|
13
13
|
import { RunningPromise, makeLoggingErrorHandler } from '@aztec/foundation/running-promise';
|
|
14
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
14
|
+
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
15
15
|
import {
|
|
16
16
|
type ArchiverEmitter,
|
|
17
17
|
L2Block,
|
|
@@ -31,6 +31,7 @@ import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@a
|
|
|
31
31
|
|
|
32
32
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
33
33
|
import { BlockAlreadyCheckpointedError, NoBlobBodiesFoundError } from './errors.js';
|
|
34
|
+
import { validateAndLogHistoricalLogsAvailability } from './l1/validate_historical_logs.js';
|
|
34
35
|
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
35
36
|
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
36
37
|
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
@@ -85,6 +86,8 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
85
86
|
|
|
86
87
|
public readonly tracer: Tracer;
|
|
87
88
|
|
|
89
|
+
private readonly instrumentation: ArchiverInstrumentation;
|
|
90
|
+
|
|
88
91
|
/**
|
|
89
92
|
* Creates a new instance of the Archiver.
|
|
90
93
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
@@ -104,7 +107,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
104
107
|
private readonly publicClient: ViemPublicClient,
|
|
105
108
|
private readonly debugClient: ViemPublicDebugClient,
|
|
106
109
|
private readonly rollup: RollupContract,
|
|
107
|
-
private readonly l1Addresses: Pick<
|
|
110
|
+
private readonly l1Addresses: Pick<
|
|
111
|
+
L1ContractAddresses,
|
|
112
|
+
'rollupAddress' | 'registryAddress' | 'inboxAddress' | 'governanceProposerAddress'
|
|
113
|
+
> & {
|
|
108
114
|
slashingProposerAddress: EthAddress;
|
|
109
115
|
},
|
|
110
116
|
readonly dataStore: KVArchiverDataStore,
|
|
@@ -114,6 +120,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
114
120
|
skipValidateCheckpointAttestations?: boolean;
|
|
115
121
|
maxAllowedEthClientDriftSeconds: number;
|
|
116
122
|
ethereumAllowNoDebugHosts?: boolean;
|
|
123
|
+
skipHistoricalLogsCheck?: boolean;
|
|
117
124
|
},
|
|
118
125
|
private readonly blobClient: BlobClientInterface,
|
|
119
126
|
instrumentation: ArchiverInstrumentation,
|
|
@@ -129,6 +136,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
129
136
|
super(dataStore, l1Constants);
|
|
130
137
|
|
|
131
138
|
this.tracer = instrumentation.tracer;
|
|
139
|
+
this.instrumentation = instrumentation;
|
|
132
140
|
this.initialSyncPromise = promiseWithResolvers();
|
|
133
141
|
this.synchronizer = synchronizer;
|
|
134
142
|
this.events = events;
|
|
@@ -169,6 +177,17 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
169
177
|
this.config.ethereumAllowNoDebugHosts ?? false,
|
|
170
178
|
this.log.getBindings(),
|
|
171
179
|
);
|
|
180
|
+
await validateAndLogHistoricalLogsAvailability(
|
|
181
|
+
this.publicClient,
|
|
182
|
+
{
|
|
183
|
+
rollupAddress: this.l1Addresses.rollupAddress,
|
|
184
|
+
inboxAddress: this.l1Addresses.inboxAddress,
|
|
185
|
+
registryAddress: this.l1Addresses.registryAddress,
|
|
186
|
+
governanceProposerAddress: this.l1Addresses.governanceProposerAddress,
|
|
187
|
+
},
|
|
188
|
+
this.config.skipHistoricalLogsCheck ?? false,
|
|
189
|
+
this.log.getBindings(),
|
|
190
|
+
);
|
|
172
191
|
|
|
173
192
|
// Log initial state for the archiver
|
|
174
193
|
const { l1StartBlock } = this.l1Constants;
|
|
@@ -244,7 +263,8 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
244
263
|
}
|
|
245
264
|
|
|
246
265
|
try {
|
|
247
|
-
await this.updater.addProposedBlock(block);
|
|
266
|
+
const [durationMs] = await elapsed(() => this.updater.addProposedBlock(block));
|
|
267
|
+
this.instrumentation.processNewProposedBlock(durationMs, block);
|
|
248
268
|
this.log.debug(`Added block ${block.number} to store`);
|
|
249
269
|
resolve();
|
|
250
270
|
} catch (err: any) {
|
package/src/config.ts
CHANGED
|
@@ -50,13 +50,17 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
50
50
|
},
|
|
51
51
|
archiverStoreMapSizeKb: {
|
|
52
52
|
env: 'ARCHIVER_STORE_MAP_SIZE_KB',
|
|
53
|
-
parseEnv: (val: string
|
|
53
|
+
parseEnv: (val: string) => +val,
|
|
54
54
|
description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
55
55
|
},
|
|
56
56
|
skipValidateCheckpointAttestations: {
|
|
57
57
|
description: 'Skip validating checkpoint attestations (for testing purposes only)',
|
|
58
58
|
...booleanConfigHelper(false),
|
|
59
59
|
},
|
|
60
|
+
skipPromoteProposedCheckpointDuringL1Sync: {
|
|
61
|
+
description: 'Skip promoting proposed checkpoints during L1 sync (for testing purposes only)',
|
|
62
|
+
...booleanConfigHelper(false),
|
|
63
|
+
},
|
|
60
64
|
maxAllowedEthClientDriftSeconds: {
|
|
61
65
|
env: 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS',
|
|
62
66
|
description: 'Maximum allowed drift in seconds between the Ethereum client and current time.',
|
|
@@ -67,6 +71,13 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
67
71
|
description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
|
|
68
72
|
...booleanConfigHelper(true),
|
|
69
73
|
},
|
|
74
|
+
archiverSkipHistoricalLogsCheck: {
|
|
75
|
+
env: 'ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK',
|
|
76
|
+
description:
|
|
77
|
+
'Skip the startup check that probes the L1 RPC for historical Rollup contract logs. ' +
|
|
78
|
+
'Set to true to bypass the check when the connected RPC node is known to prune old logs.',
|
|
79
|
+
...booleanConfigHelper(false),
|
|
80
|
+
},
|
|
70
81
|
...chainConfigMappings,
|
|
71
82
|
...l1ReaderConfigMappings,
|
|
72
83
|
viemPollingIntervalMS: {
|
|
@@ -96,7 +107,9 @@ export function mapArchiverConfig(config: Partial<ArchiverConfig>) {
|
|
|
96
107
|
pollingIntervalMs: config.archiverPollingIntervalMS,
|
|
97
108
|
batchSize: config.archiverBatchSize,
|
|
98
109
|
skipValidateCheckpointAttestations: config.skipValidateCheckpointAttestations,
|
|
110
|
+
skipPromoteProposedCheckpointDuringL1Sync: config.skipPromoteProposedCheckpointDuringL1Sync,
|
|
99
111
|
maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
|
|
100
112
|
ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
|
|
113
|
+
skipHistoricalLogsCheck: config.archiverSkipHistoricalLogsCheck,
|
|
101
114
|
};
|
|
102
115
|
}
|
package/src/errors.ts
CHANGED
|
@@ -132,6 +132,40 @@ export class ProposedCheckpointNotSequentialError extends Error {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/** Thrown when attempting to promote a proposed checkpoint but no proposed checkpoint exists in the store. */
|
|
136
|
+
export class NoProposedCheckpointToPromoteError extends Error {
|
|
137
|
+
constructor() {
|
|
138
|
+
super('Cannot promote proposed checkpoint: no proposed checkpoint exists');
|
|
139
|
+
this.name = 'NoProposedCheckpointToPromoteError';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Thrown when the archive root of the proposed checkpoint does not match the expected one. */
|
|
144
|
+
export class ProposedCheckpointArchiveRootMismatchError extends Error {
|
|
145
|
+
constructor(
|
|
146
|
+
public readonly expectedArchiveRoot: Fr,
|
|
147
|
+
public readonly actualArchiveRoot: Fr,
|
|
148
|
+
) {
|
|
149
|
+
super(
|
|
150
|
+
`Cannot promote proposed checkpoint: archive root mismatch (expected ${expectedArchiveRoot}, got ${actualArchiveRoot})`,
|
|
151
|
+
);
|
|
152
|
+
this.name = 'ProposedCheckpointArchiveRootMismatchError';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Thrown when the proposed checkpoint does not directly follow the latest confirmed checkpoint. */
|
|
157
|
+
export class ProposedCheckpointPromotionNotSequentialError extends Error {
|
|
158
|
+
constructor(
|
|
159
|
+
public readonly proposedCheckpointNumber: number,
|
|
160
|
+
public readonly latestCheckpointNumber: number,
|
|
161
|
+
) {
|
|
162
|
+
super(
|
|
163
|
+
`Cannot promote proposed checkpoint: not sequential (latest ${latestCheckpointNumber}, proposed ${proposedCheckpointNumber})`,
|
|
164
|
+
);
|
|
165
|
+
this.name = 'ProposedCheckpointPromotionNotSequentialError';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
135
169
|
/** Thrown when a proposed block conflicts with an already checkpointed block (different content). */
|
|
136
170
|
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
137
171
|
constructor(
|
package/src/factory.ts
CHANGED
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';
|
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, 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,
|
|
@@ -268,19 +266,16 @@ async function processCheckpointProposedLogs(
|
|
|
268
266
|
const { timestamp, parentBeaconBlockRoot } = await getL1Block(publicClient, log.l1BlockNumber);
|
|
269
267
|
const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
|
|
270
268
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
269
|
+
retrievedCheckpoints.push({
|
|
270
|
+
...checkpoint,
|
|
271
|
+
l1,
|
|
272
|
+
chainId,
|
|
273
|
+
version,
|
|
274
274
|
blobHashes,
|
|
275
|
-
checkpointNumber,
|
|
276
|
-
logger,
|
|
277
|
-
isHistoricalSync,
|
|
278
275
|
parentBeaconBlockRoot,
|
|
279
|
-
|
|
280
|
-
);
|
|
276
|
+
});
|
|
281
277
|
|
|
282
|
-
|
|
283
|
-
logger.trace(`Retrieved checkpoint ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
278
|
+
logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|
|
284
279
|
l1BlockNumber: log.l1BlockNumber,
|
|
285
280
|
checkpointNumber,
|
|
286
281
|
archive: archive.toString(),
|
|
@@ -346,7 +341,7 @@ export async function retrieveL1ToL2Message(
|
|
|
346
341
|
inbox: InboxContract,
|
|
347
342
|
message: InboxMessage,
|
|
348
343
|
): Promise<InboxMessage | undefined> {
|
|
349
|
-
const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.
|
|
344
|
+
const log = await inbox.getMessageSentEventByHash(message.leaf.toString(), message.l1BlockNumber);
|
|
350
345
|
return log && mapLogInboxMessage(log);
|
|
351
346
|
}
|
|
352
347
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { getPublicClient, getRpcUrlsFromClient } from '@aztec/ethereum/client';
|
|
2
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
4
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
|
|
7
|
+
/** Subset of L1 contract addresses whose historical logs the Aztec node relies on. */
|
|
8
|
+
export type HistoricalLogsContractAddresses = Pick<
|
|
9
|
+
L1ContractAddresses,
|
|
10
|
+
'rollupAddress' | 'inboxAddress' | 'registryAddress' | 'governanceProposerAddress'
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
/** Result of probing a single RPC URL. */
|
|
14
|
+
type ProbeResult = { ok: true } | { ok: false; reason: string; clientVersion: string | undefined };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Validates that every configured L1 RPC URL returns historical logs for the Rollup contract.
|
|
18
|
+
*
|
|
19
|
+
* Some RPC providers prune old logs, which would cause L1 syncing to silently fail. To detect this,
|
|
20
|
+
* we query for the `OwnershipTransferred` event which every Rollup emits in its constructor (via
|
|
21
|
+
* Ownable) on the block it was deployed (`l1StartBlock`). The `client` is typically a viem fallback
|
|
22
|
+
* transport over several user-configured RPC URLs — checking only the first URL would miss a bad
|
|
23
|
+
* secondary, so we probe each URL independently. The first URL that fails aborts startup, unless
|
|
24
|
+
* the operator has explicitly opted out.
|
|
25
|
+
*
|
|
26
|
+
* @param client - The L1 public client built from the user-configured RPC URLs.
|
|
27
|
+
* @param addresses - The subset of L1 contract addresses we rely on for historical log retrieval.
|
|
28
|
+
* @param skipCheck - If true, log warnings instead of throwing.
|
|
29
|
+
* @param bindings - Optional logger bindings for context.
|
|
30
|
+
* @throws Error if any URL fails the probe and skipCheck is false.
|
|
31
|
+
*/
|
|
32
|
+
export async function validateAndLogHistoricalLogsAvailability(
|
|
33
|
+
client: ViemPublicClient,
|
|
34
|
+
addresses: HistoricalLogsContractAddresses,
|
|
35
|
+
skipCheck: boolean,
|
|
36
|
+
bindings?: LoggerBindings,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const logger = createLogger('archiver:validate_historical_logs', bindings);
|
|
39
|
+
logger.debug('Validating historical log availability on L1 RPCs');
|
|
40
|
+
|
|
41
|
+
const urls = getRpcUrlsFromClient(client);
|
|
42
|
+
if (urls.length === 0) {
|
|
43
|
+
logger.warn('Could not determine L1 RPC URLs from the public client; skipping historical logs check.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const chainId = client.chain?.id;
|
|
48
|
+
if (chainId === undefined) {
|
|
49
|
+
logger.warn('Could not determine L1 chain ID from the public client; skipping historical logs check.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const url of urls) {
|
|
54
|
+
const probeClient = getPublicClient({ l1RpcUrls: [url], l1ChainId: chainId });
|
|
55
|
+
const rollup = new RollupContract(probeClient, addresses.rollupAddress.toString());
|
|
56
|
+
const result = await probeRpcUrl(rollup, probeClient, logger);
|
|
57
|
+
|
|
58
|
+
if (result.ok) {
|
|
59
|
+
logger.debug(`L1 RPC ${url} returned historical OwnershipTransferred log for the Rollup contract.`);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const errorMessage = buildErrorMessage(url, result, addresses);
|
|
64
|
+
if (skipCheck) {
|
|
65
|
+
logger.warn(`${errorMessage}\nContinuing because ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK is true.`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
logger.error(errorMessage);
|
|
70
|
+
throw new Error(errorMessage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Runs the OwnershipTransferred probe against a single RPC and queries its client version. */
|
|
75
|
+
async function probeRpcUrl(rollup: RollupContract, client: ViemPublicClient, logger: Logger): Promise<ProbeResult> {
|
|
76
|
+
let queryError: unknown;
|
|
77
|
+
try {
|
|
78
|
+
const logs = await rollup.getOwnershipTransferredEventsAtDeploy();
|
|
79
|
+
if (logs.length > 0) {
|
|
80
|
+
return { ok: true };
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
queryError = err;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const clientVersion = await getClientVersion(client, logger);
|
|
87
|
+
|
|
88
|
+
let reason: string;
|
|
89
|
+
if (queryError instanceof Error) {
|
|
90
|
+
reason = `Query for historical logs failed: ${queryError.message}`;
|
|
91
|
+
} else if (queryError !== undefined) {
|
|
92
|
+
reason = 'Query for historical logs failed with a non-Error value.';
|
|
93
|
+
} else {
|
|
94
|
+
reason = 'No OwnershipTransferred event was returned by the L1 RPC for the Rollup deploy block.';
|
|
95
|
+
}
|
|
96
|
+
return { ok: false, reason, clientVersion };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Builds the operator-facing error message for a failing RPC URL. */
|
|
100
|
+
function buildErrorMessage(
|
|
101
|
+
url: string,
|
|
102
|
+
result: Extract<ProbeResult, { ok: false }>,
|
|
103
|
+
addresses: HistoricalLogsContractAddresses,
|
|
104
|
+
): string {
|
|
105
|
+
return [
|
|
106
|
+
`L1 RPC at ${url} does not return historical logs for the Rollup contract. ${result.reason}`,
|
|
107
|
+
`This likely means this Ethereum RPC node prunes old logs, which would cause the archiver ` +
|
|
108
|
+
`to silently miss data during L1 sync.`,
|
|
109
|
+
result.clientVersion
|
|
110
|
+
? `Detected L1 client version for ${url}: ${result.clientVersion}.`
|
|
111
|
+
: `Could not determine L1 client version for ${url}.`,
|
|
112
|
+
`The following L1 contract addresses must have their historical logs retained by the RPC node:`,
|
|
113
|
+
` - Rollup: ${addresses.rollupAddress.toString()}`,
|
|
114
|
+
` - Inbox: ${addresses.inboxAddress.toString()}`,
|
|
115
|
+
` - Registry: ${addresses.registryAddress.toString()}`,
|
|
116
|
+
` - GovernanceProposer: ${addresses.governanceProposerAddress.toString()}`,
|
|
117
|
+
isReth(result.clientVersion)
|
|
118
|
+
? `To retain logs for these contracts, configure reth with a ` +
|
|
119
|
+
`prune.segments.receipts_log_filter entry for each address above ` +
|
|
120
|
+
`so reth does not prune their receipts/logs. See https://reth.rs/run/pruning.html for details.`
|
|
121
|
+
: `Point this RPC endpoint at a node that retains full log history for the addresses above.`,
|
|
122
|
+
`Set ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK=true to bypass this check at your own risk.`,
|
|
123
|
+
].join('\n');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Queries `web3_clientVersion` on the L1 RPC. Returns undefined if the call fails or returns a non-string. */
|
|
127
|
+
async function getClientVersion(client: ViemPublicClient, logger: Logger): Promise<string | undefined> {
|
|
128
|
+
try {
|
|
129
|
+
const result = await client.request({ method: 'web3_clientVersion' });
|
|
130
|
+
return typeof result === 'string' ? result : undefined;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
logger.debug(`Failed to query web3_clientVersion: ${err instanceof Error ? err.message : err}`);
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Heuristic check for reth based on the web3_clientVersion string (reth returns e.g. "reth/v1.0.0-..."). */
|
|
138
|
+
function isReth(clientVersion: string | undefined): boolean {
|
|
139
|
+
return !!clientVersion && /reth/i.test(clientVersion);
|
|
140
|
+
}
|
|
@@ -6,8 +6,13 @@ import {
|
|
|
6
6
|
ContractInstancePublishedEvent,
|
|
7
7
|
ContractInstanceUpdatedEvent,
|
|
8
8
|
} from '@aztec/protocol-contracts/instance-registry';
|
|
9
|
-
import type { L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
-
import {
|
|
9
|
+
import type { CommitteeAttestation, L2Block, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
|
+
import {
|
|
11
|
+
type L1PublishedData,
|
|
12
|
+
type ProposedCheckpointInput,
|
|
13
|
+
type PublishedCheckpoint,
|
|
14
|
+
validateCheckpoint,
|
|
15
|
+
} from '@aztec/stdlib/checkpoint';
|
|
11
16
|
import {
|
|
12
17
|
type ContractClassPublicWithCommitment,
|
|
13
18
|
computeContractAddressFromInstance,
|
|
@@ -79,18 +84,29 @@ export class ArchiverDataStoreUpdater {
|
|
|
79
84
|
* Adds new checkpoints to the store with contract class/instance extraction from logs.
|
|
80
85
|
* Prunes any local blocks that conflict with checkpoint data (by comparing archive roots).
|
|
81
86
|
* Extracts ContractClassPublished, ContractInstancePublished, ContractInstanceUpdated events from the checkpoint block logs.
|
|
87
|
+
* If `promoteProposed` is supplied, the proposed-checkpoint promotion runs inside the same transaction
|
|
88
|
+
* as the added checkpoints so both updates are applied atomically.
|
|
82
89
|
*
|
|
83
|
-
* @param checkpoints - The published checkpoints to add.
|
|
90
|
+
* @param checkpoints - The published checkpoints to add (excluding any being promoted from proposed).
|
|
84
91
|
* @param pendingChainValidationStatus - Optional validation status to set.
|
|
92
|
+
* @param promoteProposed - Optional promotion of the current proposed checkpoint (fast path when blocks are already local).
|
|
85
93
|
* @returns Result with information about any pruned blocks.
|
|
86
94
|
*/
|
|
87
95
|
public async addCheckpoints(
|
|
88
96
|
checkpoints: PublishedCheckpoint[],
|
|
89
97
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
98
|
+
promoteProposed?: {
|
|
99
|
+
l1: L1PublishedData;
|
|
100
|
+
attestations: CommitteeAttestation[];
|
|
101
|
+
checkpoint: PublishedCheckpoint;
|
|
102
|
+
},
|
|
90
103
|
): Promise<ReconcileCheckpointsResult> {
|
|
91
104
|
for (const checkpoint of checkpoints) {
|
|
92
105
|
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
93
106
|
}
|
|
107
|
+
if (promoteProposed) {
|
|
108
|
+
validateCheckpoint(promoteProposed.checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
109
|
+
}
|
|
94
110
|
|
|
95
111
|
const result = await this.store.transactionAsync(async () => {
|
|
96
112
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
@@ -110,6 +126,14 @@ export class ArchiverDataStoreUpdater {
|
|
|
110
126
|
this.store.addLogs(newBlocks),
|
|
111
127
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
112
128
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
129
|
+
// Promote the proposed checkpoint if requested
|
|
130
|
+
promoteProposed
|
|
131
|
+
? this.store.promoteProposedToCheckpointed(
|
|
132
|
+
promoteProposed.l1,
|
|
133
|
+
promoteProposed.attestations,
|
|
134
|
+
promoteProposed.checkpoint.checkpoint.archive.root,
|
|
135
|
+
)
|
|
136
|
+
: undefined,
|
|
113
137
|
]);
|
|
114
138
|
|
|
115
139
|
await this.l2TipsCache?.refresh();
|
|
@@ -32,6 +32,7 @@ export class ArchiverInstrumentation {
|
|
|
32
32
|
private pruneCount: UpDownCounter;
|
|
33
33
|
|
|
34
34
|
private syncDurationPerBlock: Histogram;
|
|
35
|
+
private syncDurationPerCheckpoint: Histogram;
|
|
35
36
|
private syncBlockCount: UpDownCounter;
|
|
36
37
|
private manaPerBlock: Histogram;
|
|
37
38
|
private txsPerBlock: Histogram;
|
|
@@ -42,6 +43,7 @@ export class ArchiverInstrumentation {
|
|
|
42
43
|
private blockProposalTxTargetCount: UpDownCounter;
|
|
43
44
|
|
|
44
45
|
private checkpointL1InclusionDelay: Histogram;
|
|
46
|
+
private checkpointPromotedCount: UpDownCounter;
|
|
45
47
|
|
|
46
48
|
private log = createLogger('archiver:instrumentation');
|
|
47
49
|
|
|
@@ -68,6 +70,8 @@ export class ArchiverInstrumentation {
|
|
|
68
70
|
|
|
69
71
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
70
72
|
|
|
73
|
+
this.syncDurationPerCheckpoint = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_CHECKPOINT);
|
|
74
|
+
|
|
71
75
|
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
72
76
|
|
|
73
77
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
@@ -92,6 +96,8 @@ export class ArchiverInstrumentation {
|
|
|
92
96
|
|
|
93
97
|
this.checkpointL1InclusionDelay = meter.createHistogram(Metrics.ARCHIVER_CHECKPOINT_L1_INCLUSION_DELAY);
|
|
94
98
|
|
|
99
|
+
this.checkpointPromotedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_CHECKPOINT_PROMOTED_COUNT);
|
|
100
|
+
|
|
95
101
|
this.dbMetrics = new LmdbMetrics(
|
|
96
102
|
meter,
|
|
97
103
|
{
|
|
@@ -113,17 +119,26 @@ export class ArchiverInstrumentation {
|
|
|
113
119
|
return this.telemetry.isEnabled();
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
public
|
|
122
|
+
public processNewProposedBlock(syncTimePerBlock: number, block: L2Block) {
|
|
123
|
+
const attrs = { [Attributes.STATUS]: 'proposed' };
|
|
124
|
+
this.blockHeight.record(block.number, attrs);
|
|
117
125
|
this.syncDurationPerBlock.record(Math.ceil(syncTimePerBlock));
|
|
126
|
+
|
|
127
|
+
// Per block metrics
|
|
128
|
+
this.txCount.add(block.body.txEffects.length);
|
|
129
|
+
this.txsPerBlock.record(block.body.txEffects.length);
|
|
130
|
+
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public processNewCheckpointedBlocks(syncTimePerCheckpoint: number, blocks: L2Block[]) {
|
|
134
|
+
if (blocks.length === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.syncDurationPerCheckpoint.record(Math.ceil(syncTimePerCheckpoint));
|
|
118
139
|
this.blockHeight.record(Math.max(...blocks.map(b => b.number)));
|
|
119
140
|
this.checkpointHeight.record(Math.max(...blocks.map(b => b.checkpointNumber)));
|
|
120
141
|
this.syncBlockCount.add(blocks.length);
|
|
121
|
-
|
|
122
|
-
for (const block of blocks) {
|
|
123
|
-
this.txCount.add(block.body.txEffects.length);
|
|
124
|
-
this.txsPerBlock.record(block.body.txEffects.length);
|
|
125
|
-
this.manaPerBlock.record(block.header.totalManaUsed.toNumber() / 1e6);
|
|
126
|
-
}
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
public processNewMessages(count: number, syncPerMessageMs: number) {
|
|
@@ -169,6 +184,11 @@ export class ArchiverInstrumentation {
|
|
|
169
184
|
});
|
|
170
185
|
}
|
|
171
186
|
|
|
187
|
+
/** Records a checkpoint promoted from proposed (blob fetch skipped). */
|
|
188
|
+
public processCheckpointPromoted() {
|
|
189
|
+
this.checkpointPromotedCount.add(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
172
192
|
/**
|
|
173
193
|
* Records L1 inclusion timing for a checkpoint observed on L1 (seconds into the L2 slot).
|
|
174
194
|
*/
|