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

refactor(cli): initialize chain without any secret key #1467

Merged
merged 1 commit into from
Oct 11, 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
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,
}
Expand All @@ -47,23 +45,20 @@ 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: "0xe3a40f0115fbf101520ceea1ce7103a73cb46554187ac7ed67f3522103e06d99",
genesis_state_root: "0x2f1e8e50d5ab97af96fdb5d6de8e691e5bb80f46f2c98c4133d265bd8b60de61",
},
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: "0x1b4cf78373961dabcba5d4a9402c924fc4fecdd9ce367239f02c8971a052f3b5",
genesis_state_root: "0xf684cbec490eb5b8a07b80f369f3bf87f05ec73494b869111010a6ad6fa89894",
},
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: "0xd930632a7565acfc149c1d896d79910608768de5b936fdb34cc47c9b2296dd2a",
genesis_state_root: "0xa5e1e7ac3e03f7dc26cc93ab69c0ec49e591cbdaa7694c75682745c40bfca468",
},
Expand Down Expand Up @@ -113,13 +108,6 @@ 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 path_block = tmp_dir.path().join("block");
let db_group = DatabaseGroup::new(
Expand All @@ -130,7 +118,7 @@ async fn check_genesis_data<'a>(case: &TestCase<'a>) {
)
.expect("initialize databases");

let partial_genesis = chain_spec.generate_genesis_block(key);
let partial_genesis = chain_spec.generate_genesis_block();
let genesis = execute_genesis(partial_genesis, &chain_spec, &db_group)
.await
.expect("complete genesis block");
Expand Down
2 changes: 0 additions & 2 deletions devtools/chain/debug.key

This file was deleted.

3 changes: 1 addition & 2 deletions devtools/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ BASE_DIR="/app/devtools/chain"
DATA_DIR="${BASE_DIR}/data"
CONFIG_FILE="${BASE_DIR}/config.toml"
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}"
Loading