Skip to content

Commit

Permalink
Remove lock/mutex from GRPC WASM querier. (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil authored Dec 9, 2024
1 parent 4248f97 commit 7e66c81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 0 additions & 5 deletions x/wasm/handler/query_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"fmt"
"sync"

msgv1 "cosmossdk.io/api/cosmos/msg/v1"
queryv1 "cosmossdk.io/api/cosmos/query/v1"
Expand All @@ -25,7 +24,6 @@ type GRPCQuerier struct {
codec codec.Codec
// map[query proto URL]proto response type
acceptedQueries map[string]func() gogoproto.Message
mu sync.Mutex
}

// NewGRPCQuerier returns a new instance of GRPCQuerier.
Expand All @@ -40,7 +38,6 @@ func NewGRPCQuerier(gRPCQueryRouter *baseapp.GRPCQueryRouter, codec codec.Codec)
gRPCQueryRouter: gRPCQueryRouter,
codec: codec,
acceptedQueries: acceptedQueries,
mu: sync.Mutex{},
}
}

Expand All @@ -59,12 +56,10 @@ func (q *GRPCQuerier) Query(ctx sdk.Context, request *wasmvmtypes.GrpcQuery) (go
return nil, wasmvmtypes.UnsupportedRequest{Kind: fmt.Sprintf("No route to query '%s'", request.Path)}
}

q.mu.Lock()
res, err := handler(ctx, &abci.RequestQuery{
Data: request.Data,
Path: request.Path,
})
q.mu.Unlock()
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions x/wasm/handler/query_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/CoreumFoundation/coreum/v5/x/wasm/handler"
)

func TestGRPCQuerier_Query(t *testing.T) {
func TestGRPCQuerier(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

Expand Down Expand Up @@ -49,13 +49,15 @@ func TestGRPCQuerier_Query(t *testing.T) {

eg, _ := errgroup.WithContext(ctx)
for range 1000 {
// rebuild the ctx
routineSDKCtx := testApp.BaseApp.NewContext(false)
eg.Go(func() error {
wasmGrpcReq := &wasmvmtypes.GrpcQuery{
Data: wasmGrpcData,
// url which corresponds query token
Path: "/coreum.asset.ft.v1.Query/Token",
}
wasmGrpcRes, err := q.Query(sdkCtx, wasmGrpcReq)
wasmGrpcRes, err := q.Query(routineSDKCtx, wasmGrpcReq)
if err != nil {
return err
}
Expand Down

0 comments on commit 7e66c81

Please sign in to comment.