Skip to content

Commit

Permalink
chore(CometBFTService): simplified cometBFTService Info (#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 authored Sep 30, 2024
1 parent b6c134d commit 320256c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 7 additions & 9 deletions mod/consensus/pkg/cometbft/service/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkversion "github.com/cosmos/cosmos-sdk/version"
"github.com/sourcegraph/conc/iter"
)

Expand Down Expand Up @@ -187,21 +188,18 @@ func (s *Service[LoggerT]) Info(
*cmtabci.InfoRequest,
) (*cmtabci.InfoResponse, error) {
lastCommitID := s.sm.CommitMultiStore().LastCommitID()
appVersion := InitialAppVersion
appVersion := initialAppVersion
if lastCommitID.Version > 0 {
ctx, err := s.CreateQueryContext(lastCommitID.Version, false)
if err != nil {
return nil, fmt.Errorf("failed creating query context: %w", err)
}
appVersion, err = s.AppVersion(ctx)
var err error
appVersion, err = s.appVersion()
if err != nil {
return nil, fmt.Errorf("failed getting app version: %w", err)
}
}

return &cmtabci.InfoResponse{
Data: s.name,
Version: s.version,
Data: appName,
Version: sdkversion.Version,
AppVersion: appVersion,
LastBlockHeight: lastCommitID.Version,
LastBlockAppHash: lastCommitID.Hash,
Expand Down Expand Up @@ -530,7 +528,7 @@ func (s *Service[LoggerT]) CreateQueryContext(
return sdk.Context{}, errorsmod.Wrapf(
sdkerrors.ErrInvalidHeight,
"%s is not ready; please wait for first block",
s.name,
appName,
)
}

Expand Down
17 changes: 9 additions & 8 deletions mod/consensus/pkg/cometbft/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/cometbft/cometbft/proxy"
dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
)

type (
Expand All @@ -54,7 +53,10 @@ const (
execModeFinalize
)

const InitialAppVersion uint64 = 0
const (
initialAppVersion uint64 = 0
appName string = "beacond"
)

type Service[
LoggerT log.AdvancedLogger[LoggerT],
Expand All @@ -63,7 +65,6 @@ type Service[
cmtCfg *cmtcfg.Config

logger LoggerT
name string
sm *statem.Manager
Middleware MiddlewareI

Expand All @@ -75,8 +76,6 @@ type Service[
initialHeight int64
minRetainBlocks uint64

// application's version string
version string
chainID string
}

Expand All @@ -93,15 +92,13 @@ func NewService[
) *Service[LoggerT] {
s := &Service[LoggerT]{
logger: logger,
name: "beacond",
sm: statem.NewManager(
db,
servercmtlog.WrapSDKLogger(logger),
),
Middleware: middleware,
cmtCfg: cmtCfg,
paramStore: params.NewConsensusParamsStore(cs),
version: version.Version,
}

s.MountStore(storeKey, storetypes.StoreTypeIAVL)
Expand Down Expand Up @@ -174,7 +171,7 @@ func (s *Service[_]) Close() error {

// Name returns the name of the cometbft.
func (s *Service[_]) Name() string {
return s.name
return appName
}

// CommitMultiStore returns the CommitMultiStore of the cometbft.
Expand All @@ -184,6 +181,10 @@ func (s *Service[_]) CommitMultiStore() storetypes.CommitMultiStore {

// AppVersion returns the application's protocol version.
func (s *Service[_]) AppVersion(_ context.Context) (uint64, error) {
return s.appVersion()
}

func (s *Service[_]) appVersion() (uint64, error) {
cp := s.paramStore.Get()
return cp.Version.App, nil
}
Expand Down

0 comments on commit 320256c

Please sign in to comment.