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

[Bug]: block header not aligned when query with latest height #21615

Closed
1 task done
mmsqe opened this issue Sep 9, 2024 · 1 comment
Closed
1 task done

[Bug]: block header not aligned when query with latest height #21615

mmsqe opened this issue Sep 9, 2024 · 1 comment
Assignees
Labels

Comments

@mmsqe
Copy link
Contributor

mmsqe commented Sep 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Currently a query result of new block height may be returned with the previous block timestamp if the block is committed but state not being set.

Cosmos SDK Version

main

How to reproduce?

Make the following code change in baseapp/abci.go, then run the test case TestABCI_CreateQueryContext_Before_Set_CheckState in #21003.

diff --git a/baseapp/abci.go b/baseapp/abci.go
index 513d8667fc..2278013f02 100644
--- a/baseapp/abci.go
+++ b/baseapp/abci.go
@@ -1245,6 +1245,15 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
 			)
 	}
 
+	header := app.checkState.Context().BlockHeader()
+	if height == lastBlockHeight && header.Height != lastBlockHeight {
+		return sdk.Context{},
+			errorsmod.Wrapf(
+				sdkerrors.ErrInvalidHeight,
+				"header height in check state context is not latest height (%d)", lastBlockHeight,
+			)
+	}
+
 	// branch the commit multi-store for safety
 	ctx := sdk.NewContext(cacheMS, true, app.logger).
 		WithMinGasPrices(app.minGasPrices).
@@ -1253,7 +1262,7 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
 			ChainID: app.chainID,
 			Height:  height,
 		}).
-		WithBlockHeader(app.checkState.Context().BlockHeader()).
+		WithBlockHeader(header).
 		WithBlockHeight(height)
 
 	if height != lastBlockHeight {

@julienrbrt
Copy link
Member

Closed by #21003

@github-project-automation github-project-automation bot moved this from 👀 Waiting / In review to 🥳 Done in Cosmos-SDK Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🥳 Done
Development

No branches or pull requests

2 participants