Skip to content

Commit

Permalink
PRT- masking provider address when context deadline hits (#461)
Browse files Browse the repository at this point in the history
* masking provider address when context deadline hits

* fixing reading deadline error
  • Loading branch information
ranlavanet authored May 7, 2023
1 parent 7e1416a commit efa9c59
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
20 changes: 20 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31428,6 +31428,10 @@ paths:
title: >-
protobuf expected in YAML format: used "moretags" to
simplify parsing
snapshot:
type: string
format: uint64
title: snapshot id to uniquely identify snapshots
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -31566,6 +31570,10 @@ paths:
title: >-
protobuf expected in YAML format: used "moretags" to
simplify parsing
snapshot:
type: string
format: uint64
title: snapshot id to uniquely identify snapshots
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -56039,6 +56047,10 @@ definitions:
type: string
format: uint64
title: 'protobuf expected in YAML format: used "moretags" to simplify parsing'
snapshot:
type: string
format: uint64
title: snapshot id to uniquely identify snapshots
lavanet.lava.projects.ProjectKey:
type: object
properties:
Expand Down Expand Up @@ -56171,6 +56183,10 @@ definitions:
title: >-
protobuf expected in YAML format: used "moretags" to simplify
parsing
snapshot:
type: string
format: uint64
title: snapshot id to uniquely identify snapshots
lavanet.lava.projects.QueryInfoResponse:
type: object
properties:
Expand Down Expand Up @@ -56275,6 +56291,10 @@ definitions:
title: >-
protobuf expected in YAML format: used "moretags" to simplify
parsing
snapshot:
type: string
format: uint64
title: snapshot id to uniquely identify snapshots
lavanet.lava.projects.QueryParamsResponse:
type: object
properties:
Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ func (cp *GrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{},
response := msgFactory.NewMessage(methodDescriptor.GetOutputType())
err = conn.Invoke(connectCtx, "/"+nodeMessage.Path, msg, response)
if err != nil {
if connectCtx.Err() == context.DeadlineExceeded {
// Not an rpc error, return provider error without disclosing the endpoint address
return nil, "", nil, utils.LavaFormatError("Provider Failed Sending Message", context.DeadlineExceeded)
}
return nil, "", nil, utils.LavaFormatError("Invoke Failed", err, utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "Method", Value: nodeMessage.Path}, utils.Attribute{Key: "msg", Value: nodeMessage.Msg})
}

Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ func (cp *JrpcChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{},
connectCtx, cancel := cp.NodeUrl.LowerContextTimeout(ctx, relayTimeout)
defer cancel()
rpcMessage, err = rpc.CallContext(connectCtx, nodeMessage.ID, nodeMessage.Method, nodeMessage.Params)
if err != nil && connectCtx.Err() == context.DeadlineExceeded {
// Not an rpc error, return provider error without disclosing the endpoint address
return nil, "", nil, utils.LavaFormatError("Provider Failed Sending Message", context.DeadlineExceeded)
}
}

var replyMsg rpcInterfaceMessages.JsonrpcMessage
Expand Down
4 changes: 4 additions & 0 deletions protocol/chainlib/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func (rcp *RestChainProxy) SendNodeMsg(ctx context.Context, ch chan interface{},

res, err := httpClient.Do(req)
if err != nil {
if err != nil && connectCtx.Err() == context.DeadlineExceeded {
// Not an rpc error, return provider error without disclosing the endpoint address
return nil, "", nil, utils.LavaFormatError("Provider Failed Sending Message", context.DeadlineExceeded)
}
return nil, "", nil, err
}

Expand Down
8 changes: 4 additions & 4 deletions protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,15 @@ func (cp *tendermintRpcChainProxy) SendRPC(ctx context.Context, nodeMessage *rpc
defer cancel()
// perform the rpc call
rpcMessage, err = rpc.CallContext(connectCtx, nodeMessage.ID, nodeMessage.Method, nodeMessage.Params)
if err != nil && connectCtx.Err() == context.DeadlineExceeded {
// Not an rpc error, return provider error without disclosing the endpoint address
return nil, "", nil, utils.LavaFormatError("Provider Failed Sending Message", context.DeadlineExceeded)
}
}

var replyMsg *rpcInterfaceMessages.RPCResponse
// the error check here would only wrap errors not from the rpc
if err != nil {
if strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
// Not an rpc error, return provider error without disclosing the endpoint address
return nil, "", nil, utils.LavaFormatError("Failed Sending Message", context.DeadlineExceeded)
}
id, idErr := rpcInterfaceMessages.IdFromRawMessage(nodeMessage.ID)
if idErr != nil {
return nil, "", nil, utils.LavaFormatError("Failed parsing ID when getting rpc error", idErr)
Expand Down

0 comments on commit efa9c59

Please sign in to comment.