Skip to content

Commit 7cbbf31

Browse files
czarcas7icmergify[bot]ValarDragonmelekes
authored
perf(state): Cache the block hash cometbft#2924 (cometbft#30)
* perf(state): Cache the block hash (backport cometbft#2924) (cometbft#2932) Closes cometbft#2923 Caches the block hash to ensure we only compute it once in consensus execution. --- #### PR checklist - [x] Tests written/updated - not sure what test I should write, any suggestions? - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2924 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * delete md * changelog * changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
1 parent ee66963 commit 7cbbf31

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
## Unreleased
44

5+
## v0.37.4-v24-osmo-4
6+
57
* [#27](https://github.com/osmosis-labs/cometbft/pull/27) Lower allocation overhead of txIndex matchRange
68
* [#28](https://github.com/osmosis-labs/cometbft/pull/28) Significantly speedup bitArray.PickRandom
79
* [#29](https://github.com/osmosis-labs/cometbft/pull/29) Lower heap overhead of JSON encoding
10+
* [#30](https://github.com/osmosis-labs/cometbft/pull/30) Cache the block hash
811

912
## v0.37.4-v24-osmo-3
1013

types/block.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ const (
4343
type Block struct {
4444
mtx cmtsync.Mutex
4545

46-
Header `json:"header"`
47-
Data `json:"data"`
48-
Evidence EvidenceData `json:"evidence"`
49-
LastCommit *Commit `json:"last_commit"`
46+
verifiedHash cmtbytes.HexBytes // Verified block hash (not included in the struct hash)
47+
Header `json:"header"`
48+
Data `json:"data"`
49+
Evidence EvidenceData `json:"evidence"`
50+
LastCommit *Commit `json:"last_commit"`
5051
}
5152

5253
// ValidateBasic performs basic validation that doesn't involve state data.
@@ -130,8 +131,13 @@ func (b *Block) Hash() cmtbytes.HexBytes {
130131
if b.LastCommit == nil {
131132
return nil
132133
}
134+
if b.verifiedHash != nil {
135+
return b.verifiedHash
136+
}
133137
b.fillHeader()
134-
return b.Header.Hash()
138+
hash := b.Header.Hash()
139+
b.verifiedHash = hash
140+
return hash
135141
}
136142

137143
// MakePartSet returns a PartSet containing parts of a serialized block.

0 commit comments

Comments
 (0)