-
Notifications
You must be signed in to change notification settings - Fork 47
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
Changes from all commits
07b51d6
5af97cf
1b02d87
3e55a3c
4c423f3
8266310
967916a
ba114ef
ac92401
7fff5d6
1404cc4
a2f72ba
711ab32
ce5c6cc
6ffb65e
2b90442
8c921c8
9b9f589
16a1412
c440497
9dff90a
36d97de
1def217
9050aa1
6f87149
ae75be1
0963b73
3f1603d
3ea4eb1
b4142d0
4e8c27f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]') | ||
|
@@ -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.')) | ||
|
||
|
@@ -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.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
'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 | ||
) | ||
|
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`, | ||
shimkiv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 tofalse
by default is because I was thinking to encourage people always use "latest and greatest" but not sure already.