Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifications to support snap sync #152

Merged
merged 9 commits into from
Jun 25, 2024
Prev Previous commit
Next Next commit
Add method to header to check for pre-gingerbread
  • Loading branch information
piersy committed Jun 24, 2024
commit cf391dedfb0d9711982ae322d87d1427521c899c
20 changes: 13 additions & 7 deletions core/types/celo_block.go
Original file line number Diff line number Diff line change
@@ -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
}