diff --git a/common/config-parser/src/types/spec.rs b/common/config-parser/src/types/spec.rs index 76caa7e84..85f9a0fa8 100644 --- a/common/config-parser/src/types/spec.rs +++ b/common/config-parser/src/types/spec.rs @@ -211,16 +211,10 @@ impl Genesis { } pub fn generate_hardfork_info(&self) -> HardforkInfoInner { - let mut info = Into::::into(HardforkInput { + Into::::into(HardforkInput { hardforks: self.hardforks.clone(), block_number: 0, - }); - - if info.flags.is_zero() { - info.flags = H256::from_low_u64_be(HardforkName::all().to_be()); - } - - info + }) } } @@ -238,12 +232,24 @@ pub struct HardforkInput { impl From for HardforkInfoInner { fn from(value: HardforkInput) -> Self { - let flags = { - let r = value.hardforks.into_iter().fold(0, |acc, s| acc | s as u64); + let convert_fn = |hardforks: Vec| -> H256 { + let r = hardforks.into_iter().fold(0, |acc, s| acc | s as u64); H256::from_low_u64_be(r.to_be()) }; + let flags = if value.hardforks.is_empty() { + H256::from_low_u64_be(HardforkName::all().to_be()) + } else if value.hardforks.len() == 1 { + if value.hardforks[0] == HardforkName::None { + H256::zero() + } else { + convert_fn(value.hardforks) + } + } else { + convert_fn(value.hardforks) + }; + HardforkInfoInner { block_number: value.block_number, flags, @@ -259,6 +265,6 @@ pub enum HardforkName { impl HardforkName { pub fn all() -> u64 { - HardforkName::None as u64 | HardforkName::Andromeda as u64 + HardforkName::Andromeda as u64 } } diff --git a/core/executor/src/system_contract/metadata/store.rs b/core/executor/src/system_contract/metadata/store.rs index d3d61c182..f8cbaef4b 100644 --- a/core/executor/src/system_contract/metadata/store.rs +++ b/core/executor/src/system_contract/metadata/store.rs @@ -18,14 +18,15 @@ use crate::{adapter::RocksTrieDB, MPTTrie, CURRENT_METADATA_ROOT}; /// The metadata store does not follow the storage layout of EVM smart contract. /// It use MPT called Metadata MPT with the following layout: -/// | key | value | -/// | -------------------- | ------------------------ | -/// | EPOCH_SEGMENT_KEY | `EpochSegment.encode()` | -/// | CKB_RELATED_INFO_KEY | `CkbRelatedInfo.encode()`| -/// | HARDFORK_KEY | `HardforkInfo.encode()` | -/// | epoch_0.be_bytes() | `Metadata.encode()` | -/// | epoch_1.be_bytes() | `Metadata.encode()` | -/// | ... | ... | +/// | key | value | +/// | -------------------- | ------------------------------------ | +/// | EPOCH_SEGMENT_KEY | `EpochSegment.encode()` | +/// | CKB_RELATED_INFO_KEY | `CkbRelatedInfo.encode()` | +/// | HARDFORK_KEY | `HardforkInfo.encode()` | +/// | epoch_0.be_bytes() | `Metadata.encode()` | +/// | epoch_1.be_bytes() | `Metadata.encode()` | +/// | CONSENSUS_CONFIG | `version + ConsensesConfig.encode()` | +/// | ... | ... | /// /// All these data are stored in a the `c9` column family of RocksDB, and the /// root of the Metadata MPT is stored in the storage MPT of the metadata diff --git a/core/run/src/tests.rs b/core/run/src/tests.rs index ae5961b20..de01e2943 100644 --- a/core/run/src/tests.rs +++ b/core/run/src/tests.rs @@ -50,8 +50,8 @@ const TESTCASES: &[TestCase] = &[ config_file: "config.toml", chain_spec_file: "specs/single_node/chain-spec.toml", key_file: "debug.key", - input_genesis_hash: "0xb427513ec79cedda702cf21fe2e5514c6f5d75fe8134e00d1f88f87d7a8ca823", - genesis_state_root: "0xfcb1f7a0000aac13be142babea87b3ee29a562111bf7e70ee22eae152ac40991", + input_genesis_hash: "0x7482aab9053b82a027477ca53cd418ffafd866ccc57b6a7718554847723e38be", + genesis_state_root: "0xf939bf06a1d818aee1555a11f06b20c215003c056e26403ecb1cb4b15958f6ac", genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", }, TestCase { @@ -59,8 +59,8 @@ 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: "0x6b2214dc0bd93c64c234a99d996c90ccd97b0f89a888d50292dc34897486e30a", - genesis_state_root: "0x11f586d996d7706bd2ee430224c279cd75b1a12bcb743dc139bea9cba2516f89", + input_genesis_hash: "0x6814c79e5f439158c00bc45dee23134966152870136a6bf41e5d0be07178baa8", + genesis_state_root: "0xe911923f522acff78d3f08b851aca86870bda9f24f1722f1d97518ff3b8697c6", genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", }, TestCase { @@ -68,8 +68,8 @@ 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: "0x7360659a70f5713a4cc30b51e819dacd421047faf3295371cccbd34f7e5536c3", - genesis_state_root: "0xc6ed6cbebcdcd05d72c9fb0ed6a9303179ca226a940c638b6dee63e7ffaec7bb", + input_genesis_hash: "0x8f6fe8d64998559224b7d635aee0681435eaa8e27dea52c7cc11c4967593815f", + genesis_state_root: "0x1fc51ffe40ba5f03523370e8a1baba3046574db9abf769f21e42458f50047a2c", genesis_receipts_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", }, ];