diff --git a/.github/workflows/openzeppelin_test_11.yml b/.github/workflows/openzeppelin_test_11.yml index 8d1746ece..2955e4f09 100644 --- a/.github/workflows/openzeppelin_test_11.yml +++ b/.github/workflows/openzeppelin_test_11.yml @@ -94,7 +94,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run prepare id: runtest diff --git a/.github/workflows/openzeppelin_test_16_19.yml b/.github/workflows/openzeppelin_test_16_19.yml index 125f959c8..19a0c3a0e 100644 --- a/.github/workflows/openzeppelin_test_16_19.yml +++ b/.github/workflows/openzeppelin_test_16_19.yml @@ -94,7 +94,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run prepare id: runtest diff --git a/.github/workflows/openzeppelin_test_1_5_and_12_15.yml b/.github/workflows/openzeppelin_test_1_5_and_12_15.yml index aa7ce50ec..da5ddaded 100644 --- a/.github/workflows/openzeppelin_test_1_5_and_12_15.yml +++ b/.github/workflows/openzeppelin_test_1_5_and_12_15.yml @@ -95,7 +95,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run prepare id: runtest diff --git a/.github/workflows/openzeppelin_test_6_10.yml b/.github/workflows/openzeppelin_test_6_10.yml index 51451f815..7d8983331 100644 --- a/.github/workflows/openzeppelin_test_6_10.yml +++ b/.github/workflows/openzeppelin_test_6_10.yml @@ -94,7 +94,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run prepare id: runtest run: | diff --git a/.github/workflows/somking_test.yml b/.github/workflows/somking_test.yml index 38cea20c6..ba9dc097a 100644 --- a/.github/workflows/somking_test.yml +++ b/.github/workflows/somking_test.yml @@ -23,7 +23,7 @@ jobs: - name: Start axon run: | cd ${{ github.workspace }}/axon - ./axon --config ${{ github.workspace }}/axon/config.toml --genesis ${{ github.workspace }}/axon/genesis_single_node.json > /tmp/log 2>&1 & + ./axon run --config ${{ github.workspace }}/axon/config.toml --genesis ${{ github.workspace }}/axon/genesis_single_node.json > /tmp/log 2>&1 & sleep 120 - name: Check Axon Status run: | diff --git a/.github/workflows/v3_core_test.yml b/.github/workflows/v3_core_test.yml index fafda69dd..395ae08de 100644 --- a/.github/workflows/v3_core_test.yml +++ b/.github/workflows/v3_core_test.yml @@ -83,7 +83,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Install dependencies run: | cd /home/runner/work/axon/axon/v3-core diff --git a/.github/workflows/web3_compatible.yml b/.github/workflows/web3_compatible.yml index 45f083fb3..6b67a3462 100644 --- a/.github/workflows/web3_compatible.yml +++ b/.github/workflows/web3_compatible.yml @@ -95,7 +95,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run Test run: | cd /home/runner/work/axon/axon/axon-test @@ -176,7 +176,7 @@ jobs: run: | cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & - name: Run Test run: | cd /home/runner/work/axon/axon/axon-test diff --git a/Dockerfile b/Dockerfile index 7676249c0..fd03bb895 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,6 @@ RUN set -eux; \ COPY --from=builder /build/target/release/axon /app/axon COPY --from=builder /build/devtools /app/devtools -CMD ./axon -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json +CMD ./axon run -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json diff --git a/Makefile b/Makefile index 015db06b7..e485bcd9a 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ e2e-test-lint: e2e-test: cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & cd tests/e2e && yarn cd tests/e2e/src && yarn exec http-server & cd tests/e2e && yarn exec wait-on -t 5000 tcp:8000 && yarn exec wait-on -t 5000 tcp:8080 && yarn test @@ -73,7 +73,7 @@ e2e-test: e2e-test-ci: cargo build rm -rf ./devtools/chain/data - ./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & + ./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 & cd tests/e2e && yarn cd tests/e2e/src && yarn exec http-server & cd tests/e2e && yarn exec wait-on -t 5000 tcp:8000 && yarn exec wait-on -t 5000 tcp:8080 && HEADLESS=true yarn test diff --git a/README.md b/README.md index 041ca9858..dfd724757 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Openness and mobility are the foundation of social development, so is blockchain ### Staking on Layer 1 CKB -Axon supports a Proof-of-Stake (PoS) consensus mechanism and requires each Axon-based appchain to issue native Extensible User Defined Tokens (xUDTs), which are designed and customized by the app chain's development team and released on CKB. For simplicity, the xUDTs on Axon-based chains are referred to as Axon tokens (AT tokens) below. Holders of AT tokens can stake to become validators and/or delegate their tokens to other validators in exchange for rewards. Unlike other sidechains where staking takes place on Layer 2, Axon's staking is grounded on Layer 1 CKB. Validators and other participants stake their native AT tokens on CKB, which uses a Proof-of-Work (PoW) consensus mechanism. This unique staking design helps Axon-based appchains enjoy the highest degree of decentralization and security from Layer 1 while maintain their high performance and sovereignty as independent Layer 2 networks. +Axon supports a Proof-of-Stake (PoS) consensus mechanism and requires each Axon-based appchain to issue native Extensible User Defined Tokens (xUDTs), which are designed and customized by the app chain's development team and released on CKB. For simplicity, the xUDTs on Axon-based chains are referred to as Axon tokens (AT tokens) below. Holders of AT tokens can stake to become validators and/or delegate their tokens to other validators in exchange for rewards. Unlike other sidechains where staking takes place on Layer 2, Axon's staking is grounded on Layer 1 CKB. Validators and other participants stake their native AT tokens on CKB, which uses a Proof-of-Work (PoW) consensus mechanism. This unique staking design helps Axon-based appchains enjoy the highest degree of decentralization and security from Layer 1 while maintain their high performance and sovereignty as independent Layer 2 networks. ## Roadmap @@ -52,7 +52,7 @@ Axon provides the compiled binary on the [release page](`https://github.com/axon # Clone from GitHub git clone https://github.com/axonweb3/axon.git && cd axon # Run release binary for single node -cargo run --release -- -c devtools/chain/config.toml -g devtools/chain/genesis_single_node.json +cargo run --release -- run -c devtools/chain/config.toml -g devtools/chain/genesis_single_node.json ``` @@ -81,7 +81,7 @@ The following ways are a great spot to ask questions about Axon: ## Socials -All Axon related accounts are displayed via [linktree](https://linktr.ee/axonweb3). +All Axon related accounts are displayed via [linktree](https://linktr.ee/axonweb3). ## License diff --git a/core/cli/src/lib.rs b/core/cli/src/lib.rs index 516f8376d..4da00a1a9 100644 --- a/core/cli/src/lib.rs +++ b/core/cli/src/lib.rs @@ -27,6 +27,8 @@ pub enum Error { GettingParent, #[error("parsing genesis: {0}")] ParsingGenesis(#[source] ParseError), + #[error("unknown subcommand: {0}")] + UnknownSubcommand(String), #[error(transparent)] Running(ProtocolError), @@ -53,23 +55,27 @@ impl AxonCli { pub fn init(axon_version: Version, cli_version: &'static str) -> Self { let matches = Command::new("axon") .version(cli_version) - .arg( - Arg::new("config_path") - .short('c') - .long("config") - .help("Axon config path") - .required(true) - .num_args(1), - ) - .arg( - Arg::new("genesis_path") - .short('g') - .long("genesis") - .help("Axon genesis path") - .required(true) - .num_args(1), - ) - .subcommand(Command::new("run").about("Run axon process")); + .subcommand_required(true) + .subcommand( + Command::new("run") + .about("Run axon process") + .arg( + Arg::new("config_path") + .short('c') + .long("config") + .help("Axon config path") + .required(true) + .num_args(1), + ) + .arg( + Arg::new("genesis_path") + .short('g') + .long("genesis") + .help("Axon genesis path") + .required(true) + .num_args(1), + ), + ); AxonCli { version: axon_version, @@ -85,29 +91,37 @@ impl AxonCli { &self, key_provider: Option, ) -> Result<()> { - let config_path = self.matches.get_one::("config_path").unwrap(); - let path = Path::new(&config_path) - .parent() - .ok_or(Error::GettingParent)?; - let mut config: Config = parse_file(config_path, false).map_err(Error::ParsingConfig)?; - - if let Some(ref mut f) = config.rocksdb.options_file { - *f = path.join(&f) + if let Some((cmd, matches)) = self.matches.subcommand() { + match cmd { + "run" => { + let config_path = matches.get_one::("config_path").unwrap(); + let path = Path::new(&config_path) + .parent() + .ok_or(Error::GettingParent)?; + let mut config: Config = + parse_file(config_path, false).map_err(Error::ParsingConfig)?; + + if let Some(ref mut f) = config.rocksdb.options_file { + *f = path.join(&f) + } + let genesis: RichBlock = + parse_file(matches.get_one::("genesis_path").unwrap(), true) + .map_err(Error::ParsingGenesis)?; + + self.check_version(&config)?; + + register_log(&config); + + Axon::new(config, genesis) + .run(key_provider) + .map_err(Error::Running) + } + _ => Err(Error::UnknownSubcommand(cmd.to_owned())), + } + } else { + // Since `clap.subcommand_required(true)`. + unreachable!(); } - let genesis: RichBlock = parse_file( - self.matches.get_one::("genesis_path").unwrap(), - true, - ) - .map_err(Error::ParsingGenesis)?; - - self.check_version(&config)?; - - register_log(&config); - - Axon::new(config, genesis) - .run(key_provider) - .map_err(Error::Running)?; - Ok(()) } fn check_version(&self, config: &Config) -> Result<()> { diff --git a/docker-compose.yml b/docker-compose.yml index 734470534..211facb7c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: - ./devtools:/app/devtools networks: - axon-net - command: ./axon -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json + command: ./axon run -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json networks: