From 85bf300736cfe2bac53426c0eb2e1db5c7992012 Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Thu, 15 Aug 2024 17:23:10 -0400 Subject: [PATCH] feat(baseapp): Cleanup (#1907) --- mod/runtime/pkg/cosmos/baseapp/abci.go | 57 ++--------------------- mod/runtime/pkg/cosmos/baseapp/baseapp.go | 54 ++++----------------- 2 files changed, 13 insertions(+), 98 deletions(-) diff --git a/mod/runtime/pkg/cosmos/baseapp/abci.go b/mod/runtime/pkg/cosmos/baseapp/abci.go index 9418003a47..2f62235591 100644 --- a/mod/runtime/pkg/cosmos/baseapp/abci.go +++ b/mod/runtime/pkg/cosmos/baseapp/abci.go @@ -198,14 +198,7 @@ func (app *BaseApp) PrepareProposal( } app.prepareProposalState.SetContext( - app.getContextForProposal(app.prepareProposalState.Context(), req.Height). - WithVoteInfos(toVoteInfo(req.LocalLastCommit.Votes)). - - // this is a set of votes that are not finalized yet, wait for - // commit - WithBlockHeight(req.Height). - WithProposer(req.ProposerAddress). - WithExecMode(sdk.ExecModePrepareProposal), + app.getContextForProposal(app.prepareProposalState.Context(), req.Height), ) app.prepareProposalState.SetContext(app.prepareProposalState.Context()) @@ -274,15 +267,7 @@ func (app *BaseApp) ProcessProposal( } app.processProposalState.SetContext( - app.getContextForProposal(app.processProposalState.Context(), req.Height). - WithVoteInfos(req.ProposedLastCommit.Votes). - - // this is a set of votes that are not finalized yet, wait for - // commit - WithBlockHeight(req.Height). - WithHeaderHash(req.Hash). - WithProposer(req.ProposerAddress). - WithExecMode(sdk.ExecModeProcessProposal), + app.getContextForProposal(app.processProposalState.Context(), req.Height), ) resp, err = app.processProposal(app.processProposalState.Context(), req) @@ -319,15 +304,6 @@ func (app *BaseApp) internalFinalizeBlock( return nil, err } - header := cmtproto.Header{ - ChainID: app.chainID, - Height: req.Height, - Time: req.Time, - ProposerAddress: req.ProposerAddress, - NextValidatorsHash: req.NextValidatorsHash, - AppHash: app.LastCommitID().Hash, - } - // finalizeBlockState should be set on InitChain or ProcessProposal. If it // is nil, it means we are replaying this block and we need to set the state // here given that during block replay ProcessProposal is not executed by @@ -336,16 +312,7 @@ func (app *BaseApp) internalFinalizeBlock( app.setState(execModeFinalize) } - // Context is now updated with Header information. - app.finalizeBlockState.SetContext(app.finalizeBlockState.Context(). - WithBlockHeader(header). - WithHeaderHash(req.Hash). - WithVoteInfos(req.DecidedLastCommit.Votes). - WithExecMode(sdk.ExecModeFinalize)) - - app.finalizeBlockState.SetContext( - app.finalizeBlockState.Context(), - ) + app.finalizeBlockState.SetContext(app.finalizeBlockState.Context()) // First check for an abort signal after beginBlock, as it's the first place // we spend any significant amount of time. @@ -634,24 +601,6 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 { return retentionHeight } -// toVoteInfo converts the new ExtendedVoteInfo to VoteInfo. -func toVoteInfo(votes []abci.ExtendedVoteInfo) []abci.VoteInfo { - legacyVotes := make([]abci.VoteInfo, len(votes)) - for i, vote := range votes { - legacyVotes[i] = abci.VoteInfo{ - Validator: abci.Validator{ - Address: vote.Validator.Address, - Power: vote.Validator.Power, - }, - BlockIdFlag: vote.BlockIdFlag, - } - } - - return legacyVotes -} - -// LEgacy Helpers - // NewContextLegacy returns a new sdk.Context with the provided header. func (app *BaseApp) NewContextLegacy( _ bool, diff --git a/mod/runtime/pkg/cosmos/baseapp/baseapp.go b/mod/runtime/pkg/cosmos/baseapp/baseapp.go index 2f09575b43..8785de9e14 100644 --- a/mod/runtime/pkg/cosmos/baseapp/baseapp.go +++ b/mod/runtime/pkg/cosmos/baseapp/baseapp.go @@ -152,6 +152,11 @@ func (app *BaseApp) Name() string { return app.name } +// CommitMultiStore returns the CommitMultiStore of the BaseApp. +func (app *BaseApp) CommitMultiStore() storetypes.CommitMultiStore { + return app.cms +} + // AppVersion returns the application's protocol version. func (app *BaseApp) AppVersion(ctx context.Context) (uint64, error) { cp, err := app.paramStore.Get(ctx) @@ -164,27 +169,6 @@ func (app *BaseApp) AppVersion(ctx context.Context) (uint64, error) { return cp.Version.App, nil } -// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp -// multistore. -func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) { - for _, key := range keys { - switch key.(type) { - case *storetypes.KVStoreKey: - app.MountStore(key, storetypes.StoreTypeIAVL) - default: - panic(fmt.Sprintf("Unrecognized store key type :%T", key)) - } - } -} - -// MountKVStores mounts all IAVL or DB stores to the provided keys in the -// BaseApp multistore. -func (app *BaseApp) MountKVStores(keys map[string]*storetypes.KVStoreKey) { - for _, key := range keys { - app.MountStore(key, storetypes.StoreTypeIAVL) - } -} - // MountStore mounts a store to the provided key in the BaseApp multistore, // using the default DB. func (app *BaseApp) MountStore( @@ -197,19 +181,12 @@ func (app *BaseApp) MountStore( // LoadLatestVersion loads the latest application version. It will panic if // called more than once on a running BaseApp. func (app *BaseApp) LoadLatestVersion() error { - err := app.cms.LoadLatestVersion() - if err != nil { + if err := app.cms.LoadLatestVersion(); err != nil { return fmt.Errorf("failed to load latest version: %w", err) } - return app.Init() -} - -// CommitMultiStore returns the root multi-store. -// App constructor can use this to access the `cms`. -// UNSAFE: must not be used during the abci life cycle. -func (app *BaseApp) CommitMultiStore() storetypes.CommitMultiStore { - return app.cms + // Validator pruning settings. + return app.cms.GetPruning().Validate() } // LoadVersion loads the BaseApp application version. It will panic if called @@ -223,7 +200,8 @@ func (app *BaseApp) LoadVersion(version int64) error { return fmt.Errorf("failed to load version %d: %w", version, err) } - return app.Init() + // Validate Pruning settings. + return app.cms.GetPruning().Validate() } // LastCommitID returns the last CommitID of the multistore. @@ -236,18 +214,6 @@ func (app *BaseApp) LastBlockHeight() int64 { return app.cms.LastCommitID().Version } -// Init initializes the app. It seals the app, preventing any -// further modifications. In addition, it validates the app against -// the earlier provided settings. Returns an error if validation fails. -// nil otherwise. Panics if the app is already sealed. -func (app *BaseApp) Init() error { - if app.cms == nil { - return errors.New("commit multi-store must not be nil") - } - - return app.cms.GetPruning().Validate() -} - func (app *BaseApp) setMinRetainBlocks(minRetainBlocks uint64) { app.minRetainBlocks = minRetainBlocks }