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

chore(executor): instrument errors to be more meaningful #2311

Merged
merged 7 commits into from
Oct 8, 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
12 changes: 10 additions & 2 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,9 +1501,10 @@ mod tests {
}
let mut config: Config = Default::default();
// Each TX consumes `tx_gas_usage` gas and so set the block gas limit to execute only 9 transactions.
let block_gas_limit = tx_gas_usage * 9;
config
.consensus_parameters
.set_block_gas_limit(tx_gas_usage * 9);
.set_block_gas_limit(block_gas_limit);
let mut executor = create_executor(Default::default(), config);

let block = PartialFuelBlock {
Expand All @@ -1519,7 +1520,14 @@ mod tests {

// Then
assert_eq!(skipped_transactions.len(), 1);
assert_eq!(skipped_transactions[0].1, ExecutorError::GasOverflow);
assert_eq!(
skipped_transactions[0].1,
ExecutorError::GasOverflow(
"Transaction cannot fit in remaining gas limit: (0).".into(),
*tx_gas_usage,
0
)
);
}

#[test]
Expand Down
35 changes: 25 additions & 10 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,16 @@ where
while regular_tx_iter.peek().is_some() {
for transaction in regular_tx_iter {
let tx_id = transaction.id(&self.consensus_params.chain_id());
if transaction.max_gas(&self.consensus_params)? > remaining_gas_limit {
data.skipped_transactions
.push((tx_id, ExecutorError::GasOverflow));
let tx_max_gas = transaction.max_gas(&self.consensus_params)?;
if tx_max_gas > remaining_gas_limit {
data.skipped_transactions.push((
tx_id,
ExecutorError::GasOverflow(
format!("Transaction cannot fit in remaining gas limit: ({remaining_gas_limit})."),
tx_max_gas,
remaining_gas_limit,
),
));
continue;
}
match self.execute_transaction_and_commit(
Expand Down Expand Up @@ -1457,10 +1464,13 @@ where
.coinbase
.checked_add(tx_fee)
.ok_or(ExecutorError::FeeOverflow)?;
execution_data.used_gas = execution_data
.used_gas
.checked_add(used_gas)
.ok_or(ExecutorError::GasOverflow)?;
execution_data.used_gas = execution_data.used_gas.checked_add(used_gas).ok_or(
ExecutorError::GasOverflow(
"Execution used gas overflowed.".into(),
execution_data.used_gas,
used_gas,
),
)?;
execution_data.used_size = execution_data
.used_size
.checked_add(used_size)
Expand Down Expand Up @@ -1813,9 +1823,14 @@ where
gas_price,
)
.ok_or(ExecutorError::FeeOverflow)?;
let total_used_gas = min_gas
.checked_add(used_gas)
.ok_or(ExecutorError::GasOverflow)?;
let total_used_gas =
min_gas
.checked_add(used_gas)
.ok_or(ExecutorError::GasOverflow(
"Total used gas overflowed.".into(),
min_gas,
used_gas,
))?;
// if there's no script result (i.e. create) then fee == base amount
Ok((
total_used_gas,
Expand Down
6 changes: 4 additions & 2 deletions crates/types/src/services/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ pub enum Error {
OutputAlreadyExists,
#[display(fmt = "The computed fee caused an integer overflow")]
FeeOverflow,
#[display(fmt = "The computed gas caused an integer overflow")]
GasOverflow,
#[display(
fmt = "The computed gas caused an integer overflow. reason: {_0}, Augend: {_1}, Addend: {_2}"
rymnc marked this conversation as resolved.
Show resolved Hide resolved
)]
GasOverflow(String, u64, u64),
#[display(fmt = "The computed transaction size caused an integer overflow")]
TxSizeOverflow,
#[display(fmt = "The block is missing `Mint` transaction.")]
Expand Down
Loading