Skip to content

Commit

Permalink
implement nodeservice v1beta1 by comet
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 18, 2024
1 parent b995dbd commit 5bbd256
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
27 changes: 11 additions & 16 deletions server/v2/api/grpc/nodeservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package nodeservice

import (
context "context"
"errors"
fmt "fmt"

"cosmossdk.io/core/appmodule"
corecontext "cosmossdk.io/core/context"
"cosmossdk.io/core/server"
)

Expand All @@ -21,8 +19,8 @@ func NewQueryServer(cfg server.ConfigMap) ServiceServer {

func (s queryServer) Config(ctx context.Context, _ *ConfigRequest) (*ConfigResponse, error) {
minGasPricesStr := ""
minGasPrices, ok := s.cfg["server.minimum_gas_price"]
if !ok {
minGasPrices, ok := s.cfg["server"].(map[string]interface{})["minimum-gas-prices"]
if ok {
minGasPricesStr = minGasPrices.(string)
}

Expand All @@ -32,17 +30,14 @@ func (s queryServer) Config(ctx context.Context, _ *ConfigRequest) (*ConfigRespo
}

func (s queryServer) Status(ctx context.Context, _ *StatusRequest) (*StatusResponse, error) {
environment, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodule.Environment)
if !ok {
return nil, errors.New("environment not set")
}
// note, environment nor execution context isn't available in the context

headerInfo := environment.HeaderService.HeaderInfo(ctx)
// return &StatusResponse{
// Height: uint64(headerInfo.Height),
// Timestamp: &headerInfo.Time,
// AppHash: headerInfo.AppHash,
// ValidatorHash: headerInfo.Hash,
// }, nil

return &StatusResponse{
Height: uint64(headerInfo.Height),
Timestamp: &headerInfo.Time,
AppHash: headerInfo.AppHash,
ValidatorHash: headerInfo.Hash,
}, nil
return &StatusResponse{}, fmt.Errorf("not implemented")
}
30 changes: 30 additions & 0 deletions server/v2/cometbft/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"cosmossdk.io/core/transaction"
errorsmod "cosmossdk.io/errors/v2"

v1 "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/cosmos/gogoproto/proto"

"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"
Expand All @@ -30,6 +32,7 @@ func (c *Consensus[T]) GRPCServiceRegistrar(
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]{c})

return nil
}
Expand Down Expand Up @@ -180,3 +183,30 @@ func (t txServer[T]) TxEncodeAmino(context.Context, *txtypes.TxEncodeAminoReques
}

var _ txtypes.ServiceServer = txServer[transaction.Tx]{}

type nodeServer[T transaction.Tx] struct {
consensus *Consensus[T]
}

func (s nodeServer[T]) Config(ctx context.Context, _ *nodeservice.ConfigRequest) (*nodeservice.ConfigResponse, error) {
return &nodeservice.ConfigResponse{
MinimumGasPrice: "check cosmos.base.v2.Service/Config",
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
}

0 comments on commit 5bbd256

Please sign in to comment.