@aztec/pxe 0.0.1-commit.6d63667d → 0.0.1-commit.86469d5
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/block_synchronizer/block_synchronizer.d.ts +2 -4
- package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
- package/dest/block_synchronizer/block_synchronizer.js +1 -7
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +2 -4
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +2 -4
- 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 +8 -20
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -4
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +6 -6
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +5 -5
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +7 -14
- package/dest/contract_sync/index.d.ts +24 -0
- package/dest/contract_sync/index.d.ts.map +1 -0
- package/dest/contract_sync/{helpers.js → index.js} +12 -6
- package/dest/debug/pxe_debug_utils.d.ts +7 -12
- package/dest/debug/pxe_debug_utils.d.ts.map +1 -1
- package/dest/debug/pxe_debug_utils.js +12 -16
- package/dest/entrypoints/server/index.d.ts +2 -2
- package/dest/entrypoints/server/index.d.ts.map +1 -1
- package/dest/entrypoints/server/index.js +1 -1
- package/dest/oracle_version.d.ts +2 -2
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +1 -2
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +12 -23
- package/package.json +16 -25
- package/src/block_synchronizer/block_synchronizer.ts +0 -6
- package/src/contract_function_simulator/contract_function_simulator.ts +0 -3
- package/src/contract_function_simulator/oracle/interfaces.ts +1 -1
- package/src/contract_function_simulator/oracle/oracle.ts +4 -11
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +6 -5
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +7 -14
- package/src/contract_sync/{helpers.ts → index.ts} +32 -6
- package/src/debug/pxe_debug_utils.ts +13 -46
- package/src/entrypoints/server/index.ts +1 -1
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +16 -30
- package/dest/contract_sync/contract_sync_service.d.ts +0 -41
- package/dest/contract_sync/contract_sync_service.d.ts.map +0 -1
- package/dest/contract_sync/contract_sync_service.js +0 -82
- package/dest/contract_sync/helpers.d.ts +0 -28
- package/dest/contract_sync/helpers.d.ts.map +0 -1
- package/src/contract_sync/contract_sync_service.ts +0 -129
|
@@ -1,129 +0,0 @@
|
|
|
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. Key is contract address string, value is a promise that resolves when
|
|
22
|
-
// the contract is synced.
|
|
23
|
-
private syncedContracts: Map<string, Promise<void>> = new Map();
|
|
24
|
-
|
|
25
|
-
// Per-job overridden contract addresses - these contracts should not be synced.
|
|
26
|
-
private overriddenContracts: Map<string, Set<string>> = new Map();
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
private aztecNode: AztecNode,
|
|
30
|
-
private contractStore: ContractStore,
|
|
31
|
-
private noteStore: NoteStore,
|
|
32
|
-
private log: Logger,
|
|
33
|
-
) {}
|
|
34
|
-
|
|
35
|
-
/** Sets contracts that should be skipped during sync for a specific job. */
|
|
36
|
-
setOverriddenContracts(jobId: string, addresses: Set<string>): void {
|
|
37
|
-
this.overriddenContracts.set(jobId, addresses);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Ensures a contract's private state is synchronized and that the PXE holds the current class artifact.
|
|
42
|
-
* Uses a cache to avoid redundant sync operations - the cache is wiped when the anchor block changes.
|
|
43
|
-
* @param contractAddress - The address of the contract to sync.
|
|
44
|
-
* @param functionToInvokeAfterSync - The function selector that will be called after sync (used to validate it's
|
|
45
|
-
* not sync_state itself).
|
|
46
|
-
* @param utilityExecutor - Executor function for running the sync_state utility function.
|
|
47
|
-
*/
|
|
48
|
-
async ensureContractSynced(
|
|
49
|
-
contractAddress: AztecAddress,
|
|
50
|
-
functionToInvokeAfterSync: FunctionSelector | null,
|
|
51
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
52
|
-
anchorBlockHeader: BlockHeader,
|
|
53
|
-
jobId: string,
|
|
54
|
-
): Promise<void> {
|
|
55
|
-
const key = contractAddress.toString();
|
|
56
|
-
|
|
57
|
-
// Skip sync if this contract has an override for this job
|
|
58
|
-
const overrides = this.overriddenContracts.get(jobId);
|
|
59
|
-
if (overrides?.has(key)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const existing = this.syncedContracts.get(key);
|
|
64
|
-
if (existing) {
|
|
65
|
-
return existing;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const syncPromise = this.#doSync(
|
|
69
|
-
contractAddress,
|
|
70
|
-
functionToInvokeAfterSync,
|
|
71
|
-
utilityExecutor,
|
|
72
|
-
anchorBlockHeader,
|
|
73
|
-
jobId,
|
|
74
|
-
);
|
|
75
|
-
this.syncedContracts.set(key, syncPromise);
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
await syncPromise;
|
|
79
|
-
} catch (err) {
|
|
80
|
-
// There was an error syncing the contract, so we remove it from the cache so that it can be retried.
|
|
81
|
-
this.syncedContracts.delete(key);
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async #doSync(
|
|
87
|
-
contractAddress: AztecAddress,
|
|
88
|
-
functionToInvokeAfterSync: FunctionSelector | null,
|
|
89
|
-
utilityExecutor: (call: FunctionCall) => Promise<any>,
|
|
90
|
-
anchorBlockHeader: BlockHeader,
|
|
91
|
-
jobId: string,
|
|
92
|
-
): Promise<void> {
|
|
93
|
-
this.log.debug(`Syncing contract ${contractAddress}`);
|
|
94
|
-
await Promise.all([
|
|
95
|
-
syncState(
|
|
96
|
-
contractAddress,
|
|
97
|
-
this.contractStore,
|
|
98
|
-
functionToInvokeAfterSync,
|
|
99
|
-
utilityExecutor,
|
|
100
|
-
this.noteStore,
|
|
101
|
-
this.aztecNode,
|
|
102
|
-
anchorBlockHeader,
|
|
103
|
-
jobId,
|
|
104
|
-
),
|
|
105
|
-
verifyCurrentClassId(contractAddress, this.aztecNode, this.contractStore, anchorBlockHeader),
|
|
106
|
-
]);
|
|
107
|
-
this.log.debug(`Contract ${contractAddress} synced`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Clears sync cache. Called by BlockSynchronizer when anchor block changes. */
|
|
111
|
-
wipe(): void {
|
|
112
|
-
this.log.debug(`Wiping contract sync cache (${this.syncedContracts.size} entries)`);
|
|
113
|
-
this.syncedContracts.clear();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
commit(jobId: string): Promise<void> {
|
|
117
|
-
// Clear overridden contracts for this job
|
|
118
|
-
this.overriddenContracts.delete(jobId);
|
|
119
|
-
return Promise.resolve();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
discardStaged(jobId: string): Promise<void> {
|
|
123
|
-
// We clear the synced contracts cache here because, when the job is discarded, any associated database writes from
|
|
124
|
-
// the sync are also undone.
|
|
125
|
-
this.syncedContracts.clear();
|
|
126
|
-
this.overriddenContracts.delete(jobId);
|
|
127
|
-
return Promise.resolve();
|
|
128
|
-
}
|
|
129
|
-
}
|