From 399e2cb25cd400455d984cc0704a1cb92af08d30 Mon Sep 17 00:00:00 2001 From: islishude Date: Thu, 12 Sep 2024 17:33:09 +0800 Subject: [PATCH] core,eth/downloader: add missing Requests for downloader and its validation in ValidateBody --- core/block_validator.go | 11 +++++++++++ eth/downloader/queue.go | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index a944db0bf896..e26fc3a522de 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -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() { diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index adad45020040..474602a4bd9e 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -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 { @@ -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)) @@ -93,6 +99,7 @@ func (f *fetchResult) body() types.Body { Transactions: f.Transactions, Uncles: f.Uncles, Withdrawals: f.Withdrawals, + Requests: f.Requests, } } @@ -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,