Skip to content

Commit

Permalink
impl versioned_constants::default()
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Oct 7, 2024
1 parent 68a60dd commit ad1e134
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
4 changes: 0 additions & 4 deletions configs/presets/devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ chain_id: "MADARA_DEVNET"
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
versioned_constants:
"0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json"
"0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json"
"0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json"
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"
eth_core_contract_address: "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057"
latest_protocol_version: "0.13.2"
block_time: "30s"
Expand Down
4 changes: 0 additions & 4 deletions configs/presets/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ chain_id: "SN_INTEGRATION_SEPOLIA"
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
versioned_constants:
"0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json"
"0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json"
"0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json"
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"
eth_core_contract_address: "0x4737c0c1B4D5b1A687B42610DdabEE781152359c"
latest_protocol_version: "0.13.2"
block_time: "30s"
Expand Down
4 changes: 0 additions & 4 deletions configs/presets/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ chain_id: "SN_MAIN"
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
versioned_constants:
"0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json"
"0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json"
"0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json"
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"
eth_core_contract_address: "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
latest_protocol_version: "0.13.2"
block_time: "30s"
Expand Down
4 changes: 0 additions & 4 deletions configs/presets/sepolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ chain_id: "SN_SEPOLIA"
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
versioned_constants:
"0.13.0": "crates/primitives/chain_config/resources/versioned_constants_13_0.json"
"0.13.1": "crates/primitives/chain_config/resources/versioned_constants_13_1.json"
"0.13.1.1": "crates/primitives/chain_config/resources/versioned_constants_13_1_1.json"
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"
eth_core_contract_address: "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057"
latest_protocol_version: "0.13.2"
block_time: "30s"
Expand Down
43 changes: 33 additions & 10 deletions crates/primitives/chain_config/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ impl ChainConfig {
))
.unwrap(),
),
versioned_constants: [
(StarknetVersion::V0_13_0, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_0.deref().clone()),
(StarknetVersion::V0_13_1, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_1.deref().clone()),
(StarknetVersion::V0_13_1_1, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_1_1.deref().clone()),
(StarknetVersion::V0_13_2, VersionedConstants::latest_constants().clone()),
]
.into(),
versioned_constants: ChainVersionedConstants::default(),

eth_core_contract_address: eth_core_contract_address::MAINNET.parse().expect("parsing a constant"),

Expand Down Expand Up @@ -250,12 +244,34 @@ impl ChainConfig {

// TODO: the motivation for these doc comments is to move them into a proper app chain developer documentation, with a
// proper page about tuning the block production performance.
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct ChainVersionedConstants(pub BTreeMap<StarknetVersion, VersionedConstants>);

impl<const N: usize> From<[(StarknetVersion, VersionedConstants); N]> for ChainVersionedConstants {
fn from(arr: [(StarknetVersion, VersionedConstants); N]) -> Self {
ChainVersionedConstants(arr.into_iter().collect())
ChainVersionedConstants(arr.into())
}
}

impl Default for ChainVersionedConstants {
fn default() -> Self {
[
(StarknetVersion::V0_13_0, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_0.deref().clone()),
(StarknetVersion::V0_13_1, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_1.deref().clone()),
(StarknetVersion::V0_13_1_1, BLOCKIFIER_VERSIONED_CONSTANTS_0_13_1_1.deref().clone()),
(StarknetVersion::V0_13_2, VersionedConstants::latest_constants().clone()),
]
.into()
}
}

impl ChainVersionedConstants {
pub fn add(&mut self, version: StarknetVersion, constants: VersionedConstants) {
self.0.insert(version, constants);
}

pub fn merge(&mut self, other: Self) {
self.0.extend(other.0);
}
}

Expand Down Expand Up @@ -292,7 +308,14 @@ impl<'de> Deserialize<'de> for ChainVersionedConstants {
result.insert(parsed_version, constants);
}

Ok(ChainVersionedConstants(result))
// insert the default versioned constants
let all_versionned_constants = {
let mut all_versionned_constants = ChainVersionedConstants::default();
all_versionned_constants.merge(ChainVersionedConstants(result));
all_versionned_constants
};

Ok(all_versionned_constants)
}
}

Expand Down

0 comments on commit ad1e134

Please sign in to comment.