@aztec/simulator 0.0.1-commit.9372f48 → 0.0.1-commit.949a33fd8

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 (103) hide show
  1. package/README.md +4 -4
  2. package/dest/private/circuit_recording/circuit_recorder.js +2 -2
  3. package/dest/public/avm/avm_gas.js +3 -3
  4. package/dest/public/avm/avm_simulator.js +1 -1
  5. package/dest/public/avm/calldata.d.ts +1 -1
  6. package/dest/public/avm/calldata.d.ts.map +1 -1
  7. package/dest/public/avm/calldata.js +3 -2
  8. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  9. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  10. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  11. package/dest/public/avm/opcodes/accrued_substate.d.ts +2 -2
  12. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  13. package/dest/public/avm/opcodes/accrued_substate.js +3 -4
  14. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  15. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  16. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  17. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  18. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  19. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  20. package/dest/public/contracts_db_checkpoint.js +1 -1
  21. package/dest/public/fixtures/amm_test.js +2 -2
  22. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  23. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  24. package/dest/public/fixtures/bulk_test.js +4 -4
  25. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  26. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  27. package/dest/public/fixtures/custom_bytecode_tests.js +61 -1
  28. package/dest/public/fixtures/opcode_spammer.d.ts +1 -1
  29. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  30. package/dest/public/fixtures/opcode_spammer.js +6 -6
  31. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  32. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  33. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  34. package/dest/public/fixtures/utils.d.ts +2 -2
  35. package/dest/public/fixtures/utils.d.ts.map +1 -1
  36. package/dest/public/fixtures/utils.js +10 -10
  37. package/dest/public/hinting_db_sources.d.ts +5 -5
  38. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  39. package/dest/public/hinting_db_sources.js +7 -6
  40. package/dest/public/public_db_sources.d.ts +3 -3
  41. package/dest/public/public_db_sources.d.ts.map +1 -1
  42. package/dest/public/public_db_sources.js +10 -10
  43. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  44. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  45. package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
  46. package/dest/public/public_processor/public_processor.d.ts +5 -3
  47. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  48. package/dest/public/public_processor/public_processor.js +68 -46
  49. package/dest/public/public_processor/public_processor_metrics.d.ts +4 -1
  50. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  51. package/dest/public/public_processor/public_processor_metrics.js +8 -0
  52. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
  53. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  54. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -1
  55. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
  56. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  57. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -3
  58. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +1 -1
  59. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  60. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +2 -2
  61. package/dest/public/public_tx_simulator/factories.d.ts +2 -2
  62. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  63. package/dest/public/public_tx_simulator/factories.js +2 -2
  64. package/dest/public/public_tx_simulator/public_tx_context.d.ts +7 -3
  65. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  66. package/dest/public/public_tx_simulator/public_tx_context.js +8 -10
  67. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +6 -2
  68. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  69. package/dest/public/public_tx_simulator/public_tx_simulator.js +14 -9
  70. package/dest/public/test_executor_metrics.d.ts +6 -1
  71. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  72. package/dest/public/test_executor_metrics.js +22 -0
  73. package/package.json +15 -16
  74. package/src/private/circuit_recording/circuit_recorder.ts +2 -2
  75. package/src/public/avm/avm_gas.ts +2 -2
  76. package/src/public/avm/avm_simulator.ts +1 -1
  77. package/src/public/avm/calldata.ts +3 -2
  78. package/src/public/avm/fixtures/account_proof.json +553 -0
  79. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  80. package/src/public/avm/opcodes/accrued_substate.ts +3 -4
  81. package/src/public/avm/opcodes/external_calls.ts +1 -1
  82. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  83. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  84. package/src/public/contracts_db_checkpoint.ts +1 -1
  85. package/src/public/fixtures/amm_test.ts +2 -2
  86. package/src/public/fixtures/bulk_test.ts +2 -4
  87. package/src/public/fixtures/custom_bytecode_tests.ts +139 -1
  88. package/src/public/fixtures/opcode_spammer.ts +6 -10
  89. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  90. package/src/public/fixtures/utils.ts +17 -12
  91. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  92. package/src/public/hinting_db_sources.ts +9 -7
  93. package/src/public/public_db_sources.ts +12 -14
  94. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  95. package/src/public/public_processor/public_processor.ts +94 -62
  96. package/src/public/public_processor/public_processor_metrics.ts +12 -0
  97. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +2 -1
  98. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +2 -3
  99. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +2 -2
  100. package/src/public/public_tx_simulator/factories.ts +2 -1
  101. package/src/public/public_tx_simulator/public_tx_context.ts +8 -10
  102. package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -10
  103. package/src/public/test_executor_metrics.ts +24 -0
@@ -2,10 +2,8 @@ import {
2
2
  CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE,
3
3
  CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
4
4
  CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
5
- DEFAULT_DA_GAS_LIMIT,
6
- DEFAULT_L2_GAS_LIMIT,
7
- DEFAULT_TEARDOWN_DA_GAS_LIMIT,
8
- DEFAULT_TEARDOWN_L2_GAS_LIMIT,
5
+ MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
6
+ MAX_PROCESSABLE_L2_GAS,
9
7
  PRIVATE_LOG_SIZE_IN_FIELDS,
10
8
  } from '@aztec/constants';
11
9
  import { padArrayEnd } from '@aztec/foundation/collection';
@@ -14,7 +12,13 @@ import { CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG } from '@aztec/protocol-contracts
14
12
  import { bufferAsFields } from '@aztec/stdlib/abi';
15
13
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
16
14
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
17
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
15
+ import {
16
+ FALLBACK_TEARDOWN_DA_GAS_LIMIT,
17
+ FALLBACK_TEARDOWN_L2_GAS_LIMIT,
18
+ Gas,
19
+ GasFees,
20
+ GasSettings,
21
+ } from '@aztec/stdlib/gas';
18
22
  import { siloNullifier } from '@aztec/stdlib/hash';
19
23
  import {
20
24
  LogHash,
@@ -62,13 +66,14 @@ export async function createTxForPublicCalls(
62
66
  feePayer = AztecAddress.zero(),
63
67
  gasUsedByPrivate: Gas = Gas.empty(),
64
68
  globals: GlobalVariables = GlobalVariables.empty(),
69
+ gasLimits?: Gas,
65
70
  ): Promise<Tx> {
66
71
  assert(
67
72
  setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
68
73
  "Can't create public tx with no enqueued calls",
69
74
  );
70
75
  // use max limits
71
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
76
+ gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
72
77
 
73
78
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
74
79
 
@@ -128,19 +133,19 @@ export async function createTxForPublicCalls(
128
133
 
129
134
  const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
130
135
  const teardownGasLimits = teardownCallRequest
131
- ? new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT)
136
+ ? new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT)
132
137
  : Gas.empty();
133
138
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
134
139
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
135
140
  const header = BlockHeader.empty({ globalVariables: globals });
136
141
  const constantData = new TxConstantData(header, txContext, Fr.zero(), Fr.zero());
137
- const includeByTimestamp = 0n; // Not used in the simulator.
142
+ const expirationTimestamp = 0n; // Not used in the simulator.
138
143
 
139
144
  const txData = new PrivateKernelTailCircuitPublicInputs(
140
145
  constantData,
141
146
  /*gasUsed=*/ gasUsedByPrivate,
142
147
  feePayer,
143
- includeByTimestamp,
148
+ expirationTimestamp,
144
149
  forPublic,
145
150
  );
146
151
 
@@ -163,7 +168,7 @@ export async function createTxForPrivateOnly(
163
168
  gasUsedByPrivate: Gas = new Gas(10, 10),
164
169
  ): Promise<Tx> {
165
170
  // use max limits
166
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
171
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
167
172
 
168
173
  const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
169
174
 
@@ -171,13 +176,13 @@ export async function createTxForPrivateOnly(
171
176
  const gasSettings = new GasSettings(gasLimits, Gas.empty(), maxFeesPerGas, GasFees.empty());
172
177
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
173
178
  const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
174
- const includeByTimestamp = 0n; // Not used in the simulator.
179
+ const expirationTimestamp = 0n; // Not used in the simulator.
175
180
 
176
181
  const txData = new PrivateKernelTailCircuitPublicInputs(
177
182
  constantData,
178
183
  /*gasUsed=*/ gasUsedByPrivate,
179
184
  feePayer,
180
- includeByTimestamp,
185
+ expirationTimestamp,
181
186
  /*forPublic=*/ undefined,
182
187
  forRollup,
183
188
  );
@@ -146,7 +146,7 @@ async function createTxFromHint(cppTx: AvmTxHint): Promise<Tx> {
146
146
  constants,
147
147
  cppTx.gasUsedByPrivate,
148
148
  cppTx.feePayer,
149
- 0n, // includeByTimestamp
149
+ 0n, // expirationTimestamp
150
150
  forPublic,
151
151
  undefined, // forRollup - not needed for public simulation
152
152
  );
@@ -410,12 +410,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
410
410
  }
411
411
  }
412
412
 
413
- public async createCheckpoint(): Promise<void> {
413
+ public async createCheckpoint(): Promise<number> {
414
414
  const actionCounter = this.checkpointActionCounter++;
415
415
  const oldCheckpointId = this.getCurrentCheckpointId();
416
416
  const treesStateHash = await this.getTreesStateHash();
417
417
 
418
- await this.db.createCheckpoint();
418
+ const depth = await this.db.createCheckpoint();
419
419
  this.checkpointStack.push(this.nextCheckpointId++);
420
420
  const newCheckpointId = this.getCurrentCheckpointId();
421
421
 
@@ -424,14 +424,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
424
424
  HintingMerkleWriteOperations.log.trace(
425
425
  `[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
426
426
  );
427
+
428
+ return depth;
427
429
  }
428
430
 
429
- public commitAllCheckpoints(): Promise<void> {
430
- throw new Error('commitAllCheckpoints is not supported in HintingMerkleWriteOperations.');
431
+ public commitAllCheckpointsTo(_depth: number): Promise<void> {
432
+ throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
431
433
  }
432
434
 
433
- public revertAllCheckpoints(): Promise<void> {
434
- throw new Error('revertAllCheckpoints is not supported in HintingMerkleWriteOperations.');
435
+ public revertAllCheckpointsTo(_depth: number): Promise<void> {
436
+ throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
435
437
  }
436
438
 
437
439
  public async commitCheckpoint(): Promise<void> {
@@ -572,7 +574,7 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
572
574
  return await this.db.close();
573
575
  }
574
576
 
575
- async [Symbol.dispose](): Promise<void> {
577
+ async [Symbol.asyncDispose](): Promise<void> {
576
578
  await this.close();
577
579
  }
578
580
 
@@ -55,10 +55,10 @@ export class PublicContractsDB implements PublicContractsDBInterface {
55
55
  this.log = createLogger('simulator:contracts-data-source', bindings);
56
56
  }
57
57
 
58
- public async addContracts(contractDeploymentData: ContractDeploymentData): Promise<void> {
58
+ public addContracts(contractDeploymentData: ContractDeploymentData): void {
59
59
  const currentState = this.getCurrentState();
60
60
 
61
- await this.addContractClassesFromEvents(
61
+ this.addContractClassesFromEvents(
62
62
  ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
63
63
  currentState,
64
64
  );
@@ -69,10 +69,10 @@ export class PublicContractsDB implements PublicContractsDBInterface {
69
69
  );
70
70
  }
71
71
 
72
- public async addNewContracts(tx: Tx): Promise<void> {
72
+ public addNewContracts(tx: Tx): void {
73
73
  const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
74
- await this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
75
- await this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
74
+ this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
75
+ this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
76
76
  }
77
77
 
78
78
  /**
@@ -81,7 +81,7 @@ export class PublicContractsDB implements PublicContractsDBInterface {
81
81
  */
82
82
  public createCheckpoint(): void {
83
83
  const currentState = this.getCurrentState();
84
- const newState = currentState.deepCopy();
84
+ const newState = currentState.fork();
85
85
  this.contractStateStack.push(newState);
86
86
  }
87
87
 
@@ -174,17 +174,15 @@ export class PublicContractsDB implements PublicContractsDBInterface {
174
174
  return await this.dataSource.getDebugFunctionName(address, selector);
175
175
  }
176
176
 
177
- private async addContractClassesFromEvents(
177
+ private addContractClassesFromEvents(
178
178
  contractClassEvents: ContractClassPublishedEvent[],
179
179
  state: ContractsDbCheckpoint,
180
180
  ) {
181
- await Promise.all(
182
- contractClassEvents.map(async (event: ContractClassPublishedEvent) => {
183
- this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
184
- const contractClass = await event.toContractClassPublic();
185
- state.addClass(event.contractClassId, contractClass);
186
- }),
187
- );
181
+ for (const event of contractClassEvents) {
182
+ this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
183
+ const contractClass = event.toContractClassPublic();
184
+ state.addClass(event.contractClassId, contractClass);
185
+ }
188
186
  }
189
187
 
190
188
  private addContractInstancesFromEvents(
@@ -82,7 +82,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
82
82
  return this.guardAndPush(() => this.target.close());
83
83
  }
84
84
 
85
- async [Symbol.dispose](): Promise<void> {
85
+ async [Symbol.asyncDispose](): Promise<void> {
86
86
  await this.close();
87
87
  }
88
88
  getTreeInfo(treeId: MerkleTreeId): Promise<TreeInfo> {
@@ -134,7 +134,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
134
134
  ): Promise<(BlockNumber | undefined)[]> {
135
135
  return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
136
136
  }
137
- createCheckpoint(): Promise<void> {
137
+ createCheckpoint(): Promise<number> {
138
138
  return this.guardAndPush(() => this.target.createCheckpoint());
139
139
  }
140
140
  commitCheckpoint(): Promise<void> {
@@ -143,11 +143,11 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
143
143
  revertCheckpoint(): Promise<void> {
144
144
  return this.guardAndPush(() => this.target.revertCheckpoint());
145
145
  }
146
- commitAllCheckpoints(): Promise<void> {
147
- return this.guardAndPush(() => this.target.commitAllCheckpoints());
146
+ commitAllCheckpointsTo(depth: number): Promise<void> {
147
+ return this.guardAndPush(() => this.target.commitAllCheckpointsTo(depth));
148
148
  }
149
- revertAllCheckpoints(): Promise<void> {
150
- return this.guardAndPush(() => this.target.revertAllCheckpoints());
149
+ revertAllCheckpointsTo(depth: number): Promise<void> {
150
+ return this.guardAndPush(() => this.target.revertAllCheckpointsTo(depth));
151
151
  }
152
152
  findSiblingPaths<ID extends MerkleTreeId>(
153
153
  treeId: ID,
@@ -25,6 +25,7 @@ import type {
25
25
  PublicProcessorValidator,
26
26
  SequencerConfig,
27
27
  } from '@aztec/stdlib/interfaces/server';
28
+ import { type DebugLog, type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
28
29
  import { ProvingRequestType } from '@aztec/stdlib/proofs';
29
30
  import { MerkleTreeId } from '@aztec/stdlib/trees';
30
31
  import {
@@ -130,7 +131,6 @@ class PublicProcessorTimeoutError extends Error {
130
131
  */
131
132
  export class PublicProcessor implements Traceable {
132
133
  private metrics: PublicProcessorMetrics;
133
-
134
134
  constructor(
135
135
  protected globalVariables: GlobalVariables,
136
136
  private guardedMerkleTree: GuardedMerkleTreeOperations,
@@ -140,6 +140,7 @@ export class PublicProcessor implements Traceable {
140
140
  telemetryClient: TelemetryClient = getTelemetryClient(),
141
141
  private log: Logger,
142
142
  private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
143
+ private debugLogStore: DebugLogStore = new NullDebugLogStore(),
143
144
  ) {
144
145
  this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
145
146
  }
@@ -159,12 +160,13 @@ export class PublicProcessor implements Traceable {
159
160
  txs: Iterable<Tx> | AsyncIterable<Tx>,
160
161
  limits: PublicProcessorLimits = {},
161
162
  validator: PublicProcessorValidator = {},
162
- ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], number]> {
163
- const { maxTransactions, maxBlockSize, deadline, maxBlockGas, maxBlobFields } = limits;
163
+ ): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], DebugLog[]]> {
164
+ const { maxTransactions, deadline, maxBlockGas, maxBlobFields, isBuildingProposal } = limits;
164
165
  const { preprocessValidator, nullifierCache } = validator;
165
166
  const result: ProcessedTx[] = [];
166
167
  const usedTxs: Tx[] = [];
167
168
  const failed: FailedTx[] = [];
169
+ const debugLogs: DebugLog[] = [];
168
170
  const timer = new Timer();
169
171
 
170
172
  let totalSizeInBytes = 0;
@@ -172,6 +174,8 @@ export class PublicProcessor implements Traceable {
172
174
  let totalPublicGas = new Gas(0, 0);
173
175
  let totalBlockGas = new Gas(0, 0);
174
176
  let totalBlobFields = 0;
177
+ let silentlySkippedCount = 0;
178
+ let totalSilentlySkippedDurationMs = 0;
175
179
 
176
180
  for await (const tx of txs) {
177
181
  // Only process up to the max tx limit
@@ -186,22 +190,23 @@ export class PublicProcessor implements Traceable {
186
190
  break;
187
191
  }
188
192
 
189
- // Skip this tx if it'd exceed max block size
190
193
  const txHash = tx.getTxHash().toString();
191
- const preTxSizeInBytes = tx.getEstimatedPrivateTxEffectsSize();
192
- if (maxBlockSize !== undefined && totalSizeInBytes + preTxSizeInBytes > maxBlockSize) {
193
- this.log.warn(`Skipping processing of tx ${txHash} sized ${preTxSizeInBytes} bytes due to block size limit`, {
194
- txHash,
195
- sizeInBytes: preTxSizeInBytes,
196
- totalSizeInBytes,
197
- maxBlockSize,
198
- });
194
+
195
+ // Skip this tx if its estimated blob fields would exceed the limit.
196
+ // Only done during proposal building: during re-execution we must process the exact txs from the proposal.
197
+ const txBlobFields = tx.getPrivateTxEffectsSizeInFields();
198
+ if (isBuildingProposal && maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
199
+ this.log.warn(
200
+ `Skipping tx ${txHash} with ${txBlobFields} fields from private side effects due to blob fields limit`,
201
+ { txHash, txBlobFields, totalBlobFields, maxBlobFields },
202
+ );
199
203
  continue;
200
204
  }
201
205
 
202
- // Skip this tx if its gas limit would exceed the block gas limit
206
+ // Skip this tx if its gas limit would exceed the block gas limit (either da or l2).
207
+ // Only done during proposal building: during re-execution we must process the exact txs from the proposal.
203
208
  const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
204
- if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
209
+ if (isBuildingProposal && maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
205
210
  this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
206
211
  txHash,
207
212
  txGasLimit,
@@ -241,7 +246,9 @@ export class PublicProcessor implements Traceable {
241
246
  this.contractsDB.createCheckpoint();
242
247
 
243
248
  try {
244
- const [processedTx, returnValues] = await this.processTx(tx, deadline);
249
+ const [txProcessingTimeMs, [processedTx, returnValues, txDebugLogs]] = await elapsed(() =>
250
+ this.processTx(tx, deadline),
251
+ );
245
252
 
246
253
  // Inject a fake processing failure after N txs if requested
247
254
  const fakeThrowAfter = this.opts.fakeThrowAfterProcessingTxCount;
@@ -250,23 +257,9 @@ export class PublicProcessor implements Traceable {
250
257
  }
251
258
 
252
259
  const txBlobFields = processedTx.txEffect.getNumBlobFields();
253
-
254
- // If the actual size of this tx would exceed block size, skip it
255
260
  const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
256
- if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
257
- this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
258
- txHash,
259
- sizeInBytes: txSize,
260
- totalSizeInBytes,
261
- maxBlockSize,
262
- });
263
- // Need to revert the checkpoint here and don't go any further
264
- await checkpoint.revert();
265
- this.contractsDB.revertCheckpoint();
266
- continue;
267
- }
268
261
 
269
- // If the actual blob fields of this tx would exceed the limit, skip it
262
+ // If the actual blob fields of this tx would exceed the limit, skip it.
270
263
  // Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
271
264
  if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
272
265
  this.log.debug(
@@ -276,25 +269,54 @@ export class PublicProcessor implements Traceable {
276
269
  txBlobFields,
277
270
  totalBlobFields,
278
271
  maxBlobFields,
272
+ txProcessingTimeMs,
279
273
  },
280
274
  );
275
+ silentlySkippedCount += 1;
276
+ totalSilentlySkippedDurationMs += txProcessingTimeMs;
277
+ this.metrics.recordSilentlySkipped(txProcessingTimeMs);
281
278
  // Need to revert the checkpoint here and don't go any further
282
279
  await checkpoint.revert();
283
280
  this.contractsDB.revertCheckpoint();
284
281
  continue;
285
282
  }
286
283
 
284
+ // During re-execution, check if the actual gas used by this tx would push the block over the gas limit.
285
+ // Unlike the proposal-building check (which uses declared gas limits pessimistically before processing),
286
+ // this uses actual gas and stops processing when the limit is exceeded.
287
+ if (
288
+ !isBuildingProposal &&
289
+ maxBlockGas !== undefined &&
290
+ totalBlockGas.add(processedTx.gasUsed.totalGas).gtAny(maxBlockGas)
291
+ ) {
292
+ this.log.warn(`Stopping re-execution since tx ${txHash} would push block gas over limit`, {
293
+ txHash,
294
+ txGas: processedTx.gasUsed.totalGas,
295
+ totalBlockGas,
296
+ maxBlockGas,
297
+ });
298
+ await checkpoint.revert();
299
+ this.contractsDB.revertCheckpoint();
300
+ break;
301
+ }
302
+
287
303
  // FIXME(fcarreiro): it's ugly to have to notify the validator of nullifiers.
288
304
  // I'd rather pass the validators the processedTx as well and let them deal with it.
289
305
  nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map(n => n.toBuffer()));
290
306
  result.push(processedTx);
291
307
  usedTxs.push(tx);
292
308
  returns = returns.concat(returnValues);
309
+ debugLogs.push(...txDebugLogs);
310
+
311
+ this.debugLogStore.storeLogs(processedTx.hash.toString(), txDebugLogs);
293
312
 
294
313
  totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
295
314
  totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
296
315
  totalSizeInBytes += txSize;
297
316
  totalBlobFields += txBlobFields;
317
+
318
+ // Commit the tx-level contracts checkpoint on success
319
+ this.contractsDB.commitCheckpoint();
298
320
  } catch (err: any) {
299
321
  if (err?.name === 'PublicProcessorTimeoutError') {
300
322
  this.log.warn(`Stopping tx processing due to timeout.`);
@@ -314,14 +336,10 @@ export class PublicProcessor implements Traceable {
314
336
  // 1. At least one outstanding checkpoint that has not been committed (the one created before we processed the tx).
315
337
  // 2. Possible state updates on that checkpoint or any others created during execution.
316
338
 
317
- // First we revert a checkpoint as managed by the ForkCheckpoint. This will revert whatever is the current checkpoint
318
- // which may not be the one originally created by this object. But that is ok, we do this to fulfil the ForkCheckpoint
319
- // lifecycle expectations and ensure it doesn't attempt to commit later on.
320
- await checkpoint.revert();
321
-
322
- // Now we want to revert any/all remaining checkpoints, destroying any outstanding state updates.
323
- // This needs to be done directly on the underlying fork as the guarded fork has been stopped.
324
- await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
339
+ // Revert all checkpoints at or above this checkpoint's depth (inclusive), destroying any outstanding state
340
+ // updates from this tx and any nested checkpoints created during execution. This preserves any checkpoints
341
+ // created by callers below our depth.
342
+ await checkpoint.revertToCheckpoint();
325
343
 
326
344
  // Revert any contracts added to the DB for the tx.
327
345
  this.contractsDB.revertCheckpoint();
@@ -333,9 +351,9 @@ export class PublicProcessor implements Traceable {
333
351
  break;
334
352
  }
335
353
 
336
- // Roll back state to start of TX before proceeding to next TX
337
- await checkpoint.revert();
338
- await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
354
+ // Roll back state to start of TX before proceeding to next TX.
355
+ // Reverts all checkpoints at or above this checkpoint's depth, preserving any caller checkpoints below.
356
+ await checkpoint.revertToCheckpoint();
339
357
  this.contractsDB.revertCheckpoint();
340
358
  const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
341
359
  this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
@@ -347,7 +365,6 @@ export class PublicProcessor implements Traceable {
347
365
  } finally {
348
366
  // Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
349
367
  await checkpoint.commit();
350
- this.contractsDB.commitCheckpointOkIfNone();
351
368
  }
352
369
  }
353
370
 
@@ -355,15 +372,26 @@ export class PublicProcessor implements Traceable {
355
372
  const rate = duration > 0 ? totalPublicGas.l2Gas / duration : 0;
356
373
  this.metrics.recordAllTxs(totalPublicGas, rate);
357
374
 
358
- this.log.info(`Processed ${result.length} successful txs and ${failed.length} failed txs in ${duration}s`, {
359
- duration,
360
- rate,
361
- totalPublicGas,
362
- totalBlockGas,
363
- totalSizeInBytes,
364
- });
375
+ const silentlySkippedDurationMs = Math.round(totalSilentlySkippedDurationMs);
376
+ this.log.info(
377
+ `Processed ${result.length} successful txs and ${failed.length} failed txs ` +
378
+ `(${silentlySkippedCount} silently skipped, ${silentlySkippedDurationMs}ms wasted) ` +
379
+ `in ${duration}s`,
380
+ {
381
+ blockNumber: this.globalVariables.blockNumber,
382
+ successfulCount: result.length,
383
+ failedCount: failed.length,
384
+ duration,
385
+ rate,
386
+ totalPublicGas,
387
+ totalBlockGas,
388
+ totalSizeInBytes,
389
+ silentlySkippedCount,
390
+ silentlySkippedDurationMs,
391
+ },
392
+ );
365
393
 
366
- return [result, failed, usedTxs, returns, totalBlobFields];
394
+ return [result, failed, usedTxs, returns, debugLogs];
367
395
  }
368
396
 
369
397
  private async checkWorldStateUnchanged(
@@ -383,8 +411,13 @@ export class PublicProcessor implements Traceable {
383
411
  }
384
412
 
385
413
  @trackSpan('PublicProcessor.processTx', tx => ({ [Attributes.TX_HASH]: tx.getTxHash().toString() }))
386
- private async processTx(tx: Tx, deadline: Date | undefined): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
387
- const [time, [processedTx, returnValues]] = await elapsed(() => this.processTxWithinDeadline(tx, deadline));
414
+ private async processTx(
415
+ tx: Tx,
416
+ deadline: Date | undefined,
417
+ ): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
418
+ const [time, [processedTx, returnValues, debugLogs]] = await elapsed(() =>
419
+ this.processTxWithinDeadline(tx, deadline),
420
+ );
388
421
 
389
422
  this.log.verbose(
390
423
  !tx.hasPublicCalls()
@@ -407,7 +440,7 @@ export class PublicProcessor implements Traceable {
407
440
  },
408
441
  );
409
442
 
410
- return [processedTx, returnValues ?? []];
443
+ return [processedTx, returnValues ?? [], debugLogs];
411
444
  }
412
445
 
413
446
  private async doTreeInsertionsForPrivateOnlyTx(processedTx: ProcessedTx): Promise<void> {
@@ -441,10 +474,9 @@ export class PublicProcessor implements Traceable {
441
474
  private async processTxWithinDeadline(
442
475
  tx: Tx,
443
476
  deadline: Date | undefined,
444
- ): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> {
445
- const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined]> = tx.hasPublicCalls()
446
- ? () => this.processTxWithPublicCalls(tx)
447
- : () => this.processPrivateOnlyTx(tx);
477
+ ): Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> {
478
+ const innerProcessFn: () => Promise<[ProcessedTx, NestedProcessReturnValues[] | undefined, DebugLog[]]> =
479
+ tx.hasPublicCalls() ? () => this.processTxWithPublicCalls(tx) : () => this.processPrivateOnlyTx(tx);
448
480
 
449
481
  // Fake a delay per tx if instructed (used for tests)
450
482
  const fakeDelayPerTxMs = this.opts.fakeProcessingDelayPerTxMs;
@@ -512,7 +544,7 @@ export class PublicProcessor implements Traceable {
512
544
  @trackSpan('PublicProcessor.processPrivateOnlyTx', (tx: Tx) => ({
513
545
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
514
546
  }))
515
- private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined]> {
547
+ private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx, undefined, DebugLog[]]> {
516
548
  const gasFees = this.globalVariables.gasFees;
517
549
  const transactionFee = computeTransactionFee(gasFees, tx.data.constants.txContext.gasSettings, tx.data.gasUsed);
518
550
 
@@ -535,15 +567,15 @@ export class PublicProcessor implements Traceable {
535
567
  // Fee payment insertion has already been done. Do the rest.
536
568
  await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
537
569
 
538
- await this.contractsDB.addNewContracts(tx);
570
+ this.contractsDB.addNewContracts(tx);
539
571
 
540
- return [processedTx, undefined];
572
+ return [processedTx, undefined, []];
541
573
  }
542
574
 
543
575
  @trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
544
576
  [Attributes.TX_HASH]: tx.getTxHash().toString(),
545
577
  }))
546
- private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
578
+ private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[], DebugLog[]]> {
547
579
  const timer = new Timer();
548
580
 
549
581
  const result = await this.publicTxSimulator.simulate(tx);
@@ -581,7 +613,7 @@ export class PublicProcessor implements Traceable {
581
613
  revertReason,
582
614
  );
583
615
 
584
- return [processedTx, appLogicReturnValues];
616
+ return [processedTx, appLogicReturnValues, result.logs ?? []];
585
617
  }
586
618
 
587
619
  /**
@@ -30,6 +30,9 @@ export class PublicProcessorMetrics {
30
30
 
31
31
  private treeInsertionDuration: Histogram;
32
32
 
33
+ private silentlySkippedCount: UpDownCounter;
34
+ private silentlySkippedDuration: Histogram;
35
+
33
36
  constructor(client: TelemetryClient, name = 'PublicProcessor') {
34
37
  this.tracer = client.getTracer(name);
35
38
  const meter = client.getMeter(name);
@@ -60,6 +63,10 @@ export class PublicProcessorMetrics {
60
63
  this.gasRate = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_GAS_RATE);
61
64
 
62
65
  this.treeInsertionDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_TREE_INSERTION);
66
+
67
+ this.silentlySkippedCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_PROCESSOR_SILENTLY_SKIPPED_COUNT);
68
+
69
+ this.silentlySkippedDuration = meter.createHistogram(Metrics.PUBLIC_PROCESSOR_SILENTLY_SKIPPED_DURATION);
63
70
  }
64
71
 
65
72
  recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
@@ -123,4 +130,9 @@ export class PublicProcessorMetrics {
123
130
  recordTreeInsertions(durationUs: number) {
124
131
  this.treeInsertionDuration.record(Math.ceil(durationUs));
125
132
  }
133
+
134
+ recordSilentlySkipped(durationMs: number) {
135
+ this.silentlySkippedCount.add(1);
136
+ this.silentlySkippedDuration.record(Math.ceil(durationMs));
137
+ }
126
138
  }
@@ -52,6 +52,7 @@ export class ContractProviderForCpp implements ContractProvider {
52
52
  return serializeWithMessagePack(contractClass);
53
53
  };
54
54
 
55
+ // eslint-disable-next-line require-await
55
56
  public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
56
57
  this.log.trace(`Contract provider callback: addContracts`);
57
58
 
@@ -62,7 +63,7 @@ export class ContractProviderForCpp implements ContractProvider {
62
63
 
63
64
  // Add contracts to the contracts DB
64
65
  this.log.trace(`Calling contractsDB.addContracts`);
65
- await this.contractsDB.addContracts(contractDeploymentData);
66
+ this.contractsDB.addContracts(contractDeploymentData);
66
67
  };
67
68
 
68
69
  public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
@@ -1,4 +1,4 @@
1
- import { type Logger, type LoggerBindings, createLogger, logLevel } from '@aztec/foundation/log';
1
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
2
2
  import { sleep } from '@aztec/foundation/sleep';
3
3
  import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
4
4
  import { ProtocolContractsList } from '@aztec/protocol-contracts';
@@ -100,8 +100,7 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
100
100
  inputBuffer,
101
101
  contractProvider,
102
102
  wsCppHandle,
103
- logLevel,
104
- // TODO: re-enable logging
103
+ this.log.level,
105
104
  undefined,
106
105
  this.cancellationToken,
107
106
  );
@@ -1,4 +1,4 @@
1
- import { type Logger, type LoggerBindings, createLogger, logLevel } from '@aztec/foundation/log';
1
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
2
2
  import { avmSimulateWithHintedDbs } from '@aztec/native';
3
3
  import {
4
4
  AvmCircuitInputs,
@@ -75,7 +75,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
75
75
 
76
76
  let resultBuffer: Buffer;
77
77
  try {
78
- resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, logLevel);
78
+ resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, this.log.level);
79
79
  } catch (error: any) {
80
80
  throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
81
81
  }
@@ -19,10 +19,11 @@ export function createPublicTxSimulatorForBlockBuilding(
19
19
  globalVariables: GlobalVariables,
20
20
  telemetryClient: TelemetryClient,
21
21
  bindings?: LoggerBindings,
22
+ collectDebugLogs = false,
22
23
  ) {
23
24
  const config = PublicSimulatorConfig.from({
24
25
  skipFeeEnforcement: false,
25
- collectDebugLogs: false,
26
+ collectDebugLogs,
26
27
  collectHints: false,
27
28
  collectPublicInputs: false,
28
29
  collectStatistics: false,