Skip to content

Commit

Permalink
Include RequestsHash in header encoding/decoding (#301)
Browse files Browse the repository at this point in the history
Updates header encoding/decoding

A new field 'RequestsHash' was added to the header, and we needed to run
go generate to regenerate the generated encoding/decoding. We also
needed to 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.

These changes allowed us to unskip the tests that were skipped during the celo11 rebase.

Fixes celo-org/celo-blockchain-planning#854
  • Loading branch information
piersy authored Dec 20, 2024
1 parent 57eef86 commit ba64a6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 51 deletions.
46 changes: 2 additions & 44 deletions core/types/celo_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,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 @@ -108,29 +88,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.

2 changes: 0 additions & 2 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,6 @@ func allBodies(blocks []*types.Block) []*types.Body {
}

func TestGetBlockBodiesByHash(t *testing.T) {
t.Skip("Skipped during rebase. Fix by setting gas limit or https://github.com/celo-org/celo-blockchain-planning/issues/588.")
node, eth, blocks := setupBodies(t)
api := NewConsensusAPI(eth)
defer node.Close()
Expand Down Expand Up @@ -1439,7 +1438,6 @@ func TestGetBlockBodiesByHash(t *testing.T) {
}

func TestGetBlockBodiesByRange(t *testing.T) {
t.Skip("Skipped during rebase. Fix by setting gas limit or https://github.com/celo-org/celo-blockchain-planning/issues/588.")
node, eth, blocks := setupBodies(t)
api := NewConsensusAPI(eth)
defer node.Close()
Expand Down

0 comments on commit ba64a6c

Please sign in to comment.