Skip to content

Commit

Permalink
Minor improvements in error handling & logging (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina authored Nov 9, 2023
1 parent 28e74cf commit de3431b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions decode/evm_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ func (r *EVMRPCRequestEnvelope) ExtractBlockNumberFromEVMRPCRequest(ctx context.
}
// handle cacheable by block hash
if MethodHasBlockHashParam(r.Method) {
return lookupBlockNumberFromHashParam(ctx, blockGetter, r.Method, r.Params)
blockNumber, err := lookupBlockNumberFromHashParam(ctx, blockGetter, r.Method, r.Params)
if err != nil {
return 0, fmt.Errorf("can't lookup block number from hash param: %v", err)
}

return blockNumber, nil
}
// handle unable to cached
return 0, ErrUncachaebleByBlockNumberEthRequest
Expand All @@ -291,7 +296,7 @@ func lookupBlockNumberFromHashParam(ctx context.Context, blockGetter EVMBlockGet

header, err := blockGetter.HeaderByHash(ctx, common.HexToHash(blockHash))
if err != nil {
return 0, err
return 0, fmt.Errorf("can't get header by %v block hash: %v", blockHash, err)
}

return header.Number.Int64(), nil
Expand Down
3 changes: 2 additions & 1 deletion service/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ func createAfterProxyFinalizer(service *ProxyService, config config.Config) http
if err != nil {
service.ServiceLogger.
Error().
Err(err).
Str("method", decodedRequestBody.Method).
Msg(fmt.Sprintf("error %s parsing block number from request %+v", err, decodedRequestBody))
Msg(fmt.Sprintf("can't parse block number from request %+v", decodedRequestBody))

blockNumber = nil
} else {
Expand Down

0 comments on commit de3431b

Please sign in to comment.