diff --git a/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts b/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts index b73b1e09a17..bc1854ac9cc 100644 --- a/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts +++ b/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts @@ -48,7 +48,7 @@ export class AnvilTestWatcher { const isAutoMining = await this.cheatcodes.isAutoMining(); if (isAutoMining) { - this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), this.logger, 1000); + this.filledRunningPromise = new RunningPromise(() => this.warpTimeIfNeeded(), this.logger, 1000); this.filledRunningPromise.start(); this.logger.info(`Watcher started for rollup at ${this.rollup.address}`); } else { @@ -60,23 +60,36 @@ export class AnvilTestWatcher { await this.filledRunningPromise?.stop(); } - async mineIfSlotFilled() { + async warpTimeIfNeeded() { try { const currentSlot = await this.rollup.read.getCurrentSlot(); const pendingBlockNumber = BigInt(await this.rollup.read.getPendingBlockNumber()); const blockLog = await this.rollup.read.getBlock([pendingBlockNumber]); + const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([currentSlot + 1n])); if (currentSlot === blockLog.slotNumber) { // We should jump to the next slot - const timestamp = await this.rollup.read.getTimestampForSlot([currentSlot + 1n]); try { - await this.cheatcodes.warp(Number(timestamp)); - this.dateProvider?.setTime(Number(timestamp) * 1000); + await this.cheatcodes.warp(nextSlotTimestamp); + this.dateProvider?.setTime(nextSlotTimestamp * 1000); } catch (e) { - this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`); + this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`); } this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`); + return; + } + + const currentTimestamp = this.dateProvider?.now() ?? Date.now(); + if (currentTimestamp > nextSlotTimestamp * 1000) { + try { + await this.cheatcodes.warp(nextSlotTimestamp); + this.dateProvider?.setTime(nextSlotTimestamp * 1000); + } catch (e) { + this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`); + } + + this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`); } } catch (err) { this.logger.error('mineIfSlotFilled failed'); diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 1996420aa9d..d98b7ef8a80 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -23,6 +23,7 @@ services: ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 HARDWARE_CONCURRENCY: ${HARDWARE_CONCURRENCY:-} + end-to-end: image: aztecprotocol/build:2.0 volumes: