Skip to content

Commit

Permalink
chore: increase AZTEC_SLOT_DURATION (#8331)
Browse files Browse the repository at this point in the history
Fixes #7850. 

Alters the aztec slot duration til 3 * ethereum slot duration = 36
seconds.

- Updated the sandbox to no longer ignore the `--l1-rpc-url` option, it
passed in test because they are all using the environment variables
`ETHEREUM_HOST`.
- Updated the watcher to check if running on an anvil with automine.
- Added a `watcher` to the sandbox, such that it can jump time if
automining as well. This was needed to work with `AZTEC_SLOT_DURATION >
ETHEREUM_SLOT_DURATION`.
- Moved the watcher into the `aztec.js` since it is now needed in
multiple places and it seeded to avoid a cycle, but needed to import
viem and l1-artifacts into it 😬
- Updates the `transfer.test.ts` to make multiple transfers in the same
blocks to speed up the test, as 36s blocks with 50 blocks is 30 minutes
which is longer than I would like to have that test run.
  • Loading branch information
LHerskind authored Sep 6, 2024
1 parent f7e4bfb commit 5d48500
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 125 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ library Constants {
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant ETHEREUM_SLOT_DURATION = 12;
uint256 internal constant AZTEC_SLOT_DURATION = 12;
uint256 internal constant AZTEC_SLOT_DURATION = 36;
uint256 internal constant AZTEC_EPOCH_DURATION = 48;
uint256 internal constant AZTEC_TARGET_COMMITTEE_SIZE = 48;
uint256 internal constant GENESIS_ARCHIVE_ROOT =
Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f",
"archive": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd7144202",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"decodedHeader": {
Expand All @@ -20,12 +20,12 @@
},
"globalVariables": {
"blockNumber": 1,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000033",
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000031",
"chainId": 31337,
"timestamp": 1724861610,
"timestamp": 1725365629,
"version": 1,
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
"coinbase": "0xe18d2e77cb7d56929128e82138140e07f81237f0",
"feeRecipient": "0x249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
Expand Down Expand Up @@ -56,8 +56,8 @@
}
}
},
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000066cf4caa872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00a46e722d885c3bf479f8cf2a786adfde7a8c43740214163f7f9846914cbe6f",
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000310000000000000000000000000000000000000000000000000000000066d6fd7de18d2e77cb7d56929128e82138140e07f81237f0249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x0042736ccfe5affa7d43b08218d225ef79539cf41495e3db480aedf4ec65d918",
"numTxs": 0
}
}
16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/empty_block_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x25126f40ad58d24006e6db629c2efb1e0868a50d5c21aa342894137b2b08bc0b",
"archive": "0x002edae6c81b7fcd630fd745c8e6fa957b8d4ac97b55baa072fae18f4a94b14e",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"decodedHeader": {
Expand All @@ -20,20 +20,20 @@
},
"globalVariables": {
"blockNumber": 2,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000035",
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000032",
"chainId": 31337,
"timestamp": 1724861634,
"timestamp": 1725365665,
"version": 1,
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
"coinbase": "0xe18d2e77cb7d56929128e82138140e07f81237f0",
"feeRecipient": "0x249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f"
"root": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd7144202"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -56,8 +56,8 @@
}
}
},
"header": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f00000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000066cf4cc2872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00de3870b035eca1a73e8adf24b738db855a034548805b300d8dbecfd2a6e66b",
"header": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd714420200000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000066d6fda1e18d2e77cb7d56929128e82138140e07f81237f0249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00b9a5096ad3d9edef7e78a242b1402a5cd1adeb08ee654c6e738a08b3522483",
"numTxs": 0
}
}
14 changes: 7 additions & 7 deletions l1-contracts/test/fixtures/mixed_block_1.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/mixed_block_2.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ global INITIAL_L2_BLOCK_NUM: Field = 1;
global BLOB_SIZE_IN_BYTES: Field = 31 * 4096;
global ETHEREUM_SLOT_DURATION: u32 = 12;
// AZTEC_SLOT_DURATION should be a multiple of ETHEREUM_SLOT_DURATION
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 1;
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 3;
global AZTEC_EPOCH_DURATION: u32 = 48;
global AZTEC_TARGET_COMMITTEE_SIZE: u32 = 48;
// The following is taken from building a block and looking at the `lastArchive` value in it.
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@
"@aztec/circuits.js": "workspace:^",
"@aztec/ethereum": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/l1-artifacts": "workspace:^",
"@aztec/protocol-contracts": "workspace:^",
"@aztec/types": "workspace:^",
"axios": "^1.7.2",
"tslib": "^2.4.0"
"tslib": "^2.4.0",
"viem": "^2.7.15"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export { ContractDeployer } from './deployment/index.js';

export {
AztecAddressLike,
AnvilTestWatcher,
CheatCodes,
EthAddressLike,
EthCheatCodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { RollupAbi } from '@aztec/l1-artifacts';
import { type GetContractReturnType, type HttpTransport, type PublicClient, getAddress, getContract } from 'viem';
import type * as chains from 'viem/chains';

export class Watcher {
/**
* 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 AnvilTestWatcher {
private rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;

private filledRunningPromise?: RunningPromise;
Expand All @@ -27,13 +34,24 @@ export class Watcher {
this.logger.info(`Watcher created for rollup at ${rollupAddress}`);
}

start() {
async start() {
if (this.filledRunningPromise) {
throw new Error('Watcher already watching for filled slot');
}
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
this.filledRunningPromise.start();
this.logger.info(`Watcher started`);

// 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) {
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
this.filledRunningPromise.start();
this.logger.info(`Watcher started`);
} else {
this.logger.info(`Watcher not started because not auto mining`);
}
}

async stop() {
Expand Down
14 changes: 14 additions & 0 deletions yarn-project/aztec.js/src/utils/cheat_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ export class EthCheatCodes {
return await (await fetch(this.rpcUrl, content)).json();
}

/**
* Get the auto mine status of the underlying chain
* @returns True if automine is on, false otherwise
*/
public async isAutoMining(): Promise<boolean> {
try {
const res = await this.rpcCall('anvil_getAutomine', []);
return res.result;
} catch (err) {
this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
}
return false;
}

/**
* Get the current blocknumber
* @returns The current block number
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './cheat_codes.js';
export * from './authwit.js';
export * from './pxe.js';
export * from './account.js';
export * from './anvil_test_watcher.js';
3 changes: 3 additions & 0 deletions yarn-project/aztec.js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
{
"path": "../foundation"
},
{
"path": "../l1-artifacts"
},
{
"path": "../protocol-contracts"
},
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
const { aztecNodeConfig, node, pxe, stop } = await createSandbox({
enableGas: sandboxOptions.enableGas,
l1Mnemonic: options.l1Mnemonic,
l1RpcUrl: options.l1RpcUrl,
});

// Deploy test accounts by default
Expand Down
22 changes: 20 additions & 2 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 { SignerlessWallet } 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,8 +166,25 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
}

let watcher: AnvilTestWatcher | undefined = undefined;
if (!aztecNodeConfig.p2pEnabled) {
await deployContractsToL1(aztecNodeConfig, hdAccount);
const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount);

const chain = aztecNodeConfig.l1RpcUrl
? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
: { chainInfo: localAnvil };

const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: httpViemTransport(aztecNodeConfig.l1RpcUrl),
});

watcher = new AnvilTestWatcher(
new EthCheatCodes(aztecNodeConfig.l1RpcUrl),
l1ContractAddresses.rollupAddress,
publicClient,
);
await watcher.start();
}

const client = await createAndStartTelemetryClient(getTelemetryClientConfig());
Expand All @@ -191,6 +208,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
const stop = async () => {
await pxe.stop();
await node.stop();
await watcher?.stop();
};

return { node, pxe, aztecNodeConfig, stop };
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const INITIALIZATION_SLOT_SEPARATOR = 1000000000;
export const INITIAL_L2_BLOCK_NUM = 1;
export const BLOB_SIZE_IN_BYTES = 126976;
export const ETHEREUM_SLOT_DURATION = 12;
export const AZTEC_SLOT_DURATION = 12;
export const AZTEC_SLOT_DURATION = 36;
export const AZTEC_EPOCH_DURATION = 48;
export const AZTEC_TARGET_COMMITTEE_SIZE = 48;
export const GENESIS_ARCHIVE_ROOT = 8142738430000951296386584486068033372964809139261822027365426310856631083550n;
Expand Down
Empty file modified yarn-project/end-to-end/scripts/create_k8s_dashboard.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE;
const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS;
const MAX_CHAIN_LENGTH = CHAIN_LENGTHS[CHAIN_LENGTHS.length - 1];
const SETUP_BLOCK_COUNT = 4; // deploy protocol contracts + deploy account + deploy contract

let setupBlockCount: number;

describe('benchmarks/process_history', () => {
let context: EndToEndContext;
Expand All @@ -30,6 +31,7 @@ describe('benchmarks/process_history', () => {

beforeEach(async () => {
({ context, contract, sequencer } = await benchmarkSetup({ maxTxsPerBlock: BLOCK_SIZE }));
setupBlockCount = await context.aztecNode.getBlockNumber();
});

it(
Expand Down Expand Up @@ -59,7 +61,7 @@ describe('benchmarks/process_history', () => {
});

const blockNumber = await node.getBlockNumber();
expect(blockNumber).toEqual(chainLength + SETUP_BLOCK_COUNT);
expect(blockNumber).toEqual(chainLength + setupBlockCount);

context.logger.info(`Node synced chain up to block ${chainLength}`, {
eventName: 'node-synced-chain-history',
Expand All @@ -74,7 +76,7 @@ describe('benchmarks/process_history', () => {
// Create a new pxe and measure how much time it takes it to sync with failed and successful decryption
// Skip the first two blocks used for setup (create account contract and deploy benchmarking contract)
context.logger.info(`Starting new pxe`);
const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + SETUP_BLOCK_COUNT);
const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount);

// Register the owner account and wait until it's synced so we measure how much time it took
context.logger.info(`Registering owner account on new pxe`);
Expand Down
1 change: 0 additions & 1 deletion yarn-project/end-to-end/src/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './fixtures.js';
export * from './logging.js';
export * from './utils.js';
export * from './watcher.js';
Loading

0 comments on commit 5d48500

Please sign in to comment.