From 200793969be66fa7ecf1dd7d07fcf70593e0d7a6 Mon Sep 17 00:00:00 2001
From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com>
Date: Tue, 30 Apr 2024 10:47:37 -0500
Subject: [PATCH] perf(state): Cache the block hash #2924 (#30) (#34)
* perf(state): Cache the block hash (backport #2924) (#2932)
Closes #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
This is an automatic backport of pull request #2924 done by
[Mergify](https://mergify.com).
---------
Co-authored-by: Dev Ojha
Co-authored-by: Anton Kaliaev
* delete md
* changelog
* changelog
---------
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Dev Ojha
Co-authored-by: Anton Kaliaev
(cherry picked from commit 7cbbf3121539a907e4e4d9d5bd89d383933ff26c)
Co-authored-by: Adam Tucker
---
CHANGELOG.md | 3 +++
types/block.go | 16 +++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 81540d0398..f9f9d623ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/types/block.go b/types/block.go
index c93acf85c2..9d3436f2af 100644
--- a/types/block.go
+++ b/types/block.go
@@ -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.
@@ -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.