Skip to content

Commit

Permalink
remove Requests in BlockBody
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Nov 13, 2024
1 parent 25eae93 commit 49e1095
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 35 deletions.
3 changes: 1 addition & 2 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ func (dlp *downloadTesterPeer) RequestBodies(hashes []common.Hash, sink chan *et
txsHashes = make([]common.Hash, len(bodies))
uncleHashes = make([]common.Hash, len(bodies))
withdrawalHashes = make([]common.Hash, len(bodies))
requestsHashes = make([]common.Hash, len(bodies))
)
hasher := trie.NewStackTrie(nil)
for i, body := range bodies {
Expand All @@ -291,7 +290,7 @@ func (dlp *downloadTesterPeer) RequestBodies(hashes []common.Hash, sink chan *et
res := &eth.Response{
Req: req,
Res: (*eth.BlockBodiesResponse)(&bodies),
Meta: [][]common.Hash{txsHashes, uncleHashes, withdrawalHashes, requestsHashes},
Meta: [][]common.Hash{txsHashes, uncleHashes, withdrawalHashes},
Time: 1,
Done: make(chan error, 1), // Ignore the returned status
}
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/fetchers_concurrent_bodies.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func (q *bodyQueue) request(peer *peerConnection, req *fetchRequest, resCh chan
// deliver is responsible for taking a generic response packet from the concurrent
// fetcher, unpacking the body data and delivering it to the downloader's queue.
func (q *bodyQueue) deliver(peer *peerConnection, packet *eth.Response) (int, error) {
txs, uncles, withdrawals, sidecars, requests := packet.Res.(*eth.BlockBodiesResponse).Unpack()
txs, uncles, withdrawals, sidecars := packet.Res.(*eth.BlockBodiesResponse).Unpack()
hashsets := packet.Meta.([][]common.Hash) // {txs hashes, uncle hashes, withdrawal hashes, requests hashes}

accepted, err := q.queue.DeliverBodies(peer.id, txs, hashsets[0], uncles, hashsets[1], withdrawals, hashsets[2], sidecars, requests, hashsets[3])
accepted, err := q.queue.DeliverBodies(peer.id, txs, hashsets[0], uncles, hashsets[1], withdrawals, hashsets[2], sidecars)
switch {
case err == nil && len(txs) == 0:
peer.log.Trace("Requested bodies delivered")
Expand Down
15 changes: 1 addition & 14 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, hashes []comm
func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListHashes []common.Hash,
uncleLists [][]*types.Header, uncleListHashes []common.Hash,
withdrawalLists [][]*types.Withdrawal, withdrawalListHashes []common.Hash, sidecars []types.BlobSidecars,
requestsLists [][]*types.Request, requestsListHashes []common.Hash) (int, error) {
) (int, error) {
q.lock.Lock()
defer q.lock.Unlock()

Expand All @@ -812,19 +812,6 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
return errInvalidBody
}
}
if header.RequestsHash == nil {
// nil hash means that requests should not be present in body
if requestsLists[index] != nil {
return errInvalidBody
}
} else { // non-nil hash: body must have requests
if requestsLists[index] == nil {
return errInvalidBody
}
if requestsListHashes[index] != *header.RequestsHash {
return errInvalidBody
}
}
// Blocks must have a number of blobs corresponding to the header gas usage,
// and zero before the Cancun hardfork.
var blobs int
Expand Down
2 changes: 1 addition & 1 deletion eth/downloader/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func XTestDelivery(t *testing.T) {
uncleHashes[i] = types.CalcUncleHash(uncles)
}
time.Sleep(100 * time.Millisecond)
_, err := q.DeliverBodies(peer.id, txset, txsHashes, uncleset, uncleHashes, nil, nil, nil, nil, nil)
_, err := q.DeliverBodies(peer.id, txset, txsHashes, uncleset, uncleHashes, nil, nil, nil)
if err != nil {
fmt.Printf("delivered %d bodies %v\n", len(txset), err)
}
Expand Down
2 changes: 1 addition & 1 deletion eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (f *BlockFetcher) loop() {
case res := <-resCh:
res.Done <- nil
// Ignoring withdrawals here, will set it to empty later if EmptyWithdrawalsHash in header.
txs, uncles, _, sidecars, _ := res.Res.(*eth.BlockBodiesResponse).Unpack()
txs, uncles, _, sidecars := res.Res.(*eth.BlockBodiesResponse).Unpack()
f.FilterBodies(peer, txs, uncles, sidecars, time.Now())

case <-timeout.C:
Expand Down
6 changes: 1 addition & 5 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func handleBlockBodies(backend Backend, msg Decoder, peer *Peer) error {
txsHashes = make([]common.Hash, len(res.BlockBodiesResponse))
uncleHashes = make([]common.Hash, len(res.BlockBodiesResponse))
withdrawalHashes = make([]common.Hash, len(res.BlockBodiesResponse))
requestsHashes = make([]common.Hash, len(res.BlockBodiesResponse))
)
hasher := trie.NewStackTrie(nil)
for i, body := range res.BlockBodiesResponse {
Expand All @@ -373,11 +372,8 @@ func handleBlockBodies(backend Backend, msg Decoder, peer *Peer) error {
if body.Withdrawals != nil {
withdrawalHashes[i] = types.DeriveSha(types.Withdrawals(body.Withdrawals), hasher)
}
if body.Requests != nil {
requestsHashes[i] = types.DeriveSha(types.Requests(body.Requests), hasher)
}
}
return [][]common.Hash{txsHashes, uncleHashes, withdrawalHashes, requestsHashes}
return [][]common.Hash{txsHashes, uncleHashes, withdrawalHashes}
}
return peer.dispatchResponse(&Response{
id: res.RequestId,
Expand Down
8 changes: 3 additions & 5 deletions eth/protocols/eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,21 @@ type BlockBody struct {
Uncles []*types.Header // Uncles contained within a block
Withdrawals []*types.Withdrawal `rlp:"optional"` // Withdrawals contained within a block
Sidecars types.BlobSidecars `rlp:"optional"` // Sidecars contained within a block
Requests []*types.Request `rlp:"optional"` // Requests contained within a block
}

// Unpack retrieves the transactions and uncles from the range packet and returns
// them in a split flat format that's more consistent with the internal data structures.
func (p *BlockBodiesResponse) Unpack() ([][]*types.Transaction, [][]*types.Header, [][]*types.Withdrawal, []types.BlobSidecars, [][]*types.Request) {
func (p *BlockBodiesResponse) Unpack() ([][]*types.Transaction, [][]*types.Header, [][]*types.Withdrawal, []types.BlobSidecars) {
var (
txset = make([][]*types.Transaction, len(*p))
uncleset = make([][]*types.Header, len(*p))
withdrawalset = make([][]*types.Withdrawal, len(*p))
sidecarset = make([]types.BlobSidecars, len(*p))
requestset = make([][]*types.Request, len(*p))
)
for i, body := range *p {
txset[i], uncleset[i], withdrawalset[i], sidecarset[i], requestset[i] = body.Transactions, body.Uncles, body.Withdrawals, body.Sidecars, body.Requests
txset[i], uncleset[i], withdrawalset[i], sidecarset[i] = body.Transactions, body.Uncles, body.Withdrawals, body.Sidecars
}
return txset, uncleset, withdrawalset, sidecarset, requestset
return txset, uncleset, withdrawalset, sidecarset
}

// GetReceiptsRequest represents a block receipts query.
Expand Down
7 changes: 2 additions & 5 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2361,11 +2361,8 @@ func TestFillBlobTransaction(t *testing.T) {
Config: params.MergedTestChainConfig,
Alloc: types.GenesisAlloc{},
}
emptyBlob = new(kzg4844.Blob)
emptyBlobs = []kzg4844.Blob{*emptyBlob}
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
emptyBlobs = []kzg4844.Blob{emptyBlob}
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
)
b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
b.SetPoS()
Expand Down

0 comments on commit 49e1095

Please sign in to comment.