Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more info to gas errors #4004

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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