Skip to content

Commit

Permalink
Revert calls of encode/decode for Header
Browse files Browse the repository at this point in the history
  • Loading branch information
Kourin1996 committed Dec 4, 2024
1 parent 62dc9b2 commit c03d68a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/types/celo_block.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"bytes"
"io"
"math/big"

Expand Down Expand Up @@ -45,8 +44,7 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error {
if preGingerbread { // Address
// Before gingerbread
decodedHeader := BeforeGingerbreadHeader{}
str := rlp.NewStream(bytes.NewReader(raw), uint64(len(raw)))
err = decodedHeader.DecodeRLP(str)
err = rlp.DecodeBytes(raw, &decodedHeader)

h.ParentHash = decodedHeader.ParentHash
h.Coinbase = decodedHeader.Coinbase
Expand All @@ -62,8 +60,7 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error {
} else {
// After gingerbread
decodedHeader := AfterGingerbreadHeader{}
str := rlp.NewStream(bytes.NewReader(raw), uint64(len(raw)))
err = decodedHeader.DecodeRLP(str)
err = rlp.DecodeBytes(raw, &decodedHeader)

h.ParentHash = decodedHeader.ParentHash
h.UncleHash = decodedHeader.UncleHash
Expand Down Expand Up @@ -106,7 +103,7 @@ func (h *Header) EncodeRLP(w io.Writer) error {
Extra: h.Extra,
}

return encodedHeader.EncodeRLP(w)
return rlp.Encode(w, &encodedHeader)
}

// After gingerbread
Expand All @@ -133,7 +130,7 @@ func (h *Header) EncodeRLP(w io.Writer) error {
ParentBeaconRoot: h.ParentBeaconRoot,
}

return encodedHeader.EncodeRLP(w)
return rlp.Encode(w, &encodedHeader)
}

// isPreGingerbreadHeader introspects the header rlp to check the length of the
Expand Down

0 comments on commit c03d68a

Please sign in to comment.