fix: ensure empty withdrawals after cancun#2384
Conversation
| }, | ||
| func() error { | ||
| // Withdrawals are present after the Shanghai fork. | ||
| if !header.EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
rollback and align with geth
| if hash := types.DeriveSha(block.Withdrawals(), trie.NewStackTrie(nil)); hash != *header.WithdrawalsHash { | ||
| return fmt.Errorf("withdrawals root hash mismatch (header value %x, calculated %x)", *header.WithdrawalsHash, hash) | ||
| } | ||
| } else if len(block.Withdrawals()) != 0 { // Withdrawals turn into empty from nil when BlockBody has Sidecars |
There was a problem hiding this comment.
rollback and align with geth
|
|
||
| // EmptyWithdrawalsHash returns true if there are no WithdrawalsHash for this header/block. | ||
| func (h *Header) EmptyWithdrawalsHash() bool { | ||
| return h.WithdrawalsHash == nil || *h.WithdrawalsHash == EmptyWithdrawalsHash |
There was a problem hiding this comment.
make it equivalent to other Emptyxxx function, such as EmptyReceipts
| } | ||
| if !header.EmptyBody() { | ||
| item.pending.Store(item.pending.Load() | (1 << bodyType)) | ||
| } else if !header.EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
rollback and align with geth
| if uncleListHashes[index] != header.UncleHash { | ||
| return errInvalidBody | ||
| } | ||
| if header.EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
rollback and align with geth
| if header.EmptyWithdrawalsHash() { | ||
| if header.WithdrawalsHash == nil { | ||
| // nil hash means that withdrawals should not be present in body | ||
| if len(withdrawalLists[index]) != 0 { |
There was a problem hiding this comment.
rollback and align with geth
| return nil, err | ||
| } | ||
| // Pre-shanghai blocks | ||
| if block.Header().EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
rollback and align with geth
| // env.receipts = receipts | ||
| finalizeBlockTimer.UpdateSince(finalizeStart) | ||
|
|
||
| if block.Header().EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
set empty withdraws at miner side
| matched = true | ||
| if f.getBlock(hash) == nil { | ||
| block := types.NewBlockWithHeader(announce.header).WithBody(task.transactions[i], task.uncles[i]) | ||
| if block.Header().EmptyWithdrawalsHash() { |
There was a problem hiding this comment.
set empty withdraws at fetcher side
There was a problem hiding this comment.
Do we need similar changes in downloader here?
bsc/eth/downloader/downloader.go
Line 1392 in 38db9bf
There was a problem hiding this comment.
Do we need similar changes in downloader here?
bsc/eth/downloader/downloader.go
Line 1392 in 38db9bf
esult.Withdrawals is already empty now
There was a problem hiding this comment.
Ok. But under what condition the above if statement of fetcher will be true?
core/types/block.go
Outdated
| @@ -195,7 +195,7 @@ func (h *Header) EmptyReceipts() bool { | |||
|
|
|||
| // EmptyWithdrawalsHash returns true if there are no WithdrawalsHash for this header/block. | |||
There was a problem hiding this comment.
Maybe we should change the description of this function to make it more clear.
There was a problem hiding this comment.
Maybe we should change the description of this function to make it more clear.
ok
| txsHashes[i] = types.DeriveSha(types.Transactions(body.Transactions), hasher) | ||
| uncleHashes[i] = types.CalcUncleHash(body.Uncles) | ||
| // Withdrawals may be not nil, but a empty value when Sidecars not empty | ||
| if len(body.Withdrawals) > 0 { |
There was a problem hiding this comment.
rollback and align with geth
|
for block header/body payload, pls refer: https://forum.bnbchain.org/t/faq-about-eip-4844-on-bsc/2620#q11-block-headerbody-payload-change-11 |
Description
fix: ensure empty withdrawals after cancun
Rationale
tell us why we need these changes...
Example
add an example CLI or API response...
Changes
Notable changes: