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

refactor: Add AccessList result type to eth_createAccessList #9811

Merged
merged 8 commits into from
Jul 29, 2024

Conversation

c0np4nn4
Copy link
Contributor

close #9746.

@mattsse I made changes based on the conversation we had on the issue #9746 .
I wonder is this the right way to handle the issue. Thank you.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty, some suggestions

Comment on lines 16 to 17
/// Optional error message if the transaction failed.
pub error: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be skipped if none

#[serde(default, skip_serializing_if = "Option::is_none")]

Comment on lines 243 to 254
let (result, env) = match self.inspect(&mut db, env, &mut inspector) {
Ok((res, env)) => (res, env),
Err(e) => {
return Err(e.into());
}
ExecutionResult::Success { .. } => Ok(()),
}?;
};

let error = match result.result {
ExecutionResult::Halt { reason, .. } => Some(format!("{:?}", reason)),
ExecutionResult::Revert { output, .. } => Some(format!("{:?}", output)),
ExecutionResult::Success { .. } => None,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can keep the code on main and use RevertError::new(output) for the revert case

Copy link
Contributor Author

@c0np4nn4 c0np4nn4 Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the code regarding (result, env) from the main branch as is.
Also, I made some changes to the Revert part and left a commit for it.


/// `AccessListWithGasUsedAndError` for handling error from `eth_createAccessList`
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AccessListWithGasUsedAndError {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also name this AccessListResult


/// `AccessListWithGasUsedAndError` for handling error from `eth_createAccessList`
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AccessListWithGasUsedAndError {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs camelCase rename

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise lgtm

use revm_primitives::U256;
use serde::{Deserialize, Serialize};

/// `AccessListResult ` for handling error from `eth_createAccessList`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// `AccessListResult ` for handling error from `eth_createAccessList`
/// `AccessListResult` for handling errors from `eth_createAccessList`

nit

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last nits

return Err(e.into());
}
};
let (result, env) = self.inspect(&mut db, env, &mut inspector)?;

let error = match result.result {
ExecutionResult::Halt { reason, .. } => Some(format!("{:?}", reason)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use + to_string

pub const fn halt(reason: HaltReason, gas_limit: u64) -> Self {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse

let error = match result.result {
ExecutionResult::Halt { reason, .. } => Some(format!("{:?}", reason).to_string()),
ExecutionResult::Revert { output, .. } => Some(RevertError::new(output).to_string()),
ExecutionResult::Success { .. } => None,
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need to use

pub const fn halt(reason: HaltReason, gas_limit: u64) -> Self {

to create the appropriate error message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bother you. I fix it.

let error = match result.result {
ExecutionResult::Halt { reason, gas_used } => {
Some(RpcInvalidTransactionError::halt(reason, gas_used).to_string())
}
ExecutionResult::Revert { output, .. } => Some(RevertError::new(output).to_string()),
ExecutionResult::Success { .. } => None,
};


let error = match result.result {
ExecutionResult::Halt { reason, .. } => Some(format!("{:?}", reason)),
ExecutionResult::Revert { output, .. } => Some(format!("{:?}", output)),
ExecutionResult::Revert { output, .. } => {
Some(format!("{:?}", RevertError::new(output)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Some(format!("{:?}", RevertError::new(output)))
Some(RevertError::new(output).to_string())

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty, I changed it slightly to exit right away if the tx failed with the correct gas used and error message

@mattsse mattsse enabled auto-merge July 29, 2024 17:55
@mattsse mattsse added this pull request to the merge queue Jul 29, 2024
Merged via the queue into paradigmxyz:main with commit f43fd7b Jul 29, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AccessList result type to eth_createAccessList
3 participants