Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reject query with block height in the future #11222

Merged
merged 9 commits into from
Feb 24, 2022
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