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

internal/ethapi: expose raw error data #30659

Closed

Conversation

rjl493456442
Copy link
Member

Alternative approach for #30653

@rjl493456442
Copy link
Member Author

@fjl @MariusVanDerWijden Please take a look

@Confucian-e
Copy link

Please check PR #30653 first

@MariusVanDerWijden
Copy link
Member

WDYT about this? @rjl493456442 @Confucian-e

diff --git a/internal/ethapi/errors.go b/internal/ethapi/errors.go
index ae38061234..272d427c1f 100644
--- a/internal/ethapi/errors.go
+++ b/internal/ethapi/errors.go
@@ -29,10 +29,16 @@ import (
 // revertError is an API error that encompasses an EVM revert with JSON error
 // code and a binary data blob.
 type revertError struct {
-       error
        reason string // revert reason hex encoded
 }
 
+func (e *revertError) Error() string {
+       if e.reason != "" {
+               return fmt.Sprintf("%s: %v", vm.ErrExecutionReverted, e.reason)
+       }
+       return vm.ErrExecutionReverted.Error()
+}
+
 // ErrorCode returns the JSON error code for a revert.
 // See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal
 func (e *revertError) ErrorCode() int {
@@ -46,15 +52,12 @@ func (e *revertError) ErrorData() interface{} {
 
 // newRevertError creates a revertError instance with the provided revert data.
 func newRevertError(revert []byte) *revertError {
-       err := vm.ErrExecutionReverted
-
-       reason, errUnpack := abi.UnpackRevert(revert)
-       if errUnpack == nil {
-               err = fmt.Errorf("%w: %v", vm.ErrExecutionReverted, reason)
+       reason := hexutil.Encode(revert)
+       if r, errUnpack := abi.UnpackRevert(revert); errUnpack == nil {
+               reason = r
        }
        return &revertError{
-               error:  err,
-               reason: hexutil.Encode(revert),
+               reason: reason,
        }
 }

@rjl493456442
Copy link
Member Author

@MariusVanDerWijden sgtm and feel free to push the changes!

@Confucian-e
Copy link

Maybe you could read this: #30653 (comment)

@rjl493456442
Copy link
Member Author

@Confucian-e I do see the point you raised.

However, rpc is a very general package and can even be used as a library for other projects.
Specializing the revert error in rpc is quite hacky and I don't think we should go with this direction.

I think we have to wait until the community gradually upgrade their infra to new version.

@Confucian-e
Copy link

@Confucian-e I do see the point you raised.

However, rpc is a very general package and can even be used as a library for other projects. Specializing the revert error in rpc is quite hacky and I don't think we should go with this direction.

I think we have to wait until the community gradually upgrade their infra to new version.

Okay, I respect your opinion.

@fjl
Copy link
Contributor

fjl commented Oct 24, 2024

I think we should not expose the revert data in error messages. Doing so will only increase the incentive to resort to error message parsing. You can see what will happen down that path in the example of this spec issue: ethereum/execution-apis#463

Since the revert reason is returned by Geth with a dedicated error code, we should just provide a better way of extracting it on the client side. Here is a PR to do that: #30669

@fjl fjl closed this Oct 24, 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.

4 participants