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 4 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
122 changes: 122 additions & 0 deletions src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ 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';

Expand Down Expand Up @@ -39,6 +44,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 +102,120 @@ 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]',
],
'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 to have closer to real world properties but slower.',
},
'proof-level': {
alias: 'p',
demand: false,
string: true,
hidden: false,
choices: Constants.lightnetProofLevels,
default: 'none',
description: '"none" value will make the network faster.',
Copy link
Contributor

Choose a reason for hiding this comment

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

@shimkiv what is the disadvantage of none proof-level? none is default, but does not test other proofs, right? maybe more description to help user choose the appropriate proof level?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the protocol configuration. One of the expensive parts of the protocol is creating blockchain snark proofs, so mocking that is important for faster everything. The proof_level Mina constant can be used to disable proving (set it to be check) or disable block calculation altogether (set it to none). None is default because for zkApps development with o1js we don't really care about protocol proofs, assuming that it is well tested. Sometimes though one might want to run zkApps against network that has closer to "real world" properties (say, some of the Nightly CI tests). That is when zk lightnet start --mode multi-node --type real --proof-level full might be useful.

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

},
},
async (argv) => await startLightnet(argv)
)
.command(
['stop [save-logs] [clean-up]'],
'Stop the lightweight Mina blockchain network Docker container and perform the clean up.',
{
'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 network configuration.',
},
},
async (argv) => await stopLightnet(argv)
)
.command(
['status'],
'Get the lightweight Mina blockchain network status.',
{},
async () => await lightnetStatus({ checkCommandsAvailability: true })
)
.demandCommand();
}
)
.version(
fs.readJsonSync(path.join(__dirname, '..', '..', 'package.json')).version
)
Expand Down
11 changes: 10 additions & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ import { homedir } from 'os';
/**
* @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: `${homedir()}/.cache/zkapp-cli/lightnet`,
lightnetModes: ['single-node', 'multi-node'],
lightnetTypes: ['fast', 'real'],
lightnetProofLevels: ['none', 'full'],
lightnetMinaBranches: ['rampup', 'berkeley', 'develop'],
});

export default Constants;
Loading