@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.023c3e5
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 +164 -9
- package/dest/archiver.d.ts +136 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +781 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +71 -0
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +13 -16
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +103 -55
- 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/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +149 -0
- package/dest/l1/calldata_retriever.d.ts +112 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +471 -0
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/l1/data_retrieval.js +312 -0
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +157 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- 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/modules/instrumentation.js +110 -0
- 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 +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/modules/validation.js +104 -0
- package/dest/store/block_store.d.ts +192 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +721 -0
- 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 +25 -27
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/store/contract_instance_store.js +77 -0
- 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 +446 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +436 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/store/message_store.js +188 -0
- package/dest/structs/data_retrieval.d.ts +27 -0
- 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/structs/inbox_message.js +39 -0
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/structs/published.js +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 +4 -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 +18 -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 +62 -16
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +263 -32
- package/dest/test/mock_structs.d.ts +85 -0
- package/dest/test/mock_structs.d.ts.map +1 -0
- package/dest/test/mock_structs.js +171 -0
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +31 -33
- package/src/archiver.ts +543 -0
- package/src/config.ts +95 -0
- package/src/errors.ts +102 -0
- package/src/factory.ts +144 -71
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +187 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/l1/data_retrieval.ts +495 -0
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +367 -0
- package/src/modules/data_store_updater.ts +423 -0
- package/src/modules/instrumentation.ts +157 -0
- package/src/modules/l1_synchronizer.ts +930 -0
- package/src/modules/validation.ts +129 -0
- package/src/store/block_store.ts +966 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +26 -32
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +37 -29
- package/src/store/kv_archiver_store.ts +639 -0
- package/src/store/log_store.ts +575 -0
- package/src/store/message_store.ts +261 -0
- package/src/structs/inbox_message.ts +41 -0
- package/src/structs/published.ts +1 -0
- package/src/test/fake_l1_state.ts +599 -0
- 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/index.ts +4 -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 +313 -42
- package/src/test/mock_structs.ts +311 -0
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -197
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -900
- package/dest/archiver/archiver_store.d.ts +0 -220
- 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 -794
- package/dest/archiver/config.d.ts +0 -37
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/config.js +0 -46
- 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/errors.d.ts +0 -4
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -5
- package/dest/archiver/index.d.ts +0 -8
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -5
- package/dest/archiver/instrumentation.d.ts +0 -29
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/instrumentation.js +0 -99
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -87
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -217
- 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 -21
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +0 -63
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -153
- 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 -254
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -364
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -33
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.js +0 -85
- 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/dest/archiver/structs/data_retrieval.d.ts +0 -27
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -11
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/structs/published.js +0 -1
- package/dest/rpc/index.d.ts +0 -10
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -18
- package/src/archiver/archiver.ts +0 -1181
- package/src/archiver/archiver_store.ts +0 -263
- package/src/archiver/archiver_store_test_suite.ts +0 -810
- package/src/archiver/config.ts +0 -92
- package/src/archiver/data_retrieval.ts +0 -422
- package/src/archiver/errors.ts +0 -5
- package/src/archiver/index.ts +0 -7
- package/src/archiver/instrumentation.ts +0 -132
- package/src/archiver/kv_archiver_store/block_store.ts +0 -283
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -358
- package/src/archiver/kv_archiver_store/log_store.ts +0 -444
- package/src/archiver/kv_archiver_store/message_store.ts +0 -102
- 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
- package/src/archiver/structs/published.ts +0 -11
- package/src/rpc/index.ts +0 -20
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
|
-
import { BlockStore } from './block_store.js';
|
|
5
|
-
import { ContractClassStore } from './contract_class_store.js';
|
|
6
|
-
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
7
|
-
import { LogStore } from './log_store.js';
|
|
8
|
-
import { MessageStore } from './message_store.js';
|
|
9
|
-
import { NullifierStore } from './nullifier_store.js';
|
|
10
|
-
/**
|
|
11
|
-
* LMDB implementation of the ArchiverDataStore interface.
|
|
12
|
-
*/ export class KVArchiverDataStore {
|
|
13
|
-
db;
|
|
14
|
-
static SCHEMA_VERSION = 1;
|
|
15
|
-
#blockStore;
|
|
16
|
-
#logStore;
|
|
17
|
-
#nullifierStore;
|
|
18
|
-
#messageStore;
|
|
19
|
-
#contractClassStore;
|
|
20
|
-
#contractInstanceStore;
|
|
21
|
-
functionNames;
|
|
22
|
-
#log;
|
|
23
|
-
constructor(db, logsMaxPageSize = 1000){
|
|
24
|
-
this.db = db;
|
|
25
|
-
this.functionNames = new Map();
|
|
26
|
-
this.#log = createLogger('archiver:data-store');
|
|
27
|
-
this.#blockStore = new BlockStore(db);
|
|
28
|
-
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
29
|
-
this.#messageStore = new MessageStore(db);
|
|
30
|
-
this.#contractClassStore = new ContractClassStore(db);
|
|
31
|
-
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
32
|
-
this.#nullifierStore = new NullifierStore(db);
|
|
33
|
-
}
|
|
34
|
-
// TODO: These function names are in memory only as they are for development/debugging. They require the full contract
|
|
35
|
-
// artifact supplied to the node out of band. This should be reviewed and potentially removed as part of
|
|
36
|
-
// the node api cleanup process.
|
|
37
|
-
getContractFunctionName(_address, selector) {
|
|
38
|
-
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
39
|
-
}
|
|
40
|
-
async registerContractFunctionSignatures(_address, signatures) {
|
|
41
|
-
for (const sig of signatures){
|
|
42
|
-
try {
|
|
43
|
-
const selector = await FunctionSelector.fromSignature(sig);
|
|
44
|
-
this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('(')));
|
|
45
|
-
} catch {
|
|
46
|
-
this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
getContractClass(id) {
|
|
51
|
-
return this.#contractClassStore.getContractClass(id);
|
|
52
|
-
}
|
|
53
|
-
getContractClassIds() {
|
|
54
|
-
return this.#contractClassStore.getContractClassIds();
|
|
55
|
-
}
|
|
56
|
-
async getContractInstance(address) {
|
|
57
|
-
const contract = this.#contractInstanceStore.getContractInstance(address, await this.getSynchedL2BlockNumber());
|
|
58
|
-
return contract;
|
|
59
|
-
}
|
|
60
|
-
async addContractClasses(data, bytecodeCommitments, blockNumber) {
|
|
61
|
-
return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
|
|
62
|
-
}
|
|
63
|
-
async deleteContractClasses(data, blockNumber) {
|
|
64
|
-
return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
|
|
65
|
-
}
|
|
66
|
-
getBytecodeCommitment(contractClassId) {
|
|
67
|
-
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
68
|
-
}
|
|
69
|
-
addFunctions(contractClassId, privateFunctions, unconstrainedFunctions) {
|
|
70
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, unconstrainedFunctions);
|
|
71
|
-
}
|
|
72
|
-
async addContractInstances(data, _blockNumber) {
|
|
73
|
-
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c)))).every(Boolean);
|
|
74
|
-
}
|
|
75
|
-
async deleteContractInstances(data, _blockNumber) {
|
|
76
|
-
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
|
|
77
|
-
}
|
|
78
|
-
async addContractInstanceUpdates(data, blockNumber) {
|
|
79
|
-
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.addContractInstanceUpdate(update, blockNumber, logIndex)))).every(Boolean);
|
|
80
|
-
}
|
|
81
|
-
async deleteContractInstanceUpdates(data, blockNumber) {
|
|
82
|
-
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, blockNumber, logIndex)))).every(Boolean);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Append new blocks to the store's list.
|
|
86
|
-
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
87
|
-
* @returns True if the operation is successful.
|
|
88
|
-
*/ addBlocks(blocks) {
|
|
89
|
-
return this.#blockStore.addBlocks(blocks);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Unwinds blocks from the database
|
|
93
|
-
* @param from - The tip of the chain, passed for verification purposes,
|
|
94
|
-
* ensuring that we don't end up deleting something we did not intend
|
|
95
|
-
* @param blocksToUnwind - The number of blocks we are to unwind
|
|
96
|
-
* @returns True if the operation is successful
|
|
97
|
-
*/ unwindBlocks(from, blocksToUnwind) {
|
|
98
|
-
return this.#blockStore.unwindBlocks(from, blocksToUnwind);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
102
|
-
*
|
|
103
|
-
* @param start - Number of the first block to return (inclusive).
|
|
104
|
-
* @param limit - The number of blocks to return.
|
|
105
|
-
* @returns The requested L2 blocks
|
|
106
|
-
*/ getBlocks(start, limit) {
|
|
107
|
-
return toArray(this.#blockStore.getBlocks(start, limit));
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Gets up to `limit` amount of L2 blocks headers starting from `from`.
|
|
111
|
-
*
|
|
112
|
-
* @param start - Number of the first block to return (inclusive).
|
|
113
|
-
* @param limit - The number of blocks to return.
|
|
114
|
-
* @returns The requested L2 blocks
|
|
115
|
-
*/ getBlockHeaders(start, limit) {
|
|
116
|
-
return toArray(this.#blockStore.getBlockHeaders(start, limit));
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Gets a tx effect.
|
|
120
|
-
* @param txHash - The txHash of the tx corresponding to the tx effect.
|
|
121
|
-
* @returns The requested tx effect (or undefined if not found).
|
|
122
|
-
*/ getTxEffect(txHash) {
|
|
123
|
-
return this.#blockStore.getTxEffect(txHash);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Gets a receipt of a settled tx.
|
|
127
|
-
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
128
|
-
* @returns The requested tx receipt (or undefined if not found).
|
|
129
|
-
*/ getSettledTxReceipt(txHash) {
|
|
130
|
-
return this.#blockStore.getSettledTxReceipt(txHash);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Append new logs to the store's list.
|
|
134
|
-
* @param blocks - The blocks for which to add the logs.
|
|
135
|
-
* @returns True if the operation is successful.
|
|
136
|
-
*/ addLogs(blocks) {
|
|
137
|
-
return this.#logStore.addLogs(blocks);
|
|
138
|
-
}
|
|
139
|
-
deleteLogs(blocks) {
|
|
140
|
-
return this.#logStore.deleteLogs(blocks);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Append new nullifiers to the store's list.
|
|
144
|
-
* @param blocks - The blocks for which to add the nullifiers.
|
|
145
|
-
* @returns True if the operation is successful.
|
|
146
|
-
*/ addNullifiers(blocks) {
|
|
147
|
-
return this.#nullifierStore.addNullifiers(blocks);
|
|
148
|
-
}
|
|
149
|
-
deleteNullifiers(blocks) {
|
|
150
|
-
return this.#nullifierStore.deleteNullifiers(blocks);
|
|
151
|
-
}
|
|
152
|
-
findNullifiersIndexesWithBlock(blockNumber, nullifiers) {
|
|
153
|
-
return this.#nullifierStore.findNullifiersIndexesWithBlock(blockNumber, nullifiers);
|
|
154
|
-
}
|
|
155
|
-
getTotalL1ToL2MessageCount() {
|
|
156
|
-
return this.#messageStore.getTotalL1ToL2MessageCount();
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Append L1 to L2 messages to the store.
|
|
160
|
-
* @param messages - The L1 to L2 messages to be added to the store and the last processed L1 block.
|
|
161
|
-
* @returns True if the operation is successful.
|
|
162
|
-
*/ addL1ToL2Messages(messages) {
|
|
163
|
-
return this.#messageStore.addL1ToL2Messages(messages);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
167
|
-
* @param l1ToL2Message - The L1 to L2 message.
|
|
168
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
169
|
-
*/ getL1ToL2MessageIndex(l1ToL2Message) {
|
|
170
|
-
return this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Gets L1 to L2 message (to be) included in a given block.
|
|
174
|
-
* @param blockNumber - L2 block number to get messages for.
|
|
175
|
-
* @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
|
|
176
|
-
*/ getL1ToL2Messages(blockNumber) {
|
|
177
|
-
return this.#messageStore.getL1ToL2Messages(blockNumber);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
|
|
181
|
-
* @param from - The block number from which to begin retrieving logs.
|
|
182
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
183
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
184
|
-
*/ getPrivateLogs(from, limit) {
|
|
185
|
-
return this.#logStore.getPrivateLogs(from, limit);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
189
|
-
* @param tags - The tags to filter the logs by.
|
|
190
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
191
|
-
* that tag.
|
|
192
|
-
*/ getLogsByTags(tags) {
|
|
193
|
-
try {
|
|
194
|
-
return this.#logStore.getLogsByTags(tags);
|
|
195
|
-
} catch (err) {
|
|
196
|
-
return Promise.reject(err);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Gets public logs based on the provided filter.
|
|
201
|
-
* @param filter - The filter to apply to the logs.
|
|
202
|
-
* @returns The requested logs.
|
|
203
|
-
*/ getPublicLogs(filter) {
|
|
204
|
-
try {
|
|
205
|
-
return this.#logStore.getPublicLogs(filter);
|
|
206
|
-
} catch (err) {
|
|
207
|
-
return Promise.reject(err);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Gets contract class logs based on the provided filter.
|
|
212
|
-
* @param filter - The filter to apply to the logs.
|
|
213
|
-
* @returns The requested logs.
|
|
214
|
-
*/ getContractClassLogs(filter) {
|
|
215
|
-
try {
|
|
216
|
-
return this.#logStore.getContractClassLogs(filter);
|
|
217
|
-
} catch (err) {
|
|
218
|
-
return Promise.reject(err);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Gets the number of the latest L2 block processed.
|
|
223
|
-
* @returns The number of the latest L2 block processed.
|
|
224
|
-
*/ getSynchedL2BlockNumber() {
|
|
225
|
-
return this.#blockStore.getSynchedL2BlockNumber();
|
|
226
|
-
}
|
|
227
|
-
getProvenL2BlockNumber() {
|
|
228
|
-
return this.#blockStore.getProvenL2BlockNumber();
|
|
229
|
-
}
|
|
230
|
-
async setProvenL2BlockNumber(blockNumber) {
|
|
231
|
-
await this.#blockStore.setProvenL2BlockNumber(blockNumber);
|
|
232
|
-
}
|
|
233
|
-
async setBlockSynchedL1BlockNumber(l1BlockNumber) {
|
|
234
|
-
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
235
|
-
}
|
|
236
|
-
async setMessageSynchedL1BlockNumber(l1BlockNumber) {
|
|
237
|
-
await this.#messageStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Gets the last L1 block number processed by the archiver
|
|
241
|
-
*/ async getSynchPoint() {
|
|
242
|
-
const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
|
|
243
|
-
this.#blockStore.getSynchedL1BlockNumber(),
|
|
244
|
-
this.#messageStore.getSynchedL1BlockNumber()
|
|
245
|
-
]);
|
|
246
|
-
return {
|
|
247
|
-
blocksSynchedTo,
|
|
248
|
-
messagesSynchedTo
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
estimateSize() {
|
|
252
|
-
return this.db.estimateSize();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
-
import type { L2Block } from '@aztec/stdlib/block';
|
|
4
|
-
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
5
|
-
import { type LogFilter, PrivateLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
|
-
import type { BlockStore } from './block_store.js';
|
|
7
|
-
/**
|
|
8
|
-
* A store for logs
|
|
9
|
-
*/
|
|
10
|
-
export declare class LogStore {
|
|
11
|
-
#private;
|
|
12
|
-
private db;
|
|
13
|
-
private blockStore;
|
|
14
|
-
constructor(db: AztecAsyncKVStore, blockStore: BlockStore, logsMaxPageSize?: number);
|
|
15
|
-
/**
|
|
16
|
-
* Append new logs to the store's list.
|
|
17
|
-
* @param blocks - The blocks for which to add the logs.
|
|
18
|
-
* @returns True if the operation is successful.
|
|
19
|
-
*/
|
|
20
|
-
addLogs(blocks: L2Block[]): Promise<boolean>;
|
|
21
|
-
deleteLogs(blocks: L2Block[]): Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `start`.
|
|
24
|
-
* @param start - The block number from which to begin retrieving logs.
|
|
25
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
26
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
27
|
-
*/
|
|
28
|
-
getPrivateLogs(start: number, limit: number): Promise<PrivateLog[]>;
|
|
29
|
-
/**
|
|
30
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
31
|
-
* @param tags - The tags to filter the logs by.
|
|
32
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
33
|
-
* that tag.
|
|
34
|
-
*/
|
|
35
|
-
getLogsByTags(tags: Fr[]): Promise<TxScopedL2Log[][]>;
|
|
36
|
-
/**
|
|
37
|
-
* Gets public logs based on the provided filter.
|
|
38
|
-
* @param filter - The filter to apply to the logs.
|
|
39
|
-
* @returns The requested logs.
|
|
40
|
-
*/
|
|
41
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse>;
|
|
42
|
-
/**
|
|
43
|
-
* Gets contract class logs based on the provided filter.
|
|
44
|
-
* @param filter - The filter to apply to the logs.
|
|
45
|
-
* @returns The requested logs.
|
|
46
|
-
*/
|
|
47
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse>;
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=log_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/log_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC3G,OAAO,EAIL,KAAK,SAAS,EAEd,UAAU,EAEV,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,qBAAa,QAAQ;;IASP,OAAO,CAAC,EAAE;IAAqB,OAAO,CAAC,UAAU;gBAAzC,EAAE,EAAE,iBAAiB,EAAU,UAAU,EAAE,UAAU,EAAE,eAAe,GAAE,MAAa;IAsFzG;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAkE5C,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA0B/C;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAWzE;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAO3D;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA+EhE;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC;CA6G/E"}
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, PUBLIC_LOG_DATA_SIZE_IN_FIELDS } from '@aztec/constants';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
4
|
-
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PrivateLog, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
5
|
-
/**
|
|
6
|
-
* A store for logs
|
|
7
|
-
*/ export class LogStore {
|
|
8
|
-
db;
|
|
9
|
-
blockStore;
|
|
10
|
-
#logsByTag;
|
|
11
|
-
#logTagsByBlock;
|
|
12
|
-
#privateLogsByBlock;
|
|
13
|
-
#publicLogsByBlock;
|
|
14
|
-
#contractClassLogsByBlock;
|
|
15
|
-
#logsMaxPageSize;
|
|
16
|
-
#log;
|
|
17
|
-
constructor(db, blockStore, logsMaxPageSize = 1000){
|
|
18
|
-
this.db = db;
|
|
19
|
-
this.blockStore = blockStore;
|
|
20
|
-
this.#log = createLogger('archiver:log_store');
|
|
21
|
-
this.#logsByTag = db.openMap('archiver_tagged_logs_by_tag');
|
|
22
|
-
this.#logTagsByBlock = db.openMap('archiver_log_tags_by_block');
|
|
23
|
-
this.#privateLogsByBlock = db.openMap('archiver_private_logs_by_block');
|
|
24
|
-
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
25
|
-
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
26
|
-
this.#logsMaxPageSize = logsMaxPageSize;
|
|
27
|
-
}
|
|
28
|
-
#extractTaggedLogsFromPrivate(block) {
|
|
29
|
-
const taggedLogs = new Map();
|
|
30
|
-
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
31
|
-
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
32
|
-
const txHash = txEffect.txHash;
|
|
33
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
34
|
-
txEffect.privateLogs.forEach((log)=>{
|
|
35
|
-
const tag = log.fields[0];
|
|
36
|
-
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
37
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, /* isFromPublic */ false, log.toBuffer()).toBuffer());
|
|
38
|
-
taggedLogs.set(tag.toString(), currentLogs);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
return taggedLogs;
|
|
42
|
-
}
|
|
43
|
-
#extractTaggedLogsFromPublic(block) {
|
|
44
|
-
const taggedLogs = new Map();
|
|
45
|
-
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
46
|
-
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
47
|
-
const txHash = txEffect.txHash;
|
|
48
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
49
|
-
txEffect.publicLogs.forEach((log)=>{
|
|
50
|
-
// Check that each log stores 2 lengths in its first field. If not, it's not a tagged log:
|
|
51
|
-
const firstFieldBuf = log.log[0].toBuffer();
|
|
52
|
-
// See macros/note/mod/ and see how finalization_log[0] is constructed, to understand this monstrosity. (It wasn't me).
|
|
53
|
-
// Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
|
|
54
|
-
if (!firstFieldBuf.subarray(0, 27).equals(Buffer.alloc(27)) || firstFieldBuf[29] !== 0) {
|
|
55
|
-
// See parseLogFromPublic - the first field of a tagged log is 5 bytes structured:
|
|
56
|
-
// [ publicLen[0], publicLen[1], 0, privateLen[0], privateLen[1]]
|
|
57
|
-
this.#log.warn(`Skipping public log with invalid first field: ${log.log[0]}`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Check that the length values line up with the log contents
|
|
61
|
-
const publicValuesLength = firstFieldBuf.subarray(-5).readUint16BE();
|
|
62
|
-
const privateValuesLength = firstFieldBuf.subarray(-5).readUint16BE(3);
|
|
63
|
-
// Add 1 for the first field holding lengths
|
|
64
|
-
const totalLogLength = 1 + publicValuesLength + privateValuesLength;
|
|
65
|
-
// Note that zeroes can be valid log values, so we can only assert that we do not go over the given length
|
|
66
|
-
if (totalLogLength > PUBLIC_LOG_DATA_SIZE_IN_FIELDS || log.log.slice(totalLogLength).find((f)=>!f.isZero())) {
|
|
67
|
-
this.#log.warn(`Skipping invalid tagged public log with first field: ${log.log[0]}`);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
// The first elt stores lengths as above => tag is in fields[1]
|
|
71
|
-
const tag = log.log[1];
|
|
72
|
-
this.#log.debug(`Found tagged public log with tag ${tag.toString()} in block ${block.number}`);
|
|
73
|
-
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
74
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, /* isFromPublic */ true, log.toBuffer()).toBuffer());
|
|
75
|
-
taggedLogs.set(tag.toString(), currentLogs);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
return taggedLogs;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Append new logs to the store's list.
|
|
82
|
-
* @param blocks - The blocks for which to add the logs.
|
|
83
|
-
* @returns True if the operation is successful.
|
|
84
|
-
*/ addLogs(blocks) {
|
|
85
|
-
const taggedLogsToAdd = blocks.flatMap((block)=>[
|
|
86
|
-
this.#extractTaggedLogsFromPrivate(block),
|
|
87
|
-
this.#extractTaggedLogsFromPublic(block)
|
|
88
|
-
]).reduce((acc, val)=>{
|
|
89
|
-
for (const [tag, logs] of val.entries()){
|
|
90
|
-
const currentLogs = acc.get(tag) ?? [];
|
|
91
|
-
acc.set(tag, currentLogs.concat(logs));
|
|
92
|
-
}
|
|
93
|
-
return acc;
|
|
94
|
-
});
|
|
95
|
-
const tagsToUpdate = Array.from(taggedLogsToAdd.keys());
|
|
96
|
-
return this.db.transactionAsync(async ()=>{
|
|
97
|
-
const currentTaggedLogs = await Promise.all(tagsToUpdate.map(async (tag)=>({
|
|
98
|
-
tag,
|
|
99
|
-
logBuffers: await this.#logsByTag.getAsync(tag)
|
|
100
|
-
})));
|
|
101
|
-
currentTaggedLogs.forEach((taggedLogBuffer)=>{
|
|
102
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
103
|
-
taggedLogsToAdd.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(taggedLogsToAdd.get(taggedLogBuffer.tag)));
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
for (const block of blocks){
|
|
107
|
-
const tagsInBlock = [];
|
|
108
|
-
for (const [tag, logs] of taggedLogsToAdd.entries()){
|
|
109
|
-
await this.#logsByTag.set(tag, logs);
|
|
110
|
-
tagsInBlock.push(tag);
|
|
111
|
-
}
|
|
112
|
-
await this.#logTagsByBlock.set(block.number, tagsInBlock);
|
|
113
|
-
const privateLogsInBlock = block.body.txEffects.map((txEffect)=>txEffect.privateLogs).flat().map((log)=>log.toBuffer());
|
|
114
|
-
await this.#privateLogsByBlock.set(block.number, Buffer.concat(privateLogsInBlock));
|
|
115
|
-
const publicLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
116
|
-
numToUInt32BE(txIndex),
|
|
117
|
-
numToUInt32BE(txEffect.publicLogs.length),
|
|
118
|
-
txEffect.publicLogs.map((log)=>log.toBuffer())
|
|
119
|
-
].flat()).flat();
|
|
120
|
-
const contractClassLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
121
|
-
numToUInt32BE(txIndex),
|
|
122
|
-
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
123
|
-
txEffect.contractClassLogs.map((log)=>log.toBuffer())
|
|
124
|
-
].flat()).flat();
|
|
125
|
-
await this.#publicLogsByBlock.set(block.number, Buffer.concat(publicLogsInBlock));
|
|
126
|
-
await this.#contractClassLogsByBlock.set(block.number, Buffer.concat(contractClassLogsInBlock));
|
|
127
|
-
}
|
|
128
|
-
return true;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
deleteLogs(blocks) {
|
|
132
|
-
return this.db.transactionAsync(async ()=>{
|
|
133
|
-
const tagsToDelete = (await Promise.all(blocks.map(async (block)=>{
|
|
134
|
-
const tags = await this.#logTagsByBlock.getAsync(block.number);
|
|
135
|
-
return tags ?? [];
|
|
136
|
-
}))).flat();
|
|
137
|
-
await Promise.all(blocks.map((block)=>Promise.all([
|
|
138
|
-
this.#privateLogsByBlock.delete(block.number),
|
|
139
|
-
this.#publicLogsByBlock.delete(block.number),
|
|
140
|
-
this.#logTagsByBlock.delete(block.number)
|
|
141
|
-
])));
|
|
142
|
-
await Promise.all(tagsToDelete.map((tag)=>this.#logsByTag.delete(tag.toString())));
|
|
143
|
-
return true;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `start`.
|
|
148
|
-
* @param start - The block number from which to begin retrieving logs.
|
|
149
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
150
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
151
|
-
*/ async getPrivateLogs(start, limit) {
|
|
152
|
-
const logs = [];
|
|
153
|
-
for await (const buffer of this.#privateLogsByBlock.valuesAsync({
|
|
154
|
-
start,
|
|
155
|
-
limit
|
|
156
|
-
})){
|
|
157
|
-
const reader = new BufferReader(buffer);
|
|
158
|
-
while(reader.remainingBytes() > 0){
|
|
159
|
-
logs.push(reader.readObject(PrivateLog));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return logs;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
166
|
-
* @param tags - The tags to filter the logs by.
|
|
167
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
168
|
-
* that tag.
|
|
169
|
-
*/ async getLogsByTags(tags) {
|
|
170
|
-
const logs = await Promise.all(tags.map((tag)=>this.#logsByTag.getAsync(tag.toString())));
|
|
171
|
-
return logs.map((noteLogBuffers)=>noteLogBuffers?.map((noteLogBuffer)=>TxScopedL2Log.fromBuffer(noteLogBuffer)) ?? []);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Gets public logs based on the provided filter.
|
|
175
|
-
* @param filter - The filter to apply to the logs.
|
|
176
|
-
* @returns The requested logs.
|
|
177
|
-
*/ getPublicLogs(filter) {
|
|
178
|
-
if (filter.afterLog) {
|
|
179
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
180
|
-
} else if (filter.txHash) {
|
|
181
|
-
return this.#filterPublicLogsOfTx(filter);
|
|
182
|
-
} else {
|
|
183
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async #filterPublicLogsOfTx(filter) {
|
|
187
|
-
if (!filter.txHash) {
|
|
188
|
-
throw new Error('Missing txHash');
|
|
189
|
-
}
|
|
190
|
-
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
191
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
192
|
-
return {
|
|
193
|
-
logs: [],
|
|
194
|
-
maxLogsHit: false
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
const buffer = await this.#publicLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
198
|
-
const publicLogsInBlock = [
|
|
199
|
-
[]
|
|
200
|
-
];
|
|
201
|
-
const reader = new BufferReader(buffer);
|
|
202
|
-
while(reader.remainingBytes() > 0){
|
|
203
|
-
const indexOfTx = reader.readNumber();
|
|
204
|
-
const numLogsInTx = reader.readNumber();
|
|
205
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
206
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
207
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
211
|
-
const logs = [];
|
|
212
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
213
|
-
return {
|
|
214
|
-
logs,
|
|
215
|
-
maxLogsHit
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
async #filterPublicLogsBetweenBlocks(filter) {
|
|
219
|
-
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
220
|
-
const end = filter.toBlock;
|
|
221
|
-
if (typeof end === 'number' && end < start) {
|
|
222
|
-
return {
|
|
223
|
-
logs: [],
|
|
224
|
-
maxLogsHit: true
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
const logs = [];
|
|
228
|
-
let maxLogsHit = false;
|
|
229
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({
|
|
230
|
-
start,
|
|
231
|
-
end
|
|
232
|
-
})){
|
|
233
|
-
const publicLogsInBlock = [
|
|
234
|
-
[]
|
|
235
|
-
];
|
|
236
|
-
const reader = new BufferReader(logBuffer);
|
|
237
|
-
while(reader.remainingBytes() > 0){
|
|
238
|
-
const indexOfTx = reader.readNumber();
|
|
239
|
-
const numLogsInTx = reader.readNumber();
|
|
240
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
241
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
242
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++){
|
|
246
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
247
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
248
|
-
if (maxLogsHit) {
|
|
249
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
250
|
-
break loopOverBlocks;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
logs,
|
|
256
|
-
maxLogsHit
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Gets contract class logs based on the provided filter.
|
|
261
|
-
* @param filter - The filter to apply to the logs.
|
|
262
|
-
* @returns The requested logs.
|
|
263
|
-
*/ getContractClassLogs(filter) {
|
|
264
|
-
if (filter.afterLog) {
|
|
265
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
266
|
-
} else if (filter.txHash) {
|
|
267
|
-
return this.#filterContractClassLogsOfTx(filter);
|
|
268
|
-
} else {
|
|
269
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async #filterContractClassLogsOfTx(filter) {
|
|
273
|
-
if (!filter.txHash) {
|
|
274
|
-
throw new Error('Missing txHash');
|
|
275
|
-
}
|
|
276
|
-
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
277
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
278
|
-
return {
|
|
279
|
-
logs: [],
|
|
280
|
-
maxLogsHit: false
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
const contractClassLogsBuffer = await this.#contractClassLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
284
|
-
const contractClassLogsInBlock = [
|
|
285
|
-
[]
|
|
286
|
-
];
|
|
287
|
-
const reader = new BufferReader(contractClassLogsBuffer);
|
|
288
|
-
while(reader.remainingBytes() > 0){
|
|
289
|
-
const indexOfTx = reader.readNumber();
|
|
290
|
-
const numLogsInTx = reader.readNumber();
|
|
291
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
292
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
293
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
297
|
-
const logs = [];
|
|
298
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
299
|
-
return {
|
|
300
|
-
logs,
|
|
301
|
-
maxLogsHit
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
async #filterContractClassLogsBetweenBlocks(filter) {
|
|
305
|
-
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
306
|
-
const end = filter.toBlock;
|
|
307
|
-
if (typeof end === 'number' && end < start) {
|
|
308
|
-
return {
|
|
309
|
-
logs: [],
|
|
310
|
-
maxLogsHit: true
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
const logs = [];
|
|
314
|
-
let maxLogsHit = false;
|
|
315
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#contractClassLogsByBlock.entriesAsync({
|
|
316
|
-
start,
|
|
317
|
-
end
|
|
318
|
-
})){
|
|
319
|
-
const contractClassLogsInBlock = [
|
|
320
|
-
[]
|
|
321
|
-
];
|
|
322
|
-
const reader = new BufferReader(logBuffer);
|
|
323
|
-
while(reader.remainingBytes() > 0){
|
|
324
|
-
const indexOfTx = reader.readNumber();
|
|
325
|
-
const numLogsInTx = reader.readNumber();
|
|
326
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
327
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
328
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++){
|
|
332
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
333
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
334
|
-
if (maxLogsHit) {
|
|
335
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
336
|
-
break loopOverBlocks;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return {
|
|
341
|
-
logs,
|
|
342
|
-
maxLogsHit
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
#accumulateLogs(results, blockNumber, txIndex, txLogs, filter) {
|
|
346
|
-
let maxLogsHit = false;
|
|
347
|
-
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
348
|
-
for(; logIndex < txLogs.length; logIndex++){
|
|
349
|
-
const log = txLogs[logIndex];
|
|
350
|
-
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
351
|
-
if (log instanceof ContractClassLog) {
|
|
352
|
-
results.push(new ExtendedContractClassLog(new LogId(blockNumber, txIndex, logIndex), log));
|
|
353
|
-
} else {
|
|
354
|
-
results.push(new ExtendedPublicLog(new LogId(blockNumber, txIndex, logIndex), log));
|
|
355
|
-
}
|
|
356
|
-
if (results.length >= this.#logsMaxPageSize) {
|
|
357
|
-
maxLogsHit = true;
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return maxLogsHit;
|
|
363
|
-
}
|
|
364
|
-
}
|