Skip to content

Commit

Permalink
Merge of #4004
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 14, 2024
2 parents cb1e963 + 3b6ce2c commit c53c703
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added more info to gas failure errors. ([\#4004](https://github.com/anoma/namada/pull/4004))
21 changes: 13 additions & 8 deletions crates/gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use thiserror::Error;
#[allow(missing_docs)]
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum Error {
#[error("Transaction gas limit exceeded")]
TransactionGasExceededError,
#[error("Transaction gas limit exceeded maximum of {0}")]
TransactionGasExceededError(u64),
#[error("Block gas limit exceeded")]
BlockGasExceeded,
#[error("Overflow during gas operations")]
Expand Down Expand Up @@ -386,8 +386,9 @@ pub trait GasMetering {
.get_tx_consumed_gas()
.checked_add(vps_gas)
.ok_or(Error::GasOverflow)?;
if total > self.get_gas_limit() {
return Err(Error::TransactionGasExceededError);
let gas_limit = self.get_gas_limit();
if total > gas_limit {
return Err(Error::TransactionGasExceededError(gas_limit.into()));
}

Ok(())
Expand Down Expand Up @@ -432,7 +433,9 @@ impl GasMetering for TxGasMeter {
})?;

if self.transaction_gas > self.tx_gas_limit {
return Err(Error::TransactionGasExceededError);
return Err(Error::TransactionGasExceededError(
self.tx_gas_limit.clone().into(),
));
}

Ok(())
Expand Down Expand Up @@ -512,7 +515,9 @@ impl GasMetering for VpGasMeter {
.ok_or(Error::GasOverflow)?;

if current_total > self.tx_gas_limit {
return Err(Error::TransactionGasExceededError);
return Err(Error::TransactionGasExceededError(
self.tx_gas_limit.clone().into(),
));
}

Ok(())
Expand Down Expand Up @@ -601,7 +606,7 @@ mod tests {
meter
.consume(TX_GAS_LIMIT.into())
.expect_err("unexpectedly succeeded"),
Error::TransactionGasExceededError
Error::TransactionGasExceededError(_)
);
}

Expand All @@ -624,7 +629,7 @@ mod tests {
meter
.consume((TX_GAS_LIMIT + 1).into())
.expect_err("unexpectedly succeeded"),
Error::TransactionGasExceededError
Error::TransactionGasExceededError(_)
);
}
}
11 changes: 6 additions & 5 deletions crates/node/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ where
};

// Commit tx to the block write log even in case of subsequent errors (if
// the fee payment failed instead, than the previous two functions must
// the fee payment failed instead, then the previous two functions must
// have propagated an error)
shell_params
.state
Expand Down Expand Up @@ -901,11 +901,12 @@ where

checked!(balance - fees).map_or_else(
|_| {
Err(Error::FeeError(
Err(Error::FeeError(format!(
"Masp fee payment unshielded an insufficient \
amount"
.to_string(),
))
amount: Balance after unshielding: {balance} \
{}; required {fees}",
wrapper.fee.token
)))
},
|_| Ok(Some(valid_batched_tx_result)),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/node/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ where
Ok(amount_per_gas_unit) if amount_per_gas_unit < minimum_gas_price => {
// The fees do not match the minimum required
return Err(Error::TxApply(protocol::Error::FeeError(format!(
"Fee amount {:?} do not match the minimum required amount \
"Fee amount {:?} does not match the minimum required amount \
{:?} for token {}",
wrapper.fee.amount_per_gas_unit,
minimum_gas_price,
Expand Down

0 comments on commit c53c703

Please sign in to comment.