Skip to content

Commit

Permalink
chore: rename watcher + extend comment
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 5, 2024
1 parent b685ac4 commit 6ff83f6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export { ContractDeployer } from './deployment/index.js';

export {
AztecAddressLike,
Watcher,
AnvilTestWatcher,
CheatCodes,
EthAddressLike,
EthCheatCodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;

private filledRunningPromise?: RunningPromise;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
10 changes: 7 additions & 3 deletions yarn-project/aztec/src/sandbox.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
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);

Expand All @@ -179,7 +179,11 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
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();
}

Expand Down
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -55,7 +55,7 @@ export type SubsystemsContext = {
pxe: PXEService;
deployL1ContractsValues: DeployL1Contracts;
proverNode: ProverNode;
watcher: Watcher;
watcher: AnvilTestWatcher;
};

type SnapshotEntry = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -417,7 +417,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
logger.verbose('Creating ETH clients...');
const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrl, mnemonicToAccount(MNEMONIC));

const watcher = new Watcher(
const watcher = new AnvilTestWatcher(
new EthCheatCodes(aztecNodeConfig.l1RpcUrl),
aztecNodeConfig.l1Contracts.rollupAddress,
publicClient,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/
import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
import {
type AccountWalletWithSecretKey,
AnvilTestWatcher,
AztecAddress,
type AztecNode,
BatchCall,
Expand All @@ -19,7 +20,6 @@ import {
type SentTx,
SignerlessWallet,
type Wallet,
Watcher,
createAztecNodeClient,
createDebugLogger,
createPXEClient,
Expand Down Expand Up @@ -406,7 +406,7 @@ export async function setup(

config.l1Contracts = deployL1ContractsValues.l1ContractAddresses;

const watcher = new Watcher(
const watcher = new AnvilTestWatcher(
new EthCheatCodes(config.l1RpcUrl),
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
deployL1ContractsValues.publicClient,
Expand Down

0 comments on commit 6ff83f6

Please sign in to comment.