@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2
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 +147 -22
- package/dest/archiver.d.ts +135 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +769 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -5
- package/dest/errors.d.ts +36 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +54 -0
- package/dest/factory.d.ts +5 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +82 -5
- 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/{archiver → l1}/data_retrieval.js +75 -150
- 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 +29 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +150 -0
- package/dest/modules/data_source_base.d.ts +85 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +291 -0
- package/dest/modules/data_store_updater.d.ts +69 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +304 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +22 -59
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1113 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +178 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +680 -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 +2 -2
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +331 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +438 -0
- package/dest/store/log_store.d.ts +45 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +422 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +15 -14
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/inbox_message.js +6 -6
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/mock_archiver.d.ts +5 -6
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +6 -11
- package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +19 -14
- package/dest/test/mock_l2_block_source.d.ts +28 -14
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +160 -52
- package/dest/test/mock_structs.d.ts +78 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +141 -10
- package/package.json +17 -18
- package/src/archiver.ts +525 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +90 -0
- package/src/factory.ts +118 -6
- 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 +182 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/{archiver → l1}/data_retrieval.ts +136 -218
- 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 +211 -0
- package/src/modules/data_source_base.ts +414 -0
- package/src/modules/data_store_updater.ts +419 -0
- package/src/{archiver → modules}/instrumentation.ts +24 -59
- package/src/modules/l1_synchronizer.ts +931 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +919 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +2 -2
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +622 -0
- package/src/store/log_store.ts +552 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +21 -18
- package/src/{archiver/structs → structs}/inbox_message.ts +7 -8
- package/src/{archiver/structs → structs}/published.ts +0 -1
- 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 +1 -0
- package/src/test/mock_archiver.ts +8 -13
- package/src/test/mock_l1_to_l2_message_source.ts +16 -15
- package/src/test/mock_l2_block_source.ts +184 -64
- package/src/test/mock_structs.ts +256 -11
- package/dest/archiver/archiver.d.ts +0 -290
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1434
- package/dest/archiver/archiver_store.d.ts +0 -256
- 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 -1289
- package/dest/archiver/config.d.ts +0 -21
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.d.ts +0 -80
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -35
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -125
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -371
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -169
- 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 -296
- 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 -337
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -39
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1880
- package/src/archiver/archiver_store.ts +0 -310
- package/src/archiver/archiver_store_test_suite.ts +0 -1295
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -482
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
- package/src/archiver/kv_archiver_store/log_store.ts +0 -407
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -1,296 +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 { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { BlockStore } from './block_store.js';
|
|
7
|
-
import { ContractClassStore } from './contract_class_store.js';
|
|
8
|
-
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
9
|
-
import { LogStore } from './log_store.js';
|
|
10
|
-
import { MessageStore } from './message_store.js';
|
|
11
|
-
export const ARCHIVER_DB_VERSION = 3;
|
|
12
|
-
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
13
|
-
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
14
|
-
/**
|
|
15
|
-
* LMDB implementation of the ArchiverDataStore interface.
|
|
16
|
-
*/ export class KVArchiverDataStore {
|
|
17
|
-
db;
|
|
18
|
-
static SCHEMA_VERSION = ARCHIVER_DB_VERSION;
|
|
19
|
-
#blockStore;
|
|
20
|
-
#logStore;
|
|
21
|
-
#messageStore;
|
|
22
|
-
#contractClassStore;
|
|
23
|
-
#contractInstanceStore;
|
|
24
|
-
functionNames;
|
|
25
|
-
#log;
|
|
26
|
-
constructor(db, logsMaxPageSize = 1000){
|
|
27
|
-
this.db = db;
|
|
28
|
-
this.functionNames = new Map();
|
|
29
|
-
this.#log = createLogger('archiver:data-store');
|
|
30
|
-
this.#blockStore = new BlockStore(db);
|
|
31
|
-
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
32
|
-
this.#messageStore = new MessageStore(db);
|
|
33
|
-
this.#contractClassStore = new ContractClassStore(db);
|
|
34
|
-
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
35
|
-
}
|
|
36
|
-
transactionAsync(callback) {
|
|
37
|
-
return this.db.transactionAsync(callback);
|
|
38
|
-
}
|
|
39
|
-
getBlockNumber() {
|
|
40
|
-
return this.getSynchedL2BlockNumber();
|
|
41
|
-
}
|
|
42
|
-
async getContract(address, maybeTimestamp) {
|
|
43
|
-
const [header] = await this.getBlockHeaders(await this.getBlockNumber(), 1);
|
|
44
|
-
const timestamp = maybeTimestamp ?? header.globalVariables.timestamp;
|
|
45
|
-
return this.getContractInstance(address, timestamp);
|
|
46
|
-
}
|
|
47
|
-
async backupTo(path, compress = true) {
|
|
48
|
-
await this.db.backupTo(path, compress);
|
|
49
|
-
return join(path, 'data.mdb');
|
|
50
|
-
}
|
|
51
|
-
close() {
|
|
52
|
-
return this.db.close();
|
|
53
|
-
}
|
|
54
|
-
getDebugFunctionName(_address, selector) {
|
|
55
|
-
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
56
|
-
}
|
|
57
|
-
async registerContractFunctionSignatures(signatures) {
|
|
58
|
-
for (const sig of signatures){
|
|
59
|
-
if (this.functionNames.size > MAX_FUNCTION_SIGNATURES) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
const selector = await FunctionSelector.fromSignature(sig);
|
|
64
|
-
this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('(')).slice(0, MAX_FUNCTION_NAME_LEN));
|
|
65
|
-
} catch {
|
|
66
|
-
this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
getContractClass(id) {
|
|
71
|
-
return this.#contractClassStore.getContractClass(id);
|
|
72
|
-
}
|
|
73
|
-
getContractClassIds() {
|
|
74
|
-
return this.#contractClassStore.getContractClassIds();
|
|
75
|
-
}
|
|
76
|
-
getContractInstance(address, timestamp) {
|
|
77
|
-
return this.#contractInstanceStore.getContractInstance(address, timestamp);
|
|
78
|
-
}
|
|
79
|
-
getContractInstanceDeploymentBlockNumber(address) {
|
|
80
|
-
return this.#contractInstanceStore.getContractInstanceDeploymentBlockNumber(address);
|
|
81
|
-
}
|
|
82
|
-
async addContractClasses(data, bytecodeCommitments, blockNumber) {
|
|
83
|
-
return (await Promise.all(data.map((c, i)=>this.#contractClassStore.addContractClass(c, bytecodeCommitments[i], blockNumber)))).every(Boolean);
|
|
84
|
-
}
|
|
85
|
-
async deleteContractClasses(data, blockNumber) {
|
|
86
|
-
return (await Promise.all(data.map((c)=>this.#contractClassStore.deleteContractClasses(c, blockNumber)))).every(Boolean);
|
|
87
|
-
}
|
|
88
|
-
getBytecodeCommitment(contractClassId) {
|
|
89
|
-
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
90
|
-
}
|
|
91
|
-
addFunctions(contractClassId, privateFunctions, utilityFunctions) {
|
|
92
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
93
|
-
}
|
|
94
|
-
async addContractInstances(data, blockNumber) {
|
|
95
|
-
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.addContractInstance(c, blockNumber)))).every(Boolean);
|
|
96
|
-
}
|
|
97
|
-
async deleteContractInstances(data, _blockNumber) {
|
|
98
|
-
return (await Promise.all(data.map((c)=>this.#contractInstanceStore.deleteContractInstance(c)))).every(Boolean);
|
|
99
|
-
}
|
|
100
|
-
async addContractInstanceUpdates(data, timestamp) {
|
|
101
|
-
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.addContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
|
|
102
|
-
}
|
|
103
|
-
async deleteContractInstanceUpdates(data, timestamp) {
|
|
104
|
-
return (await Promise.all(data.map((update, logIndex)=>this.#contractInstanceStore.deleteContractInstanceUpdate(update, timestamp, logIndex)))).every(Boolean);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Append new blocks to the store's list.
|
|
108
|
-
* @param blocks - The L2 blocks to be added to the store and the last processed L1 block.
|
|
109
|
-
* @returns True if the operation is successful.
|
|
110
|
-
*/ addBlocks(blocks, opts = {}) {
|
|
111
|
-
return this.#blockStore.addBlocks(blocks, opts);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Unwinds blocks from the database
|
|
115
|
-
* @param from - The tip of the chain, passed for verification purposes,
|
|
116
|
-
* ensuring that we don't end up deleting something we did not intend
|
|
117
|
-
* @param blocksToUnwind - The number of blocks we are to unwind
|
|
118
|
-
* @returns True if the operation is successful
|
|
119
|
-
*/ unwindBlocks(from, blocksToUnwind) {
|
|
120
|
-
return this.#blockStore.unwindBlocks(from, blocksToUnwind);
|
|
121
|
-
}
|
|
122
|
-
getPublishedBlock(number) {
|
|
123
|
-
return this.#blockStore.getBlock(number);
|
|
124
|
-
}
|
|
125
|
-
getPublishedBlockByHash(blockHash) {
|
|
126
|
-
return this.#blockStore.getBlockByHash(L2BlockHash.fromField(blockHash));
|
|
127
|
-
}
|
|
128
|
-
getPublishedBlockByArchive(archive) {
|
|
129
|
-
return this.#blockStore.getBlockByArchive(archive);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Gets up to `limit` amount of L2 blocks starting from `from`.
|
|
133
|
-
*
|
|
134
|
-
* @param start - Number of the first block to return (inclusive).
|
|
135
|
-
* @param limit - The number of blocks to return.
|
|
136
|
-
* @returns The requested L2 blocks
|
|
137
|
-
*/ getPublishedBlocks(start, limit) {
|
|
138
|
-
return toArray(this.#blockStore.getBlocks(start, limit));
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Gets up to `limit` amount of L2 blocks headers starting from `from`.
|
|
142
|
-
*
|
|
143
|
-
* @param start - Number of the first block to return (inclusive).
|
|
144
|
-
* @param limit - The number of blocks to return.
|
|
145
|
-
* @returns The requested L2 blocks
|
|
146
|
-
*/ getBlockHeaders(start, limit) {
|
|
147
|
-
return toArray(this.#blockStore.getBlockHeaders(start, limit));
|
|
148
|
-
}
|
|
149
|
-
getBlockHeaderByHash(blockHash) {
|
|
150
|
-
return this.#blockStore.getBlockHeaderByHash(L2BlockHash.fromField(blockHash));
|
|
151
|
-
}
|
|
152
|
-
getBlockHeaderByArchive(archive) {
|
|
153
|
-
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Gets a tx effect.
|
|
157
|
-
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
158
|
-
* @returns The requested tx effect with block info (or undefined if not found).
|
|
159
|
-
*/ getTxEffect(txHash) {
|
|
160
|
-
return this.#blockStore.getTxEffect(txHash);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Gets a receipt of a settled tx.
|
|
164
|
-
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
165
|
-
* @returns The requested tx receipt (or undefined if not found).
|
|
166
|
-
*/ getSettledTxReceipt(txHash) {
|
|
167
|
-
return this.#blockStore.getSettledTxReceipt(txHash);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Append new logs to the store's list.
|
|
171
|
-
* @param blocks - The blocks for which to add the logs.
|
|
172
|
-
* @returns True if the operation is successful.
|
|
173
|
-
*/ addLogs(blocks) {
|
|
174
|
-
return this.#logStore.addLogs(blocks);
|
|
175
|
-
}
|
|
176
|
-
deleteLogs(blocks) {
|
|
177
|
-
return this.#logStore.deleteLogs(blocks);
|
|
178
|
-
}
|
|
179
|
-
getTotalL1ToL2MessageCount() {
|
|
180
|
-
return this.#messageStore.getTotalL1ToL2MessageCount();
|
|
181
|
-
}
|
|
182
|
-
getLastL1ToL2Message() {
|
|
183
|
-
return this.#messageStore.getLastMessage();
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Append L1 to L2 messages to the store.
|
|
187
|
-
* @param messages - The L1 to L2 messages to be added to the store.
|
|
188
|
-
*/ addL1ToL2Messages(messages) {
|
|
189
|
-
return this.#messageStore.addL1ToL2Messages(messages);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Gets the L1 to L2 message index in the L1 to L2 message tree.
|
|
193
|
-
* @param l1ToL2Message - The L1 to L2 message.
|
|
194
|
-
* @returns The index of the L1 to L2 message in the L1 to L2 message tree (undefined if not found).
|
|
195
|
-
*/ getL1ToL2MessageIndex(l1ToL2Message) {
|
|
196
|
-
return this.#messageStore.getL1ToL2MessageIndex(l1ToL2Message);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Gets L1 to L2 message (to be) included in a given block.
|
|
200
|
-
* @param blockNumber - L2 block number to get messages for.
|
|
201
|
-
* @returns The L1 to L2 messages/leaves of the messages subtree (throws if not found).
|
|
202
|
-
*/ getL1ToL2Messages(blockNumber) {
|
|
203
|
-
return this.#messageStore.getL1ToL2Messages(blockNumber);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
|
|
207
|
-
* @param from - The block number from which to begin retrieving logs.
|
|
208
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
209
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
210
|
-
*/ getPrivateLogs(from, limit) {
|
|
211
|
-
return this.#logStore.getPrivateLogs(from, limit);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
215
|
-
* @param tags - The tags to filter the logs by.
|
|
216
|
-
* @param logsPerTag - How many logs to return per tag. Default returns everything
|
|
217
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
218
|
-
* that tag.
|
|
219
|
-
*/ getLogsByTags(tags, logsPerTag) {
|
|
220
|
-
try {
|
|
221
|
-
return this.#logStore.getLogsByTags(tags, logsPerTag);
|
|
222
|
-
} catch (err) {
|
|
223
|
-
return Promise.reject(err);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Gets public logs based on the provided filter.
|
|
228
|
-
* @param filter - The filter to apply to the logs.
|
|
229
|
-
* @returns The requested logs.
|
|
230
|
-
*/ getPublicLogs(filter) {
|
|
231
|
-
try {
|
|
232
|
-
return this.#logStore.getPublicLogs(filter);
|
|
233
|
-
} catch (err) {
|
|
234
|
-
return Promise.reject(err);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Gets contract class logs based on the provided filter.
|
|
239
|
-
* @param filter - The filter to apply to the logs.
|
|
240
|
-
* @returns The requested logs.
|
|
241
|
-
*/ getContractClassLogs(filter) {
|
|
242
|
-
try {
|
|
243
|
-
return this.#logStore.getContractClassLogs(filter);
|
|
244
|
-
} catch (err) {
|
|
245
|
-
return Promise.reject(err);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Gets the number of the latest L2 block processed.
|
|
250
|
-
* @returns The number of the latest L2 block processed.
|
|
251
|
-
*/ getSynchedL2BlockNumber() {
|
|
252
|
-
return this.#blockStore.getSynchedL2BlockNumber();
|
|
253
|
-
}
|
|
254
|
-
getProvenL2BlockNumber() {
|
|
255
|
-
return this.#blockStore.getProvenL2BlockNumber();
|
|
256
|
-
}
|
|
257
|
-
async setProvenL2BlockNumber(blockNumber) {
|
|
258
|
-
await this.#blockStore.setProvenL2BlockNumber(blockNumber);
|
|
259
|
-
}
|
|
260
|
-
async setBlockSynchedL1BlockNumber(l1BlockNumber) {
|
|
261
|
-
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
262
|
-
}
|
|
263
|
-
async setMessageSynchedL1Block(l1Block) {
|
|
264
|
-
await this.#messageStore.setSynchedL1Block(l1Block);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Gets the last L1 block number processed by the archiver
|
|
268
|
-
*/ async getSynchPoint() {
|
|
269
|
-
const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
|
|
270
|
-
this.#blockStore.getSynchedL1BlockNumber(),
|
|
271
|
-
this.#messageStore.getSynchedL1Block()
|
|
272
|
-
]);
|
|
273
|
-
return {
|
|
274
|
-
blocksSynchedTo,
|
|
275
|
-
messagesSynchedTo
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
estimateSize() {
|
|
279
|
-
return this.db.estimateSize();
|
|
280
|
-
}
|
|
281
|
-
rollbackL1ToL2MessagesToL2Block(targetBlockNumber) {
|
|
282
|
-
return this.#messageStore.rollbackL1ToL2MessagesToL2Block(targetBlockNumber);
|
|
283
|
-
}
|
|
284
|
-
iterateL1ToL2Messages(range = {}) {
|
|
285
|
-
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
286
|
-
}
|
|
287
|
-
removeL1ToL2Messages(startIndex) {
|
|
288
|
-
return this.#messageStore.removeL1ToL2Messages(startIndex);
|
|
289
|
-
}
|
|
290
|
-
getPendingChainValidationStatus() {
|
|
291
|
-
return this.#blockStore.getPendingChainValidationStatus();
|
|
292
|
-
}
|
|
293
|
-
setPendingChainValidationStatus(status) {
|
|
294
|
-
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
@@ -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[], limitPerTag?: number): 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=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXJjaGl2ZXIva3ZfYXJjaGl2ZXJfc3RvcmUvbG9nX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBR25ELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBQ3hFLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ25ELE9BQU8sS0FBSyxFQUFFLDRCQUE0QixFQUFFLHFCQUFxQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDM0csT0FBTyxFQUlMLEtBQUssU0FBUyxFQUVkLFVBQVUsRUFFVixhQUFhLEVBQ2QsTUFBTSxvQkFBb0IsQ0FBQztBQUU1QixPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVuRDs7R0FFRztBQUNILHFCQUFhLFFBQVE7O0lBVWpCLE9BQU8sQ0FBQyxFQUFFO0lBQ1YsT0FBTyxDQUFDLFVBQVU7SUFGcEIsWUFDVSxFQUFFLEVBQUUsaUJBQWlCLEVBQ3JCLFVBQVUsRUFBRSxVQUFVLEVBQzlCLGVBQWUsR0FBRSxNQUFhLEVBUy9CO0lBZ0NEOzs7O09BSUc7SUFDSCxPQUFPLENBQUMsTUFBTSxFQUFFLE9BQU8sRUFBRSxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FnRTNDO0lBRUQsVUFBVSxDQUFDLE1BQU0sRUFBRSxPQUFPLEVBQUUsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBeUI5QztJQUVEOzs7OztPQUtHO0lBQ0csY0FBYyxDQUFDLEtBQUssRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsVUFBVSxFQUFFLENBQUMsQ0FTeEU7SUFFRDs7Ozs7T0FLRztJQUNHLGFBQWEsQ0FBQyxJQUFJLEVBQUUsRUFBRSxFQUFFLEVBQUUsV0FBVyxDQUFDLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxhQUFhLEVBQUUsRUFBRSxDQUFDLENBUWhGO0lBRUQ7Ozs7T0FJRztJQUNILGFBQWEsQ0FBQyxNQUFNLEVBQUUsU0FBUyxHQUFHLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBQyxDQVEvRDtJQXVFRDs7OztPQUlHO0lBQ0gsb0JBQW9CLENBQUMsTUFBTSxFQUFFLFNBQVMsR0FBRyxPQUFPLENBQUMsNEJBQTRCLENBQUMsQ0FRN0U7Q0FxR0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log_store.d.ts","sourceRoot":"","sources":["../../../src/archiver/kv_archiver_store/log_store.ts"],"names":[],"mappings":"AAEA,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;;IAUjB,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,UAAU;IAFpB,YACU,EAAE,EAAE,iBAAiB,EACrB,UAAU,EAAE,UAAU,EAC9B,eAAe,GAAE,MAAa,EAS/B;IAgCD;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAgE3C;IAED,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAyB9C;IAED;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CASxE;IAED;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAQhF;IAED;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAQ/D;IAuED;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAQ7E;CAqGF"}
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
|
|
2
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
5
|
-
import { ContractClassLog, ExtendedContractClassLog, ExtendedPublicLog, LogId, PrivateLog, PublicLog, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
6
|
-
/**
|
|
7
|
-
* A store for logs
|
|
8
|
-
*/ export class LogStore {
|
|
9
|
-
db;
|
|
10
|
-
blockStore;
|
|
11
|
-
#logsByTag;
|
|
12
|
-
#logTagsByBlock;
|
|
13
|
-
#privateLogsByBlock;
|
|
14
|
-
#publicLogsByBlock;
|
|
15
|
-
#contractClassLogsByBlock;
|
|
16
|
-
#logsMaxPageSize;
|
|
17
|
-
#log;
|
|
18
|
-
constructor(db, blockStore, logsMaxPageSize = 1000){
|
|
19
|
-
this.db = db;
|
|
20
|
-
this.blockStore = blockStore;
|
|
21
|
-
this.#log = createLogger('archiver:log_store');
|
|
22
|
-
this.#logsByTag = db.openMap('archiver_tagged_logs_by_tag');
|
|
23
|
-
this.#logTagsByBlock = db.openMap('archiver_log_tags_by_block');
|
|
24
|
-
this.#privateLogsByBlock = db.openMap('archiver_private_logs_by_block');
|
|
25
|
-
this.#publicLogsByBlock = db.openMap('archiver_public_logs_by_block');
|
|
26
|
-
this.#contractClassLogsByBlock = db.openMap('archiver_contract_class_logs_by_block');
|
|
27
|
-
this.#logsMaxPageSize = logsMaxPageSize;
|
|
28
|
-
}
|
|
29
|
-
#extractTaggedLogs(block) {
|
|
30
|
-
const taggedLogs = new Map();
|
|
31
|
-
const dataStartIndexForBlock = block.header.state.partial.noteHashTree.nextAvailableLeafIndex - block.body.txEffects.length * MAX_NOTE_HASHES_PER_TX;
|
|
32
|
-
block.body.txEffects.forEach((txEffect, txIndex)=>{
|
|
33
|
-
const txHash = txEffect.txHash;
|
|
34
|
-
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
35
|
-
txEffect.privateLogs.forEach((log, logIndex)=>{
|
|
36
|
-
const tag = log.fields[0];
|
|
37
|
-
this.#log.debug(`Found private log with tag ${tag.toString()} in block ${block.number}`);
|
|
38
|
-
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
39
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, logIndex, block.number, log).toBuffer());
|
|
40
|
-
taggedLogs.set(tag.toString(), currentLogs);
|
|
41
|
-
});
|
|
42
|
-
txEffect.publicLogs.forEach((log, logIndex)=>{
|
|
43
|
-
const tag = log.fields[0];
|
|
44
|
-
this.#log.debug(`Found public log with tag ${tag.toString()} in block ${block.number}`);
|
|
45
|
-
const currentLogs = taggedLogs.get(tag.toString()) ?? [];
|
|
46
|
-
currentLogs.push(new TxScopedL2Log(txHash, dataStartIndexForTx, logIndex, block.number, log).toBuffer());
|
|
47
|
-
taggedLogs.set(tag.toString(), currentLogs);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return taggedLogs;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Append new logs to the store's list.
|
|
54
|
-
* @param blocks - The blocks for which to add the logs.
|
|
55
|
-
* @returns True if the operation is successful.
|
|
56
|
-
*/ addLogs(blocks) {
|
|
57
|
-
const taggedLogsToAdd = blocks.map((block)=>this.#extractTaggedLogs(block)).reduce((acc, val)=>{
|
|
58
|
-
for (const [tag, logs] of val.entries()){
|
|
59
|
-
const currentLogs = acc.get(tag) ?? [];
|
|
60
|
-
acc.set(tag, currentLogs.concat(logs));
|
|
61
|
-
}
|
|
62
|
-
return acc;
|
|
63
|
-
}, new Map());
|
|
64
|
-
const tagsToUpdate = Array.from(taggedLogsToAdd.keys());
|
|
65
|
-
return this.db.transactionAsync(async ()=>{
|
|
66
|
-
const currentTaggedLogs = await Promise.all(tagsToUpdate.map(async (tag)=>({
|
|
67
|
-
tag,
|
|
68
|
-
logBuffers: await this.#logsByTag.getAsync(tag)
|
|
69
|
-
})));
|
|
70
|
-
currentTaggedLogs.forEach((taggedLogBuffer)=>{
|
|
71
|
-
if (taggedLogBuffer.logBuffers && taggedLogBuffer.logBuffers.length > 0) {
|
|
72
|
-
taggedLogsToAdd.set(taggedLogBuffer.tag, taggedLogBuffer.logBuffers.concat(taggedLogsToAdd.get(taggedLogBuffer.tag)));
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
for (const block of blocks){
|
|
76
|
-
const tagsInBlock = [];
|
|
77
|
-
for (const [tag, logs] of taggedLogsToAdd.entries()){
|
|
78
|
-
await this.#logsByTag.set(tag, logs);
|
|
79
|
-
tagsInBlock.push(tag);
|
|
80
|
-
}
|
|
81
|
-
await this.#logTagsByBlock.set(block.number, tagsInBlock);
|
|
82
|
-
const privateLogsInBlock = block.body.txEffects.map((txEffect)=>txEffect.privateLogs).flat().map((log)=>log.toBuffer());
|
|
83
|
-
await this.#privateLogsByBlock.set(block.number, Buffer.concat(privateLogsInBlock));
|
|
84
|
-
const publicLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
85
|
-
numToUInt32BE(txIndex),
|
|
86
|
-
numToUInt32BE(txEffect.publicLogs.length),
|
|
87
|
-
txEffect.publicLogs.map((log)=>log.toBuffer())
|
|
88
|
-
].flat()).flat();
|
|
89
|
-
const contractClassLogsInBlock = block.body.txEffects.map((txEffect, txIndex)=>[
|
|
90
|
-
numToUInt32BE(txIndex),
|
|
91
|
-
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
92
|
-
txEffect.contractClassLogs.map((log)=>log.toBuffer())
|
|
93
|
-
].flat()).flat();
|
|
94
|
-
await this.#publicLogsByBlock.set(block.number, Buffer.concat(publicLogsInBlock));
|
|
95
|
-
await this.#contractClassLogsByBlock.set(block.number, Buffer.concat(contractClassLogsInBlock));
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
deleteLogs(blocks) {
|
|
101
|
-
return this.db.transactionAsync(async ()=>{
|
|
102
|
-
const tagsToDelete = (await Promise.all(blocks.map(async (block)=>{
|
|
103
|
-
const tags = await this.#logTagsByBlock.getAsync(block.number);
|
|
104
|
-
return tags ?? [];
|
|
105
|
-
}))).flat();
|
|
106
|
-
await Promise.all(blocks.map((block)=>Promise.all([
|
|
107
|
-
this.#privateLogsByBlock.delete(block.number),
|
|
108
|
-
this.#publicLogsByBlock.delete(block.number),
|
|
109
|
-
this.#logTagsByBlock.delete(block.number),
|
|
110
|
-
this.#contractClassLogsByBlock.delete(block.number)
|
|
111
|
-
])));
|
|
112
|
-
await Promise.all(tagsToDelete.map((tag)=>this.#logsByTag.delete(tag.toString())));
|
|
113
|
-
return true;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Retrieves all private logs from up to `limit` blocks, starting from the block number `start`.
|
|
118
|
-
* @param start - The block number from which to begin retrieving logs.
|
|
119
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
120
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
121
|
-
*/ async getPrivateLogs(start, limit) {
|
|
122
|
-
const logs = [];
|
|
123
|
-
for await (const buffer of this.#privateLogsByBlock.valuesAsync({
|
|
124
|
-
start,
|
|
125
|
-
limit
|
|
126
|
-
})){
|
|
127
|
-
const reader = new BufferReader(buffer);
|
|
128
|
-
while(reader.remainingBytes() > 0){
|
|
129
|
-
logs.push(reader.readObject(PrivateLog));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return logs;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
136
|
-
* @param tags - The tags to filter the logs by.
|
|
137
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
138
|
-
* that tag.
|
|
139
|
-
*/ async getLogsByTags(tags, limitPerTag) {
|
|
140
|
-
if (limitPerTag !== undefined && limitPerTag <= 0) {
|
|
141
|
-
throw new TypeError('limitPerTag needs to be greater than 0');
|
|
142
|
-
}
|
|
143
|
-
const logs = await Promise.all(tags.map((tag)=>this.#logsByTag.getAsync(tag.toString())));
|
|
144
|
-
return logs.map((logBuffers)=>logBuffers?.slice(0, limitPerTag).map((logBuffer)=>TxScopedL2Log.fromBuffer(logBuffer)) ?? []);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Gets public logs based on the provided filter.
|
|
148
|
-
* @param filter - The filter to apply to the logs.
|
|
149
|
-
* @returns The requested logs.
|
|
150
|
-
*/ getPublicLogs(filter) {
|
|
151
|
-
if (filter.afterLog) {
|
|
152
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
153
|
-
} else if (filter.txHash) {
|
|
154
|
-
return this.#filterPublicLogsOfTx(filter);
|
|
155
|
-
} else {
|
|
156
|
-
return this.#filterPublicLogsBetweenBlocks(filter);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async #filterPublicLogsOfTx(filter) {
|
|
160
|
-
if (!filter.txHash) {
|
|
161
|
-
throw new Error('Missing txHash');
|
|
162
|
-
}
|
|
163
|
-
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
164
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
165
|
-
return {
|
|
166
|
-
logs: [],
|
|
167
|
-
maxLogsHit: false
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const buffer = await this.#publicLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
171
|
-
const publicLogsInBlock = [
|
|
172
|
-
[]
|
|
173
|
-
];
|
|
174
|
-
const reader = new BufferReader(buffer);
|
|
175
|
-
while(reader.remainingBytes() > 0){
|
|
176
|
-
const indexOfTx = reader.readNumber();
|
|
177
|
-
const numLogsInTx = reader.readNumber();
|
|
178
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
179
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
180
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
184
|
-
const logs = [];
|
|
185
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
186
|
-
return {
|
|
187
|
-
logs,
|
|
188
|
-
maxLogsHit
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
async #filterPublicLogsBetweenBlocks(filter) {
|
|
192
|
-
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
193
|
-
const end = filter.toBlock;
|
|
194
|
-
if (typeof end === 'number' && end < start) {
|
|
195
|
-
return {
|
|
196
|
-
logs: [],
|
|
197
|
-
maxLogsHit: true
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
const logs = [];
|
|
201
|
-
let maxLogsHit = false;
|
|
202
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({
|
|
203
|
-
start,
|
|
204
|
-
end
|
|
205
|
-
})){
|
|
206
|
-
const publicLogsInBlock = [
|
|
207
|
-
[]
|
|
208
|
-
];
|
|
209
|
-
const reader = new BufferReader(logBuffer);
|
|
210
|
-
while(reader.remainingBytes() > 0){
|
|
211
|
-
const indexOfTx = reader.readNumber();
|
|
212
|
-
const numLogsInTx = reader.readNumber();
|
|
213
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
214
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
215
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++){
|
|
219
|
-
const txLogs = publicLogsInBlock[txIndex];
|
|
220
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
221
|
-
if (maxLogsHit) {
|
|
222
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
223
|
-
break loopOverBlocks;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
logs,
|
|
229
|
-
maxLogsHit
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Gets contract class logs based on the provided filter.
|
|
234
|
-
* @param filter - The filter to apply to the logs.
|
|
235
|
-
* @returns The requested logs.
|
|
236
|
-
*/ getContractClassLogs(filter) {
|
|
237
|
-
if (filter.afterLog) {
|
|
238
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
239
|
-
} else if (filter.txHash) {
|
|
240
|
-
return this.#filterContractClassLogsOfTx(filter);
|
|
241
|
-
} else {
|
|
242
|
-
return this.#filterContractClassLogsBetweenBlocks(filter);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async #filterContractClassLogsOfTx(filter) {
|
|
246
|
-
if (!filter.txHash) {
|
|
247
|
-
throw new Error('Missing txHash');
|
|
248
|
-
}
|
|
249
|
-
const [blockNumber, txIndex] = await this.blockStore.getTxLocation(filter.txHash) ?? [];
|
|
250
|
-
if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
|
|
251
|
-
return {
|
|
252
|
-
logs: [],
|
|
253
|
-
maxLogsHit: false
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
const contractClassLogsBuffer = await this.#contractClassLogsByBlock.getAsync(blockNumber) ?? Buffer.alloc(0);
|
|
257
|
-
const contractClassLogsInBlock = [
|
|
258
|
-
[]
|
|
259
|
-
];
|
|
260
|
-
const reader = new BufferReader(contractClassLogsBuffer);
|
|
261
|
-
while(reader.remainingBytes() > 0){
|
|
262
|
-
const indexOfTx = reader.readNumber();
|
|
263
|
-
const numLogsInTx = reader.readNumber();
|
|
264
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
265
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
266
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
270
|
-
const logs = [];
|
|
271
|
-
const maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
272
|
-
return {
|
|
273
|
-
logs,
|
|
274
|
-
maxLogsHit
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
async #filterContractClassLogsBetweenBlocks(filter) {
|
|
278
|
-
const start = filter.afterLog?.blockNumber ?? Math.max(filter.fromBlock ?? INITIAL_L2_BLOCK_NUM, INITIAL_L2_BLOCK_NUM);
|
|
279
|
-
const end = filter.toBlock;
|
|
280
|
-
if (typeof end === 'number' && end < start) {
|
|
281
|
-
return {
|
|
282
|
-
logs: [],
|
|
283
|
-
maxLogsHit: true
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
const logs = [];
|
|
287
|
-
let maxLogsHit = false;
|
|
288
|
-
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#contractClassLogsByBlock.entriesAsync({
|
|
289
|
-
start,
|
|
290
|
-
end
|
|
291
|
-
})){
|
|
292
|
-
const contractClassLogsInBlock = [
|
|
293
|
-
[]
|
|
294
|
-
];
|
|
295
|
-
const reader = new BufferReader(logBuffer);
|
|
296
|
-
while(reader.remainingBytes() > 0){
|
|
297
|
-
const indexOfTx = reader.readNumber();
|
|
298
|
-
const numLogsInTx = reader.readNumber();
|
|
299
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
300
|
-
for(let i = 0; i < numLogsInTx; i++){
|
|
301
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
for(let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++){
|
|
305
|
-
const txLogs = contractClassLogsInBlock[txIndex];
|
|
306
|
-
maxLogsHit = this.#accumulateLogs(logs, blockNumber, txIndex, txLogs, filter);
|
|
307
|
-
if (maxLogsHit) {
|
|
308
|
-
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
309
|
-
break loopOverBlocks;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
logs,
|
|
315
|
-
maxLogsHit
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
#accumulateLogs(results, blockNumber, txIndex, txLogs, filter) {
|
|
319
|
-
let maxLogsHit = false;
|
|
320
|
-
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
321
|
-
for(; logIndex < txLogs.length; logIndex++){
|
|
322
|
-
const log = txLogs[logIndex];
|
|
323
|
-
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
324
|
-
if (log instanceof ContractClassLog) {
|
|
325
|
-
results.push(new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), txIndex, logIndex), log));
|
|
326
|
-
} else {
|
|
327
|
-
results.push(new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), txIndex, logIndex), log));
|
|
328
|
-
}
|
|
329
|
-
if (results.length >= this.#logsMaxPageSize) {
|
|
330
|
-
maxLogsHit = true;
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return maxLogsHit;
|
|
336
|
-
}
|
|
337
|
-
}
|