chore: allow queries to be routed to abci.Query (#20774)

This commit is contained in:
Marko
2024-06-25 16:11:34 +00:00
committed by GitHub
parent 5864cf82f5
commit 524a84c3ba
4 changed files with 20 additions and 18 deletions
+6 -2
View File
@@ -6,7 +6,7 @@ export COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
SIMAPP = ./simapp
SIMAPP = simapp
MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER := $(shell which docker)
@@ -49,6 +49,10 @@ ifeq (legacy,$(findstring legacy,$(COSMOS_BUILD_OPTIONS)))
build_tags += app_v1
endif
ifeq (v2,$(findstring v2,$(COSMOS_BUILD_OPTIONS)))
SIMAPP = simapp/v2
endif
# DB backend selection
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
@@ -123,7 +127,7 @@ build-linux-arm64:
GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
cd ${CURRENT_DIR}/simapp && go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
cd ${CURRENT_DIR}/${SIMAPP} && go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
+2 -4
View File
@@ -5,13 +5,11 @@ set -o nounset
set -x
ROOT=$PWD
SIMAPP_DIR="$ROOT/simapp/v2"
SIMD="$ROOT/build/simdv2"
CONFIG="${CONFIG:-$HOME/.simappv2/config}"
cd "$SIMAPP_DIR"
go build -o "$ROOT/build/simdv2" simdv2/main.go
COSMOS_BUILD_OPTIONS=v2 make build
if [ -d "$($SIMD config home)" ]; then rm -r $($SIMD config home); fi
@@ -48,4 +46,4 @@ while ! $SIMD query block --type=height 5; do
sleep 1
done
kill -9 "$SIMD_PID"
kill -9 "$SIMD_PID"
+4 -9
View File
@@ -17,6 +17,7 @@ import (
"cosmossdk.io/core/transaction"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/server/v2/appmanager"
"cosmossdk.io/server/v2/cometbft/client/grpc/cmtservice"
"cosmossdk.io/server/v2/cometbft/handlers"
"cosmossdk.io/server/v2/cometbft/mempool"
"cosmossdk.io/server/v2/cometbft/types"
@@ -26,12 +27,6 @@ import (
consensustypes "cosmossdk.io/x/consensus/types"
)
const (
QueryPathApp = "app"
QueryPathP2P = "p2p"
QueryPathStore = "store"
)
var _ abci.Application = (*Consensus[transaction.Tx])(nil)
type Consensus[T transaction.Tx] struct {
@@ -212,13 +207,13 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
var resp *abciproto.QueryResponse
switch path[0] {
case QueryPathApp:
case cmtservice.QueryPathApp:
resp, err = c.handlerQueryApp(ctx, path, req)
case QueryPathStore:
case cmtservice.QueryPathStore:
resp, err = c.handleQueryStore(path, c.store, req)
case QueryPathP2P:
case cmtservice.QueryPathP2P:
resp, err = c.handleQueryP2P(path)
default:
@@ -2,7 +2,6 @@ package cmtservice
import (
"context"
"fmt"
"strings"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
@@ -27,6 +26,12 @@ var (
_ codectypes.UnpackInterfacesMessage = &GetLatestValidatorSetResponse{}
)
const (
QueryPathApp = "app"
QueryPathP2P = "p2p"
QueryPathStore = "store"
)
type (
abciQueryFn = func(context.Context, *abci.QueryRequest) (*abci.QueryResponse, error)
@@ -265,8 +270,8 @@ func (s queryServer) ABCIQuery(ctx context.Context, req *ABCIQueryRequest) (*ABC
if path := SplitABCIQueryPath(req.Path); len(path) > 0 {
switch path[0] {
case "app", "store", "p2p", "custom": // TODO: check if we can use the ones from abci.go without having circular deps.
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("ABCI query path not yet implemented: %s", req.Path))
case QueryPathApp, QueryPathStore, QueryPathP2P:
// valid path
default:
// Otherwise, error as to prevent either valid gRPC service requests or