@aztec/archiver 0.0.1-commit.c7c42ec → 0.0.1-commit.d1f2d6c
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 +156 -22
- package/dest/archiver.d.ts +135 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +769 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +11 -2
- package/dest/{archiver/errors.d.ts → errors.d.ts} +1 -1
- package/dest/errors.d.ts.map +1 -0
- package/dest/factory.d.ts +7 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +87 -8
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +2 -2
- package/dest/{archiver/l1 → l1}/calldata_retriever.d.ts +3 -3
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/calldata_retriever.js +2 -2
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +35 -54
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +1 -1
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +1 -1
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +1 -1
- package/dest/modules/data_source_base.d.ts +84 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +260 -0
- package/dest/modules/data_store_updater.d.ts +69 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +304 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +15 -63
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1113 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +188 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +119 -17
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +1 -1
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +339 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/kv_archiver_store.js +185 -52
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/log_store.js +89 -54
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +1 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +12 -3
- package/dest/test/mock_l2_block_source.d.ts +21 -14
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +161 -55
- package/dest/test/mock_structs.d.ts +76 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +133 -2
- package/package.json +15 -17
- package/src/archiver.ts +522 -0
- package/src/{archiver/config.ts → config.ts} +13 -2
- package/src/factory.ts +122 -8
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +7 -2
- package/src/{archiver/l1 → l1}/calldata_retriever.ts +3 -3
- package/src/{archiver/l1 → l1}/data_retrieval.ts +56 -73
- package/src/{archiver/l1 → l1}/validate_trace.ts +1 -1
- package/src/modules/data_source_base.ts +367 -0
- package/src/modules/data_store_updater.ts +419 -0
- package/src/{archiver → modules}/instrumentation.ts +16 -65
- package/src/modules/l1_synchronizer.ts +931 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +170 -35
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +224 -24
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +145 -86
- package/src/test/fake_l1_state.ts +599 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_archiver.ts +2 -2
- package/src/test/mock_l1_to_l2_message_source.ts +10 -4
- package/src/test/mock_l2_block_source.ts +171 -65
- package/src/test/mock_structs.ts +247 -2
- package/dest/archiver/archiver.d.ts +0 -304
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1645
- package/dest/archiver/archiver_store.d.ts +0 -308
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -157
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -158
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2157
- package/src/archiver/archiver_store.ts +0 -372
- package/src/archiver/archiver_store_test_suite.ts +0 -2843
- package/src/archiver/index.ts +0 -6
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/errors.js → errors.js} +0 -0
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/spire_proposer.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/kv_archiver_store → store}/message_store.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/errors.ts → errors.ts} +0 -0
- /package/src/{archiver/l1 → l1}/README.md +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/spire_proposer.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/kv_archiver_store → store}/message_store.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -12,7 +12,8 @@ export const ARCHIVER_DB_VERSION = 5;
|
|
|
12
12
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
13
13
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
14
14
|
/**
|
|
15
|
-
* LMDB
|
|
15
|
+
* LMDB-based data store for the archiver.
|
|
16
|
+
* Stores all archiver data including blocks, logs, contract classes/instances, and L1 to L2 messages.
|
|
16
17
|
*/ export class KVArchiverDataStore {
|
|
17
18
|
db;
|
|
18
19
|
static SCHEMA_VERSION = ARCHIVER_DB_VERSION;
|
|
@@ -23,17 +24,17 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
23
24
|
#contractInstanceStore;
|
|
24
25
|
functionNames;
|
|
25
26
|
#log;
|
|
26
|
-
constructor(db, logsMaxPageSize = 1000){
|
|
27
|
+
constructor(db, logsMaxPageSize = 1000, l1Constants){
|
|
27
28
|
this.db = db;
|
|
28
29
|
this.functionNames = new Map();
|
|
29
30
|
this.#log = createLogger('archiver:data-store');
|
|
30
|
-
this.#blockStore = new BlockStore(db);
|
|
31
|
+
this.#blockStore = new BlockStore(db, l1Constants);
|
|
31
32
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
32
33
|
this.#messageStore = new MessageStore(db);
|
|
33
34
|
this.#contractClassStore = new ContractClassStore(db);
|
|
34
35
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
35
36
|
}
|
|
36
|
-
transactionAsync(callback) {
|
|
37
|
+
/** Opens a new transaction to the underlying store and runs all operations within it. */ transactionAsync(callback) {
|
|
37
38
|
return this.db.transactionAsync(callback);
|
|
38
39
|
}
|
|
39
40
|
getBlockNumber() {
|
|
@@ -44,17 +45,20 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
44
45
|
const timestamp = maybeTimestamp ?? header.globalVariables.timestamp;
|
|
45
46
|
return this.getContractInstance(address, timestamp);
|
|
46
47
|
}
|
|
47
|
-
async backupTo(path, compress = true) {
|
|
48
|
+
/** Backups the archiver db to the target folder. Returns the path to the db file. */ async backupTo(path, compress = true) {
|
|
48
49
|
await this.db.backupTo(path, compress);
|
|
49
50
|
return join(path, 'data.mdb');
|
|
50
51
|
}
|
|
51
|
-
close() {
|
|
52
|
+
/** Closes the underlying data store. */ close() {
|
|
52
53
|
return this.db.close();
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
/** Computes the finalized block number based on the proven block number. */ getFinalizedL2BlockNumber() {
|
|
56
|
+
return this.#blockStore.getFinalizedL2BlockNumber();
|
|
57
|
+
}
|
|
58
|
+
/** Looks up a public function name given a selector. */ getDebugFunctionName(_address, selector) {
|
|
55
59
|
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
56
60
|
}
|
|
57
|
-
async registerContractFunctionSignatures(signatures) {
|
|
61
|
+
/** Register a public function signature, so it can be looked up by selector. */ async registerContractFunctionSignatures(signatures) {
|
|
58
62
|
for (const sig of signatures){
|
|
59
63
|
if (this.functionNames.size > MAX_FUNCTION_SIGNATURES) {
|
|
60
64
|
return;
|
|
@@ -67,19 +71,33 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Returns a contract class given its id, or undefined if not exists.
|
|
76
|
+
* @param id - Id of the contract class.
|
|
77
|
+
*/ getContractClass(id) {
|
|
71
78
|
return this.#contractClassStore.getContractClass(id);
|
|
72
79
|
}
|
|
73
|
-
getContractClassIds() {
|
|
80
|
+
/** Returns the list of all class ids known by the archiver. */ getContractClassIds() {
|
|
74
81
|
return this.#contractClassStore.getContractClassIds();
|
|
75
82
|
}
|
|
76
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Returns a contract instance given its address and the given timestamp, or undefined if not exists.
|
|
85
|
+
* @param address - Address of the contract.
|
|
86
|
+
* @param timestamp - Timestamp to get the contract instance at. Contract updates might change the instance.
|
|
87
|
+
* @returns The contract instance or undefined if not found.
|
|
88
|
+
*/ getContractInstance(address, timestamp) {
|
|
77
89
|
return this.#contractInstanceStore.getContractInstance(address, timestamp);
|
|
78
90
|
}
|
|
79
91
|
getContractInstanceDeploymentBlockNumber(address) {
|
|
80
92
|
return this.#contractInstanceStore.getContractInstanceDeploymentBlockNumber(address);
|
|
81
93
|
}
|
|
82
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Add new contract classes from an L2 block to the store's list.
|
|
96
|
+
* @param data - List of contract classes to be added.
|
|
97
|
+
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
98
|
+
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
99
|
+
* @returns True if the operation is successful.
|
|
100
|
+
*/ async addContractClasses(data, bytecodeCommitments, blockNumber) {
|
|
83
101
|
return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
|
|
84
102
|
}
|
|
85
103
|
async deleteContractClasses(data, blockNumber) {
|
|
@@ -88,16 +106,26 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
88
106
|
getBytecodeCommitment(contractClassId) {
|
|
89
107
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
90
108
|
}
|
|
91
|
-
addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
109
|
+
/** Adds private functions to a contract class. */ addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
92
110
|
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
93
111
|
}
|
|
94
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Add new contract instances from an L2 block to the store's list.
|
|
114
|
+
* @param data - List of contract instances to be added.
|
|
115
|
+
* @param blockNumber - Number of the L2 block the instances were deployed in.
|
|
116
|
+
* @returns True if the operation is successful.
|
|
117
|
+
*/ async addContractInstances(data, blockNumber) {
|
|
95
118
|
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c, blockNumber)))).every(Boolean);
|
|
96
119
|
}
|
|
97
120
|
async deleteContractInstances(data, _blockNumber) {
|
|
98
121
|
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
|
|
99
122
|
}
|
|
100
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Add new contract instance updates
|
|
125
|
+
* @param data - List of contract updates to be added.
|
|
126
|
+
* @param timestamp - Timestamp at which the updates were scheduled.
|
|
127
|
+
* @returns True if the operation is successful.
|
|
128
|
+
*/ async addContractInstanceUpdates(data, timestamp) {
|
|
101
129
|
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.addContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
|
|
102
130
|
}
|
|
103
131
|
async deleteContractInstanceUpdates(data, timestamp) {
|
|
@@ -110,10 +138,18 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
110
138
|
*/ addBlocks(blocks, opts = {}) {
|
|
111
139
|
return this.#blockStore.addBlocks(blocks, opts);
|
|
112
140
|
}
|
|
113
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Returns an array of checkpoint objects
|
|
143
|
+
* @param from The first checkpoint number to be retrieved
|
|
144
|
+
* @param limit The maximum number of checkpoints to retrieve
|
|
145
|
+
* @returns The array of requested checkpoint data objects
|
|
146
|
+
*/ getRangeOfCheckpoints(from, limit) {
|
|
114
147
|
return this.#blockStore.getRangeOfCheckpoints(from, limit);
|
|
115
148
|
}
|
|
116
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Returns the number of the latest block
|
|
151
|
+
* @returns The number of the latest block
|
|
152
|
+
*/ getLatestBlockNumber() {
|
|
117
153
|
return this.#blockStore.getLatestBlockNumber();
|
|
118
154
|
}
|
|
119
155
|
/**
|
|
@@ -125,43 +161,83 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
125
161
|
*/ unwindCheckpoints(from, checkpointsToUnwind) {
|
|
126
162
|
return this.#blockStore.unwindCheckpoints(from, checkpointsToUnwind);
|
|
127
163
|
}
|
|
128
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Appends new checkpoints, and their blocks to the store's collection
|
|
166
|
+
* @param checkpoints The collection of checkpoints to be added
|
|
167
|
+
* @returns True if the operation is successful
|
|
168
|
+
*/ addCheckpoints(checkpoints) {
|
|
129
169
|
return this.#blockStore.addCheckpoints(checkpoints);
|
|
130
170
|
}
|
|
131
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Returns the block for the given number, or undefined if not exists.
|
|
173
|
+
* @param number - The block number to return.
|
|
174
|
+
*/ getCheckpointedBlock(number) {
|
|
132
175
|
return this.#blockStore.getCheckpointedBlock(number);
|
|
133
176
|
}
|
|
134
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Returns the block for the given hash, or undefined if not exists.
|
|
179
|
+
* @param blockHash - The block hash to return.
|
|
180
|
+
*/ getCheckpointedBlockByHash(blockHash) {
|
|
135
181
|
return this.#blockStore.getCheckpointedBlockByHash(blockHash);
|
|
136
182
|
}
|
|
137
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Returns the block for the given archive root, or undefined if not exists.
|
|
185
|
+
* @param archive - The archive root to return.
|
|
186
|
+
*/ getCheckpointedBlockByArchive(archive) {
|
|
138
187
|
return this.#blockStore.getCheckpointedBlockByArchive(archive);
|
|
139
188
|
}
|
|
140
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Returns the block for the given number, or undefined if not exists.
|
|
191
|
+
* @param number - The block number to return.
|
|
192
|
+
*/ getBlock(number) {
|
|
141
193
|
return this.#blockStore.getBlock(number);
|
|
142
194
|
}
|
|
143
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Returns the block for the given hash, or undefined if not exists.
|
|
197
|
+
* @param blockHash - The block hash to return.
|
|
198
|
+
*/ getBlockByHash(blockHash) {
|
|
144
199
|
return this.#blockStore.getBlockByHash(L2BlockHash.fromField(blockHash));
|
|
145
200
|
}
|
|
146
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Returns the block for the given archive root, or undefined if not exists.
|
|
203
|
+
* @param archive - The archive root to return.
|
|
204
|
+
*/ getBlockByArchive(archive) {
|
|
147
205
|
return this.#blockStore.getBlockByArchive(archive);
|
|
148
206
|
}
|
|
149
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Gets up to `limit` amount of published L2 blocks starting from `from`.
|
|
209
|
+
* @param from - Number of the first block to return (inclusive).
|
|
210
|
+
* @param limit - The number of blocks to return.
|
|
211
|
+
* @returns The requested L2 blocks.
|
|
212
|
+
*/ getBlocks(from, limit) {
|
|
150
213
|
return toArray(this.#blockStore.getBlocks(from, limit));
|
|
151
214
|
}
|
|
152
215
|
/**
|
|
153
|
-
* Gets up to `limit` amount of L2 blocks
|
|
154
|
-
*
|
|
216
|
+
* Gets up to `limit` amount of checkpointed L2 blocks starting from `from`.
|
|
217
|
+
* @param from - Number of the first block to return (inclusive).
|
|
218
|
+
* @param limit - The number of blocks to return.
|
|
219
|
+
* @returns The requested checkpointed L2 blocks.
|
|
220
|
+
*/ getCheckpointedBlocks(from, limit) {
|
|
221
|
+
return toArray(this.#blockStore.getCheckpointedBlocks(from, limit));
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Gets up to `limit` amount of L2 block headers starting from `from`.
|
|
155
225
|
* @param start - Number of the first block to return (inclusive).
|
|
156
226
|
* @param limit - The number of blocks to return.
|
|
157
|
-
* @returns The requested L2
|
|
227
|
+
* @returns The requested L2 block headers.
|
|
158
228
|
*/ getBlockHeaders(start, limit) {
|
|
159
229
|
return toArray(this.#blockStore.getBlockHeaders(start, limit));
|
|
160
230
|
}
|
|
161
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Returns the block header for the given hash, or undefined if not exists.
|
|
233
|
+
* @param blockHash - The block hash to return.
|
|
234
|
+
*/ getBlockHeaderByHash(blockHash) {
|
|
162
235
|
return this.#blockStore.getBlockHeaderByHash(L2BlockHash.fromField(blockHash));
|
|
163
236
|
}
|
|
164
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Returns the block header for the given archive root, or undefined if not exists.
|
|
239
|
+
* @param archive - The archive root to return.
|
|
240
|
+
*/ getBlockHeaderByArchive(archive) {
|
|
165
241
|
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
166
242
|
}
|
|
167
243
|
/**
|
|
@@ -188,15 +264,19 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
188
264
|
deleteLogs(blocks) {
|
|
189
265
|
return this.#logStore.deleteLogs(blocks);
|
|
190
266
|
}
|
|
191
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Get the total number of L1 to L2 messages
|
|
269
|
+
* @returns The number of L1 to L2 messages in the store
|
|
270
|
+
*/ getTotalL1ToL2MessageCount() {
|
|
192
271
|
return this.#messageStore.getTotalL1ToL2MessageCount();
|
|
193
272
|
}
|
|
194
|
-
getLastL1ToL2Message() {
|
|
273
|
+
/** Returns the last L1 to L2 message stored. */ getLastL1ToL2Message() {
|
|
195
274
|
return this.#messageStore.getLastMessage();
|
|
196
275
|
}
|
|
197
276
|
/**
|
|
198
277
|
* Append L1 to L2 messages to the store.
|
|
199
278
|
* @param messages - The L1 to L2 messages to be added to the store.
|
|
279
|
+
* @returns True if the operation is successful.
|
|
200
280
|
*/ addL1ToL2Messages(messages) {
|
|
201
281
|
return this.#messageStore.addL1ToL2Messages(messages);
|
|
202
282
|
}
|
|
@@ -214,16 +294,27 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
214
294
|
*/ getL1ToL2Messages(checkpointNumber) {
|
|
215
295
|
return this.#messageStore.getL1ToL2Messages(checkpointNumber);
|
|
216
296
|
}
|
|
217
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
299
|
+
* array implies no logs match that tag.
|
|
300
|
+
* @param tags - The tags to search for.
|
|
301
|
+
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
302
|
+
*/ getPrivateLogsByTags(tags, page) {
|
|
218
303
|
try {
|
|
219
|
-
return this.#logStore.getPrivateLogsByTags(tags);
|
|
304
|
+
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
220
305
|
} catch (err) {
|
|
221
306
|
return Promise.reject(err);
|
|
222
307
|
}
|
|
223
308
|
}
|
|
224
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
311
|
+
* logs is returned. An empty array implies no logs match that tag.
|
|
312
|
+
* @param contractAddress - The contract address to search logs for.
|
|
313
|
+
* @param tags - The tags to search for.
|
|
314
|
+
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
315
|
+
*/ getPublicLogsByTagsFromContract(contractAddress, tags, page) {
|
|
225
316
|
try {
|
|
226
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags);
|
|
317
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
227
318
|
} catch (err) {
|
|
228
319
|
return Promise.reject(err);
|
|
229
320
|
}
|
|
@@ -250,23 +341,34 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
250
341
|
return Promise.reject(err);
|
|
251
342
|
}
|
|
252
343
|
}
|
|
253
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Gets the number of the latest proven checkpoint processed.
|
|
346
|
+
* @returns The number of the latest proven checkpoint processed.
|
|
347
|
+
*/ getProvenCheckpointNumber() {
|
|
254
348
|
return this.#blockStore.getProvenCheckpointNumber();
|
|
255
349
|
}
|
|
256
|
-
|
|
350
|
+
/**
|
|
351
|
+
* Stores the number of the latest proven checkpoint processed.
|
|
352
|
+
* @param checkpointNumber - The number of the latest proven checkpoint processed.
|
|
353
|
+
*/ async setProvenCheckpointNumber(checkpointNumber) {
|
|
257
354
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
258
355
|
}
|
|
259
356
|
async setBlockSynchedL1BlockNumber(l1BlockNumber) {
|
|
260
357
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
261
358
|
}
|
|
262
|
-
|
|
359
|
+
/**
|
|
360
|
+
* Stores the l1 block that messages have been synched until
|
|
361
|
+
*/ async setMessageSynchedL1Block(l1Block) {
|
|
263
362
|
await this.#messageStore.setSynchedL1Block(l1Block);
|
|
264
363
|
}
|
|
265
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Returns the number of the most recent proven block
|
|
366
|
+
* @returns The number of the most recent proven block
|
|
367
|
+
*/ getProvenBlockNumber() {
|
|
266
368
|
return this.#blockStore.getProvenBlockNumber();
|
|
267
369
|
}
|
|
268
370
|
/**
|
|
269
|
-
* Gets the
|
|
371
|
+
* Gets the synch point of the archiver
|
|
270
372
|
*/ async getSynchPoint() {
|
|
271
373
|
const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
|
|
272
374
|
this.#blockStore.getSynchedL1BlockNumber(),
|
|
@@ -277,37 +379,68 @@ export const MAX_FUNCTION_NAME_LEN = 256;
|
|
|
277
379
|
messagesSynchedTo
|
|
278
380
|
};
|
|
279
381
|
}
|
|
280
|
-
estimateSize() {
|
|
382
|
+
/** Estimates the size of the store in bytes. */ estimateSize() {
|
|
281
383
|
return this.db.estimateSize();
|
|
282
384
|
}
|
|
283
|
-
rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
|
|
385
|
+
/** Deletes all L1 to L2 messages up until (excluding) the target checkpoint number. */ rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber) {
|
|
284
386
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
285
387
|
}
|
|
286
|
-
iterateL1ToL2Messages(range = {}) {
|
|
388
|
+
/** Returns an async iterator to all L1 to L2 messages on the range. */ iterateL1ToL2Messages(range = {}) {
|
|
287
389
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
288
390
|
}
|
|
289
|
-
removeL1ToL2Messages(startIndex) {
|
|
391
|
+
/** Removes all L1 to L2 messages starting from the given index (inclusive). */ removeL1ToL2Messages(startIndex) {
|
|
290
392
|
return this.#messageStore.removeL1ToL2Messages(startIndex);
|
|
291
393
|
}
|
|
292
|
-
getPendingChainValidationStatus() {
|
|
394
|
+
/** Returns the last synced validation status of the pending chain. */ getPendingChainValidationStatus() {
|
|
293
395
|
return this.#blockStore.getPendingChainValidationStatus();
|
|
294
396
|
}
|
|
295
|
-
setPendingChainValidationStatus(status) {
|
|
397
|
+
/** Sets the last synced validation status of the pending chain. */ setPendingChainValidationStatus(status) {
|
|
296
398
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
297
399
|
}
|
|
298
|
-
|
|
400
|
+
/**
|
|
401
|
+
* Gets the number of the latest L2 block processed.
|
|
402
|
+
* @returns The number of the latest L2 block processed.
|
|
403
|
+
*/ getCheckpointedL2BlockNumber() {
|
|
299
404
|
return this.#blockStore.getCheckpointedL2BlockNumber();
|
|
300
405
|
}
|
|
301
|
-
|
|
406
|
+
/**
|
|
407
|
+
* Gets the number of the latest published checkpoint processed.
|
|
408
|
+
* @returns The number of the latest published checkpoint processed
|
|
409
|
+
*/ getSynchedCheckpointNumber() {
|
|
302
410
|
return this.#blockStore.getLatestCheckpointNumber();
|
|
303
411
|
}
|
|
304
|
-
|
|
412
|
+
/**
|
|
413
|
+
* Stores the l1 block number that checkpoints have been synched until
|
|
414
|
+
* @param l1BlockNumber - The l1 block number
|
|
415
|
+
*/ async setCheckpointSynchedL1BlockNumber(l1BlockNumber) {
|
|
305
416
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
306
417
|
}
|
|
307
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Retrieves all blocks for the requested checkpoint
|
|
420
|
+
* @param checkpointNumber Retrieves all blocks for the given checkpoint
|
|
421
|
+
* @returns The collection of blocks for the requested checkpoint if available (undefined otherwise)
|
|
422
|
+
*/ getBlocksForCheckpoint(checkpointNumber) {
|
|
308
423
|
return this.#blockStore.getBlocksForCheckpoint(checkpointNumber);
|
|
309
424
|
}
|
|
310
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Returns checkpoint data for the requested checkpoint number
|
|
427
|
+
* @param checkpointNumber - The checkpoint requested
|
|
428
|
+
* @returns The checkpoint data or undefined if not found
|
|
429
|
+
*/ getCheckpointData(checkpointNumber) {
|
|
311
430
|
return this.#blockStore.getCheckpointData(checkpointNumber);
|
|
312
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* Gets all blocks that have the given slot number.
|
|
434
|
+
* @param slotNumber - The slot number to search for.
|
|
435
|
+
* @returns All blocks with the given slot number.
|
|
436
|
+
*/ getBlocksForSlot(slotNumber) {
|
|
437
|
+
return this.#blockStore.getBlocksForSlot(slotNumber);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Removes all blocks with block number > blockNumber.
|
|
441
|
+
* @param blockNumber - The block number to remove after.
|
|
442
|
+
* @returns The removed blocks (for event emission).
|
|
443
|
+
*/ removeBlocksAfter(blockNumber) {
|
|
444
|
+
return this.#blockStore.unwindBlocksAfter(blockNumber);
|
|
445
|
+
}
|
|
313
446
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
4
|
+
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import { type LogFilter, type SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
|
+
import type { BlockStore } from './block_store.js';
|
|
7
|
+
/**
|
|
8
|
+
* A store for logs
|
|
9
|
+
*/
|
|
10
|
+
export declare class LogStore {
|
|
11
|
+
#private;
|
|
12
|
+
private db;
|
|
13
|
+
private blockStore;
|
|
14
|
+
constructor(db: AztecAsyncKVStore, blockStore: BlockStore, logsMaxPageSize?: number);
|
|
15
|
+
/**
|
|
16
|
+
* Append new logs to the store's list.
|
|
17
|
+
* @param blocks - The blocks for which to add the logs.
|
|
18
|
+
* @returns True if the operation is successful.
|
|
19
|
+
*/
|
|
20
|
+
addLogs(blocks: L2Block[]): Promise<boolean>;
|
|
21
|
+
deleteLogs(blocks: L2Block[]): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
24
|
+
* array implies no logs match that tag.
|
|
25
|
+
* @param tags - The tags to search for.
|
|
26
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
27
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
28
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
29
|
+
*/
|
|
30
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
33
|
+
* logs is returned. An empty array implies no logs match that tag.
|
|
34
|
+
* @param contractAddress - The contract address to search logs for.
|
|
35
|
+
* @param tags - The tags to search for.
|
|
36
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
37
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
38
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
39
|
+
*/
|
|
40
|
+
getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[], page?: number): Promise<TxScopedL2Log[][]>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets public logs based on the provided filter.
|
|
43
|
+
* @param filter - The filter to apply to the logs.
|
|
44
|
+
* @returns The requested logs.
|
|
45
|
+
*/
|
|
46
|
+
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets contract class logs based on the provided filter.
|
|
49
|
+
* @param filter - The filter to apply to the logs.
|
|
50
|
+
* @returns The requested logs.
|
|
51
|
+
*/
|
|
52
|
+
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hFLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBRSxPQUFPLEVBQWUsTUFBTSxxQkFBcUIsQ0FBQztBQUUzRCxPQUFPLEtBQUssRUFBRSw0QkFBNEIsRUFBRSxxQkFBcUIsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzNHLE9BQU8sRUFJTCxLQUFLLFNBQVMsRUFHZCxLQUFLLFNBQVMsRUFDZCxHQUFHLEVBQ0gsYUFBYSxFQUNkLE1BQU0sb0JBQW9CLENBQUM7QUFFNUIsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFbkQ7O0dBRUc7QUFDSCxxQkFBYSxRQUFROztJQWFqQixPQUFPLENBQUMsRUFBRTtJQUNWLE9BQU8sQ0FBQyxVQUFVO0lBRnBCLFlBQ1UsRUFBRSxFQUFFLGlCQUFpQixFQUNyQixVQUFVLEVBQUUsVUFBVSxFQUM5QixlQUFlLEdBQUUsTUFBYSxFQVUvQjtJQTRNRDs7OztPQUlHO0lBQ0gsT0FBTyxDQUFDLE1BQU0sRUFBRSxPQUFPLEVBQUUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBUzNDO0lBZ0JELFVBQVUsQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFFLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQTJCOUM7SUFFRDs7Ozs7OztPQU9HO0lBQ0csb0JBQW9CLENBQUMsSUFBSSxFQUFFLFNBQVMsRUFBRSxFQUFFLElBQUksR0FBRSxNQUFVLEdBQUcsT0FBTyxDQUFDLGFBQWEsRUFBRSxFQUFFLENBQUMsQ0FRMUY7SUFFRDs7Ozs7Ozs7T0FRRztJQUNHLCtCQUErQixDQUNuQyxlQUFlLEVBQUUsWUFBWSxFQUM3QixJQUFJLEVBQUUsR0FBRyxFQUFFLEVBQ1gsSUFBSSxHQUFFLE1BQVUsR0FDZixPQUFPLENBQUMsYUFBYSxFQUFFLEVBQUUsQ0FBQyxDQWE1QjtJQUVEOzs7O09BSUc7SUFDSCxhQUFhLENBQUMsTUFBTSxFQUFFLFNBQVMsR0FBRyxPQUFPLENBQUMscUJBQXFCLENBQUMsQ0FRL0Q7SUE2RUQ7Ozs7T0FJRztJQUNILG9CQUFvQixDQUFDLE1BQU0sRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBUTdFO0NBNkdGIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../src/store/log_store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAe,MAAM,qBAAqB,CAAC;AAE3D,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;AAE5B,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;IA4MD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAS3C;IAgBD,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CA2B9C;IAED;;;;;;;OAOG;IACG,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAQ1F;IAED;;;;;;;;OAQG;IACG,+BAA+B,CACnC,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,GAAE,MAAU,GACf,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAa5B;IAED;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQ/D;IA6ED;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAQ7E;CA6GF"}
|
|
@@ -1,9 +1,11 @@
|
|
|
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';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
6
7
|
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
8
|
+
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
7
9
|
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
8
10
|
/**
|
|
9
11
|
* A store for logs
|
|
@@ -95,60 +97,80 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
95
97
|
publicTaggedLogs
|
|
96
98
|
};
|
|
97
99
|
}
|
|
100
|
+
async #addPrivateLogs(blocks) {
|
|
101
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#privateLogKeysByBlock.hasAsync(block.number));
|
|
102
|
+
const { privateTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
103
|
+
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
104
|
+
const currentPrivateTaggedLogs = await Promise.all(keysOfPrivateLogsToUpdate.map(async (key)=>({
|
|
105
|
+
tag: key,
|
|
106
|
+
logBuffers: await this.#privateLogsByTag.getAsync(key)
|
|
107
|
+
})));
|
|
108
|
+
for (const taggedLogBuffer of currentPrivateTaggedLogs){
|
|
109
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
110
|
+
privateTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(privateTaggedLogs.get(taggedLogBuffer.tag)));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const block of newBlocks){
|
|
114
|
+
const privateTagsInBlock = [];
|
|
115
|
+
for (const [tag, logs] of privateTaggedLogs.entries()){
|
|
116
|
+
await this.#privateLogsByTag.set(tag, logs);
|
|
117
|
+
privateTagsInBlock.push(tag);
|
|
118
|
+
}
|
|
119
|
+
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async #addPublicLogs(blocks) {
|
|
123
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#publicLogKeysByBlock.hasAsync(block.number));
|
|
124
|
+
const { publicTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
125
|
+
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
126
|
+
const currentPublicTaggedLogs = await Promise.all(keysOfPublicLogsToUpdate.map(async (key)=>({
|
|
127
|
+
tag: key,
|
|
128
|
+
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key)
|
|
129
|
+
})));
|
|
130
|
+
for (const taggedLogBuffer of currentPublicTaggedLogs){
|
|
131
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
132
|
+
publicTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(publicTaggedLogs.get(taggedLogBuffer.tag)));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const block of newBlocks){
|
|
136
|
+
const blockHash = await block.hash();
|
|
137
|
+
const publicTagsInBlock = [];
|
|
138
|
+
for (const [tag, logs] of publicTaggedLogs.entries()){
|
|
139
|
+
await this.#publicLogsByContractAndTag.set(tag, logs);
|
|
140
|
+
publicTagsInBlock.push(tag);
|
|
141
|
+
}
|
|
142
|
+
await this.#publicLogKeysByBlock.set(block.number, publicTagsInBlock);
|
|
143
|
+
const publicLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
144
|
+
numToUInt32BE(txIndex),
|
|
145
|
+
numToUInt32BE(txEffect.publicLogs.length),
|
|
146
|
+
txEffect.publicLogs.map((log)=>log.toBuffer())
|
|
147
|
+
].flat()).flat();
|
|
148
|
+
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async #addContractClassLogs(blocks) {
|
|
152
|
+
const newBlocks = await filterAsync(blocks, async (block)=>!await this.#contractClassLogsByBlock.hasAsync(block.number));
|
|
153
|
+
for (const block of newBlocks){
|
|
154
|
+
const blockHash = await block.hash();
|
|
155
|
+
const contractClassLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
156
|
+
numToUInt32BE(txIndex),
|
|
157
|
+
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
158
|
+
txEffect.contractClassLogs.map((log)=>log.toBuffer())
|
|
159
|
+
].flat()).flat();
|
|
160
|
+
await this.#contractClassLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, contractClassLogsInBlock));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
98
163
|
/**
|
|
99
164
|
* Append new logs to the store's list.
|
|
100
165
|
* @param blocks - The blocks for which to add the logs.
|
|
101
166
|
* @returns True if the operation is successful.
|
|
102
167
|
*/ addLogs(blocks) {
|
|
103
|
-
const { privateTaggedLogs, publicTaggedLogs } = this.#extractTaggedLogs(blocks);
|
|
104
|
-
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
105
|
-
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
106
168
|
return this.db.transactionAsync(async ()=>{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
113
|
-
privateTaggedLogs.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(privateTaggedLogs.get(taggedLogBuffer.tag)));
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
const currentPublicTaggedLogs = await Promise.all(keysOfPublicLogsToUpdate.map(async (key)=>({
|
|
117
|
-
key,
|
|
118
|
-
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key)
|
|
119
|
-
})));
|
|
120
|
-
currentPublicTaggedLogs.forEach((taggedLogBuffer)=>{
|
|
121
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
122
|
-
publicTaggedLogs.set(taggedLogBuffer.key, taggedLogBuffer.logBuffers.concat(publicTaggedLogs.get(taggedLogBuffer.key)));
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
for (const block of blocks){
|
|
126
|
-
const blockHash = await block.hash();
|
|
127
|
-
const privateTagsInBlock = [];
|
|
128
|
-
for (const [tag, logs] of privateTaggedLogs.entries()){
|
|
129
|
-
await this.#privateLogsByTag.set(tag, logs);
|
|
130
|
-
privateTagsInBlock.push(tag);
|
|
131
|
-
}
|
|
132
|
-
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
133
|
-
const publicKeysInBlock = [];
|
|
134
|
-
for (const [key, logs] of publicTaggedLogs.entries()){
|
|
135
|
-
await this.#publicLogsByContractAndTag.set(key, logs);
|
|
136
|
-
publicKeysInBlock.push(key);
|
|
137
|
-
}
|
|
138
|
-
await this.#publicLogKeysByBlock.set(block.number, publicKeysInBlock);
|
|
139
|
-
const publicLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
140
|
-
numToUInt32BE(txIndex),
|
|
141
|
-
numToUInt32BE(txEffect.publicLogs.length),
|
|
142
|
-
txEffect.publicLogs.map((log)=>log.toBuffer())
|
|
143
|
-
].flat()).flat();
|
|
144
|
-
const contractClassLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
145
|
-
numToUInt32BE(txIndex),
|
|
146
|
-
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
147
|
-
txEffect.contractClassLogs.map((log)=>log.toBuffer())
|
|
148
|
-
].flat()).flat();
|
|
149
|
-
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
150
|
-
await this.#contractClassLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, contractClassLogsInBlock));
|
|
151
|
-
}
|
|
169
|
+
await Promise.all([
|
|
170
|
+
this.#addPrivateLogs(blocks),
|
|
171
|
+
this.#addPublicLogs(blocks),
|
|
172
|
+
this.#addContractClassLogs(blocks)
|
|
173
|
+
]);
|
|
152
174
|
return true;
|
|
153
175
|
});
|
|
154
176
|
}
|
|
@@ -185,21 +207,34 @@ import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, P
|
|
|
185
207
|
});
|
|
186
208
|
}
|
|
187
209
|
/**
|
|
188
|
-
* Gets
|
|
210
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
189
211
|
* array implies no logs match that tag.
|
|
190
|
-
|
|
212
|
+
* @param tags - The tags to search for.
|
|
213
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
214
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
215
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
216
|
+
*/ async getPrivateLogsByTags(tags, page = 0) {
|
|
191
217
|
const logs = await Promise.all(tags.map((tag)=>this.#privateLogsByTag.getAsync(tag.toString())));
|
|
192
|
-
|
|
218
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
219
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
220
|
+
return logs.map((logBuffers)=>logBuffers?.slice(start, end).map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
193
221
|
}
|
|
194
222
|
/**
|
|
195
|
-
* Gets
|
|
223
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
196
224
|
* logs is returned. An empty array implies no logs match that tag.
|
|
197
|
-
|
|
225
|
+
* @param contractAddress - The contract address to search logs for.
|
|
226
|
+
* @param tags - The tags to search for.
|
|
227
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
228
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
229
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
230
|
+
*/ async getPublicLogsByTagsFromContract(contractAddress, tags, page = 0) {
|
|
198
231
|
const logs = await Promise.all(tags.map((tag)=>{
|
|
199
232
|
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
200
233
|
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
201
234
|
}));
|
|
202
|
-
|
|
235
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
236
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
237
|
+
return logs.map((logBuffers)=>logBuffers?.slice(start, end).map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
203
238
|
}
|
|
204
239
|
/**
|
|
205
240
|
* Gets public logs based on the provided filter.
|