Skip to content

Commit

Permalink
feat(baseapp): Cleanup (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Aug 15, 2024
1 parent 64872ae commit 85bf300
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 98 deletions.
57 changes: 3 additions & 54 deletions mod/runtime/pkg/cosmos/baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
54 changes: 10 additions & 44 deletions mod/runtime/pkg/cosmos/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit 85bf300

Please sign in to comment.