Skip to content

Commit

Permalink
Fixing returning rpc to the wrong connector (#408)
Browse files Browse the repository at this point in the history
* Fixing returning rpc to the wrong connector

* adding a cache log to verify pairing if it fails

* fixing a missing defer function
  • Loading branch information
ranlavanet authored Apr 10, 2023
1 parent 66b3ad8 commit 475e755
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions protocol/chainlib/chainproxy/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (connector *Connector) Close() {
}

func (connector *Connector) increaseNumberOfClients(ctx context.Context, numberOfFreeClients int) {
utils.LavaFormatDebug("increasing number of clients", utils.Attribute{Key: "numberOfFreeClients", Value: numberOfFreeClients})
utils.LavaFormatDebug("increasing number of clients", utils.Attribute{Key: "numberOfFreeClients", Value: numberOfFreeClients},
utils.Attribute{Key: "url", Value: connector.nodeUrl.Url})
var rpcClient *rpcclient.Client
var err error
for connectionAttempt := 0; connectionAttempt < MaximumNumberOfParallelConnectionsAttempts; connectionAttempt++ {
Expand Down Expand Up @@ -241,7 +242,8 @@ func NewGRPCConnector(ctx context.Context, nConns uint, addr string) (*GRPCConne
}

func (connector *GRPCConnector) increaseNumberOfClients(ctx context.Context, numberOfFreeClients int) {
utils.LavaFormatDebug("increasing number of clients", utils.Attribute{Key: "numberOfFreeClients", Value: numberOfFreeClients})
utils.LavaFormatDebug("increasing number of clients", utils.Attribute{Key: "numberOfFreeClients", Value: numberOfFreeClients},
utils.Attribute{Key: "url", Value: connector.addr})
var grpcClient *grpc.ClientConn
var err error
for connectionAttempt := 0; connectionAttempt < MaximumNumberOfParallelConnectionsAttempts; connectionAttempt++ {
Expand Down
6 changes: 4 additions & 2 deletions protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,16 @@ func (cp *tendermintRpcChainProxy) SendRPC(ctx context.Context, nodeMessage *rpc
if err != nil {
return nil, "", nil, err
}
// return the rpc connection to the websocket pool after the function completes
defer cp.conn.ReturnRpc(rpc)
} else {
rpc, err = cp.httpConnector.GetRpc(ctx, true)
if err != nil {
return nil, "", nil, err
}
// return the rpc connection to the http pool after the function completes
defer cp.httpConnector.ReturnRpc(rpc)
}
// return the rpc connection to the pool after the function completes
defer cp.conn.ReturnRpc(rpc)

// create variables for the rpc message and reply message
var rpcMessage *rpcclient.JsonrpcMessage
Expand Down
5 changes: 3 additions & 2 deletions protocol/statetracker/state_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@ func (psq *ProviderStateQuery) VoteEvents(ctx context.Context, latestBlock int64

func (psq *ProviderStateQuery) VerifyPairing(ctx context.Context, consumerAddress string, providerAddress string, epoch uint64, chainID string) (valid bool, index int64, err error) {
key := psq.entryKey(consumerAddress, chainID, epoch, providerAddress)

extractedResultFromCache := false
cachedInterface, found := psq.ResponsesCache.Get(VerifyPairingRespKey + key)
var verifyResponse *pairingtypes.QueryVerifyPairingResponse = nil
if found && cachedInterface != nil {
if cachedResp, ok := cachedInterface.(*pairingtypes.QueryVerifyPairingResponse); ok {
verifyResponse = cachedResp
extractedResultFromCache = true
} else {
utils.LavaFormatError("invalid cache entry - failed casting response", nil, utils.Attribute{Key: "castingType", Value: "*pairingtypes.QueryVerifyPairingResponse"}, utils.Attribute{Key: "type", Value: fmt.Sprintf("%T", cachedInterface)})
}
Expand All @@ -252,7 +253,7 @@ func (psq *ProviderStateQuery) VerifyPairing(ctx context.Context, consumerAddres
psq.ResponsesCache.SetWithTTL(VerifyPairingRespKey+key, verifyResponse, 1, DefaultTimeToLiveExpiration)
}
if !verifyResponse.Valid {
return false, 0, utils.LavaFormatError("invalid self pairing with consumer", nil, utils.Attribute{Key: "provider", Value: providerAddress}, utils.Attribute{Key: "consumer address", Value: consumerAddress}, utils.Attribute{Key: "epoch", Value: epoch})
return false, 0, utils.LavaFormatError("invalid self pairing with consumer", nil, utils.Attribute{Key: "provider", Value: providerAddress}, utils.Attribute{Key: "consumer address", Value: consumerAddress}, utils.Attribute{Key: "epoch", Value: epoch}, utils.Attribute{Key: "from_cache", Value: extractedResultFromCache})
}
return verifyResponse.Valid, verifyResponse.GetIndex(), nil
}
Expand Down

0 comments on commit 475e755

Please sign in to comment.