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

fix(server/v2/comebft): wire missing services + fix simulation (backport #21964) #22555

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
981 changes: 981 additions & 0 deletions api/cosmos/base/node/v2/query.pulsar.go

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions api/cosmos/base/node/v2/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions client/grpc/cmtservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ type (

// NewQueryServer creates a new CometBFT query server.
func NewQueryServer(
clientCtx CometRPC,
cometRPC CometRPC,
queryFn abciQueryFn,
consensusAddressCodec address.Codec,
) ServiceServer {
return queryServer{
rpc: clientCtx,
rpc: cometRPC,
queryFn: queryFn,
consensusCodec: consensusAddressCodec,
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s queryServer) ABCIQuery(ctx context.Context, req *ABCIQueryRequest) (*ABC
func RegisterTendermintService(
clientCtx client.Context,
server gogogrpc.Server,
iRegistry codectypes.InterfaceRegistry,
_ codectypes.InterfaceRegistry,
queryFn abciQueryFn,
) {
node, err := clientCtx.GetNode()
Expand Down
22 changes: 22 additions & 0 deletions proto/cosmos/base/node/v2/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package cosmos.base.node.v2;

import "google/api/annotations.proto";

option go_package = "cosmossdk.io/server/v2/api/grpc/nodeservice";

// Service defines the gRPC querier service for node related queries.
service Service {
// Config queries for the operator configuration.
rpc Config(ConfigRequest) returns (ConfigResponse) {
option (google.api.http).get = "/cosmos/base/node/v2/config";
}
}

// ConfigRequest defines the request structure for the Config gRPC query.
message ConfigRequest {}

// ConfigResponse defines the response structure for the Config gRPC query.
message ConfigResponse {
string minimum_gas_price = 1;
}
68 changes: 58 additions & 10 deletions server/v2/cometbft/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
gogoproto "github.com/cosmos/gogoproto/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
Expand All @@ -27,7 +30,6 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/schema/appdata"
"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"
Expand All @@ -37,13 +39,18 @@ 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 {
logger log.Logger
appName, version string
app appmanager.AppManager[T]
appCloser func() error
txCodec transaction.Codec[T]
store types.Store
streaming streaming.Manager
Expand Down Expand Up @@ -78,7 +85,6 @@ func NewConsensus[T transaction.Tx](
logger log.Logger,
appName string,
app appmanager.AppManager[T],
appCloser func() error,
mp mempool.Mempool[T],
indexedEvents map[string]struct{},
queryHandlersMap map[string]appmodulev2.Handler,
Expand All @@ -91,7 +97,6 @@ func NewConsensus[T transaction.Tx](
appName: appName,
version: getCometBFTServerVersion(),
app: app,
appCloser: appCloser,
cfg: cfg,
store: store,
logger: logger,
Expand Down Expand Up @@ -221,17 +226,17 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (
}

switch path[0] {
case cmtservice.QueryPathApp:
case QueryPathApp:
resp, err = c.handlerQueryApp(ctx, path, req)

case cmtservice.QueryPathStore:
resp, err = c.handleQueryStore(path, c.store, req)
case QueryPathStore:
resp, err = c.handleQueryStore(path, req)

case cmtservice.QueryPathP2P:
case QueryPathP2P:
resp, err = c.handleQueryP2P(path)

default:
resp = QueryResult(errorsmod.Wrap(cometerrors.ErrUnknownRequest, "unknown query path"), c.cfg.AppTomlConfig.Trace)
resp = QueryResult(errorsmod.Wrapf(cometerrors.ErrUnknownRequest, "unknown query path %s", req.Path), c.cfg.AppTomlConfig.Trace)
}

if err != nil {
Expand Down Expand Up @@ -267,6 +272,50 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
handlerFullName = string(md.Input().FullName())
}

// special case for simulation as it is an external gRPC registered on the grpc server component
// and not on the app itself, so it won't pass the router afterwards.
if req.Path == "/cosmos.tx.v1beta1.Service/Simulate" {
simulateRequest := &txtypes.SimulateRequest{}
err = gogoproto.Unmarshal(req.Data, simulateRequest)
if err != nil {
return nil, true, fmt.Errorf("unable to decode gRPC request with path %s from ABCI.Query: %w", req.Path, err)
}

tx, err := c.txCodec.Decode(simulateRequest.TxBytes)
if err != nil {
return nil, true, fmt.Errorf("failed to decode tx: %w", err)
}

txResult, _, err := c.app.Simulate(ctx, tx)
if err != nil {
return nil, true, fmt.Errorf("%v with gas used: '%d'", err, txResult.GasUsed)
}

msgResponses := make([]*codectypes.Any, 0, len(txResult.Resp))
// pack the messages into Any
for _, msg := range txResult.Resp {
anyMsg, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return nil, true, fmt.Errorf("failed to pack message response: %w", err)
}

msgResponses = append(msgResponses, anyMsg)
}

resp := &txtypes.SimulateResponse{
GasInfo: &sdk.GasInfo{
GasUsed: txResult.GasUsed,
GasWanted: txResult.GasWanted,
},
Result: &sdk.Result{
MsgResponses: msgResponses,
},
}

res, err := queryResponse(resp, req.Height)
return res, true, err
}

handler, found := c.queryHandlersMap[handlerFullName]
if !found {
return nil, true, fmt.Errorf("no query handler found for %s", req.Path)
Expand All @@ -281,7 +330,6 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq
resp := QueryResult(err, c.cfg.AppTomlConfig.Trace)
resp.Height = req.Height
return resp, true, err

}

resp, err = queryResponse(res, req.Height)
Expand Down
2 changes: 1 addition & 1 deletion server/v2/cometbft/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func setUpConsensus(t *testing.T, gasLimit uint64, mempool mempool.Mempool[mock.
nil,
)

return NewConsensus[mock.Tx](log.NewNopLogger(), "testing-app", am, func() error { return nil },
return NewConsensus[mock.Tx](log.NewNopLogger(), "testing-app", am,
mempool, map[string]struct{}{}, nil, mockStore,
Config{AppTomlConfig: DefaultAppTomlConfig()}, mock.TxCodec{}, "test")
}
Expand Down
71 changes: 0 additions & 71 deletions server/v2/cometbft/client/grpc/cmtservice/autocli.go

This file was deleted.

Loading
Loading