From cf391dedfb0d9711982ae322d87d1427521c899c Mon Sep 17 00:00:00 2001 From: Piers Powlesland Date: Tue, 18 Jun 2024 15:32:54 +0100 Subject: [PATCH] Add method to header to check for pre-gingerbread --- core/types/celo_block.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/types/celo_block.go b/core/types/celo_block.go index c657fa4153..075c856087 100644 --- a/core/types/celo_block.go +++ b/core/types/celo_block.go @@ -86,13 +86,7 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error { // EncodeRLP implements encodes the Header to an RLP data stream. func (h *Header) EncodeRLP(w io.Writer) error { - // We check for a pre gingerbread header by looking for (GasLimit == 0) - // here. We don't use Difficulty because CopyHeader can end up setting a - // nil Difficulty to a zero difficulty, so testing for nil difficulty is - // not reliable, and post gingerbread difficulty is hardcoded to zero. Also - // testing for base fee is not reliable because some older eth blocks had - // no base fee and they are used in some tests. - if h.GasLimit == 0 { + if h.IsPreGingerbread() { // Encode the header encodedHeader := beforeGingerbreadHeader{ ParentHash: h.ParentHash, @@ -153,3 +147,15 @@ func isPreGingerbreadHeader(buf []byte) (bool, error) { return contentSize == common.AddressLength, nil } + +// Returns if the header is a gingerbread header by looking at the gas limit. +func (h *Header) IsPreGingerbread() bool { + // We check for a pre gingerbread header by looking for (GasLimit == 0) + // here. We don't use Difficulty because we ensure that headers have a zero + // difficulty, even if it's not set in the rlp encoded form (we do this + // because the go ethereum codebase assumed non nil difficulties) and post + // gingerbread difficulty is hardcoded to zero. Also testing for base fee + // is not reliable because some older eth blocks had no base fee and they + // are used in some tests. + return h.GasLimit == 0 +}