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

add custom conversion error to handle additional situations (such as optimism deposit tx) #875

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

zobront
Copy link
Contributor

@zobront zobront commented Jun 12, 2024

Motivation

paradigmxyz/reth#8763 implements conversion of Alloy transaction to Reth transaction for Optimism deposit transactions. In the conversion process, additional errors are required.

Solution

[EDIT] Originally, this PR added new errors for the three situations that were not already covered.

After additional discussion, the PR was revised to add a single Custom(String) error type that could be used in situations that were not already covered, rather than enumerating all possibilities.

The plan is to remove the whole enum in the future. From @prestwich:

yeah, let's move this to custom and then plan to delete the whole enum when we embed the tx envelope in the rpc response

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich
Copy link
Member

Modifying rpc types to support optimism is generally not the plan for this repo. The only concession made so far is the optional signature in transaction response. I would suggest duplicating this error enum into a separate optimism-specific repo

@zobront
Copy link
Contributor Author

zobront commented Jun 12, 2024

@prestwich Would you be willing to add a Custom(String) variant to ConversionError?

@prestwich
Copy link
Member

I'm not opposed to a Custom(String), but do we actually match on or destructure this enum anywhere? 🤔

@zobront
Copy link
Contributor Author

zobront commented Jun 12, 2024

I've searched Reth and Alloy and only references to this enum I see are:

Neither matches or destructures, just references the individual elements.

Any other repos I should be checking to confirm?

@prestwich
Copy link
Member

Any other repos I should be checking to confirm?

not that i know of

at this point i am wondering if this is an example of non-useful type safety. Why is this error anything other than a string? we use structures &'static str for transaction building

cc @mattsse

@zobront
Copy link
Contributor Author

zobront commented Jun 12, 2024

From what I've seen, I agree with this perspective.

Comment on lines 61 to 69
/// Missing source hash (for Optimism deposit tx)
#[error("missing source hash")]
MissingSourceHash,
/// Invalid source hash (for Optimism deposit tx)
#[error("invalid source hash")]
InvalidSourceHash,
/// Invalid mint value (for Optimism deposit tx)
#[error("invalid mint value")]
InvalidMintValue,
Copy link
Member

Choose a reason for hiding this comment

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

these are OP specific ones, I don't like this because this OP specific and should not be included here

we should either add a custom(String) or Box

Copy link
Member

Choose a reason for hiding this comment

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

would love you feedback about the discussion in the comments

@mattsse
Copy link
Member

mattsse commented Jun 12, 2024

at this point i am wondering if this is an example of non-useful type safety.

yeah this can fail for a lot for reasons, and I guess it would be more convenient to just return a message, I doubt matching these variants is very useful. but we have a lot of reasonable ones already and I'd like to keep those and instead add an Other(String) variant

@prestwich
Copy link
Member

yeah, let's move this to custom and then plan to delete the whole enum when we embed the tx envelope in the rpc response

@zobront zobront changed the title add new conversion errors required for optimism deposit tx add custom conversion error to handle additional situations (such as optimism deposit tx) Jun 13, 2024
@zobront
Copy link
Contributor Author

zobront commented Jun 13, 2024

@prestwich Updated based on conversation above, and adjusted the PR title & description to match.

@prestwich prestwich merged commit b64f434 into alloy-rs:main Jun 13, 2024
22 checks passed
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
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.

3 participants