Skip to content

Commit

Permalink
fix(beacon): update ExecutableData parameters (ethereum#83)
Browse files Browse the repository at this point in the history
* fix(beacon): update `ExecutableData` parameters

* chore: update workflow

* feat: update types

* feat: update api.go

* feat: update queue.go

* chore: update workflow
  • Loading branch information
davidtaikocha authored May 28, 2023
1 parent f839977 commit f4b7892
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 59 deletions.
87 changes: 49 additions & 38 deletions beacon/engine/gen_ed.go

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

35 changes: 18 additions & 17 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ type blockMetadataMarshaling struct {
//
//go:generate go run github.com/fjl/gencodec -type ExecutableData -field-override executableDataMarshaling -out gen_ed.go
type ExecutableData struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
Number uint64 `json:"blockNumber" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Timestamp uint64 `json:"timestamp" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
Transactions [][]byte `json:"transactions" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
TxHash common.Hash `json:"txHash"` // CHANGE(taiko): allow passing txHash directly instead of transactions list
TaikoBlock bool // CHANGE(taiko): whether this is a Taiko L2 block, only used by ExecutableDataToBlock
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
FeeRecipient common.Address `json:"feeRecipient" gencodec:"required"`
StateRoot common.Hash `json:"stateRoot" gencodec:"required"`
ReceiptsRoot common.Hash `json:"receiptsRoot" gencodec:"required"`
LogsBloom []byte `json:"logsBloom" gencodec:"required"`
Random common.Hash `json:"prevRandao" gencodec:"required"`
Number uint64 `json:"blockNumber" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Timestamp uint64 `json:"timestamp" gencodec:"required"`
ExtraData []byte `json:"extraData" gencodec:"required"`
BaseFeePerGas *big.Int `json:"baseFeePerGas" gencodec:"required"`
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
Transactions [][]byte `json:"transactions"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
TxHash common.Hash `json:"txHash"` // CHANGE(taiko): allow passing txHash directly instead of transactions list
WithdrawalsHash common.Hash `json:"withdrawalsHash"` // CHANGE(taiko): allow passing WithdrawalsHash directly instead of withdrawals
TaikoBlock bool // CHANGE(taiko): whether this is a Taiko L2 block, only used by ExecutableDataToBlock
}

// JSON type overrides for executableData.
Expand Down
8 changes: 4 additions & 4 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ func (api *ConsensusAPI) NewPayloadV1(params engine.ExecutableData) (engine.Payl
// NewPayloadV2 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
if api.eth.BlockChain().Config().IsShanghai(params.Timestamp) {
if params.Withdrawals == nil {
if params.Withdrawals == nil &&
(api.eth.BlockChain().Config().Taiko && params.WithdrawalsHash == (common.Hash{})) { // CHANGE(taiko): allow only passing `WithdrawalsHash`
return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(fmt.Errorf("nil withdrawals post-shanghai"))
}
} else if params.Withdrawals != nil {
Expand Down Expand Up @@ -523,8 +524,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData) (engine.Payloa
err error
)
params.TaikoBlock = api.eth.BlockChain().Config().Taiko
if api.eth.BlockChain().Config().Taiko && params.Transactions == nil {
h := types.CalcWithdrawalsRootTaiko(params.Withdrawals)
if api.eth.BlockChain().Config().Taiko && params.Transactions == nil && params.Withdrawals == nil {
block = types.NewBlockWithHeader(&types.Header{
ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash,
Expand All @@ -541,7 +541,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData) (engine.Payloa
BaseFee: params.BaseFeePerGas,
Extra: params.ExtraData,
MixDigest: params.Random,
WithdrawalsHash: &h,
WithdrawalsHash: &params.WithdrawalsHash,
})
} else {
block, err = engine.ExecutableDataToBlock(params)
Expand Down
5 changes: 5 additions & 0 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package downloader
import (
"errors"
"fmt"
"os"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -792,6 +793,10 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
if withdrawalLists[index] == nil {
return errInvalidBody
}
// CHANGE(taiko): change the empty withdrawalsRoot hash to EmptyCodeHash
if withdrawalListHashes[index] == types.EmptyRootHash && os.Getenv("TAIKO_TEST") == "" {
withdrawalListHashes[index] = types.EmptyCodeHash
}
if withdrawalListHashes[index] != *header.WithdrawalsHash {
return errInvalidBody
}
Expand Down

0 comments on commit f4b7892

Please sign in to comment.