@aztec/archiver 0.0.1-commit.0dc957cde → 0.0.1-commit.0ec55a70b
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 +15 -9
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +85 -53
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -2
- package/dest/errors.d.ts +16 -5
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +29 -6
- package/dest/factory.d.ts +4 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +11 -9
- package/dest/index.d.ts +8 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +7 -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 +9 -4
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +42 -0
- package/dest/modules/data_source_base.d.ts +16 -10
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +71 -60
- package/dest/modules/data_store_updater.d.ts +6 -6
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +42 -40
- package/dest/modules/l1_synchronizer.d.ts +5 -4
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +79 -54
- package/dest/modules/validation.d.ts +4 -3
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +4 -4
- package/dest/store/block_store.d.ts +58 -27
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +152 -75
- package/dest/store/contract_class_store.d.ts +17 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +17 -1
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +31 -0
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +50 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.js +1 -1
- package/dest/test/fake_l1_state.d.ts +2 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +25 -8
- package/dest/test/mock_l2_block_source.d.ts +12 -3
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +24 -2
- package/dest/test/noop_l1_archiver.d.ts +4 -4
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -5
- package/package.json +13 -13
- package/src/archiver.ts +91 -49
- package/src/config.ts +2 -1
- package/src/errors.ts +41 -8
- package/src/factory.ts +10 -10
- package/src/index.ts +15 -1
- package/src/l1/calldata_retriever.ts +15 -4
- package/src/modules/contract_data_source_adapter.ts +59 -0
- package/src/modules/data_source_base.ts +75 -57
- package/src/modules/data_store_updater.ts +46 -38
- package/src/modules/l1_synchronizer.ts +92 -60
- package/src/modules/validation.ts +8 -7
- package/src/store/block_store.ts +159 -80
- package/src/store/contract_class_store.ts +28 -2
- package/src/store/contract_instance_store.ts +43 -0
- package/src/store/data_stores.ts +108 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +1 -1
- package/src/test/fake_l1_state.ts +24 -14
- package/src/test/mock_l2_block_source.ts +23 -2
- package/src/test/noop_l1_archiver.ts +6 -6
- package/dest/store/kv_archiver_store.d.ts +0 -383
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -501
- package/src/store/kv_archiver_store.ts +0 -728
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import type { ContractClassLog, PrivateLog, PublicLog } from '@aztec/stdlib/logs';
|
|
22
22
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
23
|
|
|
24
|
-
import type {
|
|
24
|
+
import type { ArchiverDataStores } from '../store/data_stores.js';
|
|
25
25
|
import type { L2TipsCache } from '../store/l2_tips_cache.js';
|
|
26
26
|
|
|
27
27
|
/** Operation type for contract data updates. */
|
|
@@ -43,7 +43,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
43
43
|
private readonly log = createLogger('archiver:store_updater');
|
|
44
44
|
|
|
45
45
|
constructor(
|
|
46
|
-
private
|
|
46
|
+
private stores: ArchiverDataStores,
|
|
47
47
|
private l2TipsCache?: L2TipsCache,
|
|
48
48
|
private opts: { rollupManaLimit?: number } = {},
|
|
49
49
|
) {}
|
|
@@ -61,14 +61,15 @@ export class ArchiverDataStoreUpdater {
|
|
|
61
61
|
block: L2Block,
|
|
62
62
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
63
63
|
): Promise<boolean> {
|
|
64
|
-
const result = await this.
|
|
65
|
-
await this.
|
|
64
|
+
const result = await this.stores.db.transactionAsync(async () => {
|
|
65
|
+
await this.stores.blocks.addProposedBlock(block);
|
|
66
66
|
|
|
67
67
|
const opResults = await Promise.all([
|
|
68
68
|
// Update the pending chain validation status if provided
|
|
69
|
-
pendingChainValidationStatus &&
|
|
69
|
+
pendingChainValidationStatus &&
|
|
70
|
+
this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
70
71
|
// Add any logs emitted during the retrieved block
|
|
71
|
-
this.
|
|
72
|
+
this.stores.logs.addLogs([block]),
|
|
72
73
|
// Unroll all logs emitted during the retrieved block and extract any contract classes and instances from it
|
|
73
74
|
this.addContractDataToDb(block),
|
|
74
75
|
]);
|
|
@@ -100,6 +101,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
100
101
|
attestations: CommitteeAttestation[];
|
|
101
102
|
checkpoint: PublishedCheckpoint;
|
|
102
103
|
},
|
|
104
|
+
evictProposedFrom?: CheckpointNumber,
|
|
103
105
|
): Promise<ReconcileCheckpointsResult> {
|
|
104
106
|
for (const checkpoint of checkpoints) {
|
|
105
107
|
validateCheckpoint(checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
@@ -108,11 +110,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
108
110
|
validateCheckpoint(promoteProposed.checkpoint.checkpoint, { rollupManaLimit: this.opts?.rollupManaLimit });
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
const result = await this.
|
|
113
|
+
const result = await this.stores.db.transactionAsync(async () => {
|
|
112
114
|
// Before adding checkpoints, check for conflicts with local blocks if any
|
|
113
115
|
const { prunedBlocks, lastAlreadyInsertedBlockNumber } = await this.pruneMismatchingLocalBlocks(checkpoints);
|
|
114
116
|
|
|
115
|
-
await this.
|
|
117
|
+
await this.stores.blocks.addCheckpoints(checkpoints);
|
|
116
118
|
|
|
117
119
|
// Filter out blocks that were already inserted via addProposedBlock() to avoid duplicating logs/contract data
|
|
118
120
|
const newBlocks = checkpoints
|
|
@@ -121,19 +123,25 @@ export class ArchiverDataStoreUpdater {
|
|
|
121
123
|
|
|
122
124
|
await Promise.all([
|
|
123
125
|
// Update the pending chain validation status if provided
|
|
124
|
-
pendingChainValidationStatus &&
|
|
126
|
+
pendingChainValidationStatus &&
|
|
127
|
+
this.stores.blocks.setPendingChainValidationStatus(pendingChainValidationStatus),
|
|
125
128
|
// Add any logs emitted during the retrieved blocks
|
|
126
|
-
this.
|
|
129
|
+
this.stores.logs.addLogs(newBlocks),
|
|
127
130
|
// Unroll all logs emitted during the retrieved blocks and extract any contract classes and instances from them
|
|
128
131
|
...newBlocks.map(block => this.addContractDataToDb(block)),
|
|
129
|
-
// Promote the proposed checkpoint if requested
|
|
132
|
+
// Promote the proposed checkpoint if requested (uses explicit checkpoint number)
|
|
130
133
|
promoteProposed
|
|
131
|
-
? this.
|
|
134
|
+
? this.stores.blocks.promoteProposedToCheckpointed(
|
|
135
|
+
promoteProposed.checkpoint.checkpoint.number,
|
|
132
136
|
promoteProposed.l1,
|
|
133
137
|
promoteProposed.attestations,
|
|
134
138
|
promoteProposed.checkpoint.checkpoint.archive.root,
|
|
135
139
|
)
|
|
136
140
|
: undefined,
|
|
141
|
+
// Evict pending checkpoints that diverged from what L1 mined
|
|
142
|
+
evictProposedFrom !== undefined
|
|
143
|
+
? this.stores.blocks.evictProposedCheckpointsFrom(evictProposedFrom)
|
|
144
|
+
: undefined,
|
|
137
145
|
]);
|
|
138
146
|
|
|
139
147
|
await this.l2TipsCache?.refresh();
|
|
@@ -142,9 +150,9 @@ export class ArchiverDataStoreUpdater {
|
|
|
142
150
|
return result;
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
public async
|
|
146
|
-
const result = await this.
|
|
147
|
-
await this.
|
|
153
|
+
public async addProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput) {
|
|
154
|
+
const result = await this.stores.db.transactionAsync(async () => {
|
|
155
|
+
await this.stores.blocks.addProposedCheckpoint(proposedCheckpoint);
|
|
148
156
|
await this.l2TipsCache?.refresh();
|
|
149
157
|
});
|
|
150
158
|
|
|
@@ -159,8 +167,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
159
167
|
*/
|
|
160
168
|
private async pruneMismatchingLocalBlocks(checkpoints: PublishedCheckpoint[]): Promise<ReconcileCheckpointsResult> {
|
|
161
169
|
const [lastCheckpointedBlockNumber, lastBlockNumber] = await Promise.all([
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
170
|
+
this.stores.blocks.getCheckpointedL2BlockNumber(),
|
|
171
|
+
this.stores.blocks.getLatestL2BlockNumber(),
|
|
164
172
|
]);
|
|
165
173
|
|
|
166
174
|
// Exit early if there are no local uncheckpointed blocks
|
|
@@ -169,7 +177,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
// Get all uncheckpointed local blocks
|
|
172
|
-
const uncheckpointedLocalBlocks = await this.
|
|
180
|
+
const uncheckpointedLocalBlocks = await this.stores.blocks.getBlocks(
|
|
173
181
|
BlockNumber.add(lastCheckpointedBlockNumber, 1),
|
|
174
182
|
lastBlockNumber - lastCheckpointedBlockNumber,
|
|
175
183
|
);
|
|
@@ -234,9 +242,9 @@ export class ArchiverDataStoreUpdater {
|
|
|
234
242
|
* @throws Error if any block to be removed is checkpointed.
|
|
235
243
|
*/
|
|
236
244
|
public async removeUncheckpointedBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
237
|
-
const result = await this.
|
|
245
|
+
const result = await this.stores.db.transactionAsync(async () => {
|
|
238
246
|
// Verify we're only removing uncheckpointed blocks
|
|
239
|
-
const lastCheckpointedBlockNumber = await this.
|
|
247
|
+
const lastCheckpointedBlockNumber = await this.stores.blocks.getCheckpointedL2BlockNumber();
|
|
240
248
|
if (blockNumber < lastCheckpointedBlockNumber) {
|
|
241
249
|
throw new Error(
|
|
242
250
|
`Cannot remove blocks after ${blockNumber} because checkpointed blocks exist up to ${lastCheckpointedBlockNumber}`,
|
|
@@ -245,8 +253,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
245
253
|
|
|
246
254
|
const result = await this.removeBlocksAfter(blockNumber);
|
|
247
255
|
|
|
248
|
-
// Clear
|
|
249
|
-
await this.
|
|
256
|
+
// Clear all pending proposed checkpoints since their blocks have been pruned
|
|
257
|
+
await this.stores.blocks.deleteProposedCheckpoints();
|
|
250
258
|
|
|
251
259
|
await this.l2TipsCache?.refresh();
|
|
252
260
|
return result;
|
|
@@ -260,11 +268,11 @@ export class ArchiverDataStoreUpdater {
|
|
|
260
268
|
*/
|
|
261
269
|
private async removeBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
262
270
|
// First get the blocks to be removed so we can clean up contract data
|
|
263
|
-
const removedBlocks = await this.
|
|
271
|
+
const removedBlocks = await this.stores.blocks.removeBlocksAfter(blockNumber);
|
|
264
272
|
|
|
265
273
|
// Clean up contract data and logs for the removed blocks
|
|
266
274
|
await Promise.all([
|
|
267
|
-
this.
|
|
275
|
+
this.stores.logs.deleteLogs(removedBlocks),
|
|
268
276
|
...removedBlocks.map(block => this.removeContractDataFromDb(block)),
|
|
269
277
|
]);
|
|
270
278
|
|
|
@@ -281,15 +289,15 @@ export class ArchiverDataStoreUpdater {
|
|
|
281
289
|
* @returns True if the operation is successful.
|
|
282
290
|
*/
|
|
283
291
|
public async removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
284
|
-
return await this.
|
|
285
|
-
const { blocksRemoved = [] } = await this.
|
|
292
|
+
return await this.stores.db.transactionAsync(async () => {
|
|
293
|
+
const { blocksRemoved = [] } = await this.stores.blocks.removeCheckpointsAfter(checkpointNumber);
|
|
286
294
|
|
|
287
295
|
const opResults = await Promise.all([
|
|
288
296
|
// Prune rolls back to the last proven block, which is by definition valid
|
|
289
|
-
this.
|
|
297
|
+
this.stores.blocks.setPendingChainValidationStatus({ valid: true }),
|
|
290
298
|
// Remove contract data for all blocks being removed
|
|
291
299
|
...blocksRemoved.map(block => this.removeContractDataFromDb(block)),
|
|
292
|
-
this.
|
|
300
|
+
this.stores.logs.deleteLogs(blocksRemoved),
|
|
293
301
|
]);
|
|
294
302
|
|
|
295
303
|
await this.l2TipsCache?.refresh();
|
|
@@ -302,8 +310,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
302
310
|
* @param checkpointNumber - The checkpoint number to set as proven.
|
|
303
311
|
*/
|
|
304
312
|
public async setProvenCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
305
|
-
await this.
|
|
306
|
-
await this.
|
|
313
|
+
await this.stores.db.transactionAsync(async () => {
|
|
314
|
+
await this.stores.blocks.setProvenCheckpointNumber(checkpointNumber);
|
|
307
315
|
await this.l2TipsCache?.refresh();
|
|
308
316
|
});
|
|
309
317
|
}
|
|
@@ -313,8 +321,8 @@ export class ArchiverDataStoreUpdater {
|
|
|
313
321
|
* @param checkpointNumber - The checkpoint number to set as finalized.
|
|
314
322
|
*/
|
|
315
323
|
public async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
316
|
-
await this.
|
|
317
|
-
await this.
|
|
324
|
+
await this.stores.db.transactionAsync(async () => {
|
|
325
|
+
await this.stores.blocks.setFinalizedCheckpointNumber(checkpointNumber);
|
|
318
326
|
await this.l2TipsCache?.refresh();
|
|
319
327
|
});
|
|
320
328
|
}
|
|
@@ -360,7 +368,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
360
368
|
const contractClasses = contractClassPublishedEvents.map(e => e.toContractClassPublic());
|
|
361
369
|
if (contractClasses.length > 0) {
|
|
362
370
|
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
363
|
-
return await this.
|
|
371
|
+
return await this.stores.contractClasses.deleteContractClasses(contractClasses, blockNum);
|
|
364
372
|
}
|
|
365
373
|
return true;
|
|
366
374
|
}
|
|
@@ -386,7 +394,7 @@ export class ArchiverDataStoreUpdater {
|
|
|
386
394
|
|
|
387
395
|
if (contractClasses.length > 0) {
|
|
388
396
|
contractClasses.forEach(c => this.log.verbose(`${Operation[operation]} contract class ${c.id.toString()}`));
|
|
389
|
-
return await this.
|
|
397
|
+
return await this.stores.contractClasses.addContractClasses(contractClasses, blockNum);
|
|
390
398
|
}
|
|
391
399
|
return true;
|
|
392
400
|
}
|
|
@@ -425,9 +433,9 @@ export class ArchiverDataStoreUpdater {
|
|
|
425
433
|
this.log.verbose(`${Operation[operation]} contract instance at ${c.address.toString()}`),
|
|
426
434
|
);
|
|
427
435
|
if (operation == Operation.Store) {
|
|
428
|
-
return await this.
|
|
436
|
+
return await this.stores.contractInstances.addContractInstances(contractInstances, blockNum);
|
|
429
437
|
} else if (operation == Operation.Delete) {
|
|
430
|
-
return await this.
|
|
438
|
+
return await this.stores.contractInstances.deleteContractInstances(contractInstances);
|
|
431
439
|
}
|
|
432
440
|
}
|
|
433
441
|
return true;
|
|
@@ -451,9 +459,9 @@ export class ArchiverDataStoreUpdater {
|
|
|
451
459
|
this.log.verbose(`${Operation[operation]} contract instance update at ${c.address.toString()}`),
|
|
452
460
|
);
|
|
453
461
|
if (operation == Operation.Store) {
|
|
454
|
-
return await this.
|
|
462
|
+
return await this.stores.contractInstances.addContractInstanceUpdates(contractUpdates, timestamp);
|
|
455
463
|
} else if (operation == Operation.Delete) {
|
|
456
|
-
return await this.
|
|
464
|
+
return await this.stores.contractInstances.deleteContractInstanceUpdates(contractUpdates, timestamp);
|
|
457
465
|
}
|
|
458
466
|
}
|
|
459
467
|
return true;
|