Skip to content

Commit a2eb996

Browse files
authored
internal/ethapi: fix error code for revert in simulate (#19006)
The error code for revert should be consistent with eth_call and be 3. ethereum/execution-apis#748
1 parent cc4fe68 commit a2eb996

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

rpc/errors.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ const (
4848
ErrCodeClientLimitExceeded = -38026
4949
ErrCodeInternalError = -32603
5050
ErrCodeInvalidParams = -32602
51-
ErrCodeReverted = -32000
51+
ErrCodeDefault = -32000
5252
ErrCodeVMError = -32015
5353

5454
ErrCodeTxSyncTimeout = 4
5555
)
5656

57-
const defaultErrorCode = ErrCodeReverted
58-
5957
type methodNotFoundError struct{ method string }
6058

6159
func (e *methodNotFoundError) ErrorCode() int { return -32601 }

rpc/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func HandleError(err error, stream jsonstream.Stream) {
9797
if ok {
9898
stream.WriteInt(ec.ErrorCode())
9999
} else {
100-
stream.WriteInt(defaultErrorCode)
100+
stream.WriteInt(ErrCodeDefault)
101101
}
102102
stream.WriteMore()
103103
stream.WriteObjectField("message")

rpc/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func NewJsonErrorFromErr(err error) any {
151151
}
152152

153153
func newJsonError(err error) *jsonError {
154-
jsonErr := &jsonError{Code: defaultErrorCode, Message: err.Error()}
154+
jsonErr := &jsonError{Code: ErrCodeDefault, Message: err.Error()}
155155
var ec Error
156156
ok := errors.As(err, &ec)
157157
if ok {

rpc/jsonrpc/eth_simulation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ func (s *simulator) simulateCall(
739739
if errors.Is(result.Err, vm.ErrExecutionReverted) {
740740
// If the result contains a revert reason, try to unpack and return it.
741741
revertError := ethapi.NewRevertError(result)
742-
callResult.Error = rpc.NewJsonError(rpc.ErrCodeReverted, revertError.Error(), revertError.ErrorData().(string))
742+
callResult.Error = rpc.NewJsonError(revertError.ErrorCode(), revertError.Error(), revertError.ErrorData().(string))
743743
} else {
744744
// Otherwise, we just capture the error message.
745745
callResult.Error = rpc.NewJsonError(rpc.ErrCodeVMError, result.Err.Error(), nil)

0 commit comments

Comments
 (0)