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

cancun: change empty withdrawHash value of header; #2350

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
// types.EmptyWithdrawalsHash represents a empty value when EIP-4895 enabled,
// here, EIP-4895 still be disabled, value expected to be `common.Hash{}` is only to feet the demand of rlp encode/decode
case header.WithdrawalsHash == nil || *header.WithdrawalsHash != common.Hash{}:
// here, EIP-4895 still be disabled, value expected to be `types.EmptyWithdrawalsHash` is only to feet the demand of rlp encode/decode
case header.WithdrawalsHash == nil || *header.WithdrawalsHash != types.EmptyWithdrawalsHash:
return errors.New("header has wrong WithdrawalsHash")
}
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
header.ExcessBlobGas = &excessBlobGas
header.BlobGasUsed = new(uint64)
if cm.config.Parlia != nil {
header.WithdrawalsHash = new(common.Hash)
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
if cm.config.Parlia == nil {
header.ParentBeaconRoot = new(common.Hash)
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (g *Genesis) ToBlock() *types.Block {
}
if conf.IsCancun(num, g.Timestamp) {
if conf.Parlia != nil {
head.WithdrawalsHash = new(common.Hash)
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
}

// EIP-4788: The parentBeaconBlockRoot of the genesis block is always
Expand Down
5 changes: 2 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (h *Header) SanityCheck() error {
// that is: no transactions, no uncles and no withdrawals.
func (h *Header) EmptyBody() bool {
if h.WithdrawalsHash != nil {
return h.TxHash == EmptyTxsHash && (*h.WithdrawalsHash == EmptyWithdrawalsHash || *h.WithdrawalsHash == common.Hash{})
return h.TxHash == EmptyTxsHash && *h.WithdrawalsHash == EmptyWithdrawalsHash
}
return h.TxHash == EmptyTxsHash && h.UncleHash == EmptyUncleHash
}
Expand All @@ -195,8 +195,7 @@ func (h *Header) EmptyReceipts() bool {

// EmptyWithdrawalsHash returns true if there are no WithdrawalsHash for this header/block.
func (h *Header) EmptyWithdrawalsHash() bool {
// TODO(GalaIO): if check EmptyWithdrawalsHash in here?
return h.WithdrawalsHash == nil || *h.WithdrawalsHash == common.Hash{}
return h.WithdrawalsHash == nil || *h.WithdrawalsHash == EmptyWithdrawalsHash
}

// Body is a simple (mutable, non-safe) data container for storing and moving
Expand Down
2 changes: 1 addition & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func getBody(block *types.Block) *engine.ExecutionPayloadBodyV1 {
}

// Post-shanghai withdrawals MUST be set to empty slice instead of nil
if withdrawals == nil && !block.Header().EmptyWithdrawalsHash() {
if withdrawals == nil && block.Header().WithdrawalsHash != nil {
withdrawals = make([]*types.Withdrawal, 0)
}

Expand Down
2 changes: 1 addition & 1 deletion graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func (b *Block) WithdrawalsRoot(ctx context.Context) (*common.Hash, error) {
return nil, err
}
// Pre-shanghai blocks
if header.EmptyWithdrawalsHash() {
if header.WithdrawalsHash == nil {
return nil, nil
}
return header.WithdrawalsHash, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
if head.BaseFee != nil {
result["baseFeePerGas"] = (*hexutil.Big)(head.BaseFee)
}
if !head.EmptyWithdrawalsHash() {
if head.WithdrawalsHash != nil {
result["withdrawalsRoot"] = head.WithdrawalsHash
}
if head.BlobGasUsed != nil {
Expand Down Expand Up @@ -1561,7 +1561,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
uncleHashes[i] = uncle.Hash()
}
fields["uncles"] = uncleHashes
if !block.Header().EmptyWithdrawalsHash() {
if block.Header().WithdrawalsHash != nil {
fields["withdrawals"] = block.Withdrawals()
}
return fields
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
header.BlobGasUsed = new(uint64)
header.ExcessBlobGas = &excessBlobGas
if w.chainConfig.Parlia != nil {
header.WithdrawalsHash = new(common.Hash)
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
if w.chainConfig.Parlia == nil {
header.ParentBeaconRoot = genParams.beaconRoot
Expand Down
Loading