Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
0083431ba9
commit
3fcdcae7cb
+58
-10
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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,
|
||||
@@ -91,7 +97,6 @@ func NewConsensus[T transaction.Tx](
|
||||
appName: appName,
|
||||
version: getCometBFTServerVersion(),
|
||||
app: app,
|
||||
appCloser: appCloser,
|
||||
cfg: cfg,
|
||||
store: store,
|
||||
logger: logger,
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package cmtservice
|
||||
|
||||
import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
cmtv1beta1 "cosmossdk.io/api/cosmos/base/tendermint/v1beta1"
|
||||
)
|
||||
|
||||
var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
|
||||
Service: cmtv1beta1.Service_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "GetNodeInfo",
|
||||
Use: "node-info",
|
||||
Short: "Query the current node info",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetSyncing",
|
||||
Use: "syncing",
|
||||
Short: "Query node syncing status",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetLatestBlock",
|
||||
Use: "block-latest",
|
||||
Short: "Query for the latest committed block",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetBlockByHeight",
|
||||
Use: "block-by-height <height>",
|
||||
Short: "Query for a committed block by height",
|
||||
Long: "Query for a specific committed block using the CometBFT RPC `block_by_height` method",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetLatestValidatorSet",
|
||||
Use: "validator-set",
|
||||
Alias: []string{"validator-set-latest", "comet-validator-set", "cometbft-validator-set", "tendermint-validator-set"},
|
||||
Short: "Query for the latest validator set",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetValidatorSetByHeight",
|
||||
Use: "validator-set-by-height <height>",
|
||||
Short: "Query for a validator set by height",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
|
||||
},
|
||||
{
|
||||
RpcMethod: "ABCIQuery",
|
||||
Skip: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// NewCometBFTCommands is a fake `appmodule.Module` to be considered as a module
|
||||
// and be added in AutoCLI.
|
||||
func NewCometBFTCommands() *cometModule {
|
||||
return &cometModule{}
|
||||
}
|
||||
|
||||
type cometModule struct{}
|
||||
|
||||
func (m cometModule) IsOnePerModuleType() {}
|
||||
func (m cometModule) IsAppModule() {}
|
||||
|
||||
func (m cometModule) Name() string {
|
||||
return "comet"
|
||||
}
|
||||
|
||||
func (m cometModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
return &autocliv1.ModuleOptions{
|
||||
Query: CometBFTAutoCLIDescriptor,
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package cmtservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
gogogrpc "github.com/cosmos/gogoproto/grpc"
|
||||
gogoprotoany "github.com/cosmos/gogoproto/types/any"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/server/v2/cometbft/client/rpc"
|
||||
|
||||
cmtservice "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
|
||||
)
|
||||
|
||||
var _ gogoprotoany.UnpackInterfacesMessage = &cmtservice.GetLatestValidatorSetResponse{}
|
||||
|
||||
const (
|
||||
QueryPathApp = "app"
|
||||
QueryPathP2P = "p2p"
|
||||
QueryPathStore = "store"
|
||||
)
|
||||
|
||||
type abciQueryFn = func(context.Context, *abci.QueryRequest) (*abci.QueryResponse, error)
|
||||
|
||||
// RegisterTendermintService registers the CometBFT queries on the gRPC router.
|
||||
func RegisterTendermintService(
|
||||
client rpc.CometRPC,
|
||||
server gogogrpc.Server,
|
||||
queryFn abciQueryFn,
|
||||
consensusCodec address.Codec,
|
||||
) {
|
||||
cmtservice.RegisterServiceServer(server, cmtservice.NewQueryServer(client, queryFn, consensusCodec))
|
||||
}
|
||||
|
||||
// RegisterGRPCGatewayRoutes mounts the CometBFT service's GRPC-gateway routes on the
|
||||
// given Mux.
|
||||
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
|
||||
_ = cmtservice.RegisterServiceHandlerClient(context.Background(), mux, cmtservice.NewServiceClient(clientConn))
|
||||
}
|
||||
|
||||
// SplitABCIQueryPath splits a string path using the delimiter '/'.
|
||||
//
|
||||
// e.g. "this/is/funny" becomes []string{"this", "is", "funny"}
|
||||
func SplitABCIQueryPath(requestPath string) (path []string) {
|
||||
path = strings.Split(requestPath, "/")
|
||||
|
||||
// first element is empty string
|
||||
if len(path) > 0 && path[0] == "" {
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
@@ -50,9 +50,15 @@ func QueryBlocks(ctx context.Context, rpcClient CometRPC, page, limit int, query
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := NewSearchBlocksResult(int64(resBlocks.TotalCount), int64(len(blocks)), int64(page), int64(limit), blocks)
|
||||
|
||||
return result, nil
|
||||
totalPages := calcTotalPages(int64(resBlocks.TotalCount), int64(limit))
|
||||
return &sdk.SearchBlocksResult{
|
||||
TotalCount: int64(resBlocks.TotalCount),
|
||||
Count: int64(len(blocks)),
|
||||
PageNumber: int64(page),
|
||||
PageTotal: totalPages,
|
||||
Limit: int64(limit),
|
||||
Blocks: blocks,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetBlockByHeight gets block by height
|
||||
@@ -65,7 +71,7 @@ func GetBlockByHeight(ctx context.Context, rpcClient CometRPC, height *int64) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out, err := NewResponseResultBlock(resBlock)
|
||||
out, err := responseResultBlock(resBlock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,7 +96,7 @@ func GetBlockByHash(ctx context.Context, rpcClient CometRPC, hashHexString strin
|
||||
} else if resBlock.Block == nil {
|
||||
return nil, fmt.Errorf("block not found with hash: %s", hashHexString)
|
||||
}
|
||||
out, err := NewResponseResultBlock(resBlock)
|
||||
out, err := responseResultBlock(resBlock)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
cmttypes "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
coretypes "github.com/cometbft/cometbft/rpc/core/types"
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// formatBlockResults parses the indexed blocks into a slice of BlockResponse objects.
|
||||
@@ -17,7 +15,7 @@ func formatBlockResults(resBlocks []*coretypes.ResultBlock) ([]*cmttypes.Block,
|
||||
out = make([]*cmttypes.Block, len(resBlocks))
|
||||
)
|
||||
for i := range resBlocks {
|
||||
out[i], err = NewResponseResultBlock(resBlocks[i])
|
||||
out[i], err = responseResultBlock(resBlocks[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create response block from comet result block: %v: %w", resBlocks[i], err)
|
||||
}
|
||||
@@ -29,20 +27,8 @@ func formatBlockResults(resBlocks []*coretypes.ResultBlock) ([]*cmttypes.Block,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSearchBlocksResult(totalCount, count, page, limit int64, blocks []*cmttypes.Block) *sdk.SearchBlocksResult {
|
||||
totalPages := calcTotalPages(totalCount, limit)
|
||||
return &sdk.SearchBlocksResult{
|
||||
TotalCount: totalCount,
|
||||
Count: count,
|
||||
PageNumber: page,
|
||||
PageTotal: totalPages,
|
||||
Limit: limit,
|
||||
Blocks: blocks,
|
||||
}
|
||||
}
|
||||
|
||||
// NewResponseResultBlock returns a BlockResponse given a ResultBlock from CometBFT
|
||||
func NewResponseResultBlock(res *coretypes.ResultBlock) (*cmttypes.Block, error) {
|
||||
// responseResultBlock returns a BlockResponse given a ResultBlock from CometBFT
|
||||
func responseResultBlock(res *coretypes.ResultBlock) (*cmttypes.Block, error) {
|
||||
blkProto, err := res.Block.ToProto()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -19,27 +19,27 @@ require (
|
||||
cosmossdk.io/core v1.0.0-alpha.6
|
||||
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5
|
||||
cosmossdk.io/log v1.5.0
|
||||
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 // main
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af // main
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af // main
|
||||
cosmossdk.io/server/v2 v2.0.0-20241119134933-d697a3de0f95 // main
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95 // main
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95 // main
|
||||
cosmossdk.io/store/v2 v2.0.0-20241108140525-43e28b43ad7a // main
|
||||
cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
github.com/cosmos/gogoproto v1.7.0
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.9.0
|
||||
google.golang.org/protobuf v1.35.1
|
||||
google.golang.org/grpc v1.68.0
|
||||
google.golang.org/protobuf v1.35.2
|
||||
sigs.k8s.io/yaml v1.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect
|
||||
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect
|
||||
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 // indirect
|
||||
cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e // indirect
|
||||
cosmossdk.io/depinject v1.1.0 // indirect
|
||||
cosmossdk.io/errors v1.0.1 // indirect
|
||||
cosmossdk.io/math v1.3.0 // indirect
|
||||
@@ -103,6 +103,7 @@ require (
|
||||
github.com/gorilla/mux v1.8.1 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
|
||||
github.com/hashicorp/go-hclog v1.6.3 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||
@@ -163,19 +164,18 @@ require (
|
||||
go.etcd.io/bbolt v1.4.0-alpha.1 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/crypto v0.29.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sync v0.9.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/term v0.25.0 // indirect
|
||||
golang.org/x/term v0.26.0 // indirect
|
||||
golang.org/x/text v0.20.0 // indirect
|
||||
golang.org/x/tools v0.25.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
|
||||
google.golang.org/grpc v1.68.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gotest.tools/v3 v3.5.1 // indirect
|
||||
|
||||
+14
-14
@@ -10,8 +10,8 @@ cosmossdk.io/collections v0.4.1-0.20241107084833-00f3065e70ee h1:OLqvi9ekfShobmd
|
||||
cosmossdk.io/collections v0.4.1-0.20241107084833-00f3065e70ee/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE=
|
||||
cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E=
|
||||
cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY=
|
||||
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY=
|
||||
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs=
|
||||
cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs=
|
||||
cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e/go.mod h1:3YvVv9aJayjPhdX0DY1IMrGse4sR63hNBWx2VtDWjGQ=
|
||||
cosmossdk.io/depinject v1.1.0 h1:wLan7LG35VM7Yo6ov0jId3RHWCGRhe8E8bsuARorl5E=
|
||||
cosmossdk.io/depinject v1.1.0/go.mod h1:kkI5H9jCGHeKeYWXTqYdruogYrEeWvBQCw1Pj4/eCFI=
|
||||
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
|
||||
@@ -24,12 +24,12 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
|
||||
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
|
||||
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc=
|
||||
cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ=
|
||||
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08 h1:hmTWRUEaRvaZhFhgC/Bd7z/6Rhn+It/3Fja3lECIOHQ=
|
||||
cosmossdk.io/server/v2 v2.0.0-20241108144957-78b5cd4dbd08/go.mod h1:OecMMKlPdlFp2PxqV/capqhUhbIDaa5OiNkY1v5hi8c=
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af h1:uDQXvGBH3kZW1UXFccMlNCgHf2L5QCGjNmw51q6atzI=
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241029092041-78cfc68c83af/go.mod h1:mONOF8GRbxs5R04zMscuQQI1gx/XHTY7imKjcwLI5uo=
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af h1:jefP4LTtln0XsXHeSqRENeAGyPQ9qSbGHMy6811FE/c=
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241029092041-78cfc68c83af/go.mod h1:npAiRkgEOigiBlWyLhwTucbzghItNAIPm2eYWSHG/cI=
|
||||
cosmossdk.io/server/v2 v2.0.0-20241119134933-d697a3de0f95 h1:WUho1r7Zcg5aPn5YtYRN5TW9fvxUirX1mSihBDJ6ccg=
|
||||
cosmossdk.io/server/v2 v2.0.0-20241119134933-d697a3de0f95/go.mod h1:gPATMrgLSzDoJiyoY+N8ULwfvAJ3Ooh6TYFsW60tHW0=
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95 h1:GOznErJieaI0OS0LDUsu5Vy3qPnCyjdvkncejP0Zv5s=
|
||||
cosmossdk.io/server/v2/appmanager v0.0.0-20241119134933-d697a3de0f95/go.mod h1:elhlrldWtm+9U4PxE0G3wjz83yQwVVGVAOncXJPY1Xc=
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95 h1:cK7wvmlA18AvLcaInseKTBmt5EXtLwafe7oH1rx7veU=
|
||||
cosmossdk.io/server/v2/stf v0.0.0-20241119134933-d697a3de0f95/go.mod h1:4e9SzLyeGptQ3tSR6nKCNwCu7Ye4uUS2WIJih29dG2c=
|
||||
cosmossdk.io/store v1.0.0-rc.0.0.20241108140525-43e28b43ad7a h1:5ENKFUhhJPkpx6dGDmc0/LXinjE3oIQDEES9gVVA4xM=
|
||||
cosmossdk.io/store v1.0.0-rc.0.0.20241108140525-43e28b43ad7a/go.mod h1:pjNPBX9giCOI18kf3mgNtn4J3SFaZbV1mAmM58iHdgg=
|
||||
cosmossdk.io/store/v2 v2.0.0-20241108140525-43e28b43ad7a h1:3SB9LPBiLuy8pCUPgfFtCP9I4wYKYajxv5vssyO5YEs=
|
||||
@@ -546,8 +546,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
||||
@@ -630,8 +630,8 @@ golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
|
||||
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
|
||||
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
|
||||
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
@@ -697,8 +697,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
package cometbft
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
cmtv1beta1 "cosmossdk.io/api/cosmos/base/tendermint/v1beta1"
|
||||
"cosmossdk.io/core/server"
|
||||
"cosmossdk.io/core/transaction"
|
||||
errorsmod "cosmossdk.io/errors/v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
|
||||
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
)
|
||||
|
||||
// GRPCServiceRegistrar returns a function that registers the CometBFT gRPC service
|
||||
// Those services are defined for backward compatibility.
|
||||
// Eventually, they will be removed in favor of the new gRPC services.
|
||||
func (c *Consensus[T]) GRPCServiceRegistrar(
|
||||
clientCtx client.Context,
|
||||
cfg server.ConfigMap,
|
||||
) func(srv *grpc.Server) error {
|
||||
return func(srv *grpc.Server) error {
|
||||
cmtservice.RegisterServiceServer(srv, cmtservice.NewQueryServer(clientCtx.Client, c.Query, clientCtx.ConsensusAddressCodec))
|
||||
txtypes.RegisterServiceServer(srv, txServer[T]{clientCtx, c})
|
||||
nodeservice.RegisterServiceServer(srv, nodeServer[T]{cfg, c})
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// CometBFTAutoCLIDescriptor is the auto-generated CLI descriptor for the CometBFT service
|
||||
var CometBFTAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
|
||||
Service: cmtv1beta1.Service_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "GetNodeInfo",
|
||||
Use: "node-info",
|
||||
Short: "Query the current node info",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetSyncing",
|
||||
Use: "syncing",
|
||||
Short: "Query node syncing status",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetLatestBlock",
|
||||
Use: "block-latest",
|
||||
Short: "Query for the latest committed block",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetBlockByHeight",
|
||||
Use: "block-by-height <height>",
|
||||
Short: "Query for a committed block by height",
|
||||
Long: "Query for a specific committed block using the CometBFT RPC `block_by_height` method",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetLatestValidatorSet",
|
||||
Use: "validator-set",
|
||||
Alias: []string{"validator-set-latest", "comet-validator-set", "cometbft-validator-set", "tendermint-validator-set"},
|
||||
Short: "Query for the latest validator set",
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetValidatorSetByHeight",
|
||||
Use: "validator-set-by-height <height>",
|
||||
Short: "Query for a validator set by height",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "height"}},
|
||||
},
|
||||
{
|
||||
RpcMethod: "ABCIQuery",
|
||||
Skip: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type txServer[T transaction.Tx] struct {
|
||||
clientCtx client.Context
|
||||
consensus *Consensus[T]
|
||||
}
|
||||
|
||||
// BroadcastTx implements tx.ServiceServer.
|
||||
func (t txServer[T]) BroadcastTx(ctx context.Context, req *txtypes.BroadcastTxRequest) (*txtypes.BroadcastTxResponse, error) {
|
||||
return client.TxServiceBroadcast(ctx, t.clientCtx, req)
|
||||
}
|
||||
|
||||
// GetBlockWithTxs implements tx.ServiceServer.
|
||||
func (t txServer[T]) GetBlockWithTxs(context.Context, *txtypes.GetBlockWithTxsRequest) (*txtypes.GetBlockWithTxsResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// GetTx implements tx.ServiceServer.
|
||||
func (t txServer[T]) GetTx(context.Context, *txtypes.GetTxRequest) (*txtypes.GetTxResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// GetTxsEvent implements tx.ServiceServer.
|
||||
func (t txServer[T]) GetTxsEvent(context.Context, *txtypes.GetTxsEventRequest) (*txtypes.GetTxsEventResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// Simulate implements tx.ServiceServer.
|
||||
func (t txServer[T]) Simulate(ctx context.Context, req *txtypes.SimulateRequest) (*txtypes.SimulateResponse, error) {
|
||||
if req == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid empty tx")
|
||||
}
|
||||
|
||||
txBytes := req.TxBytes
|
||||
if txBytes == nil && req.Tx != nil {
|
||||
// This block is for backwards-compatibility.
|
||||
// We used to support passing a `Tx` in req. But if we do that, sig
|
||||
// verification might not pass, because the .Marshal() below might not
|
||||
// be the same marshaling done by the client.
|
||||
var err error
|
||||
txBytes, err = proto.Marshal(req.Tx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid tx; %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if txBytes == nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "empty txBytes is not allowed")
|
||||
}
|
||||
|
||||
tx, err := t.consensus.txCodec.Decode(txBytes)
|
||||
if err != nil {
|
||||
return nil, errorsmod.Wrap(err, "failed to decode tx")
|
||||
}
|
||||
|
||||
txResult, _, err := t.consensus.app.Simulate(ctx, tx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unknown, "%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, status.Errorf(codes.Unknown, "failed to pack message response: %v", err)
|
||||
}
|
||||
msgResponses = append(msgResponses, anyMsg)
|
||||
}
|
||||
|
||||
return &txtypes.SimulateResponse{
|
||||
GasInfo: &sdk.GasInfo{
|
||||
GasUsed: txResult.GasUsed,
|
||||
GasWanted: txResult.GasWanted,
|
||||
},
|
||||
Result: &sdk.Result{
|
||||
MsgResponses: msgResponses,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TxDecode implements tx.ServiceServer.
|
||||
func (t txServer[T]) TxDecode(context.Context, *txtypes.TxDecodeRequest) (*txtypes.TxDecodeResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// TxDecodeAmino implements tx.ServiceServer.
|
||||
func (t txServer[T]) TxDecodeAmino(context.Context, *txtypes.TxDecodeAminoRequest) (*txtypes.TxDecodeAminoResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// TxEncode implements tx.ServiceServer.
|
||||
func (t txServer[T]) TxEncode(context.Context, *txtypes.TxEncodeRequest) (*txtypes.TxEncodeResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
// TxEncodeAmino implements tx.ServiceServer.
|
||||
func (t txServer[T]) TxEncodeAmino(context.Context, *txtypes.TxEncodeAminoRequest) (*txtypes.TxEncodeAminoResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
var _ txtypes.ServiceServer = txServer[transaction.Tx]{}
|
||||
|
||||
type nodeServer[T transaction.Tx] struct {
|
||||
cfg server.ConfigMap
|
||||
consensus *Consensus[T]
|
||||
}
|
||||
|
||||
func (s nodeServer[T]) Config(ctx context.Context, _ *nodeservice.ConfigRequest) (*nodeservice.ConfigResponse, error) {
|
||||
minGasPricesStr := ""
|
||||
minGasPrices, ok := s.cfg["server"].(map[string]interface{})["minimum-gas-prices"]
|
||||
if ok {
|
||||
minGasPricesStr = minGasPrices.(string)
|
||||
}
|
||||
|
||||
return &nodeservice.ConfigResponse{
|
||||
MinimumGasPrice: minGasPricesStr,
|
||||
PruningKeepRecent: "ambiguous in v2",
|
||||
PruningInterval: "ambiguous in v2",
|
||||
HaltHeight: s.consensus.cfg.AppTomlConfig.HaltHeight,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s nodeServer[T]) Status(ctx context.Context, _ *nodeservice.StatusRequest) (*nodeservice.StatusResponse, error) {
|
||||
nodeInfo, err := s.consensus.Info(ctx, &v1.InfoRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &nodeservice.StatusResponse{
|
||||
Height: uint64(nodeInfo.LastBlockHeight),
|
||||
Timestamp: nil,
|
||||
AppHash: nil,
|
||||
ValidatorHash: nodeInfo.LastBlockAppHash,
|
||||
}, nil
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
crypto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
|
||||
|
||||
errorsmod "cosmossdk.io/errors/v2"
|
||||
"cosmossdk.io/server/v2/cometbft/types"
|
||||
cometerrors "cosmossdk.io/server/v2/cometbft/types/errors"
|
||||
)
|
||||
|
||||
@@ -84,7 +83,7 @@ func (c *Consensus[T]) handlerQueryApp(ctx context.Context, path []string, req *
|
||||
return nil, errorsmod.Wrapf(cometerrors.ErrUnknownRequest, "unknown query: %s", path)
|
||||
}
|
||||
|
||||
func (c *Consensus[T]) handleQueryStore(path []string, _ types.Store, req *abci.QueryRequest) (*abci.QueryResponse, error) {
|
||||
func (c *Consensus[T]) handleQueryStore(path []string, req *abci.QueryRequest) (*abci.QueryResponse, error) {
|
||||
req.Path = "/" + strings.Join(path[1:], "/")
|
||||
if req.Height <= 1 && req.Prove {
|
||||
return nil, errorsmod.Wrap(
|
||||
|
||||
@@ -116,7 +116,6 @@ func New[T transaction.Tx](
|
||||
logger,
|
||||
appName,
|
||||
appManager,
|
||||
nil,
|
||||
srv.serverOptions.Mempool(cfg),
|
||||
indexEvents,
|
||||
queryHandlers,
|
||||
|
||||
Reference in New Issue
Block a user