From 00c8dd246560b85803e34ea299edd4d160bd14d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Fri, 8 Nov 2024 10:31:21 +0100 Subject: [PATCH 1/6] EVM node: read gas price from current block --- etherlink/bin_node/lib_dev/durable_storage.ml | 17 +++++++++++++---- .../bin_node/lib_dev/durable_storage_path.ml | 2 -- .../bin_node/lib_dev/durable_storage_path.mli | 2 -- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/etherlink/bin_node/lib_dev/durable_storage.ml b/etherlink/bin_node/lib_dev/durable_storage.ml index fa4b13864e06..39f8b7c636b6 100644 --- a/etherlink/bin_node/lib_dev/durable_storage.ml +++ b/etherlink/bin_node/lib_dev/durable_storage.ml @@ -263,10 +263,19 @@ let chain_id read = inspect_durable_and_decode read Durable_storage_path.chain_id decode_number_le let base_fee_per_gas read = - inspect_durable_and_decode - read - Durable_storage_path.base_fee_per_gas - decode_number_le + let open Lwt_result_syntax in + let* block = + blocks_by_number + read + ~full_transaction_object:false + ~number:Durable_storage_path.Block.Current + in + match block.baseFeePerGas with + | Some base_fee_per_gas -> return base_fee_per_gas + | None -> + Error_monad.failwith + "Attempted to get the base fee per gas from a block which does not \ + have one." let kernel_version read = inspect_durable_and_decode diff --git a/etherlink/bin_node/lib_dev/durable_storage_path.ml b/etherlink/bin_node/lib_dev/durable_storage_path.ml index 6aef664287da..6f2841e65ba0 100644 --- a/etherlink/bin_node/lib_dev/durable_storage_path.ml +++ b/etherlink/bin_node/lib_dev/durable_storage_path.ml @@ -32,8 +32,6 @@ let chain_id = EVM.make "/chain_id" let minimum_base_fee_per_gas = World_state.make "/fees/minimum_base_fee_per_gas" -let base_fee_per_gas = World_state.make "/fees/base_fee_per_gas" - let da_fee_per_byte = World_state.make "/fees/da_fee_per_byte" let kernel_version = EVM.make "/kernel_version" diff --git a/etherlink/bin_node/lib_dev/durable_storage_path.mli b/etherlink/bin_node/lib_dev/durable_storage_path.mli index d490a39ad07b..5c929a1b2ab5 100644 --- a/etherlink/bin_node/lib_dev/durable_storage_path.mli +++ b/etherlink/bin_node/lib_dev/durable_storage_path.mli @@ -20,8 +20,6 @@ val chain_id : path val minimum_base_fee_per_gas : path -val base_fee_per_gas : path - val da_fee_per_byte : path val kernel_version : path -- GitLab From 8c29810b9481b7ce1acdb18a345d4a016e1c698e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 7 Nov 2024 10:08:28 +0100 Subject: [PATCH 2/6] Etherlink/Kernel: read base_fee_per_gas from current block --- etherlink/kernel_evm/kernel/src/gas_price.rs | 16 ++++++++ etherlink/kernel_evm/kernel/src/lib.rs | 41 +++++++++----------- etherlink/kernel_evm/kernel/src/storage.rs | 4 -- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/gas_price.rs b/etherlink/kernel_evm/kernel/src/gas_price.rs index 5abb330f3aa2..e2a4eea8da1a 100644 --- a/etherlink/kernel_evm/kernel/src/gas_price.rs +++ b/etherlink/kernel_evm/kernel/src/gas_price.rs @@ -153,8 +153,10 @@ fn f64_to_u64(f: F64) -> u64 { #[cfg(test)] mod test { use super::*; + use primitive_types::H160; use proptest::prelude::*; use std::collections::VecDeque; + use tezos_ethereum::block::BlockConstants; use tezos_evm_runtime::runtime::{MockKernelHost, Runtime}; proptest! { @@ -187,6 +189,14 @@ mod test { fn gas_price_responds_to_load() { let mut host = MockKernelHost::default(); let timestamp = 0_i64; + let block_fees = crate::retrieve_block_fees(&mut host).unwrap(); + let dummy_block_constants = BlockConstants::first_block( + timestamp.into(), + U256::zero(), + block_fees, + crate::block::GAS_LIMIT, + H160::zero(), + ); let mut bip = BlockInProgress::new_with_ticks( U256::zero(), @@ -200,6 +210,9 @@ mod test { bip.estimated_ticks_in_block = TOLERANCE; register_block(&mut host, &bip).unwrap(); + bip.clone() + .finalize_and_store(&mut host, &dummy_block_constants, vec![], vec![]) + .unwrap(); // At tolerance, gas price should be min. let (min, gas_price) = load_gas_price(&mut host); @@ -209,7 +222,10 @@ mod test { assert_eq!(gas_price, gas_price_now); // register more blocks - now double tolerance + bip.number = 1.into(); register_block(&mut host, &bip).unwrap(); + bip.finalize_and_store(&mut host, &dummy_block_constants, vec![], vec![]) + .unwrap(); let gas_price_now = base_fee_per_gas(&host, timestamp.into()); store_base_fee_per_gas(&mut host, gas_price_now).unwrap(); diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index f0c053c66fc2..c7109836f226 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -20,11 +20,11 @@ use migration::MigrationStatus; use primitive_types::U256; use reveal_storage::{is_revealed_storage, reveal_storage}; use storage::{ - read_base_fee_per_gas, read_chain_id, read_da_fee, read_kernel_version, - read_last_info_per_level_timestamp, read_last_info_per_level_timestamp_stats, - read_minimum_base_fee_per_gas, read_tracer_input, store_base_fee_per_gas, - store_chain_id, store_da_fee, store_kernel_version, store_minimum_base_fee_per_gas, - store_storage_version, STORAGE_VERSION, STORAGE_VERSION_PATH, + read_chain_id, read_da_fee, read_kernel_version, read_last_info_per_level_timestamp, + read_last_info_per_level_timestamp_stats, read_minimum_base_fee_per_gas, + read_tracer_input, store_chain_id, store_da_fee, store_kernel_version, + store_minimum_base_fee_per_gas, store_storage_version, STORAGE_VERSION, + STORAGE_VERSION_PATH, }; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_ethereum::block::BlockFees; @@ -192,15 +192,17 @@ fn retrieve_minimum_base_fee_per_gas( fn retrieve_base_fee_per_gas( host: &mut Host, minimum_base_fee_per_gas: U256, -) -> Result { - match read_base_fee_per_gas(host) { - Ok(base_fee_per_gas) if base_fee_per_gas > minimum_base_fee_per_gas => { - Ok(base_fee_per_gas) - } - _ => { - store_base_fee_per_gas(host, minimum_base_fee_per_gas)?; - Ok(minimum_base_fee_per_gas) +) -> U256 { + match block_storage::read_current(host) { + Ok(current_block) => { + let current_base_fee_per_gas = current_block.base_fee_per_gas; + if current_base_fee_per_gas < minimum_base_fee_per_gas { + minimum_base_fee_per_gas + } else { + current_base_fee_per_gas + } } + Err(_) => minimum_base_fee_per_gas, } } @@ -217,7 +219,7 @@ fn retrieve_da_fee(host: &mut Host) -> Result { fn retrieve_block_fees(host: &mut Host) -> Result { let minimum_base_fee_per_gas = retrieve_minimum_base_fee_per_gas(host)?; - let base_fee_per_gas = retrieve_base_fee_per_gas(host, minimum_base_fee_per_gas)?; + let base_fee_per_gas = retrieve_base_fee_per_gas(host, minimum_base_fee_per_gas); let da_fee = retrieve_da_fee(host)?; let block_fees = BlockFees::new(minimum_base_fee_per_gas, base_fee_per_gas, da_fee); @@ -397,7 +399,6 @@ mod tests { use crate::{ blueprint::Blueprint, inbox::{Transaction, TransactionContent}, - storage, upgrade::KernelUpgrade, }; use evm_execution::account_storage::{self, EthereumAccountStorage}; @@ -670,7 +671,7 @@ mod tests { } #[test] - fn load_block_fees_with_minimum() { + fn load_min_block_fees() { let min_path = RefPath::assert_from(b"/evm/world_state/fees/minimum_base_fee_per_gas"); @@ -678,23 +679,17 @@ mod tests { let mut host = MockKernelHost::default(); let min_base_fee = U256::from(17); - let curr_base_fee = U256::from(20); - storage::store_base_fee_per_gas(&mut host, curr_base_fee).unwrap(); tezos_storage::write_u256_le(&mut host, &min_path, min_base_fee).unwrap(); // Act let result = crate::retrieve_block_fees(&mut host); - let base_fee = storage::read_base_fee_per_gas(&mut host); // Assert let expected = - BlockFees::new(min_base_fee, curr_base_fee, fees::DA_FEE_PER_BYTE.into()); + BlockFees::new(min_base_fee, min_base_fee, fees::DA_FEE_PER_BYTE.into()); assert!(result.is_ok()); assert_eq!(expected, result.unwrap()); - - assert!(base_fee.is_ok()); - assert_eq!(curr_base_fee, base_fee.unwrap()); } #[test] diff --git a/etherlink/kernel_evm/kernel/src/storage.rs b/etherlink/kernel_evm/kernel/src/storage.rs index e4e40e1d2a98..40ba495b1a06 100644 --- a/etherlink/kernel_evm/kernel/src/storage.rs +++ b/etherlink/kernel_evm/kernel/src/storage.rs @@ -454,10 +454,6 @@ pub fn store_base_fee_per_gas( write_u256_le(host, &EVM_BASE_FEE_PER_GAS, base_fee_per_gas).map_err(Error::from) } -pub fn read_base_fee_per_gas(host: &mut Host) -> Result { - read_u256_le(host, &EVM_BASE_FEE_PER_GAS).map_err(Error::from) -} - pub fn read_minimum_base_fee_per_gas(host: &Host) -> Result { read_u256_le(host, &EVM_MINIMUM_BASE_FEE_PER_GAS).map_err(Error::from) } -- GitLab From e2dd493beedf69f776b1403369f9a98c10b81b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 7 Nov 2024 10:12:40 +0100 Subject: [PATCH 3/6] Etherlink/Kernel: don't store base_fee_per_gas with fees constants --- etherlink/kernel_evm/kernel/src/block.rs | 1 - etherlink/kernel_evm/kernel/src/gas_price.rs | 5 +---- etherlink/kernel_evm/kernel/src/lib.rs | 2 -- etherlink/kernel_evm/kernel/src/storage.rs | 9 --------- 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index c8f9bac893cc..900a0f9359fb 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -827,7 +827,6 @@ mod tests { host, block_fees.minimum_base_fee_per_gas(), )?; - storage::store_base_fee_per_gas(host, block_fees.base_fee_per_gas())?; storage::store_da_fee(host, block_fees.da_fee_per_byte())?; Ok(()) } diff --git a/etherlink/kernel_evm/kernel/src/gas_price.rs b/etherlink/kernel_evm/kernel/src/gas_price.rs index e2a4eea8da1a..4e9942989f7e 100644 --- a/etherlink/kernel_evm/kernel/src/gas_price.rs +++ b/etherlink/kernel_evm/kernel/src/gas_price.rs @@ -5,7 +5,7 @@ //! Adjustments of the gas price (a.k.a `base_fee_per_gas`), in response to load. use crate::block_in_progress::BlockInProgress; -use crate::storage::{read_minimum_base_fee_per_gas, store_base_fee_per_gas}; +use crate::storage::read_minimum_base_fee_per_gas; use primitive_types::U256; use softfloat::F64; @@ -32,8 +32,6 @@ pub fn register_block( } update_tick_backlog(host, bip.estimated_ticks_in_block, bip.timestamp)?; - let base_fee_per_gas = base_fee_per_gas(host, bip.timestamp); - store_base_fee_per_gas(host, base_fee_per_gas)?; Ok(()) } @@ -227,7 +225,6 @@ mod test { bip.finalize_and_store(&mut host, &dummy_block_constants, vec![], vec![]) .unwrap(); let gas_price_now = base_fee_per_gas(&host, timestamp.into()); - store_base_fee_per_gas(&mut host, gas_price_now).unwrap(); let (min, gas_price) = load_gas_price(&mut host); assert!(gas_price > min); diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index c7109836f226..ad0712ec0f4b 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -622,8 +622,6 @@ mod tests { block_fees.minimum_base_fee_per_gas(), ) .unwrap(); - crate::storage::store_base_fee_per_gas(&mut host, block_fees.base_fee_per_gas()) - .unwrap(); crate::storage::store_da_fee(&mut host, block_fees.da_fee_per_byte()).unwrap(); // If the upgrade is started, it should raise an error diff --git a/etherlink/kernel_evm/kernel/src/storage.rs b/etherlink/kernel_evm/kernel/src/storage.rs index 40ba495b1a06..534615289434 100644 --- a/etherlink/kernel_evm/kernel/src/storage.rs +++ b/etherlink/kernel_evm/kernel/src/storage.rs @@ -106,8 +106,6 @@ pub const EVM_TRANSACTIONS_OBJECTS: RefPath = const EVM_CHAIN_ID: RefPath = RefPath::assert_from(b"/evm/chain_id"); -pub const EVM_BASE_FEE_PER_GAS: RefPath = - RefPath::assert_from(b"/evm/world_state/fees/base_fee_per_gas"); 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 = @@ -447,13 +445,6 @@ pub fn read_chain_id(host: &Host) -> Result { read_u256_le(host, &EVM_CHAIN_ID).map_err(Error::from) } -pub fn store_base_fee_per_gas( - host: &mut Host, - base_fee_per_gas: U256, -) -> Result<(), Error> { - write_u256_le(host, &EVM_BASE_FEE_PER_GAS, base_fee_per_gas).map_err(Error::from) -} - pub fn read_minimum_base_fee_per_gas(host: &Host) -> Result { read_u256_le(host, &EVM_MINIMUM_BASE_FEE_PER_GAS).map_err(Error::from) } -- GitLab From dd6a01ef02e9163c94ef39c37548c37ee2766852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Tue, 12 Nov 2024 19:25:23 +0100 Subject: [PATCH 4/6] Etherlink/Kernel: don't read minimum_base_fee_per_gas in gas_price.rs --- etherlink/kernel_evm/kernel/src/block.rs | 8 +++++++- .../kernel_evm/kernel/src/block_in_progress.rs | 6 +++++- etherlink/kernel_evm/kernel/src/gas_price.rs | 18 +++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/block.rs b/etherlink/kernel_evm/kernel/src/block.rs index 900a0f9359fb..69f0f459df99 100644 --- a/etherlink/kernel_evm/kernel/src/block.rs +++ b/etherlink/kernel_evm/kernel/src/block.rs @@ -237,6 +237,7 @@ fn next_bip_from_blueprints( tick_counter: &TickCounter, config: &mut Configuration, kernel_upgrade: &Option, + minimum_base_fee_per_gas: U256, ) -> Result { let (blueprint, size) = read_next_blueprint(host, config)?; log!(host, Benchmarking, "Size of blueprint: {}", size); @@ -250,7 +251,11 @@ fn next_bip_from_blueprints( return Ok(BlueprintParsing::None); } } - let gas_price = crate::gas_price::base_fee_per_gas(host, blueprint.timestamp); + let gas_price = crate::gas_price::base_fee_per_gas( + host, + blueprint.timestamp, + minimum_base_fee_per_gas, + ); let bip = block_in_progress::BlockInProgress::from_blueprint( blueprint, @@ -530,6 +535,7 @@ pub fn produce( &tick_counter, config, &kernel_upgrade, + minimum_base_fee_per_gas, )? { BlueprintParsing::Next(bip) => bip, BlueprintParsing::None => { diff --git a/etherlink/kernel_evm/kernel/src/block_in_progress.rs b/etherlink/kernel_evm/kernel/src/block_in_progress.rs index 81d3da890f6c..00452ee4dae2 100644 --- a/etherlink/kernel_evm/kernel/src/block_in_progress.rs +++ b/etherlink/kernel_evm/kernel/src/block_in_progress.rs @@ -420,7 +420,11 @@ impl BlockInProgress { let receipts_root = self.receipts_root(host, previous_receipts_root)?; let transactions_root = self.transactions_root(host, previous_transactions_root)?; - let base_fee_per_gas = base_fee_per_gas(host, self.timestamp); + let base_fee_per_gas = base_fee_per_gas( + host, + self.timestamp, + block_constants.block_fees.minimum_base_fee_per_gas(), + ); let new_block = L2Block::new( self.number, self.valid_txs, diff --git a/etherlink/kernel_evm/kernel/src/gas_price.rs b/etherlink/kernel_evm/kernel/src/gas_price.rs index 4e9942989f7e..8d79fec4f759 100644 --- a/etherlink/kernel_evm/kernel/src/gas_price.rs +++ b/etherlink/kernel_evm/kernel/src/gas_price.rs @@ -5,7 +5,6 @@ //! Adjustments of the gas price (a.k.a `base_fee_per_gas`), in response to load. use crate::block_in_progress::BlockInProgress; -use crate::storage::read_minimum_base_fee_per_gas; use primitive_types::U256; use softfloat::F64; @@ -37,18 +36,19 @@ pub fn register_block( } /// Retrieve *base fee per gas*, according to the current timestamp. -pub fn base_fee_per_gas(host: &impl Runtime, timestamp: Timestamp) -> U256 { +pub fn base_fee_per_gas( + host: &impl Runtime, + timestamp: Timestamp, + minimum_gas_price: U256, +) -> U256 { let timestamp = timestamp.as_u64(); + let minimum_gas_price = minimum_gas_price.as_u64(); let last_timestamp = crate::storage::read_tick_backlog_timestamp(host).unwrap_or(timestamp); let backlog = backlog_with_time_elapsed(host, 0, timestamp, last_timestamp); - let minimum_gas_price = read_minimum_base_fee_per_gas(host) - .map(|p| p.as_u64()) - .unwrap_or(crate::fees::MINIMUM_BASE_FEE_PER_GAS); - price_from_tick_backlog(backlog, minimum_gas_price).into() } @@ -216,7 +216,7 @@ mod test { let (min, gas_price) = load_gas_price(&mut host); assert_eq!(min, crate::fees::MINIMUM_BASE_FEE_PER_GAS.into()); assert_eq!(gas_price, crate::fees::MINIMUM_BASE_FEE_PER_GAS.into()); - let gas_price_now = base_fee_per_gas(&host, timestamp.into()); + let gas_price_now = base_fee_per_gas(&host, timestamp.into(), min); assert_eq!(gas_price, gas_price_now); // register more blocks - now double tolerance @@ -224,14 +224,14 @@ mod test { register_block(&mut host, &bip).unwrap(); bip.finalize_and_store(&mut host, &dummy_block_constants, vec![], vec![]) .unwrap(); - let gas_price_now = base_fee_per_gas(&host, timestamp.into()); + let gas_price_now = base_fee_per_gas(&host, timestamp.into(), min); let (min, gas_price) = load_gas_price(&mut host); assert!(gas_price > min); assert_eq!(gas_price, gas_price_now); // after 10 seconds, reduces back to tolerance - let gas_price_after_10 = base_fee_per_gas(&host, (timestamp + 10).into()); + let gas_price_after_10 = base_fee_per_gas(&host, (timestamp + 10).into(), min); assert_eq!( gas_price_after_10, crate::fees::MINIMUM_BASE_FEE_PER_GAS.into() -- GitLab From 461553c616863b2b68da952c7cfbea2a15e5c99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Mon, 6 Jan 2025 15:51:25 +0100 Subject: [PATCH 5/6] Etherlink/Kernel/Simulation: save a read of current block This is a small optimization of simulation; instead of reading the current block twice (once to get the base fee + once to get the block number and timestamp) we read the current block only once and read the three pieces of information at once. --- etherlink/kernel_evm/kernel/src/lib.rs | 13 ++++++--- etherlink/kernel_evm/kernel/src/simulation.rs | 27 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index ad0712ec0f4b..aab122a48a25 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -27,7 +27,6 @@ use storage::{ STORAGE_VERSION_PATH, }; use tezos_crypto_rs::hash::ContractKt1Hash; -use tezos_ethereum::block::BlockFees; use tezos_evm_logging::{log, Level::*, Verbosity}; use tezos_evm_runtime::runtime::{KernelHost, Runtime}; use tezos_evm_runtime::safe_storage::WORLD_STATE_PATH; @@ -189,6 +188,7 @@ fn retrieve_minimum_base_fee_per_gas( } } +#[cfg(test)] fn retrieve_base_fee_per_gas( host: &mut Host, minimum_base_fee_per_gas: U256, @@ -217,11 +217,18 @@ fn retrieve_da_fee(host: &mut Host) -> Result { } } -fn retrieve_block_fees(host: &mut Host) -> Result { +#[cfg(test)] +fn retrieve_block_fees( + host: &mut Host, +) -> Result { let minimum_base_fee_per_gas = retrieve_minimum_base_fee_per_gas(host)?; let base_fee_per_gas = retrieve_base_fee_per_gas(host, minimum_base_fee_per_gas); let da_fee = retrieve_da_fee(host)?; - let block_fees = BlockFees::new(minimum_base_fee_per_gas, base_fee_per_gas, da_fee); + let block_fees = tezos_ethereum::block::BlockFees::new( + minimum_base_fee_per_gas, + base_fee_per_gas, + da_fee, + ); Ok(block_fees) } diff --git a/etherlink/kernel_evm/kernel/src/simulation.rs b/etherlink/kernel_evm/kernel/src/simulation.rs index e2bca3538086..df26acdeca7c 100644 --- a/etherlink/kernel_evm/kernel/src/simulation.rs +++ b/etherlink/kernel_evm/kernel/src/simulation.rs @@ -16,8 +16,7 @@ use crate::tick_model::constants::MAXIMUM_GAS_LIMIT; use crate::{error::Error, error::StorageError, storage}; use crate::{ - current_timestamp, parsable, parsing, retrieve_block_fees, retrieve_chain_id, - tick_model, CONFIG, + current_timestamp, parsable, parsing, retrieve_chain_id, tick_model, CONFIG, }; use evm_execution::account_storage::account_path; @@ -30,7 +29,7 @@ use evm_execution::{ use evm_execution::{run_transaction, EthereumError}; use primitive_types::{H160, U256}; use rlp::{Decodable, DecoderError, Encodable, Rlp}; -use tezos_ethereum::block::BlockConstants; +use tezos_ethereum::block::{BlockConstants, BlockFees}; use tezos_ethereum::rlp_helpers::{ append_option_u64_le, check_list, decode_field, decode_option, decode_option_u64_le, decode_timestamp, next, VersionedEncoding, @@ -372,7 +371,8 @@ impl Evaluation { enable_fa_withdrawals: bool, ) -> Result, Error> { let chain_id = retrieve_chain_id(host)?; - let block_fees = retrieve_block_fees(host)?; + let minimum_base_fee_per_gas = crate::retrieve_minimum_base_fee_per_gas(host)?; + let da_fee = crate::retrieve_da_fee(host)?; let coinbase = read_sequencer_pool_address(host).unwrap_or_default(); let mut evm_account_storage = account_storage::init_account_storage() .map_err(|_| Error::Storage(StorageError::AccountInitialisation))?; @@ -403,6 +403,11 @@ impl Evaluation { .map(|timestamp| U256::from(timestamp.as_u64())) .unwrap_or_else(|| U256::from(block.timestamp.as_u64())); + let block_fees = BlockFees::new( + minimum_base_fee_per_gas, + block.base_fee_per_gas, + da_fee, + ); BlockConstants { number: block.number + 1, coinbase, @@ -422,6 +427,9 @@ impl Evaluation { .map(|timestamp| U256::from(timestamp.as_u64())) .unwrap_or_else(|| U256::from(current_timestamp(host).as_u64())); + let base_fee_per_gas = minimum_base_fee_per_gas; + let block_fees = + BlockFees::new(minimum_base_fee_per_gas, base_fee_per_gas, da_fee); BlockConstants::first_block( timestamp, chain_id, @@ -445,7 +453,7 @@ impl Evaluation { let gas_price = if let Some(gas_price) = self.gas_price { U256::from(gas_price) } else { - block_fees.base_fee_per_gas() + constants.block_fees.base_fee_per_gas() }; match run_transaction( @@ -475,9 +483,12 @@ impl Evaluation { Ok(result) } Ok(Some(outcome)) => { - let outcome = - simulation_add_gas_for_fees(outcome, &block_fees, &self.data) - .map_err(Error::Simulation)?; + let outcome = simulation_add_gas_for_fees( + outcome, + &constants.block_fees, + &self.data, + ) + .map_err(Error::Simulation)?; let result: SimulationResult = Result::Ok(Some(outcome)).into(); -- GitLab From c080d9ede1b9699dc2e9b1fee3e9c3cd1e0c8e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Mon, 6 Jan 2025 15:58:27 +0100 Subject: [PATCH 6/6] Etherlink/Kernel/Changes: mention !15609 --- etherlink/CHANGES_KERNEL.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etherlink/CHANGES_KERNEL.md b/etherlink/CHANGES_KERNEL.md index 0570ad4c703d..f2920361b3df 100644 --- a/etherlink/CHANGES_KERNEL.md +++ b/etherlink/CHANGES_KERNEL.md @@ -22,6 +22,9 @@ - Transaction validation support in simulation is dropped, the validation must be done outside of the kernel. (!15958) - Parsing a DAL slot is now resumed after invalid inputs. (!15926) +- Current block's gas price is not stored on its own anymore but the + information is still available as part of the current + block. (!15609) ### Bug fixes -- GitLab