From 0a40476e2b5dbae28d72841d48e377e22317d46e Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 14 Mar 2025 15:21:59 +0100 Subject: [PATCH 1/3] Etherlink/Kernel/Storage: Function to read the chain_family Introduce a root path pointing to where are stored the chain configurations --- etherlink/kernel_latest/kernel/src/chains.rs | 16 +++++++++++ etherlink/kernel_latest/kernel/src/storage.rs | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/etherlink/kernel_latest/kernel/src/chains.rs b/etherlink/kernel_latest/kernel/src/chains.rs index d3bccff5a72f..bf97cba52237 100644 --- a/etherlink/kernel_latest/kernel/src/chains.rs +++ b/etherlink/kernel_latest/kernel/src/chains.rs @@ -16,6 +16,22 @@ pub enum ChainFamily { Michelson, } +impl Default for ChainFamily { + fn default() -> Self { + Self::Evm + } +} + +impl From for ChainFamily { + fn from(value: String) -> Self { + match value.as_str() { + "Michelson" => Self::Michelson, + "Evm" => Self::Evm, + _ => Self::default(), + } + } +} + pub struct EvmChainConfig { pub chain_id: U256, pub limits: EvmLimits, diff --git a/etherlink/kernel_latest/kernel/src/storage.rs b/etherlink/kernel_latest/kernel/src/storage.rs index 417b6a9b70d8..ca86c5517d2e 100644 --- a/etherlink/kernel_latest/kernel/src/storage.rs +++ b/etherlink/kernel_latest/kernel/src/storage.rs @@ -6,6 +6,7 @@ // SPDX-License-Identifier: MIT use crate::block_in_progress::EthBlockInProgress; +use crate::chains::ChainFamily; use crate::event::Event; use crate::simulation::SimulationResult; use crate::tick_model::constants::MAXIMUM_GAS_LIMIT; @@ -118,6 +119,10 @@ const EVM_CHAIN_ID: RefPath = RefPath::assert_from(b"/evm/chain_id"); pub const ENABLE_MULTICHAIN: RefPath = RefPath::assert_from(b"/evm/feature_flags/enable_multichain"); +// Root for chain configurations. Informations about a chain are available by appending its chain ID. +pub const CHAIN_CONFIGURATIONS: RefPath = + RefPath::assert_from(b"/evm/chain_configurations"); + const EVM_MINIMUM_BASE_FEE_PER_GAS: RefPath = RefPath::assert_from(b"/evm/world_state/fees/minimum_base_fee_per_gas"); const EVM_DA_FEE: RefPath = @@ -191,6 +196,12 @@ pub fn object_path(object_hash: &TransactionHash) -> Result { concat(&EVM_TRANSACTIONS_OBJECTS, &object_path).map_err(Error::from) } +pub fn chain_config_path(chain_id: &U256) -> Result { + let raw_chain_id_path: Vec = format!("/{}", chain_id).into(); + let chain_id_path = OwnedPath::try_from(raw_chain_id_path)?; + concat(&CHAIN_CONFIGURATIONS, &chain_id_path).map_err(Error::from) +} + pub fn store_simulation_result( host: &mut Host, result: SimulationResult, @@ -871,6 +882,23 @@ pub fn max_blueprint_lookahead_in_seconds(host: &impl Runtime) -> anyhow::Result Ok(i64::from_le_bytes(bytes)) } +// Storage functions related to a chain configuration + +#[allow(dead_code)] +pub fn read_chain_family( + host: &impl Runtime, + chain_id: U256, +) -> anyhow::Result { + let chain_configurations_path = chain_config_path(&chain_id)?; + let chain_family_path = RefPath::assert_from(b"/chain_family"); + let path = concat(&chain_configurations_path, &chain_family_path)?; + let bytes = host + .store_read_all(&path) + .context(format!("Cannot read chain family for chain {}", chain_id))?; + let chain_family = String::from_utf8(bytes)?; + Ok(chain_family.into()) +} + #[cfg(test)] mod internal_for_tests { use super::*; -- GitLab From 14bd708b14a7e85bf98b432975cc196234c26eb8 Mon Sep 17 00:00:00 2001 From: arnaud Date: Tue, 18 Mar 2025 10:32:09 +0100 Subject: [PATCH 2/3] Etherlink/Kernel: Introducing a function to create a Michelson configuration --- etherlink/kernel_latest/kernel/src/chains.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etherlink/kernel_latest/kernel/src/chains.rs b/etherlink/kernel_latest/kernel/src/chains.rs index bf97cba52237..911a973aaa90 100644 --- a/etherlink/kernel_latest/kernel/src/chains.rs +++ b/etherlink/kernel_latest/kernel/src/chains.rs @@ -77,6 +77,10 @@ impl ChainConfig { ChainConfig::Evm(EvmChainConfig::create_config(chain_id, limits, evm_config)) } + pub fn new_michelson_config(chain_id: U256) -> Self { + ChainConfig::Michelson(MichelsonChainConfig::create_config(chain_id)) + } + pub fn get_chain_family(&self) -> ChainFamily { match self { ChainConfig::Evm(_) => ChainFamily::Evm, -- GitLab From efbb71620936fd308966e9f9569a82e3c4beb003 Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 14 Mar 2025 15:23:12 +0100 Subject: [PATCH 3/3] Etherlink/Kernel/Configuration: Fetch chain_configuration depending on the chain family found in the storage --- .../kernel_latest/kernel/src/configuration.rs | 31 +++++++++++++------ etherlink/kernel_latest/kernel/src/storage.rs | 1 - 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/etherlink/kernel_latest/kernel/src/configuration.rs b/etherlink/kernel_latest/kernel/src/configuration.rs index f2d0ac9192d6..1719fabf2237 100644 --- a/etherlink/kernel_latest/kernel/src/configuration.rs +++ b/etherlink/kernel_latest/kernel/src/configuration.rs @@ -5,15 +5,15 @@ use crate::{ blueprint_storage::DEFAULT_MAX_BLUEPRINT_LOOKAHEAD_IN_SECONDS, - chains::{ChainConfig, EvmLimits}, + chains::{ChainConfig, ChainFamily, EvmLimits}, delayed_inbox::DelayedInbox, retrieve_minimum_base_fee_per_gas, storage::{ dal_slots, enable_dal, evm_node_flag, is_enable_fa_bridge, - max_blueprint_lookahead_in_seconds, read_admin, read_delayed_transaction_bridge, - read_kernel_governance, read_kernel_security_governance, - read_maximum_allowed_ticks, read_or_set_maximum_gas_per_transaction, - read_sequencer_governance, sequencer, + max_blueprint_lookahead_in_seconds, read_admin, read_chain_family, + read_delayed_transaction_bridge, read_kernel_governance, + read_kernel_security_governance, read_maximum_allowed_ticks, + read_or_set_maximum_gas_per_transaction, read_sequencer_governance, sequencer, }, tick_model::constants::{MAXIMUM_GAS_LIMIT, MAX_ALLOWED_TICKS}, }; @@ -193,6 +193,22 @@ fn fetch_dal_configuration(host: &mut Host) -> Option( + host: &mut Host, + chain_id: U256, +) -> ChainConfig { + // if the info is not in durable storage, we must not fail, but treat it as EVM + let chain_family = read_chain_family(host, chain_id).unwrap_or_default(); + match chain_family { + ChainFamily::Michelson => ChainConfig::new_michelson_config(chain_id), + ChainFamily::Evm => { + let evm_limits = fetch_evm_limits(host); + let evm_configuration = fetch_evm_configuration(host); + ChainConfig::new_evm_config(chain_id, evm_limits, evm_configuration) + } + } +} + pub fn fetch_configuration( host: &mut Host, chain_id: U256, @@ -200,14 +216,11 @@ pub fn fetch_configuration( let tezos_contracts = fetch_tezos_contracts(host); let maximum_allowed_ticks = read_maximum_allowed_ticks(host).unwrap_or(MAX_ALLOWED_TICKS); - let evm_limits = fetch_evm_limits(host); let sequencer = sequencer(host).unwrap_or_default(); let enable_fa_bridge = is_enable_fa_bridge(host).unwrap_or_default(); - let evm_configuration = fetch_evm_configuration(host); let dal: Option = fetch_dal_configuration(host); let evm_node_flag = evm_node_flag(host).unwrap_or(false); - let chain_config = - ChainConfig::new_evm_config(chain_id, evm_limits, evm_configuration); + let chain_config = fetch_chain_configuration(host, chain_id); match sequencer { Some(sequencer) => { let delayed_bridge = read_delayed_transaction_bridge(host) diff --git a/etherlink/kernel_latest/kernel/src/storage.rs b/etherlink/kernel_latest/kernel/src/storage.rs index ca86c5517d2e..726c6f5f0062 100644 --- a/etherlink/kernel_latest/kernel/src/storage.rs +++ b/etherlink/kernel_latest/kernel/src/storage.rs @@ -884,7 +884,6 @@ pub fn max_blueprint_lookahead_in_seconds(host: &impl Runtime) -> anyhow::Result // Storage functions related to a chain configuration -#[allow(dead_code)] pub fn read_chain_family( host: &impl Runtime, chain_id: U256, -- GitLab