@aztec/aztec 0.0.1-commit.2b2662070 → 0.0.1-commit.2c0ee1788

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 (53) hide show
  1. package/dest/cli/aztec_start_action.d.ts +1 -1
  2. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  3. package/dest/cli/aztec_start_action.js +2 -3
  4. package/dest/cli/aztec_start_options.d.ts +1 -1
  5. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  6. package/dest/cli/aztec_start_options.js +6 -6
  7. package/dest/cli/cmds/compile.d.ts +1 -1
  8. package/dest/cli/cmds/compile.d.ts.map +1 -1
  9. package/dest/cli/cmds/compile.js +1 -14
  10. package/dest/cli/cmds/profile.d.ts +1 -1
  11. package/dest/cli/cmds/profile.d.ts.map +1 -1
  12. package/dest/cli/cmds/profile.js +1 -1
  13. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  14. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  15. package/dest/cli/cmds/profile_gates.js +21 -3
  16. package/dest/cli/cmds/start_prover_agent.js +2 -2
  17. package/dest/cli/cmds/start_prover_broker.js +2 -2
  18. package/dest/cli/cmds/start_txe.d.ts +2 -2
  19. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  20. package/dest/cli/cmds/start_txe.js +4 -3
  21. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +2 -2
  22. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -1
  23. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +33 -12
  24. package/dest/testing/anvil_test_watcher.d.ts +7 -3
  25. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  26. package/dest/testing/anvil_test_watcher.js +39 -13
  27. package/dest/testing/index.d.ts +2 -2
  28. package/dest/testing/index.d.ts.map +1 -1
  29. package/package.json +33 -33
  30. package/scripts/add_crate.sh +8 -58
  31. package/scripts/aztec.sh +5 -1
  32. package/scripts/init.sh +5 -5
  33. package/scripts/new.sh +2 -2
  34. package/scripts/setup_workspace.sh +3 -2
  35. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  36. package/scripts/templates/blank/contract/src/main.nr +10 -0
  37. package/scripts/templates/blank/test/Nargo.toml +7 -0
  38. package/scripts/templates/blank/test/src/lib.nr +11 -0
  39. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  40. package/scripts/templates/counter/contract/src/main.nr +48 -0
  41. package/scripts/templates/counter/test/Nargo.toml +7 -0
  42. package/scripts/templates/counter/test/src/lib.nr +32 -0
  43. package/src/cli/aztec_start_action.ts +2 -3
  44. package/src/cli/aztec_start_options.ts +7 -9
  45. package/src/cli/cmds/compile.ts +1 -17
  46. package/src/cli/cmds/profile.ts +2 -1
  47. package/src/cli/cmds/profile_gates.ts +20 -4
  48. package/src/cli/cmds/start_prover_agent.ts +2 -2
  49. package/src/cli/cmds/start_prover_broker.ts +2 -2
  50. package/src/cli/cmds/start_txe.ts +5 -3
  51. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +35 -12
  52. package/src/testing/anvil_test_watcher.ts +43 -12
  53. package/src/testing/index.ts +1 -1
@@ -9,6 +9,11 @@ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
9
9
 
10
10
  import { type GetContractReturnType, getAddress, getContract } from 'viem';
11
11
 
12
+ export type AnvilTestWatcherOpts = {
13
+ isLocalNetwork?: boolean;
14
+ isMarkingAsProven?: boolean;
15
+ };
16
+
12
17
  /**
13
18
  * Represents a watcher for a rollup contract.
14
19
  *
@@ -17,7 +22,8 @@ import { type GetContractReturnType, getAddress, getContract } from 'viem';
17
22
  * block within the slot. And if so, it will time travel into the next slot.
18
23
  */
19
24
  export class AnvilTestWatcher {
20
- private isLocalNetwork: boolean = false;
25
+ private isLocalNetwork;
26
+ private isMarkingAsProven;
21
27
 
22
28
  private rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
23
29
  private rollupCheatCodes: RollupCheatCodes;
@@ -29,8 +35,6 @@ export class AnvilTestWatcher {
29
35
 
30
36
  private logger: Logger = createLogger(`aztecjs:utils:watcher`);
31
37
 
32
- private isMarkingAsProven = true;
33
-
34
38
  // Optional callback to check if there are pending txs in the mempool.
35
39
  private getPendingTxCount?: () => Promise<number>;
36
40
 
@@ -45,6 +49,7 @@ export class AnvilTestWatcher {
45
49
  rollupAddress: EthAddress,
46
50
  l1Client: ViemClient,
47
51
  private dateProvider?: TestDateProvider,
52
+ opts: AnvilTestWatcherOpts = {},
48
53
  ) {
49
54
  this.rollup = getContract({
50
55
  address: getAddress(rollupAddress.toString()),
@@ -56,6 +61,9 @@ export class AnvilTestWatcher {
56
61
  rollupAddress,
57
62
  });
58
63
 
64
+ this.isLocalNetwork = opts.isLocalNetwork ?? false;
65
+ this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
66
+
59
67
  this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
60
68
  }
61
69
 
@@ -136,8 +144,15 @@ export class AnvilTestWatcher {
136
144
  this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
137
145
  this.dateProvider.setTime(l1Time);
138
146
  } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
139
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
140
- await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
147
+ // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
148
+ // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
149
+ // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
150
+ // a second apart and one of them is then rejected by anvil as non-monotonic.
151
+ const wallSec = Math.floor(wallTime / 1000);
152
+ const targetSlot = await this.rollup.read.getSlotAt([BigInt(wallSec)]);
153
+ const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([targetSlot]));
154
+ this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
155
+ await this.warpToTimestamp(targetTimestamp);
141
156
  }
142
157
  }
143
158
 
@@ -151,8 +166,9 @@ export class AnvilTestWatcher {
151
166
 
152
167
  if (BigInt(currentSlot) === checkpointLog.slotNumber) {
153
168
  // The current slot has been filled, we should jump to the next slot.
154
- await this.warpToTimestamp(nextSlotTimestamp);
155
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
169
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
170
+ this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
171
+ }
156
172
  return;
157
173
  }
158
174
 
@@ -180,9 +196,10 @@ export class AnvilTestWatcher {
180
196
  }
181
197
 
182
198
  if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
183
- await this.warpToTimestamp(nextSlotTimestamp);
199
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
200
+ this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
201
+ }
184
202
  this.unfilledSlotFirstSeen = undefined;
185
- this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
186
203
  }
187
204
 
188
205
  return;
@@ -192,19 +209,33 @@ export class AnvilTestWatcher {
192
209
  // Fallback: warp when the dateProvider time has passed the next slot timestamp.
193
210
  const currentTimestamp = this.dateProvider?.now() ?? Date.now();
194
211
  if (currentTimestamp > nextSlotTimestamp * 1000) {
195
- await this.warpToTimestamp(nextSlotTimestamp);
196
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
212
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
213
+ this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
214
+ }
197
215
  }
198
216
  } catch {
199
217
  this.logger.error('mineIfSlotFilled failed');
200
218
  }
201
219
  }
202
220
 
203
- private async warpToTimestamp(timestamp: number) {
221
+ /**
222
+ * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
223
+ * happened, false when skipped or on error. Callers use the return value to gate success logs.
224
+ */
225
+ private async warpToTimestamp(timestamp: number): Promise<boolean> {
204
226
  try {
227
+ // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
228
+ // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
229
+ // letting the second one error out noisily.
230
+ const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
231
+ if (timestamp <= lastTimestamp) {
232
+ return false;
233
+ }
205
234
  await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
235
+ return true;
206
236
  } catch (e) {
207
237
  this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
238
+ return false;
208
239
  }
209
240
  }
210
241
  }
@@ -1,4 +1,4 @@
1
- export { AnvilTestWatcher } from './anvil_test_watcher.js';
1
+ export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
2
2
  export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
3
3
  export { CheatCodes } from './cheat_codes.js';
4
4
  export { EpochTestSettler } from './epoch_test_settler.js';