@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +21 -6
- package/dest/archiver.d.ts +17 -12
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +108 -127
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -2
- package/dest/errors.d.ts +39 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +52 -15
- package/dest/factory.d.ts +4 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -23
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +38 -37
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +29 -23
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +55 -124
- package/dest/modules/data_store_updater.d.ts +43 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +158 -129
- package/dest/modules/instrumentation.d.ts +19 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +53 -18
- package/dest/modules/l1_synchronizer.d.ts +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +186 -145
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +86 -34
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +414 -152
- 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 +16 -72
- 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 +80 -39
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +86 -35
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- package/dest/store/log_store.d.ts +9 -6
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +151 -56
- 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 +24 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- 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 +44 -23
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +185 -115
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +24 -10
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +71 -0
- package/package.json +14 -13
- package/src/archiver.ts +144 -159
- package/src/config.ts +9 -2
- package/src/errors.ts +82 -26
- package/src/factory.ts +46 -22
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +35 -41
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +98 -169
- package/src/modules/data_store_updater.ts +178 -160
- package/src/modules/instrumentation.ts +64 -20
- package/src/modules/l1_synchronizer.ts +212 -182
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +533 -207
- package/src/store/contract_class_store.ts +16 -110
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +141 -59
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +232 -74
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +180 -32
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +247 -130
- package/src/test/mock_structs.ts +45 -15
- package/src/test/noop_l1_archiver.ts +114 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
4
|
import { join } from 'path';
|
|
6
5
|
import { BlockStore } from './block_store.js';
|
|
7
6
|
import { ContractClassStore } from './contract_class_store.js';
|
|
8
7
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
9
8
|
import { LogStore } from './log_store.js';
|
|
10
9
|
import { MessageStore } from './message_store.js';
|
|
11
|
-
export const ARCHIVER_DB_VERSION =
|
|
10
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
12
11
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
13
12
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
14
13
|
/**
|
|
@@ -34,6 +33,9 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
34
33
|
this.#contractClassStore = new ContractClassStore(db);
|
|
35
34
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
36
35
|
}
|
|
36
|
+
/** Returns the underlying block store. Used by L2TipsCache. */ get blockStore() {
|
|
37
|
+
return this.#blockStore;
|
|
38
|
+
}
|
|
37
39
|
/** Opens a new transaction to the underlying store and runs all operations within it. */ transactionAsync(callback) {
|
|
38
40
|
return this.db.transactionAsync(callback);
|
|
39
41
|
}
|
|
@@ -52,6 +54,9 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
52
54
|
/** Closes the underlying data store. */ close() {
|
|
53
55
|
return this.db.close();
|
|
54
56
|
}
|
|
57
|
+
/** Computes the finalized block number based on the proven block number. */ getFinalizedL2BlockNumber() {
|
|
58
|
+
return this.#blockStore.getFinalizedL2BlockNumber();
|
|
59
|
+
}
|
|
55
60
|
/** Looks up a public function name given a selector. */ getDebugFunctionName(_address, selector) {
|
|
56
61
|
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
57
62
|
}
|
|
@@ -90,12 +95,11 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
97
|
* Add new contract classes from an L2 block to the store's list.
|
|
93
|
-
* @param data - List of contract classes to be added.
|
|
94
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
98
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
95
99
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
96
100
|
* @returns True if the operation is successful.
|
|
97
|
-
*/ async addContractClasses(data,
|
|
98
|
-
return (await Promise.all(data.map((c
|
|
101
|
+
*/ async addContractClasses(data, blockNumber) {
|
|
102
|
+
return (await Promise.all(data.map((c)=>this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)))).every(Boolean);
|
|
99
103
|
}
|
|
100
104
|
async deleteContractClasses(data, blockNumber) {
|
|
101
105
|
return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
|
|
@@ -103,9 +107,6 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
103
107
|
getBytecodeCommitment(contractClassId) {
|
|
104
108
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
105
109
|
}
|
|
106
|
-
/** Adds private functions to a contract class. */ addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
107
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
108
|
-
}
|
|
109
110
|
/**
|
|
110
111
|
* Add new contract instances from an L2 block to the store's list.
|
|
111
112
|
* @param data - List of contract instances to be added.
|
|
@@ -129,11 +130,13 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
129
130
|
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
|
-
* Append new
|
|
133
|
-
*
|
|
133
|
+
* Append a new proposed block to the store.
|
|
134
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
135
|
+
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
136
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
134
137
|
* @returns True if the operation is successful.
|
|
135
|
-
*/
|
|
136
|
-
return this.#blockStore.
|
|
138
|
+
*/ addProposedBlock(block, opts = {}) {
|
|
139
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
137
140
|
}
|
|
138
141
|
/**
|
|
139
142
|
* Returns an array of checkpoint objects
|
|
@@ -147,16 +150,14 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
147
150
|
* Returns the number of the latest block
|
|
148
151
|
* @returns The number of the latest block
|
|
149
152
|
*/ getLatestBlockNumber() {
|
|
150
|
-
return this.#blockStore.
|
|
153
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
151
154
|
}
|
|
152
155
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*/ unwindCheckpoints(from, checkpointsToUnwind) {
|
|
159
|
-
return this.#blockStore.unwindCheckpoints(from, checkpointsToUnwind);
|
|
156
|
+
* Removes all checkpoints with checkpoint number > checkpointNumber.
|
|
157
|
+
* Also removes ALL blocks (both checkpointed and uncheckpointed) after the last block of the given checkpoint.
|
|
158
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
159
|
+
*/ removeCheckpointsAfter(checkpointNumber) {
|
|
160
|
+
return this.#blockStore.removeCheckpointsAfter(checkpointNumber);
|
|
160
161
|
}
|
|
161
162
|
/**
|
|
162
163
|
* Appends new checkpoints, and their blocks to the store's collection
|
|
@@ -193,7 +194,7 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
193
194
|
* Returns the block for the given hash, or undefined if not exists.
|
|
194
195
|
* @param blockHash - The block hash to return.
|
|
195
196
|
*/ getBlockByHash(blockHash) {
|
|
196
|
-
return this.#blockStore.getBlockByHash(
|
|
197
|
+
return this.#blockStore.getBlockByHash(blockHash);
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
199
200
|
* Returns the block for the given archive root, or undefined if not exists.
|
|
@@ -229,7 +230,7 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
229
230
|
* Returns the block header for the given hash, or undefined if not exists.
|
|
230
231
|
* @param blockHash - The block hash to return.
|
|
231
232
|
*/ getBlockHeaderByHash(blockHash) {
|
|
232
|
-
return this.#blockStore.getBlockHeaderByHash(
|
|
233
|
+
return this.#blockStore.getBlockHeaderByHash(blockHash);
|
|
233
234
|
}
|
|
234
235
|
/**
|
|
235
236
|
* Returns the block header for the given archive root, or undefined if not exists.
|
|
@@ -238,6 +239,18 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
238
239
|
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
239
240
|
}
|
|
240
241
|
/**
|
|
242
|
+
* Gets block metadata (without tx data) by block number.
|
|
243
|
+
* @param blockNumber - The block number to return.
|
|
244
|
+
*/ getBlockData(blockNumber) {
|
|
245
|
+
return this.#blockStore.getBlockData(blockNumber);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Gets block metadata (without tx data) by archive root.
|
|
249
|
+
* @param archive - The archive root to return.
|
|
250
|
+
*/ getBlockDataByArchive(archive) {
|
|
251
|
+
return this.#blockStore.getBlockDataByArchive(archive);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
241
254
|
* Gets a tx effect.
|
|
242
255
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
243
256
|
* @returns The requested tx effect with block info (or undefined if not found).
|
|
@@ -248,8 +261,8 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
248
261
|
* Gets a receipt of a settled tx.
|
|
249
262
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
250
263
|
* @returns The requested tx receipt (or undefined if not found).
|
|
251
|
-
*/ getSettledTxReceipt(txHash) {
|
|
252
|
-
return this.#blockStore.getSettledTxReceipt(txHash);
|
|
264
|
+
*/ getSettledTxReceipt(txHash, l1Constants) {
|
|
265
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
253
266
|
}
|
|
254
267
|
/**
|
|
255
268
|
* Append new logs to the store's list.
|
|
@@ -296,9 +309,10 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
296
309
|
* array implies no logs match that tag.
|
|
297
310
|
* @param tags - The tags to search for.
|
|
298
311
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
299
|
-
|
|
312
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
313
|
+
*/ getPrivateLogsByTags(tags, page, upToBlockNumber) {
|
|
300
314
|
try {
|
|
301
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
315
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
302
316
|
} catch (err) {
|
|
303
317
|
return Promise.reject(err);
|
|
304
318
|
}
|
|
@@ -309,9 +323,10 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
309
323
|
* @param contractAddress - The contract address to search logs for.
|
|
310
324
|
* @param tags - The tags to search for.
|
|
311
325
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
312
|
-
|
|
326
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
327
|
+
*/ getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber) {
|
|
313
328
|
try {
|
|
314
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
329
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
315
330
|
} catch (err) {
|
|
316
331
|
return Promise.reject(err);
|
|
317
332
|
}
|
|
@@ -350,13 +365,20 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
350
365
|
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
351
366
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
352
367
|
}
|
|
353
|
-
|
|
354
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Gets the number of the latest finalized checkpoint processed.
|
|
370
|
+
* @returns The number of the latest finalized checkpoint processed.
|
|
371
|
+
*/ getFinalizedCheckpointNumber() {
|
|
372
|
+
return this.#blockStore.getFinalizedCheckpointNumber();
|
|
355
373
|
}
|
|
356
374
|
/**
|
|
357
|
-
* Stores the
|
|
358
|
-
|
|
359
|
-
|
|
375
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
376
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
377
|
+
*/ async setFinalizedCheckpointNumber(checkpointNumber) {
|
|
378
|
+
await this.#blockStore.setFinalizedCheckpointNumber(checkpointNumber);
|
|
379
|
+
}
|
|
380
|
+
async setBlockSynchedL1BlockNumber(l1BlockNumber) {
|
|
381
|
+
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
360
382
|
}
|
|
361
383
|
/**
|
|
362
384
|
* Returns the number of the most recent proven block
|
|
@@ -382,6 +404,9 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
382
404
|
/** Deletes all L1 to L2 messages up until (excluding) the target checkpoint number. */ rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
|
|
383
405
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
384
406
|
}
|
|
407
|
+
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */ setMessageSyncState(l1Block, treeInProgress) {
|
|
408
|
+
return this.#messageStore.setMessageSyncState(l1Block, treeInProgress);
|
|
409
|
+
}
|
|
385
410
|
/** Returns an async iterator to all L1 to L2 messages on the range. */ iterateL1ToL2Messages(range = {}) {
|
|
386
411
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
387
412
|
}
|
|
@@ -395,6 +420,28 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
395
420
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
396
421
|
}
|
|
397
422
|
/**
|
|
423
|
+
* Gets the L2 block number of the proposed checkpoint.
|
|
424
|
+
* @returns The block number of the proposed checkpoint, or the checkpointed block number if none.
|
|
425
|
+
*/ getProposedCheckpointL2BlockNumber() {
|
|
426
|
+
return this.#blockStore.getProposedCheckpointL2BlockNumber();
|
|
427
|
+
}
|
|
428
|
+
/** Returns the checkpoint data at the proposed tip */ getProposedCheckpoint() {
|
|
429
|
+
return this.#blockStore.getProposedCheckpoint();
|
|
430
|
+
}
|
|
431
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */ getProposedCheckpointOnly() {
|
|
432
|
+
return this.#blockStore.getProposedCheckpointOnly();
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Set proposed checkpoint
|
|
436
|
+
* @param proposedCheckpoint
|
|
437
|
+
* @returns
|
|
438
|
+
*/ setProposedCheckpoint(proposedCheckpoint) {
|
|
439
|
+
return this.#blockStore.setProposedCheckpoint(proposedCheckpoint);
|
|
440
|
+
}
|
|
441
|
+
/** Deletes the proposed checkpoint from storage. */ deleteProposedCheckpoint() {
|
|
442
|
+
return this.#blockStore.deleteProposedCheckpoint();
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
398
445
|
* Gets the number of the latest L2 block processed.
|
|
399
446
|
* @returns The number of the latest L2 block processed.
|
|
400
447
|
*/ getCheckpointedL2BlockNumber() {
|
|
@@ -426,6 +473,9 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
426
473
|
*/ getCheckpointData(checkpointNumber) {
|
|
427
474
|
return this.#blockStore.getCheckpointData(checkpointNumber);
|
|
428
475
|
}
|
|
476
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */ getCheckpointDataForSlotRange(startSlot, endSlot) {
|
|
477
|
+
return this.#blockStore.getCheckpointDataForSlotRange(startSlot, endSlot);
|
|
478
|
+
}
|
|
429
479
|
/**
|
|
430
480
|
* Gets all blocks that have the given slot number.
|
|
431
481
|
* @param slotNumber - The slot number to search for.
|
|
@@ -435,9 +485,10 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
435
485
|
}
|
|
436
486
|
/**
|
|
437
487
|
* Removes all blocks with block number > blockNumber.
|
|
488
|
+
* Does not remove any associated checkpoints.
|
|
438
489
|
* @param blockNumber - The block number to remove after.
|
|
439
490
|
* @returns The removed blocks (for event emission).
|
|
440
491
|
*/ removeBlocksAfter(blockNumber) {
|
|
441
|
-
return this.#blockStore.
|
|
492
|
+
return this.#blockStore.removeBlocksAfter(blockNumber);
|
|
442
493
|
}
|
|
443
494
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type L2Tips } from '@aztec/stdlib/block';
|
|
2
|
+
import type { BlockStore } from './block_store.js';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory cache for L2 chain tips (proposed, checkpointed, proven, finalized).
|
|
5
|
+
* Populated from the BlockStore on first access, then kept up-to-date by the ArchiverDataStoreUpdater.
|
|
6
|
+
* Refresh calls should happen within the store transaction that mutates block data to ensure consistency.
|
|
7
|
+
*/
|
|
8
|
+
export declare class L2TipsCache {
|
|
9
|
+
#private;
|
|
10
|
+
private blockStore;
|
|
11
|
+
constructor(blockStore: BlockStore);
|
|
12
|
+
/** Returns the cached L2 tips. Loads from the block store on first call. */
|
|
13
|
+
getL2Tips(): Promise<L2Tips>;
|
|
14
|
+
/** Reloads the L2 tips from the block store. Should be called within the store transaction that mutates data. */
|
|
15
|
+
refresh(): Promise<void>;
|
|
16
|
+
private loadFromStore;
|
|
17
|
+
private getCheckpointIdForProposedCheckpoint;
|
|
18
|
+
private getCheckpointIdForBlock;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19jYWNoZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3JlL2wyX3RpcHNfY2FjaGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUtMLEtBQUssTUFBTSxFQUNaLE1BQU0scUJBQXFCLENBQUM7QUFFN0IsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFbkQ7Ozs7R0FJRztBQUNILHFCQUFhLFdBQVc7O0lBR1YsT0FBTyxDQUFDLFVBQVU7SUFBOUIsWUFBb0IsVUFBVSxFQUFFLFVBQVUsRUFBSTtJQUU5Qyw0RUFBNEU7SUFDckUsU0FBUyxJQUFJLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FFbEM7SUFFRCxpSEFBaUg7SUFDcEcsT0FBTyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FHcEM7WUFFYSxhQUFhO1lBMEViLG9DQUFvQztZQWFwQyx1QkFBdUI7Q0FhdEMifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l2_tips_cache.d.ts","sourceRoot":"","sources":["../../src/store/l2_tips_cache.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,MAAM,EACZ,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,qBAAa,WAAW;;IAGV,OAAO,CAAC,UAAU;IAA9B,YAAoB,UAAU,EAAE,UAAU,EAAI;IAE9C,4EAA4E;IACrE,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAElC;IAED,iHAAiH;IACpG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAGpC;YAEa,aAAa;YA0Eb,oCAAoC;YAapC,uBAAuB;CAatC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { GENESIS_BLOCK_HEADER_HASH, GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
4
|
+
/**
|
|
5
|
+
* In-memory cache for L2 chain tips (proposed, checkpointed, proven, finalized).
|
|
6
|
+
* Populated from the BlockStore on first access, then kept up-to-date by the ArchiverDataStoreUpdater.
|
|
7
|
+
* Refresh calls should happen within the store transaction that mutates block data to ensure consistency.
|
|
8
|
+
*/ export class L2TipsCache {
|
|
9
|
+
blockStore;
|
|
10
|
+
#tipsPromise;
|
|
11
|
+
constructor(blockStore){
|
|
12
|
+
this.blockStore = blockStore;
|
|
13
|
+
}
|
|
14
|
+
/** Returns the cached L2 tips. Loads from the block store on first call. */ getL2Tips() {
|
|
15
|
+
return this.#tipsPromise ??= this.loadFromStore();
|
|
16
|
+
}
|
|
17
|
+
/** Reloads the L2 tips from the block store. Should be called within the store transaction that mutates data. */ async refresh() {
|
|
18
|
+
this.#tipsPromise = this.loadFromStore();
|
|
19
|
+
await this.#tipsPromise;
|
|
20
|
+
}
|
|
21
|
+
async loadFromStore() {
|
|
22
|
+
const [latestBlockNumber, provenBlockNumber, proposedCheckpointBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
23
|
+
this.blockStore.getLatestL2BlockNumber(),
|
|
24
|
+
this.blockStore.getProvenBlockNumber(),
|
|
25
|
+
this.blockStore.getProposedCheckpointL2BlockNumber(),
|
|
26
|
+
this.blockStore.getCheckpointedL2BlockNumber(),
|
|
27
|
+
this.blockStore.getFinalizedL2BlockNumber()
|
|
28
|
+
]);
|
|
29
|
+
const genesisBlockHeader = {
|
|
30
|
+
blockHash: GENESIS_BLOCK_HEADER_HASH,
|
|
31
|
+
checkpointNumber: CheckpointNumber.ZERO
|
|
32
|
+
};
|
|
33
|
+
const beforeInitialBlockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
34
|
+
const getBlockData = (blockNumber)=>blockNumber > beforeInitialBlockNumber ? this.blockStore.getBlockData(blockNumber) : genesisBlockHeader;
|
|
35
|
+
const [latestBlockData, provenBlockData, proposedCheckpointBlockData, checkpointedBlockData, finalizedBlockData] = await Promise.all([
|
|
36
|
+
latestBlockNumber,
|
|
37
|
+
provenBlockNumber,
|
|
38
|
+
proposedCheckpointBlockNumber,
|
|
39
|
+
checkpointedBlockNumber,
|
|
40
|
+
finalizedBlockNumber
|
|
41
|
+
].map(getBlockData));
|
|
42
|
+
if (!latestBlockData || !provenBlockData || !finalizedBlockData || !checkpointedBlockData || !proposedCheckpointBlockData) {
|
|
43
|
+
throw new Error('Failed to load block data for L2 tips');
|
|
44
|
+
}
|
|
45
|
+
const [provenCheckpointId, finalizedCheckpointId, proposedCheckpointId, checkpointedCheckpointId] = await Promise.all([
|
|
46
|
+
this.getCheckpointIdForBlock(provenBlockData),
|
|
47
|
+
this.getCheckpointIdForBlock(finalizedBlockData),
|
|
48
|
+
this.getCheckpointIdForProposedCheckpoint(checkpointedBlockData),
|
|
49
|
+
this.getCheckpointIdForBlock(checkpointedBlockData)
|
|
50
|
+
]);
|
|
51
|
+
return {
|
|
52
|
+
proposed: {
|
|
53
|
+
number: latestBlockNumber,
|
|
54
|
+
hash: latestBlockData.blockHash.toString()
|
|
55
|
+
},
|
|
56
|
+
proven: {
|
|
57
|
+
block: {
|
|
58
|
+
number: provenBlockNumber,
|
|
59
|
+
hash: provenBlockData.blockHash.toString()
|
|
60
|
+
},
|
|
61
|
+
checkpoint: provenCheckpointId
|
|
62
|
+
},
|
|
63
|
+
proposedCheckpoint: {
|
|
64
|
+
block: {
|
|
65
|
+
number: proposedCheckpointBlockNumber,
|
|
66
|
+
hash: proposedCheckpointBlockData.blockHash.toString()
|
|
67
|
+
},
|
|
68
|
+
checkpoint: proposedCheckpointId
|
|
69
|
+
},
|
|
70
|
+
finalized: {
|
|
71
|
+
block: {
|
|
72
|
+
number: finalizedBlockNumber,
|
|
73
|
+
hash: finalizedBlockData.blockHash.toString()
|
|
74
|
+
},
|
|
75
|
+
checkpoint: finalizedCheckpointId
|
|
76
|
+
},
|
|
77
|
+
checkpointed: {
|
|
78
|
+
block: {
|
|
79
|
+
number: checkpointedBlockNumber,
|
|
80
|
+
hash: checkpointedBlockData.blockHash.toString()
|
|
81
|
+
},
|
|
82
|
+
checkpoint: checkpointedCheckpointId
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
async getCheckpointIdForProposedCheckpoint(checkpointedBlockData) {
|
|
87
|
+
const checkpointData = await this.blockStore.getProposedCheckpointOnly();
|
|
88
|
+
if (!checkpointData) {
|
|
89
|
+
return this.getCheckpointIdForBlock(checkpointedBlockData);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
number: checkpointData.checkpointNumber,
|
|
93
|
+
hash: checkpointData.header.hash().toString()
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async getCheckpointIdForBlock(blockData) {
|
|
97
|
+
const checkpointData = await this.blockStore.getCheckpointData(blockData.checkpointNumber);
|
|
98
|
+
if (!checkpointData) {
|
|
99
|
+
return {
|
|
100
|
+
number: CheckpointNumber.ZERO,
|
|
101
|
+
hash: GENESIS_CHECKPOINT_HEADER_HASH.toString()
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
number: checkpointData.checkpointNumber,
|
|
106
|
+
hash: checkpointData.header.hash().toString()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import {
|
|
4
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
4
5
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
5
6
|
import { type LogFilter, type SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
7
|
import type { BlockStore } from './block_store.js';
|
|
@@ -17,27 +18,29 @@ export declare class LogStore {
|
|
|
17
18
|
* @param blocks - The blocks for which to add the logs.
|
|
18
19
|
* @returns True if the operation is successful.
|
|
19
20
|
*/
|
|
20
|
-
addLogs(blocks:
|
|
21
|
-
deleteLogs(blocks:
|
|
21
|
+
addLogs(blocks: L2Block[]): Promise<boolean>;
|
|
22
|
+
deleteLogs(blocks: L2Block[]): Promise<boolean>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
24
25
|
* array implies no logs match that tag.
|
|
25
26
|
* @param tags - The tags to search for.
|
|
26
27
|
* @param page - The page number (0-indexed) for pagination.
|
|
28
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
27
29
|
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
28
30
|
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
29
31
|
*/
|
|
30
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]>;
|
|
32
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]>;
|
|
31
33
|
/**
|
|
32
34
|
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
33
35
|
* logs is returned. An empty array implies no logs match that tag.
|
|
34
36
|
* @param contractAddress - The contract address to search logs for.
|
|
35
37
|
* @param tags - The tags to search for.
|
|
36
38
|
* @param page - The page number (0-indexed) for pagination.
|
|
39
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
37
40
|
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
38
41
|
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
39
42
|
*/
|
|
40
|
-
getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[], page?: number): Promise<TxScopedL2Log[][]>;
|
|
43
|
+
getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]>;
|
|
41
44
|
/**
|
|
42
45
|
* Gets public logs based on the provided filter.
|
|
43
46
|
* @param filter - The filter to apply to the logs.
|
|
@@ -51,4 +54,4 @@ export declare class LogStore {
|
|
|
51
54
|
*/
|
|
52
55
|
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse>;
|
|
53
56
|
}
|
|
54
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
57
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUk5RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQWEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFekQsT0FBTyxLQUFLLEVBQUUsNEJBQTRCLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUMzRyxPQUFPLEVBSUwsS0FBSyxTQUFTLEVBR2QsS0FBSyxTQUFTLEVBQ2QsR0FBRyxFQUNILGFBQWEsRUFDZCxNQUFNLG9CQUFvQixDQUFDO0FBSTVCLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBRW5EOztHQUVHO0FBQ0gscUJBQWEsUUFBUTs7SUFhakIsT0FBTyxDQUFDLEVBQUU7SUFDVixPQUFPLENBQUMsVUFBVTtJQUZwQixZQUNVLEVBQUUsRUFBRSxpQkFBaUIsRUFDckIsVUFBVSxFQUFFLFVBQVUsRUFDOUIsZUFBZSxHQUFFLE1BQWEsRUFVL0I7SUFvT0Q7Ozs7T0FJRztJQUNILE9BQU8sQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFFLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQVMzQztJQWNELFVBQVUsQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFFLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQTBEOUM7SUFFRDs7Ozs7Ozs7T0FRRztJQUNHLG9CQUFvQixDQUN4QixJQUFJLEVBQUUsU0FBUyxFQUFFLEVBQ2pCLElBQUksR0FBRSxNQUFVLEVBQ2hCLGVBQWUsQ0FBQyxFQUFFLFdBQVcsR0FDNUIsT0FBTyxDQUFDLGFBQWEsRUFBRSxFQUFFLENBQUMsQ0FnQjVCO0lBRUQ7Ozs7Ozs7OztPQVNHO0lBQ0csK0JBQStCLENBQ25DLGVBQWUsRUFBRSxZQUFZLEVBQzdCLElBQUksRUFBRSxHQUFHLEVBQUUsRUFDWCxJQUFJLEdBQUUsTUFBVSxFQUNoQixlQUFlLENBQUMsRUFBRSxXQUFXLEdBQzVCLE9BQU8sQ0FBQyxhQUFhLEVBQUUsRUFBRSxDQUFDLENBb0I1QjtJQUVEOzs7O09BSUc7SUFDSCxhQUFhLENBQUMsTUFBTSxFQUFFLFNBQVMsR0FBRyxPQUFPLENBQUMscUJBQXFCLENBQUMsQ0FRL0Q7SUErRkQ7Ozs7T0FJRztJQUNILG9CQUFvQixDQUFDLE1BQU0sRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBUTdFO0NBNktGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../src/store/log_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../src/store/log_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI9D,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAa,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAIL,KAAK,SAAS,EAGd,KAAK,SAAS,EACd,GAAG,EACH,aAAa,EACd,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAQ;;IAajB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,UAAU;IAFpB,YACU,EAAE,EAAE,iBAAiB,EACrB,UAAU,EAAE,UAAU,EAC9B,eAAe,GAAE,MAAa,EAU/B;IAoOD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAS3C;IAcD,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA0D9C;IAED;;;;;;;;OAQG;IACG,oBAAoB,CACxB,IAAI,EAAE,SAAS,EAAE,EACjB,IAAI,GAAE,MAAU,EAChB,eAAe,CAAC,EAAE,WAAW,GAC5B,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAgB5B;IAED;;;;;;;;;OASG;IACG,+BAA+B,CACnC,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,GAAE,MAAU,EAChB,eAAe,CAAC,EAAE,WAAW,GAC5B,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAoB5B;IAED;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQ/D;IA+FD;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAQ7E;CA6KF"}
|