diff --git a/common/config-parser/src/types/spec.rs b/common/config-parser/src/types/spec.rs index 58212728f..d182841e4 100644 --- a/common/config-parser/src/types/spec.rs +++ b/common/config-parser/src/types/spec.rs @@ -16,8 +16,8 @@ use common_crypto::Secp256k1RecoverablePrivateKey; use protocol::{ codec::{decode_256bits_key, deserialize_address, ProtocolCodec}, types::{ - Block, HardforkInfoInner, Header, Key256Bits, Metadata, RichBlock, SignedTransaction, H160, - H256, U256, + Block, ExtraData, HardforkInfoInner, Header, Key256Bits, Metadata, RichBlock, + SignedTransaction, H160, H256, U256, }, }; @@ -40,7 +40,7 @@ pub struct ChainSpec { #[derive(Clone, Debug, Deserialize)] pub struct Genesis { pub timestamp: u64, - pub extra_data: HardforkInput, + pub hardforks: Vec, pub base_fee_per_gas: U256, pub chain_id: u64, @@ -261,12 +261,12 @@ impl Genesis { timestamp: self.timestamp, // todo: if Hardforkinput is empty, it must change to latest hardfork info to init // genesis - extra_data: if self.extra_data.block_number != 0 { - Default::default() - } else { - Into::::into(self.extra_data.clone()) - .encode() - .unwrap() + extra_data: { + let r = self.hardforks.iter().fold(0, |acc, &s| acc | s as u64); + + vec![ExtraData { + inner: H256::from_low_u64_be(r.to_be()).encode().unwrap(), + }] }, base_fee_per_gas: self.base_fee_per_gas, chain_id: self.chain_id, diff --git a/core/api/src/jsonrpc/web3_types.rs b/core/api/src/jsonrpc/web3_types.rs index 27ceaeb89..90fe8241d 100644 --- a/core/api/src/jsonrpc/web3_types.rs +++ b/core/api/src/jsonrpc/web3_types.rs @@ -300,7 +300,7 @@ pub struct Web3Block { pub number: U256, pub gas_used: U256, pub gas_limit: U256, - pub extra_data: Hex, + pub extra_data: Vec, pub logs_bloom: Option, pub timestamp: U256, pub difficulty: U256, @@ -331,7 +331,12 @@ impl From for Web3Block { total_difficulty: Some(b.header.number.into()), seal_fields: vec![], base_fee_per_gas: b.header.base_fee_per_gas, - extra_data: Hex::encode(&b.header.extra_data), + extra_data: b + .header + .extra_data + .iter() + .map(|i| Hex::encode(&i.inner)) + .collect(), size: Some(b.header.size().into()), gas_limit: b.header.gas_limit, gas_used: b.header.gas_used, @@ -821,7 +826,7 @@ pub struct FeeHistoryEmpty { #[serde(rename_all = "camelCase")] pub struct Web3Header { pub difficulty: U256, - pub extra_data: Hex, + pub extra_data: Vec, pub gas_limit: U256, pub gas_used: U256, pub logs_bloom: Option, @@ -849,7 +854,11 @@ impl From
for Web3Header { receipts_root: h.receipts_root, miner: h.proposer, difficulty: U256::one(), - extra_data: Hex::encode(&h.extra_data), + extra_data: h + .extra_data + .into_iter() + .map(|i| Hex::encode(i.inner)) + .collect(), gas_limit: h.gas_limit, gas_used: h.gas_used, timestamp: h.timestamp.into(), diff --git a/core/consensus/src/engine.rs b/core/consensus/src/engine.rs index cc1ecd6ce..8ee990b38 100644 --- a/core/consensus/src/engine.rs +++ b/core/consensus/src/engine.rs @@ -19,8 +19,8 @@ use common_merkle::TrieMerkle; use core_executor::MetadataHandle; use protocol::traits::{ConsensusAdapter, Context, MessageTarget, NodeInfo}; use protocol::types::{ - Block, BlockVersion, Bytes, ExecResp, Hash, Hex, Metadata, Proof, Proposal, SignedTransaction, - ValidatorExtend, BASE_FEE_PER_GAS, MAX_BLOCK_GAS_LIMIT, RLP_NULL, + Block, BlockVersion, Bytes, ExecResp, ExtraData, Hash, Hex, Metadata, Proof, Proposal, + SignedTransaction, ValidatorExtend, BASE_FEE_PER_GAS, MAX_BLOCK_GAS_LIMIT, RLP_NULL, }; use protocol::{ async_trait, codec::ProtocolCodec, tokio::sync::Mutex as AsyncMutex, types::HardforkInfoInner, @@ -114,7 +114,9 @@ impl Engine for ConsensusEngine Engine for ConsensusEngine SystemContract let mut store = MetadataStore::new(root).unwrap(); - if let Ok(data) = HardforkInfoInner::decode(adapter.get_ctx().extra_data) { - store - .set_hardfork_info(data.block_number, data.flags) - .expect("set new hardfork info fail") + if let Some(t) = adapter.get_ctx().extra_data.get(0) { + if let Ok(data) = HardforkInfoInner::decode(&t.inner) { + store + .set_hardfork_info(data.block_number, data.flags) + .expect("set new hardfork info fail") + } } let hardfork = store.hardfork_info(block_number.as_u64()).unwrap(); diff --git a/core/run/src/tests.rs b/core/run/src/tests.rs index 33ef1c19f..fefa581a1 100644 --- a/core/run/src/tests.rs +++ b/core/run/src/tests.rs @@ -39,7 +39,7 @@ const TESTCASES: &[TestCase] = &[ config_file: "config.toml", chain_spec_file: "specs/single_node/chain-spec.toml", key_file: "debug.key", - input_genesis_hash: "0x5a4918d8cf9440b11f40047e184e4e2e0231cc449bd473d7dca1275b2ef938e1", + input_genesis_hash: "0x3efe365ab7a903557a846646bdc4abdb2eed9d7292ed2ccce1f2e94e1c9e7ad0", genesis_state_root: "0x601bd874d41eb9adb32021ee3ab934e0481065c58abfe7e757e33fb01be18dd5", genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b", }, @@ -48,7 +48,7 @@ const TESTCASES: &[TestCase] = &[ config_file: "nodes/node_1.toml", chain_spec_file: "specs/multi_nodes/chain-spec.toml", key_file: "debug.key", - input_genesis_hash: "0xf22e8b2cdcae7c833623c6a56ec072e130f1ac7dda93c615351e6598bdef61a1", + input_genesis_hash: "0xd138005096cc7e43531e34e33afd8964e9bde49afcb37ce0c8192650e18fa8ee", genesis_state_root: "0xc36f75519a047fec6a34c7be5dfca783a40eafa0d7418ad7b3ba99ad9c2dc655", genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b", }, @@ -57,7 +57,7 @@ const TESTCASES: &[TestCase] = &[ 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: "0x5a4918d8cf9440b11f40047e184e4e2e0231cc449bd473d7dca1275b2ef938e1", + input_genesis_hash: "0x3efe365ab7a903557a846646bdc4abdb2eed9d7292ed2ccce1f2e94e1c9e7ad0", genesis_state_root: "0x42886558baab8a3c310d5a8313398e5f353cc4f8192838b578c857a329e9bb65", genesis_receipts_root: "0x8544b530238201f1620b139861a6841040b37f78f8bdae8736ef5cec474e979b", }, diff --git a/devtools/chain/specs/multi_nodes/chain-spec.toml b/devtools/chain/specs/multi_nodes/chain-spec.toml index cfe8fe49c..a5a3292f8 100644 --- a/devtools/chain/specs/multi_nodes/chain-spec.toml +++ b/devtools/chain/specs/multi_nodes/chain-spec.toml @@ -9,9 +9,6 @@ base_fee_per_gas = "0x539" chain_id = 0x41786f6e # A JSON file which includes all transactions in the genesis block. transactions = "genesis_transactions.json" - -[genesis.extra_data] -block_number = 0 hardforks = [] # diff --git a/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml b/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml index 91c8a5cd0..b7c9f9d28 100644 --- a/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml +++ b/devtools/chain/specs/multi_nodes_short_epoch_len/chain-spec.toml @@ -9,9 +9,6 @@ base_fee_per_gas = "0x539" chain_id = 0x41786f6e # A JSON file which includes all transactions in the genesis block. transactions = "genesis_transactions.json" - -[genesis.extra_data] -block_number = 0 hardforks = [] # diff --git a/devtools/chain/specs/single_node/chain-spec.toml b/devtools/chain/specs/single_node/chain-spec.toml index 65751daef..a986fd844 100644 --- a/devtools/chain/specs/single_node/chain-spec.toml +++ b/devtools/chain/specs/single_node/chain-spec.toml @@ -9,9 +9,6 @@ base_fee_per_gas = "0x539" chain_id = 0x41786f6e # A JSON file which includes all transactions in the genesis block. transactions = "genesis_transactions.json" - -[genesis.extra_data] -block_number = 0 hardforks = [] # diff --git a/protocol/src/types/block.rs b/protocol/src/types/block.rs index 74f6ea964..b4b4adc9a 100644 --- a/protocol/src/types/block.rs +++ b/protocol/src/types/block.rs @@ -58,11 +58,7 @@ pub struct Proposal { #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] pub number: BlockNumber, pub gas_limit: U256, - #[cfg_attr( - feature = "hex-serialize", - serde(serialize_with = "withpfx_lowercase::serialize") - )] - pub extra_data: Bytes, + pub extra_data: Vec, pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] @@ -223,11 +219,7 @@ pub struct Header { pub number: BlockNumber, pub gas_used: U256, pub gas_limit: U256, - #[cfg_attr( - feature = "hex-serialize", - serde(serialize_with = "withpfx_lowercase::serialize") - )] - pub extra_data: Bytes, + pub extra_data: Vec, pub base_fee_per_gas: U256, pub proof: Proof, #[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))] @@ -246,6 +238,17 @@ impl Header { } } +#[derive( + RlpEncodable, RlpDecodable, Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, +)] +pub struct ExtraData { + #[cfg_attr( + feature = "hex-serialize", + serde(serialize_with = "withpfx_lowercase::serialize") + )] + pub inner: Bytes, +} + #[derive( RlpEncodable, RlpDecodable, Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq, )] diff --git a/protocol/src/types/executor.rs b/protocol/src/types/executor.rs index 26be301ca..808a5d7e5 100644 --- a/protocol/src/types/executor.rs +++ b/protocol/src/types/executor.rs @@ -4,8 +4,7 @@ pub use hasher::HasherKeccak; use rlp_derive::{RlpDecodable, RlpEncodable}; -use crate::types::{Bloom, Hash, Hasher, Header, MerkleRoot, Proposal, H160, U256}; -use bytes::Bytes; +use crate::types::{Bloom, ExtraData, Hash, Hasher, Header, MerkleRoot, Proposal, H160, U256}; const BLOOM_BYTE_LENGTH: usize = 256; @@ -54,7 +53,7 @@ pub struct ExecutorContext { pub gas_price: U256, pub block_gas_limit: U256, pub block_base_fee_per_gas: U256, - pub extra_data: Bytes, + pub extra_data: Vec, } impl From for ExecutorContext {