diff --git a/configs/presets/devnet.yaml b/configs/presets/devnet.yaml index a33227182..ff994280c 100644 --- a/configs/presets/devnet.yaml +++ b/configs/presets/devnet.yaml @@ -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" diff --git a/configs/presets/integration.yaml b/configs/presets/integration.yaml index 2b522fd3c..ef7e271dd 100644 --- a/configs/presets/integration.yaml +++ b/configs/presets/integration.yaml @@ -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" diff --git a/configs/presets/mainnet.yaml b/configs/presets/mainnet.yaml index 305f60df7..7a75f0aaa 100644 --- a/configs/presets/mainnet.yaml +++ b/configs/presets/mainnet.yaml @@ -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" diff --git a/configs/presets/sepolia.yaml b/configs/presets/sepolia.yaml index 3186427e3..886552bc5 100644 --- a/configs/presets/sepolia.yaml +++ b/configs/presets/sepolia.yaml @@ -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" diff --git a/crates/primitives/chain_config/src/chain_config.rs b/crates/primitives/chain_config/src/chain_config.rs index 1e098052c..3cdbccbc0 100644 --- a/crates/primitives/chain_config/src/chain_config.rs +++ b/crates/primitives/chain_config/src/chain_config.rs @@ -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"), @@ -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); impl 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); } } @@ -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) } }