@aztec/pxe 0.77.0 → 0.78.0
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/index.js +1 -1
- package/dest/config/index.d.ts +1 -0
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -0
- package/dest/entrypoints/client/bundle/index.d.ts +6 -0
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/index.js +5 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +16 -0
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/utils.js +30 -0
- package/dest/entrypoints/client/lazy/index.d.ts +6 -0
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -0
- package/dest/entrypoints/client/lazy/index.js +5 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +15 -0
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -0
- package/dest/entrypoints/client/lazy/utils.js +29 -0
- package/dest/entrypoints/client/pxe_creation_options.d.ts +11 -0
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +7 -0
- package/dest/entrypoints/server/index.d.ts.map +1 -0
- package/dest/entrypoints/server/index.js +6 -0
- package/dest/{utils/create_pxe_service.d.ts → entrypoints/server/utils.d.ts} +4 -4
- package/dest/entrypoints/server/utils.d.ts.map +1 -0
- package/dest/{utils/create_pxe_service.js → entrypoints/server/utils.js} +5 -11
- package/dest/kernel_oracle/index.d.ts +2 -1
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +0 -24
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +2 -2
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +1 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +3 -3
- package/dest/{pxe_data_provider → pxe_oracle_interface}/index.d.ts +17 -9
- package/dest/pxe_oracle_interface/index.d.ts.map +1 -0
- package/dest/{pxe_data_provider → pxe_oracle_interface}/index.js +104 -61
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +1 -0
- package/dest/pxe_service/error_enriching.d.ts +3 -4
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +4 -4
- package/dest/pxe_service/pxe_service.d.ts +18 -14
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +118 -65
- package/dest/storage/address_data_provider/address_data_provider.d.ts +13 -0
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -0
- package/dest/storage/address_data_provider/address_data_provider.js +50 -0
- package/dest/storage/address_data_provider/index.d.ts +2 -0
- package/dest/storage/address_data_provider/index.d.ts.map +1 -0
- package/dest/storage/address_data_provider/index.js +1 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +11 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +1 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +20 -0
- package/dest/storage/auth_witness_data_provider/index.d.ts +2 -0
- package/dest/storage/auth_witness_data_provider/index.d.ts.map +1 -0
- package/dest/storage/auth_witness_data_provider/index.js +1 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +16 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +57 -0
- package/dest/storage/capsule_data_provider/index.d.ts +2 -0
- package/dest/storage/capsule_data_provider/index.d.ts.map +1 -0
- package/dest/storage/capsule_data_provider/index.js +1 -0
- package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.d.ts +38 -33
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -0
- package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.js +87 -42
- package/dest/storage/contract_data_provider/index.d.ts.map +1 -0
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -0
- package/dest/storage/data_provider.d.ts +4 -0
- package/dest/storage/data_provider.d.ts.map +1 -0
- package/dest/storage/data_provider.js +1 -0
- package/dest/storage/index.d.ts +10 -0
- package/dest/storage/index.d.ts.map +1 -0
- package/dest/storage/index.js +9 -0
- package/dest/storage/note_data_provider/index.d.ts +3 -0
- package/dest/storage/note_data_provider/index.d.ts.map +1 -0
- package/dest/storage/note_data_provider/index.js +2 -0
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -0
- package/dest/storage/note_data_provider/note_data_provider.d.ts +20 -0
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -0
- package/dest/storage/note_data_provider/note_data_provider.js +249 -0
- package/dest/storage/sync_data_provider/index.d.ts +2 -0
- package/dest/storage/sync_data_provider/index.d.ts.map +1 -0
- package/dest/storage/sync_data_provider/index.js +1 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +12 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -0
- package/dest/storage/sync_data_provider/sync_data_provider.js +29 -0
- package/dest/storage/tagging_data_provider/index.d.ts +2 -0
- package/dest/storage/tagging_data_provider/index.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/index.js +1 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +18 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +65 -0
- package/dest/synchronizer/synchronizer.d.ts +7 -3
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +16 -11
- package/dest/test/pxe_test_suite.d.ts.map +1 -0
- package/dest/{pxe_service/test → test}/pxe_test_suite.js +2 -6
- package/package.json +19 -26
- package/src/bin/index.ts +1 -1
- package/src/config/index.ts +2 -0
- package/src/entrypoints/client/bundle/index.ts +5 -0
- package/src/entrypoints/client/bundle/utils.ts +58 -0
- package/src/entrypoints/client/lazy/index.ts +5 -0
- package/src/entrypoints/client/lazy/utils.ts +53 -0
- package/src/entrypoints/client/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +6 -0
- package/src/{utils/create_pxe_service.ts → entrypoints/server/utils.ts} +7 -18
- package/src/kernel_oracle/index.ts +1 -1
- package/src/kernel_prover/kernel_prover.ts +0 -46
- package/src/note_decryption_utils/add_public_values_to_payload.ts +4 -4
- package/src/{pxe_data_provider → pxe_oracle_interface}/index.ts +128 -96
- package/src/pxe_service/error_enriching.ts +8 -6
- package/src/pxe_service/pxe_service.ts +155 -89
- package/src/storage/address_data_provider/address_data_provider.ts +71 -0
- package/src/storage/address_data_provider/index.ts +1 -0
- package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +34 -0
- package/src/storage/auth_witness_data_provider/index.ts +1 -0
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +80 -0
- package/src/storage/capsule_data_provider/index.ts +1 -0
- package/src/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.ts +128 -48
- package/src/storage/data_provider.ts +3 -0
- package/src/storage/index.ts +10 -0
- package/src/storage/note_data_provider/index.ts +2 -0
- package/src/storage/note_data_provider/note_data_provider.ts +345 -0
- package/src/storage/sync_data_provider/index.ts +1 -0
- package/src/storage/sync_data_provider/sync_data_provider.ts +40 -0
- package/src/storage/tagging_data_provider/index.ts +1 -0
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +92 -0
- package/src/synchronizer/synchronizer.ts +15 -10
- package/src/{pxe_service/test → test}/pxe_test_suite.ts +2 -9
- package/dest/contract_data_provider/contract_data_provider.d.ts.map +0 -1
- package/dest/contract_data_provider/index.d.ts.map +0 -1
- package/dest/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/database/index.d.ts +0 -3
- package/dest/database/index.d.ts.map +0 -1
- package/dest/database/index.js +0 -2
- package/dest/database/interfaces/contract_artifact_db.d.ts +0 -20
- package/dest/database/interfaces/contract_artifact_db.d.ts.map +0 -1
- package/dest/database/interfaces/contract_artifact_db.js +0 -3
- package/dest/database/interfaces/contract_instance_db.d.ts +0 -20
- package/dest/database/interfaces/contract_instance_db.d.ts.map +0 -1
- package/dest/database/interfaces/contract_instance_db.js +0 -3
- package/dest/database/interfaces/index.d.ts +0 -4
- package/dest/database/interfaces/index.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database.d.ts +0 -211
- package/dest/database/interfaces/pxe_database.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database.js +0 -4
- package/dest/database/interfaces/pxe_database_test_suite.d.ts +0 -7
- package/dest/database/interfaces/pxe_database_test_suite.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database_test_suite.js +0 -557
- package/dest/database/kv_pxe_database.d.ts +0 -58
- package/dest/database/kv_pxe_database.d.ts.map +0 -1
- package/dest/database/kv_pxe_database.js +0 -480
- package/dest/database/note_dao.d.ts.map +0 -1
- package/dest/index.d.ts +0 -9
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -8
- package/dest/pxe_data_provider/index.d.ts.map +0 -1
- package/dest/pxe_data_provider/tagging_utils.d.ts.map +0 -1
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +0 -1
- package/dest/utils/create_pxe_service.d.ts.map +0 -1
- package/src/database/index.ts +0 -2
- package/src/database/interfaces/contract_artifact_db.ts +0 -20
- package/src/database/interfaces/contract_instance_db.ts +0 -21
- package/src/database/interfaces/index.ts +0 -3
- package/src/database/interfaces/pxe_database.ts +0 -240
- package/src/database/interfaces/pxe_database_test_suite.ts +0 -558
- package/src/database/kv_pxe_database.ts +0 -670
- package/src/index.ts +0 -9
- /package/dest/{database/interfaces/index.js → entrypoints/client/pxe_creation_options.js} +0 -0
- /package/dest/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.d.ts +0 -0
- /package/dest/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.js +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/index.d.ts +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/index.js +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.d.ts +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.js +0 -0
- /package/dest/{database → storage/note_data_provider}/note_dao.d.ts +0 -0
- /package/dest/{database → storage/note_data_provider}/note_dao.js +0 -0
- /package/dest/{pxe_service/test → test}/pxe_test_suite.d.ts +0 -0
- /package/src/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.ts +0 -0
- /package/src/{contract_data_provider → storage/contract_data_provider}/index.ts +0 -0
- /package/src/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.ts +0 -0
- /package/src/{database → storage/note_data_provider}/note_dao.ts +0 -0
|
@@ -3,8 +3,9 @@ import { Fr, type Point } from '@aztec/foundation/fields';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
5
|
import type { SiblingPath } from '@aztec/foundation/trees';
|
|
6
|
-
import
|
|
7
|
-
import type {
|
|
6
|
+
import { KeyStore } from '@aztec/key-store';
|
|
7
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
8
|
+
import { L2TipsStore } from '@aztec/kv-store/stores';
|
|
8
9
|
import {
|
|
9
10
|
ProtocolContractAddress,
|
|
10
11
|
type ProtocolContractsProvider,
|
|
@@ -24,12 +25,12 @@ import {
|
|
|
24
25
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
26
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
27
|
import type { InBlock, L2Block } from '@aztec/stdlib/block';
|
|
27
|
-
import
|
|
28
|
+
import {
|
|
28
29
|
CompleteAddress,
|
|
29
|
-
ContractClassWithId,
|
|
30
|
-
ContractInstanceWithAddress,
|
|
31
|
-
NodeInfo,
|
|
32
|
-
PartialAddress,
|
|
30
|
+
type ContractClassWithId,
|
|
31
|
+
type ContractInstanceWithAddress,
|
|
32
|
+
type NodeInfo,
|
|
33
|
+
type PartialAddress,
|
|
33
34
|
} from '@aztec/stdlib/contract';
|
|
34
35
|
import { computeContractAddressFromInstance, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
35
36
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
@@ -50,6 +51,7 @@ import { computeAddressSecret } from '@aztec/stdlib/keys';
|
|
|
50
51
|
import type { LogFilter } from '@aztec/stdlib/logs';
|
|
51
52
|
import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
|
|
52
53
|
import { type NotesFilter, UniqueNote } from '@aztec/stdlib/note';
|
|
54
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
53
55
|
import {
|
|
54
56
|
PrivateExecutionResult,
|
|
55
57
|
PrivateSimulationResult,
|
|
@@ -67,11 +69,16 @@ import { inspect } from 'util';
|
|
|
67
69
|
|
|
68
70
|
import type { PXEServiceConfig } from '../config/index.js';
|
|
69
71
|
import { getPackageInfo } from '../config/package_info.js';
|
|
70
|
-
import { ContractDataProvider } from '../contract_data_provider/index.js';
|
|
71
|
-
import type { PxeDatabase } from '../database/index.js';
|
|
72
72
|
import { KernelOracle } from '../kernel_oracle/index.js';
|
|
73
73
|
import { KernelProver, type ProvingConfig } from '../kernel_prover/kernel_prover.js';
|
|
74
|
-
import {
|
|
74
|
+
import { PXEOracleInterface } from '../pxe_oracle_interface/index.js';
|
|
75
|
+
import { AddressDataProvider } from '../storage/address_data_provider/address_data_provider.js';
|
|
76
|
+
import { AuthWitnessDataProvider } from '../storage/auth_witness_data_provider/auth_witness_data_provider.js';
|
|
77
|
+
import { CapsuleDataProvider } from '../storage/capsule_data_provider/capsule_data_provider.js';
|
|
78
|
+
import { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
79
|
+
import { NoteDataProvider } from '../storage/note_data_provider/note_data_provider.js';
|
|
80
|
+
import { SyncDataProvider } from '../storage/sync_data_provider/sync_data_provider.js';
|
|
81
|
+
import { TaggingDataProvider } from '../storage/tagging_data_provider/tagging_data_provider.js';
|
|
75
82
|
import { Synchronizer } from '../synchronizer/index.js';
|
|
76
83
|
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
|
|
77
84
|
|
|
@@ -79,53 +86,102 @@ import { enrichPublicSimulationError, enrichSimulationError } from './error_enri
|
|
|
79
86
|
* A Private eXecution Environment (PXE) implementation.
|
|
80
87
|
*/
|
|
81
88
|
export class PXEService implements PXE {
|
|
82
|
-
private
|
|
83
|
-
private contractDataProvider: ContractDataProvider;
|
|
84
|
-
private pxeDataProvider: PXEDataProvider;
|
|
85
|
-
private simulator: AcirSimulator;
|
|
86
|
-
private log: Logger;
|
|
87
|
-
private packageVersion: string;
|
|
88
|
-
private proverEnabled: boolean;
|
|
89
|
-
|
|
90
|
-
constructor(
|
|
91
|
-
private keyStore: KeyStore,
|
|
89
|
+
private constructor(
|
|
92
90
|
private node: AztecNode,
|
|
93
|
-
private
|
|
94
|
-
|
|
91
|
+
private synchronizer: Synchronizer,
|
|
92
|
+
private keyStore: KeyStore,
|
|
93
|
+
private contractDataProvider: ContractDataProvider,
|
|
94
|
+
private noteDataProvider: NoteDataProvider,
|
|
95
|
+
private capsuleDataProvider: CapsuleDataProvider,
|
|
96
|
+
private syncDataProvider: SyncDataProvider,
|
|
97
|
+
private taggingDataProvider: TaggingDataProvider,
|
|
98
|
+
private addressDataProvider: AddressDataProvider,
|
|
99
|
+
private authWitnessDataProvider: AuthWitnessDataProvider,
|
|
100
|
+
private simulator: AcirSimulator,
|
|
101
|
+
private packageVersion: string,
|
|
102
|
+
private proverEnabled: boolean,
|
|
95
103
|
private proofCreator: PrivateKernelProver,
|
|
96
|
-
simulationProvider: SimulationProvider,
|
|
97
104
|
private protocolContractsProvider: ProtocolContractsProvider,
|
|
105
|
+
private log: Logger,
|
|
106
|
+
) {}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates an instance of a PXE Service by instantiating all the necessary data providers and services.
|
|
110
|
+
* Also triggers the registration of the protocol contracts and makes sure the provided node
|
|
111
|
+
* can be contacted.
|
|
112
|
+
*
|
|
113
|
+
* @returns A promise that resolves PXE service is ready to be used.
|
|
114
|
+
*/
|
|
115
|
+
public static async create(
|
|
116
|
+
node: AztecNode,
|
|
117
|
+
store: AztecAsyncKVStore,
|
|
118
|
+
proofCreator: PrivateKernelProver,
|
|
119
|
+
simulationProvider: SimulationProvider,
|
|
120
|
+
protocolContractsProvider: ProtocolContractsProvider,
|
|
98
121
|
config: PXEServiceConfig,
|
|
99
122
|
loggerOrSuffix?: string | Logger,
|
|
100
123
|
) {
|
|
101
|
-
|
|
124
|
+
const log =
|
|
102
125
|
!loggerOrSuffix || typeof loggerOrSuffix === 'string'
|
|
103
126
|
? createLogger(loggerOrSuffix ? `pxe:service:${loggerOrSuffix}` : `pxe:service`)
|
|
104
127
|
: loggerOrSuffix;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
|
|
129
|
+
const packageVersion = getPackageInfo().version;
|
|
130
|
+
const proverEnabled = !!config.proverEnabled;
|
|
131
|
+
const addressDataProvider = new AddressDataProvider(store);
|
|
132
|
+
const authWitnessDataProvider = new AuthWitnessDataProvider(store);
|
|
133
|
+
const contractDataProvider = new ContractDataProvider(store);
|
|
134
|
+
const noteDataProvider = await NoteDataProvider.create(store);
|
|
135
|
+
const syncDataProvider = new SyncDataProvider(store);
|
|
136
|
+
const taggingDataProvider = new TaggingDataProvider(store);
|
|
137
|
+
const capsuleDataProvider = new CapsuleDataProvider(store);
|
|
138
|
+
const keyStore = new KeyStore(store);
|
|
139
|
+
const tipsStore = new L2TipsStore(store, 'pxe');
|
|
140
|
+
const synchronizer = new Synchronizer(
|
|
110
141
|
node,
|
|
142
|
+
syncDataProvider,
|
|
143
|
+
noteDataProvider,
|
|
144
|
+
taggingDataProvider,
|
|
145
|
+
tipsStore,
|
|
146
|
+
config,
|
|
147
|
+
loggerOrSuffix,
|
|
148
|
+
);
|
|
149
|
+
const pxeOracleInterface = new PXEOracleInterface(
|
|
150
|
+
node,
|
|
151
|
+
keyStore,
|
|
111
152
|
simulationProvider,
|
|
112
|
-
|
|
113
|
-
|
|
153
|
+
contractDataProvider,
|
|
154
|
+
noteDataProvider,
|
|
155
|
+
capsuleDataProvider,
|
|
156
|
+
syncDataProvider,
|
|
157
|
+
taggingDataProvider,
|
|
158
|
+
addressDataProvider,
|
|
159
|
+
authWitnessDataProvider,
|
|
160
|
+
log,
|
|
114
161
|
);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
162
|
+
const simulator = new AcirSimulator(pxeOracleInterface, simulationProvider);
|
|
163
|
+
const pxeService = new PXEService(
|
|
164
|
+
node,
|
|
165
|
+
synchronizer,
|
|
166
|
+
keyStore,
|
|
167
|
+
contractDataProvider,
|
|
168
|
+
noteDataProvider,
|
|
169
|
+
capsuleDataProvider,
|
|
170
|
+
syncDataProvider,
|
|
171
|
+
taggingDataProvider,
|
|
172
|
+
addressDataProvider,
|
|
173
|
+
authWitnessDataProvider,
|
|
174
|
+
simulator,
|
|
175
|
+
packageVersion,
|
|
176
|
+
proverEnabled,
|
|
177
|
+
proofCreator,
|
|
178
|
+
protocolContractsProvider,
|
|
179
|
+
log,
|
|
180
|
+
);
|
|
181
|
+
await pxeService.#registerProtocolContracts();
|
|
182
|
+
const info = await pxeService.getNodeInfo();
|
|
183
|
+
log.info(`Started PXE connected to chain ${info.l1ChainId} version ${info.protocolVersion}`);
|
|
184
|
+
return pxeService;
|
|
129
185
|
}
|
|
130
186
|
|
|
131
187
|
isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
@@ -133,24 +189,34 @@ export class PXEService implements PXE {
|
|
|
133
189
|
}
|
|
134
190
|
|
|
135
191
|
/** Returns an estimate of the db size in bytes. */
|
|
136
|
-
public estimateDbSize() {
|
|
137
|
-
|
|
192
|
+
public async estimateDbSize() {
|
|
193
|
+
const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES;
|
|
194
|
+
const dbSizes = await Promise.all([
|
|
195
|
+
this.addressDataProvider.getSize(),
|
|
196
|
+
this.authWitnessDataProvider.getSize(),
|
|
197
|
+
this.capsuleDataProvider.getSize(),
|
|
198
|
+
this.contractDataProvider.getSize(),
|
|
199
|
+
this.noteDataProvider.getSize(),
|
|
200
|
+
this.syncDataProvider.getSize(),
|
|
201
|
+
this.taggingDataProvider.getSize(),
|
|
202
|
+
]);
|
|
203
|
+
return [...dbSizes, treeRootsSize].reduce((sum, size) => sum + size, 0);
|
|
138
204
|
}
|
|
139
205
|
|
|
140
206
|
public addAuthWitness(witness: AuthWitness) {
|
|
141
|
-
return this.
|
|
207
|
+
return this.authWitnessDataProvider.addAuthWitness(witness.requestHash, witness.witness);
|
|
142
208
|
}
|
|
143
209
|
|
|
144
210
|
public getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
145
|
-
return this.
|
|
211
|
+
return this.authWitnessDataProvider.getAuthWitness(messageHash);
|
|
146
212
|
}
|
|
147
213
|
|
|
148
214
|
public storeCapsule(contract: AztecAddress, storageSlot: Fr, capsule: Fr[]) {
|
|
149
|
-
return this.
|
|
215
|
+
return this.capsuleDataProvider.storeCapsule(contract, storageSlot, capsule);
|
|
150
216
|
}
|
|
151
217
|
|
|
152
218
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
153
|
-
return this.
|
|
219
|
+
return this.contractDataProvider.getContractInstance(address);
|
|
154
220
|
}
|
|
155
221
|
|
|
156
222
|
public async getContractClassMetadata(
|
|
@@ -161,7 +227,12 @@ export class PXEService implements PXE {
|
|
|
161
227
|
isContractClassPubliclyRegistered: boolean;
|
|
162
228
|
artifact: ContractArtifact | undefined;
|
|
163
229
|
}> {
|
|
164
|
-
|
|
230
|
+
let artifact;
|
|
231
|
+
try {
|
|
232
|
+
artifact = await this.contractDataProvider.getContractArtifact(id);
|
|
233
|
+
} catch {
|
|
234
|
+
this.log.warn(`No artifact found for contract class ${id.toString()} when looking for its metadata`);
|
|
235
|
+
}
|
|
165
236
|
|
|
166
237
|
return {
|
|
167
238
|
contractClass: artifact && (await getContractClassFromArtifact(artifact)),
|
|
@@ -175,8 +246,14 @@ export class PXEService implements PXE {
|
|
|
175
246
|
isContractInitialized: boolean;
|
|
176
247
|
isContractPubliclyDeployed: boolean;
|
|
177
248
|
}> {
|
|
249
|
+
let instance;
|
|
250
|
+
try {
|
|
251
|
+
instance = await this.contractDataProvider.getContractInstance(address);
|
|
252
|
+
} catch {
|
|
253
|
+
this.log.warn(`No instance found for contract ${address.toString()} when looking for its metadata`);
|
|
254
|
+
}
|
|
178
255
|
return {
|
|
179
|
-
contractInstance:
|
|
256
|
+
contractInstance: instance,
|
|
180
257
|
isContractInitialized: await this.#isContractInitialized(address),
|
|
181
258
|
isContractPubliclyDeployed: await this.#isContractPubliclyDeployed(address),
|
|
182
259
|
};
|
|
@@ -193,7 +270,8 @@ export class PXEService implements PXE {
|
|
|
193
270
|
this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`);
|
|
194
271
|
}
|
|
195
272
|
|
|
196
|
-
await this.
|
|
273
|
+
await this.addressDataProvider.addCompleteAddress(accountCompleteAddress);
|
|
274
|
+
await this.noteDataProvider.addScope(accountCompleteAddress.address);
|
|
197
275
|
return accountCompleteAddress;
|
|
198
276
|
}
|
|
199
277
|
|
|
@@ -204,7 +282,7 @@ export class PXEService implements PXE {
|
|
|
204
282
|
return address;
|
|
205
283
|
}
|
|
206
284
|
|
|
207
|
-
const wasAdded = await this.
|
|
285
|
+
const wasAdded = await this.taggingDataProvider.addSenderAddress(address);
|
|
208
286
|
|
|
209
287
|
if (wasAdded) {
|
|
210
288
|
this.log.info(`Added sender:\n ${address.toString()}`);
|
|
@@ -216,13 +294,13 @@ export class PXEService implements PXE {
|
|
|
216
294
|
}
|
|
217
295
|
|
|
218
296
|
public getSenders(): Promise<AztecAddress[]> {
|
|
219
|
-
const senders = this.
|
|
297
|
+
const senders = this.taggingDataProvider.getSenderAddresses();
|
|
220
298
|
|
|
221
299
|
return Promise.resolve(senders);
|
|
222
300
|
}
|
|
223
301
|
|
|
224
302
|
public async removeSender(address: AztecAddress): Promise<void> {
|
|
225
|
-
const wasRemoved = await this.
|
|
303
|
+
const wasRemoved = await this.taggingDataProvider.removeSenderAddress(address);
|
|
226
304
|
|
|
227
305
|
if (wasRemoved) {
|
|
228
306
|
this.log.info(`Removed sender:\n ${address.toString()}`);
|
|
@@ -235,7 +313,7 @@ export class PXEService implements PXE {
|
|
|
235
313
|
|
|
236
314
|
public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
|
|
237
315
|
// Get complete addresses of both the recipients and the accounts
|
|
238
|
-
const completeAddresses = await this.
|
|
316
|
+
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
239
317
|
// Filter out the addresses not corresponding to accounts
|
|
240
318
|
const accounts = await this.keyStore.getAccounts();
|
|
241
319
|
return completeAddresses.filter(completeAddress =>
|
|
@@ -245,7 +323,7 @@ export class PXEService implements PXE {
|
|
|
245
323
|
|
|
246
324
|
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
247
325
|
const { id: contractClassId } = await getContractClassFromArtifact(artifact);
|
|
248
|
-
await this.
|
|
326
|
+
await this.contractDataProvider.addContractArtifact(contractClassId, artifact);
|
|
249
327
|
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
250
328
|
}
|
|
251
329
|
|
|
@@ -266,8 +344,7 @@ export class PXEService implements PXE {
|
|
|
266
344
|
if (!computedAddress.equals(instance.address)) {
|
|
267
345
|
throw new Error('Added a contract in which the address does not match the contract instance.');
|
|
268
346
|
}
|
|
269
|
-
|
|
270
|
-
await this.db.addContractArtifact(contractClass.id, artifact);
|
|
347
|
+
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
271
348
|
|
|
272
349
|
const publicFunctionSignatures = artifact.functions
|
|
273
350
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -278,41 +355,33 @@ export class PXEService implements PXE {
|
|
|
278
355
|
await this.node.addContractClass({ ...contractClass, privateFunctions: [], unconstrainedFunctions: [] });
|
|
279
356
|
} else {
|
|
280
357
|
// Otherwise, make sure there is an artifact already registered for that class id
|
|
281
|
-
artifact = await this.
|
|
282
|
-
if (!artifact) {
|
|
283
|
-
throw new Error(
|
|
284
|
-
`Missing contract artifact for class id ${instance.currentContractClassId} for contract ${instance.address}`,
|
|
285
|
-
);
|
|
286
|
-
}
|
|
358
|
+
artifact = await this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
|
|
287
359
|
}
|
|
288
360
|
|
|
289
|
-
await this.
|
|
361
|
+
await this.contractDataProvider.addContractInstance(instance);
|
|
290
362
|
this.log.info(
|
|
291
363
|
`Added contract ${artifact.name} at ${instance.address.toString()} with class ${instance.currentContractClassId}`,
|
|
292
364
|
);
|
|
293
365
|
}
|
|
294
366
|
|
|
295
367
|
public async updateContract(contractAddress: AztecAddress, artifact: ContractArtifact): Promise<void> {
|
|
296
|
-
const currentInstance = await this.
|
|
297
|
-
if (!currentInstance) {
|
|
298
|
-
throw new Error(`Contract ${contractAddress.toString()} is not registered.`);
|
|
299
|
-
}
|
|
368
|
+
const currentInstance = await this.contractDataProvider.getContractInstance(contractAddress);
|
|
300
369
|
const contractClass = await getContractClassFromArtifact(artifact);
|
|
301
370
|
await this.synchronizer.sync();
|
|
302
371
|
|
|
303
|
-
const header = await this.
|
|
372
|
+
const header = await this.syncDataProvider.getBlockHeader();
|
|
304
373
|
|
|
305
374
|
const currentClassId = await readCurrentClassId(
|
|
306
375
|
contractAddress,
|
|
307
376
|
currentInstance,
|
|
308
|
-
this.
|
|
377
|
+
this.node,
|
|
309
378
|
header.globalVariables.blockNumber.toNumber(),
|
|
310
379
|
);
|
|
311
380
|
if (!contractClass.id.equals(currentClassId)) {
|
|
312
381
|
throw new Error('Could not update contract to a class different from the current one.');
|
|
313
382
|
}
|
|
314
383
|
|
|
315
|
-
await this.
|
|
384
|
+
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
316
385
|
|
|
317
386
|
const publicFunctionSignatures = artifact.functions
|
|
318
387
|
.filter(fn => fn.functionType === FunctionType.PUBLIC)
|
|
@@ -322,28 +391,25 @@ export class PXEService implements PXE {
|
|
|
322
391
|
// TODO(#10007): Node should get public contract class from the registration event, not from PXE registration
|
|
323
392
|
await this.node.addContractClass({ ...contractClass, privateFunctions: [], unconstrainedFunctions: [] });
|
|
324
393
|
currentInstance.currentContractClassId = contractClass.id;
|
|
325
|
-
await this.
|
|
394
|
+
await this.contractDataProvider.addContractInstance(currentInstance);
|
|
326
395
|
this.log.info(`Updated contract ${artifact.name} at ${contractAddress.toString()} to class ${contractClass.id}`);
|
|
327
396
|
}
|
|
328
397
|
|
|
329
398
|
public getContracts(): Promise<AztecAddress[]> {
|
|
330
|
-
return this.
|
|
399
|
+
return this.contractDataProvider.getContractsAddresses();
|
|
331
400
|
}
|
|
332
401
|
|
|
333
402
|
public async getPublicStorageAt(contract: AztecAddress, slot: Fr) {
|
|
334
|
-
if (!(await this.getContractInstance(contract))) {
|
|
335
|
-
throw new Error(`Contract ${contract.toString()} is not deployed`);
|
|
336
|
-
}
|
|
337
403
|
return await this.node.getPublicStorageAt('latest', contract, slot);
|
|
338
404
|
}
|
|
339
405
|
|
|
340
406
|
public async getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
|
|
341
|
-
const noteDaos = await this.
|
|
407
|
+
const noteDaos = await this.noteDataProvider.getNotes(filter);
|
|
342
408
|
|
|
343
409
|
const extendedNotes = noteDaos.map(async dao => {
|
|
344
410
|
let owner = filter.owner;
|
|
345
411
|
if (owner === undefined) {
|
|
346
|
-
const completeAddresses = await this.
|
|
412
|
+
const completeAddresses = await this.addressDataProvider.getCompleteAddresses();
|
|
347
413
|
const completeAddressIndex = (
|
|
348
414
|
await Promise.all(completeAddresses.map(completeAddresses => completeAddresses.address.toAddressPoint()))
|
|
349
415
|
).findIndex(addressPoint => addressPoint.equals(dao.addressPoint));
|
|
@@ -559,7 +625,7 @@ export class PXEService implements PXE {
|
|
|
559
625
|
}
|
|
560
626
|
|
|
561
627
|
async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
|
|
562
|
-
const contract = await this.
|
|
628
|
+
const contract = await this.contractDataProvider.getContract(to);
|
|
563
629
|
if (!contract) {
|
|
564
630
|
throw new Error(
|
|
565
631
|
`Unknown contract ${to}: add it to PXE Service by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/reference/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
|
|
@@ -622,8 +688,8 @@ export class PXEService implements PXE {
|
|
|
622
688
|
for (const name of protocolContractNames) {
|
|
623
689
|
const { address, contractClass, instance, artifact } =
|
|
624
690
|
await this.protocolContractsProvider.getProtocolContractArtifact(name);
|
|
625
|
-
await this.
|
|
626
|
-
await this.
|
|
691
|
+
await this.contractDataProvider.addContractArtifact(contractClass.id, artifact);
|
|
692
|
+
await this.contractDataProvider.addContractInstance(instance);
|
|
627
693
|
registered[name] = address.toString();
|
|
628
694
|
}
|
|
629
695
|
this.log.verbose(`Registered protocol contracts in pxe`, registered);
|
|
@@ -661,7 +727,7 @@ export class PXEService implements PXE {
|
|
|
661
727
|
return result;
|
|
662
728
|
} catch (err) {
|
|
663
729
|
if (err instanceof SimulationError) {
|
|
664
|
-
await enrichSimulationError(err, this.
|
|
730
|
+
await enrichSimulationError(err, this.contractDataProvider, this.log);
|
|
665
731
|
}
|
|
666
732
|
throw err;
|
|
667
733
|
}
|
|
@@ -687,7 +753,7 @@ export class PXEService implements PXE {
|
|
|
687
753
|
return result;
|
|
688
754
|
} catch (err) {
|
|
689
755
|
if (err instanceof SimulationError) {
|
|
690
|
-
await enrichSimulationError(err, this.
|
|
756
|
+
await enrichSimulationError(err, this.contractDataProvider, this.log);
|
|
691
757
|
}
|
|
692
758
|
throw err;
|
|
693
759
|
}
|
|
@@ -711,7 +777,7 @@ export class PXEService implements PXE {
|
|
|
711
777
|
} catch (err) {
|
|
712
778
|
if (err instanceof SimulationError) {
|
|
713
779
|
try {
|
|
714
|
-
await enrichPublicSimulationError(err, this.contractDataProvider, this.
|
|
780
|
+
await enrichPublicSimulationError(err, this.contractDataProvider, this.log);
|
|
715
781
|
} catch (enrichErr) {
|
|
716
782
|
this.log.error(`Failed to enrich public simulation error: ${enrichErr}`);
|
|
717
783
|
}
|
|
@@ -864,7 +930,7 @@ export class PXEService implements PXE {
|
|
|
864
930
|
}
|
|
865
931
|
|
|
866
932
|
async resetNoteSyncData() {
|
|
867
|
-
return await this.
|
|
933
|
+
return await this.taggingDataProvider.resetNoteSyncData();
|
|
868
934
|
}
|
|
869
935
|
|
|
870
936
|
private contextualizeError(err: Error, ...context: string[]): Error {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
2
|
+
import type { AztecAsyncArray, AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
|
|
6
|
+
import type { DataProvider } from '../data_provider.js';
|
|
7
|
+
|
|
8
|
+
export class AddressDataProvider implements DataProvider {
|
|
9
|
+
#store: AztecAsyncKVStore;
|
|
10
|
+
#completeAddresses: AztecAsyncArray<Buffer>;
|
|
11
|
+
#completeAddressIndex: AztecAsyncMap<string, number>;
|
|
12
|
+
|
|
13
|
+
constructor(store: AztecAsyncKVStore) {
|
|
14
|
+
this.#store = store;
|
|
15
|
+
|
|
16
|
+
this.#completeAddresses = this.#store.openArray('complete_addresses');
|
|
17
|
+
this.#completeAddressIndex = this.#store.openMap('complete_address_index');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
addCompleteAddress(completeAddress: CompleteAddress): Promise<boolean> {
|
|
21
|
+
return this.#store.transactionAsync(async () => {
|
|
22
|
+
// TODO readd this
|
|
23
|
+
// await this.#addScope(completeAddress.address);
|
|
24
|
+
|
|
25
|
+
const addressString = completeAddress.address.toString();
|
|
26
|
+
const buffer = completeAddress.toBuffer();
|
|
27
|
+
const existing = await this.#completeAddressIndex.getAsync(addressString);
|
|
28
|
+
if (existing === undefined) {
|
|
29
|
+
const index = await this.#completeAddresses.lengthAsync();
|
|
30
|
+
await this.#completeAddresses.push(buffer);
|
|
31
|
+
await this.#completeAddressIndex.set(addressString, index);
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
} else {
|
|
35
|
+
const existingBuffer = await this.#completeAddresses.atAsync(existing);
|
|
36
|
+
|
|
37
|
+
if (existingBuffer && Buffer.from(existingBuffer).equals(buffer)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Complete address with aztec address ${addressString} but different public key or partial key already exists in memory database`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async #getCompleteAddress(address: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
49
|
+
const index = await this.#completeAddressIndex.getAsync(address.toString());
|
|
50
|
+
if (index === undefined) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const value = await this.#completeAddresses.atAsync(index);
|
|
55
|
+
return value ? await CompleteAddress.fromBuffer(value) : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getCompleteAddress(account: AztecAddress): Promise<CompleteAddress | undefined> {
|
|
59
|
+
return this.#getCompleteAddress(account);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getCompleteAddresses(): Promise<CompleteAddress[]> {
|
|
63
|
+
return await Promise.all(
|
|
64
|
+
(await toArray(this.#completeAddresses.valuesAsync())).map(v => CompleteAddress.fromBuffer(v)),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getSize(): Promise<number> {
|
|
69
|
+
return (await this.#completeAddresses.lengthAsync()) * CompleteAddress.SIZE_IN_BYTES;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AddressDataProvider } from './address_data_provider.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
4
|
+
|
|
5
|
+
import type { DataProvider } from '../data_provider.js';
|
|
6
|
+
|
|
7
|
+
export class AuthWitnessDataProvider implements DataProvider {
|
|
8
|
+
#store: AztecAsyncKVStore;
|
|
9
|
+
#authWitnesses: AztecAsyncMap<string, Buffer[]>;
|
|
10
|
+
|
|
11
|
+
constructor(store: AztecAsyncKVStore) {
|
|
12
|
+
this.#store = store;
|
|
13
|
+
this.#authWitnesses = this.#store.openMap('auth_witnesses');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async addAuthWitness(messageHash: Fr, witness: Fr[]): Promise<void> {
|
|
17
|
+
await this.#authWitnesses.set(
|
|
18
|
+
messageHash.toString(),
|
|
19
|
+
witness.map(w => w.toBuffer()),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async getAuthWitness(messageHash: Fr): Promise<Fr[] | undefined> {
|
|
24
|
+
const witness = await this.#authWitnesses.getAsync(messageHash.toString());
|
|
25
|
+
return witness?.map(w => Fr.fromBuffer(w));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async getSize(): Promise<number> {
|
|
29
|
+
return (await toArray(this.#authWitnesses.valuesAsync())).reduce(
|
|
30
|
+
(sum, value) => sum + value.length * Fr.SIZE_IN_BYTES,
|
|
31
|
+
0,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AuthWitnessDataProvider } from './auth_witness_data_provider.js';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import { type LogFn, createDebugOnlyLogger } from '@aztec/foundation/log';
|
|
4
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import type { DataProvider } from '../data_provider.js';
|
|
8
|
+
|
|
9
|
+
export class CapsuleDataProvider implements DataProvider {
|
|
10
|
+
#store: AztecAsyncKVStore;
|
|
11
|
+
|
|
12
|
+
// Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
|
|
13
|
+
#capsules: AztecAsyncMap<string, Buffer>;
|
|
14
|
+
|
|
15
|
+
debug: LogFn;
|
|
16
|
+
|
|
17
|
+
constructor(store: AztecAsyncKVStore) {
|
|
18
|
+
this.#store = store;
|
|
19
|
+
|
|
20
|
+
this.#capsules = this.#store.openMap('capsules');
|
|
21
|
+
|
|
22
|
+
this.debug = createDebugOnlyLogger('pxe:capsule-data-provider');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async storeCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void> {
|
|
26
|
+
await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map(value => value.toBuffer())));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async loadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
|
|
30
|
+
const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
|
|
31
|
+
if (!dataBuffer) {
|
|
32
|
+
this.debug(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const capsule: Fr[] = [];
|
|
36
|
+
for (let i = 0; i < dataBuffer.length; i += Fr.SIZE_IN_BYTES) {
|
|
37
|
+
capsule.push(Fr.fromBuffer(dataBuffer.subarray(i, i + Fr.SIZE_IN_BYTES)));
|
|
38
|
+
}
|
|
39
|
+
return capsule;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async deleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void> {
|
|
43
|
+
await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async copyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void> {
|
|
47
|
+
// In order to support overlapping source and destination regions, we need to check the relative positions of source
|
|
48
|
+
// and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
|
|
49
|
+
// indexes we'll have already read those. On the contrary, if source is ahead of destination we need to use backward
|
|
50
|
+
// indexes to avoid reading elements that've been overwritten.
|
|
51
|
+
|
|
52
|
+
const indexes = Array.from(Array(numEntries).keys());
|
|
53
|
+
if (srcSlot.lt(dstSlot)) {
|
|
54
|
+
indexes.reverse();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const i of indexes) {
|
|
58
|
+
const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
|
|
59
|
+
const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
|
|
60
|
+
|
|
61
|
+
const toCopy = await this.#capsules.getAsync(currentSrcSlot);
|
|
62
|
+
if (!toCopy) {
|
|
63
|
+
throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await this.#capsules.set(currentDstSlot, toCopy);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async getSize() {
|
|
71
|
+
return (await toArray(this.#capsules.valuesAsync())).reduce(
|
|
72
|
+
(sum, value) => sum + value.length * Fr.SIZE_IN_BYTES,
|
|
73
|
+
0,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function dbSlotToKey(contractAddress: AztecAddress, slot: Fr): string {
|
|
79
|
+
return `${contractAddress.toString()}:${slot.toString()}`;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CapsuleDataProvider } from './capsule_data_provider.js';
|