From b3ba1a7b5998dd78d7bae1e05915b2087d983bba Mon Sep 17 00:00:00 2001 From: brentstone Date: Thu, 6 Jun 2024 13:15:04 +0200 Subject: [PATCH 01/10] add gas scale to protocol params --- crates/apps_lib/src/config/genesis.rs | 2 ++ crates/apps_lib/src/config/genesis/chain.rs | 2 ++ crates/apps_lib/src/config/genesis/templates.rs | 4 ++++ crates/core/src/parameters.rs | 2 ++ crates/node/src/storage/mod.rs | 1 + crates/parameters/src/lib.rs | 14 ++++++++++++++ crates/parameters/src/storage.rs | 6 ++++++ crates/proof_of_stake/src/lib.rs | 1 + crates/state/src/lib.rs | 1 + genesis/localnet/parameters.toml | 2 ++ genesis/starter/parameters.toml | 2 ++ 11 files changed, 37 insertions(+) diff --git a/crates/apps_lib/src/config/genesis.rs b/crates/apps_lib/src/config/genesis.rs index d6e5d97046..f3445ff496 100644 --- a/crates/apps_lib/src/config/genesis.rs +++ b/crates/apps_lib/src/config/genesis.rs @@ -315,6 +315,8 @@ pub struct Parameters { pub max_signatures_per_transaction: u8, /// Fee unshielding gas limit pub fee_unshielding_gas_limit: u64, + /// Gas scale + pub gas_scale: u64, /// Map of the cost per gas unit for every token allowed for fee payment pub minimum_gas_price: BTreeMap, } diff --git a/crates/apps_lib/src/config/genesis/chain.rs b/crates/apps_lib/src/config/genesis/chain.rs index 690d67909f..eb01309a1d 100644 --- a/crates/apps_lib/src/config/genesis/chain.rs +++ b/crates/apps_lib/src/config/genesis/chain.rs @@ -305,6 +305,7 @@ impl Finalized { masp_epoch_multiplier, max_signatures_per_transaction, fee_unshielding_gas_limit, + gas_scale, max_block_gas, minimum_gas_price, max_tx_bytes, @@ -351,6 +352,7 @@ impl Finalized { max_proposal_bytes, max_signatures_per_transaction, fee_unshielding_gas_limit, + gas_scale, max_block_gas, minimum_gas_price: minimum_gas_price .iter() diff --git a/crates/apps_lib/src/config/genesis/templates.rs b/crates/apps_lib/src/config/genesis/templates.rs index db5ac13772..c9c0d5133b 100644 --- a/crates/apps_lib/src/config/genesis/templates.rs +++ b/crates/apps_lib/src/config/genesis/templates.rs @@ -301,6 +301,8 @@ pub struct ChainParams { pub max_block_gas: u64, /// Fee unshielding gas limit pub fee_unshielding_gas_limit: u64, + /// Gas scale + pub gas_scale: u64, /// Map of the cost per gas unit for every token allowed for fee payment pub minimum_gas_price: T::GasMinimums, } @@ -325,6 +327,7 @@ impl ChainParams { max_signatures_per_transaction, max_block_gas, fee_unshielding_gas_limit, + gas_scale, minimum_gas_price, } = self; let mut min_gas_prices = BTreeMap::default(); @@ -371,6 +374,7 @@ impl ChainParams { max_signatures_per_transaction, max_block_gas, fee_unshielding_gas_limit, + gas_scale, minimum_gas_price: min_gas_prices, }) } diff --git a/crates/core/src/parameters.rs b/crates/core/src/parameters.rs index aaf2c294f8..d7bd2b26a4 100644 --- a/crates/core/src/parameters.rs +++ b/crates/core/src/parameters.rs @@ -53,6 +53,8 @@ pub struct Parameters { pub max_signatures_per_transaction: u8, /// Fee unshielding gas limit pub fee_unshielding_gas_limit: u64, + /// Gas scale + pub gas_scale: u64, /// Map of the cost per gas unit for every token allowed for fee payment pub minimum_gas_price: BTreeMap, /// Enable the native token transfer if it is true diff --git a/crates/node/src/storage/mod.rs b/crates/node/src/storage/mod.rs index 49d37c81a8..96bc5e716b 100644 --- a/crates/node/src/storage/mod.rs +++ b/crates/node/src/storage/mod.rs @@ -176,6 +176,7 @@ mod tests { masp_epoch_multiplier: 2, max_signatures_per_transaction: 10, fee_unshielding_gas_limit: 0, + gas_scale: 100_000_000, minimum_gas_price: Default::default(), is_native_token_transferable: true, }; diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index b8dbe12a88..4f394ea968 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -78,6 +78,7 @@ where max_signatures_per_transaction, minimum_gas_price, fee_unshielding_gas_limit, + gas_scale, is_native_token_transferable, } = parameters; @@ -102,6 +103,10 @@ where storage::get_fee_unshielding_gas_limit_key(); storage.write(&fee_unshielding_gas_limit_key, fee_unshielding_gas_limit)?; + // write the gas scale + let gas_scale_key = storage::get_gas_scale_key(); + storage.write(&gas_scale_key, gas_scale)?; + // write vp allowlist parameter let vp_allowlist_key = storage::get_vp_allowlist_storage_key(); let vp_allowlist = vp_allowlist @@ -379,6 +384,13 @@ where .ok_or(ReadError::ParametersMissing) .into_storage_result()?; + // read gas scale + let gas_scale_key = storage::get_gas_scale_key(); + let value = storage.read(&gas_scale_key)?; + let gas_scale: u64 = value + .ok_or(ReadError::ParametersMissing) + .into_storage_result()?; + // read epochs per year let epochs_per_year_key = storage::get_epochs_per_year_key(); let value = storage.read(&epochs_per_year_key)?; @@ -433,6 +445,7 @@ where max_signatures_per_transaction, minimum_gas_price, fee_unshielding_gas_limit, + gas_scale, is_native_token_transferable, }) } @@ -478,6 +491,7 @@ where masp_epoch_multiplier: 2, max_signatures_per_transaction: 10, fee_unshielding_gas_limit: 0, + gas_scale: 100_000_000, minimum_gas_price: Default::default(), is_native_token_transferable: true, }; diff --git a/crates/parameters/src/storage.rs b/crates/parameters/src/storage.rs index 27204f9568..e280064962 100644 --- a/crates/parameters/src/storage.rs +++ b/crates/parameters/src/storage.rs @@ -39,6 +39,7 @@ struct Keys { max_block_gas: &'static str, minimum_gas_price: &'static str, fee_unshielding_gas_limit: &'static str, + gas_scale: &'static str, max_signatures_per_transaction: &'static str, native_token_transferable: &'static str, } @@ -121,6 +122,11 @@ pub fn get_fee_unshielding_gas_limit_key() -> Key { get_fee_unshielding_gas_limit_key_at_addr(ADDRESS) } +/// Storage key used for the gas scale +pub fn get_gas_scale_key() -> Key { + get_gas_scale_key_at_addr(ADDRESS) +} + /// Storage key used for max_epected_time_per_block parameter. pub fn get_max_expected_time_per_block_key() -> Key { get_max_expected_time_per_block_key_at_addr(ADDRESS) diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 19b003541f..1326bcd7ab 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -2727,6 +2727,7 @@ pub mod test_utils { masp_epoch_multiplier: 2, max_signatures_per_transaction: 15, fee_unshielding_gas_limit: 10000, + gas_scale: 100_000_000, minimum_gas_price: BTreeMap::new(), is_native_token_transferable: true, }; diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index f62ab1c862..38695ce723 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -761,6 +761,7 @@ mod tests { masp_epoch_multiplier: 2, max_signatures_per_transaction: 15, fee_unshielding_gas_limit: 20_000, + gas_scale: 100_000_000, minimum_gas_price: BTreeMap::default(), is_native_token_transferable: true, }; diff --git a/genesis/localnet/parameters.toml b/genesis/localnet/parameters.toml index bef2c1ae2d..b2c8a1b9d7 100644 --- a/genesis/localnet/parameters.toml +++ b/genesis/localnet/parameters.toml @@ -26,6 +26,8 @@ max_signatures_per_transaction = 15 max_block_gas = 20000000 # Fee unshielding gas limit fee_unshielding_gas_limit = 20000 +# Gas scale +gas_scale = 100_000_000 # Map of the cost per gas unit for every token allowed for fee payment [parameters.minimum_gas_price] diff --git a/genesis/starter/parameters.toml b/genesis/starter/parameters.toml index dfb01522d6..2fc30e455b 100644 --- a/genesis/starter/parameters.toml +++ b/genesis/starter/parameters.toml @@ -26,6 +26,8 @@ max_signatures_per_transaction = 15 max_block_gas = 20000000 # Fee unshielding gas limit fee_unshielding_gas_limit = 20000 +# Gas scale +gas_scale = 100_000_000 # Map of the cost per gas unit for every token allowed for fee payment [parameters.minimum_gas_price] From aa7778ff5d414ae6559e537e24955e09071ffce8 Mon Sep 17 00:00:00 2001 From: brentstone Date: Fri, 7 Jun 2024 14:24:32 +0200 Subject: [PATCH 02/10] remove hard-coded gas scale --- crates/gas/src/event.rs | 14 +++++ crates/gas/src/lib.rs | 20 ++++--- crates/namada/src/ledger/mod.rs | 15 ++++-- crates/namada/src/ledger/protocol/mod.rs | 6 +++ crates/node/src/bench_utils.rs | 1 + crates/node/src/shell/finalize_block.rs | 64 ++++++++++++++++------- crates/node/src/shell/mod.rs | 9 +++- crates/node/src/shell/prepare_proposal.rs | 7 ++- crates/node/src/shell/process_proposal.rs | 12 ++++- crates/parameters/src/lib.rs | 2 +- crates/parameters/src/storage.rs | 12 +++++ crates/sdk/src/rpc.rs | 13 ++++- crates/tx/src/data/mod.rs | 10 +++- crates/tx/src/data/wrapper.rs | 26 ++++++--- 14 files changed, 161 insertions(+), 50 deletions(-) diff --git a/crates/gas/src/event.rs b/crates/gas/src/event.rs index d76889fece..066b98c30c 100644 --- a/crates/gas/src/event.rs +++ b/crates/gas/src/event.rs @@ -17,3 +17,17 @@ impl EventAttributeEntry<'static> for GasUsed { self.0 } } + +/// Extend a [`namada_events::Event`] with the gas scale data. +pub struct GasScale(pub u64); + +impl EventAttributeEntry<'static> for GasScale { + type Value = u64; + type ValueOwned = Self::Value; + + const KEY: &'static str = "gas_scale"; + + fn into_value(self) -> Self::Value { + self.0 + } +} diff --git a/crates/gas/src/lib.rs b/crates/gas/src/lib.rs index 89e24209ff..1f17202c77 100644 --- a/crates/gas/src/lib.rs +++ b/crates/gas/src/lib.rs @@ -113,9 +113,6 @@ pub const MASP_PARALLEL_GAS_DIVIDER: u64 = PARALLEL_GAS_DIVIDER / 2; /// Gas module result for functions that may fail pub type Result = std::result::Result; -/// Decimal scale of Gas units -const SCALE: u64 = 100_000_000; - /// Representation of gas in sub-units. This effectively decouples gas metering /// from fee payment, allowing higher resolution when accounting for gas while, /// at the same time, providing a contained gas value when paying fees. @@ -155,9 +152,10 @@ impl Gas { /// Converts the sub gas units to whole ones. If the sub units are not a /// multiple of the `SCALE` than ceil the quotient - fn get_whole_gas_units(&self) -> u64 { - let quotient = self.sub / SCALE; - if self.sub % SCALE == 0 { + #[allow(clippy::arithmetic_side_effects)] + pub fn get_whole_gas_units(&self, scale: u64) -> u64 { + let quotient = self.sub / scale; + if self.sub % scale == 0 { quotient } else { quotient @@ -167,8 +165,8 @@ impl Gas { } /// Generates a `Gas` instance from a whole amount - pub fn from_whole_units(whole: u64) -> Option { - let sub = whole.checked_mul(SCALE)?; + pub fn from_whole_units(whole: u64, scale: u64) -> Option { + let sub = whole.checked_mul(scale)?; Some(Self { sub }) } } @@ -188,7 +186,7 @@ impl From for u64 { impl Display for Gas { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // Display the gas in whole amounts - write!(f, "{}", self.get_whole_gas_units()) + write!(f, "{}", self.sub) } } @@ -197,8 +195,8 @@ impl FromStr for Gas { fn from_str(s: &str) -> std::result::Result { let raw: u64 = s.parse().map_err(GasParseError::Parse)?; - let gas = Gas::from_whole_units(raw).ok_or(GasParseError::Overflow)?; - Ok(gas) + // let gas = Gas::from_whole_units(raw).ok_or(GasParseError::Overflow)?; + Ok(Self { sub: raw }) } } diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 2f952e4f99..2ea021bb69 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -23,7 +23,6 @@ pub use { mod dry_run_tx { use std::cell::RefCell; - use namada_gas::Gas; use namada_sdk::queries::{EncodedResponseQuery, RequestCtx, RequestQuery}; use namada_state::{DBIter, ResultExt, StorageHasher, DB}; use namada_tx::data::{GasLimit, TxResult}; @@ -57,8 +56,11 @@ mod dry_run_tx { // Wrapper dry run to allow estimating the gas cost of a transaction let (mut tx_result, tx_gas_meter) = match tx.header().tx_type { TxType::Wrapper(wrapper) => { - let gas_limit = - Gas::try_from(wrapper.gas_limit).into_storage_result()?; + let gas_scale = namada_parameters::get_gas_scale(ctx.state)?; + let gas_limit = wrapper + .gas_limit + .as_scaled_gas(gas_scale) + .into_storage_result()?; let tx_gas_meter = RefCell::new(TxGasMeter::new(gas_limit)); let tx_result = protocol::apply_wrapper_tx( &tx, @@ -77,10 +79,15 @@ mod dry_run_tx { _ => { // If dry run only the inner tx, use the max block gas as // the gas limit + let gas_scale = namada_parameters::get_gas_scale(ctx.state)?; + let max_block_gas = namada_parameters::get_max_block_gas(ctx.state)?; - let gas_limit = Gas::try_from(GasLimit::from(max_block_gas)) + let gas_limit = GasLimit::from(max_block_gas) + .as_scaled_gas(gas_scale) .into_storage_result()?; + // let gas_limit = Gas::try_from(GasLimit::from(max_block_gas)) + // .into_storage_result()?; (TxResult::default(), TxGasMeter::new(gas_limit)) } }; diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index b19098e18d..2c18194cb1 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -261,8 +261,11 @@ where tx_wasm_cache, }, )?; + let gas_scale = + namada_parameters::get_gas_scale(state).unwrap(); Ok(TxResult { gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), + gas_scale, batch_results: BatchResults( [(cmt.get_hash(), Ok(batched_tx_result))] .into_iter() @@ -430,8 +433,11 @@ where .add_wrapper_gas(tx_bytes) .map_err(|err| Error::GasError(err.to_string()))?; + let gas_scale = namada_parameters::get_gas_scale(state).unwrap(); + Ok(TxResult { gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), + gas_scale, batch_results: BatchResults::default(), }) } diff --git a/crates/node/src/bench_utils.rs b/crates/node/src/bench_utils.rs index ef80036715..3cb6ac531c 100644 --- a/crates/node/src/bench_utils.rs +++ b/crates/node/src/bench_utils.rs @@ -913,6 +913,7 @@ impl Client for BenchShell { .map(|(idx, (tx, changed_keys))| { let tx_result = TxResult:: { gas_used: 0.into(), + gas_scale: 0_u64, // TODO: is this correct? batch_results: BatchResults( [( tx.first_commitments().unwrap().get_hash(), diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 7adbcd17ba..4a0aa27fe5 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -29,6 +29,7 @@ use namada::tx::event::{Batch, Code}; use namada::tx::new_tx_event; use namada::vote_ext::ethereum_events::MultiSignedEthEvent; use namada::vote_ext::ethereum_tx_data_variants; +use parameters::get_gas_scale; use super::*; use crate::facade::tendermint::abci::types::VoteInfo; @@ -385,9 +386,16 @@ where .unwrap_or(""), msg, ); + let gas_scale = get_gas_scale(&self.state).unwrap(); + let scaled_gas = Gas::from( + tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale), + ); tx_logs .tx_event - .extend(GasUsed(tx_data.tx_gas_meter.get_tx_consumed_gas())) + .extend(GasUsed(scaled_gas)) .extend(Info(msg.to_string())) .extend(Code(ResultCode::InvalidTx)); // Make sure to clean the write logs for the next transaction @@ -410,9 +418,17 @@ where msg ); + let gas_scale = get_gas_scale(&self.state).unwrap(); + let scaled_gas = Gas::from( + tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale), + ); + tx_logs .tx_event - .extend(GasUsed(tx_data.tx_gas_meter.get_tx_consumed_gas())) + .extend(GasUsed(scaled_gas)) .extend(Info(msg.to_string())) .extend(Code(ResultCode::WasmRuntimeError)); @@ -487,9 +503,17 @@ where self.commit_batch_hash(tx_data.replay_protection_hashes); } + let gas_scale = get_gas_scale(&self.state).unwrap(); + let scaled_gas = Gas::from( + tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale), + ); + tx_logs .tx_event - .extend(GasUsed(extended_tx_result.tx_result.gas_used)) + .extend(GasUsed(scaled_gas)) .extend(Info("Check batch for result.".to_string())) .extend(Batch(&extended_tx_result.tx_result.to_result_string())); } @@ -669,22 +693,24 @@ where TxType::Wrapper(wrapper) => { stats.increment_wrapper_txs(); - let gas_limit = match Gas::try_from(wrapper.gas_limit) { - Ok(value) => value, - Err(_) => { - response.events.emit( - new_tx_event(&tx, height.0) - .with(Code(ResultCode::InvalidTx)) - .with(Info( - "The wrapper gas limit overflowed gas \ - representation" - .to_owned(), - )) - .with(GasUsed(0.into())), - ); - continue; - } - }; + let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_limit = + match wrapper.gas_limit.as_scaled_gas(gas_scale) { + Ok(value) => value, + Err(_) => { + response.events.emit( + new_tx_event(&tx, height.0) + .with(Code(ResultCode::InvalidTx)) + .with(Info( + "The wrapper gas limit overflowed \ + gas representation" + .to_owned(), + )) + .with(GasUsed(0.into())), + ); + continue; + } + }; let tx_gas_meter = TxGasMeter::new(gas_limit); for cmt in tx.commitments() { if let Some(code_sec) = tx diff --git a/crates/node/src/shell/mod.rs b/crates/node/src/shell/mod.rs index 2ace0f620a..eb8624a7b5 100644 --- a/crates/node/src/shell/mod.rs +++ b/crates/node/src/shell/mod.rs @@ -48,7 +48,7 @@ use namada::ledger::pos::namada_proof_of_stake::types::{ }; use namada::ledger::protocol::ShellParams; use namada::ledger::{parameters, protocol}; -use namada::parameters::validate_tx_bytes; +use namada::parameters::{get_gas_scale, validate_tx_bytes}; use namada::proof_of_stake::storage::read_pos_params; use namada::state::tx_queue::ExpiredTx; use namada::state::{ @@ -1069,7 +1069,9 @@ where TxType::Wrapper(wrapper) => { // Validate wrapper first // Tx gas limit - let gas_limit = match Gas::try_from(wrapper.gas_limit) { + let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_limit = match wrapper.gas_limit.as_scaled_gas(gas_scale) + { Ok(value) => value, Err(_) => { response.code = ResultCode::InvalidTx.into(); @@ -1089,8 +1091,11 @@ where } // Max block gas + let gas_scale = + namada::parameters::get_gas_scale(&self.state).unwrap(); let block_gas_limit: Gas = Gas::from_whole_units( namada::parameters::get_max_block_gas(&self.state).unwrap(), + gas_scale, ) .expect("Gas limit from parameter must not overflow"); if gas_meter.tx_gas_limit > block_gas_limit { diff --git a/crates/node/src/shell/prepare_proposal.rs b/crates/node/src/shell/prepare_proposal.rs index 6cc2f22392..f8e9bd59df 100644 --- a/crates/node/src/shell/prepare_proposal.rs +++ b/crates/node/src/shell/prepare_proposal.rs @@ -4,9 +4,10 @@ use std::cell::RefCell; use namada::core::address::Address; use namada::core::key::tm_raw_hash_to_string; -use namada::gas::{Gas, TxGasMeter}; +use namada::gas::TxGasMeter; use namada::hash::Hash; use namada::ledger::protocol::{self, ShellParams}; +use namada::parameters::get_gas_scale; use namada::proof_of_stake::storage::find_validator_by_raw_hash; use namada::state::{DBIter, StorageHasher, TempWlState, DB}; use namada::token::{Amount, DenominatedAmount}; @@ -288,7 +289,9 @@ where tx.validate_tx().map_err(|_| ())?; if let TxType::Wrapper(wrapper) = tx.header().tx_type { // Check tx gas limit for tx size - let gas_limit = Gas::try_from(wrapper.gas_limit).map_err(|_| ())?; + let gas_scale = get_gas_scale(temp_state).unwrap(); + let gas_limit = + wrapper.gas_limit.as_scaled_gas(gas_scale).map_err(|_| ())?; let mut tx_gas_meter = TxGasMeter::new(gas_limit); tx_gas_meter.add_wrapper_gas(tx_bytes).map_err(|_| ())?; diff --git a/crates/node/src/shell/process_proposal.rs b/crates/node/src/shell/process_proposal.rs index f226097c11..7554be9e50 100644 --- a/crates/node/src/shell/process_proposal.rs +++ b/crates/node/src/shell/process_proposal.rs @@ -410,7 +410,17 @@ where let allocated_gas = metadata.user_gas.try_dump(u64::from(wrapper.gas_limit)); - let gas_limit = match Gas::try_from(wrapper.gas_limit) { + let gas_scale = match get_gas_scale(temp_state) { + Ok(scale) => scale, + Err(_) => { + return TxResult { + code: ResultCode::TxGasLimit.into(), + info: "Failed to get gas scale".to_owned(), + }; + } + }; + let gas_limit = match wrapper.gas_limit.as_scaled_gas(gas_scale) + { Ok(value) => value, Err(_) => { return TxResult { diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index 4f394ea968..affaded892 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -28,7 +28,7 @@ use namada_core::storage::Key; use namada_core::time::DurationSecs; use namada_core::token; use namada_storage::{ResultExt, StorageRead, StorageWrite}; -pub use storage::get_max_block_gas; +pub use storage::{get_gas_scale, get_max_block_gas}; use thiserror::Error; pub use wasm_allowlist::{is_tx_allowed, is_vp_allowed}; diff --git a/crates/parameters/src/storage.rs b/crates/parameters/src/storage.rs index e280064962..7b3d847138 100644 --- a/crates/parameters/src/storage.rs +++ b/crates/parameters/src/storage.rs @@ -184,6 +184,18 @@ pub fn get_max_block_gas( ) } +/// Helper function to retrieve the `gas_scale` protocol parameter from +/// storage +pub fn get_gas_scale( + storage: &impl StorageRead, +) -> std::result::Result { + storage.read(&get_gas_scale_key())?.ok_or( + namada_storage::Error::SimpleMessage( + "Missing gas_scale parameter from storage", + ), + ) +} + /// Storage key used for the flag to enable the native token transfer pub fn get_native_token_transferable_key() -> Key { get_native_token_transferable_key_at_addr(ADDRESS) diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 52f079c5ad..9feac5cb34 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -23,7 +23,7 @@ use namada_core::token::{ Amount, DenominatedAmount, Denomination, MaspDigitPos, }; use namada_core::{storage, token}; -use namada_gas::event::GasUsed as GasUsedAttr; +use namada_gas::event::{GasScale as GasScaleAttr, GasUsed as GasUsedAttr}; use namada_gas::Gas; use namada_governance::parameters::GovernanceParameters; use namada_governance::pgf::parameters::PgfParameters; @@ -539,7 +539,10 @@ pub async fn dry_run_tx( .await, )? .data; - let result_str = format!("Transaction consumed {} gas", result.gas_used); + let result_str = format!( + "Transaction consumed {} gas", + result.gas_used.get_whole_gas_units(result.gas_scale) + ); let mut cmt_result_str = String::new(); for (cmt_hash, cmt_result) in &result.batch_results.0 { match cmt_result { @@ -648,6 +651,12 @@ impl TryFrom for TxResponse { let gas_used = event .read_attribute::() .map_err(|err| err.to_string())?; + let gas_scale = event + .read_attribute::() + .map_err(|err| err.to_string())?; + + let gas_used = + Gas::from_whole_units(gas_used.into(), gas_scale).expect("temp"); Ok(TxResponse { batch, diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index 20c4019fc2..4a6af670b1 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -265,6 +265,8 @@ impl Default for ExtendedTxResult { pub struct TxResult { /// Total gas used by the transaction (includes the gas used by VPs) pub gas_used: Gas, + /// bing + pub gas_scale: u64, /// The results of the batch, indexed by the hash of the specific /// [`crate::types::TxCommitments`] pub batch_results: BatchResults, @@ -274,6 +276,7 @@ impl Default for TxResult { fn default() -> Self { Self { gas_used: Default::default(), + gas_scale: 100_000_000_u64, batch_results: Default::default(), } } @@ -295,6 +298,7 @@ impl TxResult { TxResult { gas_used: self.gas_used, + gas_scale: self.gas_scale, batch_results: BatchResults(batch_results), } } @@ -411,7 +415,11 @@ pub struct VpsResult { impl fmt::Display for TxResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { - write!(f, "Transaction is valid. Gas used: {}", self.gas_used,) + write!( + f, + "Transaction is valid. Gas used: {}", + self.gas_used.get_whole_gas_units(self.gas_scale) + ) } else { write!(f, "{}", serde_json::to_string(self).unwrap()) } diff --git a/crates/tx/src/data/wrapper.rs b/crates/tx/src/data/wrapper.rs index 23bd4c53f1..522c3caffb 100644 --- a/crates/tx/src/data/wrapper.rs +++ b/crates/tx/src/data/wrapper.rs @@ -111,13 +111,25 @@ impl From for Amount { } } -impl TryFrom for Gas { - type Error = std::io::Error; - - /// Derive a Gas instance with a sub amount which is exactly a whole - /// amount since the limit represents gas in whole units - fn try_from(value: GasLimit) -> Result { - Self::from_whole_units(u64::from(value)).ok_or_else(|| { +// impl TryFrom for Gas { +// type Error = std::io::Error; + +// /// Derive a Gas instance with a sub amount which is exactly a whole +// /// amount since the limit represents gas in whole units +// fn try_from(value: GasLimit) -> Result { +// Self::from_whole_units(u64::from(value)).ok_or_else(|| { +// std::io::Error::new( +// std::io::ErrorKind::InvalidInput, +// "gas overflow", +// ) +// }) +// } +// } + +impl GasLimit { + /// Convert the gas limit into scaled gas + pub fn as_scaled_gas(&self, scale: u64) -> Result { + Gas::from_whole_units(u64::from(*self), scale).ok_or_else(|| { std::io::Error::new( std::io::ErrorKind::InvalidInput, "gas overflow", From 4f793e78d77ef561362dfd4be271d3b91ac0dc90 Mon Sep 17 00:00:00 2001 From: brentstone Date: Fri, 7 Jun 2024 16:10:55 +0200 Subject: [PATCH 03/10] Light error handling --- crates/gas/src/lib.rs | 13 ++++++++++--- crates/node/src/shell/finalize_block.rs | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/gas/src/lib.rs b/crates/gas/src/lib.rs index 1f17202c77..46728132c2 100644 --- a/crates/gas/src/lib.rs +++ b/crates/gas/src/lib.rs @@ -152,10 +152,17 @@ impl Gas { /// Converts the sub gas units to whole ones. If the sub units are not a /// multiple of the `SCALE` than ceil the quotient - #[allow(clippy::arithmetic_side_effects)] pub fn get_whole_gas_units(&self, scale: u64) -> u64 { - let quotient = self.sub / scale; - if self.sub % scale == 0 { + let quotient = self + .sub + .checked_div(scale) + .expect("Gas quotient should not overflow on checked division"); + if self + .sub + .checked_rem(scale) + .expect("Gas quotient remainder should not overflow") + == 0 + { quotient } else { quotient diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 4a0aa27fe5..25a0e994d6 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -386,7 +386,8 @@ where .unwrap_or(""), msg, ); - let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_scale = get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let scaled_gas = Gas::from( tx_data .tx_gas_meter From 037f62f73b6c7fd1e9a73b8d485a67caa8ec0767 Mon Sep 17 00:00:00 2001 From: brentstone Date: Sat, 8 Jun 2024 12:19:43 +0200 Subject: [PATCH 04/10] fix and clean up --- crates/gas/src/lib.rs | 1 - crates/namada/src/ledger/mod.rs | 2 -- crates/namada/src/ledger/protocol/mod.rs | 7 +------ crates/node/src/bench_utils.rs | 1 - crates/node/src/shell/finalize_block.rs | 9 ++++++--- crates/node/src/shell/mod.rs | 7 ++++--- crates/node/src/shell/prepare_proposal.rs | 3 ++- crates/sdk/src/rpc.rs | 14 +++----------- crates/sdk/src/tx.rs | 4 +++- crates/tx/src/data/mod.rs | 10 +--------- crates/tx/src/data/wrapper.rs | 15 --------------- 11 files changed, 20 insertions(+), 53 deletions(-) diff --git a/crates/gas/src/lib.rs b/crates/gas/src/lib.rs index 46728132c2..367ef7c4e7 100644 --- a/crates/gas/src/lib.rs +++ b/crates/gas/src/lib.rs @@ -202,7 +202,6 @@ impl FromStr for Gas { fn from_str(s: &str) -> std::result::Result { let raw: u64 = s.parse().map_err(GasParseError::Parse)?; - // let gas = Gas::from_whole_units(raw).ok_or(GasParseError::Overflow)?; Ok(Self { sub: raw }) } } diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 2ea021bb69..6de3420a86 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -86,8 +86,6 @@ mod dry_run_tx { let gas_limit = GasLimit::from(max_block_gas) .as_scaled_gas(gas_scale) .into_storage_result()?; - // let gas_limit = Gas::try_from(GasLimit::from(max_block_gas)) - // .into_storage_result()?; (TxResult::default(), TxGasMeter::new(gas_limit)) } }; diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 2c18194cb1..2bb8ecb4d2 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -261,11 +261,9 @@ where tx_wasm_cache, }, )?; - let gas_scale = - namada_parameters::get_gas_scale(state).unwrap(); + Ok(TxResult { gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), - gas_scale, batch_results: BatchResults( [(cmt.get_hash(), Ok(batched_tx_result))] .into_iter() @@ -433,11 +431,8 @@ where .add_wrapper_gas(tx_bytes) .map_err(|err| Error::GasError(err.to_string()))?; - let gas_scale = namada_parameters::get_gas_scale(state).unwrap(); - Ok(TxResult { gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), - gas_scale, batch_results: BatchResults::default(), }) } diff --git a/crates/node/src/bench_utils.rs b/crates/node/src/bench_utils.rs index 3cb6ac531c..ef80036715 100644 --- a/crates/node/src/bench_utils.rs +++ b/crates/node/src/bench_utils.rs @@ -913,7 +913,6 @@ impl Client for BenchShell { .map(|(idx, (tx, changed_keys))| { let tx_result = TxResult:: { gas_used: 0.into(), - gas_scale: 0_u64, // TODO: is this correct? batch_results: BatchResults( [( tx.first_commitments().unwrap().get_hash(), diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 25a0e994d6..844d3dec71 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -419,7 +419,8 @@ where msg ); - let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_scale = get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let scaled_gas = Gas::from( tx_data .tx_gas_meter @@ -504,7 +505,8 @@ where self.commit_batch_hash(tx_data.replay_protection_hashes); } - let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_scale = get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let scaled_gas = Gas::from( tx_data .tx_gas_meter @@ -694,7 +696,8 @@ where TxType::Wrapper(wrapper) => { stats.increment_wrapper_txs(); - let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_scale = get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let gas_limit = match wrapper.gas_limit.as_scaled_gas(gas_scale) { Ok(value) => value, diff --git a/crates/node/src/shell/mod.rs b/crates/node/src/shell/mod.rs index eb8624a7b5..3f79141f11 100644 --- a/crates/node/src/shell/mod.rs +++ b/crates/node/src/shell/mod.rs @@ -1069,7 +1069,8 @@ where TxType::Wrapper(wrapper) => { // Validate wrapper first // Tx gas limit - let gas_scale = get_gas_scale(&self.state).unwrap(); + let gas_scale = get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let gas_limit = match wrapper.gas_limit.as_scaled_gas(gas_scale) { Ok(value) => value, @@ -1091,8 +1092,8 @@ where } // Max block gas - let gas_scale = - namada::parameters::get_gas_scale(&self.state).unwrap(); + let gas_scale = namada::parameters::get_gas_scale(&self.state) + .expect("Failed to get gas scale from parameters"); let block_gas_limit: Gas = Gas::from_whole_units( namada::parameters::get_max_block_gas(&self.state).unwrap(), gas_scale, diff --git a/crates/node/src/shell/prepare_proposal.rs b/crates/node/src/shell/prepare_proposal.rs index f8e9bd59df..33f22c2fb8 100644 --- a/crates/node/src/shell/prepare_proposal.rs +++ b/crates/node/src/shell/prepare_proposal.rs @@ -289,7 +289,8 @@ where tx.validate_tx().map_err(|_| ())?; if let TxType::Wrapper(wrapper) = tx.header().tx_type { // Check tx gas limit for tx size - let gas_scale = get_gas_scale(temp_state).unwrap(); + let gas_scale = get_gas_scale(temp_state) + .expect("Failed to get gas scale from parameters"); let gas_limit = wrapper.gas_limit.as_scaled_gas(gas_scale).map_err(|_| ())?; let mut tx_gas_meter = TxGasMeter::new(gas_limit); diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 9feac5cb34..6f07a373c3 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -23,7 +23,7 @@ use namada_core::token::{ Amount, DenominatedAmount, Denomination, MaspDigitPos, }; use namada_core::{storage, token}; -use namada_gas::event::{GasScale as GasScaleAttr, GasUsed as GasUsedAttr}; +use namada_gas::event::GasUsed as GasUsedAttr; use namada_gas::Gas; use namada_governance::parameters::GovernanceParameters; use namada_governance::pgf::parameters::PgfParameters; @@ -539,10 +539,8 @@ pub async fn dry_run_tx( .await, )? .data; - let result_str = format!( - "Transaction consumed {} gas", - result.gas_used.get_whole_gas_units(result.gas_scale) - ); + let result_str = format!("Transaction consumed {} gas", result.gas_used); + let mut cmt_result_str = String::new(); for (cmt_hash, cmt_result) in &result.batch_results.0 { match cmt_result { @@ -651,12 +649,6 @@ impl TryFrom for TxResponse { let gas_used = event .read_attribute::() .map_err(|err| err.to_string())?; - let gas_scale = event - .read_attribute::() - .map_err(|err| err.to_string())?; - - let gas_used = - Gas::from_whole_units(gas_used.into(), gas_scale).expect("temp"); Ok(TxResponse { batch, diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index b9daabeca2..bd17b498ef 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -405,9 +405,11 @@ pub fn display_batch_resp(context: &impl Namada, resp: &TxResponse) { InnerTxResult::Success(_) => { display_line!( context.io(), - "Transaction {} was successfully applied at height {}.", + "Transaction {} was successfully applied at height {}, \ + consuming {} gas units.", cmt_hash, resp.height, + resp.gas_used ); } InnerTxResult::VpsRejected(inner) => { diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index 4a6af670b1..5984dafdc9 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -265,8 +265,6 @@ impl Default for ExtendedTxResult { pub struct TxResult { /// Total gas used by the transaction (includes the gas used by VPs) pub gas_used: Gas, - /// bing - pub gas_scale: u64, /// The results of the batch, indexed by the hash of the specific /// [`crate::types::TxCommitments`] pub batch_results: BatchResults, @@ -276,7 +274,6 @@ impl Default for TxResult { fn default() -> Self { Self { gas_used: Default::default(), - gas_scale: 100_000_000_u64, batch_results: Default::default(), } } @@ -298,7 +295,6 @@ impl TxResult { TxResult { gas_used: self.gas_used, - gas_scale: self.gas_scale, batch_results: BatchResults(batch_results), } } @@ -415,11 +411,7 @@ pub struct VpsResult { impl fmt::Display for TxResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { - write!( - f, - "Transaction is valid. Gas used: {}", - self.gas_used.get_whole_gas_units(self.gas_scale) - ) + write!(f, "Transaction is valid. Gas used: {}", self.gas_used) } else { write!(f, "{}", serde_json::to_string(self).unwrap()) } diff --git a/crates/tx/src/data/wrapper.rs b/crates/tx/src/data/wrapper.rs index 522c3caffb..3a2f1ebcc7 100644 --- a/crates/tx/src/data/wrapper.rs +++ b/crates/tx/src/data/wrapper.rs @@ -111,21 +111,6 @@ impl From for Amount { } } -// impl TryFrom for Gas { -// type Error = std::io::Error; - -// /// Derive a Gas instance with a sub amount which is exactly a whole -// /// amount since the limit represents gas in whole units -// fn try_from(value: GasLimit) -> Result { -// Self::from_whole_units(u64::from(value)).ok_or_else(|| { -// std::io::Error::new( -// std::io::ErrorKind::InvalidInput, -// "gas overflow", -// ) -// }) -// } -// } - impl GasLimit { /// Convert the gas limit into scaled gas pub fn as_scaled_gas(&self, scale: u64) -> Result { From 468d423d8788e0561d1985e4e81f7a0315dde9ff Mon Sep 17 00:00:00 2001 From: brentstone Date: Sun, 9 Jun 2024 20:45:29 +0200 Subject: [PATCH 05/10] changelog: add #3391 --- .../unreleased/improvements/3391-parameterize-gas-scale.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/improvements/3391-parameterize-gas-scale.md diff --git a/.changelog/unreleased/improvements/3391-parameterize-gas-scale.md b/.changelog/unreleased/improvements/3391-parameterize-gas-scale.md new file mode 100644 index 0000000000..2729821cb7 --- /dev/null +++ b/.changelog/unreleased/improvements/3391-parameterize-gas-scale.md @@ -0,0 +1,3 @@ +- Include the gas scale as a protocol parameter that is + mutable via governance rather than as a hard-coded constant. + ([\#3391](https://github.com/anoma/namada/pull/3391)) \ No newline at end of file From 37e59950958f292ed6ee1e9d9130897e239888a0 Mon Sep 17 00:00:00 2001 From: brentstone Date: Sun, 9 Jun 2024 20:44:29 +0200 Subject: [PATCH 06/10] fixes from comments --- crates/gas/src/event.rs | 14 -------------- crates/namada/src/ledger/mod.rs | 5 ++--- crates/node/src/shell/mod.rs | 16 ++++++++++++---- crates/node/src/shell/prepare_proposal.rs | 3 +-- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/crates/gas/src/event.rs b/crates/gas/src/event.rs index 066b98c30c..d76889fece 100644 --- a/crates/gas/src/event.rs +++ b/crates/gas/src/event.rs @@ -17,17 +17,3 @@ impl EventAttributeEntry<'static> for GasUsed { self.0 } } - -/// Extend a [`namada_events::Event`] with the gas scale data. -pub struct GasScale(pub u64); - -impl EventAttributeEntry<'static> for GasScale { - type Value = u64; - type ValueOwned = Self::Value; - - const KEY: &'static str = "gas_scale"; - - fn into_value(self) -> Self::Value { - self.0 - } -} diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 6de3420a86..8562a4a564 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -53,10 +53,11 @@ mod dry_run_tx { let tx = Tx::try_from(&request.data[..]).into_storage_result()?; tx.validate_tx().into_storage_result()?; + let gas_scale = namada_parameters::get_gas_scale(ctx.state)?; + // Wrapper dry run to allow estimating the gas cost of a transaction let (mut tx_result, tx_gas_meter) = match tx.header().tx_type { TxType::Wrapper(wrapper) => { - let gas_scale = namada_parameters::get_gas_scale(ctx.state)?; let gas_limit = wrapper .gas_limit .as_scaled_gas(gas_scale) @@ -79,8 +80,6 @@ mod dry_run_tx { _ => { // If dry run only the inner tx, use the max block gas as // the gas limit - let gas_scale = namada_parameters::get_gas_scale(ctx.state)?; - let max_block_gas = namada_parameters::get_max_block_gas(ctx.state)?; let gas_limit = GasLimit::from(max_block_gas) diff --git a/crates/node/src/shell/mod.rs b/crates/node/src/shell/mod.rs index 3f79141f11..4caf8a169e 100644 --- a/crates/node/src/shell/mod.rs +++ b/crates/node/src/shell/mod.rs @@ -1067,10 +1067,20 @@ where } }, TxType::Wrapper(wrapper) => { + // Get the gas scale first + let gas_scale = match get_gas_scale(&self.state) { + Ok(scale) => scale, + Err(_) => { + response.code = ResultCode::InvalidTx.into(); + response.log = "The gas scale could not be found in \ + the parameters storage" + .to_string(); + return response; + } + }; + // Validate wrapper first // Tx gas limit - let gas_scale = get_gas_scale(&self.state) - .expect("Failed to get gas scale from parameters"); let gas_limit = match wrapper.gas_limit.as_scaled_gas(gas_scale) { Ok(value) => value, @@ -1092,8 +1102,6 @@ where } // Max block gas - let gas_scale = namada::parameters::get_gas_scale(&self.state) - .expect("Failed to get gas scale from parameters"); let block_gas_limit: Gas = Gas::from_whole_units( namada::parameters::get_max_block_gas(&self.state).unwrap(), gas_scale, diff --git a/crates/node/src/shell/prepare_proposal.rs b/crates/node/src/shell/prepare_proposal.rs index 33f22c2fb8..aa6fe39b5f 100644 --- a/crates/node/src/shell/prepare_proposal.rs +++ b/crates/node/src/shell/prepare_proposal.rs @@ -289,8 +289,7 @@ where tx.validate_tx().map_err(|_| ())?; if let TxType::Wrapper(wrapper) = tx.header().tx_type { // Check tx gas limit for tx size - let gas_scale = get_gas_scale(temp_state) - .expect("Failed to get gas scale from parameters"); + let gas_scale = get_gas_scale(temp_state).map_err(|_| ())?; let gas_limit = wrapper.gas_limit.as_scaled_gas(gas_scale).map_err(|_| ())?; let mut tx_gas_meter = TxGasMeter::new(gas_limit); From 112da6116adeb7a1dd41c726aab0232a6b6efd3f Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 10 Jun 2024 10:07:44 -0700 Subject: [PATCH 07/10] change comment on Gas Display --- crates/gas/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/gas/src/lib.rs b/crates/gas/src/lib.rs index 367ef7c4e7..dc9c4c0a20 100644 --- a/crates/gas/src/lib.rs +++ b/crates/gas/src/lib.rs @@ -192,7 +192,8 @@ impl From for u64 { impl Display for Gas { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - // Display the gas in whole amounts + // Need to do this now that the gas scale is a parameter. Should + // manually scale gas first before calling this write!(f, "{}", self.sub) } } From 8740d8d5cfa8d04dfaa6a133baeb2dde2a3c16b7 Mon Sep 17 00:00:00 2001 From: brentstone Date: Wed, 12 Jun 2024 11:06:19 -0700 Subject: [PATCH 08/10] fix unit test --- crates/namada/src/ledger/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 8562a4a564..f36406453d 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -191,6 +191,12 @@ mod test { .expect( "Max block gas parameter must be initialized in storage", ); + // Initialize mock gas scale + let gas_scale_key = namada_parameters::storage::get_gas_scale_key(); + state + .db_write(&gas_scale_key, 100_000_000_u64.serialize_to_vec()) + .expect("Gas scale parameter must be initialized in storage"); + let event_log = EventLog::default(); let (vp_wasm_cache, vp_cache_dir) = wasm::compilation_cache::common::testing::cache(); From 749c45a4f6887aecf6e165969d5c7b526da9d6a1 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 20 Jun 2024 14:45:04 +0100 Subject: [PATCH 09/10] Fixes ibc e2e test --- crates/tests/src/e2e/ibc_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index c1781b6295..a49f6211e4 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -2202,7 +2202,7 @@ fn check_tx_height(test: &Test, client: &mut NamadaCmd) -> Result { .split_once(' ') .unwrap() .1 - .split_once('.') + .split_once(',') .unwrap() .0; let height: u32 = height_str.parse().unwrap(); From 16a2c585a240bde7cb6fb6b9a2cc5e11fee03261 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Mon, 24 Jun 2024 14:58:21 +0200 Subject: [PATCH 10/10] Updated example of expected string --- crates/tests/src/e2e/ibc_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index a49f6211e4..3aadda7164 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -2196,7 +2196,7 @@ fn transfer_from_gaia( fn check_tx_height(test: &Test, client: &mut NamadaCmd) -> Result { let (_unread, matched) = client.exp_regex(r"height .*")?; - // Expecting e.g. "height 1337." + // Expecting e.g. "height 1337, consuming x gas units." let height_str = matched .trim() .split_once(' ')