Skip to content

Commit a95503a

Browse files
interop error code spec awareness and rpc_supervisor_checks metric improvements (#306)
Signed-off-by: Yashvardhan Kukreja <[email protected]>
1 parent 0cade1a commit a95503a

File tree

6 files changed

+494
-60
lines changed

6 files changed

+494
-60
lines changed

proxyd/backend.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"time"
1919

2020
sw "github.com/ethereum-optimism/infra/proxyd/pkg/avg-sliding-window"
21+
supervisorBackend "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend"
22+
supervisorTypes "github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
2123
"github.com/ethereum/go-ethereum/common"
2224
"github.com/ethereum/go-ethereum/log"
2325
"github.com/ethereum/go-ethereum/rpc"
@@ -117,6 +119,140 @@ var (
117119
ErrConsensusGetReceiptsInvalidTarget = errors.New("unsupported consensus_receipts_target")
118120
)
119121

122+
/*
123+
These adhere to the interop RPC error codes defined in the supervisor spec
124+
Ref: https://github.com/ethereum-optimism/specs/blob/41a2ea8d362ac132ad2edf7f577bd393ec8beccc/specs/interop/supervisor.md
125+
Summary:
126+
127+
-3204XX DEADLINE_EXCEEDED errors
128+
-320400 UNINITIALIZED_CHAIN_DATABASE
129+
-3205XX NOT_FOUND errors
130+
-320500 SKIPPED_DATA
131+
-320501 UNKNOWN_CHAIN
132+
-3206XX ALREADY_EXISTS errors
133+
-320600 CONFLICTING_DATA
134+
-320601 INEFFECTIVE_DATA
135+
-3209XX FAILED_PRECONDITION errors
136+
-320900 OUT_OF_ORDER
137+
-320901 AWAITING_REPLACEMENT_BLOCK
138+
-3210XX ABORTED errors
139+
-321000 ITER_STOP
140+
-3211XX OUT_OF_RANGE errors
141+
-321100 OUT_OF_SCOPE
142+
-3212XX UNIMPLEMENTED errors
143+
-321200 CANNOT_GET_PARENT_OF_FIRST_BLOCK_IN_DB
144+
-3214XX UNAVAILABLE errors
145+
-321401 FUTURE_DATA
146+
-3215XX DATA_LOSS errors
147+
-321500 MISSED_DATA
148+
-321501 DATA_CORRUPTION
149+
*/
150+
var interopRPCErrorMap = map[error]*RPCErr{
151+
supervisorTypes.ErrUninitialized: {
152+
Code: -320400,
153+
HTTPErrorCode: 400,
154+
},
155+
supervisorTypes.ErrSkipped: {
156+
Code: -320500,
157+
HTTPErrorCode: 422,
158+
},
159+
supervisorTypes.ErrUnknownChain: {
160+
Code: -320501,
161+
HTTPErrorCode: 404,
162+
},
163+
supervisorTypes.ErrConflict: {
164+
Code: -320600,
165+
HTTPErrorCode: 409,
166+
},
167+
supervisorTypes.ErrIneffective: {
168+
Code: -320601,
169+
HTTPErrorCode: 422,
170+
},
171+
supervisorTypes.ErrOutOfOrder: {
172+
Code: -320900,
173+
HTTPErrorCode: 409,
174+
},
175+
supervisorTypes.ErrAwaitReplacementBlock: {
176+
Code: -320901,
177+
HTTPErrorCode: 409,
178+
},
179+
supervisorTypes.ErrStop: {
180+
Code: -321000,
181+
HTTPErrorCode: 400,
182+
},
183+
supervisorTypes.ErrOutOfScope: {
184+
Code: -321100,
185+
HTTPErrorCode: 400,
186+
},
187+
supervisorTypes.ErrPreviousToFirst: {
188+
Code: -321200,
189+
HTTPErrorCode: 404,
190+
},
191+
supervisorTypes.ErrFuture: {
192+
Code: -321401,
193+
HTTPErrorCode: 422,
194+
},
195+
supervisorTypes.ErrNotExact: {
196+
Code: -321500,
197+
HTTPErrorCode: 404,
198+
},
199+
supervisorTypes.ErrDataCorruption: {
200+
Code: -321501,
201+
HTTPErrorCode: 422,
202+
},
203+
supervisorBackend.ErrUnexpectedMinSafetyLevel: {
204+
Code: -32602, // invalid params
205+
HTTPErrorCode: 400,
206+
},
207+
errors.New("stopped acces-list check early"): {
208+
Code: JSONRPCErrorInternal,
209+
HTTPErrorCode: 500,
210+
},
211+
errors.New("failed to read data"): {
212+
Code: -32602, // invalid params
213+
HTTPErrorCode: 400,
214+
},
215+
}
216+
217+
func ParseInteropError(err error) *RPCErr {
218+
var fallbackErr *RPCErr
219+
httpErr, isHTTPError := err.(rpc.HTTPError)
220+
if !isHTTPError {
221+
fallbackErr = &RPCErr{
222+
Code: JSONRPCErrorInternal,
223+
Message: err.Error(),
224+
HTTPErrorCode: 500,
225+
}
226+
} else {
227+
// if the underlying error is a JSON-RPC error, overwrite it with the inherent error message body
228+
var rpcErrJson rpcResJSON
229+
unmarshalErr := json.Unmarshal(httpErr.Body, &rpcErrJson)
230+
if unmarshalErr != nil {
231+
fallbackErr = ErrInvalidParams(string(httpErr.Body))
232+
fallbackErr.HTTPErrorCode = httpErr.StatusCode
233+
} else {
234+
fallbackErr = &RPCErr{
235+
Code: rpcErrJson.Error.Code,
236+
Message: rpcErrJson.Error.Message,
237+
Data: rpcErrJson.Error.Data,
238+
HTTPErrorCode: httpErr.StatusCode,
239+
}
240+
241+
err = fmt.Errorf(rpcErrJson.Error.Message)
242+
}
243+
}
244+
245+
errStr := err.Error()
246+
for errSubStr, errCodes := range interopRPCErrorMap {
247+
if strings.Contains(errStr, errSubStr.Error()) {
248+
interopParsedErr := errCodes.Clone()
249+
interopParsedErr.Message = errStr
250+
return interopParsedErr
251+
}
252+
}
253+
return fallbackErr
254+
}
255+
120256
func ErrInvalidRequest(msg string) *RPCErr {
121257
return &RPCErr{
122258
Code: -32600,

proxyd/go.mod

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/BurntSushi/toml v1.5.0
99
github.com/alicebob/miniredis v2.5.0+incompatible
1010
github.com/emirpasic/gods v1.18.1
11+
github.com/ethereum-optimism/optimism v1.13.3-0.20250506125223-182c0424f6dc
1112
github.com/ethereum/go-ethereum v1.15.3
1213
github.com/go-redsync/redsync/v4 v4.10.0
1314
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb
@@ -28,53 +29,115 @@ require (
2829
replace github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101503.4-rc.1
2930

3031
require (
32+
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
3133
github.com/Microsoft/go-winio v0.6.2 // indirect
3234
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
3335
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 // indirect
34-
github.com/allegro/bigcache v1.2.1 // indirect
36+
github.com/andybalholm/brotli v1.1.0 // indirect
3537
github.com/beorn7/perks v1.0.1 // indirect
3638
github.com/bits-and-blooms/bitset v1.20.0 // indirect
39+
github.com/btcsuite/btcd v0.24.2 // indirect
40+
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
41+
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
42+
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
3743
github.com/cespare/xxhash/v2 v2.3.0 // indirect
44+
github.com/cockroachdb/errors v1.11.3 // indirect
45+
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
46+
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
3847
github.com/cockroachdb/pebble v1.1.5 // indirect
48+
github.com/cockroachdb/redact v1.1.5 // indirect
49+
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
3950
github.com/consensys/bavard v0.1.27 // indirect
4051
github.com/consensys/gnark-crypto v0.16.0 // indirect
52+
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
4153
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
4254
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
4355
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4456
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
4557
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
4658
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
59+
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 // indirect
4760
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
4861
github.com/ethereum/go-verkle v0.2.2 // indirect
62+
github.com/fsnotify/fsnotify v1.9.0 // indirect
63+
github.com/getsentry/sentry-go v0.27.0 // indirect
4964
github.com/go-ole/go-ole v1.3.0 // indirect
5065
github.com/gofrs/flock v0.8.1 // indirect
66+
github.com/gogo/protobuf v1.3.2 // indirect
67+
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
5168
github.com/gomodule/redigo v1.8.9 // indirect
69+
github.com/google/uuid v1.6.0 // indirect
5270
github.com/hashicorp/errwrap v1.1.0 // indirect
71+
github.com/hashicorp/go-bexpr v0.1.11 // indirect
5372
github.com/hashicorp/go-multierror v1.1.1 // indirect
73+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
74+
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
5475
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
5576
github.com/holiman/uint256 v1.3.2 // indirect
77+
github.com/huin/goupnp v1.3.0 // indirect
78+
github.com/ipfs/go-cid v0.4.1 // indirect
79+
github.com/ipfs/go-datastore v0.6.0 // indirect
80+
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
81+
github.com/jbenet/goprocess v0.1.4 // indirect
5682
github.com/klauspost/compress v1.18.0 // indirect
83+
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
84+
github.com/kr/pretty v0.3.1 // indirect
85+
github.com/kr/text v0.2.0 // indirect
86+
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
87+
github.com/libp2p/go-libp2p v0.36.2 // indirect
88+
github.com/mattn/go-colorable v0.1.13 // indirect
89+
github.com/mattn/go-isatty v0.0.20 // indirect
5790
github.com/mattn/go-runewidth v0.0.16 // indirect
91+
github.com/minio/sha256-simd v1.0.1 // indirect
92+
github.com/mitchellh/mapstructure v1.5.0 // indirect
93+
github.com/mitchellh/pointerstructure v1.2.1 // indirect
5894
github.com/mmcloughlin/addchain v0.4.0 // indirect
95+
github.com/mr-tron/base58 v1.2.0 // indirect
96+
github.com/multiformats/go-base32 v0.1.0 // indirect
97+
github.com/multiformats/go-base36 v0.2.0 // indirect
98+
github.com/multiformats/go-multiaddr v0.14.0 // indirect
99+
github.com/multiformats/go-multibase v0.2.0 // indirect
100+
github.com/multiformats/go-multicodec v0.9.0 // indirect
101+
github.com/multiformats/go-multihash v0.2.3 // indirect
102+
github.com/multiformats/go-multistream v0.5.0 // indirect
103+
github.com/multiformats/go-varint v0.0.7 // indirect
59104
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
60105
github.com/naoina/go-stringutil v0.1.0 // indirect
61106
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 // indirect
62107
github.com/olekukonko/tablewriter v0.0.5 // indirect
108+
github.com/pion/dtls/v2 v2.2.12 // indirect
109+
github.com/pion/logging v0.2.2 // indirect
110+
github.com/pion/stun/v2 v2.0.0 // indirect
111+
github.com/pion/transport/v2 v2.2.10 // indirect
112+
github.com/pion/transport/v3 v3.0.7 // indirect
63113
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
64114
github.com/prometheus/client_model v0.6.2 // indirect
65115
github.com/prometheus/common v0.62.0 // indirect
66116
github.com/prometheus/procfs v0.15.1 // indirect
67117
github.com/rivo/uniseg v0.4.7 // indirect
68118
github.com/rogpeppe/go-internal v1.13.1 // indirect
119+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
69120
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
121+
github.com/spaolacci/murmur3 v1.1.0 // indirect
122+
github.com/stretchr/objx v0.5.2 // indirect
70123
github.com/supranational/blst v0.3.14 // indirect
71124
github.com/tklauser/go-sysconf v0.3.12 // indirect
72125
github.com/tklauser/numcpus v0.6.1 // indirect
126+
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
127+
github.com/urfave/cli/v2 v2.27.6 // indirect
128+
github.com/wlynxg/anet v0.0.4 // indirect
129+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
73130
github.com/yuin/gopher-lua v1.1.0 // indirect
74131
github.com/yusufpapurcu/wmi v1.2.3 // indirect
75132
golang.org/x/crypto v0.32.0 // indirect
76133
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
134+
golang.org/x/net v0.34.0 // indirect
77135
golang.org/x/sys v0.30.0 // indirect
136+
golang.org/x/term v0.28.0 // indirect
137+
golang.org/x/text v0.21.0 // indirect
138+
golang.org/x/time v0.10.0 // indirect
78139
google.golang.org/protobuf v1.36.6 // indirect
140+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
141+
lukechampine.com/blake3 v1.3.0 // indirect
79142
rsc.io/tmplfunc v0.0.3 // indirect
80143
)

0 commit comments

Comments
 (0)