Skip to content

Commit

Permalink
feat: if hardforks only one and eq None, it will be no hardfork enabl…
Browse files Browse the repository at this point in the history
…e in genesis
  • Loading branch information
driftluo committed Oct 10, 2023
1 parent 25d85ac commit a813760
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
24 changes: 16 additions & 8 deletions common/config-parser/src/types/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,11 @@ impl Genesis {
}

pub fn generate_hardfork_info(&self) -> HardforkInfoInner {
let mut info = Into::<HardforkInfoInner>::into(HardforkInput {
let info = Into::<HardforkInfoInner>::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
}
}
Expand All @@ -238,12 +234,24 @@ pub struct HardforkInput {

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);
let convert_fn = |hardforks: Vec<HardforkName>| -> 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,
Expand All @@ -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
}
}
17 changes: 9 additions & 8 deletions core/executor/src/system_contract/metadata/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a813760

Please sign in to comment.