@aztec/archiver 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a
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 +19 -11
- package/dest/archiver.d.ts +39 -17
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +260 -160
- package/dest/config.d.ts +6 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -15
- package/dest/errors.d.ts +55 -9
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +81 -14
- package/dest/factory.d.ts +13 -9
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +51 -37
- package/dest/index.d.ts +12 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +11 -2
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- package/dest/l1/calldata_retriever.d.ts +74 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +201 -260
- package/dest/l1/data_retrieval.d.ts +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +42 -47
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +12 -66
- package/dest/l1/trace_tx.d.ts.map +1 -1
- 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/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +71 -42
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +270 -179
- package/dest/modules/data_store_updater.d.ts +49 -17
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +211 -121
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +44 -9
- package/dest/modules/l1_synchronizer.d.ts +14 -12
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +443 -211
- 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 +174 -66
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +743 -245
- package/dest/store/contract_class_store.d.ts +17 -4
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +24 -68
- package/dest/store/contract_instance_store.d.ts +28 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +37 -2
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +42 -37
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +262 -388
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +11 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +51 -9
- package/dest/test/fake_l1_state.d.ts +25 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +166 -32
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +62 -41
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +321 -202
- 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 +12 -6
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +26 -9
- package/package.json +14 -14
- package/src/archiver.ts +319 -181
- package/src/config.ts +32 -12
- package/src/errors.ts +122 -21
- package/src/factory.ts +75 -36
- package/src/index.ts +19 -2
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +260 -379
- package/src/l1/data_retrieval.ts +58 -69
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +347 -221
- package/src/modules/data_store_updater.ts +248 -153
- package/src/modules/instrumentation.ts +56 -9
- package/src/modules/l1_synchronizer.ts +585 -258
- package/src/modules/validation.ts +10 -9
- package/src/store/block_store.ts +924 -300
- package/src/store/contract_class_store.ts +31 -103
- package/src/store/contract_instance_store.ts +51 -5
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +303 -499
- package/src/store/log_store_codec.ts +132 -0
- package/src/store/message_store.ts +60 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +213 -42
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +394 -210
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +39 -9
- package/dest/store/kv_archiver_store.d.ts +0 -340
- package/dest/store/kv_archiver_store.d.ts.map +0 -1
- package/dest/store/kv_archiver_store.js +0 -446
- package/src/store/kv_archiver_store.ts +0 -639
package/src/store/log_store.ts
CHANGED
|
@@ -1,575 +1,379 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { filterAsync } from '@aztec/foundation/collection';
|
|
4
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
7
4
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
8
|
-
import type {
|
|
9
|
-
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
5
|
+
import type { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
10
6
|
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
LogId,
|
|
18
|
-
PublicLog,
|
|
19
|
-
type SiloedTag,
|
|
7
|
+
import type {
|
|
8
|
+
LogCursor,
|
|
9
|
+
LogResult,
|
|
10
|
+
PrivateLogsQuery,
|
|
11
|
+
PublicLogsQuery,
|
|
12
|
+
SiloedTag,
|
|
20
13
|
Tag,
|
|
21
|
-
|
|
14
|
+
TagQuery,
|
|
22
15
|
} from '@aztec/stdlib/logs';
|
|
16
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
23
17
|
|
|
24
18
|
import type { BlockStore } from './block_store.js';
|
|
19
|
+
import {
|
|
20
|
+
decodeKeyTail,
|
|
21
|
+
decodeValue,
|
|
22
|
+
encodeKey,
|
|
23
|
+
encodePublicPrefix,
|
|
24
|
+
encodeValue,
|
|
25
|
+
endOfTagRange,
|
|
26
|
+
endOfTxRange,
|
|
27
|
+
fieldHex,
|
|
28
|
+
incKey,
|
|
29
|
+
} from './log_store_codec.js';
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
|
-
*
|
|
32
|
+
* Indexes every emitted private and public log under a composite hex-string key
|
|
33
|
+
* `[contractAddress (public only)]-tag-blockNumber-txIndexWithinBlock-logIndexWithinTx`,
|
|
34
|
+
* where each numeric segment is zero-padded to 8 lowercase hex digits (4 bytes BE) and
|
|
35
|
+
* `contractAddress` / `tag` are the bare 64-hex-char field representations (no `0x` prefix). The
|
|
36
|
+
* fixed-width zero-padded hex segments sort lexicographically in the same order as the canonical
|
|
37
|
+
* `(contract, tag, blockNumber, txIndexWithinBlock, logIndexWithinTx)` tuple, so a single ordered
|
|
38
|
+
* range scan answers every {@link PrivateLogsQuery} / {@link PublicLogsQuery}.
|
|
39
|
+
*
|
|
40
|
+
* Per-block secondary indices (`#privateKeysByBlock`, `#publicKeysByBlock`) record the exact primary
|
|
41
|
+
* keys written for each block so {@link deleteLogs} can drop them on reorg without having to range
|
|
42
|
+
* scan by block (block isn't the leading key segment).
|
|
43
|
+
*
|
|
44
|
+
* Contract-class logs are no longer stored or served by the log store.
|
|
28
45
|
*/
|
|
29
46
|
export class LogStore {
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
|
|
47
|
+
/** Primary map: composite private key (tag + tail = 96 hex chars + separators) -> serialized {@link StoredLogValue}. */
|
|
48
|
+
#privateLogs: AztecAsyncMap<string, Buffer>;
|
|
49
|
+
/** Primary map: composite public key (contract + tag + tail) -> serialized {@link StoredLogValue}. */
|
|
50
|
+
#publicLogs: AztecAsyncMap<string, Buffer>;
|
|
51
|
+
|
|
52
|
+
/** Secondary deletion index: blockNumber -> the exact primary keys written for that block. */
|
|
53
|
+
#privateKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
54
|
+
#publicKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
55
|
+
|
|
39
56
|
#log = createLogger('archiver:log_store');
|
|
40
57
|
|
|
58
|
+
/**
|
|
59
|
+
* @param genesisBlockHash - Hash of the synthetic genesis block. During early sync the PXE anchors to
|
|
60
|
+
* genesis and passes its hash as a query `referenceBlock`; since the archiver never indexes the
|
|
61
|
+
* genesis block, the store recognizes this hash directly and resolves it to the genesis block number
|
|
62
|
+
* rather than mistaking it for a reorg.
|
|
63
|
+
*/
|
|
41
64
|
constructor(
|
|
42
65
|
private db: AztecAsyncKVStore,
|
|
43
66
|
private blockStore: BlockStore,
|
|
44
|
-
|
|
67
|
+
private readonly genesisBlockHash: BlockHash,
|
|
45
68
|
) {
|
|
46
|
-
this.#
|
|
47
|
-
this.#
|
|
48
|
-
this.#
|
|
49
|
-
this.#
|
|
50
|
-
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
51
|
-
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
52
|
-
|
|
53
|
-
this.#logsMaxPageSize = logsMaxPageSize;
|
|
69
|
+
this.#privateLogs = db.openMap('archiver_private_logs');
|
|
70
|
+
this.#publicLogs = db.openMap('archiver_public_logs');
|
|
71
|
+
this.#privateKeysByBlock = db.openMap('archiver_private_log_keys_by_block');
|
|
72
|
+
this.#publicKeysByBlock = db.openMap('archiver_public_log_keys_by_block');
|
|
54
73
|
}
|
|
55
74
|
|
|
56
75
|
/**
|
|
57
|
-
*
|
|
76
|
+
* Indexes every emitted private and public log from the given blocks. Wraps the write in a single
|
|
77
|
+
* `db.transactionAsync` so the primary entries and the per-block secondary indices stay consistent.
|
|
58
78
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
#extractTaggedLogsFromBlock(block: L2Block) {
|
|
63
|
-
// SiloedTag (as string) -> array of log buffers.
|
|
64
|
-
const privateTaggedLogs = new Map<string, Buffer[]>();
|
|
65
|
-
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
66
|
-
const publicTaggedLogs = new Map<string, Buffer[]>();
|
|
67
|
-
|
|
68
|
-
block.body.txEffects.forEach(txEffect => {
|
|
69
|
-
const txHash = txEffect.txHash;
|
|
70
|
-
|
|
71
|
-
txEffect.privateLogs.forEach(log => {
|
|
72
|
-
// Private logs use SiloedTag (already siloed by kernel)
|
|
73
|
-
const tag = log.fields[0];
|
|
74
|
-
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
75
|
-
|
|
76
|
-
const currentLogs = privateTaggedLogs.get(tag.toString()) ?? [];
|
|
77
|
-
currentLogs.push(
|
|
78
|
-
new TxScopedL2Log(
|
|
79
|
-
txHash,
|
|
80
|
-
block.number,
|
|
81
|
-
block.timestamp,
|
|
82
|
-
log.getEmittedFields(),
|
|
83
|
-
txEffect.noteHashes,
|
|
84
|
-
txEffect.nullifiers[0],
|
|
85
|
-
).toBuffer(),
|
|
86
|
-
);
|
|
87
|
-
privateTaggedLogs.set(tag.toString(), currentLogs);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
txEffect.publicLogs.forEach(log => {
|
|
91
|
-
// Public logs use Tag directly (not siloed) and are stored with contract address
|
|
92
|
-
const tag = log.fields[0];
|
|
93
|
-
const contractAddress = log.contractAddress;
|
|
94
|
-
const key = `${contractAddress.toString()}_${tag.toString()}`;
|
|
95
|
-
this.#log.debug(
|
|
96
|
-
`Found public log with tag ${tag.toString()} from contract ${contractAddress.toString()} in block ${block.number}`,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const currentLogs = publicTaggedLogs.get(key) ?? [];
|
|
100
|
-
currentLogs.push(
|
|
101
|
-
new TxScopedL2Log(
|
|
102
|
-
txHash,
|
|
103
|
-
block.number,
|
|
104
|
-
block.timestamp,
|
|
105
|
-
log.getEmittedFields(),
|
|
106
|
-
txEffect.noteHashes,
|
|
107
|
-
txEffect.nullifiers[0],
|
|
108
|
-
).toBuffer(),
|
|
109
|
-
);
|
|
110
|
-
publicTaggedLogs.set(key, currentLogs);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return { privateTaggedLogs, publicTaggedLogs };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Extracts and aggregates tagged logs from a list of blocks.
|
|
119
|
-
* @param blocks - The blocks to extract logs from.
|
|
120
|
-
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
121
|
-
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
79
|
+
* A block is only ever added once; on reorg the archiver calls {@link deleteLogs} first, so we write
|
|
80
|
+
* the secondary index entries with a plain `set` (overwrite) rather than read-modify-append.
|
|
122
81
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
await this.#privateLogsByTag.set(tag, logs);
|
|
178
|
-
privateTagsInBlock.push(tag);
|
|
179
|
-
}
|
|
180
|
-
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async #addPublicLogs(blocks: L2Block[]): Promise<void> {
|
|
185
|
-
const newBlocks = await filterAsync(
|
|
186
|
-
blocks,
|
|
187
|
-
async block => !(await this.#publicLogKeysByBlock.hasAsync(block.number)),
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
const { publicTaggedLogs } = this.#extractTaggedLogs(newBlocks);
|
|
191
|
-
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
82
|
+
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
83
|
+
return this.db.transactionAsync(async () => {
|
|
84
|
+
for (const block of blocks) {
|
|
85
|
+
const blockHash = await block.hash();
|
|
86
|
+
const blockNumber = block.number;
|
|
87
|
+
const blockTimestamp = block.timestamp;
|
|
88
|
+
|
|
89
|
+
const privateKeys: string[] = [];
|
|
90
|
+
const privateValues: Buffer[] = [];
|
|
91
|
+
const publicKeys: string[] = [];
|
|
92
|
+
const publicValues: Buffer[] = [];
|
|
93
|
+
|
|
94
|
+
for (let txIndexWithinBlock = 0; txIndexWithinBlock < block.body.txEffects.length; txIndexWithinBlock++) {
|
|
95
|
+
const txEffect = block.body.txEffects[txIndexWithinBlock];
|
|
96
|
+
const txHash = txEffect.txHash;
|
|
97
|
+
|
|
98
|
+
// Private and public log indices are counted independently per tx, each starting at 0.
|
|
99
|
+
let privateLogIndexWithinTx = 0;
|
|
100
|
+
let publicLogIndexWithinTx = 0;
|
|
101
|
+
|
|
102
|
+
for (const log of txEffect.privateLogs) {
|
|
103
|
+
const tagHex = fieldHex(log.fields[0]);
|
|
104
|
+
const key = encodeKey(tagHex, blockNumber, txIndexWithinBlock, privateLogIndexWithinTx);
|
|
105
|
+
const value = encodeValue({
|
|
106
|
+
txHash,
|
|
107
|
+
blockHash,
|
|
108
|
+
blockTimestamp,
|
|
109
|
+
logData: log.getEmittedFields(),
|
|
110
|
+
});
|
|
111
|
+
privateKeys.push(key);
|
|
112
|
+
privateValues.push(value);
|
|
113
|
+
privateLogIndexWithinTx++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const log of txEffect.publicLogs) {
|
|
117
|
+
const contractHex = fieldHex(log.contractAddress);
|
|
118
|
+
const tagHex = fieldHex(log.fields[0]);
|
|
119
|
+
const key = encodeKey(
|
|
120
|
+
encodePublicPrefix(contractHex, tagHex),
|
|
121
|
+
blockNumber,
|
|
122
|
+
txIndexWithinBlock,
|
|
123
|
+
publicLogIndexWithinTx,
|
|
124
|
+
);
|
|
125
|
+
const value = encodeValue({
|
|
126
|
+
txHash,
|
|
127
|
+
blockHash,
|
|
128
|
+
blockTimestamp,
|
|
129
|
+
logData: log.getEmittedFields(),
|
|
130
|
+
});
|
|
131
|
+
publicKeys.push(key);
|
|
132
|
+
publicValues.push(value);
|
|
133
|
+
publicLogIndexWithinTx++;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
192
136
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
137
|
+
for (let i = 0; i < privateKeys.length; i++) {
|
|
138
|
+
await this.#privateLogs.set(privateKeys[i], privateValues[i]);
|
|
139
|
+
}
|
|
140
|
+
for (let i = 0; i < publicKeys.length; i++) {
|
|
141
|
+
await this.#publicLogs.set(publicKeys[i], publicValues[i]);
|
|
142
|
+
}
|
|
199
143
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
publicTaggedLogs.set(
|
|
203
|
-
taggedLogBuffer.tag,
|
|
204
|
-
taggedLogBuffer.logBuffers!.concat(publicTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
144
|
+
await this.#privateKeysByBlock.set(blockNumber, privateKeys);
|
|
145
|
+
await this.#publicKeysByBlock.set(blockNumber, publicKeys);
|
|
208
146
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
publicTagsInBlock.push(tag);
|
|
147
|
+
this.#log.debug(`Indexed logs for block ${blockNumber}`, {
|
|
148
|
+
blockNumber,
|
|
149
|
+
privateCount: privateKeys.length,
|
|
150
|
+
publicCount: publicKeys.length,
|
|
151
|
+
});
|
|
215
152
|
}
|
|
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
|
-
]);
|
|
270
153
|
return true;
|
|
271
154
|
});
|
|
272
155
|
}
|
|
273
156
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
#unpackBlockHash(reader: BufferReader): BlockHash {
|
|
279
|
-
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
280
|
-
|
|
281
|
-
if (!blockHash) {
|
|
282
|
-
throw new Error('Failed to read block hash from log entry buffer');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return new BlockHash(blockHash);
|
|
286
|
-
}
|
|
287
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Deletes every log indexed under any of the given blocks. Secondary-index driven, so it doesn't
|
|
159
|
+
* have to range-scan the primary maps.
|
|
160
|
+
*/
|
|
288
161
|
deleteLogs(blocks: L2Block[]): Promise<boolean> {
|
|
289
162
|
return this.db.transactionAsync(async () => {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
this.#
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
);
|
|
312
|
-
|
|
163
|
+
for (const block of blocks) {
|
|
164
|
+
const blockNumber = block.number;
|
|
165
|
+
|
|
166
|
+
const [privateKeys, publicKeys] = await Promise.all([
|
|
167
|
+
this.#privateKeysByBlock.getAsync(blockNumber),
|
|
168
|
+
this.#publicKeysByBlock.getAsync(blockNumber),
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
if (privateKeys) {
|
|
172
|
+
for (const key of privateKeys) {
|
|
173
|
+
await this.#privateLogs.delete(key);
|
|
174
|
+
}
|
|
175
|
+
await this.#privateKeysByBlock.delete(blockNumber);
|
|
176
|
+
}
|
|
177
|
+
if (publicKeys) {
|
|
178
|
+
for (const key of publicKeys) {
|
|
179
|
+
await this.#publicLogs.delete(key);
|
|
180
|
+
}
|
|
181
|
+
await this.#publicKeysByBlock.delete(blockNumber);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
313
184
|
return true;
|
|
314
185
|
});
|
|
315
186
|
}
|
|
316
187
|
|
|
317
|
-
/**
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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.
|
|
324
|
-
*/
|
|
325
|
-
async getPrivateLogsByTags(tags: SiloedTag[], page: number = 0): Promise<TxScopedL2Log[][]> {
|
|
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;
|
|
329
|
-
|
|
330
|
-
return logs.map(
|
|
331
|
-
logBuffers => logBuffers?.slice(start, end).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
|
|
332
|
-
);
|
|
188
|
+
/** Returns one inner array per element of `query.tags`, in input order. */
|
|
189
|
+
getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
190
|
+
LogStore.#validateQuery(query);
|
|
191
|
+
return this.db.transactionAsync(() => this.#runQuery(query, /* contractHex */ undefined));
|
|
333
192
|
}
|
|
334
193
|
|
|
335
|
-
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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.
|
|
343
|
-
*/
|
|
344
|
-
async getPublicLogsByTagsFromContract(
|
|
345
|
-
contractAddress: AztecAddress,
|
|
346
|
-
tags: Tag[],
|
|
347
|
-
page: number = 0,
|
|
348
|
-
): Promise<TxScopedL2Log[][]> {
|
|
349
|
-
const logs = await Promise.all(
|
|
350
|
-
tags.map(tag => {
|
|
351
|
-
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
352
|
-
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
353
|
-
}),
|
|
354
|
-
);
|
|
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
|
-
);
|
|
194
|
+
/** Returns one inner array per element of `query.tags`, in input order. */
|
|
195
|
+
getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
|
|
196
|
+
LogStore.#validateQuery(query);
|
|
197
|
+
return this.db.transactionAsync(() => this.#runQuery(query, fieldHex(query.contractAddress)));
|
|
361
198
|
}
|
|
362
199
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
* @returns The requested logs.
|
|
367
|
-
*/
|
|
368
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
369
|
-
if (filter.afterLog) {
|
|
370
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
371
|
-
} else if (filter.txHash) {
|
|
372
|
-
return this.#filterPublicLogsOfTx(filter);
|
|
373
|
-
} else {
|
|
374
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
200
|
+
static #validateQuery(query: { txHash?: TxHash; fromBlock?: unknown; toBlock?: unknown }): void {
|
|
201
|
+
if (query.txHash !== undefined && (query.fromBlock !== undefined || query.toBlock !== undefined)) {
|
|
202
|
+
throw new Error('`txHash` is mutually exclusive with `fromBlock`/`toBlock`');
|
|
375
203
|
}
|
|
376
204
|
}
|
|
377
205
|
|
|
378
|
-
async #
|
|
379
|
-
|
|
380
|
-
|
|
206
|
+
async #runQuery(query: PrivateLogsQuery | PublicLogsQuery, contractHex: string | undefined): Promise<LogResult[][]> {
|
|
207
|
+
const isPublic = contractHex !== undefined;
|
|
208
|
+
const tags = (query.tags as ReadonlyArray<TagQuery<Tag | SiloedTag>>) ?? [];
|
|
209
|
+
const primaryMap = isPublic ? this.#publicLogs : this.#privateLogs;
|
|
210
|
+
|
|
211
|
+
// referenceBlock reorg check, in-transaction, against the same db the log primary maps live on. The
|
|
212
|
+
// genesis block is a valid anchor during early sync but is synthetic and never indexed in the block
|
|
213
|
+
// store, so resolve it directly to the genesis block number rather than mistaking it for a reorg.
|
|
214
|
+
let referenceBlockNumber: number | undefined;
|
|
215
|
+
if (query.referenceBlock) {
|
|
216
|
+
if (query.referenceBlock.equals(this.genesisBlockHash)) {
|
|
217
|
+
referenceBlockNumber = INITIAL_L2_BLOCK_NUM - 1;
|
|
218
|
+
} else {
|
|
219
|
+
const refBlk = await this.blockStore.getBlockData({ hash: query.referenceBlock });
|
|
220
|
+
if (!refBlk) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
`Reference block ${query.referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
referenceBlockNumber = refBlk.header.globalVariables.blockNumber;
|
|
226
|
+
}
|
|
381
227
|
}
|
|
382
228
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
229
|
+
// Compute the exclusive upper-block bound across `toBlock` and `referenceBlock`.
|
|
230
|
+
// `toBlock` is already exclusive; `referenceBlock` caps inclusively, so its exclusive form is +1.
|
|
231
|
+
let upperExclusive: number | undefined;
|
|
232
|
+
if (query.toBlock !== undefined) {
|
|
233
|
+
upperExclusive = query.toBlock;
|
|
234
|
+
}
|
|
235
|
+
if (referenceBlockNumber !== undefined) {
|
|
236
|
+
const refExclusive = referenceBlockNumber + 1;
|
|
237
|
+
upperExclusive = upperExclusive === undefined ? refExclusive : Math.min(upperExclusive, refExclusive);
|
|
386
238
|
}
|
|
387
239
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
399
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
240
|
+
// Resolve txHash -> (blockNumber, txIndexInBlock) once for the whole query.
|
|
241
|
+
let txLocation: [number, number] | undefined;
|
|
242
|
+
if (query.txHash) {
|
|
243
|
+
const loc = await this.blockStore.getTxLocation(query.txHash);
|
|
244
|
+
if (!loc) {
|
|
245
|
+
return tags.map(() => []);
|
|
246
|
+
}
|
|
247
|
+
txLocation = loc;
|
|
248
|
+
if (upperExclusive !== undefined && txLocation[0] >= upperExclusive) {
|
|
249
|
+
return tags.map(() => []);
|
|
400
250
|
}
|
|
401
251
|
}
|
|
402
252
|
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
253
|
+
const fromBlock = query.fromBlock ?? INITIAL_L2_BLOCK_NUM;
|
|
254
|
+
const includeEffects = query.includeEffects === true;
|
|
255
|
+
|
|
256
|
+
const perTagResults: LogResult[][] = [];
|
|
257
|
+
for (const tagEntry of tags) {
|
|
258
|
+
const { tagHex, afterLog } = normalizeTagEntry(tagEntry);
|
|
259
|
+
const prefix = contractHex !== undefined ? encodePublicPrefix(contractHex, tagHex) : tagHex;
|
|
260
|
+
|
|
261
|
+
const end = txLocation
|
|
262
|
+
? endOfTxRange(prefix, txLocation[0], txLocation[1])
|
|
263
|
+
: endOfTagRange(prefix, upperExclusive);
|
|
264
|
+
|
|
265
|
+
let start: string;
|
|
266
|
+
if (afterLog) {
|
|
267
|
+
// Cursor wins as the start; `fromBlock` is ignored (fine if the cursor sits below it). The cursor
|
|
268
|
+
// carries `(blockNumber, txIndexWithinBlock, logIndexWithinTx)`, which slot directly into the
|
|
269
|
+
// composite key — no tx-hash lookup needed.
|
|
270
|
+
start = incKey(encodeKey(prefix, afterLog.blockNumber, afterLog.txIndexWithinBlock, afterLog.logIndexWithinTx));
|
|
271
|
+
} else if (txLocation) {
|
|
272
|
+
start = encodeKey(prefix, txLocation[0], txLocation[1], 0);
|
|
273
|
+
} else {
|
|
274
|
+
start = encodeKey(prefix, fromBlock, 0, 0);
|
|
275
|
+
}
|
|
415
276
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
277
|
+
const limit = query.limitPerTag ?? MAX_LOGS_PER_TAG;
|
|
278
|
+
const out: LogResult[] = [];
|
|
279
|
+
for await (const [rawKey, rawVal] of primaryMap.entriesAsync({ start, end, limit })) {
|
|
280
|
+
const tail = decodeKeyTail(rawKey);
|
|
281
|
+
const value = decodeValue(rawVal);
|
|
282
|
+
out.push({
|
|
283
|
+
logData: value.logData,
|
|
284
|
+
blockNumber: tail.blockNumber,
|
|
285
|
+
blockHash: value.blockHash,
|
|
286
|
+
blockTimestamp: value.blockTimestamp,
|
|
287
|
+
txHash: value.txHash,
|
|
288
|
+
txIndexWithinBlock: tail.txIndexWithinBlock,
|
|
289
|
+
logIndexWithinTx: tail.logIndexWithinTx,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
perTagResults.push(out);
|
|
421
293
|
}
|
|
422
294
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
431
|
-
|
|
432
|
-
while (reader.remainingBytes() > 0) {
|
|
433
|
-
const indexOfTx = reader.readNumber();
|
|
434
|
-
const numLogsInTx = reader.readNumber();
|
|
435
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
436
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
437
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
295
|
+
if (includeEffects) {
|
|
296
|
+
// Dedupe by txHash across the entire page so a tx with many tagged logs costs one fetch.
|
|
297
|
+
const txHashByKey = new Map<string, TxHash>();
|
|
298
|
+
for (const arr of perTagResults) {
|
|
299
|
+
for (const log of arr) {
|
|
300
|
+
txHashByKey.set(log.txHash.toString(), log.txHash);
|
|
438
301
|
}
|
|
439
302
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
303
|
+
const uniqueTxs = Array.from(txHashByKey.values());
|
|
304
|
+
if (uniqueTxs.length > 0) {
|
|
305
|
+
const effects = await this.blockStore.getNoteHashesAndNullifiers(uniqueTxs);
|
|
306
|
+
const byTxHash = new Map<string, [Fr[], Fr[]]>();
|
|
307
|
+
uniqueTxs.forEach((tx, i) => byTxHash.set(tx.toString(), effects[i]));
|
|
308
|
+
for (let i = 0; i < perTagResults.length; i++) {
|
|
309
|
+
perTagResults[i] = perTagResults[i].map(log => {
|
|
310
|
+
const [noteHashes, nullifiers] = byTxHash.get(log.txHash.toString()) ?? [[], []];
|
|
311
|
+
return { ...log, noteHashes, nullifiers };
|
|
312
|
+
});
|
|
446
313
|
}
|
|
447
314
|
}
|
|
448
315
|
}
|
|
449
316
|
|
|
450
|
-
return
|
|
317
|
+
return perTagResults;
|
|
451
318
|
}
|
|
452
319
|
|
|
453
320
|
/**
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
321
|
+
* Reads back every private log indexed for the given block via the per-block secondary index. Order
|
|
322
|
+
* matches the canonical composite-key order (`tag`, `blockNumber`, `txIndexWithinBlock`,
|
|
323
|
+
* `logIndexWithinTx`). Used by the data-store-updater test suite to verify the indexed-vs-block-body
|
|
324
|
+
* counts without depending on the removed `getPublicLogs(LogFilter)` API.
|
|
457
325
|
*/
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return this.#filterContractClassLogsOfTx(filter);
|
|
463
|
-
} else {
|
|
464
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
465
|
-
}
|
|
326
|
+
getPrivateLogsForBlock(blockNumber: number): Promise<LogResult[]> {
|
|
327
|
+
return this.db.transactionAsync(() =>
|
|
328
|
+
this.#readBlockLogs(this.#privateKeysByBlock, this.#privateLogs, blockNumber),
|
|
329
|
+
);
|
|
466
330
|
}
|
|
467
331
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const [blockNumber, txIndex] = (await this.blockStore.getTxLocation(filter.txHash)) ?? [];
|
|
474
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
475
|
-
return { logs: [], maxLogsHit: false };
|
|
476
|
-
}
|
|
477
|
-
const contractClassLogsBuffer = (await this.#contractClassLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
478
|
-
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
479
|
-
|
|
480
|
-
const reader = new BufferReader(contractClassLogsBuffer);
|
|
481
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
482
|
-
|
|
483
|
-
while (reader.remainingBytes() > 0) {
|
|
484
|
-
const indexOfTx = reader.readNumber();
|
|
485
|
-
const numLogsInTx = reader.readNumber();
|
|
486
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
487
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
488
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
493
|
-
|
|
494
|
-
const logs: ExtendedContractClassLog[] = [];
|
|
495
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
496
|
-
|
|
497
|
-
return { logs, maxLogsHit };
|
|
332
|
+
/** {@inheritDoc LogStore.getPrivateLogsForBlock} */
|
|
333
|
+
getPublicLogsForBlock(blockNumber: number): Promise<LogResult[]> {
|
|
334
|
+
return this.db.transactionAsync(() => this.#readBlockLogs(this.#publicKeysByBlock, this.#publicLogs, blockNumber));
|
|
498
335
|
}
|
|
499
336
|
|
|
500
|
-
async #
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
maxLogsHit: true,
|
|
509
|
-
};
|
|
337
|
+
async #readBlockLogs(
|
|
338
|
+
keysByBlock: AztecAsyncMap<number, string[]>,
|
|
339
|
+
primaryMap: AztecAsyncMap<string, Buffer>,
|
|
340
|
+
blockNumber: number,
|
|
341
|
+
): Promise<LogResult[]> {
|
|
342
|
+
const keys = await keysByBlock.getAsync(blockNumber);
|
|
343
|
+
if (!keys || keys.length === 0) {
|
|
344
|
+
return [];
|
|
510
345
|
}
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
start,
|
|
517
|
-
end,
|
|
518
|
-
})) {
|
|
519
|
-
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
520
|
-
const reader = new BufferReader(logBuffer);
|
|
521
|
-
const blockHash = this.#unpackBlockHash(reader);
|
|
522
|
-
while (reader.remainingBytes() > 0) {
|
|
523
|
-
const indexOfTx = reader.readNumber();
|
|
524
|
-
const numLogsInTx = reader.readNumber();
|
|
525
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
526
|
-
for (let i = 0; i < numLogsInTx; i++) {
|
|
527
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
|
|
531
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
532
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
533
|
-
if (maxLogsHit) {
|
|
534
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
535
|
-
break loopOverBlocks;
|
|
536
|
-
}
|
|
346
|
+
const results: LogResult[] = [];
|
|
347
|
+
for (const key of keys) {
|
|
348
|
+
const raw = await primaryMap.getAsync(key);
|
|
349
|
+
if (!raw) {
|
|
350
|
+
continue;
|
|
537
351
|
}
|
|
352
|
+
const tail = decodeKeyTail(key);
|
|
353
|
+
const value = decodeValue(raw);
|
|
354
|
+
results.push({
|
|
355
|
+
logData: value.logData,
|
|
356
|
+
blockNumber: tail.blockNumber,
|
|
357
|
+
blockHash: value.blockHash,
|
|
358
|
+
blockTimestamp: value.blockTimestamp,
|
|
359
|
+
txHash: value.txHash,
|
|
360
|
+
txIndexWithinBlock: tail.txIndexWithinBlock,
|
|
361
|
+
logIndexWithinTx: tail.logIndexWithinTx,
|
|
362
|
+
});
|
|
538
363
|
}
|
|
539
|
-
|
|
540
|
-
return { logs, maxLogsHit };
|
|
364
|
+
return results;
|
|
541
365
|
}
|
|
366
|
+
}
|
|
542
367
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
553
|
-
for (; logIndex < txLogs.length; logIndex++) {
|
|
554
|
-
const log = txLogs[logIndex];
|
|
555
|
-
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
556
|
-
if (log instanceof ContractClassLog) {
|
|
557
|
-
results.push(
|
|
558
|
-
new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log),
|
|
559
|
-
);
|
|
560
|
-
} else if (log instanceof PublicLog) {
|
|
561
|
-
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log));
|
|
562
|
-
} else {
|
|
563
|
-
throw new Error('Unknown log type');
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (results.length >= this.#logsMaxPageSize) {
|
|
567
|
-
maxLogsHit = true;
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
return maxLogsHit;
|
|
368
|
+
/** Pulls `{ tagHex, afterLog }` out of a {@link TagQuery}, normalizing the bare-tag form. */
|
|
369
|
+
function normalizeTagEntry<T extends Tag | SiloedTag>(
|
|
370
|
+
entry: TagQuery<T>,
|
|
371
|
+
): {
|
|
372
|
+
tagHex: string;
|
|
373
|
+
afterLog: LogCursor | undefined;
|
|
374
|
+
} {
|
|
375
|
+
if (typeof entry === 'object' && entry !== null && 'tag' in entry) {
|
|
376
|
+
return { tagHex: fieldHex(entry.tag.value), afterLog: entry.afterLog };
|
|
574
377
|
}
|
|
378
|
+
return { tagHex: fieldHex((entry as T).value), afterLog: undefined };
|
|
575
379
|
}
|