From 6ff83f602bd03cfb2026308dfe155a256878ec01 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Thu, 5 Sep 2024 10:05:51 +0000 Subject: [PATCH] chore: rename watcher + extend comment --- yarn-project/aztec.js/src/index.ts | 2 +- .../src/utils/{watcher.ts => anvil_test_watcher.ts} | 12 ++++++++++-- yarn-project/aztec.js/src/utils/index.ts | 2 +- yarn-project/aztec/src/sandbox.ts | 10 +++++++--- .../end-to-end/src/fixtures/snapshot_manager.ts | 8 ++++---- yarn-project/end-to-end/src/fixtures/utils.ts | 4 ++-- 6 files changed, 25 insertions(+), 13 deletions(-) rename yarn-project/aztec.js/src/utils/{watcher.ts => anvil_test_watcher.ts} (79%) diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 2c7f02e06859..84e5a7d6c14f 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -39,7 +39,7 @@ export { ContractDeployer } from './deployment/index.js'; export { AztecAddressLike, - Watcher, + AnvilTestWatcher, CheatCodes, EthAddressLike, EthCheatCodes, diff --git a/yarn-project/aztec.js/src/utils/watcher.ts b/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts similarity index 79% rename from yarn-project/aztec.js/src/utils/watcher.ts rename to yarn-project/aztec.js/src/utils/anvil_test_watcher.ts index 6f125b265a4c..1b6e0cf7f637 100644 --- a/yarn-project/aztec.js/src/utils/watcher.ts +++ b/yarn-project/aztec.js/src/utils/anvil_test_watcher.ts @@ -7,9 +7,13 @@ import { type GetContractReturnType, type HttpTransport, type PublicClient, getA import type * as chains from 'viem/chains'; /** - * Represents a watcher for a rollup contract. It periodically checks if a slot is filled and mines if necessary. + * Represents a watcher for a rollup contract. + * + * It started on a network like anvil where time traveling is allowed, and auto-mine is turned on + * it will periodically check if the current slot have already been filled, e.g., there was an L2 + * block within the slot. And if so, it will time travel into the next slot. */ -export class Watcher { +export class AnvilTestWatcher { private rollup: GetContractReturnType>; private filledRunningPromise?: RunningPromise; @@ -35,6 +39,10 @@ export class Watcher { throw new Error('Watcher already watching for filled slot'); } + // If auto mining is not supported (e.g., we are on a real network), then we + // will simple do nothing. But if on an anvil or the like, this make sure that + // the sandbox and tests don't break because time is frozen and we never get to + // the next slot. const isAutoMining = await this.cheatcodes.isAutoMining(); if (isAutoMining) { diff --git a/yarn-project/aztec.js/src/utils/index.ts b/yarn-project/aztec.js/src/utils/index.ts index 32a90c5a100d..3fdc939fca1b 100644 --- a/yarn-project/aztec.js/src/utils/index.ts +++ b/yarn-project/aztec.js/src/utils/index.ts @@ -5,4 +5,4 @@ export * from './cheat_codes.js'; export * from './authwit.js'; export * from './pxe.js'; export * from './account.js'; -export * from './watcher.js'; +export * from './anvil_test_watcher.js'; diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index 143713093f3c..81e24a948560 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S node --no-warnings import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; -import { EthCheatCodes, SignerlessWallet, Watcher } from '@aztec/aztec.js'; +import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet } from '@aztec/aztec.js'; import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint'; import { type AztecNode } from '@aztec/circuit-types'; import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, deployCanonicalL2FeeJuice } from '@aztec/cli/misc'; @@ -166,7 +166,7 @@ export async function createSandbox(config: Partial = {}) { aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`; } - let watcher: Watcher | undefined = undefined; + let watcher: AnvilTestWatcher | undefined = undefined; if (!aztecNodeConfig.p2pEnabled) { const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount); @@ -179,7 +179,11 @@ export async function createSandbox(config: Partial = {}) { transport: httpViemTransport(aztecNodeConfig.l1RpcUrl), }); - watcher = new Watcher(new EthCheatCodes(aztecNodeConfig.l1RpcUrl), l1ContractAddresses.rollupAddress, publicClient); + watcher = new AnvilTestWatcher( + new EthCheatCodes(aztecNodeConfig.l1RpcUrl), + l1ContractAddresses.rollupAddress, + publicClient, + ); await watcher.start(); } diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index c21e7744e082..4a5400f53ebc 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -2,6 +2,7 @@ import { SchnorrAccountContractArtifact, getSchnorrAccount } from '@aztec/accoun import { type Archiver, createArchiver } from '@aztec/archiver'; import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { + AnvilTestWatcher, type AztecAddress, type AztecNode, BatchCall, @@ -14,7 +15,6 @@ import { type PXE, SignerlessWallet, type Wallet, - Watcher, } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint'; @@ -55,7 +55,7 @@ export type SubsystemsContext = { pxe: PXEService; deployL1ContractsValues: DeployL1Contracts; proverNode: ProverNode; - watcher: Watcher; + watcher: AnvilTestWatcher; }; type SnapshotEntry = { @@ -312,7 +312,7 @@ async function setupFromFresh( aztecNodeConfig.l1Contracts = deployL1ContractsValues.l1ContractAddresses; aztecNodeConfig.l1PublishRetryIntervalMS = 100; - const watcher = new Watcher( + const watcher = new AnvilTestWatcher( new EthCheatCodes(aztecNodeConfig.l1RpcUrl), deployL1ContractsValues.l1ContractAddresses.rollupAddress, deployL1ContractsValues.publicClient, @@ -417,7 +417,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise