Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightnet sub-commands implementation (start/stop/status). #510

Merged
merged 31 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
07b51d6
Lightnet sub-commands implementation (start/stop/status).
shimkiv Oct 27, 2023
5af97cf
Typo.
shimkiv Oct 27, 2023
1b02d87
One more typo.
shimkiv Oct 27, 2023
3e55a3c
Logs clarification message and a bit of refactoring.
shimkiv Oct 30, 2023
4c423f3
Clarification.
shimkiv Oct 30, 2023
8266310
Update src/bin/index.js
shimkiv Oct 30, 2023
967916a
Update src/bin/index.js
shimkiv Oct 30, 2023
ba114ef
Additional check if Docker Engine is runnning.
shimkiv Oct 30, 2023
ac92401
Naming fix.
shimkiv Oct 30, 2023
7fff5d6
serial comma
barriebyron Oct 30, 2023
1404cc4
Code snippet issue.
shimkiv Oct 31, 2023
a2f72ba
Merge remote-tracking branch 'origin/lightnet-start-stop-status' into…
shimkiv Oct 31, 2023
711ab32
Update src/bin/index.js
shimkiv Oct 31, 2023
ce5c6cc
Merge remote-tracking branch 'origin/main' into lightnet-start-stop-s…
shimkiv Oct 31, 2023
6ffb65e
Addressing review items.
shimkiv Oct 31, 2023
2b90442
Debug mode.
shimkiv Oct 31, 2023
8c921c8
Addressing review items.
shimkiv Oct 31, 2023
9b9f589
Better steps and text formatting.
shimkiv Oct 31, 2023
16a1412
Fast lightnet max-attempts reverted (commited by mistake).
shimkiv Oct 31, 2023
c440497
docker run --pull=missing instead of --pull=always since we extracted…
shimkiv Oct 31, 2023
9dff90a
Commands update in order to respect *nix and win32 (powershell and cm…
shimkiv Oct 31, 2023
36d97de
Merge remote-tracking branch 'origin/main' into lightnet-start-stop-s…
shimkiv Oct 31, 2023
1def217
Increased max-attempts for slower env. (90210, hello 90s ;).
shimkiv Oct 31, 2023
9050aa1
Fix for Windows logs persistence storage path.
shimkiv Oct 31, 2023
6f87149
Trivial wording improvement.
shimkiv Oct 31, 2023
ae75be1
Print catched error messages in debug mode.
shimkiv Nov 1, 2023
0963b73
Print catched error messages in debug mode.
shimkiv Nov 1, 2023
3f1603d
Merge remote-tracking branch 'origin/main' into lightnet-start-stop-s…
shimkiv Nov 3, 2023
3ea4eb1
Merge remote-tracking branch 'origin/main' into lightnet-start-stop-s…
shimkiv Nov 3, 2023
b4142d0
package-lock
shimkiv Nov 4, 2023
4e8c27f
Version bump and changelog
shimkiv Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shimkiv advantages and disadvantages? default is true, so when would we want to use false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker images are updated each night and pulling the new image will takes resources and time should you start the network next day from scratch. It is useful to set false when you develop/test zkapp functionality using same version of o1js and Mina dependencies. The reason it is not set to false by default is because I was thinking to encourage people always use "latest and greatest" but not sure already.

},
...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.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default is true, what happens if false? where else would Docker container processes logs be saved? (or not saved at all?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • zk lightnet stop - saves logs from container to host file-system, stops and removes the container.
  • zk lightnet stop --no-save-logs - stops and removes the container, logs produced by different apps inside the container are gone. Useful for short lived networks when users will just check something zkapp related and don't care about logs.
  • zk lightnet stop --no-save-logs --no-clean-up - stops the container, it is not removed so container still can be accessible by users in order to get logs manually.

},
'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