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

perf(state): Cache the block hash #2924 #30

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

## Unreleased

## v0.37.4-v24-osmo-4

* [#27](https://github.com/osmosis-labs/cometbft/pull/27) Lower allocation overhead of txIndex matchRange
* [#28](https://github.com/osmosis-labs/cometbft/pull/28) Significantly speedup bitArray.PickRandom
* [#29](https://github.com/osmosis-labs/cometbft/pull/29) Lower heap overhead of JSON encoding
* [#30](https://github.com/osmosis-labs/cometbft/pull/30) Cache the block hash

## v0.37.4-v24-osmo-3

Expand Down
16 changes: 11 additions & 5 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ const (
type Block struct {
mtx cmtsync.Mutex

Header `json:"header"`
Data `json:"data"`
Evidence EvidenceData `json:"evidence"`
LastCommit *Commit `json:"last_commit"`
verifiedHash cmtbytes.HexBytes // Verified block hash (not included in the struct hash)
Header `json:"header"`
Data `json:"data"`
Evidence EvidenceData `json:"evidence"`
LastCommit *Commit `json:"last_commit"`
}

// ValidateBasic performs basic validation that doesn't involve state data.
Expand Down Expand Up @@ -130,8 +131,13 @@ func (b *Block) Hash() cmtbytes.HexBytes {
if b.LastCommit == nil {
return nil
}
if b.verifiedHash != nil {
return b.verifiedHash
}
b.fillHeader()
return b.Header.Hash()
hash := b.Header.Hash()
b.verifiedHash = hash
return hash
}

// MakePartSet returns a PartSet containing parts of a serialized block.
Expand Down
Loading