Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidecar fetching changes for 4844 #2283

Merged
merged 13 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ type Block struct {
ReceivedAt time.Time
ReceivedFrom interface{}

// blobs provides DA check
blobs BlobTxSidecars
// sidecars provides DA check
sidecars BlobTxSidecars
}

// "external" block encoding. used for eth protocol, etc.
Expand Down Expand Up @@ -455,7 +455,7 @@ func (b *Block) SanityCheck() error {
}

func (b *Block) Blobs() BlobTxSidecars {
return b.blobs
return b.sidecars
}

type writeCounter uint64
Expand Down Expand Up @@ -520,12 +520,12 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
}

// WithBlobs returns a block containing the given blobs.
func (b *Block) WithBlobs(blobs BlobTxSidecars) *Block {
func (b *Block) WithBlobs(sidecars BlobTxSidecars) *Block {
block := &Block{
header: b.header,
transactions: b.transactions,
uncles: b.uncles,
blobs: blobs,
sidecars: sidecars,
}
return block
}
Expand Down
34 changes: 18 additions & 16 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ type headerFilterTask struct {
time time.Time // Arrival time of the headers
}

// bodyFilterTask represents a batch of block bodies (transactions and uncles)
// bodyFilterTask represents a batch of block bodies (transactions, sidecars and uncles)
// needing fetcher filtering.
type bodyFilterTask struct {
peer string // The source peer of block bodies
transactions [][]*types.Transaction // Collection of transactions per block bodies
uncles [][]*types.Header // Collection of uncles per block bodies
time time.Time // Arrival time of the blocks' contents
peer string // The source peer of block bodies
transactions [][]*types.Transaction // Collection of transactions per block bodies
uncles [][]*types.Header // Collection of uncles per block bodies
sidecars [][]*types.BlobTxSidecar // Collection of sidecars per block bodies
time time.Time // Arrival time of the blocks' contents
}

// blockOrHeaderInject represents a schedules import operation.
Expand Down Expand Up @@ -314,29 +315,29 @@ func (f *BlockFetcher) FilterHeaders(peer string, headers []*types.Header, time

// FilterBodies extracts all the block bodies that were explicitly requested by
// the fetcher, returning those that should be handled differently.
func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header) {
log.Trace("Filtering bodies", "peer", peer, "txs", len(transactions), "uncles", len(uncles))
func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, sidecars [][]*types.BlobTxSidecar, time time.Time) ([][]*types.Transaction, [][]*types.Header, [][]*types.BlobTxSidecar) {
log.Trace("Filtering bodies", "peer", peer, "txs", len(transactions), "uncles", len(uncles), "sidecars", len(sidecars))

// Send the filter channel to the fetcher
filter := make(chan *bodyFilterTask)

select {
case f.bodyFilter <- filter:
case <-f.quit:
return nil, nil
return nil, nil, nil
}
// Request the filtering of the body list
select {
case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, time: time}:
case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, sidecars: sidecars, time: time}:
case <-f.quit:
return nil, nil
return nil, nil, nil
}
// Retrieve the bodies remaining after filtering
select {
case task := <-filter:
return task.transactions, task.uncles
return task.transactions, task.uncles, task.sidecars
case <-f.quit:
return nil, nil
return nil, nil, nil
}
}

Expand Down Expand Up @@ -576,9 +577,8 @@ func (f *BlockFetcher) loop() {
case res := <-resCh:
res.Done <- nil
// Ignoring withdrawals here, since the block fetcher is not used post-merge.
// todo 4844 is it ok to ignore sidecars here too?
txs, uncles, _, _ := res.Res.(*eth.BlockBodiesResponse).Unpack()
f.FilterBodies(peer, txs, uncles, time.Now())
txs, uncles, _, sidecars := res.Res.(*eth.BlockBodiesResponse).Unpack()
f.FilterBodies(peer, txs, uncles, sidecars, time.Now())

case <-timeout.C:
// The peer didn't respond in time. The request
Expand Down Expand Up @@ -696,7 +696,7 @@ func (f *BlockFetcher) loop() {
blocks := []*types.Block{}
// abort early if there's nothing explicitly requested
if len(f.completing) > 0 {
for i := 0; i < len(task.transactions) && i < len(task.uncles); i++ {
for i := 0; i < len(task.transactions) && i < len(task.uncles) && i < len(task.sidecars); i++ {
// Match up a body to any possible completion request
var (
matched = false
Expand All @@ -723,6 +723,7 @@ func (f *BlockFetcher) loop() {
matched = true
if f.getBlock(hash) == nil {
block := types.NewBlockWithHeader(announce.header).WithBody(task.transactions[i], task.uncles[i])
block = block.WithBlobs(task.sidecars[i])
block.ReceivedAt = task.time
blocks = append(blocks, block)
} else {
Expand All @@ -732,6 +733,7 @@ func (f *BlockFetcher) loop() {
if matched {
task.transactions = append(task.transactions[:i], task.transactions[i+1:]...)
task.uncles = append(task.uncles[:i], task.uncles[i+1:]...)
task.sidecars = append(task.sidecars[:i], task.sidecars[i+1:]...)
i--
continue
}
Expand Down
8 changes: 0 additions & 8 deletions eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,6 @@
}

protos := []p2p.Protocol{
{
Name: "eth",
Version: ETH67,
},
{
Name: "eth",
Version: ETH68,
Expand All @@ -604,10 +600,6 @@
},
}
caps := []p2p.Cap{
{
Name: "eth",
Version: ETH67,
},
{
Name: "eth",
Version: ETH68,
Expand All @@ -634,7 +626,7 @@
}
})
}

Check failure on line 629 in eth/protocols/eth/handler_test.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.21.x, ubuntu-latest)

unnecessary trailing newline (whitespace)
}

func makeBlkBlobs(n, nPerTx int) types.BlobTxSidecars {
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type BlockHeadersRLPPacket struct {
type NewBlockPacket struct {
Block *types.Block
TD *big.Int
Sidecars []*types.BlobTxSidecar `rlp:"optional"`
Sidecars types.BlobTxSidecars `rlp:"optional"`
}

// sanityCheck verifies that the values are reasonable, as a DoS protection
Expand Down
Loading