@aztec/pxe 0.8.9 → 0.8.11

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.
Files changed (42) hide show
  1. package/dest/contract_data_oracle/index.d.ts +4 -4
  2. package/dest/contract_data_oracle/index.d.ts.map +1 -1
  3. package/dest/contract_data_oracle/index.js +9 -9
  4. package/dest/contract_tree/index.d.ts +10 -10
  5. package/dest/contract_tree/index.d.ts.map +1 -1
  6. package/dest/contract_tree/index.js +21 -21
  7. package/dest/database/database.d.ts +5 -0
  8. package/dest/database/database.d.ts.map +1 -1
  9. package/dest/database/memory_db.d.ts +1 -0
  10. package/dest/database/memory_db.d.ts.map +1 -1
  11. package/dest/database/memory_db.js +10 -2
  12. package/dest/database/note_spending_info_dao.d.ts +7 -1
  13. package/dest/database/note_spending_info_dao.d.ts.map +1 -1
  14. package/dest/database/note_spending_info_dao.js +11 -1
  15. package/dest/kernel_prover/proof_creator.d.ts.map +1 -1
  16. package/dest/kernel_prover/proof_creator.js +7 -7
  17. package/dest/note_processor/note_processor.d.ts +2 -11
  18. package/dest/note_processor/note_processor.d.ts.map +1 -1
  19. package/dest/note_processor/note_processor.js +6 -4
  20. package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
  21. package/dest/pxe_http/pxe_http_server.js +6 -2
  22. package/dest/pxe_service/pxe_service.d.ts +10 -3
  23. package/dest/pxe_service/pxe_service.d.ts.map +1 -1
  24. package/dest/pxe_service/pxe_service.js +33 -24
  25. package/dest/simulator_oracle/index.d.ts +2 -2
  26. package/dest/simulator_oracle/index.d.ts.map +1 -1
  27. package/dest/simulator_oracle/index.js +4 -4
  28. package/dest/synchronizer/synchronizer.d.ts +2 -2
  29. package/dest/synchronizer/synchronizer.d.ts.map +1 -1
  30. package/dest/synchronizer/synchronizer.js +11 -10
  31. package/package.json +8 -8
  32. package/src/contract_data_oracle/index.ts +8 -8
  33. package/src/contract_tree/index.ts +21 -21
  34. package/src/database/database.ts +6 -0
  35. package/src/database/memory_db.ts +9 -1
  36. package/src/database/note_spending_info_dao.ts +12 -1
  37. package/src/kernel_prover/proof_creator.ts +10 -9
  38. package/src/note_processor/note_processor.ts +6 -13
  39. package/src/pxe_http/pxe_http_server.ts +6 -0
  40. package/src/pxe_service/pxe_service.ts +38 -33
  41. package/src/simulator_oracle/index.ts +5 -5
  42. package/src/synchronizer/synchronizer.ts +12 -10
@@ -10,7 +10,6 @@ import {
10
10
  AztecAddress,
11
11
  CircuitsWasm,
12
12
  CompleteAddress,
13
- EthAddress,
14
13
  FunctionData,
15
14
  GrumpkinPrivateKey,
16
15
  KernelCircuitPublicInputsFinal,
@@ -21,7 +20,7 @@ import {
21
20
  import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/abis';
22
21
  import { encodeArguments } from '@aztec/foundation/abi';
23
22
  import { padArrayEnd } from '@aztec/foundation/collection';
24
- import { Fr, Point } from '@aztec/foundation/fields';
23
+ import { Fr } from '@aztec/foundation/fields';
25
24
  import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
26
25
  import NoirVersion from '@aztec/noir-compiler/noir-version';
27
26
  import {
@@ -32,11 +31,11 @@ import {
32
31
  DeployedContract,
33
32
  ExtendedContractData,
34
33
  FunctionCall,
34
+ GetUnencryptedLogsResponse,
35
35
  KeyStore,
36
36
  L2Block,
37
- L2BlockL2Logs,
38
37
  L2Tx,
39
- LogType,
38
+ LogFilter,
40
39
  MerkleTreeId,
41
40
  NodeInfo,
42
41
  NotePreimage,
@@ -87,7 +86,7 @@ export class PXEService implements PXE {
87
86
  }
88
87
 
89
88
  /**
90
- * Starts the PXE Service by beginning the synchronisation process between the Aztec node and the database.
89
+ * Starts the PXE Service by beginning the synchronization process between the Aztec node and the database.
91
90
  *
92
91
  * @returns A promise that resolves when the server has started successfully.
93
92
  */
@@ -110,6 +109,11 @@ export class PXEService implements PXE {
110
109
  this.log.info('Stopped');
111
110
  }
112
111
 
112
+ /** Returns an estimate of the db size in bytes. */
113
+ public estimateDbSize() {
114
+ return this.db.estimateSize();
115
+ }
116
+
113
117
  public addAuthWitness(witness: AuthWitness) {
114
118
  return this.db.addAuthWitness(witness.requestHash, witness.witness);
115
119
  }
@@ -168,7 +172,7 @@ export class PXEService implements PXE {
168
172
  }
169
173
 
170
174
  public async addContracts(contracts: DeployedContract[]) {
171
- const contractDaos = contracts.map(c => toContractDao(c.abi, c.completeAddress, c.portalContract));
175
+ const contractDaos = contracts.map(c => toContractDao(c.artifact, c.completeAddress, c.portalContract));
172
176
  await Promise.all(contractDaos.map(c => this.db.addContract(c)));
173
177
  for (const contract of contractDaos) {
174
178
  const portalInfo =
@@ -334,7 +338,7 @@ export class PXEService implements PXE {
334
338
  const functionCall = await this.#getFunctionCall(functionName, args, to);
335
339
  const executionResult = await this.#simulateUnconstrained(functionCall);
336
340
 
337
- // TODO - Return typed result based on the function abi.
341
+ // TODO - Return typed result based on the function artifact.
338
342
  return executionResult;
339
343
  }
340
344
 
@@ -379,8 +383,13 @@ export class PXEService implements PXE {
379
383
  return await this.node.getContractData(contractAddress);
380
384
  }
381
385
 
382
- public async getUnencryptedLogs(from: number, limit: number): Promise<L2BlockL2Logs[]> {
383
- return await this.node.getLogs(from, limit, LogType.UNENCRYPTED);
386
+ /**
387
+ * Gets unencrypted logs based on the provided filter.
388
+ * @param filter - The filter to apply to the logs.
389
+ * @returns The requested logs.
390
+ */
391
+ public getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
392
+ return this.node.getUnencryptedLogs(filter);
384
393
  }
385
394
 
386
395
  async #getFunctionCall(functionName: string, args: any[], to: AztecAddress): Promise<FunctionCall> {
@@ -420,14 +429,14 @@ export class PXEService implements PXE {
420
429
 
421
430
  /**
422
431
  * Retrieves the simulation parameters required to run an ACIR simulation.
423
- * This includes the contract address, function ABI, portal contract address, and historic tree roots.
432
+ * This includes the contract address, function artifact, portal contract address, and historic tree roots.
424
433
  *
425
434
  * @param execRequest - The transaction request object containing details of the contract call.
426
- * @returns An object containing the contract address, function ABI, portal contract address, and historic tree roots.
435
+ * @returns An object containing the contract address, function artifact, portal contract address, and historic tree roots.
427
436
  */
428
437
  async #getSimulationParameters(execRequest: FunctionCall | TxExecutionRequest) {
429
438
  const contractAddress = (execRequest as FunctionCall).to ?? (execRequest as TxExecutionRequest).origin;
430
- const functionAbi = await this.contractDataOracle.getFunctionAbi(
439
+ const functionArtifact = await this.contractDataOracle.getFunctionArtifact(
431
440
  contractAddress,
432
441
  execRequest.functionData.selector,
433
442
  );
@@ -439,8 +448,8 @@ export class PXEService implements PXE {
439
448
 
440
449
  return {
441
450
  contractAddress,
442
- functionAbi: {
443
- ...functionAbi,
451
+ functionArtifact: {
452
+ ...functionArtifact,
444
453
  debug,
445
454
  },
446
455
  portalContract,
@@ -450,11 +459,11 @@ export class PXEService implements PXE {
450
459
  async #simulate(txRequest: TxExecutionRequest): Promise<ExecutionResult> {
451
460
  // TODO - Pause syncing while simulating.
452
461
 
453
- const { contractAddress, functionAbi, portalContract } = await this.#getSimulationParameters(txRequest);
462
+ const { contractAddress, functionArtifact, portalContract } = await this.#getSimulationParameters(txRequest);
454
463
 
455
464
  this.log('Executing simulator...');
456
465
  try {
457
- const result = await this.simulator.run(txRequest, functionAbi, contractAddress, portalContract);
466
+ const result = await this.simulator.run(txRequest, functionArtifact, contractAddress, portalContract);
458
467
  this.log('Simulation completed!');
459
468
  return result;
460
469
  } catch (err) {
@@ -474,11 +483,11 @@ export class PXEService implements PXE {
474
483
  * @returns The simulation result containing the outputs of the unconstrained function.
475
484
  */
476
485
  async #simulateUnconstrained(execRequest: FunctionCall) {
477
- const { contractAddress, functionAbi } = await this.#getSimulationParameters(execRequest);
486
+ const { contractAddress, functionArtifact } = await this.#getSimulationParameters(execRequest);
478
487
 
479
488
  this.log('Executing unconstrained simulator...');
480
489
  try {
481
- const result = await this.simulator.runUnconstrained(execRequest, functionAbi, contractAddress, this.node);
490
+ const result = await this.simulator.runUnconstrained(execRequest, functionArtifact, contractAddress, this.node);
482
491
  this.log('Unconstrained simulation completed!');
483
492
 
484
493
  return result;
@@ -543,22 +552,18 @@ export class PXEService implements PXE {
543
552
  this.log(`Executing kernel prover...`);
544
553
  const { proof, publicInputs } = await kernelProver.prove(txExecutionRequest.toTxRequest(), executionResult);
545
554
 
546
- const newContractPublicFunctions = newContract ? getNewContractPublicFunctions(newContract) : [];
547
-
548
555
  const encryptedLogs = new TxL2Logs(collectEncryptedLogs(executionResult));
549
556
  const unencryptedLogs = new TxL2Logs(collectUnencryptedLogs(executionResult));
550
557
  const enqueuedPublicFunctions = collectEnqueuedPublicFunctionCalls(executionResult);
551
558
 
552
- const contractData = new ContractData(
553
- newContract?.completeAddress.address ?? AztecAddress.ZERO,
554
- newContract?.portalContract ?? EthAddress.ZERO,
555
- );
556
- const extendedContractData = new ExtendedContractData(
557
- contractData,
558
- newContractPublicFunctions,
559
- newContract?.completeAddress.partialAddress ?? Fr.ZERO,
560
- newContract?.completeAddress.publicKey ?? Point.ZERO,
561
- );
559
+ const extendedContractData = newContract
560
+ ? new ExtendedContractData(
561
+ new ContractData(newContract.completeAddress.address, newContract.portalContract),
562
+ getNewContractPublicFunctions(newContract),
563
+ newContract.completeAddress.partialAddress,
564
+ newContract.completeAddress.publicKey,
565
+ )
566
+ : ExtendedContractData.empty();
562
567
 
563
568
  // HACK(#1639): Manually patches the ordering of the public call stack
564
569
  // TODO(#757): Enforce proper ordering of enqueued public calls
@@ -590,9 +595,9 @@ export class PXEService implements PXE {
590
595
  if (contract) {
591
596
  err.enrichWithContractName(parsedContractAddress, contract.name);
592
597
  selectors.forEach(selector => {
593
- const functionAbi = contract.functions.find(f => f.selector.toString() === selector);
594
- if (functionAbi) {
595
- err.enrichWithFunctionName(parsedContractAddress, functionAbi.selector, functionAbi.name);
598
+ const functionArtifact = contract.functions.find(f => f.selector.toString() === selector);
599
+ if (functionArtifact) {
600
+ err.enrichWithFunctionName(parsedContractAddress, functionArtifact.selector, functionArtifact.name);
596
601
  }
597
602
  });
598
603
  }
@@ -1,4 +1,4 @@
1
- import { DBOracle, FunctionAbiWithDebugMetadata, MessageLoadOracleInputs } from '@aztec/acir-simulator';
1
+ import { DBOracle, FunctionArtifactWithDebugMetadata, MessageLoadOracleInputs } from '@aztec/acir-simulator';
2
2
  import {
3
3
  AztecAddress,
4
4
  CompleteAddress,
@@ -60,14 +60,14 @@ export class SimulatorOracle implements DBOracle {
60
60
  );
61
61
  }
62
62
 
63
- async getFunctionABI(
63
+ async getFunctionArtifact(
64
64
  contractAddress: AztecAddress,
65
65
  selector: FunctionSelector,
66
- ): Promise<FunctionAbiWithDebugMetadata> {
67
- const abi = await this.contractDataOracle.getFunctionAbi(contractAddress, selector);
66
+ ): Promise<FunctionArtifactWithDebugMetadata> {
67
+ const artifact = await this.contractDataOracle.getFunctionArtifact(contractAddress, selector);
68
68
  const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, selector);
69
69
  return {
70
- ...abi,
70
+ ...artifact,
71
71
  debug,
72
72
  };
73
73
  }
@@ -1,8 +1,9 @@
1
1
  import { AztecAddress, CircuitsWasm, Fr, HistoricBlockData, PublicKey } from '@aztec/circuits.js';
2
2
  import { computeGlobalsHash } from '@aztec/circuits.js/abis';
3
3
  import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
4
- import { InterruptableSleep } from '@aztec/foundation/sleep';
4
+ import { InterruptibleSleep } from '@aztec/foundation/sleep';
5
5
  import { AztecNode, INITIAL_L2_BLOCK_NUM, KeyStore, L2BlockContext, L2BlockL2Logs, LogType } from '@aztec/types';
6
+ import { NoteProcessorCaughtUpStats } from '@aztec/types/stats';
6
7
 
7
8
  import { Database } from '../database/index.js';
8
9
  import { NoteProcessor } from '../note_processor/index.js';
@@ -17,7 +18,7 @@ import { NoteProcessor } from '../note_processor/index.js';
17
18
  export class Synchronizer {
18
19
  private runningPromise?: Promise<void>;
19
20
  private noteProcessors: NoteProcessor[] = [];
20
- private interruptableSleep = new InterruptableSleep();
21
+ private interruptibleSleep = new InterruptibleSleep();
21
22
  private running = false;
22
23
  private initialSyncBlockNumber = 0;
23
24
  private synchedToBlock = 0;
@@ -29,7 +30,7 @@ export class Synchronizer {
29
30
  }
30
31
 
31
32
  /**
32
- * Starts the synchronisation process by fetching encrypted logs and blocks from a specified position.
33
+ * Starts the synchronization process by fetching encrypted logs and blocks from a specified position.
33
34
  * Continuously processes the fetched data for all note processors until stopped. If there is no data
34
35
  * available, it retries after a specified interval.
35
36
  *
@@ -79,20 +80,20 @@ export class Synchronizer {
79
80
  try {
80
81
  let encryptedLogs = await this.node.getLogs(from, limit, LogType.ENCRYPTED);
81
82
  if (!encryptedLogs.length) {
82
- await this.interruptableSleep.sleep(retryInterval);
83
+ await this.interruptibleSleep.sleep(retryInterval);
83
84
  return;
84
85
  }
85
86
 
86
87
  let unencryptedLogs = await this.node.getLogs(from, limit, LogType.UNENCRYPTED);
87
88
  if (!unencryptedLogs.length) {
88
- await this.interruptableSleep.sleep(retryInterval);
89
+ await this.interruptibleSleep.sleep(retryInterval);
89
90
  return;
90
91
  }
91
92
 
92
93
  // Note: If less than `limit` encrypted logs is returned, then we fetch only that number of blocks.
93
94
  const blocks = await this.node.getBlocks(from, encryptedLogs.length);
94
95
  if (!blocks.length) {
95
- await this.interruptableSleep.sleep(retryInterval);
96
+ await this.interruptibleSleep.sleep(retryInterval);
96
97
  return;
97
98
  }
98
99
 
@@ -128,7 +129,7 @@ export class Synchronizer {
128
129
  this.synchedToBlock = latestBlock.block.number;
129
130
  } catch (err) {
130
131
  this.log.error(`Error in synchronizer work`, err);
131
- await this.interruptableSleep.sleep(retryInterval);
132
+ await this.interruptibleSleep.sleep(retryInterval);
132
133
  }
133
134
  }
134
135
 
@@ -182,14 +183,15 @@ export class Synchronizer {
182
183
  eventName: 'note-processor-caught-up',
183
184
  publicKey: noteProcessor.publicKey.toString(),
184
185
  duration: noteProcessor.timer.ms(),
186
+ dbSize: this.db.estimateSize(),
185
187
  ...noteProcessor.stats,
186
- });
188
+ } satisfies NoteProcessorCaughtUpStats);
187
189
  this.noteProcessorsToCatchUp.shift();
188
190
  this.noteProcessors.push(noteProcessor);
189
191
  }
190
192
  } catch (err) {
191
193
  this.log.error(`Error in synchronizer workNoteProcessorCatchUp`, err);
192
- await this.interruptableSleep.sleep(retryInterval);
194
+ await this.interruptibleSleep.sleep(retryInterval);
193
195
  }
194
196
  }
195
197
 
@@ -222,7 +224,7 @@ export class Synchronizer {
222
224
  */
223
225
  public async stop() {
224
226
  this.running = false;
225
- this.interruptableSleep.interrupt();
227
+ this.interruptibleSleep.interrupt();
226
228
  await this.runningPromise;
227
229
  this.log('Stopped');
228
230
  }