github.com/theQRL/go-zond@v0.2.1/beacon/engine/errors.go (about) 1 // Copyright 2022 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package engine 18 19 import ( 20 "github.com/theQRL/go-zond/rpc" 21 ) 22 23 // EngineAPIError is a standardized error message between consensus and execution 24 // clients, also containing any custom error message Gzond might include. 25 type EngineAPIError struct { 26 code int 27 msg string 28 err error 29 } 30 31 func (e *EngineAPIError) ErrorCode() int { return e.code } 32 func (e *EngineAPIError) Error() string { return e.msg } 33 func (e *EngineAPIError) ErrorData() interface{} { 34 if e.err == nil { 35 return nil 36 } 37 return struct { 38 Error string `json:"err"` 39 }{e.err.Error()} 40 } 41 42 // With returns a copy of the error with a new embedded custom data field. 43 func (e *EngineAPIError) With(err error) *EngineAPIError { 44 return &EngineAPIError{ 45 code: e.code, 46 msg: e.msg, 47 err: err, 48 } 49 } 50 51 var ( 52 _ rpc.Error = new(EngineAPIError) 53 _ rpc.DataError = new(EngineAPIError) 54 ) 55 56 var ( 57 // VALID is returned by the engine API in the following calls: 58 // - newPayloadV1: if the payload was already known or was just validated and executed 59 // - forkchoiceUpdateV1: if the chain accepted the reorg (might ignore if it's stale) 60 VALID = "VALID" 61 62 // INVALID is returned by the engine API in the following calls: 63 // - newPayloadV1: if the payload failed to execute on top of the local chain 64 // - forkchoiceUpdateV1: if the new head is unknown, pre-merge, or reorg to it fails 65 INVALID = "INVALID" 66 67 // SYNCING is returned by the engine API in the following calls: 68 // - newPayloadV1: if the payload was accepted on top of an active sync 69 // - forkchoiceUpdateV1: if the new head was seen before, but not part of the chain 70 SYNCING = "SYNCING" 71 72 // ACCEPTED is returned by the engine API in the following calls: 73 // - newPayloadV1: if the payload was accepted, but not processed (side chain) 74 ACCEPTED = "ACCEPTED" 75 76 GenericServerError = &EngineAPIError{code: -32000, msg: "Server error"} 77 UnknownPayload = &EngineAPIError{code: -38001, msg: "Unknown payload"} 78 InvalidForkChoiceState = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"} 79 InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"} 80 TooLargeRequest = &EngineAPIError{code: -38004, msg: "Too large request"} 81 InvalidParams = &EngineAPIError{code: -32602, msg: "Invalid parameters"} 82 UnsupportedFork = &EngineAPIError{code: -38005, msg: "Unsupported fork"} 83 84 STATUS_INVALID = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil} 85 STATUS_SYNCING = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: SYNCING}, PayloadID: nil} 86 )