Skip to content
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

Merged
merged 15 commits into from
Feb 18, 2025

Conversation

rezbera
Copy link
Contributor

@rezbera rezbera commented Feb 17, 2025

  • For some reason, in the error case we were returning req.Txs. That is the only time it is used and from what I can tell - it's always empty. This minor change makes it more clear that we do not use req.Txs

  • Our error handling from the RPC was also borked. We did not check status codes and immediately tried to unmarshal which mean that any unmarshalling errors masked the real issue which was the status code. This occurred most frequently for unauthorized errors. There was also bugs with the handling of Unauthorized Errors

@rezbera rezbera requested a review from a team as a code owner February 17, 2025 19:05
@rezbera rezbera enabled auto-merge (squash) February 17, 2025 19:05
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.

Project coverage is 32.31%. Comparing base (5e3edfa) to head (671b18e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
execution/client/errors.go 0.00% 10 Missing ⚠️
execution/client/ethclient/rpc/client.go 0.00% 7 Missing ⚠️
config/config.go 0.00% 4 Missing ⚠️
execution/client/metrics.go 0.00% 3 Missing ⚠️
primitives/net/http/errors.go 0.00% 3 Missing ⚠️
consensus/cometbft/service/encoding/encoding.go 0.00% 2 Missing ⚠️
consensus/cometbft/service/prepare_proposal.go 0.00% 1 Missing ⚠️
execution/client/client.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2517   +/-   ##
=======================================
  Coverage   32.30%   32.31%           
=======================================
  Files         350      350           
  Lines       15674    15672    -2     
  Branches       20       20           
=======================================
  Hits         5064     5064           
+ Misses      10247    10245    -2     
  Partials      363      363           
Files with missing lines Coverage Δ
primitives/net/json-rpc/errors.go 0.00% <ø> (ø)
consensus/cometbft/service/prepare_proposal.go 0.00% <0.00%> (ø)
execution/client/client.go 0.00% <0.00%> (ø)
consensus/cometbft/service/encoding/encoding.go 0.00% <0.00%> (ø)
execution/client/metrics.go 0.00% <0.00%> (ø)
primitives/net/http/errors.go 0.00% <0.00%> (ø)
config/config.go 0.00% <0.00%> (ø)
execution/client/ethclient/rpc/client.go 0.00% <0.00%> (ø)
execution/client/errors.go 0.00% <0.00%> (ø)

@rezbera rezbera marked this pull request as draft February 17, 2025 19:09
auto-merge was automatically disabled February 17, 2025 19:09

Pull request was converted to draft

@rezbera rezbera changed the title chore(prepare-proposal): Ignore requests Txs fix(errors): Ignore requests Txs + RPC Error Handlings Fixes Feb 17, 2025
Comment on lines -76 to -78
if jsonrpc.IsUnauthorizedError(e) {
return http.ErrUnauthorized
}
Copy link
Contributor Author

@rezbera rezbera Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was borked. It attempt to use e as the input for IsUnauthorizedError which is nil given that the casting failed and hence ok == false. This meant that IsUnauthorizedError always returned false.

Comment on lines +188 to +191
case http.StatusOK:
// OK: just proceed (no return)
case http.StatusUnauthorized:
return nil, beaconhttp.ErrUnauthorized
Copy link
Contributor Author

@rezbera rezbera Feb 17, 2025

Choose a reason for hiding this comment

The 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.

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 " +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

Comment on lines -45 to -49
// 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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unusued

@@ -77,7 +77,7 @@ func (s *Service) prepareProposal(
"time", req.Time,
"err", err,
)
return &cmtabci.PrepareProposalResponse{Txs: req.Txs}, nil
return &cmtabci.PrepareProposalResponse{Txs: [][]byte{}}, nil
Copy link
Contributor Author

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

Copy link
Collaborator

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:

  • PrepareProposal passes to the app the transactions CometBFT knows about, that are available in CometBFT mempool (our CometBFT mempool is set to zero, so no txs)
  • The app is free to reorder, replace and add any transaction it wants. CometBFT will use the transactions returned in PrepareProposalResponse to prepare the block
  • now my guess is that default behaviour for the app, in case of errors is to let CometBFT build a block with whatever txs it has (mempool txs are verified via CheckTx anyhow)

It does not currently matter for us, so I am not opposed to this change.
I would only ask @sbudella-gco to confirm my story

e, ok := err.(Error)
if !ok {
if strings.Contains(
e.Error(), "401 Unauthorized",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string comparisons is bad

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems again a copy of Prysm

return http.ErrUnauthorized
}
var e jsonrpc.Error
ok := errors.As(err, &e)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
//nolint:errorlint // by design.
t, ok := e.(TimeoutError)
var t TimeoutError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rezbera rezbera marked this pull request as ready for review February 17, 2025 23:55
Comment on lines +79 to +88
// GetPayloadBuilder returns the block store configuration.
func (c Config) GetPayloadBuilder() *builder.Config {
return &c.PayloadBuilder
}

// GetBlockStoreService returns the block store configuration.
func (c Config) GetBlockStoreService() *blockstore.Config {
return &c.BlockStoreService
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these for consistency with other Getters - not directly related to the goal of this PR but useful in a future one

@@ -58,16 +58,11 @@ func ExtractBlobsAndBlockFromRequest(
// UnmarshalBeaconBlockFromABCIRequest extracts a beacon block from an ABCI
// request.
func UnmarshalBeaconBlockFromABCIRequest(
req ABCIRequest,
txs [][]byte,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a tangential change not relevant to this PR. However it makes this function easier to test.
It also removes the need for duplicate nil checks on req

Copy link
Collaborator

@abi87 abi87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending confirmation that returning no txs makes no difference for us currently.

Copy link
Contributor

@fridrik01 fridrik01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rezbera
Copy link
Contributor Author

rezbera commented Feb 18, 2025

LGTM pending confirmation that returning no txs makes no difference for us currently.

Confirmed

@rezbera rezbera merged commit 9af4d0d into main Feb 18, 2025
19 checks passed
@rezbera rezbera deleted the minor-cleanup-prepare branch February 18, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants