From fa2367e4a180cd4eb6d12be34d0bb0543c019b90 Mon Sep 17 00:00:00 2001 From: gop Date: Thu, 14 Sep 2023 12:24:03 -0500 Subject: [PATCH] bugfix: Prevent crash on the first block because of race in writing the phcache --- core/slice.go | 2 +- core/types/block.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/slice.go b/core/slice.go index f775d31711..eabd50f754 100644 --- a/core/slice.go +++ b/core/slice.go @@ -252,7 +252,7 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do if !exist { sl.bestPhKey = sl.config.GenesisHash sl.writePhCache(block.Hash(), pendingHeaderWithTermini) - bestPh = pendingHeaderWithTermini + bestPh = types.EmptyPendingHeader() log.Error("BestPh Key does not exist for", "key", sl.bestPhKey) } diff --git a/core/types/block.go b/core/types/block.go index 822d612f48..7f415cd425 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -992,14 +992,14 @@ func (ph *PendingHeader) SetTermini(termini Termini) { ph.termini = CopyTermini(termini) } -func emptyPendingHeader() PendingHeader { +func EmptyPendingHeader() PendingHeader { pendingHeader := PendingHeader{} pendingHeader.SetTermini(EmptyTermini()) return pendingHeader } func NewPendingHeader(header *Header, termini Termini) PendingHeader { - emptyPh := emptyPendingHeader() + emptyPh := EmptyPendingHeader() emptyPh.SetHeader(header) emptyPh.SetTermini(termini) return emptyPh