From c57f614a6b8b6d02b68dabb45279167977da4966 Mon Sep 17 00:00:00 2001 From: aBear Date: Sun, 29 Sep 2024 00:17:29 +0200 Subject: [PATCH] simplified cometBFTService Info --- mod/consensus/pkg/cometbft/service/abci.go | 16 +++++++--------- mod/consensus/pkg/cometbft/service/service.go | 17 +++++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/mod/consensus/pkg/cometbft/service/abci.go b/mod/consensus/pkg/cometbft/service/abci.go index 605d145137..ac820c23d4 100644 --- a/mod/consensus/pkg/cometbft/service/abci.go +++ b/mod/consensus/pkg/cometbft/service/abci.go @@ -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" ) @@ -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, @@ -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, ) } diff --git a/mod/consensus/pkg/cometbft/service/service.go b/mod/consensus/pkg/cometbft/service/service.go index e2837c1275..9e6357ab5b 100644 --- a/mod/consensus/pkg/cometbft/service/service.go +++ b/mod/consensus/pkg/cometbft/service/service.go @@ -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 ( @@ -54,7 +53,10 @@ const ( execModeFinalize ) -const InitialAppVersion uint64 = 0 +const ( + initialAppVersion uint64 = 0 + appName string = "beacond" +) type Service[ LoggerT log.AdvancedLogger[LoggerT], @@ -63,7 +65,6 @@ type Service[ cmtCfg *cmtcfg.Config logger LoggerT - name string sm *statem.Manager Middleware MiddlewareI @@ -75,8 +76,6 @@ type Service[ initialHeight int64 minRetainBlocks uint64 - // application's version string - version string chainID string } @@ -93,7 +92,6 @@ func NewService[ ) *Service[LoggerT] { s := &Service[LoggerT]{ logger: logger, - name: "beacond", sm: statem.NewManager( db, servercmtlog.WrapSDKLogger(logger), @@ -101,7 +99,6 @@ func NewService[ Middleware: middleware, cmtCfg: cmtCfg, paramStore: params.NewConsensusParamsStore(cs), - version: version.Version, } s.MountStore(storeKey, storetypes.StoreTypeIAVL) @@ -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. @@ -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 }