Skip to content

Commit

Permalink
refactor(cli): initialize chain without secret keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yangby-cryptape committed Oct 10, 2023
1 parent 5b2310c commit 81cfc98
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 54 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/axon-start-with-short-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
| tee -a ${{ env.LOG_FILE }}
target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down Expand Up @@ -74,7 +73,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Cache of Cargo
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -102,7 +101,6 @@ jobs:
target/debug/axon init \
--config devtools/chain/nodes/node_${id}.toml \
--chain-spec devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml \
--key-file devtools/chain/debug.key \
> ${{ env.LOG_PATH }}/node_${id}.log
done
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/openzeppelin_test_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/openzeppelin_test_16_19.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/openzeppelin_test_1_5_and_12_15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/openzeppelin_test_6_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/somking_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
./axon init \
--config ${{ github.workspace }}/axon/config.toml \
--chain-spec ${{ github.workspace }}/axon/specs/single_node/chain-spec.toml \
--key-file ${{ github.workspace }}/axon/debug.key \
> /tmp/log 2>&1
./axon run \
--config ${{ github.workspace }}/axon/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/v3_core_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/web3_compatible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ e2e-test:
./target/debug/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key \
> /tmp/log 2>&1
./target/debug/axon run \
--config devtools/chain/config.toml \
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ cargo build --release
# Initialize the chain
target/release/axon init \
--config devtools/chain/config.toml \
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \
--key-file devtools/chain/debug.key
--chain-spec devtools/chain/specs/single_node/chain-spec.toml
# Start a single Axon node
target/release/axon run --config devtools/chain/config.toml
```
Expand Down
14 changes: 3 additions & 11 deletions core/cli/src/args/init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use clap::Parser;

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

use crate::{
Expand All @@ -28,16 +25,11 @@ pub struct InitArgs {
help = "File path of chain spec."
)]
pub spec: ChainSpec,

#[command(flatten)]
pub key: PrivateKey,
}

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

let key_data = key.data().map_err(Error::Internal)?;
let Self { config, spec } = self;

utils::check_version(
&config.data_path_for_version(),
Expand All @@ -46,6 +38,6 @@ impl InitArgs {
)?;
utils::register_log(&config);

core_run::init(config, spec, key_data).map_err(Error::Running)
core_run::init(config, spec).map_err(Error::Running)
}
}
5 changes: 2 additions & 3 deletions core/run/src/components/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use common_config_parser::types::spec::ChainSpec;
use common_crypto::Secp256k1RecoverablePrivateKey;

use protocol::types::{
Block, Eip1559Transaction, RichBlock, TransactionAction, UnsignedTransaction, BASE_FEE_PER_GAS,
};

pub(crate) trait ChainSpecExt {
//! Generate the genesis block.
fn generate_genesis_block(&self, genesis_key: Secp256k1RecoverablePrivateKey) -> RichBlock;
fn generate_genesis_block(&self) -> RichBlock;
}

impl ChainSpecExt for ChainSpec {
fn generate_genesis_block(&self, _genesis_key: Secp256k1RecoverablePrivateKey) -> RichBlock {
fn generate_genesis_block(&self) -> RichBlock {
let txs = vec![];
let block = Block {
header: self.genesis.build_header(),
Expand Down
13 changes: 3 additions & 10 deletions core/run/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration};
use common_apm::metrics::mempool::{MEMPOOL_CO_QUEUE_LEN, MEMPOOL_LEN_GAUGE};
use common_config_parser::types::spec::{ChainSpec, InitialAccount};
use common_config_parser::types::{Config, ConfigMempool};
use common_crypto::{
BlsPrivateKey, BlsPublicKey, Secp256k1, Secp256k1PrivateKey, Secp256k1RecoverablePrivateKey,
ToPublicKey,
};
use common_crypto::{BlsPrivateKey, BlsPublicKey, Secp256k1, Secp256k1PrivateKey, ToPublicKey};

use protocol::tokio::{
self, runtime::Builder as RuntimeBuilder, sync::Mutex as AsyncMutex, time::sleep,
Expand Down Expand Up @@ -50,12 +47,8 @@ use components::{
pub use error::MainError;
use key_provider::KeyP;

pub fn init(
config: Config,
spec: ChainSpec,
key: Secp256k1RecoverablePrivateKey,
) -> ProtocolResult<()> {
let genesis = spec.generate_genesis_block(key);
pub fn init(config: Config, spec: ChainSpec) -> ProtocolResult<()> {
let genesis = spec.generate_genesis_block();

let path_rocksdb = config.data_path_for_rocksdb();
if path_rocksdb.exists() {
Expand Down
16 changes: 2 additions & 14 deletions core/run/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use clap::{builder::TypedValueParser as _, Command};
use hasher::HasherKeccak;

use common_config_parser::types::{
spec::{ChainSpec, ChainSpecValueParser, PrivateKeyFileValueParser},
spec::{ChainSpec, ChainSpecValueParser},
Config, ConfigValueParser,
};
use common_crypto::Secp256k1RecoverablePrivateKey;
use core_executor::{
system_contract::metadata::{segment::EpochSegment, EPOCH_SEGMENT_KEY},
AxonExecutorApplyAdapter, MetadataHandle,
Expand All @@ -37,7 +36,6 @@ struct TestCase<'a> {
chain_name: &'a str,
config_file: &'a str,
chain_spec_file: &'a str,
key_file: &'a str,
input_genesis_hash: &'a str,
genesis_state_root: &'a str,
genesis_receipts_root: &'a str,
Expand All @@ -48,7 +46,6 @@ const TESTCASES: &[TestCase] = &[
chain_name: "single_node",
config_file: "config.toml",
chain_spec_file: "specs/single_node/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0x4e06dc4a01178db42c029f7d65f65a5763702a21082cfcb626c6c41054a7a276",
genesis_state_root: "0x2f1e8e50d5ab97af96fdb5d6de8e691e5bb80f46f2c98c4133d265bd8b60de61",
genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
Expand All @@ -57,7 +54,6 @@ const TESTCASES: &[TestCase] = &[
chain_name: "multi_nodes",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0xf16db25ca1a0cff5339d76e9802c75c43faac35ee4a9294a51234b167c69159f",
genesis_state_root: "0xf684cbec490eb5b8a07b80f369f3bf87f05ec73494b869111010a6ad6fa89894",
genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
Expand All @@ -66,7 +62,6 @@ const TESTCASES: &[TestCase] = &[
chain_name: "multi_nodes_short_epoch_len",
config_file: "nodes/node_1.toml",
chain_spec_file: "specs/multi_nodes_short_epoch_len/chain-spec.toml",
key_file: "debug.key",
input_genesis_hash: "0x4e06dc4a01178db42c029f7d65f65a5763702a21082cfcb626c6c41054a7a276",
genesis_state_root: "0xa5e1e7ac3e03f7dc26cc93ab69c0ec49e591cbdaa7694c75682745c40bfca468",
genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
Expand Down Expand Up @@ -117,14 +112,7 @@ async fn check_genesis_data<'a>(case: &TestCase<'a>) {
.parse_ref(&command, None, chain_spec_path.as_os_str())
.expect("parse chain-spec file")
};
let key: Secp256k1RecoverablePrivateKey = {
let key_file_path = tmp_dir_path.join(case.key_file);
let key_data = PrivateKeyFileValueParser
.parse_ref(&command, None, key_file_path.as_os_str())
.expect("parse key file");
Secp256k1RecoverablePrivateKey::try_from(key_data.as_ref()).expect("load key data")
};
let genesis = chain_spec.generate_genesis_block(key);
let genesis = chain_spec.generate_genesis_block();

assert!(genesis.txs.is_empty());

Expand Down
2 changes: 0 additions & 2 deletions devtools/chain/debug.key

This file was deleted.

2 changes: 1 addition & 1 deletion devtools/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ CHAIN_SPEC_FILE="${BASE_DIR}/specs/single_node/chain-spec.toml"
KEY_FILE="${BASE_DIR}/debug.key"

if [ ! -e "${DATA_DIR}" ]; then
/app/axon init --config "${CONFIG_FILE}" --chain-spec "${CHAIN_SPEC_FILE}" --key-file "${KEY_FILE}"
/app/axon init --config "${CONFIG_FILE}" --chain-spec "${CHAIN_SPEC_FILE}"
fi
/app/axon run --config "${CONFIG_FILE}"

0 comments on commit 81cfc98

Please sign in to comment.