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 4049cd7 commit 1211020
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
28 changes: 17 additions & 11 deletions common/config-parser/src/types/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,10 @@ impl Genesis {
}

pub fn generate_hardfork_info(&self) -> HardforkInfoInner {
let mut info = Into::<HardforkInfoInner>::into(HardforkInput {
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 +232,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 +265,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
12 changes: 6 additions & 6 deletions core/run/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ 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 {
chain_name: "multi_nodes",
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 {
chain_name: "multi_nodes_short_epoch_len",
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",
},
];
Expand Down

0 comments on commit 1211020

Please sign in to comment.