diff --git a/common/config-parser/src/types/spec.rs b/common/config-parser/src/types/spec.rs index 76caa7e84..df70f8d28 100644 --- a/common/config-parser/src/types/spec.rs +++ b/common/config-parser/src/types/spec.rs @@ -211,15 +211,11 @@ impl Genesis { } pub fn generate_hardfork_info(&self) -> HardforkInfoInner { - let mut info = Into::::into(HardforkInput { + let info = 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 +234,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 +267,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