Skip to content

Commit 3ee868c

Browse files
committed
refactor(PXE)!: move getNotes to debug submodule
I would rather not have to explain that `getNotes`, despite being a public method in PXE, is not really intended for production usage in every public facing doc about PXE we write, so I'm proposing to "conceal" it under a `debug` accessor so it looks like: `pxe.debug.getNotes()` instead of `pxe.getNotes()` A potential discussion point: moving `getFunctionCall` to `ContractDataProvider`: this function is only used as part of the "invoke contract sync" hack, currently only used by the `getNotes` and `getPrivateEvents`. So it doesn't seem to be a function with a lot of potential for reuse. The decision to move it to `ContractDataProvider` stems from trying to clean PXE a bit and make it available from the new `PXEDebugUtils` module. But I expect this to change and not be necessary once we sort out how we handle contract sync
1 parent 0046f64 commit 3ee868c

File tree

6 files changed

+94
-51
lines changed

6 files changed

+94
-51
lines changed

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Aztec is in full-speed development. Literally every version breaks compatibility
99

1010
## TBD
1111

12+
### [PXE] deprecated `getNotes`
13+
14+
This function serves only for debugging purposes so we are taking it out of the main PXE API. If you still need to consume it, you can
15+
do so through the new `debug` sub-module.
16+
17+
```diff
18+
- this.pxe.getNotes(filter);
19+
+ this.pxe.debug.getNotes(filter);
20+
```
21+
1222
### [Aztec node, archiver] Deprecated `getPrivateLogs`
1323

1424
Aztec node no longer offers a `getPrivateLogs` method. If you need to process the logs of a block, you can instead use `getBlock` and call `getPrivateLogs` on an `L2BlockNew` instance. See the diff below for before/after equivalent code samples.

yarn-project/cli-wallet/src/utils/wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,6 @@ export class CLIWallet extends BaseWallet {
261261
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
262262
// this is just a CLI wallet.
263263
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
264-
return this.pxe.getNotes(filter);
264+
return this.pxe.debug.getNotes(filter);
265265
}
266266
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
2+
3+
import type { PXE } from '../pxe.js';
4+
import type { ContractDataProvider, NoteDataProvider } from '../storage/index.js';
5+
6+
/**
7+
* Methods provided by this class might help debugging but must not be used in production.
8+
* No backwards compatibility or API stability should be expected. Use at your own risk.
9+
*/
10+
export class PXEDebugUtils {
11+
#pxe: PXE | undefined = undefined;
12+
13+
constructor(
14+
private contractDataProvider: ContractDataProvider,
15+
private noteDataProvider: NoteDataProvider,
16+
) {}
17+
18+
/**
19+
* Not injected through constructor since they're are co-dependant.
20+
*/
21+
public setPXE(pxe: PXE) {
22+
this.#pxe = pxe;
23+
}
24+
25+
/**
26+
* A debugging utility to get notes based on the provided filter.
27+
*
28+
* Note that this should not be used in production code because the structure of notes is considered to be
29+
* an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
30+
* note-related information in production code, please implement a custom utility function on your contract and call
31+
* that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
32+
*
33+
* @param filter - The filter to apply to the notes.
34+
* @returns The requested notes.
35+
*/
36+
public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
37+
if (!this.#pxe) {
38+
throw new Error('Cannot getNotes because no PXE is set');
39+
}
40+
41+
// We need to manually trigger private state sync to have a guarantee that all the notes are available.
42+
const call = await this.contractDataProvider.getFunctionCall('sync_private_state', [], filter.contractAddress);
43+
await this.#pxe.simulateUtility(call);
44+
45+
return this.noteDataProvider.getNotes(filter);
46+
}
47+
}

yarn-project/pxe/src/pxe.ts

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import {
1212
type ContractArtifact,
1313
EventSelector,
1414
FunctionCall,
15-
FunctionSelector,
1615
FunctionType,
1716
decodeFunctionSignature,
18-
encodeArguments,
1917
} from '@aztec/stdlib/abi';
2018
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
2119
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -35,8 +33,6 @@ import type {
3533
PrivateKernelExecutionProofOutput,
3634
PrivateKernelTailCircuitPublicInputs,
3735
} from '@aztec/stdlib/kernel';
38-
import type { NotesFilter } from '@aztec/stdlib/note';
39-
import { NoteDao } from '@aztec/stdlib/note';
4036
import {
4137
type ContractOverrides,
4238
type InTx,
@@ -66,6 +62,7 @@ import { readCurrentClassId } from './contract_function_simulator/oracle/private
6662
import { ProxiedContractDataProviderFactory } from './contract_function_simulator/proxied_contract_data_source.js';
6763
import { ProxiedNodeFactory } from './contract_function_simulator/proxied_node.js';
6864
import { PXEOracleInterface } from './contract_function_simulator/pxe_oracle_interface.js';
65+
import { PXEDebugUtils } from './debug/pxe_debug_utils.js';
6966
import { enrichPublicSimulationError, enrichSimulationError } from './error_enriching.js';
7067
import { PrivateEventFilterValidator } from './events/private_event_filter_validator.js';
7168
import {
@@ -108,6 +105,7 @@ export class PXE {
108105
private protocolContractsProvider: ProtocolContractsProvider,
109106
private log: Logger,
110107
private jobQueue: SerialQueue,
108+
public debug: PXEDebugUtils,
111109
) {}
112110

113111
/**
@@ -151,6 +149,8 @@ export class PXE {
151149
loggerOrSuffix,
152150
);
153151

152+
const debugUtils = new PXEDebugUtils(contractDataProvider, noteDataProvider);
153+
154154
const jobQueue = new SerialQueue();
155155

156156
const pxe = new PXE(
@@ -170,8 +170,11 @@ export class PXE {
170170
protocolContractsProvider,
171171
log,
172172
jobQueue,
173+
debugUtils,
173174
);
174175

176+
debugUtils.setPXE(pxe);
177+
175178
pxe.jobQueue.start();
176179

177180
await pxe.#registerProtocolContracts();
@@ -254,31 +257,6 @@ export class PXE {
254257
return !!(await this.node.getNullifierMembershipWitness('latest', initNullifier));
255258
}
256259

257-
async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
258-
const contract = await this.contractDataProvider.getContract(to);
259-
if (!contract) {
260-
throw new Error(
261-
`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
262-
);
263-
}
264-
265-
const functionDao = contract.functions.find(f => f.name === functionName);
266-
if (!functionDao) {
267-
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
268-
}
269-
270-
return {
271-
name: functionDao.name,
272-
args: encodeArguments(functionDao, args),
273-
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
274-
type: functionDao.functionType,
275-
to,
276-
hideMsgSender: false,
277-
isStatic: functionDao.isStatic,
278-
returnTypes: functionDao.returnTypes,
279-
};
280-
}
281-
282260
// Executes the entrypoint private function, as well as all nested private
283261
// functions that might arise.
284262
async #executePrivate(
@@ -663,25 +641,6 @@ export class PXE {
663641
return this.contractDataProvider.getContractsAddresses();
664642
}
665643

666-
/**
667-
* A debugging utility to get notes based on the provided filter.
668-
*
669-
* Note that this should not be used in production code because the structure of notes is considered to be
670-
* an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
671-
* note-related information in production code, please implement a custom utility function on your contract and call
672-
* that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
673-
*
674-
* @param filter - The filter to apply to the notes.
675-
* @returns The requested notes.
676-
*/
677-
public async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
678-
// We need to manually trigger private state sync to have a guarantee that all the notes are available.
679-
const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
680-
await this.simulateUtility(call);
681-
682-
return this.noteDataProvider.getNotes(filter);
683-
}
684-
685644
/**
686645
* Proves the private portion of a simulated transaction, ready to send to the network
687646
* (where validators prove the public portion).
@@ -1066,7 +1025,7 @@ export class PXE {
10661025
filter: PrivateEventFilter,
10671026
): Promise<PackedPrivateEvent[]> {
10681027
// We need to manually trigger private state sync to have a guarantee that all the events are available.
1069-
const call = await this.#getFunctionCall('sync_private_state', [], filter.contractAddress);
1028+
const call = await this.contractDataProvider.getFunctionCall('sync_private_state', [], filter.contractAddress);
10701029
await this.simulateUtility(call);
10711030

10721031
const sanitizedFilter = await new PrivateEventFilterValidator(this.anchorBlockDataProvider).validate(filter);

yarn-project/pxe/src/storage/contract_data_provider/contract_data_provider.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import {
88
type FunctionAbi,
99
type FunctionArtifact,
1010
type FunctionArtifactWithContractName,
11+
FunctionCall,
1112
type FunctionDebugMetadata,
1213
FunctionSelector,
1314
FunctionType,
1415
contractArtifactFromBuffer,
1516
contractArtifactToBuffer,
17+
encodeArguments,
1618
getFunctionDebugMetadata,
1719
} from '@aztec/stdlib/abi';
1820
import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -274,4 +276,29 @@ export class ContractDataProvider {
274276
}
275277
}
276278
}
279+
280+
public async getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
281+
const contract = await this.getContract(to);
282+
if (!contract) {
283+
throw new Error(
284+
`Unknown contract ${to}: add it to PXE by calling server.addContracts(...).\nSee docs for context: https://docs.aztec.network/developers/resources/debugging/aztecnr-errors#unknown-contract-0x0-add-it-to-pxe-by-calling-serveraddcontracts`,
285+
);
286+
}
287+
288+
const functionDao = contract.functions.find(f => f.name === functionName);
289+
if (!functionDao) {
290+
throw new Error(`Unknown function ${functionName} in contract ${contract.name}.`);
291+
}
292+
293+
return {
294+
name: functionDao.name,
295+
args: encodeArguments(functionDao, args),
296+
selector: await FunctionSelector.fromNameAndParameters(functionDao.name, functionDao.parameters),
297+
type: functionDao.functionType,
298+
to,
299+
hideMsgSender: false,
300+
isStatic: functionDao.isStatic,
301+
returnTypes: functionDao.returnTypes,
302+
};
303+
}
277304
}

yarn-project/test-wallet/src/wallet/test_wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export abstract class BaseTestWallet extends BaseWallet {
252252
* @returns The requested notes.
253253
*/
254254
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
255-
return this.pxe.getNotes(filter);
255+
return this.pxe.debug.getNotes(filter);
256256
}
257257

258258
/**

0 commit comments

Comments
 (0)