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);