@aztec/pxe 0.0.1-commit.8afd444 → 0.0.1-commit.934299a21
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/dest/access_scopes.d.ts +9 -0
- package/dest/access_scopes.d.ts.map +1 -0
- package/dest/access_scopes.js +6 -0
- package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +7 -1
- package/dest/config/package_info.js +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +54 -28
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +174 -68
- package/dest/contract_function_simulator/noir-structs/event_validation_request.js +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts +2 -2
- package/dest/contract_function_simulator/noir-structs/note_validation_request.d.ts.map +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +2 -2
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +3 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +36 -35
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +64 -19
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +32 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +57 -31
- package/dest/contract_logging.d.ts +22 -0
- package/dest/contract_logging.d.ts.map +1 -0
- package/dest/contract_logging.js +23 -0
- package/dest/contract_sync/contract_sync_service.d.ts +43 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +97 -0
- package/dest/contract_sync/helpers.d.ts +29 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/{index.js → helpers.js} +8 -14
- package/dest/debug/pxe_debug_utils.d.ts +14 -10
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +16 -15
- package/dest/entrypoints/client/bundle/index.d.ts +4 -1
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/index.js +3 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +9 -1
- package/dest/entrypoints/client/lazy/index.d.ts +4 -1
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/index.js +3 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +9 -1
- package/dest/entrypoints/server/index.d.ts +4 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +3 -1
- package/dest/entrypoints/server/utils.js +9 -1
- package/dest/logs/log_service.d.ts +3 -2
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +5 -10
- package/dest/notes/note_service.d.ts +4 -3
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +3 -2
- package/dest/notes_filter.d.ts +25 -0
- package/dest/notes_filter.d.ts.map +1 -0
- package/dest/notes_filter.js +4 -0
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts +4 -0
- package/dest/private_kernel/hints/compute_tx_expiration_timestamp.d.ts.map +1 -0
- package/dest/private_kernel/hints/{compute_tx_include_by_timestamp.js → compute_tx_expiration_timestamp.js} +12 -12
- package/dest/private_kernel/hints/index.d.ts +1 -1
- package/dest/private_kernel/hints/index.js +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts +4 -3
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.d.ts.map +1 -1
- package/dest/private_kernel/hints/private_kernel_reset_private_inputs_builder.js +129 -68
- package/dest/private_kernel/hints/test_utils.d.ts +122 -0
- package/dest/private_kernel/hints/test_utils.d.ts.map +1 -0
- package/dest/private_kernel/hints/test_utils.js +203 -0
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +19 -11
- package/dest/private_kernel/private_kernel_oracle.d.ts +6 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_oracle.js +7 -3
- package/dest/pxe.d.ts +69 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +92 -60
- package/dest/storage/contract_store/contract_store.d.ts +42 -15
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +145 -69
- package/dest/storage/note_store/note_store.d.ts +3 -3
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +6 -4
- package/dest/tagging/get_all_logs_by_tags.d.ts +1 -1
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
- package/dest/tagging/get_all_logs_by_tags.js +17 -3
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +4 -4
- package/dest/tagging/recipient_sync/utils/find_highest_indexes.js +2 -2
- package/package.json +25 -16
- package/src/access_scopes.ts +9 -0
- package/src/block_synchronizer/block_synchronizer.ts +6 -0
- package/src/config/package_info.ts +1 -1
- package/src/contract_function_simulator/contract_function_simulator.ts +323 -128
- package/src/contract_function_simulator/noir-structs/event_validation_request.ts +1 -1
- package/src/contract_function_simulator/noir-structs/note_validation_request.ts +1 -1
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +3 -3
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +85 -96
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +102 -29
- package/src/contract_logging.ts +39 -0
- package/src/contract_sync/contract_sync_service.ts +152 -0
- package/src/contract_sync/{index.ts → helpers.ts} +13 -34
- package/src/debug/pxe_debug_utils.ts +48 -18
- package/src/entrypoints/client/bundle/index.ts +3 -0
- package/src/entrypoints/client/bundle/utils.ts +9 -1
- package/src/entrypoints/client/lazy/index.ts +3 -0
- package/src/entrypoints/client/lazy/utils.ts +9 -1
- package/src/entrypoints/server/index.ts +3 -1
- package/src/entrypoints/server/utils.ts +7 -7
- package/src/logs/log_service.ts +7 -19
- package/src/notes/note_service.ts +4 -3
- package/src/notes_filter.ts +26 -0
- package/src/oracle_version.ts +2 -2
- package/src/private_kernel/hints/{compute_tx_include_by_timestamp.ts → compute_tx_expiration_timestamp.ts} +13 -13
- package/src/private_kernel/hints/index.ts +1 -1
- package/src/private_kernel/hints/private_kernel_reset_private_inputs_builder.ts +164 -117
- package/src/private_kernel/hints/test_utils.ts +325 -0
- package/src/private_kernel/private_kernel_execution_prover.ts +19 -12
- package/src/private_kernel/private_kernel_oracle.ts +7 -7
- package/src/pxe.ts +173 -112
- package/src/storage/contract_store/contract_store.ts +174 -75
- package/src/storage/note_store/note_store.ts +12 -5
- package/src/tagging/get_all_logs_by_tags.ts +28 -4
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -4
- package/src/tagging/recipient_sync/utils/find_highest_indexes.ts +2 -2
- package/dest/contract_sync/index.d.ts +0 -24
- package/dest/contract_sync/index.d.ts.map +0 -1
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts +0 -4
- package/dest/private_kernel/hints/compute_tx_include_by_timestamp.d.ts.map +0 -1
|
@@ -1,8 +1,53 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
-
import {
|
|
3
|
+
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import { FunctionCall, FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, encodeArguments, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
3
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
6
|
import { SerializableContractInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
5
7
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
8
|
+
const VERSION = 1;
|
|
9
|
+
/**
|
|
10
|
+
* All contract class data except the large packedBytecode.
|
|
11
|
+
* The expensive data from the ContractClass is precomputed and stored in this format to avoid redundant hashing.
|
|
12
|
+
* Since we have to store the artifacts anyway, the final ContractClass is reconstructed by combining this data
|
|
13
|
+
* with the packedBytecode obtained from the former. That way we can have quick class lookups without wasted storage.
|
|
14
|
+
*/ export class SerializableContractClassData {
|
|
15
|
+
version = VERSION;
|
|
16
|
+
id;
|
|
17
|
+
artifactHash;
|
|
18
|
+
privateFunctionsRoot;
|
|
19
|
+
publicBytecodeCommitment;
|
|
20
|
+
privateFunctions;
|
|
21
|
+
constructor(data){
|
|
22
|
+
this.id = data.id;
|
|
23
|
+
this.artifactHash = data.artifactHash;
|
|
24
|
+
this.privateFunctionsRoot = data.privateFunctionsRoot;
|
|
25
|
+
this.publicBytecodeCommitment = data.publicBytecodeCommitment;
|
|
26
|
+
this.privateFunctions = data.privateFunctions;
|
|
27
|
+
}
|
|
28
|
+
toBuffer() {
|
|
29
|
+
return serializeToBuffer(numToUInt8(this.version), this.id, this.artifactHash, this.privateFunctionsRoot, this.publicBytecodeCommitment, this.privateFunctions.length, ...this.privateFunctions.map((fn)=>serializeToBuffer(fn.selector, fn.vkHash)));
|
|
30
|
+
}
|
|
31
|
+
static fromBuffer(bufferOrReader) {
|
|
32
|
+
const reader = BufferReader.asReader(bufferOrReader);
|
|
33
|
+
const version = reader.readUInt8();
|
|
34
|
+
if (version !== VERSION) {
|
|
35
|
+
throw new Error(`Unexpected contract class data version ${version}`);
|
|
36
|
+
}
|
|
37
|
+
return new SerializableContractClassData({
|
|
38
|
+
id: reader.readObject(Fr),
|
|
39
|
+
artifactHash: reader.readObject(Fr),
|
|
40
|
+
privateFunctionsRoot: reader.readObject(Fr),
|
|
41
|
+
publicBytecodeCommitment: reader.readObject(Fr),
|
|
42
|
+
privateFunctions: reader.readVector({
|
|
43
|
+
fromBuffer: (r)=>({
|
|
44
|
+
selector: r.readObject(FunctionSelector),
|
|
45
|
+
vkHash: r.readObject(Fr)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
6
51
|
/**
|
|
7
52
|
* ContractStore serves as a data manager and retriever for Aztec.nr contracts.
|
|
8
53
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -12,24 +57,46 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
12
57
|
*/ export class ContractStore {
|
|
13
58
|
/** Map from contract class id to private function tree. */ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
14
59
|
#privateFunctionTrees = new Map();
|
|
15
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* In-memory cache of deserialized ContractArtifact objects, keyed by class id string.
|
|
62
|
+
* Avoids repeated LMDB reads + JSON.parse + Zod validation on every oracle call.
|
|
63
|
+
* Artifacts are large but immutable after registration — safe to cache for the lifetime of the store.
|
|
64
|
+
*/ // TODO: Update it to be LRU cache so that it doesn't keep all the data all the time.
|
|
65
|
+
#contractArtifactCache = new Map();
|
|
66
|
+
/** Map from contract address to contract class id (avoids KV round-trip on hot path). */ #contractClassIdMap = new Map();
|
|
16
67
|
#store;
|
|
17
68
|
#contractArtifacts;
|
|
69
|
+
#contractClassData;
|
|
18
70
|
#contractInstances;
|
|
19
71
|
constructor(store){
|
|
20
72
|
this.#store = store;
|
|
21
73
|
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
74
|
+
this.#contractClassData = store.openMap('contract_classes');
|
|
22
75
|
this.#contractInstances = store.openMap('contracts_instances');
|
|
23
76
|
}
|
|
24
77
|
// Setters
|
|
25
|
-
|
|
26
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Registers a new contract artifact and its corresponding class data.
|
|
80
|
+
* IMPORTANT: This method does not verify that the provided artifact matches the class data or that the class id matches the artifact.
|
|
81
|
+
* It is the caller's responsibility to ensure the consistency and correctness of the provided data.
|
|
82
|
+
* This is done to avoid redundant, expensive contract class computations
|
|
83
|
+
*/ async addContractArtifact(contract, contractClassWithIdAndPreimage) {
|
|
84
|
+
const contractClass = contractClassWithIdAndPreimage ?? await getContractClassFromArtifact(contract);
|
|
85
|
+
const key = contractClass.id.toString();
|
|
86
|
+
if (this.#contractArtifactCache.has(key)) {
|
|
87
|
+
return contractClass.id;
|
|
88
|
+
}
|
|
27
89
|
const privateFunctions = contract.functions.filter((functionArtifact)=>functionArtifact.functionType === FunctionType.PRIVATE);
|
|
28
|
-
const privateSelectors = await Promise.all(privateFunctions.map(async (
|
|
90
|
+
const privateSelectors = await Promise.all(privateFunctions.map(async (fn)=>(await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)).toString()));
|
|
29
91
|
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
30
92
|
throw new Error('Repeated function selectors of private functions');
|
|
31
93
|
}
|
|
32
|
-
|
|
94
|
+
this.#contractArtifactCache.set(key, contract);
|
|
95
|
+
await this.#store.transactionAsync(async ()=>{
|
|
96
|
+
await this.#contractArtifacts.set(key, contractArtifactToBuffer(contract));
|
|
97
|
+
await this.#contractClassData.set(key, new SerializableContractClassData(contractClass).toBuffer());
|
|
98
|
+
});
|
|
99
|
+
return contractClass.id;
|
|
33
100
|
}
|
|
34
101
|
async addContractInstance(contract) {
|
|
35
102
|
this.#contractClassIdMap.set(contract.address.toString(), contract.currentContractClassId);
|
|
@@ -37,25 +104,17 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
37
104
|
}
|
|
38
105
|
// Private getters
|
|
39
106
|
async #getContractClassId(contractAddress) {
|
|
40
|
-
|
|
107
|
+
const key = contractAddress.toString();
|
|
108
|
+
if (!this.#contractClassIdMap.has(key)) {
|
|
41
109
|
const instance = await this.getContractInstance(contractAddress);
|
|
42
110
|
if (!instance) {
|
|
43
111
|
return;
|
|
44
112
|
}
|
|
45
|
-
this.#contractClassIdMap.set(
|
|
113
|
+
this.#contractClassIdMap.set(key, instance.currentContractClassId);
|
|
46
114
|
}
|
|
47
|
-
return this.#contractClassIdMap.get(
|
|
115
|
+
return this.#contractClassIdMap.get(key);
|
|
48
116
|
}
|
|
49
|
-
|
|
50
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
51
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
52
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
53
|
-
* and added to the cache before returning.
|
|
54
|
-
*
|
|
55
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
56
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
57
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
58
|
-
*/ async #getPrivateFunctionTreeForClassId(classId) {
|
|
117
|
+
async #getPrivateFunctionTreeForClassId(classId) {
|
|
59
118
|
if (!this.#privateFunctionTrees.has(classId.toString())) {
|
|
60
119
|
const artifact = await this.getContractArtifact(classId);
|
|
61
120
|
if (!artifact) {
|
|
@@ -66,9 +125,9 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
66
125
|
}
|
|
67
126
|
return this.#privateFunctionTrees.get(classId.toString());
|
|
68
127
|
}
|
|
69
|
-
async #
|
|
70
|
-
const
|
|
71
|
-
return
|
|
128
|
+
async #getArtifactByAddress(contractAddress) {
|
|
129
|
+
const classId = await this.#getContractClassId(contractAddress);
|
|
130
|
+
return classId && this.getContractArtifact(classId);
|
|
72
131
|
}
|
|
73
132
|
// Public getters
|
|
74
133
|
getContractsAddresses() {
|
|
@@ -77,22 +136,43 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
77
136
|
return keys.map(AztecAddress.fromString);
|
|
78
137
|
});
|
|
79
138
|
}
|
|
80
|
-
/** Returns a contract instance for a given address.
|
|
139
|
+
/** Returns a contract instance for a given address. */ getContractInstance(contractAddress) {
|
|
81
140
|
return this.#store.transactionAsync(async ()=>{
|
|
82
141
|
const contract = await this.#contractInstances.getAsync(contractAddress.toString());
|
|
83
142
|
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(contractAddress);
|
|
84
143
|
});
|
|
85
144
|
}
|
|
86
|
-
getContractArtifact(contractClassId) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
145
|
+
/** Returns the raw contract artifact for a given class id. */ async getContractArtifact(contractClassId) {
|
|
146
|
+
const key = contractClassId.toString();
|
|
147
|
+
const cached = this.#contractArtifactCache.get(key);
|
|
148
|
+
if (cached) {
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
151
|
+
const artifact = await this.#store.transactionAsync(async ()=>{
|
|
152
|
+
const buf = await this.#contractArtifacts.getAsync(key);
|
|
153
|
+
return buf && contractArtifactFromBuffer(buf);
|
|
91
154
|
});
|
|
155
|
+
if (artifact) {
|
|
156
|
+
this.#contractArtifactCache.set(key, artifact);
|
|
157
|
+
}
|
|
158
|
+
return artifact;
|
|
92
159
|
}
|
|
93
|
-
/** Returns a contract class for a given class id.
|
|
160
|
+
/** Returns a contract class for a given class id. */ async getContractClassWithPreimage(contractClassId) {
|
|
161
|
+
const key = contractClassId.toString();
|
|
162
|
+
const buf = await this.#contractClassData.getAsync(key);
|
|
163
|
+
if (!buf) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const classData = SerializableContractClassData.fromBuffer(buf);
|
|
94
167
|
const artifact = await this.getContractArtifact(contractClassId);
|
|
95
|
-
|
|
168
|
+
if (!artifact) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const packedBytecode = artifact.functions.find((f)=>f.name === 'public_dispatch')?.bytecode ?? Buffer.alloc(0);
|
|
172
|
+
return {
|
|
173
|
+
...classData,
|
|
174
|
+
packedBytecode
|
|
175
|
+
};
|
|
96
176
|
}
|
|
97
177
|
async getContract(address) {
|
|
98
178
|
const instance = await this.getContractInstance(address);
|
|
@@ -110,17 +190,18 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
110
190
|
}
|
|
111
191
|
/**
|
|
112
192
|
* Retrieves the artifact of a specified function within a given contract.
|
|
113
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
114
|
-
* Throws an error if the contract address or function selector are invalid or not found.
|
|
115
193
|
*
|
|
116
194
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
117
195
|
* @param selector - The function selector.
|
|
118
196
|
* @returns The corresponding function's artifact as an object.
|
|
119
197
|
*/ async getFunctionArtifact(contractAddress, selector) {
|
|
120
|
-
const artifact = await this.#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
198
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
199
|
+
if (!artifact) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
203
|
+
return fn && {
|
|
204
|
+
...fn,
|
|
124
205
|
contractName: artifact.name
|
|
125
206
|
};
|
|
126
207
|
}
|
|
@@ -136,40 +217,38 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
136
217
|
};
|
|
137
218
|
}
|
|
138
219
|
async getPublicFunctionArtifact(contractAddress) {
|
|
139
|
-
const artifact = await this.#
|
|
140
|
-
const
|
|
141
|
-
return
|
|
142
|
-
...
|
|
220
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
221
|
+
const fn = artifact && artifact.functions.find((f)=>f.functionType === FunctionType.PUBLIC);
|
|
222
|
+
return fn && {
|
|
223
|
+
...fn,
|
|
143
224
|
contractName: artifact.name
|
|
144
225
|
};
|
|
145
226
|
}
|
|
146
227
|
async getFunctionAbi(contractAddress, selector) {
|
|
147
|
-
const artifact = await this.#
|
|
228
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
148
229
|
return artifact && await this.#findFunctionAbiBySelector(artifact, selector);
|
|
149
230
|
}
|
|
150
231
|
/**
|
|
151
232
|
* Retrieves the debug metadata of a specified function within a given contract.
|
|
152
|
-
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
153
|
-
* Returns undefined if the debug metadata for the given function is not found.
|
|
154
|
-
* Throws if the contract has not been added to the database.
|
|
155
233
|
*
|
|
156
234
|
* @param contractAddress - The AztecAddress representing the contract containing the function.
|
|
157
235
|
* @param selector - The function selector.
|
|
158
|
-
* @returns The corresponding function's
|
|
236
|
+
* @returns The corresponding function's debug metadata, or undefined.
|
|
159
237
|
*/ async getFunctionDebugMetadata(contractAddress, selector) {
|
|
160
|
-
const artifact = await this.#
|
|
161
|
-
|
|
162
|
-
|
|
238
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
239
|
+
if (!artifact) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
const fn = await this.#findFunctionArtifactBySelector(artifact, selector);
|
|
243
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
163
244
|
}
|
|
164
245
|
async getPublicFunctionDebugMetadata(contractAddress) {
|
|
165
|
-
const artifact = await this.#
|
|
166
|
-
const
|
|
167
|
-
return
|
|
246
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
247
|
+
const fn = artifact && artifact.functions.find((f)=>f.functionType === FunctionType.PUBLIC);
|
|
248
|
+
return fn && getFunctionDebugMetadata(artifact, fn);
|
|
168
249
|
}
|
|
169
250
|
/**
|
|
170
251
|
* Retrieve the function membership witness for the given contract class and function selector.
|
|
171
|
-
* The function membership witness represents a proof that the function belongs to the specified contract.
|
|
172
|
-
* Throws an error if the contract address or function selector is unknown.
|
|
173
252
|
*
|
|
174
253
|
* @param contractClassId - The id of the class.
|
|
175
254
|
* @param selector - The function selector.
|
|
@@ -179,18 +258,16 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
179
258
|
return tree?.getFunctionMembershipWitness(selector);
|
|
180
259
|
}
|
|
181
260
|
async getDebugContractName(contractAddress) {
|
|
182
|
-
const artifact = await this.#
|
|
261
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
183
262
|
return artifact?.name;
|
|
184
263
|
}
|
|
185
264
|
async getDebugFunctionName(contractAddress, selector) {
|
|
186
|
-
const artifact = await this.#
|
|
187
|
-
const
|
|
188
|
-
return `${artifact?.name ?? contractAddress}:${
|
|
265
|
+
const artifact = await this.#getArtifactByAddress(contractAddress);
|
|
266
|
+
const fn = artifact && await this.#findFunctionAbiBySelector(artifact, selector);
|
|
267
|
+
return `${artifact?.name ?? contractAddress}:${fn?.name ?? selector}`;
|
|
189
268
|
}
|
|
190
269
|
async #findFunctionArtifactBySelector(artifact, selector) {
|
|
191
|
-
const
|
|
192
|
-
for(let i = 0; i < functions.length; i++){
|
|
193
|
-
const fn = functions[i];
|
|
270
|
+
for (const fn of artifact.functions){
|
|
194
271
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
195
272
|
if (fnSelector.equals(selector)) {
|
|
196
273
|
return fn;
|
|
@@ -198,12 +275,10 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
198
275
|
}
|
|
199
276
|
}
|
|
200
277
|
async #findFunctionAbiBySelector(artifact, selector) {
|
|
201
|
-
const
|
|
278
|
+
for (const fn of [
|
|
202
279
|
...artifact.functions,
|
|
203
280
|
...artifact.nonDispatchPublicFunctions ?? []
|
|
204
|
-
]
|
|
205
|
-
for(let i = 0; i < functions.length; i++){
|
|
206
|
-
const fn = functions[i];
|
|
281
|
+
]){
|
|
207
282
|
const fnSelector = await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters);
|
|
208
283
|
if (fnSelector.equals(selector)) {
|
|
209
284
|
return fn;
|
|
@@ -219,15 +294,16 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
219
294
|
if (!functionDao) {
|
|
220
295
|
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
|
|
221
296
|
}
|
|
222
|
-
|
|
297
|
+
const selector = await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters);
|
|
298
|
+
return FunctionCall.from({
|
|
223
299
|
name: functionDao.name,
|
|
224
|
-
args: encodeArguments(functionDao, args),
|
|
225
|
-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
|
|
226
|
-
type: functionDao.functionType,
|
|
227
300
|
to,
|
|
301
|
+
selector,
|
|
302
|
+
type: functionDao.functionType,
|
|
228
303
|
hideMsgSender: false,
|
|
229
304
|
isStatic: functionDao.isStatic,
|
|
305
|
+
args: encodeArguments(functionDao, args),
|
|
230
306
|
returnTypes: functionDao.returnTypes
|
|
231
|
-
};
|
|
307
|
+
});
|
|
232
308
|
}
|
|
233
309
|
}
|
|
@@ -2,8 +2,9 @@ import type { Fr } from '@aztec/foundation/schemas';
|
|
|
2
2
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { DataInBlock } from '@aztec/stdlib/block';
|
|
5
|
-
import { NoteDao
|
|
5
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
6
6
|
import type { StagedStore } from '../../job_coordinator/job_coordinator.js';
|
|
7
|
+
import type { NotesFilter } from '../../notes_filter.js';
|
|
7
8
|
/**
|
|
8
9
|
* NoteStore manages the storage and retrieval of notes.
|
|
9
10
|
*
|
|
@@ -35,7 +36,6 @@ export declare class NoteStore implements StagedStore {
|
|
|
35
36
|
* @params jobId - the job context to read from.
|
|
36
37
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
37
38
|
* returned once if this is the case)
|
|
38
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
39
39
|
*/
|
|
40
40
|
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]>;
|
|
41
41
|
/**
|
|
@@ -80,4 +80,4 @@ export declare class NoteStore implements StagedStore {
|
|
|
80
80
|
commit(jobId: string): Promise<void>;
|
|
81
81
|
discardStaged(jobId: string): Promise<void>;
|
|
82
82
|
}
|
|
83
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2Uvbm90ZV9zdG9yZS9ub3RlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFxQyxNQUFNLGlCQUFpQixDQUFDO0FBQzVGLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxPQUFPLEVBQWMsTUFBTSxvQkFBb0IsQ0FBQztBQUV6RCxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwwQ0FBMEMsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUd6RDs7Ozs7SUFLSTtBQUNKLHFCQUFhLFNBQVUsWUFBVyxXQUFXOztJQUMzQyxRQUFRLENBQUMsU0FBUyxFQUFFLE1BQU0sQ0FBVTtJQStCcEMsWUFBWSxLQUFLLEVBQUUsaUJBQWlCLEVBUW5DO0lBRUQ7Ozs7Ozs7OztPQVNHO0lBQ0ksUUFBUSxDQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsRUFBRSxLQUFLLEVBQUUsWUFBWSxFQUFFLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksRUFBRSxDQUFDLENBYXJGO0lBY0Q7Ozs7Ozs7Ozs7T0FVRztJQUNILFFBQVEsQ0FBQyxNQUFNLEVBQUUsV0FBVyxFQUFFLEtBQUssRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE9BQU8sRUFBRSxDQUFDLENBZ0cvRDtJQUVEOzs7Ozs7Ozs7Ozs7OztPQWNHO0lBQ0gsZUFBZSxDQUFDLFVBQVUsRUFBRSxXQUFXLENBQUMsRUFBRSxDQUFDLEVBQUUsRUFBRSxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQXlDaEY7SUFFRDs7Ozs7Ozs7Ozs7T0FXRztJQUNVLFFBQVEsQ0FBQyxXQUFXLEVBQUUsTUFBTSxFQUFFLGtCQUFrQixFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBTXBGO0lBNkVEOzs7Ozs7Ozs7T0FTRztJQUNHLE1BQU0sQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FVekM7SUFFRCxhQUFhLENBQUMsS0FBSyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRzFDO0NBa0NGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"note_store.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"note_store.d.ts","sourceRoot":"","sources":["../../../src/storage/note_store/note_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAc,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD;;;;;IAKI;AACJ,qBAAa,SAAU,YAAW,WAAW;;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAU;IA+BpC,YAAY,KAAK,EAAE,iBAAiB,EAQnC;IAED;;;;;;;;;OASG;IACI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAarF;IAcD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAgG/D;IAED;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAyChF;IAED;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMpF;IA6ED;;;;;;;;;OASG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUzC;IAED,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1C;CAkCF"}
|
|
@@ -74,10 +74,9 @@ import { StoredNote } from './stored_note.js';
|
|
|
74
74
|
* @params jobId - the job context to read from.
|
|
75
75
|
* @returns Filtered and deduplicated notes (a note might be present in multiple scopes - we ensure it is only
|
|
76
76
|
* returned once if this is the case)
|
|
77
|
-
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
78
77
|
*/ getNotes(filter, jobId) {
|
|
79
|
-
if (filter.scopes !==
|
|
80
|
-
return Promise.
|
|
78
|
+
if (filter.scopes !== 'ALL_SCOPES' && filter.scopes.length === 0) {
|
|
79
|
+
return Promise.resolve([]);
|
|
81
80
|
}
|
|
82
81
|
return this.#store.transactionAsync(async ()=>{
|
|
83
82
|
const targetStatus = filter.status ?? NoteStatus.ACTIVE;
|
|
@@ -136,7 +135,7 @@ import { StoredNote } from './stored_note.js';
|
|
|
136
135
|
if (filter.siloedNullifier && !note.noteDao.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
137
136
|
continue;
|
|
138
137
|
}
|
|
139
|
-
if (filter.scopes && note.scopes.intersection(new Set(filter.scopes.map((s)=>s.toString()))).size === 0) {
|
|
138
|
+
if (filter.scopes !== 'ALL_SCOPES' && note.scopes.intersection(new Set(filter.scopes.map((s)=>s.toString()))).size === 0) {
|
|
140
139
|
continue;
|
|
141
140
|
}
|
|
142
141
|
foundNotes.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
@@ -173,6 +172,9 @@ import { StoredNote } from './stored_note.js';
|
|
|
173
172
|
if (nullifiers.length === 0) {
|
|
174
173
|
return Promise.resolve([]);
|
|
175
174
|
}
|
|
175
|
+
if (nullifiers.some((n)=>n.l2BlockNumber === 0)) {
|
|
176
|
+
return Promise.reject(new Error('applyNullifiers: nullifiers cannot have been emitted at block 0'));
|
|
177
|
+
}
|
|
176
178
|
return this.#withJobLock(jobId, ()=>this.#store.transactionAsync(async ()=>{
|
|
177
179
|
const notesToNullify = await Promise.all(nullifiers.map(async (nullifierInBlock)=>{
|
|
178
180
|
const nullifier = nullifierInBlock.data.toString();
|
|
@@ -21,4 +21,4 @@ export declare function getAllPrivateLogsByTags(aztecNode: AztecNode, tags: Silo
|
|
|
21
21
|
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
22
22
|
*/
|
|
23
23
|
export declare function getAllPublicLogsByTagsFromContract(aztecNode: AztecNode, contractAddress: AztecAddress, tags: Tag[], anchorBlockHash: BlockHash): Promise<TxScopedL2Log[][]>;
|
|
24
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2V0X2FsbF9sb2dzX2J5X3RhZ3MuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90YWdnaW5nL2dldF9hbGxfbG9nc19ieV90YWdzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXJELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxHQUFHLEVBQUUsYUFBYSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFpRHhFOzs7Ozs7O0dBT0c7QUFDSCx3QkFBZ0IsdUJBQXVCLENBQ3JDLFNBQVMsRUFBRSxTQUFTLEVBQ3BCLElBQUksRUFBRSxTQUFTLEVBQUUsRUFDakIsZUFBZSxFQUFFLFNBQVMsR0FDekIsT0FBTyxDQUFDLGFBQWEsRUFBRSxFQUFFLENBQUMsQ0FJNUI7QUFFRDs7Ozs7Ozs7R0FRRztBQUNILHdCQUFnQixrQ0FBa0MsQ0FDaEQsU0FBUyxFQUFFLFNBQVMsRUFDcEIsZUFBZSxFQUFFLFlBQVksRUFDN0IsSUFBSSxFQUFFLEdBQUcsRUFBRSxFQUNYLGVBQWUsRUFBRSxTQUFTLEdBQ3pCLE9BQU8sQ0FBQyxhQUFhLEVBQUUsRUFBRSxDQUFDLENBTTVCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_all_logs_by_tags.d.ts","sourceRoot":"","sources":["../../src/tagging/get_all_logs_by_tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"get_all_logs_by_tags.d.ts","sourceRoot":"","sources":["../../src/tagging/get_all_logs_by_tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAiDxE;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,SAAS,EAAE,EACjB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAI5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,YAAY,EAC7B,IAAI,EAAE,GAAG,EAAE,EACX,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAM5B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
1
|
+
import { MAX_LOGS_PER_TAG, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/api-limit';
|
|
2
2
|
/**
|
|
3
3
|
* Generic pagination helper that fetches all pages of results.
|
|
4
4
|
* @param numTags - The number of tags being queried (determines result array size).
|
|
@@ -23,6 +23,20 @@ import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
|
23
23
|
}
|
|
24
24
|
return allResultsPerTag;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Splits tags into chunks of MAX_RPC_LEN, fetches logs for each chunk using getAllPages, then stitches the results
|
|
28
|
+
* back into a single array preserving the original tag order.
|
|
29
|
+
*/ async function getAllPagesInBatches(tags, fetchAllPagesForBatch) {
|
|
30
|
+
if (tags.length <= MAX_RPC_LEN) {
|
|
31
|
+
return fetchAllPagesForBatch(tags);
|
|
32
|
+
}
|
|
33
|
+
const batches = [];
|
|
34
|
+
for(let i = 0; i < tags.length; i += MAX_RPC_LEN){
|
|
35
|
+
batches.push(tags.slice(i, i + MAX_RPC_LEN));
|
|
36
|
+
}
|
|
37
|
+
const batchResults = await Promise.all(batches.map(fetchAllPagesForBatch));
|
|
38
|
+
return batchResults.flat();
|
|
39
|
+
}
|
|
26
40
|
/**
|
|
27
41
|
* Fetches all private logs for the given tags, automatically paginating through all pages.
|
|
28
42
|
* @param aztecNode - The Aztec node to query.
|
|
@@ -31,7 +45,7 @@ import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
|
31
45
|
* because of reorgs).
|
|
32
46
|
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
33
47
|
*/ export function getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash) {
|
|
34
|
-
return getAllPages(
|
|
48
|
+
return getAllPagesInBatches(tags, (batch)=>getAllPages(batch.length, (page)=>aztecNode.getPrivateLogsByTags(batch, page, anchorBlockHash)));
|
|
35
49
|
}
|
|
36
50
|
/**
|
|
37
51
|
* Fetches all public logs for the given tags from a contract, automatically paginating through all pages.
|
|
@@ -42,5 +56,5 @@ import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
|
42
56
|
* because of reorgs).
|
|
43
57
|
* @returns An array of log arrays, one per tag, containing all logs across all pages.
|
|
44
58
|
*/ export function getAllPublicLogsByTagsFromContract(aztecNode, contractAddress, tags, anchorBlockHash) {
|
|
45
|
-
return getAllPages(
|
|
59
|
+
return getAllPagesInBatches(tags, (batch)=>getAllPages(batch.length, (page)=>aztecNode.getPublicLogsByTagsFromContract(contractAddress, batch, page, anchorBlockHash)));
|
|
46
60
|
}
|
|
@@ -13,7 +13,7 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
13
13
|
// (highestAgedIndex, highestFinalizedIndex + WINDOW_LEN]
|
|
14
14
|
//
|
|
15
15
|
// highestAgedIndex is the highest index that was used in a tx that is included in a block at least
|
|
16
|
-
// `
|
|
16
|
+
// `MAX_TX_LIFETIME` seconds ago.
|
|
17
17
|
// highestFinalizedIndex is the highest index that was used in a tx that is included in a finalized block.
|
|
18
18
|
//
|
|
19
19
|
// "(" denotes an open end of the range - the index is not included in the range.
|
|
@@ -25,19 +25,19 @@ import { loadLogsForRange } from './utils/load_logs_for_range.js';
|
|
|
25
25
|
// ever appear.
|
|
26
26
|
//
|
|
27
27
|
// This relies on the "maximum inclusion timestamp" rule enforced by the kernel and rollup circuits:
|
|
28
|
-
// - a transaction's maximum inclusion timestamp is at most `
|
|
28
|
+
// - a transaction's maximum inclusion timestamp is at most `MAX_TX_LIFETIME` seconds after
|
|
29
29
|
// the timestamp of its anchor block; and
|
|
30
30
|
// - a rollup only includes transactions whose inclusion timestamp is >= the L2 block's timestamp.
|
|
31
31
|
//
|
|
32
32
|
// Suppose some device used index `I` in a transaction anchored to block `B_N` at time `N`, and that block is now at
|
|
33
|
-
// least `
|
|
33
|
+
// least `MAX_TX_LIFETIME` seconds in the past. Then there is no possibility of any *other* device
|
|
34
34
|
// trying to use an index <= `I` while anchoring to a *newer* block than `B_N` because if we were anchoring to
|
|
35
35
|
// a newer block than `B_N` then we would already have seen the log with index `I` and hence the device would have
|
|
36
36
|
// chosen a larger index.
|
|
37
37
|
// If that *other* device would anchor to a block older than `B_N` then that tx could never be included in a block
|
|
38
38
|
// because it would already have been expired.
|
|
39
39
|
//
|
|
40
|
-
// Therefore, once we see that index `I` has been used in a block that is at least `
|
|
40
|
+
// Therefore, once we see that index `I` has been used in a block that is at least `MAX_TX_LIFETIME`
|
|
41
41
|
// seconds old, we can safely stop syncing logs for all indexes <= `I` and set highestAgedIndex = `I`.
|
|
42
42
|
//
|
|
43
43
|
// ## Explanation of the upper bound `highestFinalizedIndex + WINDOW_LEN`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_TX_LIFETIME } from '@aztec/constants';
|
|
2
2
|
/**
|
|
3
3
|
* Finds the highest aged and the highest finalized tagging indexes.
|
|
4
4
|
*/ export function findHighestIndexes(privateLogsWithIndexes, currentTimestamp, finalizedBlockNumber) {
|
|
@@ -6,7 +6,7 @@ import { MAX_INCLUDE_BY_TIMESTAMP_DURATION } from '@aztec/constants';
|
|
|
6
6
|
let highestFinalizedIndex = undefined;
|
|
7
7
|
for (const { log, taggingIndex } of privateLogsWithIndexes){
|
|
8
8
|
const ageInSeconds = currentTimestamp - log.blockTimestamp;
|
|
9
|
-
if (ageInSeconds >= BigInt(
|
|
9
|
+
if (ageInSeconds >= BigInt(MAX_TX_LIFETIME) && (highestAgedIndex === undefined || taggingIndex > highestAgedIndex)) {
|
|
10
10
|
highestAgedIndex = taggingIndex;
|
|
11
11
|
}
|
|
12
12
|
if (log.blockNumber <= finalizedBlockNumber && (highestFinalizedIndex === undefined || taggingIndex > highestFinalizedIndex)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/pxe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.934299a21",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"typedocOptions": {
|
|
6
|
+
"entryPoints": [
|
|
7
|
+
"./src/entrypoints/server/index.ts",
|
|
8
|
+
"./src/entrypoints/client/lazy/index.ts",
|
|
9
|
+
"./src/config/index.ts"
|
|
10
|
+
],
|
|
11
|
+
"name": "PXE",
|
|
12
|
+
"tsconfig": "./tsconfig.json"
|
|
13
|
+
},
|
|
5
14
|
"exports": {
|
|
6
15
|
"./server": "./dest/entrypoints/server/index.js",
|
|
7
16
|
"./client/lazy": "./dest/entrypoints/client/lazy/index.js",
|
|
@@ -61,19 +70,19 @@
|
|
|
61
70
|
]
|
|
62
71
|
},
|
|
63
72
|
"dependencies": {
|
|
64
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
65
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
66
|
-
"@aztec/builder": "0.0.1-commit.
|
|
67
|
-
"@aztec/constants": "0.0.1-commit.
|
|
68
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
69
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
70
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
71
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
72
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
73
|
-
"@aztec/noir-types": "0.0.1-commit.
|
|
74
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
75
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
76
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
73
|
+
"@aztec/bb-prover": "0.0.1-commit.934299a21",
|
|
74
|
+
"@aztec/bb.js": "0.0.1-commit.934299a21",
|
|
75
|
+
"@aztec/builder": "0.0.1-commit.934299a21",
|
|
76
|
+
"@aztec/constants": "0.0.1-commit.934299a21",
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.934299a21",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.934299a21",
|
|
79
|
+
"@aztec/key-store": "0.0.1-commit.934299a21",
|
|
80
|
+
"@aztec/kv-store": "0.0.1-commit.934299a21",
|
|
81
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.934299a21",
|
|
82
|
+
"@aztec/noir-types": "0.0.1-commit.934299a21",
|
|
83
|
+
"@aztec/protocol-contracts": "0.0.1-commit.934299a21",
|
|
84
|
+
"@aztec/simulator": "0.0.1-commit.934299a21",
|
|
85
|
+
"@aztec/stdlib": "0.0.1-commit.934299a21",
|
|
77
86
|
"koa": "^2.16.1",
|
|
78
87
|
"koa-router": "^13.1.1",
|
|
79
88
|
"lodash.omit": "^4.5.0",
|
|
@@ -82,8 +91,8 @@
|
|
|
82
91
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
83
92
|
},
|
|
84
93
|
"devDependencies": {
|
|
85
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
86
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
94
|
+
"@aztec/merkle-tree": "0.0.1-commit.934299a21",
|
|
95
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.934299a21",
|
|
87
96
|
"@jest/globals": "^30.0.0",
|
|
88
97
|
"@types/jest": "^30.0.0",
|
|
89
98
|
"@types/lodash.omit": "^4.5.7",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Controls which accounts' private state and keys are accessible during execution.
|
|
5
|
+
* - `'ALL_SCOPES'`: All registered accounts' private state and keys are accessible.
|
|
6
|
+
* - `AztecAddress[]` with entries: Only the specified accounts' private state and keys are accessible.
|
|
7
|
+
* - `[]` (empty array): Deny-all. No private state is visible and no keys are accessible.
|
|
8
|
+
*/
|
|
9
|
+
export type AccessScopes = 'ALL_SCOPES' | AztecAddress[];
|
|
@@ -7,6 +7,7 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
|
7
7
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
9
|
import type { BlockSynchronizerConfig } from '../config/index.js';
|
|
10
|
+
import type { ContractSyncService } from '../contract_sync/contract_sync_service.js';
|
|
10
11
|
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
11
12
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
12
13
|
import type { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
|
|
@@ -28,6 +29,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
28
29
|
private noteStore: NoteStore,
|
|
29
30
|
private privateEventStore: PrivateEventStore,
|
|
30
31
|
private l2TipsStore: L2TipsKVStore,
|
|
32
|
+
private contractSyncService: ContractSyncService,
|
|
31
33
|
private config: Partial<BlockSynchronizerConfig> = {},
|
|
32
34
|
bindings?: LoggerBindings,
|
|
33
35
|
) {
|
|
@@ -125,6 +127,10 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
|
|
|
125
127
|
|
|
126
128
|
/** Updates the anchor block header to the target block */
|
|
127
129
|
private async updateAnchorBlockHeader(blockHeader: BlockHeader) {
|
|
130
|
+
// Whenever the anchor block header is updated, we need to synchronize the private state of contracts again.
|
|
131
|
+
// Therefore, we clear the contract synchronization cache here such that the sync is re-triggered upon new
|
|
132
|
+
// execution.
|
|
133
|
+
this.contractSyncService.wipe();
|
|
128
134
|
this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
|
|
129
135
|
await this.anchorBlockStore.setHeader(blockHeader);
|
|
130
136
|
}
|