Skip to content

Commit

Permalink
refactor: split config and genesis to client config and chain spec (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yangby-cryptape authored Aug 21, 2023
1 parent 2014fa6 commit 1d89fa1
Show file tree
Hide file tree
Showing 47 changed files with 3,645 additions and 2,945 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/axon-start-with-short-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ jobs:
sudo rm -rf logs*
sudo rm -rf devtools/chain/data*
sed -i 's/image:.*$/image: axonweb3\/axon:start-test/g' docker-compose.yml
cp ${{ github.workspace }}/devtools/chain/geneses/genesis_multi_nodes_short_epoch_len.json devtools/chain/genesis_multi_nodes.json
cp ${{ github.workspace }}/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml devtools/chain/specs/multi_nodes/chain-spec.toml
cp ${{ github.workspace }}/devtools/chain/specs/multi_nodes_short_epoch_len/genesis_transactions.json devtools/chain/specs/multi_nodes/genesis_transactions.json
cp ${{ github.workspace }}/devtools/chain/k8s/node_1.toml devtools/chain/node_1.toml
cp ${{ github.workspace }}/devtools/chain/k8s/node_2.toml devtools/chain/node_2.toml
cp ${{ github.workspace }}/devtools/chain/k8s/node_3.toml devtools/chain/node_3.toml
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/copy_config_to_devops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
branches:
- main
paths:
- 'devtools/chain/genesis_multi_nodes.json'
- 'devtools/chain/default.db-options'
- 'devtools/chain/specs/multi_nodes'
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,13 +21,13 @@ jobs:
path: ${{ github.workspace}}/axon-devops
- name: apply config toml config_toml.patch
run: |
# copy default.db-options & genesis_multi_nodes.json to axon-devops always
# copy default.db-options & specs/multi_nodes to axon-devops always
cp ${{ github.workspace}}/devtools/chain/default.db-options ${{ github.workspace}}/axon-devops/deploy/templates
cp ${{ github.workspace}}/devtools/chain/default.db-options ${{ github.workspace}}/axon-devops/docker-deploy/devtools/chain
cp ${{ github.workspace}}/devtools/chain/default.db-options ${{ github.workspace}}/axon-devops/k8s-deploy/k8s/axon/axon-config
cp ${{ github.workspace}}/devtools/chain/nodes/genesis_multi_nodes.json ${{ github.workspace}}/axon-devops/deploy/templates/genesis.json
cp ${{ github.workspace}}/devtools/chain/nodes/genesis_multi_nodes.json ${{ github.workspace}}/axon-devops/docker-deploy/devtools/chain/genesis.json
cp ${{ github.workspace}}/devtools/chain/nodes/genesis_multi_nodes.json ${{ github.workspace}}/axon-devops/k8s-deploy/k8s/axon/axon-config/genesis.json
cp -r ${{ github.workspace}}/devtools/chain/nodes/specs/multi_nodes ${{ github.workspace}}/axon-devops/deploy/templates/specs
cp -r ${{ github.workspace}}/devtools/chain/nodes/specs/multi_nodes ${{ github.workspace}}/axon-devops/docker-deploy/devtools/chain/specs
cp -r ${{ github.workspace}}/devtools/chain/nodes/specs/multi_nodes ${{ github.workspace}}/axon-devops/k8s-deploy/k8s/axon/axon-config/specs
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_16_19.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_1_5_and_12_15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_6_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
run: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ jobs:
cp "target/${{ matrix.job.target }}/release/axon" "releases/$PKG_NAME"
cp "devtools/chain/config.toml" "releases/$PKG_NAME"
cp "devtools/chain/default.db-options" "releases/$PKG_NAME"
cp "devtools/chain/genesis_single_node.json" "releases/$PKG_NAME"
cp "devtools/chain/nodes/genesis_multi_nodes.json" "releases/$PKG_NAME"
cp -r "devtools/chain/specs" "releases/$PKG_NAME"
cp README.md "releases/$PKG_NAME"
cp -R docs "releases/$PKG_NAME"
cp core/api/README.md "releases/$PKG_NAME/docs/rpc.md"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/somking_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Start axon
run: |
cd ${{ github.workspace }}/axon
./axon run --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 --chain-spec ${{ github.workspace }}/axon/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
sleep 120
- name: Check Axon Status
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_core_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Install dependencies
run: |
cd /home/runner/work/axon/axon/v3-core
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/web3_compatible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run Test
run: |
cd /home/runner/work/axon/axon/axon-test
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 &
- name: Run Test
run: |
cd /home/runner/work/axon/axon/axon-test
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 -g=/app/devtools/chain/genesis_single_node.json


CMD ./axon run -c=/app/devtools/chain/config.toml -s=/app/devtools/chain/specs/single_node/chain-spec.toml
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ e2e-test-lint:
e2e-test:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.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 +73,7 @@ e2e-test:
e2e-test-ci:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon run --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 --chain-spec devtools/chain/specs/single_node/chain-spec.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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- run -c devtools/chain/config.toml -g devtools/chain/genesis_single_node.json
cargo run --release -- run -c devtools/chain/config.toml -s devtools/chain/specs/single_node/chain-spec.toml

```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{
collections::HashMap, ffi::OsStr, io, marker::PhantomData, net::SocketAddr, path::PathBuf,
};
use std::{collections::HashMap, ffi::OsStr, io, net::SocketAddr, path::PathBuf};

use clap::builder::{StringValueParser, TypedValueParser, ValueParserFactory};
use serde::{de, Deserialize};
use serde::Deserialize;
use tentacle_multiaddr::MultiAddr;

use protocol::types::{Hex, H160, U256};
use protocol::types::{Hex, H160};

use crate::parse_file;

Expand All @@ -15,15 +13,17 @@ pub const DEFAULT_BROADCAST_TXS_INTERVAL: u64 = 200; // milliseconds
pub const DEFAULT_SYNC_TXS_CHUNK_SIZE: usize = 5000;
pub const DEFAULT_CACHE_SIZE: usize = 100;

/// The configuration for Axon clients.
///
/// All configurations can be modified, and the chain won't be affected by their
/// changes.
#[derive(Clone, Debug, Deserialize)]
pub struct Config {
// crypto
pub privkey: Privkey,
// db config
pub data_path: PathBuf,

pub accounts: Vec<InitialAccount>,

pub rpc: ConfigApi,
pub web3: ConfigWeb3,
pub network: ConfigNetwork,
Expand Down Expand Up @@ -124,50 +124,15 @@ impl TypedValueParser for ConfigValueParser {
})
.map_err(|err| {
let kind = clap::error::ErrorKind::InvalidValue;
let msg = format!("failed to parse file {} since {err}", file_path.display());
let msg = format!(
"failed to parse config file {} since {err}",
file_path.display()
);
clap::Error::raw(kind, msg)
})
}
}

#[derive(Clone, Debug)]
pub struct JsonValueParser<T: de::DeserializeOwned + 'static + Clone + Send + Sync>(PhantomData<T>);

impl<T> Default for JsonValueParser<T>
where
T: de::DeserializeOwned + 'static + Clone + Send + Sync,
{
fn default() -> Self {
Self(PhantomData)
}
}

impl<T> TypedValueParser for JsonValueParser<T>
where
T: de::DeserializeOwned + 'static + Clone + Send + Sync,
{
type Value = T;

fn parse_ref(
&self,
cmd: &clap::Command,
arg: Option<&clap::Arg>,
value: &OsStr,
) -> Result<Self::Value, clap::Error> {
let file_path = StringValueParser::new()
.parse_ref(cmd, arg, value)
.map(PathBuf::from)?;
parse_file(&file_path, true).map_err(|err| {
let kind = clap::error::ErrorKind::InvalidValue;
let msg = format!(
"failed to parse JSON file {} since {err}",
file_path.display()
);
clap::Error::raw(kind, msg)
})
}
}

#[derive(Clone, Debug, Deserialize)]
pub struct ConfigApi {
pub http_listening_address: Option<SocketAddr>,
Expand Down Expand Up @@ -301,12 +266,6 @@ pub struct ConfigPrometheus {
pub listening_address: Option<SocketAddr>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct InitialAccount {
pub address: H160,
pub balance: U256,
}

fn default_max_gas_cap() -> u64 {
25_000_000
}
Expand Down
49 changes: 49 additions & 0 deletions common/config-parser/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::{ffi::OsStr, marker::PhantomData, path::PathBuf};

use clap::builder::{StringValueParser, TypedValueParser};
use serde::de;

use crate::parse_file;

mod config;
pub mod spec;

pub use config::*;

#[derive(Clone, Debug)]
pub struct JsonValueParser<T: de::DeserializeOwned + 'static + Clone + Send + Sync>(PhantomData<T>);

impl<T> Default for JsonValueParser<T>
where
T: de::DeserializeOwned + 'static + Clone + Send + Sync,
{
fn default() -> Self {
Self(PhantomData)
}
}

impl<T> TypedValueParser for JsonValueParser<T>
where
T: de::DeserializeOwned + 'static + Clone + Send + Sync,
{
type Value = T;

fn parse_ref(
&self,
cmd: &clap::Command,
arg: Option<&clap::Arg>,
value: &OsStr,
) -> Result<Self::Value, clap::Error> {
let file_path = StringValueParser::new()
.parse_ref(cmd, arg, value)
.map(PathBuf::from)?;
parse_file(&file_path, true).map_err(|err| {
let kind = clap::error::ErrorKind::InvalidValue;
let msg = format!(
"failed to parse JSON file {} since {err}",
file_path.display()
);
clap::Error::raw(kind, msg)
})
}
}
Loading

0 comments on commit 1d89fa1

Please sign in to comment.