@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
|
@@ -7,7 +7,7 @@ import { ContractClassStore } from './contract_class_store.js';
|
|
|
7
7
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
8
8
|
import { LogStore } from './log_store.js';
|
|
9
9
|
import { MessageStore } from './message_store.js';
|
|
10
|
-
export const ARCHIVER_DB_VERSION =
|
|
10
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
11
11
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
12
12
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
13
13
|
/**
|
|
@@ -23,11 +23,11 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
23
23
|
#contractInstanceStore;
|
|
24
24
|
functionNames;
|
|
25
25
|
#log;
|
|
26
|
-
constructor(db, logsMaxPageSize = 1000
|
|
26
|
+
constructor(db, logsMaxPageSize = 1000){
|
|
27
27
|
this.db = db;
|
|
28
28
|
this.functionNames = new Map();
|
|
29
29
|
this.#log = createLogger('archiver:data-store');
|
|
30
|
-
this.#blockStore = new BlockStore(db
|
|
30
|
+
this.#blockStore = new BlockStore(db);
|
|
31
31
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
32
32
|
this.#messageStore = new MessageStore(db);
|
|
33
33
|
this.#contractClassStore = new ContractClassStore(db);
|
|
@@ -95,12 +95,11 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Add new contract classes from an L2 block to the store's list.
|
|
98
|
-
* @param data - List of contract classes to be added.
|
|
99
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
98
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
100
99
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
101
100
|
* @returns True if the operation is successful.
|
|
102
|
-
*/ async addContractClasses(data,
|
|
103
|
-
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);
|
|
104
103
|
}
|
|
105
104
|
async deleteContractClasses(data, blockNumber) {
|
|
106
105
|
return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
|
|
@@ -108,9 +107,6 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
108
107
|
getBytecodeCommitment(contractClassId) {
|
|
109
108
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
110
109
|
}
|
|
111
|
-
/** Adds private functions to a contract class. */ addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
112
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
113
|
-
}
|
|
114
110
|
/**
|
|
115
111
|
* Add new contract instances from an L2 block to the store's list.
|
|
116
112
|
* @param data - List of contract instances to be added.
|
|
@@ -134,13 +130,13 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
134
130
|
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
|
|
135
131
|
}
|
|
136
132
|
/**
|
|
137
|
-
* Append new proposed
|
|
138
|
-
*
|
|
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.
|
|
139
135
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
140
|
-
* @param
|
|
136
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
141
137
|
* @returns True if the operation is successful.
|
|
142
|
-
*/
|
|
143
|
-
return this.#blockStore.
|
|
138
|
+
*/ addProposedBlock(block, opts = {}) {
|
|
139
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
144
140
|
}
|
|
145
141
|
/**
|
|
146
142
|
* Returns an array of checkpoint objects
|
|
@@ -154,7 +150,7 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
154
150
|
* Returns the number of the latest block
|
|
155
151
|
* @returns The number of the latest block
|
|
156
152
|
*/ getLatestBlockNumber() {
|
|
157
|
-
return this.#blockStore.
|
|
153
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
158
154
|
}
|
|
159
155
|
/**
|
|
160
156
|
* Removes all checkpoints with checkpoint number > checkpointNumber.
|
|
@@ -265,8 +261,8 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
265
261
|
* Gets a receipt of a settled tx.
|
|
266
262
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
267
263
|
* @returns The requested tx receipt (or undefined if not found).
|
|
268
|
-
*/ getSettledTxReceipt(txHash) {
|
|
269
|
-
return this.#blockStore.getSettledTxReceipt(txHash);
|
|
264
|
+
*/ getSettledTxReceipt(txHash, l1Constants) {
|
|
265
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
270
266
|
}
|
|
271
267
|
/**
|
|
272
268
|
* Append new logs to the store's list.
|
|
@@ -313,9 +309,10 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
313
309
|
* array implies no logs match that tag.
|
|
314
310
|
* @param tags - The tags to search for.
|
|
315
311
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
316
|
-
|
|
312
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
313
|
+
*/ getPrivateLogsByTags(tags, page, upToBlockNumber) {
|
|
317
314
|
try {
|
|
318
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
315
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
319
316
|
} catch (err) {
|
|
320
317
|
return Promise.reject(err);
|
|
321
318
|
}
|
|
@@ -326,9 +323,10 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
326
323
|
* @param contractAddress - The contract address to search logs for.
|
|
327
324
|
* @param tags - The tags to search for.
|
|
328
325
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
329
|
-
|
|
326
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
327
|
+
*/ getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber) {
|
|
330
328
|
try {
|
|
331
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
329
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
332
330
|
} catch (err) {
|
|
333
331
|
return Promise.reject(err);
|
|
334
332
|
}
|
|
@@ -367,13 +365,20 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
367
365
|
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
368
366
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
369
367
|
}
|
|
370
|
-
|
|
371
|
-
|
|
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();
|
|
372
373
|
}
|
|
373
374
|
/**
|
|
374
|
-
* Stores the
|
|
375
|
-
|
|
376
|
-
|
|
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);
|
|
377
382
|
}
|
|
378
383
|
/**
|
|
379
384
|
* Returns the number of the most recent proven block
|
|
@@ -399,6 +404,9 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
399
404
|
/** Deletes all L1 to L2 messages up until (excluding) the target checkpoint number. */ rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
|
|
400
405
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
401
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
|
+
}
|
|
402
410
|
/** Returns an async iterator to all L1 to L2 messages on the range. */ iterateL1ToL2Messages(range = {}) {
|
|
403
411
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
404
412
|
}
|
|
@@ -412,6 +420,50 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
412
420
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
413
421
|
}
|
|
414
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 */ getLastCheckpoint() {
|
|
429
|
+
return this.#blockStore.getLastCheckpoint();
|
|
430
|
+
}
|
|
431
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */ getLastProposedCheckpoint() {
|
|
432
|
+
return this.#blockStore.getLastProposedCheckpoint();
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Set proposed checkpoint
|
|
436
|
+
* @param proposedCheckpoint
|
|
437
|
+
* @returns
|
|
438
|
+
*/ addProposedCheckpoint(proposedCheckpoint) {
|
|
439
|
+
return this.#blockStore.addProposedCheckpoint(proposedCheckpoint);
|
|
440
|
+
}
|
|
441
|
+
/** Deletes all pending proposed checkpoints from storage. */ deleteProposedCheckpoints() {
|
|
442
|
+
return this.#blockStore.deleteProposedCheckpoints();
|
|
443
|
+
}
|
|
444
|
+
/** Returns the pending checkpoint for a specific checkpoint number, or undefined if not found. */ getProposedCheckpointByNumber(n) {
|
|
445
|
+
return this.#blockStore.getProposedCheckpointByNumber(n);
|
|
446
|
+
}
|
|
447
|
+
/** Returns all pending checkpoints in ascending checkpoint-number order. */ getProposedCheckpoints() {
|
|
448
|
+
return this.#blockStore.getProposedCheckpoints();
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Evicts all pending checkpoints with checkpoint number >= fromNumber.
|
|
452
|
+
* Used for divergent-mined-checkpoint cleanup.
|
|
453
|
+
*/ evictProposedCheckpointsFrom(fromNumber) {
|
|
454
|
+
return this.#blockStore.evictProposedCheckpointsFrom(fromNumber);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Promotes a specific pending checkpoint to a confirmed checkpoint entry.
|
|
458
|
+
* Should only be called after the checkpoint has been validated.
|
|
459
|
+
* @param checkpointNumber - The checkpoint number to promote.
|
|
460
|
+
* @param l1 - L1 published data for the checkpoint.
|
|
461
|
+
* @param attestations - Committee attestations.
|
|
462
|
+
* @param expectedArchiveRoot - The archive root to match against the proposed checkpoint, to guard against races.
|
|
463
|
+
*/ promoteProposedToCheckpointed(checkpointNumber, l1, attestations, expectedArchiveRoot) {
|
|
464
|
+
return this.#blockStore.promoteProposedToCheckpointed(checkpointNumber, l1, attestations, expectedArchiveRoot);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
415
467
|
* Gets the number of the latest L2 block processed.
|
|
416
468
|
* @returns The number of the latest L2 block processed.
|
|
417
469
|
*/ getCheckpointedL2BlockNumber() {
|
|
@@ -446,6 +498,15 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
446
498
|
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */ getCheckpointDataForSlotRange(startSlot, endSlot) {
|
|
447
499
|
return this.#blockStore.getCheckpointDataForSlotRange(startSlot, endSlot);
|
|
448
500
|
}
|
|
501
|
+
/** Returns lightweight checkpoint metadata for a range of checkpoints. */ getCheckpointDataRange(from, limit) {
|
|
502
|
+
return this.#blockStore.getRangeOfCheckpoints(from, limit);
|
|
503
|
+
}
|
|
504
|
+
/** Returns the checkpoint number for a given slot, if one exists. */ getCheckpointNumberBySlot(slot) {
|
|
505
|
+
return this.#blockStore.getCheckpointNumberBySlot(slot);
|
|
506
|
+
}
|
|
507
|
+
/** Returns block metadata plus checkpoint-derived context (L1 publish info, attestations). */ getBlockDataWithCheckpointContext(blockNumber) {
|
|
508
|
+
return this.#blockStore.getBlockDataWithCheckpointContext(blockNumber);
|
|
509
|
+
}
|
|
449
510
|
/**
|
|
450
511
|
* Gets all blocks that have the given slot number.
|
|
451
512
|
* @param slotNumber - The slot number to search for.
|
|
@@ -14,6 +14,7 @@ export declare class L2TipsCache {
|
|
|
14
14
|
/** Reloads the L2 tips from the block store. Should be called within the store transaction that mutates data. */
|
|
15
15
|
refresh(): Promise<void>;
|
|
16
16
|
private loadFromStore;
|
|
17
|
+
private getCheckpointIdForProposedCheckpoint;
|
|
17
18
|
private getCheckpointIdForBlock;
|
|
18
19
|
}
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19jYWNoZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3JlL2wyX3RpcHNfY2FjaGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUtMLEtBQUssTUFBTSxFQUNaLE1BQU0scUJBQXFCLENBQUM7QUFFN0IsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFbkQ7Ozs7R0FJRztBQUNILHFCQUFhLFdBQVc7O0lBR1YsT0FBTyxDQUFDLFVBQVU7SUFBOUIsWUFBb0IsVUFBVSxFQUFFLFVBQVUsRUFBSTtJQUU5Qyw0RUFBNEU7SUFDckUsU0FBUyxJQUFJLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FFbEM7SUFFRCxpSEFBaUg7SUFDcEcsT0FBTyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FHcEM7WUFFYSxhQUFhO1lBMEViLG9DQUFvQztZQWFwQyx1QkFBdUI7Q0FhdEMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_cache.d.ts","sourceRoot":"","sources":["../../src/store/l2_tips_cache.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
3
|
+
import { GENESIS_BLOCK_HEADER_HASH, GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
4
4
|
/**
|
|
5
5
|
* In-memory cache for L2 chain tips (proposed, checkpointed, proven, finalized).
|
|
6
6
|
* Populated from the BlockStore on first access, then kept up-to-date by the ArchiverDataStoreUpdater.
|
|
@@ -19,9 +19,10 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
|
19
19
|
await this.#tipsPromise;
|
|
20
20
|
}
|
|
21
21
|
async loadFromStore() {
|
|
22
|
-
const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
23
|
-
this.blockStore.
|
|
22
|
+
const [latestBlockNumber, provenBlockNumber, proposedCheckpointBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
23
|
+
this.blockStore.getLatestL2BlockNumber(),
|
|
24
24
|
this.blockStore.getProvenBlockNumber(),
|
|
25
|
+
this.blockStore.getProposedCheckpointL2BlockNumber(),
|
|
25
26
|
this.blockStore.getCheckpointedL2BlockNumber(),
|
|
26
27
|
this.blockStore.getFinalizedL2BlockNumber()
|
|
27
28
|
]);
|
|
@@ -31,18 +32,20 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
|
31
32
|
};
|
|
32
33
|
const beforeInitialBlockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
33
34
|
const getBlockData = (blockNumber)=>blockNumber > beforeInitialBlockNumber ? this.blockStore.getBlockData(blockNumber) : genesisBlockHeader;
|
|
34
|
-
const [latestBlockData, provenBlockData, checkpointedBlockData, finalizedBlockData] = await Promise.all([
|
|
35
|
+
const [latestBlockData, provenBlockData, proposedCheckpointBlockData, checkpointedBlockData, finalizedBlockData] = await Promise.all([
|
|
35
36
|
latestBlockNumber,
|
|
36
37
|
provenBlockNumber,
|
|
38
|
+
proposedCheckpointBlockNumber,
|
|
37
39
|
checkpointedBlockNumber,
|
|
38
40
|
finalizedBlockNumber
|
|
39
41
|
].map(getBlockData));
|
|
40
|
-
if (!latestBlockData || !provenBlockData || !finalizedBlockData || !checkpointedBlockData) {
|
|
42
|
+
if (!latestBlockData || !provenBlockData || !finalizedBlockData || !checkpointedBlockData || !proposedCheckpointBlockData) {
|
|
41
43
|
throw new Error('Failed to load block data for L2 tips');
|
|
42
44
|
}
|
|
43
|
-
const [provenCheckpointId, finalizedCheckpointId, checkpointedCheckpointId] = await Promise.all([
|
|
45
|
+
const [provenCheckpointId, finalizedCheckpointId, proposedCheckpointId, checkpointedCheckpointId] = await Promise.all([
|
|
44
46
|
this.getCheckpointIdForBlock(provenBlockData),
|
|
45
47
|
this.getCheckpointIdForBlock(finalizedBlockData),
|
|
48
|
+
this.getCheckpointIdForProposedCheckpoint(checkpointedBlockData),
|
|
46
49
|
this.getCheckpointIdForBlock(checkpointedBlockData)
|
|
47
50
|
]);
|
|
48
51
|
return {
|
|
@@ -57,6 +60,13 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
|
57
60
|
},
|
|
58
61
|
checkpoint: provenCheckpointId
|
|
59
62
|
},
|
|
63
|
+
proposedCheckpoint: {
|
|
64
|
+
block: {
|
|
65
|
+
number: proposedCheckpointBlockNumber,
|
|
66
|
+
hash: proposedCheckpointBlockData.blockHash.toString()
|
|
67
|
+
},
|
|
68
|
+
checkpoint: proposedCheckpointId
|
|
69
|
+
},
|
|
60
70
|
finalized: {
|
|
61
71
|
block: {
|
|
62
72
|
number: finalizedBlockNumber,
|
|
@@ -73,6 +83,16 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '@aztec/stdlib/block';
|
|
|
73
83
|
}
|
|
74
84
|
};
|
|
75
85
|
}
|
|
86
|
+
async getCheckpointIdForProposedCheckpoint(checkpointedBlockData) {
|
|
87
|
+
const checkpointData = await this.blockStore.getLastProposedCheckpoint();
|
|
88
|
+
if (!checkpointData) {
|
|
89
|
+
return this.getCheckpointIdForBlock(checkpointedBlockData);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
number: checkpointData.checkpointNumber,
|
|
93
|
+
hash: checkpointData.header.hash().toString()
|
|
94
|
+
};
|
|
95
|
+
}
|
|
76
96
|
async getCheckpointIdForBlock(blockData) {
|
|
77
97
|
const checkpointData = await this.blockStore.getCheckpointData(blockData.checkpointNumber);
|
|
78
98
|
if (!checkpointData) {
|
|
@@ -1,3 +1,4 @@
|
|
|
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
4
|
import { L2Block } from '@aztec/stdlib/block';
|
|
@@ -24,20 +25,22 @@ export declare class LogStore {
|
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwc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BQVcsR0FDNUIsT0FBTyxDQUFDLGFBQWEsRUFBRSxFQUFFLENBQUMsQ0FnQjVCO0lBRUQ7Ozs7Ozs7OztPQVNHO0lBQ0csK0JBQStCLENBQ25DLGVBQWUsRUFBRSxZQUFZLEVBQzdCLElBQUksRUFBRSxHQUFHLEVBQUUsRUFDWCxJQUFJLEdBQUUsTUFBVSxFQUNoQixlQUFlLENBQUMsRUFBRSxXQUFXLEdBQzVCLE9BQU8sQ0FBQyxhQUFhLEVBQUUsRUFBRSxDQUFDLENBb0I1QjtJQUVEOzs7O09BSUc7SUFDSCxhQUFhLENBQUMsTUFBTSxFQUFFLFNBQVMsR0FBRyxPQUFPLENBQUMscUJBQXFCLENBQUMsQ0FRL0Q7SUErRkQ7Ozs7T0FJRztJQUNILG9CQUFvQixDQUFDLE1BQU0sRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBUTdFO0NBNktGIn0=
|
|
@@ -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"}
|
package/dest/store/log_store.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { filterAsync } from '@aztec/foundation/collection';
|
|
4
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { compactArray, filterAsync } from '@aztec/foundation/collection';
|
|
5
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
5
|
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
7
6
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
8
7
|
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
9
8
|
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
10
9
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
10
|
+
import { OutOfOrderLogInsertionError } from '../errors.js';
|
|
11
11
|
/**
|
|
12
12
|
* A store for logs
|
|
13
13
|
*/ export class LogStore {
|
|
@@ -108,7 +108,16 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
108
108
|
})));
|
|
109
109
|
for (const taggedLogBuffer of currentPrivateTaggedLogs){
|
|
110
110
|
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
111
|
-
|
|
111
|
+
const newLogs = privateTaggedLogs.get(taggedLogBuffer.tag);
|
|
112
|
+
if (newLogs.length === 0) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const lastExisting = TxScopedL2Log.fromBuffer(taggedLogBuffer.logBuffers.at(-1));
|
|
116
|
+
const firstNew = TxScopedL2Log.fromBuffer(newLogs[0]);
|
|
117
|
+
if (lastExisting.blockNumber > firstNew.blockNumber) {
|
|
118
|
+
throw new OutOfOrderLogInsertionError('private', taggedLogBuffer.tag, lastExisting.blockNumber, firstNew.blockNumber);
|
|
119
|
+
}
|
|
120
|
+
privateTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(newLogs));
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
for (const block of newBlocks){
|
|
@@ -130,7 +139,16 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
130
139
|
})));
|
|
131
140
|
for (const taggedLogBuffer of currentPublicTaggedLogs){
|
|
132
141
|
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
133
|
-
|
|
142
|
+
const newLogs = publicTaggedLogs.get(taggedLogBuffer.tag);
|
|
143
|
+
if (newLogs.length === 0) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const lastExisting = TxScopedL2Log.fromBuffer(taggedLogBuffer.logBuffers.at(-1));
|
|
147
|
+
const firstNew = TxScopedL2Log.fromBuffer(newLogs[0]);
|
|
148
|
+
if (lastExisting.blockNumber > firstNew.blockNumber) {
|
|
149
|
+
throw new OutOfOrderLogInsertionError('public', taggedLogBuffer.tag, lastExisting.blockNumber, firstNew.blockNumber);
|
|
150
|
+
}
|
|
151
|
+
publicTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(newLogs));
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
154
|
for (const block of newBlocks){
|
|
@@ -184,22 +202,41 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
184
202
|
]);
|
|
185
203
|
}
|
|
186
204
|
#unpackBlockHash(reader) {
|
|
187
|
-
|
|
188
|
-
if (!blockHash) {
|
|
205
|
+
if (reader.remainingBytes() === 0) {
|
|
189
206
|
throw new Error('Failed to read block hash from log entry buffer');
|
|
190
207
|
}
|
|
191
|
-
return
|
|
208
|
+
return BlockHash.fromBuffer(reader);
|
|
192
209
|
}
|
|
193
210
|
deleteLogs(blocks) {
|
|
194
211
|
return this.db.transactionAsync(async ()=>{
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
212
|
+
const blockNumbers = new Set(blocks.map((block)=>block.number));
|
|
213
|
+
const firstBlockToDelete = Math.min(...blockNumbers);
|
|
214
|
+
// Collect all unique private tags across all blocks being deleted
|
|
215
|
+
const allPrivateTags = new Set(compactArray(await Promise.all(blocks.map((block)=>this.#privateLogKeysByBlock.getAsync(block.number)))).flat());
|
|
216
|
+
// Trim private logs: for each tag, delete all instances including and after the first block being deleted.
|
|
217
|
+
// This hinges on the invariant that logs for a given tag are always inserted in order of block number, which is enforced in #addPrivateLogs.
|
|
218
|
+
for (const tag of allPrivateTags){
|
|
219
|
+
const existing = await this.#privateLogsByTag.getAsync(tag);
|
|
220
|
+
if (existing === undefined || existing.length === 0) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const lastIndexToKeep = existing.findLastIndex((buf)=>TxScopedL2Log.getBlockNumberFromBuffer(buf) < firstBlockToDelete);
|
|
224
|
+
const remaining = existing.slice(0, lastIndexToKeep + 1);
|
|
225
|
+
await (remaining.length > 0 ? this.#privateLogsByTag.set(tag, remaining) : this.#privateLogsByTag.delete(tag));
|
|
226
|
+
}
|
|
227
|
+
// Collect all unique public keys across all blocks being deleted
|
|
228
|
+
const allPublicKeys = new Set(compactArray(await Promise.all(blocks.map((block)=>this.#publicLogKeysByBlock.getAsync(block.number)))).flat());
|
|
229
|
+
// And do the same as we did with private logs
|
|
230
|
+
for (const key of allPublicKeys){
|
|
231
|
+
const existing = await this.#publicLogsByContractAndTag.getAsync(key);
|
|
232
|
+
if (existing === undefined || existing.length === 0) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const lastIndexToKeep = existing.findLastIndex((buf)=>TxScopedL2Log.getBlockNumberFromBuffer(buf) < firstBlockToDelete);
|
|
236
|
+
const remaining = existing.slice(0, lastIndexToKeep + 1);
|
|
237
|
+
await (remaining.length > 0 ? this.#publicLogsByContractAndTag.set(key, remaining) : this.#publicLogsByContractAndTag.delete(key));
|
|
238
|
+
}
|
|
239
|
+
// After trimming the tagged logs, we can delete the block-level keys that track which tags are in which blocks.
|
|
203
240
|
await Promise.all(blocks.map((block)=>Promise.all([
|
|
204
241
|
this.#publicLogsByBlock.delete(block.number),
|
|
205
242
|
this.#privateLogKeysByBlock.delete(block.number),
|
|
@@ -214,13 +251,23 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
214
251
|
* array implies no logs match that tag.
|
|
215
252
|
* @param tags - The tags to search for.
|
|
216
253
|
* @param page - The page number (0-indexed) for pagination.
|
|
254
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
217
255
|
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
218
256
|
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
219
|
-
*/ async getPrivateLogsByTags(tags, page = 0) {
|
|
257
|
+
*/ async getPrivateLogsByTags(tags, page = 0, upToBlockNumber) {
|
|
220
258
|
const logs = await Promise.all(tags.map((tag)=>this.#privateLogsByTag.getAsync(tag.toString())));
|
|
221
259
|
const start = page * MAX_LOGS_PER_TAG;
|
|
222
260
|
const end = start + MAX_LOGS_PER_TAG;
|
|
223
|
-
return logs.map((logBuffers)=>
|
|
261
|
+
return logs.map((logBuffers)=>{
|
|
262
|
+
const deserialized = logBuffers?.slice(start, end).map((buf)=>TxScopedL2Log.fromBuffer(buf)) ?? [];
|
|
263
|
+
if (upToBlockNumber !== undefined) {
|
|
264
|
+
const cutoff = deserialized.findIndex((log)=>log.blockNumber > upToBlockNumber);
|
|
265
|
+
if (cutoff !== -1) {
|
|
266
|
+
return deserialized.slice(0, cutoff);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return deserialized;
|
|
270
|
+
});
|
|
224
271
|
}
|
|
225
272
|
/**
|
|
226
273
|
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
@@ -228,16 +275,26 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
228
275
|
* @param contractAddress - The contract address to search logs for.
|
|
229
276
|
* @param tags - The tags to search for.
|
|
230
277
|
* @param page - The page number (0-indexed) for pagination.
|
|
278
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
231
279
|
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
232
280
|
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
233
|
-
*/ async getPublicLogsByTagsFromContract(contractAddress, tags, page = 0) {
|
|
281
|
+
*/ async getPublicLogsByTagsFromContract(contractAddress, tags, page = 0, upToBlockNumber) {
|
|
234
282
|
const logs = await Promise.all(tags.map((tag)=>{
|
|
235
283
|
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
236
284
|
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
237
285
|
}));
|
|
238
286
|
const start = page * MAX_LOGS_PER_TAG;
|
|
239
287
|
const end = start + MAX_LOGS_PER_TAG;
|
|
240
|
-
return logs.map((logBuffers)=>
|
|
288
|
+
return logs.map((logBuffers)=>{
|
|
289
|
+
const deserialized = logBuffers?.slice(start, end).map((buf)=>TxScopedL2Log.fromBuffer(buf)) ?? [];
|
|
290
|
+
if (upToBlockNumber !== undefined) {
|
|
291
|
+
const cutoff = deserialized.findIndex((log)=>log.blockNumber > upToBlockNumber);
|
|
292
|
+
if (cutoff !== -1) {
|
|
293
|
+
return deserialized.slice(0, cutoff);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return deserialized;
|
|
297
|
+
});
|
|
241
298
|
}
|
|
242
299
|
/**
|
|
243
300
|
* Gets public logs based on the provided filter.
|
|
@@ -424,11 +481,20 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
424
481
|
};
|
|
425
482
|
}
|
|
426
483
|
#accumulatePublicLogs(results, blockNumber, blockHash, txIndex, txHash, txLogs, filter = {}) {
|
|
484
|
+
if (filter.fromBlock && blockNumber < filter.fromBlock) {
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
if (filter.toBlock && blockNumber >= filter.toBlock) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
if (filter.txHash && !txHash.equals(filter.txHash)) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
427
493
|
let maxLogsHit = false;
|
|
428
494
|
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
429
495
|
for(; logIndex < txLogs.length; logIndex++){
|
|
430
496
|
const log = txLogs[logIndex];
|
|
431
|
-
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
497
|
+
if ((!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) && (!filter.tag || log.fields[0]?.equals(filter.tag))) {
|
|
432
498
|
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log));
|
|
433
499
|
if (results.length >= this.#logsMaxPageSize) {
|
|
434
500
|
maxLogsHit = true;
|
|
@@ -439,6 +505,15 @@ import { TxHash } from '@aztec/stdlib/tx';
|
|
|
439
505
|
return maxLogsHit;
|
|
440
506
|
}
|
|
441
507
|
#accumulateContractClassLogs(results, blockNumber, blockHash, txIndex, txHash, txLogs, filter = {}) {
|
|
508
|
+
if (filter.fromBlock && blockNumber < filter.fromBlock) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
if (filter.toBlock && blockNumber >= filter.toBlock) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
if (filter.txHash && !txHash.equals(filter.txHash)) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
442
517
|
let maxLogsHit = false;
|
|
443
518
|
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
444
519
|
for(; logIndex < txLogs.length; logIndex++){
|
|
@@ -29,6 +29,10 @@ export declare class MessageStore {
|
|
|
29
29
|
*/
|
|
30
30
|
getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined>;
|
|
31
31
|
getLastMessage(): Promise<InboxMessage | undefined>;
|
|
32
|
+
/** Returns the inbox tree-in-progress checkpoint number from L1, or undefined if not yet set. */
|
|
33
|
+
getInboxTreeInProgress(): Promise<bigint | undefined>;
|
|
34
|
+
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */
|
|
35
|
+
setMessageSyncState(l1Block: L1BlockId, treeInProgress: bigint | undefined): Promise<void>;
|
|
32
36
|
getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]>;
|
|
33
37
|
iterateL1ToL2Messages(range?: CustomRange<bigint>): AsyncIterableIterator<InboxMessage>;
|
|
34
38
|
removeL1ToL2Messages(startIndex: bigint): Promise<void>;
|
|
@@ -37,4 +41,4 @@ export declare class MessageStore {
|
|
|
37
41
|
private leafToIndexKey;
|
|
38
42
|
private increaseTotalMessageCount;
|
|
39
43
|
}
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
44
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzc2FnZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N0b3JlL21lc3NhZ2Vfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDMUQsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbkUsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBSXBELE9BQU8sRUFDTCxLQUFLLGlCQUFpQixFQUd0QixLQUFLLFdBQVcsRUFFakIsTUFBTSxpQkFBaUIsQ0FBQztBQUl6QixPQUFPLEVBQ0wsS0FBSyxZQUFZLEVBSWxCLE1BQU0sNkJBQTZCLENBQUM7QUFFckMscUJBQWEsaUJBQWtCLFNBQVEsS0FBSzthQUd4QixZQUFZLEVBQUUsWUFBWTtJQUY1QyxZQUNFLE9BQU8sRUFBRSxNQUFNLEVBQ0MsWUFBWSxFQUFFLFlBQVksRUFJM0M7Q0FDRjtBQUVELHFCQUFhLFlBQVk7O0lBY1gsT0FBTyxDQUFDLEVBQUU7SUFBdEIsWUFBb0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BRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWdCN0Q7SUFFTSxrQ0FBa0MsQ0FBQyxzQkFBc0IsRUFBRSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBSWpHO0lBRUQsT0FBTyxDQUFDLFVBQVU7SUFJbEIsT0FBTyxDQUFDLGNBQWM7WUFJUix5QkFBeUI7Q0FTeEMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_store.d.ts","sourceRoot":"","sources":["../../src/store/message_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAIpD,OAAO,EACL,KAAK,iBAAiB,EAGtB,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"message_store.d.ts","sourceRoot":"","sources":["../../src/store/message_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAIpD,OAAO,EACL,KAAK,iBAAiB,EAGtB,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,6BAA6B,CAAC;AAErC,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,YAAY,EAAE,YAAY;IAF5C,YACE,OAAO,EAAE,MAAM,EACC,YAAY,EAAE,YAAY,EAI3C;CACF;AAED,qBAAa,YAAY;;IAcX,OAAO,CAAC,EAAE;IAAtB,YAAoB,EAAE,EAAE,iBAAiB,EAMxC;IAEY,0BAA0B,IAAI,OAA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