@aztec/pxe 0.0.1-commit.d431d1c → 0.0.1-commit.e2b2873ed
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 +87 -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 +108 -86
- package/dest/contract_sync/contract_sync_service.d.ts +42 -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 +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 +24 -28
- 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 +68 -23
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +78 -48
- 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 +47 -50
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +278 -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 +117 -87
- 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 +122 -101
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +170 -95
- package/src/contract_sync/contract_sync_service.ts +145 -0
- package/src/contract_sync/helpers.ts +93 -0
- package/src/debug/pxe_debug_utils.ts +61 -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 +35 -28
- 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 +178 -85
- 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 +317 -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,18 +1,21 @@
|
|
|
1
|
+
import type { ARCHIVE_HEIGHT, NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
1
2
|
import type { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Aes128 } from '@aztec/foundation/crypto/aes128';
|
|
3
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { Point } from '@aztec/foundation/curves/grumpkin';
|
|
5
|
-
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
6
8
|
import type { KeyStore } from '@aztec/key-store';
|
|
7
9
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
8
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import {
|
|
11
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
10
12
|
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
11
13
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
12
14
|
import type { AztecNode } from '@aztec/stdlib/interfaces/server';
|
|
13
15
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
14
16
|
import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
15
17
|
import { deriveEcdhSharedSecret } from '@aztec/stdlib/logs';
|
|
18
|
+
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
16
19
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
17
20
|
import { MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
18
21
|
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
@@ -22,14 +25,12 @@ import { LogService } from '../../logs/log_service.js';
|
|
|
22
25
|
import { NoteService } from '../../notes/note_service.js';
|
|
23
26
|
import { ORACLE_VERSION } from '../../oracle_version.js';
|
|
24
27
|
import type { AddressStore } from '../../storage/address_store/address_store.js';
|
|
25
|
-
import type { AnchorBlockStore } from '../../storage/anchor_block_store/anchor_block_store.js';
|
|
26
28
|
import type { CapsuleStore } from '../../storage/capsule_store/capsule_store.js';
|
|
27
29
|
import type { ContractStore } from '../../storage/contract_store/contract_store.js';
|
|
28
30
|
import type { NoteStore } from '../../storage/note_store/note_store.js';
|
|
29
31
|
import type { PrivateEventStore } from '../../storage/private_event_store/private_event_store.js';
|
|
30
32
|
import type { RecipientTaggingStore } from '../../storage/tagging_store/recipient_tagging_store.js';
|
|
31
33
|
import type { SenderAddressBookStore } from '../../storage/tagging_store/sender_address_book_store.js';
|
|
32
|
-
import { TreeMembershipService } from '../../tree_membership/tree_membership_service.js';
|
|
33
34
|
import { EventValidationRequest } from '../noir-structs/event_validation_request.js';
|
|
34
35
|
import { LogRetrievalRequest } from '../noir-structs/log_retrieval_request.js';
|
|
35
36
|
import { LogRetrievalResponse } from '../noir-structs/log_retrieval_response.js';
|
|
@@ -39,6 +40,27 @@ import { pickNotes } from '../pick_notes.js';
|
|
|
39
40
|
import type { IMiscOracle, IUtilityExecutionOracle, NoteData } from './interfaces.js';
|
|
40
41
|
import { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
|
|
41
42
|
|
|
43
|
+
/** Args for UtilityExecutionOracle constructor. */
|
|
44
|
+
export type UtilityExecutionOracleArgs = {
|
|
45
|
+
contractAddress: AztecAddress;
|
|
46
|
+
/** List of transient auth witnesses to be used during this simulation */
|
|
47
|
+
authWitnesses: AuthWitness[];
|
|
48
|
+
capsules: Capsule[]; // TODO(#12425): Rename to transientCapsules
|
|
49
|
+
anchorBlockHeader: BlockHeader;
|
|
50
|
+
contractStore: ContractStore;
|
|
51
|
+
noteStore: NoteStore;
|
|
52
|
+
keyStore: KeyStore;
|
|
53
|
+
addressStore: AddressStore;
|
|
54
|
+
aztecNode: AztecNode;
|
|
55
|
+
recipientTaggingStore: RecipientTaggingStore;
|
|
56
|
+
senderAddressBookStore: SenderAddressBookStore;
|
|
57
|
+
capsuleStore: CapsuleStore;
|
|
58
|
+
privateEventStore: PrivateEventStore;
|
|
59
|
+
jobId: string;
|
|
60
|
+
log?: ReturnType<typeof createLogger>;
|
|
61
|
+
scopes?: AztecAddress[];
|
|
62
|
+
};
|
|
63
|
+
|
|
42
64
|
/**
|
|
43
65
|
* The oracle for an execution of utility contract functions.
|
|
44
66
|
*/
|
|
@@ -46,28 +68,43 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
46
68
|
isMisc = true as const;
|
|
47
69
|
isUtility = true as const;
|
|
48
70
|
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
private contractLogger: Logger | undefined;
|
|
72
|
+
|
|
73
|
+
protected readonly contractAddress: AztecAddress;
|
|
74
|
+
protected readonly authWitnesses: AuthWitness[];
|
|
75
|
+
protected readonly capsules: Capsule[];
|
|
76
|
+
protected readonly anchorBlockHeader: BlockHeader;
|
|
77
|
+
protected readonly contractStore: ContractStore;
|
|
78
|
+
protected readonly noteStore: NoteStore;
|
|
79
|
+
protected readonly keyStore: KeyStore;
|
|
80
|
+
protected readonly addressStore: AddressStore;
|
|
81
|
+
protected readonly aztecNode: AztecNode;
|
|
82
|
+
protected readonly recipientTaggingStore: RecipientTaggingStore;
|
|
83
|
+
protected readonly senderAddressBookStore: SenderAddressBookStore;
|
|
84
|
+
protected readonly capsuleStore: CapsuleStore;
|
|
85
|
+
protected readonly privateEventStore: PrivateEventStore;
|
|
86
|
+
protected readonly jobId: string;
|
|
87
|
+
protected log: ReturnType<typeof createLogger>;
|
|
88
|
+
protected readonly scopes?: AztecAddress[];
|
|
89
|
+
|
|
90
|
+
constructor(args: UtilityExecutionOracleArgs) {
|
|
91
|
+
this.contractAddress = args.contractAddress;
|
|
92
|
+
this.authWitnesses = args.authWitnesses;
|
|
93
|
+
this.capsules = args.capsules;
|
|
94
|
+
this.anchorBlockHeader = args.anchorBlockHeader;
|
|
95
|
+
this.contractStore = args.contractStore;
|
|
96
|
+
this.noteStore = args.noteStore;
|
|
97
|
+
this.keyStore = args.keyStore;
|
|
98
|
+
this.addressStore = args.addressStore;
|
|
99
|
+
this.aztecNode = args.aztecNode;
|
|
100
|
+
this.recipientTaggingStore = args.recipientTaggingStore;
|
|
101
|
+
this.senderAddressBookStore = args.senderAddressBookStore;
|
|
102
|
+
this.capsuleStore = args.capsuleStore;
|
|
103
|
+
this.privateEventStore = args.privateEventStore;
|
|
104
|
+
this.jobId = args.jobId;
|
|
105
|
+
this.log = args.log ?? createLogger('simulator:client_view_context');
|
|
106
|
+
this.scopes = args.scopes;
|
|
107
|
+
}
|
|
71
108
|
|
|
72
109
|
public utilityAssertCompatibleOracleVersion(version: number): void {
|
|
73
110
|
if (version !== ORACLE_VERSION) {
|
|
@@ -88,21 +125,54 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
88
125
|
* @param pkMHash - The master public key hash.
|
|
89
126
|
* @returns A Promise that resolves to nullifier keys.
|
|
90
127
|
* @throws If the keys are not registered in the key store.
|
|
128
|
+
* @throws If scopes are defined and the account is not in the scopes.
|
|
91
129
|
*/
|
|
92
|
-
public utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
130
|
+
public async utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest> {
|
|
131
|
+
// If scopes are defined, check that the key belongs to an account in the scopes.
|
|
132
|
+
if (this.scopes && this.scopes.length > 0) {
|
|
133
|
+
let hasAccess = false;
|
|
134
|
+
for (let i = 0; i < this.scopes.length && !hasAccess; i++) {
|
|
135
|
+
if (await this.keyStore.accountHasKey(this.scopes[i], pkMHash)) {
|
|
136
|
+
hasAccess = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!hasAccess) {
|
|
140
|
+
throw new Error(`Key validation request denied: no scoped account has a key with hash ${pkMHash.toString()}.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
93
143
|
return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress);
|
|
94
144
|
}
|
|
95
145
|
|
|
96
146
|
/**
|
|
97
|
-
* Fetches the index and sibling path of a leaf at a given block from
|
|
98
|
-
* @param
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
* @returns The index and sibling path
|
|
147
|
+
* Fetches the index and sibling path of a leaf at a given block from the note hash tree.
|
|
148
|
+
* @param anchorBlockHash - The hash of a block that contains the note hash tree root in which to find the membership
|
|
149
|
+
* witness.
|
|
150
|
+
* @param noteHash - The note hash to find in the note hash tree.
|
|
151
|
+
* @returns The membership witness containing the leaf index and sibling path
|
|
152
|
+
*/
|
|
153
|
+
public utilityGetNoteHashMembershipWitness(
|
|
154
|
+
anchorBlockHash: BlockHash,
|
|
155
|
+
noteHash: Fr,
|
|
156
|
+
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
157
|
+
return this.aztecNode.getNoteHashMembershipWitness(anchorBlockHash, noteHash);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Fetches the index and sibling path of a block hash in the archive tree.
|
|
162
|
+
*
|
|
163
|
+
* Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
|
|
164
|
+
* its block hash is appended as a new leaf to the archive tree.
|
|
165
|
+
*
|
|
166
|
+
* @param anchorBlockHash - The hash of a block that contains the archive tree root in which to find the membership
|
|
167
|
+
* witness.
|
|
168
|
+
* @param blockHash - The block hash to find in the archive tree.
|
|
169
|
+
* @returns The membership witness containing the leaf index and sibling path
|
|
102
170
|
*/
|
|
103
|
-
public
|
|
104
|
-
|
|
105
|
-
|
|
171
|
+
public utilityGetBlockHashMembershipWitness(
|
|
172
|
+
anchorBlockHash: BlockHash,
|
|
173
|
+
blockHash: BlockHash,
|
|
174
|
+
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
175
|
+
return this.aztecNode.getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
106
176
|
}
|
|
107
177
|
|
|
108
178
|
/**
|
|
@@ -111,11 +181,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
111
181
|
* @param nullifier - Nullifier we try to find witness for.
|
|
112
182
|
* @returns The nullifier membership witness (if found).
|
|
113
183
|
*/
|
|
114
|
-
public
|
|
115
|
-
blockHash:
|
|
184
|
+
public utilityGetNullifierMembershipWitness(
|
|
185
|
+
blockHash: BlockHash,
|
|
116
186
|
nullifier: Fr,
|
|
117
187
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
118
|
-
return
|
|
188
|
+
return this.aztecNode.getNullifierMembershipWitness(blockHash, nullifier);
|
|
119
189
|
}
|
|
120
190
|
|
|
121
191
|
/**
|
|
@@ -127,12 +197,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
127
197
|
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
128
198
|
* we are trying to prove non-inclusion for.
|
|
129
199
|
*/
|
|
130
|
-
public
|
|
131
|
-
blockHash:
|
|
200
|
+
public utilityGetLowNullifierMembershipWitness(
|
|
201
|
+
blockHash: BlockHash,
|
|
132
202
|
nullifier: Fr,
|
|
133
203
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
134
|
-
|
|
135
|
-
return await treeMembershipService.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
204
|
+
return this.aztecNode.getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
136
205
|
}
|
|
137
206
|
|
|
138
207
|
/**
|
|
@@ -141,12 +210,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
141
210
|
* @param leafSlot - The slot of the public data tree to get the witness for.
|
|
142
211
|
* @returns - The witness
|
|
143
212
|
*/
|
|
144
|
-
public
|
|
145
|
-
blockHash
|
|
146
|
-
leafSlot: Fr,
|
|
147
|
-
): Promise<PublicDataWitness | undefined> {
|
|
148
|
-
const treeMembershipService = new TreeMembershipService(this.aztecNode);
|
|
149
|
-
return await treeMembershipService.getPublicDataWitness(blockHash, leafSlot);
|
|
213
|
+
public utilityGetPublicDataWitness(blockHash: BlockHash, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
214
|
+
return this.aztecNode.getPublicDataWitness(blockHash, leafSlot);
|
|
150
215
|
}
|
|
151
216
|
|
|
152
217
|
/**
|
|
@@ -155,7 +220,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
155
220
|
* @returns Block extracted from a block with block number `blockNumber`.
|
|
156
221
|
*/
|
|
157
222
|
public async utilityGetBlockHeader(blockNumber: BlockNumber): Promise<BlockHeader | undefined> {
|
|
158
|
-
const anchorBlockNumber =
|
|
223
|
+
const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
|
|
159
224
|
if (blockNumber > anchorBlockNumber) {
|
|
160
225
|
throw new Error(`Block number ${blockNumber} is higher than current block ${anchorBlockNumber}`);
|
|
161
226
|
}
|
|
@@ -167,14 +232,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
167
232
|
/**
|
|
168
233
|
* Retrieve the complete address associated to a given address.
|
|
169
234
|
* @param account - The account address.
|
|
170
|
-
* @returns A complete address associated with the input address.
|
|
171
|
-
* @throws An error if the account is not registered in the database.
|
|
235
|
+
* @returns A complete address associated with the input address, or `undefined` if not registered.
|
|
172
236
|
*/
|
|
173
|
-
public
|
|
174
|
-
return this.getCompleteAddress(account);
|
|
237
|
+
public utilityTryGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
238
|
+
return this.addressStore.getCompleteAddress(account);
|
|
175
239
|
}
|
|
176
240
|
|
|
177
|
-
protected async
|
|
241
|
+
protected async getCompleteAddressOrFail(account: AztecAddress): Promise<CompleteAddress> {
|
|
178
242
|
const completeAddress = await this.addressStore.getCompleteAddress(account);
|
|
179
243
|
if (!completeAddress) {
|
|
180
244
|
throw new Error(
|
|
@@ -251,7 +315,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
251
315
|
offset: number,
|
|
252
316
|
status: NoteStatus,
|
|
253
317
|
): Promise<NoteData[]> {
|
|
254
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.
|
|
318
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
255
319
|
|
|
256
320
|
const dbNotes = await noteService.getNotes(this.contractAddress, owner, storageSlot, status, this.scopes);
|
|
257
321
|
return pickNotes<NoteData>(dbNotes, {
|
|
@@ -275,10 +339,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
275
339
|
* @returns A boolean indicating whether the nullifier exists in the tree or not.
|
|
276
340
|
*/
|
|
277
341
|
public async utilityCheckNullifierExists(innerNullifier: Fr) {
|
|
278
|
-
const nullifier = await
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
342
|
+
const [nullifier, anchorBlockHash] = await Promise.all([
|
|
343
|
+
siloNullifier(this.contractAddress, innerNullifier!),
|
|
344
|
+
this.anchorBlockHeader.hash(),
|
|
345
|
+
]);
|
|
346
|
+
const [leafIndex] = await this.aztecNode.findLeavesIndexes(anchorBlockHash, MerkleTreeId.NULLIFIER_TREE, [
|
|
347
|
+
nullifier,
|
|
348
|
+
]);
|
|
349
|
+
return leafIndex?.data !== undefined;
|
|
282
350
|
}
|
|
283
351
|
|
|
284
352
|
/**
|
|
@@ -290,14 +358,13 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
290
358
|
* @returns The l1 to l2 membership witness (index of message in the tree and sibling path).
|
|
291
359
|
*/
|
|
292
360
|
public async utilityGetL1ToL2MembershipWitness(contractAddress: AztecAddress, messageHash: Fr, secret: Fr) {
|
|
293
|
-
const
|
|
294
|
-
|
|
361
|
+
const [messageIndex, siblingPath] = await getNonNullifiedL1ToL2MessageWitness(
|
|
362
|
+
this.aztecNode,
|
|
295
363
|
contractAddress,
|
|
296
364
|
messageHash,
|
|
297
365
|
secret,
|
|
298
366
|
);
|
|
299
367
|
|
|
300
|
-
// Assuming messageIndex is what you intended to use for the index in MessageLoadOracleInputs
|
|
301
368
|
return new MessageLoadOracleInputs(messageIndex, siblingPath);
|
|
302
369
|
}
|
|
303
370
|
|
|
@@ -309,57 +376,64 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
309
376
|
* @param numberOfElements - Number of elements to read from the starting storage slot.
|
|
310
377
|
*/
|
|
311
378
|
public async utilityStorageRead(
|
|
312
|
-
blockHash:
|
|
379
|
+
blockHash: BlockHash,
|
|
313
380
|
contractAddress: AztecAddress,
|
|
314
381
|
startStorageSlot: Fr,
|
|
315
382
|
numberOfElements: number,
|
|
316
383
|
) {
|
|
317
|
-
const
|
|
384
|
+
const slots = Array(numberOfElements)
|
|
385
|
+
.fill(0)
|
|
386
|
+
.map((_, i) => new Fr(startStorageSlot.value + BigInt(i)));
|
|
318
387
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
388
|
+
const values = await Promise.all(
|
|
389
|
+
slots.map(storageSlot => this.aztecNode.getPublicStorageAt(blockHash, contractAddress, storageSlot)),
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
this.log.debug(
|
|
393
|
+
`Oracle storage read: slots=[${slots.map(slot => slot.toString()).join(', ')}] address=${contractAddress.toString()} values=[${values.join(', ')}]`,
|
|
394
|
+
);
|
|
324
395
|
|
|
325
|
-
this.log.debug(
|
|
326
|
-
`Oracle storage read: slot=${storageSlot.toString()} address-${contractAddress.toString()} value=${value}`,
|
|
327
|
-
);
|
|
328
|
-
values.push(value);
|
|
329
|
-
}
|
|
330
396
|
return values;
|
|
331
397
|
}
|
|
332
398
|
|
|
333
|
-
|
|
399
|
+
/**
|
|
400
|
+
* Returns a per-contract logger whose output is prefixed with `contract_log::<name>(<addrAbbrev>)`.
|
|
401
|
+
*/
|
|
402
|
+
async #getContractLogger(): Promise<Logger> {
|
|
403
|
+
if (!this.contractLogger) {
|
|
404
|
+
const addrAbbrev = this.contractAddress.toString().slice(0, 10);
|
|
405
|
+
const name = await this.contractStore.getDebugContractName(this.contractAddress);
|
|
406
|
+
const module = name ? `contract_log::${name}(${addrAbbrev})` : `contract_log::${addrAbbrev}`;
|
|
407
|
+
// Purpose of instanceId is to distinguish logs from different instances of the same component. It makes sense
|
|
408
|
+
// to re-use jobId as instanceId here as executions of different PXE jobs are isolated.
|
|
409
|
+
this.contractLogger = createLogger(module, { instanceId: this.jobId });
|
|
410
|
+
}
|
|
411
|
+
return this.contractLogger;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
public async utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
334
415
|
if (!LogLevels[level]) {
|
|
335
|
-
throw new Error(`Invalid
|
|
416
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
336
417
|
}
|
|
337
418
|
const levelName = LogLevels[level];
|
|
338
|
-
this
|
|
419
|
+
const logger = await this.#getContractLogger();
|
|
420
|
+
logger[levelName](`${applyStringFormatting(message, fields)}`);
|
|
339
421
|
}
|
|
340
422
|
|
|
341
423
|
public async utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
342
424
|
const logService = new LogService(
|
|
343
425
|
this.aztecNode,
|
|
344
|
-
this.
|
|
426
|
+
this.anchorBlockHeader,
|
|
345
427
|
this.keyStore,
|
|
346
428
|
this.capsuleStore,
|
|
347
429
|
this.recipientTaggingStore,
|
|
348
430
|
this.senderAddressBookStore,
|
|
349
431
|
this.addressStore,
|
|
350
432
|
this.jobId,
|
|
433
|
+
this.log.getBindings(),
|
|
351
434
|
);
|
|
352
435
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
// It is acceptable to run the following operations in parallel for several reasons:
|
|
356
|
-
// 1. syncTaggedLogs does not write to the note store — it only stores the pending tagged logs in a capsule array,
|
|
357
|
-
// which is then processed in Noir after this handler returns.
|
|
358
|
-
// 2. Even if syncTaggedLogs did write to the note store, it would not cause inconsistent state.
|
|
359
|
-
await Promise.all([
|
|
360
|
-
logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes),
|
|
361
|
-
noteService.syncNoteNullifiers(this.contractAddress),
|
|
362
|
-
]);
|
|
436
|
+
await logService.fetchTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
363
437
|
}
|
|
364
438
|
|
|
365
439
|
/**
|
|
@@ -372,7 +446,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
372
446
|
* @param noteValidationRequestsArrayBaseSlot - The base slot of capsule array containing note validation requests.
|
|
373
447
|
* @param eventValidationRequestsArrayBaseSlot - The base slot of capsule array containing event validation requests.
|
|
374
448
|
*/
|
|
375
|
-
public async
|
|
449
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
376
450
|
contractAddress: AztecAddress,
|
|
377
451
|
noteValidationRequestsArrayBaseSlot: Fr,
|
|
378
452
|
eventValidationRequestsArrayBaseSlot: Fr,
|
|
@@ -392,9 +466,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
392
466
|
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
|
|
393
467
|
).map(EventValidationRequest.fromFields);
|
|
394
468
|
|
|
395
|
-
const noteService = new NoteService(this.noteStore, this.aztecNode, this.
|
|
469
|
+
const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockHeader, this.jobId);
|
|
396
470
|
const noteStorePromises = noteValidationRequests.map(request =>
|
|
397
|
-
noteService.
|
|
471
|
+
noteService.validateAndStoreNote(
|
|
398
472
|
request.contractAddress,
|
|
399
473
|
request.owner,
|
|
400
474
|
request.storageSlot,
|
|
@@ -408,9 +482,9 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
408
482
|
),
|
|
409
483
|
);
|
|
410
484
|
|
|
411
|
-
const eventService = new EventService(this.
|
|
485
|
+
const eventService = new EventService(this.anchorBlockHeader, this.aztecNode, this.privateEventStore, this.jobId);
|
|
412
486
|
const eventStorePromises = eventValidationRequests.map(request =>
|
|
413
|
-
eventService.
|
|
487
|
+
eventService.validateAndStoreEvent(
|
|
414
488
|
request.contractAddress,
|
|
415
489
|
request.eventTypeId,
|
|
416
490
|
request.randomness,
|
|
@@ -446,13 +520,14 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
446
520
|
|
|
447
521
|
const logService = new LogService(
|
|
448
522
|
this.aztecNode,
|
|
449
|
-
this.
|
|
523
|
+
this.anchorBlockHeader,
|
|
450
524
|
this.keyStore,
|
|
451
525
|
this.capsuleStore,
|
|
452
526
|
this.recipientTaggingStore,
|
|
453
527
|
this.senderAddressBookStore,
|
|
454
528
|
this.addressStore,
|
|
455
529
|
this.jobId,
|
|
530
|
+
this.log.getBindings(),
|
|
456
531
|
);
|
|
457
532
|
|
|
458
533
|
const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);
|
|
@@ -530,7 +605,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
|
|
|
530
605
|
|
|
531
606
|
protected async getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
532
607
|
// TODO(#12656): return an app-siloed secret
|
|
533
|
-
const recipientCompleteAddress = await this.
|
|
608
|
+
const recipientCompleteAddress = await this.getCompleteAddressOrFail(address);
|
|
534
609
|
const ivskM = await this.keyStore.getMasterSecretKey(
|
|
535
610
|
recipientCompleteAddress.publicKeys.masterIncomingViewingPublicKey,
|
|
536
611
|
);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import type { StagedStore } from '../job_coordinator/job_coordinator.js';
|
|
8
|
+
import type { ContractStore } from '../storage/contract_store/contract_store.js';
|
|
9
|
+
import type { NoteStore } from '../storage/note_store/note_store.js';
|
|
10
|
+
import { syncState, verifyCurrentClassId } from './helpers.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Service for syncing the private state of contracts and verifying that the PXE holds the current class artifact.
|
|
14
|
+
* It uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
15
|
+
*
|
|
16
|
+
* TODO: The StagedStore naming is broken here. Figure out a better name.
|
|
17
|
+
*/
|
|
18
|
+
export class ContractSyncService implements StagedStore {
|
|
19
|
+
readonly storeName = 'contract_sync';
|
|
20
|
+
|
|
21
|
+
// Tracks contracts synced since last wipe. The cache is keyed per individual scope address
|
|
22
|
+
// (`contractAddress:scopeAddress`), or `contractAddress:*` for undefined scopes (all accounts).
|
|
23
|
+
// The value is a promise that resolves when the contract is synced.
|
|
24
|
+
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
25
|
+
|
|
26
|
+
// Per-job overridden contract addresses - these contracts should not be synced.
|
|
27
|
+
private overriddenContracts: Map<string, Set<string>> = new Map();
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
private aztecNode: AztecNode,
|
|
31
|
+
private contractStore: ContractStore,
|
|
32
|
+
private noteStore: NoteStore,
|
|
33
|
+
private log: Logger,
|
|
34
|
+
) {}
|
|
35
|
+
|
|
36
|
+
/** Sets contracts that should be skipped during sync for a specific job. */
|
|
37
|
+
setOverriddenContracts(jobId: string, addresses: Set<string>): void {
|
|
38
|
+
this.overriddenContracts.set(jobId, addresses);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
|
|
43
|
+
* Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
44
|
+
* @param contractAddress - The address of the contract to sync.
|
|
45
|
+
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
46
|
+
* not sync_state itself).
|
|
47
|
+
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
48
|
+
* @param scopes - Scopes to pass through to the utility executor (affects which notes are discovered).
|
|
49
|
+
*/
|
|
50
|
+
async ensureContractSynced(
|
|
51
|
+
contractAddress: AztecAddress,
|
|
52
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
53
|
+
utilityExecutor: (call: FunctionCall, scopes: undefined | AztecAddress[]) => Promise<any>,
|
|
54
|
+
anchorBlockHeader: BlockHeader,
|
|
55
|
+
jobId: string,
|
|
56
|
+
scopes: undefined | AztecAddress[],
|
|
57
|
+
): Promise<void> {
|
|
58
|
+
// Skip sync if this contract has an override for this job (overrides are keyed by contract address only)
|
|
59
|
+
const overrides = this.overriddenContracts.get(jobId);
|
|
60
|
+
if (overrides?.has(contractAddress.toString())) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Skip sync if we already synced for "all scopes", or if we have an empty list of scopes
|
|
65
|
+
const allScopesKey = toKey(contractAddress, undefined);
|
|
66
|
+
const allScopesExisting = this.syncedContracts.get(allScopesKey);
|
|
67
|
+
if (allScopesExisting || (scopes && scopes.length == 0)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const unsyncedScopes = scopes?.filter(scope => !this.syncedContracts.has(toKey(contractAddress, scope)));
|
|
72
|
+
const unsyncedScopesKeys = toKeys(contractAddress, unsyncedScopes);
|
|
73
|
+
|
|
74
|
+
if (unsyncedScopesKeys.length > 0) {
|
|
75
|
+
// Start sync and store the promise for all unsynced scopes
|
|
76
|
+
const promise = this.#doSync(
|
|
77
|
+
contractAddress,
|
|
78
|
+
functionToInvokeAfterSync,
|
|
79
|
+
call => utilityExecutor(call, unsyncedScopes),
|
|
80
|
+
anchorBlockHeader,
|
|
81
|
+
jobId,
|
|
82
|
+
).catch(err => {
|
|
83
|
+
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
84
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.delete(key));
|
|
85
|
+
throw err;
|
|
86
|
+
});
|
|
87
|
+
unsyncedScopesKeys.forEach(key => this.syncedContracts.set(key, promise));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const promises = toKeys(contractAddress, scopes).map(key => this.syncedContracts.get(key)!);
|
|
91
|
+
await Promise.all(promises);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async #doSync(
|
|
95
|
+
contractAddress: AztecAddress,
|
|
96
|
+
functionToInvokeAfterSync: FunctionSelector | null,
|
|
97
|
+
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
98
|
+
anchorBlockHeader: BlockHeader,
|
|
99
|
+
jobId: string,
|
|
100
|
+
): Promise<void> {
|
|
101
|
+
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
102
|
+
await Promise.all([
|
|
103
|
+
syncState(
|
|
104
|
+
contractAddress,
|
|
105
|
+
this.contractStore,
|
|
106
|
+
functionToInvokeAfterSync,
|
|
107
|
+
utilityExecutor,
|
|
108
|
+
this.noteStore,
|
|
109
|
+
this.aztecNode,
|
|
110
|
+
anchorBlockHeader,
|
|
111
|
+
jobId,
|
|
112
|
+
),
|
|
113
|
+
verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
114
|
+
]);
|
|
115
|
+
this.log.debug(`Contract ${contractAddress} synced`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
|
|
119
|
+
wipe(): void {
|
|
120
|
+
this.log.debug(`Wiping contract sync cache (${this.syncedContracts.size} entries)`);
|
|
121
|
+
this.syncedContracts.clear();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
commit(jobId: string): Promise<void> {
|
|
125
|
+
// Clear overridden contracts for this job
|
|
126
|
+
this.overriddenContracts.delete(jobId);
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
discardStaged(jobId: string): Promise<void> {
|
|
131
|
+
// We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
|
|
132
|
+
// the sync are also undone.
|
|
133
|
+
this.syncedContracts.clear();
|
|
134
|
+
this.overriddenContracts.delete(jobId);
|
|
135
|
+
return Promise.resolve();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function toKeys(contract: AztecAddress, scopes: undefined | AztecAddress[]) {
|
|
140
|
+
return scopes === undefined ? [toKey(contract, undefined)] : scopes.map(scope => toKey(contract, scope));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function toKey(contract: AztecAddress, scope: AztecAddress | undefined) {
|
|
144
|
+
return scope === undefined ? `${contract.toString()}:*` : `${contract.toString()}:${scope.toString()}`;
|
|
145
|
+
}
|