github.com/theQRL/go-zond@v0.1.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/common"
    21  	"github.com/theQRL/go-zond/rpc"
    22  )
    23  
    24  // EngineAPIError is a standardized error message between consensus and execution
    25  // clients, also containing any custom error message Geth might include.
    26  type EngineAPIError struct {
    27  	code int
    28  	msg  string
    29  	err  error
    30  }
    31  
    32  func (e *EngineAPIError) ErrorCode() int { return e.code }
    33  func (e *EngineAPIError) Error() string  { return e.msg }
    34  func (e *EngineAPIError) ErrorData() interface{} {
    35  	if e.err == nil {
    36  		return nil
    37  	}
    38  	return struct {
    39  		Error string `json:"err"`
    40  	}{e.err.Error()}
    41  }
    42  
    43  // With returns a copy of the error with a new embedded custom data field.
    44  func (e *EngineAPIError) With(err error) *EngineAPIError {
    45  	return &EngineAPIError{
    46  		code: e.code,
    47  		msg:  e.msg,
    48  		err:  err,
    49  	}
    50  }
    51  
    52  var (
    53  	_ rpc.Error     = new(EngineAPIError)
    54  	_ rpc.DataError = new(EngineAPIError)
    55  )
    56  
    57  var (
    58  	// VALID is returned by the engine API in the following calls:
    59  	//   - newPayloadV1:       if the payload was already known or was just validated and executed
    60  	//   - forkchoiceUpdateV1: if the chain accepted the reorg (might ignore if it's stale)
    61  	VALID = "VALID"
    62  
    63  	// INVALID is returned by the engine API in the following calls:
    64  	//   - newPayloadV1:       if the payload failed to execute on top of the local chain
    65  	//   - forkchoiceUpdateV1: if the new head is unknown, pre-merge, or reorg to it fails
    66  	INVALID = "INVALID"
    67  
    68  	// SYNCING is returned by the engine API in the following calls:
    69  	//   - newPayloadV1:       if the payload was accepted on top of an active sync
    70  	//   - forkchoiceUpdateV1: if the new head was seen before, but not part of the chain
    71  	SYNCING = "SYNCING"
    72  
    73  	// ACCEPTED is returned by the engine API in the following calls:
    74  	//   - newPayloadV1: if the payload was accepted, but not processed (side chain)
    75  	ACCEPTED = "ACCEPTED"
    76  
    77  	GenericServerError       = &EngineAPIError{code: -32000, msg: "Server error"}
    78  	UnknownPayload           = &EngineAPIError{code: -38001, msg: "Unknown payload"}
    79  	InvalidForkChoiceState   = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"}
    80  	InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"}
    81  	TooLargeRequest          = &EngineAPIError{code: -38004, msg: "Too large request"}
    82  	InvalidParams            = &EngineAPIError{code: -32602, msg: "Invalid parameters"}
    83  	UnsupportedFork          = &EngineAPIError{code: -38005, msg: "Unsupported fork"}
    84  
    85  	STATUS_INVALID         = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil}
    86  	STATUS_SYNCING         = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: SYNCING}, PayloadID: nil}
    87  	INVALID_TERMINAL_BLOCK = PayloadStatusV1{Status: INVALID, LatestValidHash: &common.Hash{}}
    88  )