@aztec/aztec 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f

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 (115) hide show
  1. package/dest/bin/index.js +3 -1
  2. package/dest/cli/aztec_start_action.d.ts +1 -1
  3. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  4. package/dest/cli/aztec_start_action.js +16 -34
  5. package/dest/cli/aztec_start_options.d.ts +2 -2
  6. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_options.js +9 -16
  8. package/dest/cli/cmds/compile.d.ts +1 -1
  9. package/dest/cli/cmds/compile.d.ts.map +1 -1
  10. package/dest/cli/cmds/compile.js +30 -24
  11. package/dest/cli/cmds/profile.d.ts +1 -1
  12. package/dest/cli/cmds/profile.d.ts.map +1 -1
  13. package/dest/cli/cmds/profile.js +1 -1
  14. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  15. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  16. package/dest/cli/cmds/profile_gates.js +21 -3
  17. package/dest/cli/cmds/prover.d.ts +4 -0
  18. package/dest/cli/cmds/prover.d.ts.map +1 -0
  19. package/dest/cli/cmds/prover.js +24 -0
  20. package/dest/cli/cmds/standby.d.ts +30 -6
  21. package/dest/cli/cmds/standby.d.ts.map +1 -1
  22. package/dest/cli/cmds/standby.js +48 -5
  23. package/dest/cli/cmds/start_bot.d.ts +1 -1
  24. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  25. package/dest/cli/cmds/start_bot.js +8 -4
  26. package/dest/cli/cmds/start_node.d.ts +1 -1
  27. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  28. package/dest/cli/cmds/start_node.js +19 -32
  29. package/dest/cli/cmds/start_prover_agent.js +2 -2
  30. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  31. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  32. package/dest/cli/cmds/start_prover_broker.js +11 -8
  33. package/dest/cli/cmds/start_txe.d.ts +2 -2
  34. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  35. package/dest/cli/cmds/start_txe.js +6 -5
  36. package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
  37. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
  38. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +2 -2
  39. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -1
  40. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +35 -15
  41. package/dest/cli/util.d.ts +10 -5
  42. package/dest/cli/util.d.ts.map +1 -1
  43. package/dest/cli/util.js +29 -56
  44. package/dest/examples/token.js +3 -3
  45. package/dest/local-network/auth_registry.d.ts +5 -0
  46. package/dest/local-network/auth_registry.d.ts.map +1 -0
  47. package/dest/local-network/auth_registry.js +17 -0
  48. package/dest/local-network/banana_fpc.d.ts +3 -2
  49. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  50. package/dest/local-network/banana_fpc.js +11 -7
  51. package/dest/local-network/local-network.d.ts +10 -32
  52. package/dest/local-network/local-network.d.ts.map +1 -1
  53. package/dest/local-network/local-network.js +52 -73
  54. package/dest/testing/cheat_codes.d.ts +16 -18
  55. package/dest/testing/cheat_codes.d.ts.map +1 -1
  56. package/dest/testing/cheat_codes.js +17 -45
  57. package/dest/testing/epoch_test_settler.d.ts +2 -2
  58. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  59. package/dest/testing/epoch_test_settler.js +6 -25
  60. package/dest/testing/index.d.ts +2 -2
  61. package/dest/testing/index.d.ts.map +1 -1
  62. package/dest/testing/index.js +1 -1
  63. package/dest/testing/local-network.d.ts +51 -0
  64. package/dest/testing/local-network.d.ts.map +1 -0
  65. package/dest/testing/local-network.js +60 -0
  66. package/dest/testing/token_allowed_setup.d.ts +9 -4
  67. package/dest/testing/token_allowed_setup.d.ts.map +1 -1
  68. package/dest/testing/token_allowed_setup.js +12 -8
  69. package/package.json +34 -34
  70. package/scripts/add_crate.sh +11 -60
  71. package/scripts/aztec.sh +7 -4
  72. package/scripts/init.sh +5 -5
  73. package/scripts/new.sh +2 -2
  74. package/scripts/setup_workspace.sh +3 -2
  75. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  76. package/scripts/templates/blank/contract/src/main.nr +10 -0
  77. package/scripts/templates/blank/test/Nargo.toml +7 -0
  78. package/scripts/templates/blank/test/src/lib.nr +11 -0
  79. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  80. package/scripts/templates/counter/contract/src/main.nr +48 -0
  81. package/scripts/templates/counter/test/Nargo.toml +7 -0
  82. package/scripts/templates/counter/test/src/lib.nr +32 -0
  83. package/src/bin/index.ts +3 -1
  84. package/src/cli/aztec_start_action.ts +14 -21
  85. package/src/cli/aztec_start_options.ts +16 -24
  86. package/src/cli/cmds/compile.ts +35 -24
  87. package/src/cli/cmds/profile.ts +2 -1
  88. package/src/cli/cmds/profile_gates.ts +20 -4
  89. package/src/cli/cmds/prover.ts +42 -0
  90. package/src/cli/cmds/standby.ts +59 -7
  91. package/src/cli/cmds/start_bot.ts +9 -6
  92. package/src/cli/cmds/start_node.ts +22 -32
  93. package/src/cli/cmds/start_prover_agent.ts +2 -2
  94. package/src/cli/cmds/start_prover_broker.ts +10 -11
  95. package/src/cli/cmds/start_txe.ts +7 -5
  96. package/src/cli/cmds/utils/artifacts.ts +5 -0
  97. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +37 -15
  98. package/src/cli/util.ts +29 -70
  99. package/src/examples/token.ts +11 -3
  100. package/src/local-network/auth_registry.ts +19 -0
  101. package/src/local-network/banana_fpc.ts +12 -8
  102. package/src/local-network/local-network.ts +61 -83
  103. package/src/testing/cheat_codes.ts +17 -54
  104. package/src/testing/epoch_test_settler.ts +8 -31
  105. package/src/testing/index.ts +1 -1
  106. package/src/testing/local-network.ts +97 -0
  107. package/src/testing/token_allowed_setup.ts +15 -8
  108. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  109. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  110. package/dest/cli/cmds/start_archiver.js +0 -48
  111. package/dest/testing/anvil_test_watcher.d.ts +0 -42
  112. package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
  113. package/dest/testing/anvil_test_watcher.js +0 -207
  114. package/src/cli/cmds/start_archiver.ts +0 -50
  115. package/src/testing/anvil_test_watcher.ts +0 -233
@@ -1,42 +0,0 @@
1
- import { EthCheatCodes } from '@aztec/ethereum/test';
2
- import type { ViemClient } from '@aztec/ethereum/types';
3
- import type { EthAddress } from '@aztec/foundation/eth-address';
4
- import type { TestDateProvider } from '@aztec/foundation/timer';
5
- /**
6
- * Represents a watcher for a rollup contract.
7
- *
8
- * It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
9
- * it will periodically check if the current slot have already been filled, e.g., there was an L2
10
- * block within the slot. And if so, it will time travel into the next slot.
11
- */
12
- export declare class AnvilTestWatcher {
13
- private cheatcodes;
14
- private dateProvider?;
15
- private isLocalNetwork;
16
- private rollup;
17
- private rollupCheatCodes;
18
- private l2SlotDuration;
19
- private filledRunningPromise?;
20
- private syncDateProviderPromise?;
21
- private markingAsProvenRunningPromise?;
22
- private logger;
23
- private isMarkingAsProven;
24
- private getPendingTxCount?;
25
- private isSequencerBuilding?;
26
- private unfilledSlotFirstSeen?;
27
- constructor(cheatcodes: EthCheatCodes, rollupAddress: EthAddress, l1Client: ViemClient, dateProvider?: TestDateProvider | undefined);
28
- setIsMarkingAsProven(isMarkingAsProven: boolean): void;
29
- setisLocalNetwork(isLocalNetwork: boolean): void;
30
- /** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
31
- setGetPendingTxCount(fn: () => Promise<number>): void;
32
- /** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
33
- setIsSequencerBuilding(fn: () => boolean): void;
34
- start(): Promise<void>;
35
- stop(): Promise<void>;
36
- trigger(): Promise<void>;
37
- markAsProven(): Promise<void>;
38
- syncDateProviderToL1IfBehind(): Promise<void>;
39
- warpTimeIfNeeded(): Promise<void>;
40
- private warpToTimestamp;
41
- }
42
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW52aWxfdGVzdF93YXRjaGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdGluZy9hbnZpbF90ZXN0X3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBb0IsTUFBTSxzQkFBc0IsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUV4RCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUdoRSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBS2hFOzs7Ozs7R0FNRztBQUNILHFCQUFhLGdCQUFnQjtJQXlCekIsT0FBTyxDQUFDLFVBQVU7SUFHbEIsT0FBTyxDQUFDLFlBQVksQ0FBQztJQTNCdkIsT0FBTyxDQUFDLGNBQWMsQ0FBa0I7SUFFeEMsT0FBTyxDQUFDLE1BQU0sQ0FBc0Q7SUFDcEUsT0FBTyxDQUFDLGdCQUFnQixDQUFtQjtJQUMzQyxPQUFPLENBQUMsY0FBYyxDQUFVO0lBRWhDLE9BQU8sQ0FBQyxvQkFBb0IsQ0FBQyxDQUFpQjtJQUM5QyxPQUFPLENBQUMsdUJBQXVCLENBQUMsQ0FBaUI7SUFDakQsT0FBTyxDQUFDLDZCQUE2QixDQUFDLENBQWlCO0lBRXZELE9BQU8sQ0FBQyxNQUFNLENBQWlEO0lBRS9ELE9BQU8sQ0FBQyxpQkFBaUIsQ0FBUTtJQUdqQyxPQUFPLENBQUMsaUJBQWlCLENBQUMsQ0FBd0I7SUFHbEQsT0FBTyxDQUFDLG1CQUFtQixDQUFDLENBQWdCO0lBRzVDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBQyxDQUFxQztJQUVuRSxZQUNVLFVBQVUsRUFBRSxhQUFhLEVBQ2pDLGFBQWEsRUFBRSxVQUFVLEVBQ3pCLFFBQVEsRUFBRSxVQUFVLEVBQ1osWUFBWSxDQUFDLDhCQUFrQixFQWF4QztJQUVELG9CQUFvQixDQUFDLGlCQUFpQixFQUFFLE9BQU8sUUFHOUM7SUFFRCxpQkFBaUIsQ0FBQyxjQUFjLEVBQUUsT0FBTyxRQUV4QztJQUVELHlHQUF5RztJQUN6RyxvQkFBb0IsQ0FBQyxFQUFFLEVBQUUsTUFBTSxPQUFPLENBQUMsTUFBTSxDQUFDLFFBRTdDO0lBRUQsdUdBQXVHO0lBQ3ZHLHNCQUFzQixDQUFDLEVBQUUsRUFBRSxNQUFNLE9BQU8sUUFFdkM7SUFFSyxLQUFLLGtCQXlCVjtJQUVLLElBQUksa0JBSVQ7SUFFSyxPQUFPLGtCQUlaO0lBRUssWUFBWSxrQkFLakI7SUFFSyw0QkFBNEIsa0JBc0JqQztJQUVLLGdCQUFnQixrQkE0RHJCO1lBTWEsZUFBZTtDQWdCOUIifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"anvil_test_watcher.d.ts","sourceRoot":"","sources":["../../src/testing/anvil_test_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAyBzB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,YAAY,CAAC;IA3BvB,OAAO,CAAC,cAAc,CAAkB;IAExC,OAAO,CAAC,MAAM,CAAsD;IACpE,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,cAAc,CAAU;IAEhC,OAAO,CAAC,oBAAoB,CAAC,CAAiB;IAC9C,OAAO,CAAC,uBAAuB,CAAC,CAAiB;IACjD,OAAO,CAAC,6BAA6B,CAAC,CAAiB;IAEvD,OAAO,CAAC,MAAM,CAAiD;IAE/D,OAAO,CAAC,iBAAiB,CAAQ;IAGjC,OAAO,CAAC,iBAAiB,CAAC,CAAwB;IAGlD,OAAO,CAAC,mBAAmB,CAAC,CAAgB;IAG5C,OAAO,CAAC,qBAAqB,CAAC,CAAqC;IAEnE,YACU,UAAU,EAAE,aAAa,EACjC,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,UAAU,EACZ,YAAY,CAAC,8BAAkB,EAaxC;IAED,oBAAoB,CAAC,iBAAiB,EAAE,OAAO,QAG9C;IAED,iBAAiB,CAAC,cAAc,EAAE,OAAO,QAExC;IAED,yGAAyG;IACzG,oBAAoB,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAE7C;IAED,uGAAuG;IACvG,sBAAsB,CAAC,EAAE,EAAE,MAAM,OAAO,QAEvC;IAEK,KAAK,kBAyBV;IAEK,IAAI,kBAIT;IAEK,OAAO,kBAIZ;IAEK,YAAY,kBAKjB;IAEK,4BAA4B,kBAsBjC;IAEK,gBAAgB,kBA4DrB;YAMa,eAAe;CAgB9B"}
@@ -1,207 +0,0 @@
1
- import { RollupCheatCodes } from '@aztec/ethereum/test';
2
- import { SlotNumber } from '@aztec/foundation/branded-types';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { RunningPromise } from '@aztec/foundation/running-promise';
5
- import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
6
- import { getAddress, getContract } from 'viem';
7
- /**
8
- * Represents a watcher for a rollup contract.
9
- *
10
- * It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
11
- * it will periodically check if the current slot have already been filled, e.g., there was an L2
12
- * block within the slot. And if so, it will time travel into the next slot.
13
- */ export class AnvilTestWatcher {
14
- cheatcodes;
15
- dateProvider;
16
- isLocalNetwork;
17
- rollup;
18
- rollupCheatCodes;
19
- l2SlotDuration;
20
- filledRunningPromise;
21
- syncDateProviderPromise;
22
- markingAsProvenRunningPromise;
23
- logger;
24
- isMarkingAsProven;
25
- // Optional callback to check if there are pending txs in the mempool.
26
- getPendingTxCount;
27
- // Optional callback to check if the sequencer is actively building a block.
28
- isSequencerBuilding;
29
- // Tracks when we first observed the current unfilled slot with pending txs (real wall time).
30
- unfilledSlotFirstSeen;
31
- constructor(cheatcodes, rollupAddress, l1Client, dateProvider){
32
- this.cheatcodes = cheatcodes;
33
- this.dateProvider = dateProvider;
34
- this.isLocalNetwork = false;
35
- this.logger = createLogger(`aztecjs:utils:watcher`);
36
- this.isMarkingAsProven = true;
37
- this.rollup = getContract({
38
- address: getAddress(rollupAddress.toString()),
39
- abi: RollupAbi,
40
- client: l1Client
41
- });
42
- this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
43
- rollupAddress
44
- });
45
- this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
46
- }
47
- setIsMarkingAsProven(isMarkingAsProven) {
48
- this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
49
- this.isMarkingAsProven = isMarkingAsProven;
50
- }
51
- setisLocalNetwork(isLocalNetwork) {
52
- this.isLocalNetwork = isLocalNetwork;
53
- }
54
- /** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */ setGetPendingTxCount(fn) {
55
- this.getPendingTxCount = fn;
56
- }
57
- /** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */ setIsSequencerBuilding(fn) {
58
- this.isSequencerBuilding = fn;
59
- }
60
- async start() {
61
- if (this.filledRunningPromise) {
62
- throw new Error('Watcher already watching for filled slot');
63
- }
64
- const config = await this.rollupCheatCodes.getConfig();
65
- this.l2SlotDuration = config.slotDuration;
66
- // If auto mining is not supported (e.g., we are on a real network), then we
67
- // will simple do nothing. But if on an anvil or the like, this make sure that
68
- // the local network and tests don't break because time is frozen and we never get to
69
- // the next slot.
70
- const isAutoMining = await this.cheatcodes.isAutoMining();
71
- if (isAutoMining) {
72
- this.filledRunningPromise = new RunningPromise(()=>this.warpTimeIfNeeded(), this.logger, 200);
73
- this.filledRunningPromise.start();
74
- this.syncDateProviderPromise = new RunningPromise(()=>this.syncDateProviderToL1IfBehind(), this.logger, 200);
75
- this.syncDateProviderPromise.start();
76
- this.markingAsProvenRunningPromise = new RunningPromise(()=>this.markAsProven(), this.logger, 200);
77
- this.markingAsProvenRunningPromise.start();
78
- this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
79
- } else {
80
- this.logger.info(`Watcher not started because not auto mining`);
81
- }
82
- }
83
- async stop() {
84
- await this.filledRunningPromise?.stop();
85
- await this.syncDateProviderPromise?.stop();
86
- await this.markingAsProvenRunningPromise?.stop();
87
- }
88
- async trigger() {
89
- await this.filledRunningPromise?.trigger();
90
- await this.syncDateProviderPromise?.trigger();
91
- await this.markingAsProvenRunningPromise?.trigger();
92
- }
93
- async markAsProven() {
94
- if (!this.isMarkingAsProven) {
95
- return;
96
- }
97
- await this.rollupCheatCodes.markAsProven();
98
- }
99
- async syncDateProviderToL1IfBehind() {
100
- // this doesn't apply to the local network, because we don't have a date provider in the local network
101
- if (!this.dateProvider) {
102
- return;
103
- }
104
- const l1Time = await this.cheatcodes.lastBlockTimestamp() * 1000;
105
- const wallTime = this.dateProvider.now();
106
- if (l1Time > wallTime) {
107
- this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
108
- this.dateProvider.setTime(l1Time);
109
- } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
110
- // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
111
- // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
112
- // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
113
- // a second apart and one of them is then rejected by anvil as non-monotonic.
114
- const wallSec = Math.floor(wallTime / 1000);
115
- const targetSlot = await this.rollup.read.getSlotAt([
116
- BigInt(wallSec)
117
- ]);
118
- const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([
119
- targetSlot
120
- ]));
121
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
122
- await this.warpToTimestamp(targetTimestamp);
123
- }
124
- }
125
- async warpTimeIfNeeded() {
126
- try {
127
- const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
128
- const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
129
- const checkpointLog = await this.rollup.read.getCheckpoint([
130
- pendingCheckpointNumber
131
- ]);
132
- const nextSlot = SlotNumber(currentSlot + 1);
133
- const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
134
- BigInt(nextSlot)
135
- ]));
136
- if (BigInt(currentSlot) === checkpointLog.slotNumber) {
137
- // The current slot has been filled, we should jump to the next slot.
138
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
139
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
140
- }
141
- return;
142
- }
143
- // If we are not in local network, we don't need to warp time
144
- if (!this.isLocalNetwork) {
145
- return;
146
- }
147
- // If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
148
- // sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
149
- // the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
150
- // to avoid invalidating its in-progress work.
151
- if (this.getPendingTxCount) {
152
- const pendingTxs = await this.getPendingTxCount();
153
- if (pendingTxs > 0) {
154
- if (this.isSequencerBuilding?.()) {
155
- this.unfilledSlotFirstSeen = undefined;
156
- return;
157
- }
158
- const realNow = Date.now();
159
- if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
160
- this.unfilledSlotFirstSeen = {
161
- slot: currentSlot,
162
- realTime: realNow
163
- };
164
- return;
165
- }
166
- if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
167
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
168
- this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
169
- }
170
- this.unfilledSlotFirstSeen = undefined;
171
- }
172
- return;
173
- }
174
- }
175
- // Fallback: warp when the dateProvider time has passed the next slot timestamp.
176
- const currentTimestamp = this.dateProvider?.now() ?? Date.now();
177
- if (currentTimestamp > nextSlotTimestamp * 1000) {
178
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
179
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
180
- }
181
- }
182
- } catch {
183
- this.logger.error('mineIfSlotFilled failed');
184
- }
185
- }
186
- /**
187
- * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
188
- * happened, false when skipped or on error. Callers use the return value to gate success logs.
189
- */ async warpToTimestamp(timestamp) {
190
- try {
191
- // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
192
- // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
193
- // letting the second one error out noisily.
194
- const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
195
- if (timestamp <= lastTimestamp) {
196
- return false;
197
- }
198
- await this.cheatcodes.warp(timestamp, {
199
- resetBlockInterval: true
200
- });
201
- return true;
202
- } catch (e) {
203
- this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
204
- return false;
205
- }
206
- }
207
- }
@@ -1,50 +0,0 @@
1
- import { type ArchiverConfig, archiverConfigMappings, createArchiver, getArchiverConfigFromEnv } from '@aztec/archiver';
2
- import { createLogger } from '@aztec/aztec.js/log';
3
- import { type BlobClientConfig, blobClientConfigMapping, createBlobClient } from '@aztec/blob-client/client';
4
- import { getL1Config } from '@aztec/cli/config';
5
- import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
6
- import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
7
- import { ArchiverApiSchema } from '@aztec/stdlib/interfaces/server';
8
- import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
9
-
10
- import { extractRelevantOptions } from '../util.js';
11
-
12
- export type { ArchiverConfig, DataStoreConfig };
13
-
14
- /** Starts a standalone archiver. */
15
- export async function startArchiver(
16
- options: any,
17
- signalHandlers: (() => Promise<void>)[],
18
- services: NamespacedApiHandlers,
19
- ): Promise<{ config: ArchiverConfig & DataStoreConfig }> {
20
- const envConfig = getArchiverConfigFromEnv();
21
- const cliOptions = extractRelevantOptions<ArchiverConfig & DataStoreConfig & BlobClientConfig>(
22
- options,
23
- { ...archiverConfigMappings, ...dataConfigMappings, ...blobClientConfigMapping },
24
- 'archiver',
25
- );
26
-
27
- let archiverConfig = { ...envConfig, ...cliOptions };
28
- archiverConfig.dataStoreMapSizeKb = archiverConfig.archiverStoreMapSizeKb ?? archiverConfig.dataStoreMapSizeKb;
29
-
30
- if (!archiverConfig.l1Contracts.registryAddress || archiverConfig.l1Contracts.registryAddress.isZero()) {
31
- throw new Error('L1 registry address is required to start an Archiver');
32
- }
33
-
34
- const { addresses, config: l1Config } = await getL1Config(
35
- archiverConfig.l1Contracts.registryAddress,
36
- archiverConfig.l1RpcUrls,
37
- archiverConfig.l1ChainId,
38
- );
39
-
40
- archiverConfig.l1Contracts = addresses;
41
- archiverConfig = { ...archiverConfig, ...l1Config };
42
-
43
- const telemetry = await initTelemetryClient(getTelemetryClientConfig());
44
- const blobClient = createBlobClient(archiverConfig, { logger: createLogger('archiver:blob-client:client') });
45
- const archiver = await createArchiver(archiverConfig, { telemetry, blobClient }, { blockUntilSync: true });
46
- services.archiver = [archiver, ArchiverApiSchema];
47
- signalHandlers.push(archiver.stop);
48
-
49
- return { config: archiverConfig };
50
- }
@@ -1,233 +0,0 @@
1
- import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
- import type { ViemClient } from '@aztec/ethereum/types';
3
- import { SlotNumber } from '@aztec/foundation/branded-types';
4
- import type { EthAddress } from '@aztec/foundation/eth-address';
5
- import { type Logger, createLogger } from '@aztec/foundation/log';
6
- import { RunningPromise } from '@aztec/foundation/running-promise';
7
- import type { TestDateProvider } from '@aztec/foundation/timer';
8
- import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
9
-
10
- import { type GetContractReturnType, getAddress, getContract } from 'viem';
11
-
12
- /**
13
- * Represents a watcher for a rollup contract.
14
- *
15
- * It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
16
- * it will periodically check if the current slot have already been filled, e.g., there was an L2
17
- * block within the slot. And if so, it will time travel into the next slot.
18
- */
19
- export class AnvilTestWatcher {
20
- private isLocalNetwork: boolean = false;
21
-
22
- private rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
23
- private rollupCheatCodes: RollupCheatCodes;
24
- private l2SlotDuration!: number;
25
-
26
- private filledRunningPromise?: RunningPromise;
27
- private syncDateProviderPromise?: RunningPromise;
28
- private markingAsProvenRunningPromise?: RunningPromise;
29
-
30
- private logger: Logger = createLogger(`aztecjs:utils:watcher`);
31
-
32
- private isMarkingAsProven = true;
33
-
34
- // Optional callback to check if there are pending txs in the mempool.
35
- private getPendingTxCount?: () => Promise<number>;
36
-
37
- // Optional callback to check if the sequencer is actively building a block.
38
- private isSequencerBuilding?: () => boolean;
39
-
40
- // Tracks when we first observed the current unfilled slot with pending txs (real wall time).
41
- private unfilledSlotFirstSeen?: { slot: number; realTime: number };
42
-
43
- constructor(
44
- private cheatcodes: EthCheatCodes,
45
- rollupAddress: EthAddress,
46
- l1Client: ViemClient,
47
- private dateProvider?: TestDateProvider,
48
- ) {
49
- this.rollup = getContract({
50
- address: getAddress(rollupAddress.toString()),
51
- abi: RollupAbi,
52
- client: l1Client,
53
- });
54
-
55
- this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
56
- rollupAddress,
57
- });
58
-
59
- this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
60
- }
61
-
62
- setIsMarkingAsProven(isMarkingAsProven: boolean) {
63
- this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
64
- this.isMarkingAsProven = isMarkingAsProven;
65
- }
66
-
67
- setisLocalNetwork(isLocalNetwork: boolean) {
68
- this.isLocalNetwork = isLocalNetwork;
69
- }
70
-
71
- /** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
72
- setGetPendingTxCount(fn: () => Promise<number>) {
73
- this.getPendingTxCount = fn;
74
- }
75
-
76
- /** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
77
- setIsSequencerBuilding(fn: () => boolean) {
78
- this.isSequencerBuilding = fn;
79
- }
80
-
81
- async start() {
82
- if (this.filledRunningPromise) {
83
- throw new Error('Watcher already watching for filled slot');
84
- }
85
-
86
- const config = await this.rollupCheatCodes.getConfig();
87
- this.l2SlotDuration = config.slotDuration;
88
-
89
- // If auto mining is not supported (e.g., we are on a real network), then we
90
- // will simple do nothing. But if on an anvil or the like, this make sure that
91
- // the local network and tests don't break because time is frozen and we never get to
92
- // the next slot.
93
- const isAutoMining = await this.cheatcodes.isAutoMining();
94
-
95
- if (isAutoMining) {
96
- this.filledRunningPromise = new RunningPromise(() => this.warpTimeIfNeeded(), this.logger, 200);
97
- this.filledRunningPromise.start();
98
- this.syncDateProviderPromise = new RunningPromise(() => this.syncDateProviderToL1IfBehind(), this.logger, 200);
99
- this.syncDateProviderPromise.start();
100
- this.markingAsProvenRunningPromise = new RunningPromise(() => this.markAsProven(), this.logger, 200);
101
- this.markingAsProvenRunningPromise.start();
102
- this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
103
- } else {
104
- this.logger.info(`Watcher not started because not auto mining`);
105
- }
106
- }
107
-
108
- async stop() {
109
- await this.filledRunningPromise?.stop();
110
- await this.syncDateProviderPromise?.stop();
111
- await this.markingAsProvenRunningPromise?.stop();
112
- }
113
-
114
- async trigger() {
115
- await this.filledRunningPromise?.trigger();
116
- await this.syncDateProviderPromise?.trigger();
117
- await this.markingAsProvenRunningPromise?.trigger();
118
- }
119
-
120
- async markAsProven() {
121
- if (!this.isMarkingAsProven) {
122
- return;
123
- }
124
- await this.rollupCheatCodes.markAsProven();
125
- }
126
-
127
- async syncDateProviderToL1IfBehind() {
128
- // this doesn't apply to the local network, because we don't have a date provider in the local network
129
- if (!this.dateProvider) {
130
- return;
131
- }
132
-
133
- const l1Time = (await this.cheatcodes.lastBlockTimestamp()) * 1000;
134
- const wallTime = this.dateProvider.now();
135
- if (l1Time > wallTime) {
136
- this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
137
- this.dateProvider.setTime(l1Time);
138
- } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
139
- // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
140
- // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
141
- // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
142
- // a second apart and one of them is then rejected by anvil as non-monotonic.
143
- const wallSec = Math.floor(wallTime / 1000);
144
- const targetSlot = await this.rollup.read.getSlotAt([BigInt(wallSec)]);
145
- const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([targetSlot]));
146
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
147
- await this.warpToTimestamp(targetTimestamp);
148
- }
149
- }
150
-
151
- async warpTimeIfNeeded() {
152
- try {
153
- const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
154
- const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
155
- const checkpointLog = await this.rollup.read.getCheckpoint([pendingCheckpointNumber]);
156
- const nextSlot = SlotNumber(currentSlot + 1);
157
- const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]));
158
-
159
- if (BigInt(currentSlot) === checkpointLog.slotNumber) {
160
- // The current slot has been filled, we should jump to the next slot.
161
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
162
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
163
- }
164
- return;
165
- }
166
-
167
- // If we are not in local network, we don't need to warp time
168
- if (!this.isLocalNetwork) {
169
- return;
170
- }
171
-
172
- // If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
173
- // sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
174
- // the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
175
- // to avoid invalidating its in-progress work.
176
- if (this.getPendingTxCount) {
177
- const pendingTxs = await this.getPendingTxCount();
178
- if (pendingTxs > 0) {
179
- if (this.isSequencerBuilding?.()) {
180
- this.unfilledSlotFirstSeen = undefined;
181
- return;
182
- }
183
-
184
- const realNow = Date.now();
185
- if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
186
- this.unfilledSlotFirstSeen = { slot: currentSlot, realTime: realNow };
187
- return;
188
- }
189
-
190
- if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
191
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
192
- this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
193
- }
194
- this.unfilledSlotFirstSeen = undefined;
195
- }
196
-
197
- return;
198
- }
199
- }
200
-
201
- // Fallback: warp when the dateProvider time has passed the next slot timestamp.
202
- const currentTimestamp = this.dateProvider?.now() ?? Date.now();
203
- if (currentTimestamp > nextSlotTimestamp * 1000) {
204
- if (await this.warpToTimestamp(nextSlotTimestamp)) {
205
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
206
- }
207
- }
208
- } catch {
209
- this.logger.error('mineIfSlotFilled failed');
210
- }
211
- }
212
-
213
- /**
214
- * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
215
- * happened, false when skipped or on error. Callers use the return value to gate success logs.
216
- */
217
- private async warpToTimestamp(timestamp: number): Promise<boolean> {
218
- try {
219
- // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
220
- // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
221
- // letting the second one error out noisily.
222
- const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
223
- if (timestamp <= lastTimestamp) {
224
- return false;
225
- }
226
- await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
227
- return true;
228
- } catch (e) {
229
- this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
230
- return false;
231
- }
232
- }
233
- }