Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit d5246d0

Browse files
authored
eth: early check the number of delivered blob transactions (#586)
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.
1 parent 0eb8e91 commit d5246d0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

eth/downloader/queue.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/types"
3232
"github.com/ethereum/go-ethereum/log"
3333
"github.com/ethereum/go-ethereum/metrics"
34+
"github.com/ethereum/go-ethereum/params"
3435
"github.com/ethereum/go-ethereum/trie"
3536
)
3637

@@ -765,6 +766,21 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, uncleLi
765766
if types.CalcUncleHash(uncleLists[index]) != header.UncleHash {
766767
return errInvalidBody
767768
}
769+
// Blocks must have a number of blobs corresponding to the header gas usage,
770+
// and zero before the Cancun hardfork
771+
var blobs int
772+
for _, tx := range txLists[index] {
773+
blobs += len(tx.BlobHashes())
774+
}
775+
if header.BlobGasUsed != nil {
776+
if want := *header.BlobGasUsed / params.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated
777+
return errInvalidBody
778+
}
779+
} else {
780+
if blobs != 0 {
781+
return errInvalidBody
782+
}
783+
}
768784
return nil
769785
}
770786

0 commit comments

Comments
 (0)