diff --git a/baseapp/abci.go b/baseapp/abci.go index b7b187151b9e..12a720847f5a 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -144,7 +144,7 @@ func (app *BaseApp) Info(_ *abci.InfoRequest) (*abci.InfoResponse, error) { lastCommitID := app.cms.LastCommitID() appVersion := InitialAppVersion if lastCommitID.Version > 0 { - ctx, err := app.CreateQueryContextWithCheckHeader(lastCommitID.Version, false, false) + ctx, err := app.CreateQueryContext(lastCommitID.Version, false) if err != nil { return nil, fmt.Errorf("failed creating query context: %w", err) } @@ -1299,12 +1299,6 @@ func checkNegativeHeight(height int64) error { // CreateQueryContext creates a new sdk.Context for a query, taking as args // the block height and whether the query needs a proof or not. func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, error) { - return app.CreateQueryContextWithCheckHeader(height, prove, true) -} - -// CreateQueryContextWithCheckHeader creates a new sdk.Context for a query, taking as args -// the block height, whether the query needs a proof or not, and whether to check the header or not. -func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, checkHeader bool) (sdk.Context, error) { if err := checkNegativeHeight(height); err != nil { return sdk.Context{}, err } @@ -1328,7 +1322,12 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check ) } - if height > 0 && height <= 1 && prove { + // when a client did not provide a query height, manually inject the latest + if height == 0 { + height = lastBlockHeight + } + + if height <= 1 && prove { return sdk.Context{}, errorsmod.Wrap( sdkerrors.ErrInvalidRequest, @@ -1336,38 +1335,6 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check ) } - var header *cmtproto.Header - isLatest := height == 0 - for _, state := range []*state{ - app.checkState, - app.finalizeBlockState, - } { - if state != nil { - // branch the commit multi-store for safety - h := state.Context().BlockHeader() - if isLatest { - lastBlockHeight = qms.LatestVersion() - } - if !checkHeader || !isLatest || isLatest && h.Height == lastBlockHeight { - header = &h - break - } - } - } - - if header == nil { - return sdk.Context{}, - errorsmod.Wrapf( - sdkerrors.ErrInvalidHeight, - "header height in all state context is not latest height (%d)", lastBlockHeight, - ) - } - - // when a client did not provide a query height, manually inject the latest - if isLatest { - height = lastBlockHeight - } - cacheMS, err := qms.CacheMultiStoreWithVersion(height) if err != nil { return sdk.Context{}, @@ -1378,6 +1345,7 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check } // branch the commit multi-store for safety + header := app.checkState.Context().BlockHeader() ctx := sdk.NewContext(cacheMS, true, app.logger). WithMinGasPrices(app.minGasPrices). WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)). @@ -1386,15 +1354,15 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check Height: height, Time: header.Time, }). - WithBlockHeader(*header). + WithBlockHeader(header). WithBlockHeight(height) - if !isLatest { + if height != lastBlockHeight { rms, ok := app.cms.(*rootmulti.Store) if ok { cInfo, err := rms.GetCommitInfo(height) if cInfo != nil && err == nil { - ctx = ctx.WithHeaderInfo(coreheader.Info{Height: height, Time: cInfo.Timestamp}) + ctx = ctx.WithHeaderInfo(coreheader.Info{ChainID: app.chainID, Height: height, Time: cInfo.Timestamp}) } } }