Skip to content

Commit

Permalink
Update header encoding/decoding
Browse files Browse the repository at this point in the history
A new field 'RequestsHash' was added to the header, and we needed to run
go generate to regenerate the generated encoding/decoding and also update
celo_block.go to account for the new field.

Simplified the encoding and decoding in celo_block.go by simply casting
the header into the right type for encoding/decoding. This ensures that
we won't need to update celo_block.go in the future when fields are
added or removed.
  • Loading branch information
piersy committed Dec 18, 2024
1 parent e26f2c8 commit 962ad37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 49 deletions.
46 changes: 2 additions & 44 deletions core/types/celo_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,7 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error {
// After gingerbread
decodedHeader := AfterGingerbreadHeader{}
err = rlp.DecodeBytes(raw, &decodedHeader)

h.ParentHash = decodedHeader.ParentHash
h.UncleHash = decodedHeader.UncleHash
h.Coinbase = decodedHeader.Coinbase
h.Root = decodedHeader.Root
h.TxHash = decodedHeader.TxHash
h.ReceiptHash = decodedHeader.ReceiptHash
h.Bloom = decodedHeader.Bloom
h.Difficulty = decodedHeader.Difficulty
h.Number = decodedHeader.Number
h.GasLimit = decodedHeader.GasLimit
h.GasUsed = decodedHeader.GasUsed
h.Time = decodedHeader.Time
h.Extra = decodedHeader.Extra
h.MixDigest = decodedHeader.MixDigest
h.Nonce = decodedHeader.Nonce
h.BaseFee = decodedHeader.BaseFee
h.WithdrawalsHash = decodedHeader.WithdrawalsHash
h.BlobGasUsed = decodedHeader.BlobGasUsed
h.ExcessBlobGas = decodedHeader.ExcessBlobGas
h.ParentBeaconRoot = decodedHeader.ParentBeaconRoot
*h = Header(decodedHeader)
}

return err
Expand All @@ -107,29 +87,7 @@ func (h *Header) EncodeRLP(w io.Writer) error {
}

// After gingerbread
encodedHeader := AfterGingerbreadHeader{
ParentHash: h.ParentHash,
UncleHash: h.UncleHash,
Coinbase: h.Coinbase,
Root: h.Root,
TxHash: h.TxHash,
ReceiptHash: h.ReceiptHash,
Bloom: h.Bloom,
Difficulty: h.Difficulty,
Number: h.Number,
GasLimit: h.GasLimit,
GasUsed: h.GasUsed,
Time: h.Time,
Extra: h.Extra,
MixDigest: h.MixDigest,
Nonce: h.Nonce,
BaseFee: h.BaseFee,
WithdrawalsHash: h.WithdrawalsHash,
BlobGasUsed: h.BlobGasUsed,
ExcessBlobGas: h.ExcessBlobGas,
ParentBeaconRoot: h.ParentBeaconRoot,
}

encodedHeader := AfterGingerbreadHeader(*h)
return rlp.Encode(w, &encodedHeader)
}

Expand Down
26 changes: 21 additions & 5 deletions core/types/gen_after_gingerbread_header_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 962ad37

Please sign in to comment.