-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: empty app hash on first block's FinalizeBlock #18524
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,13 +726,25 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request | |
)) | ||
} | ||
|
||
// In the case of a new chain, AppHash will be the hash of an empty string. | ||
// During an upgrade, it'll be the hash of the last committed block. | ||
var appHash []byte | ||
if !app.LastCommitID().IsZero() { | ||
appHash = app.LastCommitID().Hash | ||
} else { | ||
// $ echo -n '' | sha256sum | ||
// e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 | ||
emptyHash := sha256.Sum256([]byte{}) | ||
appHash = emptyHash[:] | ||
} | ||
Comment on lines
726
to
+739
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change potentially affects state. Call sequence:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really correct? In the case of the first block of a new chain, the app hash, IIRC, is the genesis hash which is supplied during BeginBlock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I observed, i.e. a |
||
|
||
header := cmtproto.Header{ | ||
ChainID: app.chainID, | ||
Height: req.Height, | ||
Time: req.Time, | ||
ProposerAddress: req.ProposerAddress, | ||
NextValidatorsHash: req.NextValidatorsHash, | ||
AppHash: app.LastCommitID().Hash, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whynot set app.LastCommitID() to an empty value on start? this would help in avoiding the above code and potentially make it cleaner |
||
AppHash: appHash, | ||
} | ||
|
||
// finalizeBlockState should be set on InitChain or ProcessProposal. If it is | ||
|
@@ -751,7 +763,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request | |
Height: req.Height, | ||
Time: req.Time, | ||
Hash: req.Hash, | ||
AppHash: app.LastCommitID().Hash, | ||
AppHash: appHash, | ||
}). | ||
WithConsensusParams(app.GetConsensusParams(app.finalizeBlockState.ctx)). | ||
WithVoteInfos(req.DecidedLastCommit.Votes). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.