cancun: change empty withdrawHash value of header; (#2350)

This commit is contained in:
GalaIO 2024-03-29 15:03:21 +08:00 committed by GitHub
parent 7c89c65a97
commit 9ab8565128
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 11 additions and 12 deletions

@ -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 {

@ -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)

@ -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

@ -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
}
@ -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

@ -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)
}

@ -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

@ -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 {
@ -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

@ -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