Skip to content

Commit

Permalink
Lightnet sub-commands implementation (start/stop/status). (#510)
Browse files Browse the repository at this point in the history
Co-authored-by: Barrie Byron <[email protected]>
  • Loading branch information
shimkiv and barriebyron authored Nov 7, 2023
1 parent 2024d94 commit 59b5b2d
Show file tree
Hide file tree
Showing 7 changed files with 926 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.15.0] - 2023-11-07

### Changed

- Lightnet sub-commands implementation (start/stop/status). [#510](https://github.com/o1-labs/zkapp-cli/pull/510)

## [0.14.1] - 2023-11-03

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zkapp-cli",
"version": "0.14.1",
"version": "0.15.0",
"description": "CLI to create zkApps (zero-knowledge apps) for Mina Protocol",
"homepage": "https://github.com/o1-labs/zkapp-cli/",
"keywords": [
Expand Down
142 changes: 142 additions & 0 deletions src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,28 @@ import Constants from '../lib/constants.js';
import { deploy } from '../lib/deploy.js';
import { example } from '../lib/example.js';
import { file } from '../lib/file.js';
import {
lightnetStatus,
startLightnet,
stopLightnet,
} from '../lib/lightnet.js';
import { project } from '../lib/project.js';
import system from '../lib/system.js';

const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const commonOptions = {
debug: {
alias: 'd',
demand: false,
boolean: true,
hidden: false,
default: false,
description: 'Whether to print the debug information.',
},
};

yargs(hideBin(process.argv))
.scriptName(chalk.green('zk'))
.usage('Usage: $0 <command> [options]')
Expand All @@ -39,6 +55,9 @@ yargs(hideBin(process.argv))
'Argument: %s, Given: %s, Choices: %s': chalk.red(
`%s was %s. Must be one of: %s.`
),
'Not enough non-option arguments: %s': {
one: chalk.red('Not enough non-option arguments: %s'),
},
})
.demandCommand(1, chalk.red('Please provide a command.'))

Expand Down Expand Up @@ -94,6 +113,129 @@ yargs(hideBin(process.argv))
async (argv) => await example(argv.name)
)
.command(['system', 'sys', 's'], 'Show system info', {}, () => system())
.command(
['lightnet <sub-command> [options]'],
'Manage the lightweight Mina blockchain for zkApps development and testing purposes.\nYou can find more information about the Docker image in use at\nhttps://hub.docker.com/r/o1labs/mina-local-network',
(yargs) => {
yargs
.command(
[
'start [mode] [type] [proof-level] [mina-branch] [archive] [sync] [pull] [debug]',
],
'Start the lightweight Mina blockchain network Docker container.',
{
mode: {
alias: 'm',
demand: false,
string: true,
hidden: false,
choices: Constants.lightnetModes,
default: 'single-node',
description:
'Whether to form the network with one node or with multiple network participants.\n"single-node" value will make the network faster.',
},
type: {
alias: 't',
demand: false,
string: true,
hidden: false,
choices: Constants.lightnetTypes,
default: 'fast',
description:
'Whether to configure the network to be fast or slower with closer-to-real-world properties.',
},
'proof-level': {
alias: 'p',
demand: false,
string: true,
hidden: false,
choices: Constants.lightnetProofLevels,
default: 'none',
description:
'"none" value will make the network faster by disabling the blockchain SNARK proofs.',
},
'mina-branch': {
alias: 'b',
demand: false,
string: true,
hidden: false,
choices: Constants.lightnetMinaBranches,
default: 'rampup',
description:
'One of the major Mina repository branches the artifacts were compiled against.',
},
archive: {
alias: 'a',
demand: false,
boolean: true,
hidden: false,
default: true,
description:
'Whether to start the Mina Archive process and Archive Node API application within the Docker container.',
},
sync: {
alias: 's',
demand: false,
boolean: true,
hidden: false,
default: true,
description:
'Whether to wait for the network to reach the synchronized state.',
},
pull: {
alias: 'u',
demand: false,
boolean: true,
hidden: false,
default: true,
description:
'Whether to pull the latest version of the Docker image from the Docker Hub.',
},
...commonOptions,
},
async (argv) => await startLightnet(argv)
)
.command(
['stop [save-logs] [clean-up] [debug]'],
'Stop the lightweight Mina blockchain network Docker container and perform the cleanup.',
{
'save-logs': {
alias: 'l',
demand: false,
boolean: true,
hidden: false,
default: true,
description:
'Whether to save the Docker container processes logs to the host file system.',
},
'clean-up': {
alias: 'c',
demand: false,
boolean: true,
hidden: false,
default: true,
description:
'Whether to remove the Docker container, dangling Docker images, consumed Docker volume, and the blockchain network configuration.',
},
...commonOptions,
},
async (argv) => await stopLightnet(argv)
)
.command(
['status [debug]'],
'Get the lightweight Mina blockchain network status.',
{
...commonOptions,
},
async (argv) =>
await lightnetStatus({
preventDockerEngineAvailabilityCheck: false,
debug: argv.debug,
})
)
.demandCommand();
}
)
.version(
fs.readJsonSync(path.join(__dirname, '..', '..', 'package.json')).version
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function config() {
const msg = '\n ' + table(tableData, tableConfig).replaceAll('\n', '\n ');
log(msg);

console.log('Enter values to create a deploy alias:');
log('Enter values to create a deploy alias:');

const {
deployAliasPrompts,
Expand Down
12 changes: 11 additions & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { homedir } from 'os';
import path from 'path';

/**
* @typedef {'next' | 'svelte' | 'nuxt' | 'empty' | 'none'} UiType
* @typedef {'sudoku' | 'tictactoe'} ExampleType
* @typedef {'single-node' | 'multi-node'} LightnetMode
* @typedef {'fast' | 'real'} LightnetType
* @typedef {'none' | 'full'} LightnetProofLevel
* @typedef {'rampup' | 'berkeley' | 'develop'} LightnetMinaBranch
*
* @type {{ uiTypes: UiType[], exampleTypes: ExampleType[], feePayerCacheDir: string }}
* @type {{ uiTypes: UiType[], exampleTypes: ExampleType[], feePayerCacheDir: string, lightnetWorkDir: string, lightnetModes: LightnetMode[], lightnetTypes: LightnetType[], lightnetProofLevels: LightnetProofLevel[], lightnetMinaBranches: LightnetMinaBranch[] }}
*/
const Constants = Object.freeze({
uiTypes: ['next', 'svelte', 'nuxt', 'empty', 'none'],
exampleTypes: ['sudoku', 'tictactoe'],
feePayerCacheDir: `${homedir()}/.cache/zkapp-cli/keys`,
lightnetWorkDir: path.resolve(`${homedir()}/.cache/zkapp-cli/lightnet`),
lightnetModes: ['single-node', 'multi-node'],
lightnetTypes: ['fast', 'real'],
lightnetProofLevels: ['none', 'full'],
lightnetMinaBranches: ['rampup', 'berkeley', 'develop'],
});

export default Constants;
Loading

0 comments on commit 59b5b2d

Please sign in to comment.