From 54b49d4bccb179f48a31586665b50971fe3e2915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Toledano?= Date: Tue, 3 Sep 2024 16:08:37 +0200 Subject: [PATCH] refactor(baseapp): audit QA v0.52 (#21515) --- baseapp/abci.go | 3 +++ baseapp/abci_utils.go | 4 ++-- baseapp/abci_utils_test.go | 2 +- baseapp/genesis.go | 6 +++--- baseapp/internal/protocompat/protocompat.go | 3 +-- baseapp/msg_service_router.go | 1 - baseapp/streaming.go | 3 ++- baseapp/test_helpers.go | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 49470e0af771..05b9e61794a7 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -38,6 +38,8 @@ const ( QueryPathBroadcastTx = "/cosmos.tx.v1beta1.Service/BroadcastTx" ) +// InitChain implements the ABCI interface. It initializes the application's state +// and sets up the initial validator set. func (app *BaseApp) InitChain(req *abci.InitChainRequest) (*abci.InitChainResponse, error) { if req.ChainId != app.chainID { return nil, fmt.Errorf("invalid chain-id on InitChain; expected: %s, got: %s", app.chainID, req.ChainId) @@ -135,6 +137,7 @@ func (app *BaseApp) InitChain(req *abci.InitChainRequest) (*abci.InitChainRespon }, nil } +// Info implements the ABCI interface. It returns information about the application. func (app *BaseApp) Info(_ *abci.InfoRequest) (*abci.InfoResponse, error) { lastCommitID := app.cms.LastCommitID() appVersion := InitialAppVersion diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index 6da80906fab5..da6adef5539d 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -23,7 +23,7 @@ import ( ) type ( - // ValidatorStore defines the interface contract require for verifying vote + // ValidatorStore defines the interface contract required for verifying vote // extension signatures. Typically, this will be implemented by the x/staking // module, which has knowledge of the CometBFT public key. ValidatorStore interface { @@ -84,7 +84,7 @@ func ValidateVoteExtensions( totalVP += vote.Validator.Power // Only check + include power if the vote is a commit vote. There must be super-majority, otherwise the - // previous block (the block vote is for) could not have been committed. + // previous block (the block the vote is for) could not have been committed. if vote.BlockIdFlag != cmtproto.BlockIDFlagCommit { continue } diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 7e1c566faf94..ded20c2b6982 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -419,7 +419,7 @@ func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrectVotingPower() { s.Require().Error(baseapp.ValidateVoteExtensions(s.ctx, s.valStore, llc)) } -func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrecOrder() { +func (s *ABCIUtilsTestSuite) TestValidateVoteExtensionsIncorrectOrder() { ext := []byte("vote-extension") cve := cmtproto.CanonicalVoteExtension{ Extension: ext, diff --git a/baseapp/genesis.go b/baseapp/genesis.go index ef3499462472..c4705c3f88db 100644 --- a/baseapp/genesis.go +++ b/baseapp/genesis.go @@ -6,9 +6,9 @@ import ( "github.com/cometbft/cometbft/abci/types" ) -// ExecuteGenesis implements a genesis TxHandler used to execute a genTxs (from genutil). -func (ba *BaseApp) ExecuteGenesisTx(tx []byte) error { - res := ba.deliverTx(tx) +// ExecuteGenesisTx implements a genesis TxHandler used to execute a genTxs (from genutil). +func (app *BaseApp) ExecuteGenesisTx(tx []byte) error { + res := app.deliverTx(tx) if res.Code != types.CodeTypeOK { return errors.New(res.Log) diff --git a/baseapp/internal/protocompat/protocompat.go b/baseapp/internal/protocompat/protocompat.go index 4bd24f6c2ff2..bd277e4a44f7 100644 --- a/baseapp/internal/protocompat/protocompat.go +++ b/baseapp/internal/protocompat/protocompat.go @@ -43,9 +43,8 @@ func MakeHybridHandler(cdc codec.BinaryCodec, sd *grpc.ServiceDesc, method grpc. } if isProtov2Handler { return makeProtoV2HybridHandler(methodDesc, cdc, method, handler) - } else { - return makeGogoHybridHandler(methodDesc, cdc, method, handler) } + return makeGogoHybridHandler(methodDesc, cdc, method, handler) } // makeProtoV2HybridHandler returns a handler that can handle both gogo and protov2 messages. diff --git a/baseapp/msg_service_router.go b/baseapp/msg_service_router.go index 867809152f57..11e3b4bf1b75 100644 --- a/baseapp/msg_service_router.go +++ b/baseapp/msg_service_router.go @@ -47,7 +47,6 @@ func NewMsgServiceRouter() *MsgServiceRouter { routes: map[string]MsgServiceHandler{}, hybridHandlers: map[string]func(ctx context.Context, req, resp protoiface.MessageV1) error{}, responseByMsgName: map[string]string{}, - circuitBreaker: nil, } } diff --git a/baseapp/streaming.go b/baseapp/streaming.go index 3afa68c91f69..6eeb8e37b449 100644 --- a/baseapp/streaming.go +++ b/baseapp/streaming.go @@ -9,6 +9,7 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" "github.com/spf13/cast" + "cosmossdk.io/log" "cosmossdk.io/schema" "cosmossdk.io/schema/appdata" "cosmossdk.io/schema/decoding" @@ -36,7 +37,7 @@ func (app *BaseApp) EnableIndexer(indexerOpts interface{}, keys map[string]*stor Config: indexerOpts, Resolver: decoding.ModuleSetDecoderResolver(appModules), SyncSource: nil, - Logger: app.logger.With("module", "indexer"), + Logger: app.logger.With(log.ModuleKey, "indexer"), }) if err != nil { return err diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 3125e268b0bd..fcd0e55c8447 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -41,7 +41,7 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, } // SimWriteState is an entrypoint for simulations only. They are not executed during the normal ABCI finalize -// block step but later. Therefore an extra call to the root multi-store (app.cms) is required to write the changes. +// block step but later. Therefore, an extra call to the root multi-store (app.cms) is required to write the changes. func (app *BaseApp) SimWriteState() { app.finalizeBlockState.ms.Write() }