-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(errors): Ignore requests Txs + RPC Error Handlings Fixes #2517
Changes from 9 commits
ea8dbee
0b6697c
51813e5
2d8a8b4
88f1341
846b634
f3bdaab
84ff5f2
554cb3c
606da80
a2d7879
13c3157
c2f63d9
8724a25
671b18e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,26 +27,13 @@ import ( | |
jsonrpc "github.com/berachain/beacon-kit/primitives/net/json-rpc" | ||
) | ||
|
||
// ErrUnauthenticatedConnection indicates that the connection is not | ||
// authenticated. | ||
const ( | ||
UnauthenticatedConnectionErrorStr = `could not verify execution chain ID as your | ||
connection is not authenticated. If connecting to your execution client via HTTP, you | ||
will need to set up JWT authentication...` | ||
|
||
AuthErrMsg = "HTTP authentication to your execution client " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
"is not working. Please ensure you are setting a correct " + | ||
"value for the JWT secret path" + | ||
"is set correctly, or use an IPC " + | ||
"connection if on the same machine." | ||
) | ||
|
||
var ( | ||
// ErrNotStarted indicates that the execution client is not started. | ||
ErrNotStarted = errors.New("engine client is not started") | ||
|
||
// ErrFailedToRefreshJWT indicates that the JWT could not be refreshed. | ||
ErrFailedToRefreshJWT = errors.New("failed to refresh auth token") | ||
Comment on lines
-45
to
-49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unusued |
||
|
||
// ErrMismatchedEth1ChainID is returned when the chainID does not | ||
// match the expected chain ID. | ||
|
@@ -67,15 +54,14 @@ func (s *EngineClient) handleRPCError( | |
s.metrics.incrementHTTPTimeoutCounter() | ||
return http.ErrTimeout | ||
} | ||
|
||
// Check for authorization errors | ||
if errors.Is(err, http.ErrUnauthorized) { | ||
return err | ||
} | ||
// Check for connection errors. | ||
// | ||
//nolint:errorlint // from prysm. | ||
e, ok := err.(jsonrpc.Error) | ||
if !ok { | ||
if jsonrpc.IsUnauthorizedError(e) { | ||
return http.ErrUnauthorized | ||
} | ||
Comment on lines
-76
to
-78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was borked. It attempt to use |
||
var e jsonrpc.Error | ||
ok := errors.As(err, &e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if !ok || e == nil { | ||
return errors.Wrapf( | ||
err, | ||
"got an unexpected server error in JSON-RPC response "+ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,14 @@ package rpc | |
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"sync" | ||
"time" | ||
|
||
"github.com/berachain/beacon-kit/primitives/encoding/json" | ||
beaconhttp "github.com/berachain/beacon-kit/primitives/net/http" | ||
"github.com/berachain/beacon-kit/primitives/net/jwt" | ||
) | ||
|
||
|
@@ -182,6 +184,16 @@ func (rpc *client) callRaw( | |
return nil, err | ||
} | ||
|
||
switch response.StatusCode { | ||
case http.StatusOK: | ||
// OK: just proceed (no return) | ||
case http.StatusUnauthorized: | ||
return nil, beaconhttp.ErrUnauthorized | ||
Comment on lines
+188
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than attempting to do string comparisons as before - which is extremely flakey as different ELs have slightly different strings, we just check the status. We do this before we unmarshal as the unmarshalling assumed a success response. |
||
default: | ||
// Return a default error | ||
return nil, fmt.Errorf("unexpected status code %d: %s", response.StatusCode, string(data)) | ||
} | ||
|
||
resp := new(Response) | ||
if err = json.Unmarshal(data, resp); err != nil { | ||
return nil, err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,6 @@ | |
package jsonrpc | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/berachain/beacon-kit/errors" | ||
) | ||
|
||
|
@@ -88,21 +86,3 @@ var ( | |
"an error occurred on the server while parsing the JSON text (code: -32700)", | ||
) | ||
) | ||
|
||
// IsUnauthorizedError defines an interface for unauthorized errors. | ||
func IsUnauthorizedError(err error) bool { | ||
if err == nil { | ||
return false | ||
} | ||
|
||
//nolint:errorlint // its'ok. | ||
e, ok := err.(Error) | ||
if !ok { | ||
if strings.Contains( | ||
e.Error(), "401 Unauthorized", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string comparisons is bad There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems again a copy of Prysm |
||
) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be explicit in the fail case here rather than what we were doing before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think strictly speaking this is a different behaviour, but it does not matter in our case. IIUC:
PrepareProposalResponse
to prepare the blockIt does not currently matter for us, so I am not opposed to this change.
I would only ask @sbudella-gco to confirm my story