@aztec/pxe 0.0.1-commit.3469e52 → 0.0.1-commit.3d8f95d
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/bin/check_oracle_version.js +1 -1
- package/dest/block_synchronizer/block_synchronizer.d.ts +9 -5
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +62 -16
- package/dest/config/index.d.ts +3 -1
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +17 -0
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +50 -28
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +71 -40
- package/dest/contract_function_simulator/noir-structs/event_validation_request.d.ts +1 -1
- 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 +1 -1
- package/dest/contract_function_simulator/noir-structs/note_validation_request.js +1 -1
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +15 -12
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +7 -5
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +51 -29
- package/dest/contract_function_simulator/oracle/private_execution.d.ts +2 -22
- package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution.js +0 -37
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +43 -36
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +79 -23
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +61 -30
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +103 -86
- package/dest/contract_sync/contract_sync_service.d.ts +41 -0
- package/dest/contract_sync/contract_sync_service.d.ts.map +1 -0
- package/dest/contract_sync/contract_sync_service.js +82 -0
- package/dest/contract_sync/helpers.d.ts +28 -0
- package/dest/contract_sync/helpers.d.ts.map +1 -0
- package/dest/contract_sync/helpers.js +55 -0
- package/dest/debug/pxe_debug_utils.d.ts +22 -9
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +28 -17
- 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 +21 -7
- package/dest/entrypoints/client/lazy/utils.d.ts +2 -2
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +22 -8
- package/dest/entrypoints/pxe_creation_options.d.ts +3 -2
- package/dest/entrypoints/pxe_creation_options.d.ts.map +1 -1
- package/dest/entrypoints/server/index.d.ts +2 -1
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -0
- package/dest/entrypoints/server/utils.d.ts +1 -1
- package/dest/entrypoints/server/utils.d.ts.map +1 -1
- package/dest/entrypoints/server/utils.js +28 -9
- package/dest/events/event_service.d.ts +5 -6
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +6 -7
- package/dest/job_coordinator/job_coordinator.d.ts +3 -2
- package/dest/job_coordinator/job_coordinator.d.ts.map +1 -1
- package/dest/job_coordinator/job_coordinator.js +3 -2
- package/dest/logs/log_service.d.ts +6 -5
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +20 -19
- package/dest/notes/note_service.d.ts +6 -6
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +14 -14
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +4 -3
- package/dest/private_kernel/private_kernel_execution_prover.d.ts +3 -2
- package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
- package/dest/private_kernel/private_kernel_execution_prover.js +2 -2
- package/dest/private_kernel/private_kernel_oracle.d.ts +3 -3
- package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
- package/dest/pxe.d.ts +64 -22
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +72 -43
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +1 -2
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +27 -30
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +48 -50
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +279 -252
- package/dest/storage/note_store/stored_note.d.ts +16 -0
- package/dest/storage/note_store/stored_note.d.ts.map +1 -0
- package/dest/storage/note_store/stored_note.js +43 -0
- package/dest/storage/private_event_store/private_event_store.d.ts +17 -4
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +198 -147
- package/dest/storage/private_event_store/stored_private_event.d.ts +23 -0
- package/dest/storage/private_event_store/stored_private_event.d.ts.map +1 -0
- package/dest/storage/private_event_store/stored_private_event.js +56 -0
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
- package/dest/tagging/get_all_logs_by_tags.d.ts +24 -0
- package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -0
- package/dest/tagging/get_all_logs_by_tags.js +46 -0
- package/dest/tagging/index.d.ts +2 -1
- package/dest/tagging/index.d.ts.map +1 -1
- package/dest/tagging/index.js +1 -0
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +3 -2
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +2 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts +3 -2
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.d.ts.map +1 -1
- package/dest/tagging/recipient_sync/utils/load_logs_for_range.js +5 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +2 -2
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +5 -8
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +3 -2
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
- package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +7 -4
- package/package.json +25 -16
- package/src/bin/check_oracle_version.ts +1 -0
- package/src/block_synchronizer/block_synchronizer.ts +76 -33
- package/src/config/index.ts +14 -0
- package/src/contract_function_simulator/contract_function_simulator.ts +116 -86
- 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 +20 -11
- package/src/contract_function_simulator/oracle/oracle.ts +56 -26
- package/src/contract_function_simulator/oracle/private_execution.ts +1 -60
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +113 -102
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +165 -95
- package/src/contract_sync/contract_sync_service.ts +129 -0
- package/src/contract_sync/helpers.ts +93 -0
- package/src/debug/pxe_debug_utils.ts +60 -17
- package/src/entrypoints/client/bundle/utils.ts +16 -15
- package/src/entrypoints/client/lazy/utils.ts +17 -15
- package/src/entrypoints/pxe_creation_options.ts +2 -1
- package/src/entrypoints/server/index.ts +1 -0
- package/src/entrypoints/server/utils.ts +22 -26
- package/src/events/event_service.ts +5 -7
- package/src/job_coordinator/job_coordinator.ts +4 -3
- package/src/logs/log_service.ts +31 -15
- package/src/notes/note_service.ts +21 -20
- package/src/oracle_version.ts +4 -3
- package/src/private_kernel/private_kernel_execution_prover.ts +6 -3
- package/src/private_kernel/private_kernel_oracle.ts +2 -2
- package/src/pxe.ts +162 -73
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +26 -35
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +318 -318
- package/src/storage/note_store/stored_note.ts +48 -0
- package/src/storage/private_event_store/private_event_store.ts +250 -190
- package/src/storage/private_event_store/stored_private_event.ts +73 -0
- package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
- package/src/tagging/get_all_logs_by_tags.ts +68 -0
- package/src/tagging/index.ts +1 -0
- package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +11 -1
- package/src/tagging/recipient_sync/utils/load_logs_for_range.ts +7 -1
- package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +3 -1
- package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +5 -17
- package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +12 -3
- package/dest/tree_membership/tree_membership_service.d.ts +0 -50
- package/dest/tree_membership/tree_membership_service.d.ts.map +0 -1
- package/dest/tree_membership/tree_membership_service.js +0 -75
- package/src/tree_membership/tree_membership_service.ts +0 -97
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { DataInBlock } from '@aztec/stdlib/block';
|
|
4
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
5
4
|
import { computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
6
5
|
import { type AztecNode, MAX_RPC_LEN } from '@aztec/stdlib/interfaces/client';
|
|
7
6
|
import { Note, NoteDao, NoteStatus } from '@aztec/stdlib/note';
|
|
8
7
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
9
|
-
import type { TxHash } from '@aztec/stdlib/tx';
|
|
8
|
+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
10
9
|
|
|
11
|
-
import type { AnchorBlockStore } from '../storage/anchor_block_store/anchor_block_store.js';
|
|
12
10
|
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
13
11
|
|
|
14
12
|
export class NoteService {
|
|
15
13
|
constructor(
|
|
16
14
|
private readonly noteStore: NoteStore,
|
|
17
15
|
private readonly aztecNode: AztecNode,
|
|
18
|
-
private readonly
|
|
16
|
+
private readonly anchorBlockHeader: BlockHeader,
|
|
17
|
+
private readonly jobId: string,
|
|
19
18
|
) {}
|
|
20
19
|
|
|
21
20
|
/**
|
|
@@ -34,13 +33,16 @@ export class NoteService {
|
|
|
34
33
|
status: NoteStatus,
|
|
35
34
|
scopes?: AztecAddress[],
|
|
36
35
|
) {
|
|
37
|
-
const noteDaos = await this.noteStore.getNotes(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
const noteDaos = await this.noteStore.getNotes(
|
|
37
|
+
{
|
|
38
|
+
contractAddress,
|
|
39
|
+
owner,
|
|
40
|
+
storageSlot,
|
|
41
|
+
status,
|
|
42
|
+
scopes,
|
|
43
|
+
},
|
|
44
|
+
this.jobId,
|
|
45
|
+
);
|
|
44
46
|
return noteDaos.map(
|
|
45
47
|
({ contractAddress, owner, storageSlot, randomness, noteNonce, note, noteHash, siloedNullifier }) => ({
|
|
46
48
|
contractAddress,
|
|
@@ -69,9 +71,9 @@ export class NoteService {
|
|
|
69
71
|
* @param contractAddress - The contract whose notes should be checked and nullified.
|
|
70
72
|
*/
|
|
71
73
|
public async syncNoteNullifiers(contractAddress: AztecAddress): Promise<void> {
|
|
72
|
-
const anchorBlockHash =
|
|
74
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
73
75
|
|
|
74
|
-
const contractNotes = await this.noteStore.getNotes({ contractAddress });
|
|
76
|
+
const contractNotes = await this.noteStore.getNotes({ contractAddress }, this.jobId);
|
|
75
77
|
|
|
76
78
|
if (contractNotes.length === 0) {
|
|
77
79
|
return;
|
|
@@ -105,10 +107,10 @@ export class NoteService {
|
|
|
105
107
|
})
|
|
106
108
|
.filter(nullifier => nullifier !== undefined) as DataInBlock<Fr>[];
|
|
107
109
|
|
|
108
|
-
await this.noteStore.applyNullifiers(foundNullifiers);
|
|
110
|
+
await this.noteStore.applyNullifiers(foundNullifiers, this.jobId);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
public async
|
|
113
|
+
public async validateAndStoreNote(
|
|
112
114
|
contractAddress: AztecAddress,
|
|
113
115
|
owner: AztecAddress,
|
|
114
116
|
storageSlot: Fr,
|
|
@@ -139,9 +141,8 @@ export class NoteService {
|
|
|
139
141
|
// number which *should* be recent enough to be available, even for non-archive nodes.
|
|
140
142
|
// Also note that the note should never be ahead of the synced block here since `fetchTaggedLogs` only processes
|
|
141
143
|
// logs up to the synced block making this only an additional safety check.
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const anchorBlockHash = L2BlockHash.fromField(await anchorBlockHeader.hash());
|
|
144
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
145
|
+
const anchorBlockHash = await this.anchorBlockHeader.hash();
|
|
145
146
|
|
|
146
147
|
// By computing siloed and unique note hashes ourselves we prevent contracts from interfering with the note storage
|
|
147
148
|
// of other contracts, which would constitute a security breach.
|
|
@@ -183,12 +184,12 @@ export class NoteService {
|
|
|
183
184
|
);
|
|
184
185
|
|
|
185
186
|
// The note was found by `recipient`, so we use that as the scope when storing the note.
|
|
186
|
-
await this.noteStore.addNotes([noteDao], recipient);
|
|
187
|
+
await this.noteStore.addNotes([noteDao], recipient, this.jobId);
|
|
187
188
|
|
|
188
189
|
if (nullifierIndex !== undefined) {
|
|
189
190
|
// We found nullifier index which implies that the note has already been nullified.
|
|
190
191
|
const { data: _, ...blockHashAndNum } = nullifierIndex;
|
|
191
|
-
await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }]);
|
|
192
|
+
await this.noteStore.applyNullifiers([{ data: siloedNullifier, ...blockHashAndNum }], this.jobId);
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
}
|
package/src/oracle_version.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
///
|
|
5
5
|
/// @dev Whenever a contract function or Noir test is run, the `utilityAssertCompatibleOracleVersion` oracle is called
|
|
6
6
|
/// and if the oracle version is incompatible an error is thrown.
|
|
7
|
-
export const ORACLE_VERSION =
|
|
7
|
+
export const ORACLE_VERSION = 12;
|
|
8
8
|
|
|
9
9
|
/// This hash is computed as by hashing the Oracle interface and it is used to detect when the Oracle interface changes,
|
|
10
|
-
/// which in turn implies that you need to update the ORACLE_VERSION constant
|
|
11
|
-
|
|
10
|
+
/// which in turn implies that you need to update the ORACLE_VERSION constant in this file and in
|
|
11
|
+
/// `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
|
|
12
|
+
export const ORACLE_INTERFACE_HASH = '666a8a7fc697f72b29dbf0ae7464db269cf5afa019acac8861f814543147dbb4';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
5
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
6
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
@@ -56,13 +56,16 @@ export interface PrivateKernelExecutionProverConfig {
|
|
|
56
56
|
* inform state tree updates.
|
|
57
57
|
*/
|
|
58
58
|
export class PrivateKernelExecutionProver {
|
|
59
|
-
private log
|
|
59
|
+
private log: Logger;
|
|
60
60
|
|
|
61
61
|
constructor(
|
|
62
62
|
private oracle: PrivateKernelOracle,
|
|
63
63
|
private proofCreator: PrivateKernelProver,
|
|
64
64
|
private fakeProofs = false,
|
|
65
|
-
|
|
65
|
+
bindings?: LoggerBindings,
|
|
66
|
+
) {
|
|
67
|
+
this.log = createLogger('pxe:private-kernel-execution-prover', bindings);
|
|
68
|
+
}
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
71
|
* Generate a proof for a given transaction request and execution result.
|
|
@@ -7,7 +7,7 @@ import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-type
|
|
|
7
7
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
8
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
-
import {
|
|
10
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
11
11
|
import {
|
|
12
12
|
type ContractInstanceWithAddress,
|
|
13
13
|
computeContractClassIdPreimage,
|
|
@@ -30,7 +30,7 @@ export class PrivateKernelOracle {
|
|
|
30
30
|
private contractStore: ContractStore,
|
|
31
31
|
private keyStore: KeyStore,
|
|
32
32
|
private node: AztecNode,
|
|
33
|
-
private blockHash:
|
|
33
|
+
private blockHash: BlockHash,
|
|
34
34
|
) {}
|
|
35
35
|
|
|
36
36
|
/** Retrieves the preimage of a contract address from the registered contract instances db. */
|
package/src/pxe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PrivateEventFilter } from '@aztec/aztec.js/wallet';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { SerialQueue } from '@aztec/foundation/queue';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
7
7
|
import { KeyStore } from '@aztec/key-store';
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
} from '@aztec/stdlib/abi';
|
|
19
19
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
20
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
21
|
-
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
22
21
|
import {
|
|
23
22
|
CompleteAddress,
|
|
24
23
|
type ContractInstanceWithAddress,
|
|
@@ -34,6 +33,7 @@ import type {
|
|
|
34
33
|
PrivateKernelTailCircuitPublicInputs,
|
|
35
34
|
} from '@aztec/stdlib/kernel';
|
|
36
35
|
import {
|
|
36
|
+
BlockHeader,
|
|
37
37
|
type ContractOverrides,
|
|
38
38
|
type InTx,
|
|
39
39
|
PrivateExecutionResult,
|
|
@@ -59,8 +59,9 @@ import {
|
|
|
59
59
|
ContractFunctionSimulator,
|
|
60
60
|
generateSimulatedProvingResult,
|
|
61
61
|
} from './contract_function_simulator/contract_function_simulator.js';
|
|
62
|
-
import { readCurrentClassId } from './contract_function_simulator/oracle/private_execution.js';
|
|
63
62
|
import { ProxiedContractStoreFactory } from './contract_function_simulator/proxied_contract_data_source.js';
|
|
63
|
+
import { ContractSyncService } from './contract_sync/contract_sync_service.js';
|
|
64
|
+
import { readCurrentClassId } from './contract_sync/helpers.js';
|
|
64
65
|
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
|
|
65
66
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
66
67
|
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
|
|
@@ -85,6 +86,54 @@ export type PackedPrivateEvent = InTx & {
|
|
|
85
86
|
eventSelector: EventSelector;
|
|
86
87
|
};
|
|
87
88
|
|
|
89
|
+
/** Options for PXE.profileTx. */
|
|
90
|
+
export type ProfileTxOpts = {
|
|
91
|
+
/** The profiling mode to use. */
|
|
92
|
+
profileMode: 'full' | 'execution-steps' | 'gates';
|
|
93
|
+
/** If true, proof generation is skipped during profiling. Defaults to true. */
|
|
94
|
+
skipProofGeneration?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Options for PXE.simulateTx. */
|
|
98
|
+
export type SimulateTxOpts = {
|
|
99
|
+
/** Whether to simulate the public part of the transaction. */
|
|
100
|
+
simulatePublic: boolean;
|
|
101
|
+
/** If false, this function throws if the transaction is unable to be included in a block at the current state. */
|
|
102
|
+
skipTxValidation?: boolean;
|
|
103
|
+
/** If false, fees are enforced. */
|
|
104
|
+
skipFeeEnforcement?: boolean;
|
|
105
|
+
/** State overrides for the simulation, such as contract instances and artifacts. */
|
|
106
|
+
overrides?: SimulationOverrides;
|
|
107
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
108
|
+
scopes?: AztecAddress[];
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** Options for PXE.simulateUtility. */
|
|
112
|
+
export type SimulateUtilityOpts = {
|
|
113
|
+
/** The authentication witnesses required for the function call. */
|
|
114
|
+
authwits?: AuthWitness[];
|
|
115
|
+
/** The accounts whose notes we can access in this call. Defaults to all. */
|
|
116
|
+
scopes?: AztecAddress[];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Args for PXE.create. */
|
|
120
|
+
export type PXECreateArgs = {
|
|
121
|
+
/** The Aztec node to connect to. */
|
|
122
|
+
node: AztecNode;
|
|
123
|
+
/** The key-value store for persisting PXE state. */
|
|
124
|
+
store: AztecAsyncKVStore;
|
|
125
|
+
/** The prover for generating private kernel proofs. */
|
|
126
|
+
proofCreator: PrivateKernelProver;
|
|
127
|
+
/** The circuit simulator for executing ACIR circuits. */
|
|
128
|
+
simulator: CircuitSimulator;
|
|
129
|
+
/** Provider for protocol contract artifacts and instances. */
|
|
130
|
+
protocolContractsProvider: ProtocolContractsProvider;
|
|
131
|
+
/** PXE configuration options. */
|
|
132
|
+
config: PXEConfig;
|
|
133
|
+
/** Optional logger instance or string suffix for the logger name. */
|
|
134
|
+
loggerOrSuffix?: string | Logger;
|
|
135
|
+
};
|
|
136
|
+
|
|
88
137
|
/**
|
|
89
138
|
* Private eXecution Environment (PXE) is a library used by wallets to simulate private phase of transactions and to
|
|
90
139
|
* manage private state of users.
|
|
@@ -103,6 +152,7 @@ export class PXE {
|
|
|
103
152
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
104
153
|
private addressStore: AddressStore,
|
|
105
154
|
private privateEventStore: PrivateEventStore,
|
|
155
|
+
private contractSyncService: ContractSyncService,
|
|
106
156
|
private simulator: CircuitSimulator,
|
|
107
157
|
private proverEnabled: boolean,
|
|
108
158
|
private proofCreator: PrivateKernelProver,
|
|
@@ -120,15 +170,19 @@ export class PXE {
|
|
|
120
170
|
*
|
|
121
171
|
* @returns A promise that resolves PXE is ready to be used.
|
|
122
172
|
*/
|
|
123
|
-
public static async create(
|
|
124
|
-
node
|
|
125
|
-
store
|
|
126
|
-
proofCreator
|
|
127
|
-
simulator
|
|
128
|
-
protocolContractsProvider
|
|
129
|
-
config
|
|
130
|
-
loggerOrSuffix
|
|
131
|
-
) {
|
|
173
|
+
public static async create({
|
|
174
|
+
node,
|
|
175
|
+
store,
|
|
176
|
+
proofCreator,
|
|
177
|
+
simulator,
|
|
178
|
+
protocolContractsProvider,
|
|
179
|
+
config,
|
|
180
|
+
loggerOrSuffix,
|
|
181
|
+
}: PXECreateArgs) {
|
|
182
|
+
// Extract bindings from the logger, or use empty bindings if a string suffix is provided.
|
|
183
|
+
const bindings: LoggerBindings | undefined =
|
|
184
|
+
loggerOrSuffix && typeof loggerOrSuffix !== 'string' ? loggerOrSuffix.getBindings() : undefined;
|
|
185
|
+
|
|
132
186
|
const log =
|
|
133
187
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
134
188
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
@@ -138,7 +192,7 @@ export class PXE {
|
|
|
138
192
|
const addressStore = new AddressStore(store);
|
|
139
193
|
const privateEventStore = new PrivateEventStore(store);
|
|
140
194
|
const contractStore = new ContractStore(store);
|
|
141
|
-
const noteStore =
|
|
195
|
+
const noteStore = new NoteStore(store);
|
|
142
196
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
143
197
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
144
198
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -146,6 +200,12 @@ export class PXE {
|
|
|
146
200
|
const capsuleStore = new CapsuleStore(store);
|
|
147
201
|
const keyStore = new KeyStore(store);
|
|
148
202
|
const tipsStore = new L2TipsKVStore(store, 'pxe');
|
|
203
|
+
const contractSyncService = new ContractSyncService(
|
|
204
|
+
node,
|
|
205
|
+
contractStore,
|
|
206
|
+
noteStore,
|
|
207
|
+
createLogger('pxe:contract_sync', bindings),
|
|
208
|
+
);
|
|
149
209
|
const synchronizer = new BlockSynchronizer(
|
|
150
210
|
node,
|
|
151
211
|
store,
|
|
@@ -153,14 +213,22 @@ export class PXE {
|
|
|
153
213
|
noteStore,
|
|
154
214
|
privateEventStore,
|
|
155
215
|
tipsStore,
|
|
216
|
+
contractSyncService,
|
|
156
217
|
config,
|
|
157
|
-
|
|
218
|
+
bindings,
|
|
158
219
|
);
|
|
159
220
|
|
|
160
|
-
const jobCoordinator = new JobCoordinator(store);
|
|
161
|
-
jobCoordinator.registerStores([
|
|
221
|
+
const jobCoordinator = new JobCoordinator(store, bindings);
|
|
222
|
+
jobCoordinator.registerStores([
|
|
223
|
+
capsuleStore,
|
|
224
|
+
senderTaggingStore,
|
|
225
|
+
recipientTaggingStore,
|
|
226
|
+
privateEventStore,
|
|
227
|
+
noteStore,
|
|
228
|
+
contractSyncService,
|
|
229
|
+
]);
|
|
162
230
|
|
|
163
|
-
const debugUtils = new PXEDebugUtils(
|
|
231
|
+
const debugUtils = new PXEDebugUtils(contractSyncService, noteStore, synchronizer, anchorBlockStore);
|
|
164
232
|
|
|
165
233
|
const jobQueue = new SerialQueue();
|
|
166
234
|
|
|
@@ -177,6 +245,7 @@ export class PXE {
|
|
|
177
245
|
recipientTaggingStore,
|
|
178
246
|
addressStore,
|
|
179
247
|
privateEventStore,
|
|
248
|
+
contractSyncService,
|
|
180
249
|
simulator,
|
|
181
250
|
proverEnabled,
|
|
182
251
|
proofCreator,
|
|
@@ -187,7 +256,11 @@ export class PXE {
|
|
|
187
256
|
debugUtils,
|
|
188
257
|
);
|
|
189
258
|
|
|
190
|
-
debugUtils.
|
|
259
|
+
debugUtils.setPXEHelpers(
|
|
260
|
+
pxe.#putInJobQueue.bind(pxe),
|
|
261
|
+
pxe.#getSimulatorForTx.bind(pxe),
|
|
262
|
+
pxe.#simulateUtility.bind(pxe),
|
|
263
|
+
);
|
|
191
264
|
|
|
192
265
|
pxe.jobQueue.start();
|
|
193
266
|
|
|
@@ -202,20 +275,20 @@ export class PXE {
|
|
|
202
275
|
#getSimulatorForTx(overrides?: { contracts?: ContractOverrides }) {
|
|
203
276
|
const proxyContractStore = ProxiedContractStoreFactory.create(this.contractStore, overrides?.contracts);
|
|
204
277
|
|
|
205
|
-
return new ContractFunctionSimulator(
|
|
206
|
-
proxyContractStore,
|
|
207
|
-
this.noteStore,
|
|
208
|
-
this.keyStore,
|
|
209
|
-
this.addressStore,
|
|
210
|
-
BenchmarkedNodeFactory.create(this.node),
|
|
211
|
-
this.
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
);
|
|
278
|
+
return new ContractFunctionSimulator({
|
|
279
|
+
contractStore: proxyContractStore,
|
|
280
|
+
noteStore: this.noteStore,
|
|
281
|
+
keyStore: this.keyStore,
|
|
282
|
+
addressStore: this.addressStore,
|
|
283
|
+
aztecNode: BenchmarkedNodeFactory.create(this.node),
|
|
284
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
285
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
286
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
287
|
+
capsuleStore: this.capsuleStore,
|
|
288
|
+
privateEventStore: this.privateEventStore,
|
|
289
|
+
simulator: this.simulator,
|
|
290
|
+
contractSyncService: this.contractSyncService,
|
|
291
|
+
});
|
|
219
292
|
}
|
|
220
293
|
|
|
221
294
|
#contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -289,18 +362,21 @@ export class PXE {
|
|
|
289
362
|
try {
|
|
290
363
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
291
364
|
|
|
292
|
-
|
|
293
|
-
txRequest,
|
|
365
|
+
await this.contractSyncService.ensureContractSynced(
|
|
294
366
|
contractAddress,
|
|
295
367
|
functionSelector,
|
|
296
|
-
undefined,
|
|
368
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
297
369
|
anchorBlockHeader,
|
|
298
|
-
// The sender for tags is set by contracts, typically by an account
|
|
299
|
-
// contract entrypoint
|
|
300
|
-
undefined, // senderForTags
|
|
301
|
-
scopes,
|
|
302
370
|
jobId,
|
|
303
371
|
);
|
|
372
|
+
|
|
373
|
+
const result = await contractFunctionSimulator.run(txRequest, {
|
|
374
|
+
contractAddress,
|
|
375
|
+
selector: functionSelector,
|
|
376
|
+
anchorBlockHeader,
|
|
377
|
+
scopes,
|
|
378
|
+
jobId,
|
|
379
|
+
});
|
|
304
380
|
this.log.debug(`Private simulation completed for ${contractAddress.toString()}:${functionSelector}`);
|
|
305
381
|
return result;
|
|
306
382
|
} catch (err) {
|
|
@@ -384,15 +460,33 @@ export class PXE {
|
|
|
384
460
|
config: PrivateKernelExecutionProverConfig,
|
|
385
461
|
): Promise<PrivateKernelExecutionProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
386
462
|
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
387
|
-
const anchorBlockHash =
|
|
463
|
+
const anchorBlockHash = await anchorBlockHeader.hash();
|
|
388
464
|
const kernelOracle = new PrivateKernelOracle(this.contractStore, this.keyStore, this.node, anchorBlockHash);
|
|
389
|
-
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
465
|
+
const kernelTraceProver = new PrivateKernelExecutionProver(
|
|
466
|
+
kernelOracle,
|
|
467
|
+
proofCreator,
|
|
468
|
+
!this.proverEnabled,
|
|
469
|
+
this.log.getBindings(),
|
|
470
|
+
);
|
|
390
471
|
this.log.debug(`Executing kernel trace prover (${JSON.stringify(config)})...`);
|
|
391
472
|
return await kernelTraceProver.proveWithKernels(txExecutionRequest.toTxRequest(), privateExecutionResult, config);
|
|
392
473
|
}
|
|
393
474
|
|
|
394
475
|
// Public API
|
|
395
476
|
|
|
477
|
+
/**
|
|
478
|
+
* Returns the block header up to which the PXE has synced.
|
|
479
|
+
* @returns The synced block header
|
|
480
|
+
*/
|
|
481
|
+
public getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
482
|
+
return this.anchorBlockStore.getBlockHeader();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Returns the contract instance for a given address, if it's registered in the PXE.
|
|
487
|
+
* @param address - The contract address.
|
|
488
|
+
* @returns The contract instance if found, undefined otherwise.
|
|
489
|
+
*/
|
|
396
490
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
397
491
|
return this.contractStore.getContractInstance(address);
|
|
398
492
|
}
|
|
@@ -428,7 +522,6 @@ export class PXE {
|
|
|
428
522
|
}
|
|
429
523
|
|
|
430
524
|
await this.addressStore.addCompleteAddress(accountCompleteAddress);
|
|
431
|
-
await this.noteStore.addScope(accountCompleteAddress.address);
|
|
432
525
|
return accountCompleteAddress;
|
|
433
526
|
}
|
|
434
527
|
|
|
@@ -686,17 +779,13 @@ export class PXE {
|
|
|
686
779
|
|
|
687
780
|
/**
|
|
688
781
|
* Profiles a transaction, reporting gate counts (unless disabled) and returns an execution trace.
|
|
689
|
-
*
|
|
690
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
691
|
-
* @param msgSender - (Optional) The message sender to use for the simulation.
|
|
692
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
782
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
693
783
|
* @returns A trace of the program execution with gate counts.
|
|
694
784
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
695
785
|
*/
|
|
696
786
|
public profileTx(
|
|
697
787
|
txRequest: TxExecutionRequest,
|
|
698
|
-
profileMode
|
|
699
|
-
skipProofGeneration: boolean = true,
|
|
788
|
+
{ profileMode, skipProofGeneration = true }: ProfileTxOpts,
|
|
700
789
|
): Promise<TxProfileResult> {
|
|
701
790
|
// We disable concurrent profiles for consistency with simulateTx.
|
|
702
791
|
return this.#putInJobQueue(async jobId => {
|
|
@@ -781,12 +870,7 @@ export class PXE {
|
|
|
781
870
|
* In that case, the transaction returned is only potentially ready to be sent to the network for execution.
|
|
782
871
|
*
|
|
783
872
|
*
|
|
784
|
-
* @param txRequest - An authenticated tx request ready for simulation
|
|
785
|
-
* @param simulatePublic - Whether to simulate the public part of the transaction.
|
|
786
|
-
* @param skipTxValidation - (Optional) If false, this function throws if the transaction is unable to be included in a block at the current state.
|
|
787
|
-
* @param skipFeeEnforcement - (Optional) If false, fees are enforced.
|
|
788
|
-
* @param overrides - (Optional) State overrides for the simulation, such as msgSender, contract instances and artifacts.
|
|
789
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all.
|
|
873
|
+
* @param txRequest - An authenticated tx request ready for simulation.
|
|
790
874
|
* @returns A simulated transaction result object that includes public and private return values.
|
|
791
875
|
* @throws If the code for the functions executed in this transaction have not been made available via `addContracts`.
|
|
792
876
|
* Also throws if simulatePublic is true and public simulation reverts.
|
|
@@ -795,11 +879,7 @@ export class PXE {
|
|
|
795
879
|
*/
|
|
796
880
|
public simulateTx(
|
|
797
881
|
txRequest: TxExecutionRequest,
|
|
798
|
-
simulatePublic:
|
|
799
|
-
skipTxValidation: boolean = false,
|
|
800
|
-
skipFeeEnforcement: boolean = false,
|
|
801
|
-
overrides?: SimulationOverrides,
|
|
802
|
-
scopes?: AztecAddress[],
|
|
882
|
+
{ simulatePublic, skipTxValidation = false, skipFeeEnforcement = false, overrides, scopes }: SimulateTxOpts,
|
|
803
883
|
): Promise<TxSimulationResult> {
|
|
804
884
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
805
885
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -827,7 +907,14 @@ export class PXE {
|
|
|
827
907
|
// Temporary: in case there are overrides, we have to skip the kernels or validations
|
|
828
908
|
// will fail. Consider handing control to the user/wallet on whether they want to run them
|
|
829
909
|
// or not.
|
|
830
|
-
const
|
|
910
|
+
const overriddenContracts = overrides?.contracts ? new Set(Object.keys(overrides.contracts)) : undefined;
|
|
911
|
+
const hasOverriddenContracts = overriddenContracts !== undefined && overriddenContracts.size > 0;
|
|
912
|
+
const skipKernels = hasOverriddenContracts;
|
|
913
|
+
|
|
914
|
+
// Set overridden contracts on the sync service so it knows to skip syncing them
|
|
915
|
+
if (hasOverriddenContracts) {
|
|
916
|
+
this.contractSyncService.setOverriddenContracts(jobId, overriddenContracts);
|
|
917
|
+
}
|
|
831
918
|
|
|
832
919
|
// Execution of private functions only; no proving, and no kernel logic.
|
|
833
920
|
const privateExecutionResult = await this.#executePrivate(contractFunctionSimulator, txRequest, scopes, jobId);
|
|
@@ -838,7 +925,7 @@ export class PXE {
|
|
|
838
925
|
if (skipKernels) {
|
|
839
926
|
({ publicInputs, executionSteps } = await generateSimulatedProvingResult(
|
|
840
927
|
privateExecutionResult,
|
|
841
|
-
this.contractStore,
|
|
928
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
842
929
|
));
|
|
843
930
|
} else {
|
|
844
931
|
// Kernel logic, plus proving of all private functions and kernels.
|
|
@@ -923,18 +1010,12 @@ export class PXE {
|
|
|
923
1010
|
}
|
|
924
1011
|
|
|
925
1012
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
1013
|
+
* Simulates the execution of a contract utility function.
|
|
928
1014
|
* @param call - The function call containing the function details, arguments, and target contract address.
|
|
929
|
-
* @param authwits - (Optional) The authentication witnesses required for the function call.
|
|
930
|
-
* @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will
|
|
931
|
-
* default to all.
|
|
932
|
-
* @returns The result of the utility function call, structured based on the function ABI.
|
|
933
1015
|
*/
|
|
934
1016
|
public simulateUtility(
|
|
935
1017
|
call: FunctionCall,
|
|
936
|
-
authwits
|
|
937
|
-
scopes?: AztecAddress[],
|
|
1018
|
+
{ authwits, scopes }: SimulateUtilityOpts = {},
|
|
938
1019
|
): Promise<UtilitySimulationResult> {
|
|
939
1020
|
// We disable concurrent simulations since those might execute oracles which read and write to the PXE stores (e.g.
|
|
940
1021
|
// to the capsules), and we need to prevent concurrent runs from interfering with one another (e.g. attempting to
|
|
@@ -948,8 +1029,13 @@ export class PXE {
|
|
|
948
1029
|
const functionTimer = new Timer();
|
|
949
1030
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
950
1031
|
|
|
951
|
-
await this.
|
|
952
|
-
|
|
1032
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1033
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1034
|
+
call.to,
|
|
1035
|
+
call.selector,
|
|
1036
|
+
privateSyncCall => this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1037
|
+
anchorBlockHeader,
|
|
1038
|
+
jobId,
|
|
953
1039
|
);
|
|
954
1040
|
|
|
955
1041
|
const executionResult = await this.#simulateUtility(
|
|
@@ -1008,15 +1094,18 @@ export class PXE {
|
|
|
1008
1094
|
await this.#putInJobQueue(async jobId => {
|
|
1009
1095
|
await this.blockStateSynchronizer.sync();
|
|
1010
1096
|
|
|
1011
|
-
|
|
1097
|
+
const anchorBlockHeader = await this.anchorBlockStore.getBlockHeader();
|
|
1098
|
+
anchorBlockNumber = anchorBlockHeader.getBlockNumber();
|
|
1012
1099
|
|
|
1013
1100
|
const contractFunctionSimulator = this.#getSimulatorForTx();
|
|
1014
1101
|
|
|
1015
|
-
await this.
|
|
1102
|
+
await this.contractSyncService.ensureContractSynced(
|
|
1016
1103
|
filter.contractAddress,
|
|
1017
1104
|
null,
|
|
1018
1105
|
async privateSyncCall =>
|
|
1019
1106
|
await this.#simulateUtility(contractFunctionSimulator, privateSyncCall, [], undefined, jobId),
|
|
1107
|
+
anchorBlockHeader,
|
|
1108
|
+
jobId,
|
|
1020
1109
|
);
|
|
1021
1110
|
});
|
|
1022
1111
|
|
|
@@ -43,23 +43,23 @@ export class AddressStore {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
47
|
-
const index = await this.#completeAddressIndex.getAsync(address.toString());
|
|
48
|
-
if (index === undefined) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const value = await this.#completeAddresses.atAsync(index);
|
|
53
|
-
return value ? await CompleteAddress.fromBuffer(value) : undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
57
|
-
return this.#
|
|
47
|
+
return this.#store.transactionAsync(async () => {
|
|
48
|
+
const index = await this.#completeAddressIndex.getAsync(account.toString());
|
|
49
|
+
if (index === undefined) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const value = await this.#completeAddresses.atAsync(index);
|
|
54
|
+
return value ? await CompleteAddress.fromBuffer(value) : undefined;
|
|
55
|
+
});
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
getCompleteAddresses(): Promise<CompleteAddress[]> {
|
|
59
|
+
return this.#store.transactionAsync(async () => {
|
|
60
|
+
return await Promise.all(
|
|
61
|
+
(await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -10,6 +10,14 @@ export class AnchorBlockStore {
|
|
|
10
10
|
this.#synchronizedHeader = this.#store.openSingleton('header');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Sets the currently synchronized block
|
|
15
|
+
*
|
|
16
|
+
* Important: this method is only called from BlockSynchronizer, and since we need it to run atomically with other
|
|
17
|
+
* stores in the case of a reorg, it MUST NOT be wrapped in a `transactionAsync` call. Doing so would result in a
|
|
18
|
+
* deadlock when the backend is IndexedDB, because `transactionAsync` is not designed to support reentrancy.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
13
21
|
async setHeader(header: BlockHeader): Promise<void> {
|
|
14
22
|
await this.#synchronizedHeader.set(header.toBuffer());
|
|
15
23
|
}
|
|
@@ -57,14 +57,14 @@ export class CapsuleStore implements StagedStore {
|
|
|
57
57
|
*/
|
|
58
58
|
async #getFromStage(jobId: string, dbSlotKey: string): Promise<Buffer | null | undefined> {
|
|
59
59
|
const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return staged;
|
|
60
|
+
const staged: Buffer | null | undefined = jobStagedCapsules.get(dbSlotKey);
|
|
61
|
+
|
|
62
|
+
// Always issue DB read to keep IndexedDB transaction alive, even if the value is in the job staged data. This
|
|
63
|
+
// keeps IndexedDB transactions alive (they auto-commit when a new micro-task starts and there are no pending read
|
|
64
|
+
// requests). The staged value still takes precedence if it exists (including null for deletions).
|
|
65
|
+
const dbValue = await this.#loadCapsuleFromDb(dbSlotKey);
|
|
66
|
+
|
|
67
|
+
return staged !== undefined ? staged : dbValue;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|