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

feat(RPC): estimate fee Error returns with transaction context #1551

Closed

Conversation

datactor
Copy link

@datactor datactor commented Apr 3, 2024

Pull Request type

Please add the labels corresponding to the type of changes your PR introduces:

  • Feature: Enhanced error handling for estimate_fee calls, including specific transaction hash in error data for failed and reverted transactions

What is the current behavior?

When requesting a fee estimate, the call expects a list of transactions. However, if the call fails, it returns an error without context, making it difficult to identify which specific transaction caused the failure.

What is the new behavior?

  • Error enum has been updated to distinguish between transactions that failed and those that were reverted.
  • If an error occurs, the hash of the transaction is now returned in the data field of the ContractError, distinguishing whether it is reverted or rejected.
  • This change makes it clear which transaction caused the error, allowing you to preview executable transactions by simulating the transaction list.

Does this introduce a breaking change?

No

Other information

@tdelabro
Copy link
Collaborator

Isn't this a duplicate with #1555? @hhamud ?

@hhamud
Copy link
Contributor

hhamud commented May 1, 2024

Isn't this a duplicate with #1555? @hhamud ?

its more specific to their case of just piping back a list of reverted and failed transactions when calling a specific function. My PR is more general change of piping whatever error back to the user.

@tdelabro
Copy link
Collaborator

tdelabro commented May 6, 2024

@hhamud which one should be merged first?

) -> jsonrpsee::core::Error {
jsonrpsee::core::Error::Call(CallError::Custom(ErrorObject::owned(
err as i32,
format!("{err}{msg}"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

no separator between err and msg?

Copy link
Collaborator

Choose a reason for hiding this comment

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

: or

Copy link
Author

@datactor datactor May 19, 2024

Choose a reason for hiding this comment

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

Thanks for the review!

In the latest commit, it is now possible to distinguish between revert_error and other errors within SimulationError. Therefore, I believe it may not be necessary to request this PR based on the current content, even if I modify it to reflect your review.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean? Sorry I don't get your point

Copy link
Author

Choose a reason for hiding this comment

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

I apologize if my previous comment was unclear. Since PR #1555 implements similar error handling, I suggest we close this PR. And if there are any further requirements, I would be happy to address them in the future in a new PR

for (i, (overall_fee, gas_consumed)) in fee_estimates.iter().enumerate() {
match (*overall_fee, *gas_consumed) {
FEE_ESTIMATION_FAILED => {
failed_estimates.push_rejected(transactions[i].compute_hash::<H>(chain_id, false))
Copy link
Collaborator

Choose a reason for hiding this comment

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

you will have to rebase. The compute_hash does not take a generic anymore

return Err(crate::errors::rpc_error_with_data(
StarknetRpcApiError::ContractError,
failed_estimates,
" with transaction hashes".to_string(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does this comes from?
IT's the "msg" field. Did you add it yourself or is it part of the specs?

Comment on lines +93 to +98
match fee_res {
Ok(fee) => fees.push(fee?),
Err(Error::<T>::TransactionExecutionFailed) => fees.push(FEE_ESTIMATION_FAILED),
Err(Error::<T>::TransactionExecutionReverted) => fees.push(FEE_ESTIMATION_REVERTED),
Err(e) => return Err(e.into()),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://github.com/starkware-libs/starknet-specs/blob/76bdde23c7dae370a3340e40f7ca2ef2520e75b9/api/starknet_api_openrpc.json#L614

For estimate fee, we abort as soon as the first estimate fail.
That is why the previous code was fees.push(fee_res??);, where ? immediately returns.
You should keep this behaviour of early exiting the loop at the first error encountered

@tdelabro tdelabro closed this May 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants