@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +27 -6
- package/dest/archiver/archiver.d.ts +204 -94
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +1616 -414
- package/dest/archiver/archiver_store.d.ts +178 -83
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +2373 -397
- package/dest/archiver/config.d.ts +7 -22
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +30 -14
- package/dest/archiver/errors.d.ts +33 -1
- package/dest/archiver/errors.d.ts.map +1 -1
- package/dest/archiver/errors.js +49 -0
- package/dest/archiver/index.d.ts +3 -4
- package/dest/archiver/index.d.ts.map +1 -1
- package/dest/archiver/index.js +1 -2
- package/dest/archiver/instrumentation.d.ts +14 -6
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/instrumentation.js +45 -41
- package/dest/archiver/kv_archiver_store/block_store.d.ts +98 -21
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +495 -86
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +4 -4
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +13 -19
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +12 -9
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +30 -16
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +81 -75
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +145 -83
- package/dest/archiver/kv_archiver_store/log_store.d.ts +12 -16
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +151 -114
- package/dest/archiver/kv_archiver_store/message_store.d.ts +25 -18
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/message_store.js +152 -49
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/archiver/l1/bin/retrieve-calldata.js +149 -0
- package/dest/archiver/l1/calldata_retriever.d.ts +112 -0
- package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/archiver/l1/calldata_retriever.js +471 -0
- package/dest/archiver/l1/data_retrieval.d.ts +90 -0
- package/dest/archiver/l1/data_retrieval.d.ts.map +1 -0
- package/dest/archiver/l1/data_retrieval.js +331 -0
- package/dest/archiver/l1/debug_tx.d.ts +19 -0
- package/dest/archiver/l1/debug_tx.d.ts.map +1 -0
- package/dest/archiver/l1/debug_tx.js +73 -0
- package/dest/archiver/l1/spire_proposer.d.ts +70 -0
- package/dest/archiver/l1/spire_proposer.d.ts.map +1 -0
- package/dest/archiver/l1/spire_proposer.js +157 -0
- package/dest/archiver/l1/trace_tx.d.ts +97 -0
- package/dest/archiver/l1/trace_tx.d.ts.map +1 -0
- package/dest/archiver/l1/trace_tx.js +91 -0
- package/dest/archiver/l1/types.d.ts +12 -0
- package/dest/archiver/l1/types.d.ts.map +1 -0
- package/dest/archiver/l1/types.js +3 -0
- package/dest/archiver/l1/validate_trace.d.ts +29 -0
- package/dest/archiver/l1/validate_trace.d.ts.map +1 -0
- package/dest/archiver/l1/validate_trace.js +150 -0
- package/dest/archiver/structs/data_retrieval.d.ts +1 -1
- package/dest/archiver/structs/inbox_message.d.ts +15 -0
- package/dest/archiver/structs/inbox_message.d.ts.map +1 -0
- package/dest/archiver/structs/inbox_message.js +39 -0
- package/dest/archiver/structs/published.d.ts +2 -11
- package/dest/archiver/structs/published.d.ts.map +1 -1
- package/dest/archiver/structs/published.js +1 -1
- package/dest/archiver/validation.d.ts +17 -0
- package/dest/archiver/validation.d.ts.map +1 -0
- package/dest/archiver/validation.js +98 -0
- package/dest/factory.d.ts +9 -14
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +22 -52
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/rpc/index.d.ts +2 -3
- package/dest/rpc/index.d.ts.map +1 -1
- package/dest/rpc/index.js +1 -4
- package/dest/test/index.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +19 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +9 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +30 -7
- package/dest/test/mock_l2_block_source.d.ts +56 -13
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +196 -25
- package/dest/test/mock_structs.d.ts +10 -0
- package/dest/test/mock_structs.d.ts.map +1 -0
- package/dest/test/mock_structs.js +38 -0
- package/package.json +29 -30
- package/src/archiver/archiver.ts +1596 -512
- package/src/archiver/archiver_store.ts +205 -88
- package/src/archiver/archiver_store_test_suite.ts +2386 -354
- package/src/archiver/config.ts +38 -46
- package/src/archiver/errors.ts +85 -0
- package/src/archiver/index.ts +2 -3
- package/src/archiver/instrumentation.ts +65 -45
- package/src/archiver/kv_archiver_store/block_store.ts +668 -101
- package/src/archiver/kv_archiver_store/contract_class_store.ts +14 -24
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +36 -28
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +197 -113
- package/src/archiver/kv_archiver_store/log_store.ts +204 -132
- package/src/archiver/kv_archiver_store/message_store.ts +213 -54
- package/src/archiver/l1/README.md +98 -0
- package/src/archiver/l1/bin/retrieve-calldata.ts +182 -0
- package/src/archiver/l1/calldata_retriever.ts +641 -0
- package/src/archiver/l1/data_retrieval.ts +512 -0
- package/src/archiver/l1/debug_tx.ts +99 -0
- package/src/archiver/l1/spire_proposer.ts +160 -0
- package/src/archiver/l1/trace_tx.ts +128 -0
- package/src/archiver/l1/types.ts +13 -0
- package/src/archiver/l1/validate_trace.ts +211 -0
- package/src/archiver/structs/inbox_message.ts +41 -0
- package/src/archiver/structs/published.ts +1 -11
- package/src/archiver/validation.ts +124 -0
- package/src/factory.ts +28 -69
- package/src/index.ts +1 -1
- package/src/rpc/index.ts +1 -5
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/mock_archiver.ts +22 -16
- package/src/test/mock_l1_to_l2_message_source.ts +26 -8
- package/src/test/mock_l2_block_source.ts +254 -31
- package/src/test/mock_structs.ts +50 -0
- package/dest/archiver/data_retrieval.d.ts +0 -74
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.js +0 -283
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
- package/src/archiver/data_retrieval.ts +0 -422
- package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM
|
|
2
|
-
import
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
5
6
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
|
-
import type {
|
|
7
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import { L2BlockHash, L2BlockNew } from '@aztec/stdlib/block';
|
|
7
9
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
8
10
|
import {
|
|
9
11
|
ContractClassLog,
|
|
@@ -11,8 +13,9 @@ import {
|
|
|
11
13
|
ExtendedPublicLog,
|
|
12
14
|
type LogFilter,
|
|
13
15
|
LogId,
|
|
14
|
-
PrivateLog,
|
|
15
16
|
PublicLog,
|
|
17
|
+
type SiloedTag,
|
|
18
|
+
Tag,
|
|
16
19
|
TxScopedL2Log,
|
|
17
20
|
} from '@aztec/stdlib/logs';
|
|
18
21
|
|
|
@@ -22,98 +25,123 @@ import type { BlockStore } from './block_store.js';
|
|
|
22
25
|
* A store for logs
|
|
23
26
|
*/
|
|
24
27
|
export class LogStore {
|
|
25
|
-
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
+
// `tag` --> private logs
|
|
29
|
+
#privateLogsByTag: AztecAsyncMap<string, Buffer[]>;
|
|
30
|
+
// `{contractAddress}_${tag}` --> public logs
|
|
31
|
+
#publicLogsByContractAndTag: AztecAsyncMap<string, Buffer[]>;
|
|
32
|
+
#privateLogKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
33
|
+
#publicLogKeysByBlock: AztecAsyncMap<number, string[]>;
|
|
28
34
|
#publicLogsByBlock: AztecAsyncMap<number, Buffer>;
|
|
29
35
|
#contractClassLogsByBlock: AztecAsyncMap<number, Buffer>;
|
|
30
36
|
#logsMaxPageSize: number;
|
|
31
37
|
#log = createLogger('archiver:log_store');
|
|
32
38
|
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
constructor(
|
|
40
|
+
private db: AztecAsyncKVStore,
|
|
41
|
+
private blockStore: BlockStore,
|
|
42
|
+
logsMaxPageSize: number = 1000,
|
|
43
|
+
) {
|
|
44
|
+
this.#privateLogsByTag = db.openMap('archiver_private_tagged_logs_by_tag');
|
|
45
|
+
this.#publicLogsByContractAndTag = db.openMap('archiver_public_tagged_logs_by_tag');
|
|
46
|
+
this.#privateLogKeysByBlock = db.openMap('archiver_private_log_keys_by_block');
|
|
47
|
+
this.#publicLogKeysByBlock = db.openMap('archiver_public_log_keys_by_block');
|
|
37
48
|
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
38
49
|
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
39
50
|
|
|
40
51
|
this.#logsMaxPageSize = logsMaxPageSize;
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Extracts tagged logs from a single block, grouping them into private and public maps.
|
|
56
|
+
*
|
|
57
|
+
* @param block - The L2 block to extract logs from.
|
|
58
|
+
* @returns An object containing the private and public tagged logs for the block.
|
|
59
|
+
*/
|
|
60
|
+
#extractTaggedLogsFromBlock(block: L2BlockNew) {
|
|
61
|
+
// SiloedTag (as string) -> array of log buffers.
|
|
62
|
+
const privateTaggedLogs = new Map<string, Buffer[]>();
|
|
63
|
+
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
64
|
+
const publicTaggedLogs = new Map<string, Buffer[]>();
|
|
65
|
+
|
|
66
|
+
block.body.txEffects.forEach(txEffect => {
|
|
49
67
|
const txHash = txEffect.txHash;
|
|
50
|
-
|
|
68
|
+
|
|
51
69
|
txEffect.privateLogs.forEach(log => {
|
|
70
|
+
// Private logs use SiloedTag (already siloed by kernel)
|
|
52
71
|
const tag = log.fields[0];
|
|
53
|
-
|
|
72
|
+
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
73
|
+
|
|
74
|
+
const currentLogs = privateTaggedLogs.get(tag.toString()) ?? [];
|
|
54
75
|
currentLogs.push(
|
|
55
76
|
new TxScopedL2Log(
|
|
56
77
|
txHash,
|
|
57
|
-
dataStartIndexForTx,
|
|
58
78
|
block.number,
|
|
59
|
-
|
|
60
|
-
log.
|
|
79
|
+
block.timestamp,
|
|
80
|
+
log.getEmittedFields(),
|
|
81
|
+
txEffect.noteHashes,
|
|
82
|
+
txEffect.nullifiers[0],
|
|
61
83
|
).toBuffer(),
|
|
62
84
|
);
|
|
63
|
-
|
|
85
|
+
privateTaggedLogs.set(tag.toString(), currentLogs);
|
|
64
86
|
});
|
|
65
|
-
});
|
|
66
|
-
return taggedLogs;
|
|
67
|
-
}
|
|
68
87
|
|
|
69
|
-
#extractTaggedLogsFromPublic(block: L2Block) {
|
|
70
|
-
const taggedLogs = new Map<string, Buffer[]>();
|
|
71
|
-
const dataStartIndexForBlock =
|
|
72
|
-
block.header.state.partial.noteHashTree.nextAvailableLeafIndex -
|
|
73
|
-
block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
74
|
-
block.body.txEffects.forEach((txEffect, txIndex) => {
|
|
75
|
-
const txHash = txEffect.txHash;
|
|
76
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
77
88
|
txEffect.publicLogs.forEach(log => {
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.#log.warn(`Skipping public log with invalid first field: ${log.log[0]}`);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
// Check that the length values line up with the log contents
|
|
89
|
-
const publicValuesLength = firstFieldBuf.subarray(-5).readUint16BE();
|
|
90
|
-
const privateValuesLength = firstFieldBuf.subarray(-5).readUint16BE(3);
|
|
91
|
-
// Add 1 for the first field holding lengths
|
|
92
|
-
const totalLogLength = 1 + publicValuesLength + privateValuesLength;
|
|
93
|
-
// Note that zeroes can be valid log values, so we can only assert that we do not go over the given length
|
|
94
|
-
if (totalLogLength > PUBLIC_LOG_DATA_SIZE_IN_FIELDS || log.log.slice(totalLogLength).find(f => !f.isZero())) {
|
|
95
|
-
this.#log.warn(`Skipping invalid tagged public log with first field: ${log.log[0]}`);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// The first elt stores lengths as above => tag is in fields[1]
|
|
100
|
-
const tag = log.log[1];
|
|
89
|
+
// Public logs use Tag directly (not siloed) and are stored with contract address
|
|
90
|
+
const tag = log.fields[0];
|
|
91
|
+
const contractAddress = log.contractAddress;
|
|
92
|
+
const key = `${contractAddress.toString()}_${tag.toString()}`;
|
|
93
|
+
this.#log.debug(
|
|
94
|
+
`Found public log with tag ${tag.toString()} from contract ${contractAddress.toString()} in block ${block.number}`,
|
|
95
|
+
);
|
|
101
96
|
|
|
102
|
-
|
|
103
|
-
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
97
|
+
const currentLogs = publicTaggedLogs.get(key) ?? [];
|
|
104
98
|
currentLogs.push(
|
|
105
99
|
new TxScopedL2Log(
|
|
106
100
|
txHash,
|
|
107
|
-
dataStartIndexForTx,
|
|
108
101
|
block.number,
|
|
109
|
-
|
|
110
|
-
log.
|
|
102
|
+
block.timestamp,
|
|
103
|
+
log.getEmittedFields(),
|
|
104
|
+
txEffect.noteHashes,
|
|
105
|
+
txEffect.nullifiers[0],
|
|
111
106
|
).toBuffer(),
|
|
112
107
|
);
|
|
113
|
-
|
|
108
|
+
publicTaggedLogs.set(key, currentLogs);
|
|
114
109
|
});
|
|
115
110
|
});
|
|
116
|
-
|
|
111
|
+
|
|
112
|
+
return { privateTaggedLogs, publicTaggedLogs };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Extracts and aggregates tagged logs from a list of blocks.
|
|
117
|
+
* @param blocks - The blocks to extract logs from.
|
|
118
|
+
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
119
|
+
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
120
|
+
*/
|
|
121
|
+
#extractTaggedLogs(blocks: L2BlockNew[]): {
|
|
122
|
+
privateTaggedLogs: Map<string, Buffer[]>;
|
|
123
|
+
publicTaggedLogs: Map<string, Buffer[]>;
|
|
124
|
+
} {
|
|
125
|
+
const taggedLogsInBlocks = blocks.map(block => this.#extractTaggedLogsFromBlock(block));
|
|
126
|
+
|
|
127
|
+
// Now we merge the maps from each block into a single map.
|
|
128
|
+
const privateTaggedLogs = taggedLogsInBlocks.reduce((acc, { privateTaggedLogs }) => {
|
|
129
|
+
for (const [tag, logs] of privateTaggedLogs.entries()) {
|
|
130
|
+
const currentLogs = acc.get(tag) ?? [];
|
|
131
|
+
acc.set(tag, currentLogs.concat(logs));
|
|
132
|
+
}
|
|
133
|
+
return acc;
|
|
134
|
+
}, new Map<string, Buffer[]>());
|
|
135
|
+
|
|
136
|
+
const publicTaggedLogs = taggedLogsInBlocks.reduce((acc, { publicTaggedLogs }) => {
|
|
137
|
+
for (const [key, logs] of publicTaggedLogs.entries()) {
|
|
138
|
+
const currentLogs = acc.get(key) ?? [];
|
|
139
|
+
acc.set(key, currentLogs.concat(logs));
|
|
140
|
+
}
|
|
141
|
+
return acc;
|
|
142
|
+
}, new Map<string, Buffer[]>());
|
|
143
|
+
|
|
144
|
+
return { privateTaggedLogs, publicTaggedLogs };
|
|
117
145
|
}
|
|
118
146
|
|
|
119
147
|
/**
|
|
@@ -121,43 +149,59 @@ export class LogStore {
|
|
|
121
149
|
* @param blocks - The blocks for which to add the logs.
|
|
122
150
|
* @returns True if the operation is successful.
|
|
123
151
|
*/
|
|
124
|
-
addLogs(blocks:
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const currentLogs = acc.get(tag) ?? [];
|
|
130
|
-
acc.set(tag, currentLogs.concat(logs));
|
|
131
|
-
}
|
|
132
|
-
return acc;
|
|
133
|
-
});
|
|
134
|
-
const tagsToUpdate = Array.from(taggedLogsToAdd.keys());
|
|
152
|
+
addLogs(blocks: L2BlockNew[]): Promise<boolean> {
|
|
153
|
+
const { privateTaggedLogs, publicTaggedLogs } = this.#extractTaggedLogs(blocks);
|
|
154
|
+
|
|
155
|
+
const keysOfPrivateLogsToUpdate = Array.from(privateTaggedLogs.keys());
|
|
156
|
+
const keysOfPublicLogsToUpdate = Array.from(publicTaggedLogs.keys());
|
|
135
157
|
|
|
136
158
|
return this.db.transactionAsync(async () => {
|
|
137
|
-
const
|
|
138
|
-
|
|
159
|
+
const currentPrivateTaggedLogs = await Promise.all(
|
|
160
|
+
keysOfPrivateLogsToUpdate.map(async key => ({
|
|
161
|
+
tag: key,
|
|
162
|
+
logBuffers: await this.#privateLogsByTag.getAsync(key),
|
|
163
|
+
})),
|
|
139
164
|
);
|
|
140
|
-
|
|
165
|
+
currentPrivateTaggedLogs.forEach(taggedLogBuffer => {
|
|
141
166
|
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
142
|
-
|
|
167
|
+
privateTaggedLogs.set(
|
|
143
168
|
taggedLogBuffer.tag,
|
|
144
|
-
taggedLogBuffer.logBuffers!.concat(
|
|
169
|
+
taggedLogBuffer.logBuffers!.concat(privateTaggedLogs.get(taggedLogBuffer.tag)!),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const currentPublicTaggedLogs = await Promise.all(
|
|
175
|
+
keysOfPublicLogsToUpdate.map(async key => ({
|
|
176
|
+
key,
|
|
177
|
+
logBuffers: await this.#publicLogsByContractAndTag.getAsync(key),
|
|
178
|
+
})),
|
|
179
|
+
);
|
|
180
|
+
currentPublicTaggedLogs.forEach(taggedLogBuffer => {
|
|
181
|
+
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
182
|
+
publicTaggedLogs.set(
|
|
183
|
+
taggedLogBuffer.key,
|
|
184
|
+
taggedLogBuffer.logBuffers!.concat(publicTaggedLogs.get(taggedLogBuffer.key)!),
|
|
145
185
|
);
|
|
146
186
|
}
|
|
147
187
|
});
|
|
188
|
+
|
|
148
189
|
for (const block of blocks) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
190
|
+
const blockHash = await block.hash();
|
|
191
|
+
|
|
192
|
+
const privateTagsInBlock: string[] = [];
|
|
193
|
+
for (const [tag, logs] of privateTaggedLogs.entries()) {
|
|
194
|
+
await this.#privateLogsByTag.set(tag, logs);
|
|
195
|
+
privateTagsInBlock.push(tag);
|
|
153
196
|
}
|
|
154
|
-
await this.#
|
|
197
|
+
await this.#privateLogKeysByBlock.set(block.number, privateTagsInBlock);
|
|
155
198
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
.
|
|
159
|
-
.
|
|
160
|
-
|
|
199
|
+
const publicKeysInBlock: string[] = [];
|
|
200
|
+
for (const [key, logs] of publicTaggedLogs.entries()) {
|
|
201
|
+
await this.#publicLogsByContractAndTag.set(key, logs);
|
|
202
|
+
publicKeysInBlock.push(key);
|
|
203
|
+
}
|
|
204
|
+
await this.#publicLogKeysByBlock.set(block.number, publicKeysInBlock);
|
|
161
205
|
|
|
162
206
|
const publicLogsInBlock = block.body.txEffects
|
|
163
207
|
.map((txEffect, txIndex) =>
|
|
@@ -179,68 +223,82 @@ export class LogStore {
|
|
|
179
223
|
)
|
|
180
224
|
.flat();
|
|
181
225
|
|
|
182
|
-
await this.#publicLogsByBlock.set(block.number,
|
|
183
|
-
await this.#contractClassLogsByBlock.set(
|
|
226
|
+
await this.#publicLogsByBlock.set(block.number, this.#packWithBlockHash(blockHash, publicLogsInBlock));
|
|
227
|
+
await this.#contractClassLogsByBlock.set(
|
|
228
|
+
block.number,
|
|
229
|
+
this.#packWithBlockHash(blockHash, contractClassLogsInBlock),
|
|
230
|
+
);
|
|
184
231
|
}
|
|
185
232
|
|
|
186
233
|
return true;
|
|
187
234
|
});
|
|
188
235
|
}
|
|
189
236
|
|
|
190
|
-
|
|
237
|
+
#packWithBlockHash(blockHash: Fr, data: Buffer<ArrayBufferLike>[]): Buffer<ArrayBufferLike> {
|
|
238
|
+
return Buffer.concat([blockHash.toBuffer(), ...data]);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#unpackBlockHash(reader: BufferReader): L2BlockHash {
|
|
242
|
+
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
243
|
+
|
|
244
|
+
if (!blockHash) {
|
|
245
|
+
throw new Error('Failed to read block hash from log entry buffer');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return L2BlockHash.fromField(blockHash);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
deleteLogs(blocks: L2BlockNew[]): Promise<boolean> {
|
|
191
252
|
return this.db.transactionAsync(async () => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
253
|
+
await Promise.all(
|
|
254
|
+
blocks.map(async block => {
|
|
255
|
+
// Delete private logs
|
|
256
|
+
const privateKeys = (await this.#privateLogKeysByBlock.getAsync(block.number)) ?? [];
|
|
257
|
+
await Promise.all(privateKeys.map(tag => this.#privateLogsByTag.delete(tag)));
|
|
258
|
+
|
|
259
|
+
// Delete public logs
|
|
260
|
+
const publicKeys = (await this.#publicLogKeysByBlock.getAsync(block.number)) ?? [];
|
|
261
|
+
await Promise.all(publicKeys.map(key => this.#publicLogsByContractAndTag.delete(key)));
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
200
264
|
|
|
201
265
|
await Promise.all(
|
|
202
266
|
blocks.map(block =>
|
|
203
267
|
Promise.all([
|
|
204
|
-
this.#privateLogsByBlock.delete(block.number),
|
|
205
268
|
this.#publicLogsByBlock.delete(block.number),
|
|
206
|
-
this.#
|
|
269
|
+
this.#privateLogKeysByBlock.delete(block.number),
|
|
270
|
+
this.#publicLogKeysByBlock.delete(block.number),
|
|
271
|
+
this.#contractClassLogsByBlock.delete(block.number),
|
|
207
272
|
]),
|
|
208
273
|
),
|
|
209
274
|
);
|
|
210
275
|
|
|
211
|
-
await Promise.all(tagsToDelete.map(tag => this.#logsByTag.delete(tag.toString())));
|
|
212
276
|
return true;
|
|
213
277
|
});
|
|
214
278
|
}
|
|
215
279
|
|
|
216
280
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
220
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
281
|
+
* Gets all private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
282
|
+
* array implies no logs match that tag.
|
|
221
283
|
*/
|
|
222
|
-
async
|
|
223
|
-
const logs =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
while (reader.remainingBytes() > 0) {
|
|
227
|
-
logs.push(reader.readObject(PrivateLog));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return logs;
|
|
284
|
+
async getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
|
|
285
|
+
const logs = await Promise.all(tags.map(tag => this.#privateLogsByTag.getAsync(tag.toString())));
|
|
286
|
+
|
|
287
|
+
return logs.map(logBuffers => logBuffers?.map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
231
288
|
}
|
|
232
289
|
|
|
233
290
|
/**
|
|
234
|
-
* Gets all logs that match any of the
|
|
235
|
-
*
|
|
236
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
237
|
-
* that tag.
|
|
291
|
+
* Gets all public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
292
|
+
* logs is returned. An empty array implies no logs match that tag.
|
|
238
293
|
*/
|
|
239
|
-
async
|
|
240
|
-
const logs = await Promise.all(
|
|
241
|
-
|
|
242
|
-
|
|
294
|
+
async getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
|
|
295
|
+
const logs = await Promise.all(
|
|
296
|
+
tags.map(tag => {
|
|
297
|
+
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
298
|
+
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
299
|
+
}),
|
|
243
300
|
);
|
|
301
|
+
return logs.map(logBuffers => logBuffers?.map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
244
302
|
}
|
|
245
303
|
|
|
246
304
|
/**
|
|
@@ -271,6 +329,9 @@ export class LogStore {
|
|
|
271
329
|
const buffer = (await this.#publicLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
272
330
|
const publicLogsInBlock: [PublicLog[]] = [[]];
|
|
273
331
|
const reader = new BufferReader(buffer);
|
|
332
|
+
|
|
333
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
334
|
+
|
|
274
335
|
while (reader.remainingBytes() > 0) {
|
|
275
336
|
const indexOfTx = reader.readNumber();
|
|
276
337
|
const numLogsInTx = reader.readNumber();
|
|
@@ -283,7 +344,7 @@ export class LogStore {
|
|
|
283
344
|
const txLogs = publicLogsInBlock[txIndex];
|
|
284
345
|
|
|
285
346
|
const logs: ExtendedPublicLog[] = [];
|
|
286
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
347
|
+
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
287
348
|
|
|
288
349
|
return { logs, maxLogsHit };
|
|
289
350
|
}
|
|
@@ -306,6 +367,9 @@ export class LogStore {
|
|
|
306
367
|
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({ start, end })) {
|
|
307
368
|
const publicLogsInBlock: [PublicLog[]] = [[]];
|
|
308
369
|
const reader = new BufferReader(logBuffer);
|
|
370
|
+
|
|
371
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
372
|
+
|
|
309
373
|
while (reader.remainingBytes() > 0) {
|
|
310
374
|
const indexOfTx = reader.readNumber();
|
|
311
375
|
const numLogsInTx = reader.readNumber();
|
|
@@ -316,7 +380,7 @@ export class LogStore {
|
|
|
316
380
|
}
|
|
317
381
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++) {
|
|
318
382
|
const txLogs = publicLogsInBlock[txIndex];
|
|
319
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
383
|
+
maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
320
384
|
if (maxLogsHit) {
|
|
321
385
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
322
386
|
break loopOverBlocks;
|
|
@@ -355,6 +419,8 @@ export class LogStore {
|
|
|
355
419
|
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
356
420
|
|
|
357
421
|
const reader = new BufferReader(contractClassLogsBuffer);
|
|
422
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
423
|
+
|
|
358
424
|
while (reader.remainingBytes() > 0) {
|
|
359
425
|
const indexOfTx = reader.readNumber();
|
|
360
426
|
const numLogsInTx = reader.readNumber();
|
|
@@ -367,7 +433,7 @@ export class LogStore {
|
|
|
367
433
|
const txLogs = contractClassLogsInBlock[txIndex];
|
|
368
434
|
|
|
369
435
|
const logs: ExtendedContractClassLog[] = [];
|
|
370
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
436
|
+
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
371
437
|
|
|
372
438
|
return { logs, maxLogsHit };
|
|
373
439
|
}
|
|
@@ -393,6 +459,7 @@ export class LogStore {
|
|
|
393
459
|
})) {
|
|
394
460
|
const contractClassLogsInBlock: [ContractClassLog[]] = [[]];
|
|
395
461
|
const reader = new BufferReader(logBuffer);
|
|
462
|
+
const blockHash = this.#unpackBlockHash(reader);
|
|
396
463
|
while (reader.remainingBytes() > 0) {
|
|
397
464
|
const indexOfTx = reader.readNumber();
|
|
398
465
|
const numLogsInTx = reader.readNumber();
|
|
@@ -403,7 +470,7 @@ export class LogStore {
|
|
|
403
470
|
}
|
|
404
471
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
|
|
405
472
|
const txLogs = contractClassLogsInBlock[txIndex];
|
|
406
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
473
|
+
maxLogsHit = this.#accumulateLogs(logs, blockNumber, blockHash, txIndex, txLogs, filter);
|
|
407
474
|
if (maxLogsHit) {
|
|
408
475
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
409
476
|
break loopOverBlocks;
|
|
@@ -417,9 +484,10 @@ export class LogStore {
|
|
|
417
484
|
#accumulateLogs(
|
|
418
485
|
results: (ExtendedContractClassLog | ExtendedPublicLog)[],
|
|
419
486
|
blockNumber: number,
|
|
487
|
+
blockHash: L2BlockHash,
|
|
420
488
|
txIndex: number,
|
|
421
489
|
txLogs: (ContractClassLog | PublicLog)[],
|
|
422
|
-
filter: LogFilter,
|
|
490
|
+
filter: LogFilter = {},
|
|
423
491
|
): boolean {
|
|
424
492
|
let maxLogsHit = false;
|
|
425
493
|
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
@@ -427,9 +495,13 @@ export class LogStore {
|
|
|
427
495
|
const log = txLogs[logIndex];
|
|
428
496
|
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
429
497
|
if (log instanceof ContractClassLog) {
|
|
430
|
-
results.push(
|
|
498
|
+
results.push(
|
|
499
|
+
new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log),
|
|
500
|
+
);
|
|
501
|
+
} else if (log instanceof PublicLog) {
|
|
502
|
+
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txIndex, logIndex), log));
|
|
431
503
|
} else {
|
|
432
|
-
|
|
504
|
+
throw new Error('Unknown log type');
|
|
433
505
|
}
|
|
434
506
|
|
|
435
507
|
if (results.length >= this.#logsMaxPageSize) {
|