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

feat(cli): split sub-command run to init and run #1386

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 27 additions & 10 deletions .github/workflows/axon-start-with-short-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ jobs:
LOG_FILE: ${{ runner.temp }}/${{ matrix.os }}-single-axon-node.log
run: |
target/debug/axon --version | tee ${{ env.LOG_FILE }}
target/debug/axon run \
target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
| tee ${{ env.LOG_FILE }} &
| tee -a ${{ env.LOG_FILE }}
target/debug/axon run \
--config devtools/chain/config.toml \
| tee -a ${{ env.LOG_FILE }} &

sleep 10

Expand Down Expand Up @@ -85,22 +88,36 @@ jobs:
mkdir -p ${{ env.LOG_PATH }}

target/debug/axon --version
target/debug/axon run \

target/debug/axon init \
--config devtools/chain/nodes/node_1.toml \
--chain-spec devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml \
> ${{ env.LOG_PATH }}/node_1.log &
target/debug/axon run \
> ${{ env.LOG_PATH }}/node_1.log
target/debug/axon init \
--config devtools/chain/nodes/node_2.toml \
--chain-spec devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml \
> ${{ env.LOG_PATH }}/node_2.log &
target/debug/axon run \
> ${{ env.LOG_PATH }}/node_2.log
target/debug/axon init \
--config devtools/chain/nodes/node_3.toml \
--chain-spec devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml \
> ${{ env.LOG_PATH }}/node_3.log &
target/debug/axon run \
> ${{ env.LOG_PATH }}/node_3.log
target/debug/axon init \
--config devtools/chain/nodes/node_4.toml \
--chain-spec devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml \
> ${{ env.LOG_PATH }}/node_4.log &
> ${{ env.LOG_PATH }}/node_4.log

target/debug/axon run \
--config devtools/chain/nodes/node_1.toml \
>> ${{ env.LOG_PATH }}/node_1.log &
target/debug/axon run \
--config devtools/chain/nodes/node_2.toml \
>> ${{ env.LOG_PATH }}/node_2.log &
target/debug/axon run \
--config devtools/chain/nodes/node_3.toml \
>> ${{ env.LOG_PATH }}/node_3.log &
target/debug/axon run \
--config devtools/chain/nodes/node_4.toml \
>> ${{ env.LOG_PATH }}/node_4.log &

npx zx <<'EOF'
import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/openzeppelin_test_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ jobs:
- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /tmp/log 2>&1 &

- name: Run prepare
id: runtest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/openzeppelin_test_16_19.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ jobs:
- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /tmp/log 2>&1 &

- name: Run prepare
id: runtest
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/openzeppelin_test_1_5_and_12_15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node_modules-

- name: Cache of the axon binary
uses: actions/cache@v3
with:
Expand All @@ -109,7 +109,8 @@ jobs:
- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /tmp/log 2>&1 &

- name: Run prepare
id: runtest
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/openzeppelin_test_6_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ jobs:
target/debug/axon
target/release/axon
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-axon-${{ github.sha }}

- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /tmp/log 2>&1 &
- name: Run prepare
id: runtest
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/somking_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
- name: Start axon
run: |
cd ${{ github.workspace }}/axon
./axon run --config ${{ github.workspace }}/axon/config.toml --chain-spec ${{ github.workspace }}/axon/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./axon init --config ${{ github.workspace }}/axon/config.toml --chain-spec ${{ github.workspace }}/axon/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./axon run --config ${{ github.workspace }}/axon/config.toml >> /tmp/log 2>&1 &
sleep 120
- name: Check Axon Status
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/v3_core_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ jobs:
- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /tmp/log 2>&1 &
- name: Install dependencies
run: |
cd /home/runner/work/axon/axon/v3-core
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/web3_compatible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
os: [ubuntu-22.04]
fail-fast: false
runs-on: ${{ matrix.os }}
env:
env:
IS_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }}
IS_REGRESSION: ${{ github.event.inputs.dispatch == 'regression' }}

Expand Down Expand Up @@ -66,10 +66,13 @@ jobs:
- name: Deploy Local Network of Axon
run: |
rm -rf ./devtools/chain/data
./target/debug/axon run \
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
> /tmp/log 2>&1 &
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
>> /tmp/log 2>&1 &

- name: Checkout gpBlockchain/axon-test
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ RUN set -eux; \
COPY --from=builder /build/target/release/axon /app/axon
COPY --from=builder /build/devtools /app/devtools

CMD ./axon run -c=/app/devtools/chain/config.toml -s=/app/devtools/chain/specs/single_node/chain-spec.toml
CMD /app/devtools/docker/docker-entrypoint.sh
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ e2e-test-lint:
e2e-test:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /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
Expand All @@ -73,7 +74,8 @@ e2e-test:
e2e-test-ci:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
./target/debug/axon init --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1
./target/debug/axon run --config devtools/chain/config.toml >> /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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ 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 -- run -c devtools/chain/config.toml -s devtools/chain/specs/single_node/chain-spec.toml
cargo run --release -- init -c devtools/chain/config.toml -s devtools/chain/specs/single_node/chain-spec.toml
cargo run --release -- run -c devtools/chain/config.toml

```

Expand Down
44 changes: 44 additions & 0 deletions core/cli/src/args/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use clap::Parser;

use common_config_parser::types::{spec::ChainSpec, Config};
use common_version::Version;

use crate::{
error::{Error, Result},
utils,
};

#[derive(Parser, Debug)]
#[command(about = "Initialize new axon data directory")]
pub struct InitArgs {
#[arg(
short = 'c',
long = "config",
value_name = "CONFIG_FILE",
help = "File path of client configurations."
)]
pub config: Config,
#[arg(
short = 's',
long = "chain-spec",
value_name = "CHAIN_SPEC_FILE",
help = "File path of chain spec."
)]
pub spec: ChainSpec,
}

impl InitArgs {
pub(crate) fn execute(self, kernel_version: Version) -> Result<()> {
let Self { config, spec } = self;
let genesis = spec.genesis.build_rich_block();

utils::check_version(
&config.data_path_for_version(),
&kernel_version,
utils::latest_compatible_version(),
)?;
utils::register_log(&config);

core_run::init(config, spec, genesis).map_err(Error::Running)
}
}
1 change: 1 addition & 0 deletions core/cli/src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod init;
pub(crate) mod run;
21 changes: 6 additions & 15 deletions core/cli/src/args/run.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use clap::Parser;

use common_config_parser::types::{spec::ChainSpec, Config};
use common_config_parser::types::Config;
use common_version::Version;
use core_run::{Axon, KeyProvider};
use core_run::KeyProvider;

use crate::{
error::{Error, Result},
utils,
};

#[derive(Parser, Debug)]
#[command(about = "Run axon process")]
#[command(about = "Run axon service")]
pub struct RunArgs {
#[arg(
short = 'c',
Expand All @@ -19,13 +19,6 @@ pub struct RunArgs {
help = "File path of client configurations."
)]
pub config: Config,
#[arg(
short = 's',
long = "chain-spec",
value_name = "CHAIN_SPEC_FILE",
help = "File path of chain spec."
)]
pub spec: ChainSpec,
}

impl RunArgs {
Expand All @@ -35,8 +28,7 @@ impl RunArgs {
kernel_version: Version,
key_provider: Option<K>,
) -> Result<()> {
let Self { config, spec } = self;
let genesis = spec.genesis.build_rich_block();
let Self { config } = self;

utils::check_version(
&config.data_path_for_version(),
Expand All @@ -45,8 +37,7 @@ impl RunArgs {
)?;
utils::register_log(&config);

Axon::new(application_version.to_string(), config, spec, genesis)
.run(key_provider)
.map_err(Error::Running)
let version = application_version.to_string();
core_run::run(version, config, key_provider).map_err(Error::Running)
}
}
4 changes: 3 additions & 1 deletion core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod args;
mod error;
pub(crate) mod utils;

pub use args::run::RunArgs;
pub use args::{init::InitArgs, run::RunArgs};
pub use error::{CheckingVersionError, Error, Result};

use clap::{CommandFactory as _, FromArgMatches as _, Parser, Subcommand};
Expand All @@ -19,6 +19,7 @@ struct Cli {

#[derive(Subcommand, Debug)]
enum Commands {
Init(InitArgs),
Run(RunArgs),
}

Expand Down Expand Up @@ -57,6 +58,7 @@ impl AxonCli {
inner: cli,
} = self;
match cli.command {
Commands::Init(args) => args.execute(kernel_version),
Commands::Run(args) => args.execute(application_version, kernel_version, key_provider),
}
}
Expand Down
25 changes: 18 additions & 7 deletions core/db/src/rocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ pub struct RocksAdapter {
}

impl RocksAdapter {
/// Create a new RocksDB or load an already existed RocksDB.
pub fn new<P: AsRef<Path>>(path: P, config: ConfigRocksDB) -> ProtocolResult<Self> {
if !path.as_ref().is_dir() {
Self::open_internal(path, config, true)
}

/// Open an already existed RocksDB, or return error if it doesn't exist.
pub fn open<P: AsRef<Path>>(path: P, config: ConfigRocksDB) -> ProtocolResult<Self> {
Self::open_internal(path, config, false)
}

fn open_internal<P: AsRef<Path>>(
path: P,
config: ConfigRocksDB,
allow_missing: bool,
) -> ProtocolResult<Self> {
if allow_missing && !path.as_ref().is_dir() {
fs::create_dir_all(&path).map_err(RocksDBError::CreateDB)?;
}

Expand Down Expand Up @@ -66,15 +80,12 @@ impl RocksAdapter {
(opts, cf_descriptors)
};

opts.create_if_missing(true);
if allow_missing {
opts.create_if_missing(true);
}
opts.create_missing_column_families(true);
opts.set_max_open_files(config.max_open_files);

// let tmp_db = DB::list_cf(&opts, path).map_err(RocksDBError::from)?;
// if tmp_db.len() != cf_descriptors.len() {
// opts.create_missing_column_families(true);
// }

let db =
DB::open_cf_descriptors(&opts, path, cf_descriptors).map_err(RocksDBError::from)?;

Expand Down
2 changes: 1 addition & 1 deletion core/run/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ rlp = "0.5"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tempfile = "3.6"
toml = "0.7"

common-apm = { path = "../../common/apm" }
Expand All @@ -38,6 +37,7 @@ jemallocator = { version = "0.5", features = ["profiling", "stats", "unprefixed_

[dev-dependencies]
clap = "4.3"
tempfile = "3.6"

[features]
jemalloc = ["dep:jemallocator", "dep:jemalloc-ctl", "dep:common-memory-tracker"]
8 changes: 7 additions & 1 deletion core/run/src/components/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ impl DatabaseGroup {
pub(crate) fn new<P: AsRef<Path>>(
config: &ConfigRocksDB,
rocksdb_path: P,
is_first_run: bool,
triedb_cache_size: usize,
) -> ProtocolResult<Self> {
let adapter = Arc::new(RocksAdapter::new(rocksdb_path, config.clone())?);
let adapter_inner = if is_first_run {
RocksAdapter::new(rocksdb_path, config.clone())
} else {
RocksAdapter::open(rocksdb_path, config.clone())
}?;
let adapter = Arc::new(adapter_inner);
let inner_db = adapter.inner_db();
let trie_db = Arc::new(RocksTrieDB::new_evm(adapter.inner_db(), triedb_cache_size));
let storage = Arc::new(ImplStorage::new(adapter, config.cache_size));
Expand Down
Loading
Loading