Skip to content

Commit

Permalink
fixes from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jun 9, 2024
1 parent 468d423 commit 37e5995
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
14 changes: 0 additions & 14 deletions crates/gas/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 2 additions & 3 deletions crates/namada/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions crates/node/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/node/src/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 37e5995

Please sign in to comment.