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

Remove lock/mutex from GRPC WASM querier. #1043

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading