Skip to content

Commit

Permalink
reject query with block height in the future
Browse files Browse the repository at this point in the history
Closes: cosmos#11220
  • Loading branch information
yihuang committed Feb 18, 2022
1 parent 9ce0844 commit ebde047
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,18 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
return sdk.Context{}, err
}

lastBlockHeight := app.LastBlockHeight()
if height > lastBlockHeight {
return sdk.Context{},
sdkerrors.Wrap(
sdkerrors.ErrInvalidHeight,
"cannot query with height in the future; please provide a valid height",
)
}

// when a client did not provide a query height, manually inject the latest
if height == 0 {
height = app.LastBlockHeight()
height = lastBlockHeight
}

if height <= 1 && prove {
Expand All @@ -642,7 +651,7 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
return sdk.Context{},
sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"failed to load state at height %d; %s (latest height: %d)", height, err, app.LastBlockHeight(),
"failed to load state at height %d; %s (latest height: %d)", height, err, lastBlockHeight,
)
}

Expand Down

0 comments on commit ebde047

Please sign in to comment.