errors.go 3.3 KB

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