@aztec/aztec 0.0.1-commit.b9865e97 → 0.0.1-commit.be03c316
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.
- package/dest/bin/index.js +2 -0
- package/dest/cli/aztec_start_action.d.ts +1 -1
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +6 -27
- package/dest/cli/aztec_start_options.js +1 -1
- package/dest/cli/cmds/compile.d.ts +1 -1
- package/dest/cli/cmds/compile.d.ts.map +1 -1
- package/dest/cli/cmds/compile.js +25 -17
- package/dest/cli/cmds/prover.d.ts +4 -0
- package/dest/cli/cmds/prover.d.ts.map +1 -0
- package/dest/cli/cmds/prover.js +24 -0
- package/dest/cli/cmds/standby.d.ts +28 -2
- package/dest/cli/cmds/standby.d.ts.map +1 -1
- package/dest/cli/cmds/standby.js +45 -2
- package/dest/cli/cmds/start_bot.d.ts +1 -1
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +5 -1
- package/dest/cli/cmds/start_node.d.ts +1 -1
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +14 -23
- package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
- package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
- package/dest/cli/util.d.ts +10 -5
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +20 -49
- package/dest/examples/token.js +3 -3
- package/dest/local-network/local-network.d.ts +6 -5
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +33 -76
- package/dest/testing/cheat_codes.d.ts +16 -23
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/cheat_codes.js +20 -82
- package/dest/testing/epoch_test_settler.d.ts +2 -2
- package/dest/testing/epoch_test_settler.d.ts.map +1 -1
- package/dest/testing/epoch_test_settler.js +5 -26
- package/dest/testing/index.d.ts +2 -2
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -1
- package/dest/testing/local-network.d.ts +51 -0
- package/dest/testing/local-network.d.ts.map +1 -0
- package/dest/testing/local-network.js +60 -0
- package/dest/testing/token_allowed_setup.d.ts +9 -4
- package/dest/testing/token_allowed_setup.d.ts.map +1 -1
- package/dest/testing/token_allowed_setup.js +12 -8
- package/package.json +34 -34
- package/scripts/templates/counter/contract/src/main.nr +4 -4
- package/src/bin/index.ts +2 -0
- package/src/cli/aztec_start_action.ts +3 -14
- package/src/cli/aztec_start_options.ts +1 -1
- package/src/cli/cmds/compile.ts +29 -16
- package/src/cli/cmds/prover.ts +42 -0
- package/src/cli/cmds/standby.ts +55 -3
- package/src/cli/cmds/start_bot.ts +6 -1
- package/src/cli/cmds/start_node.ts +17 -23
- package/src/cli/cmds/utils/artifacts.ts +5 -0
- package/src/cli/util.ts +21 -62
- package/src/examples/token.ts +11 -3
- package/src/local-network/local-network.ts +40 -88
- package/src/testing/cheat_codes.ts +19 -103
- package/src/testing/epoch_test_settler.ts +8 -30
- package/src/testing/index.ts +1 -1
- package/src/testing/local-network.ts +97 -0
- package/src/testing/token_allowed_setup.ts +15 -8
- package/dest/testing/anvil_test_watcher.d.ts +0 -54
- package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
- package/dest/testing/anvil_test_watcher.js +0 -235
- package/src/testing/anvil_test_watcher.ts +0 -273
|
@@ -1,273 +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
|
-
export type AnvilTestWatcherOpts = {
|
|
13
|
-
isLocalNetwork?: boolean;
|
|
14
|
-
isMarkingAsProven?: boolean;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Represents a watcher for a rollup contract.
|
|
19
|
-
*
|
|
20
|
-
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
|
|
21
|
-
* it will periodically check if the current slot have already been filled, e.g., there was an L2
|
|
22
|
-
* block within the slot. And if so, it will time travel into the next slot.
|
|
23
|
-
*/
|
|
24
|
-
export class AnvilTestWatcher {
|
|
25
|
-
private isLocalNetwork;
|
|
26
|
-
private isMarkingAsProven;
|
|
27
|
-
|
|
28
|
-
private rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
29
|
-
private rollupCheatCodes: RollupCheatCodes;
|
|
30
|
-
private l2SlotDuration!: number;
|
|
31
|
-
|
|
32
|
-
private filledRunningPromise?: RunningPromise;
|
|
33
|
-
private syncDateProviderPromise?: RunningPromise;
|
|
34
|
-
private markingAsProvenRunningPromise?: RunningPromise;
|
|
35
|
-
|
|
36
|
-
private logger: Logger = createLogger(`aztecjs:utils:watcher`);
|
|
37
|
-
|
|
38
|
-
// Optional callback to check if there are pending txs in the mempool.
|
|
39
|
-
private getPendingTxCount?: () => Promise<number>;
|
|
40
|
-
|
|
41
|
-
// Optional callback to check if the sequencer is actively building a block.
|
|
42
|
-
private isSequencerBuilding?: () => boolean;
|
|
43
|
-
|
|
44
|
-
// Tracks when we first observed the current unfilled slot with pending txs (real wall time).
|
|
45
|
-
private unfilledSlotFirstSeen?: { slot: number; realTime: number };
|
|
46
|
-
|
|
47
|
-
// Latest target slot for which the proposer has built a block destined for L1 but which has
|
|
48
|
-
// not yet been committed. Set by the proposer-pipelining hook from `block-proposed` events so
|
|
49
|
-
// the watcher can advance L1 (and the injected date provider) to the target slot ahead of the
|
|
50
|
-
// publisher's `sendRequestsAt` sleep, instead of waiting a full wall-clock slot.
|
|
51
|
-
private proposedTargetSlot?: number;
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
private cheatcodes: EthCheatCodes,
|
|
55
|
-
rollupAddress: EthAddress,
|
|
56
|
-
l1Client: ViemClient,
|
|
57
|
-
private dateProvider?: TestDateProvider,
|
|
58
|
-
opts: AnvilTestWatcherOpts = {},
|
|
59
|
-
) {
|
|
60
|
-
this.rollup = getContract({
|
|
61
|
-
address: getAddress(rollupAddress.toString()),
|
|
62
|
-
abi: RollupAbi,
|
|
63
|
-
client: l1Client,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
|
|
67
|
-
rollupAddress,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
this.isLocalNetwork = opts.isLocalNetwork ?? false;
|
|
71
|
-
this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
|
|
72
|
-
|
|
73
|
-
this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setIsMarkingAsProven(isMarkingAsProven: boolean) {
|
|
77
|
-
this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
|
|
78
|
-
this.isMarkingAsProven = isMarkingAsProven;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setisLocalNetwork(isLocalNetwork: boolean) {
|
|
82
|
-
this.isLocalNetwork = isLocalNetwork;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
|
|
86
|
-
setGetPendingTxCount(fn: () => Promise<number>) {
|
|
87
|
-
this.getPendingTxCount = fn;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
|
|
91
|
-
setIsSequencerBuilding(fn: () => boolean) {
|
|
92
|
-
this.isSequencerBuilding = fn;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Records the target slot for which the proposer has built a block destined for L1. Used by
|
|
97
|
-
* the local-network watcher to fast-forward L1 (and the injected date provider) ahead of the
|
|
98
|
-
* pipelined publisher's `sendRequestsAt` sleep so it ends promptly instead of waiting a full
|
|
99
|
-
* wall-clock slot. Only ratchets up — late warps for stale slots are no-ops.
|
|
100
|
-
*/
|
|
101
|
-
setProposedTargetSlot(slot: number) {
|
|
102
|
-
if (this.proposedTargetSlot === undefined || slot > this.proposedTargetSlot) {
|
|
103
|
-
this.proposedTargetSlot = slot;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async start() {
|
|
108
|
-
if (this.filledRunningPromise) {
|
|
109
|
-
throw new Error('Watcher already watching for filled slot');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const config = await this.rollupCheatCodes.getConfig();
|
|
113
|
-
this.l2SlotDuration = config.slotDuration;
|
|
114
|
-
|
|
115
|
-
// If auto mining is not supported (e.g., we are on a real network), then we
|
|
116
|
-
// will simple do nothing. But if on an anvil or the like, this make sure that
|
|
117
|
-
// the local network and tests don't break because time is frozen and we never get to
|
|
118
|
-
// the next slot.
|
|
119
|
-
const isAutoMining = await this.cheatcodes.isAutoMining();
|
|
120
|
-
|
|
121
|
-
if (isAutoMining) {
|
|
122
|
-
this.filledRunningPromise = new RunningPromise(() => this.warpTimeIfNeeded(), this.logger, 200);
|
|
123
|
-
this.filledRunningPromise.start();
|
|
124
|
-
this.syncDateProviderPromise = new RunningPromise(() => this.syncDateProviderToL1IfBehind(), this.logger, 200);
|
|
125
|
-
this.syncDateProviderPromise.start();
|
|
126
|
-
this.markingAsProvenRunningPromise = new RunningPromise(() => this.markAsProven(), this.logger, 200);
|
|
127
|
-
this.markingAsProvenRunningPromise.start();
|
|
128
|
-
this.logger.info(`Watcher started for rollup at ${this.rollup.address}`);
|
|
129
|
-
} else {
|
|
130
|
-
this.logger.info(`Watcher not started because not auto mining`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async stop() {
|
|
135
|
-
await this.filledRunningPromise?.stop();
|
|
136
|
-
await this.syncDateProviderPromise?.stop();
|
|
137
|
-
await this.markingAsProvenRunningPromise?.stop();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async trigger() {
|
|
141
|
-
await this.filledRunningPromise?.trigger();
|
|
142
|
-
await this.syncDateProviderPromise?.trigger();
|
|
143
|
-
await this.markingAsProvenRunningPromise?.trigger();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async markAsProven() {
|
|
147
|
-
if (!this.isMarkingAsProven) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
await this.rollupCheatCodes.markAsProven();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async syncDateProviderToL1IfBehind() {
|
|
154
|
-
// this doesn't apply to the local network, because we don't have a date provider in the local network
|
|
155
|
-
if (!this.dateProvider) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const l1Time = (await this.cheatcodes.lastBlockTimestamp()) * 1000;
|
|
160
|
-
const wallTime = this.dateProvider.now();
|
|
161
|
-
if (l1Time > wallTime) {
|
|
162
|
-
this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
|
|
163
|
-
this.dateProvider.setTime(l1Time);
|
|
164
|
-
} else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
|
|
165
|
-
// Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
|
|
166
|
-
// `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
|
|
167
|
-
// `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
|
|
168
|
-
// a second apart and one of them is then rejected by anvil as non-monotonic.
|
|
169
|
-
const wallSec = Math.floor(wallTime / 1000);
|
|
170
|
-
const targetSlot = await this.rollup.read.getSlotAt([BigInt(wallSec)]);
|
|
171
|
-
const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([targetSlot]));
|
|
172
|
-
this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
|
|
173
|
-
await this.warpToTimestamp(targetTimestamp);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async warpTimeIfNeeded() {
|
|
178
|
-
try {
|
|
179
|
-
const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
180
|
-
const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
|
|
181
|
-
const checkpointLog = await this.rollup.read.getCheckpoint([pendingCheckpointNumber]);
|
|
182
|
-
const nextSlot = SlotNumber(currentSlot + 1);
|
|
183
|
-
const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]));
|
|
184
|
-
|
|
185
|
-
if (BigInt(currentSlot) === checkpointLog.slotNumber) {
|
|
186
|
-
// The current slot has been filled, we should jump to the next slot.
|
|
187
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
188
|
-
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// If we are not in local network, we don't need to warp time
|
|
194
|
-
if (!this.isLocalNetwork) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Pipelined-publish shortcut: if the proposer has built a block destined for a slot
|
|
199
|
-
// beyond the current L1 slot, fast-forward L1 to that slot's timestamp so the publisher's
|
|
200
|
-
// `sendRequestsAt(targetSlot)` sleep ends and the multicall mines inside the target slot.
|
|
201
|
-
// Without this, the publisher waits up to a full real-time slot for wall clock to catch up.
|
|
202
|
-
if (this.proposedTargetSlot !== undefined && this.proposedTargetSlot > currentSlot) {
|
|
203
|
-
const targetSlotTimestamp = Number(
|
|
204
|
-
await this.rollup.read.getTimestampForSlot([BigInt(this.proposedTargetSlot)]),
|
|
205
|
-
);
|
|
206
|
-
if (await this.warpToTimestamp(targetSlotTimestamp)) {
|
|
207
|
-
this.logger.info(`Warped L1 to target slot ${this.proposedTargetSlot} for pipelined publish`);
|
|
208
|
-
}
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
|
|
213
|
-
// sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
|
|
214
|
-
// the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
|
|
215
|
-
// to avoid invalidating its in-progress work.
|
|
216
|
-
if (this.getPendingTxCount) {
|
|
217
|
-
const pendingTxs = await this.getPendingTxCount();
|
|
218
|
-
if (pendingTxs > 0) {
|
|
219
|
-
if (this.isSequencerBuilding?.()) {
|
|
220
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const realNow = Date.now();
|
|
225
|
-
if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
|
|
226
|
-
this.unfilledSlotFirstSeen = { slot: currentSlot, realTime: realNow };
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
|
|
231
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
232
|
-
this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
|
|
233
|
-
}
|
|
234
|
-
this.unfilledSlotFirstSeen = undefined;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Fallback: warp when the dateProvider time has passed the next slot timestamp.
|
|
242
|
-
const currentTimestamp = this.dateProvider?.now() ?? Date.now();
|
|
243
|
-
if (currentTimestamp > nextSlotTimestamp * 1000) {
|
|
244
|
-
if (await this.warpToTimestamp(nextSlotTimestamp)) {
|
|
245
|
-
this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
} catch {
|
|
249
|
-
this.logger.error('mineIfSlotFilled failed');
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
|
|
255
|
-
* happened, false when skipped or on error. Callers use the return value to gate success logs.
|
|
256
|
-
*/
|
|
257
|
-
private async warpToTimestamp(timestamp: number): Promise<boolean> {
|
|
258
|
-
try {
|
|
259
|
-
// Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
|
|
260
|
-
// watcher loops can race and pick targets a fraction of a second apart; skip here rather than
|
|
261
|
-
// letting the second one error out noisily.
|
|
262
|
-
const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
|
|
263
|
-
if (timestamp <= lastTimestamp) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
|
|
267
|
-
return true;
|
|
268
|
-
} catch (e) {
|
|
269
|
-
this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|