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: support set hardfork from command line #1422

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 24 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions common/config-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
stringreader = "0.1"
strum = "0.25"
strum_macros = "0.25"
tentacle-multiaddr = "0.3"
toml = "0.7"

Expand Down
39 changes: 26 additions & 13 deletions common/config-parser/src/types/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::{
builder::{StringValueParser, TypedValueParser, ValueParserFactory},
Args,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use common_crypto::Secp256k1RecoverablePrivateKey;
use protocol::{
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct ChainSpec {
#[derive(Clone, Debug, Deserialize)]
pub struct Genesis {
pub timestamp: u64,
pub extra_data: HarforkInput,
pub extra_data: HardforkInput,
pub base_fee_per_gas: U256,
pub chain_id: u64,

Expand Down Expand Up @@ -261,24 +261,37 @@ impl Genesis {
timestamp: self.timestamp,
// todo: if Hardforkinput is empty, it must change to latest hardfork info to init
KaoImin marked this conversation as resolved.
Show resolved Hide resolved
// genesis
extra_data: Into::<HardforkInfoInner>::into(self.extra_data.clone())
.encode()
.unwrap(),
extra_data: if self.extra_data.block_number != 0 {
Default::default()
} else {
Into::<HardforkInfoInner>::into(self.extra_data.clone())
.encode()
.unwrap()
},
base_fee_per_gas: self.base_fee_per_gas,
chain_id: self.chain_id,
..Default::default()
}
}
}

#[derive(Clone, Debug, Deserialize)]
pub struct HarforkInput {
block_number: u64,
hardforks: Vec<HardforkType>,
use clap::ValueEnum;
use strum_macros::EnumIter;

#[derive(Clone, Debug, Deserialize, Args)]
pub struct HardforkInput {
#[arg(
long = "hardfork-start-number",
required = false,
requires = "hardforks"
)]
pub block_number: u64,
#[arg(long = "feature", requires = "block_number")]
pub hardforks: Vec<HardforkName>,
}

impl From<HarforkInput> for HardforkInfoInner {
fn from(value: HarforkInput) -> Self {
impl From<HardforkInput> for HardforkInfoInner {
fn from(value: HardforkInput) -> Self {
let flags = {
let r = value.hardforks.into_iter().fold(0, |acc, s| acc | s as u64);

Expand All @@ -292,7 +305,7 @@ impl From<HarforkInput> for HardforkInfoInner {
}
}

#[derive(Clone, Debug, Deserialize, Copy)]
enum HardforkType {
#[derive(Clone, Debug, Serialize, Deserialize, Copy, ValueEnum, EnumIter, PartialEq, Eq, Hash)]
pub enum HardforkName {
None = 0b0,
}
5 changes: 3 additions & 2 deletions core/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ beef = "0.5"
ckb-jsonrpc-types = "0.108"
ckb-traits = "0.108"
ckb-types = "0.108"
jsonrpsee = { version = "0.16", features = ["macros","server"] }
jsonrpsee = { version = "0.16", features = ["macros", "server"] }
log = "0.4"
parking_lot = "0.12"
pprof = { version = "0.11", features = ["prost-codec"], optional = true }
rlp = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = "0.25"

common-apm = { path = "../../common/apm" }
common-config-parser = { path = "../../common/config-parser" }
core-consensus = { path = "../../core/consensus" }
core-executor = { path = "../../core/executor" }
core-interoperation ={ path = "../../core/interoperation" }
core-interoperation = { path = "../../core/interoperation" }
either = { version = "1.8", features = ["serde"] }
protocol = { path = "../../protocol", package = "axon-protocol" }

Expand Down
8 changes: 6 additions & 2 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use protocol::traits::{
use protocol::trie::Trie as _;
use protocol::types::{
Account, BigEndianHash, Block, BlockNumber, Bytes, CkbRelatedInfo, ExecutorContext,
HardforkInfo, Hash, Header, Metadata, Proposal, Receipt, SignedTransaction, TxResp, H160, H256,
MAX_BLOCK_GAS_LIMIT, NIL_DATA, RLP_NULL, U256,
HardforkInfo, HardforkInfoInner, Hash, Header, Metadata, Proposal, Receipt, SignedTransaction,
TxResp, H160, H256, MAX_BLOCK_GAS_LIMIT, NIL_DATA, RLP_NULL, U256,
};
use protocol::{async_trait, codec::ProtocolCodec, trie, ProtocolResult};

Expand Down Expand Up @@ -289,4 +289,8 @@ where
async fn hardfork_info(&self, ctx: Context) -> ProtocolResult<HardforkInfo> {
MetadataHandle::new(self.get_metadata_root(ctx).await?).hardfork_infos()
}

async fn hardfork_proposal(&self, ctx: Context) -> ProtocolResult<Option<HardforkInfoInner>> {
self.storage.hardfork_proposal(ctx).await
}
}
Loading
Loading