@aztec/archiver 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701
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 +768 -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/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/{archiver/errors.js → errors.js} +8 -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 +73 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +302 -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 +192 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +162 -48
- 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 +340 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +447 -0
- 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 +99 -67
- 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 +22 -15
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +163 -57
- 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 +523 -0
- package/src/{archiver/config.ts → config.ts} +13 -2
- package/src/{archiver/errors.ts → errors.ts} +12 -0
- 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 +423 -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 +210 -66
- 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 +236 -35
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +159 -106
- 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 +173 -67
- 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 -2790
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- 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/kv_archiver_store.js +0 -313
- 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 -2863
- package/src/archiver/index.ts +0 -6
- package/src/rpc/index.ts +0 -16
- /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/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
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM
|
|
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 type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
7
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import {
|
|
9
|
+
import { L2Block, L2BlockHash } from '@aztec/stdlib/block';
|
|
10
|
+
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
9
11
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
10
12
|
import {
|
|
11
13
|
ContractClassLog,
|
|
@@ -57,21 +59,16 @@ export class LogStore {
|
|
|
57
59
|
* @param block - The L2 block to extract logs from.
|
|
58
60
|
* @returns An object containing the private and public tagged logs for the block.
|
|
59
61
|
*/
|
|
60
|
-
|
|
61
|
-
const blockHash = L2BlockHash.fromField(await block.hash());
|
|
62
|
+
#extractTaggedLogsFromBlock(block: L2Block) {
|
|
62
63
|
// SiloedTag (as string) -> array of log buffers.
|
|
63
64
|
const privateTaggedLogs = new Map<string, Buffer[]>();
|
|
64
65
|
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
65
66
|
const publicTaggedLogs = new Map<string, Buffer[]>();
|
|
66
|
-
const dataStartIndexForBlock =
|
|
67
|
-
block.header.state.partial.noteHashTree.nextAvailableLeafIndex -
|
|
68
|
-
block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
69
67
|
|
|
70
|
-
block.body.txEffects.forEach(
|
|
68
|
+
block.body.txEffects.forEach(txEffect => {
|
|
71
69
|
const txHash = txEffect.txHash;
|
|
72
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
73
70
|
|
|
74
|
-
txEffect.privateLogs.forEach(
|
|
71
|
+
txEffect.privateLogs.forEach(log => {
|
|
75
72
|
// Private logs use SiloedTag (already siloed by kernel)
|
|
76
73
|
const tag = log.fields[0];
|
|
77
74
|
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
@@ -80,18 +77,17 @@ export class LogStore {
|
|
|
80
77
|
currentLogs.push(
|
|
81
78
|
new TxScopedL2Log(
|
|
82
79
|
txHash,
|
|
83
|
-
dataStartIndexForTx,
|
|
84
|
-
logIndex,
|
|
85
80
|
block.number,
|
|
86
|
-
blockHash,
|
|
87
81
|
block.timestamp,
|
|
88
|
-
log,
|
|
82
|
+
log.getEmittedFields(),
|
|
83
|
+
txEffect.noteHashes,
|
|
84
|
+
txEffect.nullifiers[0],
|
|
89
85
|
).toBuffer(),
|
|
90
86
|
);
|
|
91
87
|
privateTaggedLogs.set(tag.toString(), currentLogs);
|
|
92
88
|
});
|
|
93
89
|
|
|
94
|
-
txEffect.publicLogs.forEach(
|
|
90
|
+
txEffect.publicLogs.forEach(log => {
|
|
95
91
|
// Public logs use Tag directly (not siloed) and are stored with contract address
|
|
96
92
|
const tag = log.fields[0];
|
|
97
93
|
const contractAddress = log.contractAddress;
|
|
@@ -104,12 +100,11 @@ export class LogStore {
|
|
|
104
100
|
currentLogs.push(
|
|
105
101
|
new TxScopedL2Log(
|
|
106
102
|
txHash,
|
|
107
|
-
dataStartIndexForTx,
|
|
108
|
-
logIndex,
|
|
109
103
|
block.number,
|
|
110
|
-
blockHash,
|
|
111
104
|
block.timestamp,
|
|
112
|
-
log,
|
|
105
|
+
log.getEmittedFields(),
|
|
106
|
+
txEffect.noteHashes,
|
|
107
|
+
txEffect.nullifiers[0],
|
|
113
108
|
).toBuffer(),
|
|
114
109
|
);
|
|
115
110
|
publicTaggedLogs.set(key, currentLogs);
|
|
@@ -125,10 +120,11 @@ export class LogStore {
|
|
|
125
120
|
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
126
121
|
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
127
122
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
#extractTaggedLogs(blocks: L2Block[]): {
|
|
124
|
+
privateTaggedLogs: Map<string, Buffer[]>;
|
|
125
|
+
publicTaggedLogs: Map<string, Buffer[]>;
|
|
126
|
+
} {
|
|
127
|
+
const taggedLogsInBlocks = blocks.map(block => this.#extractTaggedLogsFromBlock(block));
|
|
132
128
|
|
|
133
129
|
// Now we merge the maps from each block into a single map.
|
|
134
130
|
const privateTaggedLogs = taggedLogsInBlocks.reduce((acc, { privateTaggedLogs }) => {
|
|
@@ -150,92 +146,127 @@ export class LogStore {
|
|
|
150
146
|
return { privateTaggedLogs, publicTaggedLogs };
|
|
151
147
|
}
|
|
152
148
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
async addLogs(blocks: L2BlockNew[]): Promise<boolean> {
|
|
159
|
-
const { privateTaggedLogs, publicTaggedLogs } = await this.#extractTaggedLogs(blocks);
|
|
149
|
+
async #addPrivateLogs(blocks: L2Block[]): Promise<void> {
|
|
150
|
+
const newBlocks = await filterAsync(
|
|
151
|
+
blocks,
|
|
152
|
+
async block => !(await this.#privateLogKeysByBlock.hasAsync(block.number)),
|
|
153
|
+
);
|
|
160
154
|
|
|
155
|
+
const { privateTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
161
156
|
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
162
|
-
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
163
157
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
);
|
|
171
|
-
currentPrivateTaggedLogs.forEach(taggedLogBuffer => {
|
|
172
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
173
|
-
privateTaggedLogs.set(
|
|
174
|
-
taggedLogBuffer.tag,
|
|
175
|
-
taggedLogBuffer.logBuffers!.concat(privateTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
158
|
+
const currentPrivateTaggedLogs = await Promise.all(
|
|
159
|
+
keysOfPrivateLogsToUpdate.map(async key => ({
|
|
160
|
+
tag: key,
|
|
161
|
+
logBuffers: await this.#privateLogsByTag.getAsync(key),
|
|
162
|
+
})),
|
|
163
|
+
);
|
|
179
164
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
publicTaggedLogs.set(
|
|
189
|
-
taggedLogBuffer.key,
|
|
190
|
-
taggedLogBuffer.logBuffers!.concat(publicTaggedLogs.get(taggedLogBuffer.key)!),
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
165
|
+
for (const taggedLogBuffer of currentPrivateTaggedLogs) {
|
|
166
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
167
|
+
privateTaggedLogs.set(
|
|
168
|
+
taggedLogBuffer.tag,
|
|
169
|
+
taggedLogBuffer.logBuffers!.concat(privateTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
194
173
|
|
|
195
|
-
|
|
196
|
-
|
|
174
|
+
for (const block of newBlocks) {
|
|
175
|
+
const privateTagsInBlock: string[] = [];
|
|
176
|
+
for (const [tag, logs] of privateTaggedLogs.entries()) {
|
|
177
|
+
await this.#privateLogsByTag.set(tag, logs);
|
|
178
|
+
privateTagsInBlock.push(tag);
|
|
179
|
+
}
|
|
180
|
+
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
197
183
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
184
|
+
async #addPublicLogs(blocks: L2Block[]): Promise<void> {
|
|
185
|
+
const newBlocks = await filterAsync(
|
|
186
|
+
blocks,
|
|
187
|
+
async block => !(await this.#publicLogKeysByBlock.hasAsync(block.number)),
|
|
188
|
+
);
|
|
204
189
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
)
|
|
220
|
-
.flat();
|
|
221
|
-
|
|
222
|
-
const contractClassLogsInBlock = block.body.txEffects
|
|
223
|
-
.map((txEffect, txIndex) =>
|
|
224
|
-
[
|
|
225
|
-
numToUInt32BE(txIndex),
|
|
226
|
-
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
227
|
-
txEffect.contractClassLogs.map(log => log.toBuffer()),
|
|
228
|
-
].flat(),
|
|
229
|
-
)
|
|
230
|
-
.flat();
|
|
231
|
-
|
|
232
|
-
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
233
|
-
await this.#contractClassLogsByBlock.set(
|
|
234
|
-
block.number,
|
|
235
|
-
this.#packWithBlockHash(blockHash, contractClassLogsInBlock),
|
|
190
|
+
const { publicTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
191
|
+
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
192
|
+
|
|
193
|
+
const currentPublicTaggedLogs = await Promise.all(
|
|
194
|
+
keysOfPublicLogsToUpdate.map(async key => ({
|
|
195
|
+
tag: key,
|
|
196
|
+
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key),
|
|
197
|
+
})),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
for (const taggedLogBuffer of currentPublicTaggedLogs) {
|
|
201
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
202
|
+
publicTaggedLogs.set(
|
|
203
|
+
taggedLogBuffer.tag,
|
|
204
|
+
taggedLogBuffer.logBuffers!.concat(publicTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
236
205
|
);
|
|
237
206
|
}
|
|
207
|
+
}
|
|
238
208
|
|
|
209
|
+
for (const block of newBlocks) {
|
|
210
|
+
const blockHash = await block.hash();
|
|
211
|
+
const publicTagsInBlock: string[] = [];
|
|
212
|
+
for (const [tag, logs] of publicTaggedLogs.entries()) {
|
|
213
|
+
await this.#publicLogsByContractAndTag.set(tag, logs);
|
|
214
|
+
publicTagsInBlock.push(tag);
|
|
215
|
+
}
|
|
216
|
+
await this.#publicLogKeysByBlock.set(block.number, publicTagsInBlock);
|
|
217
|
+
|
|
218
|
+
const publicLogsInBlock = block.body.txEffects
|
|
219
|
+
.map((txEffect, txIndex) =>
|
|
220
|
+
[
|
|
221
|
+
numToUInt32BE(txIndex),
|
|
222
|
+
numToUInt32BE(txEffect.publicLogs.length),
|
|
223
|
+
txEffect.publicLogs.map(log => log.toBuffer()),
|
|
224
|
+
].flat(),
|
|
225
|
+
)
|
|
226
|
+
.flat();
|
|
227
|
+
|
|
228
|
+
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async #addContractClassLogs(blocks: L2Block[]): Promise<void> {
|
|
233
|
+
const newBlocks = await filterAsync(
|
|
234
|
+
blocks,
|
|
235
|
+
async block => !(await this.#contractClassLogsByBlock.hasAsync(block.number)),
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
for (const block of newBlocks) {
|
|
239
|
+
const blockHash = await block.hash();
|
|
240
|
+
|
|
241
|
+
const contractClassLogsInBlock = block.body.txEffects
|
|
242
|
+
.map((txEffect, txIndex) =>
|
|
243
|
+
[
|
|
244
|
+
numToUInt32BE(txIndex),
|
|
245
|
+
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
246
|
+
txEffect.contractClassLogs.map(log => log.toBuffer()),
|
|
247
|
+
].flat(),
|
|
248
|
+
)
|
|
249
|
+
.flat();
|
|
250
|
+
|
|
251
|
+
await this.#contractClassLogsByBlock.set(
|
|
252
|
+
block.number,
|
|
253
|
+
this.#packWithBlockHash(blockHash, contractClassLogsInBlock),
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Append new logs to the store's list.
|
|
260
|
+
* @param blocks - The blocks for which to add the logs.
|
|
261
|
+
* @returns True if the operation is successful.
|
|
262
|
+
*/
|
|
263
|
+
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
264
|
+
return this.db.transactionAsync(async () => {
|
|
265
|
+
await Promise.all([
|
|
266
|
+
this.#addPrivateLogs(blocks),
|
|
267
|
+
this.#addPublicLogs(blocks),
|
|
268
|
+
this.#addContractClassLogs(blocks),
|
|
269
|
+
]);
|
|
239
270
|
return true;
|
|
240
271
|
});
|
|
241
272
|
}
|
|
@@ -254,7 +285,7 @@ export class LogStore {
|
|
|
254
285
|
return L2BlockHash.fromField(blockHash);
|
|
255
286
|
}
|
|
256
287
|
|
|
257
|
-
deleteLogs(blocks:
|
|
288
|
+
deleteLogs(blocks: L2Block[]): Promise<boolean> {
|
|
258
289
|
return this.db.transactionAsync(async () => {
|
|
259
290
|
await Promise.all(
|
|
260
291
|
blocks.map(async block => {
|
|
@@ -284,27 +315,49 @@ export class LogStore {
|
|
|
284
315
|
}
|
|
285
316
|
|
|
286
317
|
/**
|
|
287
|
-
* Gets
|
|
318
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
288
319
|
* array implies no logs match that tag.
|
|
320
|
+
* @param tags - The tags to search for.
|
|
321
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
322
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
323
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
289
324
|
*/
|
|
290
|
-
async getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
|
|
325
|
+
async getPrivateLogsByTags(tags: SiloedTag[], page: number = 0): Promise<TxScopedL2Log[][]> {
|
|
291
326
|
const logs = await Promise.all(tags.map(tag => this.#privateLogsByTag.getAsync(tag.toString())));
|
|
327
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
328
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
292
329
|
|
|
293
|
-
return logs.map(
|
|
330
|
+
return logs.map(
|
|
331
|
+
logBuffers => logBuffers?.slice(start, end).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
|
|
332
|
+
);
|
|
294
333
|
}
|
|
295
334
|
|
|
296
335
|
/**
|
|
297
|
-
* Gets
|
|
336
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
298
337
|
* logs is returned. An empty array implies no logs match that tag.
|
|
338
|
+
* @param contractAddress - The contract address to search logs for.
|
|
339
|
+
* @param tags - The tags to search for.
|
|
340
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
341
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
342
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
299
343
|
*/
|
|
300
|
-
async getPublicLogsByTagsFromContract(
|
|
344
|
+
async getPublicLogsByTagsFromContract(
|
|
345
|
+
contractAddress: AztecAddress,
|
|
346
|
+
tags: Tag[],
|
|
347
|
+
page: number = 0,
|
|
348
|
+
): Promise<TxScopedL2Log[][]> {
|
|
301
349
|
const logs = await Promise.all(
|
|
302
350
|
tags.map(tag => {
|
|
303
351
|
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
304
352
|
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
305
353
|
}),
|
|
306
354
|
);
|
|
307
|
-
|
|
355
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
356
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
357
|
+
|
|
358
|
+
return logs.map(
|
|
359
|
+
logBuffers => logBuffers?.slice(start, end).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
|
|
360
|
+
);
|
|
308
361
|
}
|
|
309
362
|
|
|
310
363
|
/**
|