From a20543b23410cfd597c91b76af2bddf1848393e4 Mon Sep 17 00:00:00 2001
From: Adi Seredinschi
Date: Fri, 24 Feb 2023 17:45:22 +0100
Subject: [PATCH 1/2] changelog
---
.changelog/unreleased/bug-fixes/386-quick-fix-needproofblock.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 .changelog/unreleased/bug-fixes/386-quick-fix-needproofblock.md
diff --git a/.changelog/unreleased/bug-fixes/386-quick-fix-needproofblock.md b/.changelog/unreleased/bug-fixes/386-quick-fix-needproofblock.md
new file mode 100644
index 00000000000..2180086ce97
--- /dev/null
+++ b/.changelog/unreleased/bug-fixes/386-quick-fix-needproofblock.md
@@ -0,0 +1,2 @@
+- `[consensus]` ([\#386](https://github.com/cometbft/cometbft/pull/386)) Short-term fix for the case when `needProofBlock` cannot find previous block meta by defaulting to the creation of a new proof block. (@adizere)
+ - Special thanks to the [Vega.xyz](https://vega.xyz/) team, and in particular to Zohar (@ze97286), for reporting the problem and working with us to get to a fix.
From 7edce06d5833c378913a06f2f24a9ea49b8fea88 Mon Sep 17 00:00:00 2001
From: Adi Seredinschi
Date: Fri, 24 Feb 2023 15:28:53 +0100
Subject: [PATCH 2/2] Added log and short-circuit in needProofBlock
---
consensus/state.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/consensus/state.go b/consensus/state.go
index 686e01c418c..c2b72150b20 100644
--- a/consensus/state.go
+++ b/consensus/state.go
@@ -1054,7 +1054,9 @@ func (cs *State) needProofBlock(height int64) bool {
lastBlockMeta := cs.blockStore.LoadBlockMeta(height - 1)
if lastBlockMeta == nil {
- panic(fmt.Sprintf("needProofBlock: last block meta for height %d not found", height-1))
+ // See https://github.com/cometbft/cometbft/issues/370
+ cs.Logger.Info("short-circuited needProofBlock", "height", height, "InitialHeight", cs.state.InitialHeight)
+ return true
}
return !bytes.Equal(cs.state.AppHash, lastBlockMeta.Header.AppHash)