Skip to content

Commit

Permalink
eth: early check the number of delivered blob transactions (#586)
Browse files Browse the repository at this point in the history
Part of commit ethereum/go-ethereum@1f9b69b.

This commit add an early check for the number of delivered blob transactions
with header's blob gas used when receiving block body packet.
  • Loading branch information
minh-bq authored Sep 30, 2024
1 parent 0eb8e91 commit d5246d0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)

Expand Down Expand Up @@ -765,6 +766,21 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, uncleLi
if types.CalcUncleHash(uncleLists[index]) != header.UncleHash {
return errInvalidBody
}
// Blocks must have a number of blobs corresponding to the header gas usage,
// and zero before the Cancun hardfork
var blobs int
for _, tx := range txLists[index] {
blobs += len(tx.BlobHashes())
}
if header.BlobGasUsed != nil {
if want := *header.BlobGasUsed / params.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated
return errInvalidBody
}
} else {
if blobs != 0 {
return errInvalidBody
}
}
return nil
}

Expand Down

0 comments on commit d5246d0

Please sign in to comment.