Skip to content

Commit

Permalink
Add --validium-mode flag to zk init command
Browse files Browse the repository at this point in the history
  • Loading branch information
ilitteri committed Jan 25, 2024
1 parent 9736d97 commit 2d9c427
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
6 changes: 4 additions & 2 deletions infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async function initHyperchain() {
testTokens: {
deploy: deployTestTokens,
args: ['--private-key', deployerPrivateKey, '--envFile', process.env.CHAIN_ETH_NETWORK!]
}
},
validiumMode: false
};

await init(initArgs);
Expand Down Expand Up @@ -785,7 +786,8 @@ async function configDemoHyperchain(cmd: Command) {
testTokens: {
deploy: deployTestTokens,
args: ['--private-key', deployerPrivateKey, '--envFile', process.env.CHAIN_ETH_NETWORK!]
}
},
validiumMode: false
};

if (!cmd.skipEnvSetup) {
Expand Down
40 changes: 32 additions & 8 deletions infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ const success = chalk.green;
const timestamp = chalk.grey;

export async function init(initArgs: InitArgs = DEFAULT_ARGS) {
const { skipSubmodulesCheckout, skipEnvSetup, testTokens, governorPrivateKeyArgs, deployerL2ContractInput } =
initArgs;
const {
skipSubmodulesCheckout,
skipEnvSetup,
testTokens,
governorPrivateKeyArgs,
deployerL2ContractInput,
validiumMode
} = initArgs;

process.env.VALIDIUM_MODE = validiumMode.toString();
await announced(`Initializing in ${validiumMode ? 'Validium mode' : 'Roll-up mode'}`);

if (!process.env.CI && !skipEnvSetup) {
await announced('Pulling images', docker.pull());
Expand Down Expand Up @@ -63,7 +72,10 @@ export async function init(initArgs: InitArgs = DEFAULT_ARGS) {

// A smaller version of `init` that "resets" the localhost environment, for which `init` was already called before.
// It does less and runs much faster.
export async function reinit() {
export async function reinit(validiumMode: boolean) {
process.env.VALIDIUM_MODE = validiumMode.toString();
await announced(`Initializing in ${validiumMode ? 'Validium mode' : 'Roll-up mode'}`);

await announced('Setting up containers', up());
await announced('Compiling JS packages', run.yarn());
await announced('Compile l2 contracts', compiler.compileAll());
Expand All @@ -83,7 +95,11 @@ export async function reinit() {
}

// A lightweight version of `init` that sets up local databases, generates genesis and deploys precompiled contracts
export async function lightweightInit() {
export async function lightweightInit(validiumMode: boolean) {
process.env.VALIDIUM_MODE = validiumMode.toString();
await announced(`Initializing in ${validiumMode ? 'Validium mode' : 'Roll-up mode'}`);

await announced(`Setting up containers`, up());
await announced('Clean rocksdb', clean('db'));
await announced('Clean backups', clean('backups'));
await announced('Deploying L1 verifier', contract.deployVerifier([]));
Expand Down Expand Up @@ -144,33 +160,41 @@ export interface InitArgs {
deploy: boolean;
args: any[];
};
validiumMode: boolean;
}

const DEFAULT_ARGS: InitArgs = {
skipSubmodulesCheckout: false,
skipEnvSetup: false,
governorPrivateKeyArgs: [],
deployerL2ContractInput: { args: [], includePaymaster: true, includeL2WETH: true },
testTokens: { deploy: true, args: [] }
testTokens: { deploy: true, args: [] },
validiumMode: false
};

export const initCommand = new Command('init')
.option('--skip-submodules-checkout')
.option('--skip-env-setup')
.option('--validium-mode')
.description('perform zksync network initialization for development')
.action(async (cmd: Command) => {
const initArgs: InitArgs = {
skipSubmodulesCheckout: cmd.skipSubmodulesCheckout,
skipEnvSetup: cmd.skipEnvSetup,
governorPrivateKeyArgs: [],
deployerL2ContractInput: { args: [], includePaymaster: true, includeL2WETH: true },
testTokens: { deploy: true, args: [] }
testTokens: { deploy: true, args: [] },
validiumMode: cmd.validiumMode
};
await init(initArgs);
});
export const reinitCommand = new Command('reinit')
.description('"reinitializes" network. Runs faster than `init`, but requires `init` to be executed prior')
.action(reinit);
.action(async (cmd: Command) => {
await reinit(cmd.validiumMode);
});
export const lightweightInitCommand = new Command('lightweight-init')
.description('perform lightweight zksync network initialization for development')
.action(lightweightInit);
.action(async (cmd: Command) => {
await lightweightInit(cmd.validiumMode);
});

0 comments on commit 2d9c427

Please sign in to comment.