Skip to content

Commit

Permalink
core,eth/downloader: add missing Requests for downloader and its vali…
Browse files Browse the repository at this point in the history
…dation in ValidateBody
  • Loading branch information
islishude committed Sep 12, 2024
1 parent ec69830 commit 399e2cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return errors.New("withdrawals present in block body")
}

if header.RequestsHash != nil {
if block.Requests() == nil {
return errors.New("missing requests in block body")
}
if hash := types.DeriveSha(block.Requests(), trie.NewStackTrie(nil)); hash != *header.RequestsHash {
return fmt.Errorf("requests root hash mismatch (header value %x, calculated %x)", *header.RequestsHash, hash)
}
} else if block.Requests() != nil {
return errors.New("requests present in block body")
}

// Blob transactions may be present after the Cancun fork.
var blobs int
for i, tx := range block.Transactions() {
Expand Down
12 changes: 10 additions & 2 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type fetchResult struct {
Transactions types.Transactions
Receipts types.Receipts
Withdrawals types.Withdrawals
Requests types.Requests
}

func newFetchResult(header *types.Header, fastSync bool) *fetchResult {
Expand All @@ -78,8 +79,13 @@ func newFetchResult(header *types.Header, fastSync bool) *fetchResult {
}
if !header.EmptyBody() {
item.pending.Store(item.pending.Load() | (1 << bodyType))
} else if header.WithdrawalsHash != nil {
item.Withdrawals = make(types.Withdrawals, 0)
} else {
if header.WithdrawalsHash != nil {
item.Withdrawals = make(types.Withdrawals, 0)
}
if header.RequestsHash != nil {
item.Requests = make(types.Requests, 0)
}
}
if fastSync && !header.EmptyReceipts() {
item.pending.Store(item.pending.Load() | (1 << receiptType))
Expand All @@ -93,6 +99,7 @@ func (f *fetchResult) body() types.Body {
Transactions: f.Transactions,
Uncles: f.Uncles,
Withdrawals: f.Withdrawals,
Requests: f.Requests,
}
}

Expand Down Expand Up @@ -860,6 +867,7 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
result.Transactions = txLists[index]
result.Uncles = uncleLists[index]
result.Withdrawals = withdrawalLists[index]
result.Requests = requestsLists[index]
result.SetBodyDone()
}
return q.deliver(id, q.blockTaskPool, q.blockTaskQueue, q.blockPendPool,
Expand Down

0 comments on commit 399e2cb

Please sign in to comment.