@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/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,
|
|
@@ -19,19 +19,20 @@ import {
|
|
|
19
19
|
type L2Tips,
|
|
20
20
|
type ValidateCheckpointResult,
|
|
21
21
|
} from '@aztec/stdlib/block';
|
|
22
|
-
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
22
|
+
import { type ProposedCheckpointInput, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
23
23
|
import {
|
|
24
24
|
type L1RollupConstants,
|
|
25
|
-
|
|
25
|
+
getEpochAtSlot,
|
|
26
26
|
getSlotAtNextL1Block,
|
|
27
|
-
getSlotAtTimestamp,
|
|
28
27
|
getSlotRangeForEpoch,
|
|
28
|
+
getTimestampForSlot,
|
|
29
29
|
getTimestampRangeForEpoch,
|
|
30
30
|
} from '@aztec/stdlib/epoch-helpers';
|
|
31
31
|
import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
32
32
|
|
|
33
33
|
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
|
|
34
|
-
import { NoBlobBodiesFoundError } from './errors.js';
|
|
34
|
+
import { BlockAlreadyCheckpointedError, BlockOrCheckpointSlotExpiredError, NoBlobBodiesFoundError } from './errors.js';
|
|
35
|
+
import { validateAndLogHistoricalLogsAvailability } from './l1/validate_historical_logs.js';
|
|
35
36
|
import { validateAndLogTraceAvailability } from './l1/validate_trace.js';
|
|
36
37
|
import { ArchiverDataSourceBase } from './modules/data_source_base.js';
|
|
37
38
|
import { ArchiverDataStoreUpdater } from './modules/data_store_updater.js';
|
|
@@ -45,11 +46,20 @@ export type { ArchiverEmitter };
|
|
|
45
46
|
|
|
46
47
|
/** Request to add a block to the archiver, queued for processing by the sync loop. */
|
|
47
48
|
type AddBlockRequest = {
|
|
49
|
+
type: 'block';
|
|
48
50
|
block: L2Block;
|
|
49
51
|
resolve: () => void;
|
|
50
52
|
reject: (err: Error) => void;
|
|
51
53
|
};
|
|
52
54
|
|
|
55
|
+
/** Request to add a proposed checkpoint to the archiver, queued for processing by the sync loop. */
|
|
56
|
+
type AddProposedCheckpointRequest = {
|
|
57
|
+
type: 'checkpoint';
|
|
58
|
+
checkpoint: ProposedCheckpointInput;
|
|
59
|
+
resolve: () => void;
|
|
60
|
+
reject: (err: Error) => void;
|
|
61
|
+
};
|
|
62
|
+
|
|
53
63
|
export type ArchiverDeps = {
|
|
54
64
|
telemetry?: TelemetryClient;
|
|
55
65
|
blobClient: BlobClientInterface;
|
|
@@ -75,8 +85,8 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
75
85
|
private initialSyncComplete: boolean = false;
|
|
76
86
|
private initialSyncPromise: PromiseWithResolvers<void>;
|
|
77
87
|
|
|
78
|
-
/** Queue of blocks to be added to the store, processed by the sync loop. */
|
|
79
|
-
private
|
|
88
|
+
/** Queue of blocks and checkpoints to be added to the store, processed by the sync loop. */
|
|
89
|
+
private inboundQueue: (AddBlockRequest | AddProposedCheckpointRequest)[] = [];
|
|
80
90
|
|
|
81
91
|
/** Helper to handle updates to the store */
|
|
82
92
|
private readonly updater: ArchiverDataStoreUpdater;
|
|
@@ -86,17 +96,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
86
96
|
|
|
87
97
|
public readonly tracer: Tracer;
|
|
88
98
|
|
|
99
|
+
private readonly instrumentation: ArchiverInstrumentation;
|
|
100
|
+
|
|
89
101
|
/**
|
|
90
102
|
* Creates a new instance of the Archiver.
|
|
91
103
|
* @param publicClient - A client for interacting with the Ethereum node.
|
|
92
104
|
* @param debugClient - A client for interacting with the Ethereum node for debug/trace methods.
|
|
93
105
|
* @param rollup - Rollup contract instance.
|
|
94
106
|
* @param inbox - Inbox contract instance.
|
|
95
|
-
* @param l1Addresses - L1 contract addresses (registry, governance proposer,
|
|
107
|
+
* @param l1Addresses - L1 contract addresses (registry, governance proposer, slashing proposer).
|
|
96
108
|
* @param dataStore - An archiver data store for storage & retrieval of blocks, encrypted logs & contract data.
|
|
97
109
|
* @param config - Archiver configuration options.
|
|
98
110
|
* @param blobClient - Client for retrieving blob data.
|
|
99
|
-
* @param epochCache - Cache for epoch-related data.
|
|
100
111
|
* @param dateProvider - Provider for current date/time.
|
|
101
112
|
* @param instrumentation - Instrumentation for metrics and tracing.
|
|
102
113
|
* @param l1Constants - L1 rollup constants.
|
|
@@ -108,8 +119,10 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
108
119
|
private readonly rollup: RollupContract,
|
|
109
120
|
private readonly l1Addresses: Pick<
|
|
110
121
|
L1ContractAddresses,
|
|
111
|
-
'registryAddress' | '
|
|
112
|
-
> & {
|
|
122
|
+
'rollupAddress' | 'registryAddress' | 'inboxAddress' | 'governanceProposerAddress'
|
|
123
|
+
> & {
|
|
124
|
+
slashingProposerAddress: EthAddress;
|
|
125
|
+
},
|
|
113
126
|
readonly dataStore: KVArchiverDataStore,
|
|
114
127
|
private config: {
|
|
115
128
|
pollingIntervalMs: number;
|
|
@@ -117,10 +130,14 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
117
130
|
skipValidateCheckpointAttestations?: boolean;
|
|
118
131
|
maxAllowedEthClientDriftSeconds: number;
|
|
119
132
|
ethereumAllowNoDebugHosts?: boolean;
|
|
133
|
+
skipHistoricalLogsCheck?: boolean;
|
|
120
134
|
},
|
|
121
135
|
private readonly blobClient: BlobClientInterface,
|
|
122
136
|
instrumentation: ArchiverInstrumentation,
|
|
123
|
-
protected override readonly l1Constants: L1RollupConstants & {
|
|
137
|
+
protected override readonly l1Constants: L1RollupConstants & {
|
|
138
|
+
l1StartBlockHash: Buffer32;
|
|
139
|
+
genesisArchiveRoot: Fr;
|
|
140
|
+
},
|
|
124
141
|
synchronizer: ArchiverL1Synchronizer,
|
|
125
142
|
events: ArchiverEmitter,
|
|
126
143
|
l2TipsCache?: L2TipsCache,
|
|
@@ -129,11 +146,14 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
129
146
|
super(dataStore, l1Constants);
|
|
130
147
|
|
|
131
148
|
this.tracer = instrumentation.tracer;
|
|
149
|
+
this.instrumentation = instrumentation;
|
|
132
150
|
this.initialSyncPromise = promiseWithResolvers();
|
|
133
151
|
this.synchronizer = synchronizer;
|
|
134
152
|
this.events = events;
|
|
135
153
|
this.l2TipsCache = l2TipsCache ?? new L2TipsCache(this.dataStore.blockStore);
|
|
136
|
-
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache
|
|
154
|
+
this.updater = new ArchiverDataStoreUpdater(this.dataStore, this.l2TipsCache, {
|
|
155
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
156
|
+
});
|
|
137
157
|
|
|
138
158
|
// Running promise starts with a small interval inbetween runs, so all iterations needed for the initial sync
|
|
139
159
|
// are done as fast as possible. This then gets updated once the initial sync completes.
|
|
@@ -167,6 +187,17 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
167
187
|
this.config.ethereumAllowNoDebugHosts ?? false,
|
|
168
188
|
this.log.getBindings(),
|
|
169
189
|
);
|
|
190
|
+
await validateAndLogHistoricalLogsAvailability(
|
|
191
|
+
this.publicClient,
|
|
192
|
+
{
|
|
193
|
+
rollupAddress: this.l1Addresses.rollupAddress,
|
|
194
|
+
inboxAddress: this.l1Addresses.inboxAddress,
|
|
195
|
+
registryAddress: this.l1Addresses.registryAddress,
|
|
196
|
+
governanceProposerAddress: this.l1Addresses.governanceProposerAddress,
|
|
197
|
+
},
|
|
198
|
+
this.config.skipHistoricalLogsCheck ?? false,
|
|
199
|
+
this.log.getBindings(),
|
|
200
|
+
);
|
|
170
201
|
|
|
171
202
|
// Log initial state for the archiver
|
|
172
203
|
const { l1StartBlock } = this.l1Constants;
|
|
@@ -188,6 +219,14 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
188
219
|
return this.runningPromise.trigger();
|
|
189
220
|
}
|
|
190
221
|
|
|
222
|
+
public trySyncImmediate() {
|
|
223
|
+
try {
|
|
224
|
+
return this.syncImmediate();
|
|
225
|
+
} catch (err) {
|
|
226
|
+
this.log.error(`Failed to trigger immediate archiver sync: ${err}`, err);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
191
230
|
/**
|
|
192
231
|
* Queues a block to be added to the archiver store and triggers processing.
|
|
193
232
|
* The block will be processed by the sync loop.
|
|
@@ -196,53 +235,85 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
196
235
|
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
197
236
|
*/
|
|
198
237
|
public addBlock(block: L2Block): Promise<void> {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
238
|
+
const promise = promiseWithResolvers<void>();
|
|
239
|
+
this.inboundQueue.push({ block, ...promise, type: 'block' });
|
|
240
|
+
this.log.debug(`Queued block ${block.number} for processing`);
|
|
241
|
+
void this.trySyncImmediate();
|
|
242
|
+
return promise.promise;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Queues a new proposed checkpoint into the archiver store.
|
|
247
|
+
* Checks that the checkpoint is not for an L2 slot already synced from L1.
|
|
248
|
+
* Resolves once the checkpoint has been processed.
|
|
249
|
+
*/
|
|
250
|
+
public addProposedCheckpoint(pending: ProposedCheckpointInput): Promise<void> {
|
|
251
|
+
const promise = promiseWithResolvers<void>();
|
|
252
|
+
this.inboundQueue.push({ checkpoint: pending, ...promise, type: 'checkpoint' });
|
|
253
|
+
this.log.debug(`Queued checkpoint ${pending.checkpointNumber} for processing`);
|
|
254
|
+
void this.trySyncImmediate();
|
|
255
|
+
return promise.promise;
|
|
207
256
|
}
|
|
208
257
|
|
|
209
258
|
/**
|
|
210
|
-
* Processes all queued blocks, adding them to the store.
|
|
259
|
+
* Processes all queued blocks and checkpoints, adding them to the store.
|
|
211
260
|
* Called at the beginning of each sync iteration.
|
|
212
|
-
*
|
|
261
|
+
* Items are processed in the order they were queued.
|
|
213
262
|
*/
|
|
214
|
-
private async
|
|
215
|
-
if (this.
|
|
263
|
+
private async processInboundQueue(): Promise<void> {
|
|
264
|
+
if (this.inboundQueue.length === 0) {
|
|
216
265
|
return;
|
|
217
266
|
}
|
|
218
267
|
|
|
219
|
-
// Take all
|
|
220
|
-
const queuedItems = this.
|
|
221
|
-
this.log.debug(`Processing ${queuedItems.length} queued
|
|
268
|
+
// Take all items from the queue
|
|
269
|
+
const queuedItems = this.inboundQueue.splice(0, this.inboundQueue.length);
|
|
270
|
+
this.log.debug(`Processing ${queuedItems.length} queued inbound items`);
|
|
222
271
|
|
|
223
272
|
// Calculate slot threshold for validation
|
|
224
273
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
225
274
|
const slotAtNextL1Block =
|
|
226
275
|
l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
227
276
|
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
277
|
+
// Helpers for manipulating blocks and checkpoints in the queue
|
|
278
|
+
const getSlot: (item: AddBlockRequest | AddProposedCheckpointRequest) => SlotNumber = item =>
|
|
279
|
+
item.type === 'block' ? item.block.header.globalVariables.slotNumber : item.checkpoint.header.slotNumber;
|
|
280
|
+
const getNumber: (item: AddBlockRequest | AddProposedCheckpointRequest) => number = item =>
|
|
281
|
+
item.type === 'block' ? item.block.number : item.checkpoint.checkpointNumber;
|
|
282
|
+
|
|
283
|
+
// Process each item individually to properly resolve/reject each promise
|
|
284
|
+
for (const item of queuedItems) {
|
|
285
|
+
const { resolve, reject, type } = item;
|
|
286
|
+
const itemSlot = getSlot(item);
|
|
287
|
+
const itemNumber = getNumber(item);
|
|
288
|
+
if (slotAtNextL1Block !== undefined && itemSlot < slotAtNextL1Block) {
|
|
289
|
+
const nextSlotTimestamp = getTimestampForSlot(slotAtNextL1Block, this.l1Constants);
|
|
232
290
|
this.log.warn(
|
|
233
|
-
`Rejecting proposed
|
|
234
|
-
{
|
|
291
|
+
`Rejecting proposed ${type} ${itemNumber} for past slot ${itemSlot} (current ${slotAtNextL1Block})`,
|
|
292
|
+
{ number: itemNumber, type, l1Timestamp, slotAtNextL1Block, nextSlotTimestamp },
|
|
235
293
|
);
|
|
236
|
-
reject(new
|
|
294
|
+
reject(new BlockOrCheckpointSlotExpiredError(itemSlot, nextSlotTimestamp, l1Timestamp));
|
|
237
295
|
continue;
|
|
238
296
|
}
|
|
239
297
|
|
|
240
298
|
try {
|
|
241
|
-
|
|
242
|
-
|
|
299
|
+
if (type === 'block') {
|
|
300
|
+
const [durationMs] = await elapsed(() => this.updater.addProposedBlock(item.block));
|
|
301
|
+
this.instrumentation.processNewProposedBlock(durationMs, item.block);
|
|
302
|
+
} else {
|
|
303
|
+
await this.updater.addProposedCheckpoint(item.checkpoint);
|
|
304
|
+
}
|
|
305
|
+
this.log.debug(`Added ${type} ${itemNumber} to store`);
|
|
243
306
|
resolve();
|
|
244
307
|
} catch (err: any) {
|
|
245
|
-
|
|
308
|
+
if (err instanceof BlockAlreadyCheckpointedError) {
|
|
309
|
+
this.log.debug(`Proposed block ${itemNumber} matches already checkpointed block, ignoring late proposal`);
|
|
310
|
+
resolve();
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
this.log.error(`Failed to add ${type} ${itemNumber} to store: ${err.message}`, err, {
|
|
314
|
+
number: itemNumber,
|
|
315
|
+
type,
|
|
316
|
+
});
|
|
246
317
|
reject(err);
|
|
247
318
|
}
|
|
248
319
|
}
|
|
@@ -258,7 +329,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
258
329
|
@trackSpan('Archiver.sync')
|
|
259
330
|
private async sync() {
|
|
260
331
|
// Process any queued blocks first, before doing L1 sync
|
|
261
|
-
await this.
|
|
332
|
+
await this.processInboundQueue();
|
|
262
333
|
// Now perform L1 sync
|
|
263
334
|
await this.syncFromL1();
|
|
264
335
|
}
|
|
@@ -333,16 +404,49 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
333
404
|
return Promise.resolve(this.synchronizer.getL1Timestamp());
|
|
334
405
|
}
|
|
335
406
|
|
|
336
|
-
public
|
|
407
|
+
public async getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
408
|
+
// The synced L2 slot is the latest slot for which we have all L1 data,
|
|
409
|
+
// either because we have seen all L1 blocks for that slot, or because
|
|
410
|
+
// we have seen the corresponding checkpoint.
|
|
411
|
+
|
|
412
|
+
let slotFromL1Sync: SlotNumber | undefined;
|
|
337
413
|
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
338
|
-
|
|
414
|
+
if (l1Timestamp !== undefined) {
|
|
415
|
+
const nextL1BlockSlot = getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
416
|
+
if (Number(nextL1BlockSlot) > 0) {
|
|
417
|
+
slotFromL1Sync = SlotNumber.add(nextL1BlockSlot, -1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let slotFromCheckpoint: SlotNumber | undefined;
|
|
422
|
+
const latestCheckpointNumber = await this.store.getSynchedCheckpointNumber();
|
|
423
|
+
if (latestCheckpointNumber > 0) {
|
|
424
|
+
const checkpointData = await this.store.getCheckpointData(latestCheckpointNumber);
|
|
425
|
+
if (checkpointData) {
|
|
426
|
+
slotFromCheckpoint = checkpointData.header.slotNumber;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (slotFromL1Sync === undefined && slotFromCheckpoint === undefined) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
return SlotNumber(Math.max(slotFromL1Sync ?? 0, slotFromCheckpoint ?? 0));
|
|
339
434
|
}
|
|
340
435
|
|
|
341
|
-
public
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
436
|
+
public async getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
437
|
+
const syncedSlot = await this.getSyncedL2SlotNumber();
|
|
438
|
+
if (syncedSlot === undefined) {
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
// An epoch is fully synced when all its slots are synced.
|
|
442
|
+
// We check if syncedSlot is the last slot of its epoch; if so, that epoch is fully synced.
|
|
443
|
+
// Otherwise, only the previous epoch is fully synced.
|
|
444
|
+
const epoch = getEpochAtSlot(syncedSlot, this.l1Constants);
|
|
445
|
+
const [, endSlot] = getSlotRangeForEpoch(epoch, this.l1Constants);
|
|
446
|
+
if (syncedSlot >= endSlot) {
|
|
447
|
+
return epoch;
|
|
448
|
+
}
|
|
449
|
+
return Number(epoch) > 0 ? EpochNumber(Number(epoch) - 1) : undefined;
|
|
346
450
|
}
|
|
347
451
|
|
|
348
452
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -399,7 +503,6 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
399
503
|
}
|
|
400
504
|
|
|
401
505
|
public async rollbackTo(targetL2BlockNumber: BlockNumber): Promise<void> {
|
|
402
|
-
// TODO(pw/mbps): This still assumes 1 block per checkpoint
|
|
403
506
|
const currentBlocks = await this.getL2Tips();
|
|
404
507
|
const currentL2Block = currentBlocks.proposed.number;
|
|
405
508
|
const currentProvenBlock = currentBlocks.proven.block.number;
|
|
@@ -411,8 +514,25 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
411
514
|
if (!targetL2Block) {
|
|
412
515
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
413
516
|
}
|
|
414
|
-
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
415
517
|
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
518
|
+
|
|
519
|
+
// Rollback operates at checkpoint granularity: the target block must be the last block of its checkpoint.
|
|
520
|
+
const checkpointData = await this.store.getCheckpointData(targetCheckpointNumber);
|
|
521
|
+
if (checkpointData) {
|
|
522
|
+
const lastBlockInCheckpoint = BlockNumber(checkpointData.startBlock + checkpointData.blockCount - 1);
|
|
523
|
+
if (targetL2BlockNumber !== lastBlockInCheckpoint) {
|
|
524
|
+
const previousCheckpointBoundary =
|
|
525
|
+
checkpointData.startBlock > 1 ? BlockNumber(checkpointData.startBlock - 1) : BlockNumber(0);
|
|
526
|
+
throw new Error(
|
|
527
|
+
`Target L2 block ${targetL2BlockNumber} is not at a checkpoint boundary. ` +
|
|
528
|
+
`Checkpoint ${targetCheckpointNumber} spans blocks ${checkpointData.startBlock} to ${lastBlockInCheckpoint}. ` +
|
|
529
|
+
`Use block ${lastBlockInCheckpoint} to roll back to this checkpoint, ` +
|
|
530
|
+
`or block ${previousCheckpointBoundary} to roll back to the previous one.`,
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
416
536
|
const targetL1Block = await this.publicClient.getBlock({
|
|
417
537
|
blockNumber: targetL1BlockNumber,
|
|
418
538
|
includeTransactions: false,
|
|
@@ -429,15 +549,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
429
549
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
430
550
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
431
551
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
|
432
|
-
await this.store.
|
|
552
|
+
await this.store.setMessageSyncState(
|
|
553
|
+
{ l1BlockNumber: targetL1BlockNumber, l1BlockHash: targetL1BlockHash },
|
|
554
|
+
undefined,
|
|
555
|
+
);
|
|
433
556
|
if (targetL2BlockNumber < currentProvenBlock) {
|
|
434
|
-
this.log.info(`
|
|
435
|
-
await this.updater.setProvenCheckpointNumber(
|
|
557
|
+
this.log.info(`Rolling back proven L2 checkpoint to ${targetCheckpointNumber}`);
|
|
558
|
+
await this.updater.setProvenCheckpointNumber(targetCheckpointNumber);
|
|
559
|
+
}
|
|
560
|
+
const currentFinalizedBlock = currentBlocks.finalized.block.number;
|
|
561
|
+
if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
562
|
+
this.log.info(`Rolling back finalized L2 checkpoint to ${targetCheckpointNumber}`);
|
|
563
|
+
await this.updater.setFinalizedCheckpointNumber(targetCheckpointNumber);
|
|
436
564
|
}
|
|
437
|
-
// TODO(palla/reorg): Set the finalized block when we add support for it.
|
|
438
|
-
// if (targetL2BlockNumber < currentFinalizedBlock) {
|
|
439
|
-
// this.log.info(`Clearing finalized L2 block number`);
|
|
440
|
-
// await this.store.setFinalizedL2BlockNumber(0);
|
|
441
|
-
// }
|
|
442
565
|
}
|
|
443
566
|
}
|
package/src/config.ts
CHANGED
|
@@ -7,8 +7,14 @@ import {
|
|
|
7
7
|
booleanConfigHelper,
|
|
8
8
|
getConfigFromMappings,
|
|
9
9
|
numberConfigHelper,
|
|
10
|
+
optionalNumberConfigHelper,
|
|
10
11
|
} from '@aztec/foundation/config';
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type ChainConfig,
|
|
14
|
+
type PipelineConfig,
|
|
15
|
+
chainConfigMappings,
|
|
16
|
+
pipelineConfigMappings,
|
|
17
|
+
} from '@aztec/stdlib/config';
|
|
12
18
|
import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
19
|
|
|
14
20
|
/**
|
|
@@ -21,11 +27,13 @@ import type { ArchiverSpecificConfig } from '@aztec/stdlib/interfaces/server';
|
|
|
21
27
|
export type ArchiverConfig = ArchiverSpecificConfig &
|
|
22
28
|
L1ReaderConfig &
|
|
23
29
|
L1ContractsConfig &
|
|
30
|
+
PipelineConfig & // required to pass through to epoch cache
|
|
24
31
|
BlobClientConfig &
|
|
25
32
|
ChainConfig;
|
|
26
33
|
|
|
27
34
|
export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
28
35
|
...blobClientConfigMapping,
|
|
36
|
+
...pipelineConfigMappings,
|
|
29
37
|
archiverPollingIntervalMS: {
|
|
30
38
|
env: 'ARCHIVER_POLLING_INTERVAL_MS',
|
|
31
39
|
description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
|
|
@@ -43,13 +51,17 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
43
51
|
},
|
|
44
52
|
archiverStoreMapSizeKb: {
|
|
45
53
|
env: 'ARCHIVER_STORE_MAP_SIZE_KB',
|
|
46
|
-
|
|
54
|
+
...optionalNumberConfigHelper(),
|
|
47
55
|
description: 'The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
48
56
|
},
|
|
49
57
|
skipValidateCheckpointAttestations: {
|
|
50
58
|
description: 'Skip validating checkpoint attestations (for testing purposes only)',
|
|
51
59
|
...booleanConfigHelper(false),
|
|
52
60
|
},
|
|
61
|
+
skipPromoteProposedCheckpointDuringL1Sync: {
|
|
62
|
+
description: 'Skip promoting proposed checkpoints during L1 sync (for testing purposes only)',
|
|
63
|
+
...booleanConfigHelper(false),
|
|
64
|
+
},
|
|
53
65
|
maxAllowedEthClientDriftSeconds: {
|
|
54
66
|
env: 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS',
|
|
55
67
|
description: 'Maximum allowed drift in seconds between the Ethereum client and current time.',
|
|
@@ -60,6 +72,13 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
60
72
|
description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
|
|
61
73
|
...booleanConfigHelper(true),
|
|
62
74
|
},
|
|
75
|
+
archiverSkipHistoricalLogsCheck: {
|
|
76
|
+
env: 'ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK',
|
|
77
|
+
description:
|
|
78
|
+
'Skip the startup check that probes the L1 RPC for historical Rollup contract logs. ' +
|
|
79
|
+
'Set to true to bypass the check when the connected RPC node is known to prune old logs.',
|
|
80
|
+
...booleanConfigHelper(false),
|
|
81
|
+
},
|
|
63
82
|
...chainConfigMappings,
|
|
64
83
|
...l1ReaderConfigMappings,
|
|
65
84
|
viemPollingIntervalMS: {
|
|
@@ -89,7 +108,9 @@ export function mapArchiverConfig(config: Partial<ArchiverConfig>) {
|
|
|
89
108
|
pollingIntervalMs: config.archiverPollingIntervalMS,
|
|
90
109
|
batchSize: config.archiverBatchSize,
|
|
91
110
|
skipValidateCheckpointAttestations: config.skipValidateCheckpointAttestations,
|
|
111
|
+
skipPromoteProposedCheckpointDuringL1Sync: config.skipPromoteProposedCheckpointDuringL1Sync,
|
|
92
112
|
maxAllowedEthClientDriftSeconds: config.maxAllowedEthClientDriftSeconds,
|
|
93
113
|
ethereumAllowNoDebugHosts: config.ethereumAllowNoDebugHosts,
|
|
114
|
+
skipHistoricalLogsCheck: config.archiverSkipHistoricalLogsCheck,
|
|
94
115
|
};
|
|
95
116
|
}
|