Skip to content

Commit a997085

Browse files
committed
fix: update sandbox setup
1 parent efb2c07 commit a997085

File tree

12 files changed

+60
-16
lines changed

12 files changed

+60
-16
lines changed

yarn-project/aztec.js/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@
7777
"@aztec/circuits.js": "workspace:^",
7878
"@aztec/ethereum": "workspace:^",
7979
"@aztec/foundation": "workspace:^",
80+
"@aztec/l1-artifacts": "workspace:^",
8081
"@aztec/protocol-contracts": "workspace:^",
8182
"@aztec/types": "workspace:^",
8283
"axios": "^1.7.2",
83-
"tslib": "^2.4.0"
84+
"tslib": "^2.4.0",
85+
"viem": "^2.7.15"
8486
},
8587
"devDependencies": {
8688
"@jest/globals": "^29.5.0",

yarn-project/aztec.js/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export { ContractDeployer } from './deployment/index.js';
3939

4040
export {
4141
AztecAddressLike,
42+
Watcher,
4243
CheatCodes,
4344
EthAddressLike,
4445
EthCheatCodes,

yarn-project/aztec.js/src/utils/cheat_codes.ts

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ export class EthCheatCodes {
5454
return await (await fetch(this.rpcUrl, content)).json();
5555
}
5656

57+
/**
58+
* Get the auto mine status of the underlying chain
59+
* @returns True if automine is on, false otherwise
60+
*/
61+
public async isAutoMining(): Promise<boolean> {
62+
try {
63+
const res = await this.rpcCall('anvil_getAutomine', []);
64+
return res.result;
65+
} catch (err) {
66+
this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
67+
}
68+
return false;
69+
}
70+
5771
/**
5872
* Get the current blocknumber
5973
* @returns The current block number

yarn-project/aztec.js/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './cheat_codes.js';
55
export * from './authwit.js';
66
export * from './pxe.js';
77
export * from './account.js';
8+
export * from './watcher.js';

yarn-project/end-to-end/src/fixtures/watcher.ts yarn-project/aztec.js/src/utils/watcher.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { RollupAbi } from '@aztec/l1-artifacts';
66
import { type GetContractReturnType, type HttpTransport, type PublicClient, getAddress, getContract } from 'viem';
77
import type * as chains from 'viem/chains';
88

9+
/**
10+
* Represents a watcher for a rollup contract. It periodically checks if a slot is filled and mines if necessary.
11+
*/
912
export class Watcher {
1013
private rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;
1114

@@ -27,13 +30,20 @@ export class Watcher {
2730
this.logger.info(`Watcher created for rollup at ${rollupAddress}`);
2831
}
2932

30-
start() {
33+
async start() {
3134
if (this.filledRunningPromise) {
3235
throw new Error('Watcher already watching for filled slot');
3336
}
34-
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
35-
this.filledRunningPromise.start();
36-
this.logger.info(`Watcher started`);
37+
38+
const isAutoMining = await this.cheatcodes.isAutoMining();
39+
40+
if (isAutoMining) {
41+
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
42+
this.filledRunningPromise.start();
43+
this.logger.info(`Watcher started`);
44+
} else {
45+
this.logger.info(`Watcher not started because not auto mining`);
46+
}
3747
}
3848

3949
async stop() {

yarn-project/aztec.js/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
{
1919
"path": "../foundation"
2020
},
21+
{
22+
"path": "../l1-artifacts"
23+
},
2124
{
2225
"path": "../protocol-contracts"
2326
},

yarn-project/aztec/src/cli/cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
5353
const { aztecNodeConfig, node, pxe, stop } = await createSandbox({
5454
enableGas: sandboxOptions.enableGas,
5555
l1Mnemonic: options.l1Mnemonic,
56+
l1RpcUrl: options.l1RpcUrl,
5657
});
5758

5859
// Deploy test accounts by default

yarn-project/aztec/src/sandbox.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env -S node --no-warnings
22
import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
3-
import { SignerlessWallet } from '@aztec/aztec.js';
3+
import { EthCheatCodes, SignerlessWallet, Watcher } from '@aztec/aztec.js';
44
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
55
import { type AztecNode } from '@aztec/circuit-types';
66
import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, deployCanonicalL2FeeJuice } from '@aztec/cli/misc';
@@ -166,8 +166,21 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
166166
aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
167167
}
168168

169+
let watcher: Watcher | undefined = undefined;
169170
if (!aztecNodeConfig.p2pEnabled) {
170-
await deployContractsToL1(aztecNodeConfig, hdAccount);
171+
const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount);
172+
173+
const chain = aztecNodeConfig.l1RpcUrl
174+
? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
175+
: { chainInfo: localAnvil };
176+
177+
const publicClient = createPublicClient({
178+
chain: chain.chainInfo,
179+
transport: httpViemTransport(aztecNodeConfig.l1RpcUrl),
180+
});
181+
182+
watcher = new Watcher(new EthCheatCodes(aztecNodeConfig.l1RpcUrl), l1ContractAddresses.rollupAddress, publicClient);
183+
await watcher.start();
171184
}
172185

173186
const client = await createAndStartTelemetryClient(getTelemetryClientConfig());
@@ -191,6 +204,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
191204
const stop = async () => {
192205
await pxe.stop();
193206
await node.stop();
207+
await watcher?.stop();
194208
};
195209

196210
return { node, pxe, aztecNodeConfig, stop };
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './fixtures.js';
22
export * from './logging.js';
33
export * from './utils.js';
4-
export * from './watcher.js';

yarn-project/end-to-end/src/fixtures/snapshot_manager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type PXE,
1616
SignerlessWallet,
1717
type Wallet,
18+
Watcher,
1819
} from '@aztec/aztec.js';
1920
import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
2021
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
@@ -41,7 +42,6 @@ import { getACVMConfig } from './get_acvm_config.js';
4142
import { getBBConfig } from './get_bb_config.js';
4243
import { setupL1Contracts } from './setup_l1_contracts.js';
4344
import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, getPrivateKeyFromIndex } from './utils.js';
44-
import { Watcher } from './watcher.js';
4545

4646
export type SubsystemsContext = {
4747
anvil: Anvil;
@@ -346,7 +346,7 @@ async function setupFromFresh(
346346
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
347347
deployL1ContractsValues.publicClient,
348348
);
349-
watcher.start();
349+
await watcher.start();
350350

351351
logger.verbose('Creating pxe...');
352352
const pxeConfig = getPXEServiceConfig();
@@ -424,7 +424,7 @@ async function setupFromState(statePath: string, logger: Logger): Promise<Subsys
424424
aztecNodeConfig.l1Contracts.rollupAddress,
425425
publicClient,
426426
);
427-
watcher.start();
427+
await watcher.start();
428428

429429
logger.verbose('Creating aztec node...');
430430
const telemetry = await createAndStartTelemetryClient(getTelemetryConfig());

yarn-project/end-to-end/src/fixtures/utils.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
type SentTx,
2020
SignerlessWallet,
2121
type Wallet,
22+
Watcher,
2223
createAztecNodeClient,
2324
createDebugLogger,
2425
createPXEClient,
@@ -87,7 +88,6 @@ import { MNEMONIC } from './fixtures.js';
8788
import { getACVMConfig } from './get_acvm_config.js';
8889
import { getBBConfig } from './get_bb_config.js';
8990
import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js';
90-
import { Watcher } from './watcher.js';
9191

9292
export { deployAndInitializeTokenAndBridgeContracts } from '../shared/cross_chain_test_harness.js';
9393

@@ -456,10 +456,7 @@ export async function setup(
456456
deployL1ContractsValues.publicClient,
457457
);
458458

459-
// If we are NOT using wall time, we should start the watcher to jump in time as needed.
460-
if (!opts.l1BlockTime) {
461-
watcher.start();
462-
}
459+
await watcher.start();
463460

464461
const wallets = numberOfAccounts > 0 ? await createAccounts(pxe, numberOfAccounts) : [];
465462
const cheatCodes = CheatCodes.create(config.l1RpcUrl, pxe!);

yarn-project/yarn.lock

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ __metadata:
186186
"@aztec/circuits.js": "workspace:^"
187187
"@aztec/ethereum": "workspace:^"
188188
"@aztec/foundation": "workspace:^"
189+
"@aztec/l1-artifacts": "workspace:^"
189190
"@aztec/protocol-contracts": "workspace:^"
190191
"@aztec/types": "workspace:^"
191192
"@jest/globals": ^29.5.0
@@ -204,6 +205,7 @@ __metadata:
204205
tslib: ^2.4.0
205206
typescript: ^5.0.4
206207
util: ^0.12.5
208+
viem: ^2.7.15
207209
webpack: ^5.88.2
208210
webpack-cli: ^5.1.4
209211
languageName: unknown

0 commit comments

Comments
 (0)