Skip to content

Commit

Permalink
eth: Add sidecars validation to sender and recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Sep 5, 2024
1 parent 24a46de commit 9ae3b8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,17 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
}
// Blocks must have a number of blobs corresponding to the header gas usage,
// and zero before the Cancun hardfork.
var blobs int
var (
blobs int
blobTxs int
)
for _, tx := range txLists[index] {
// Count the number of blobs to validate against the header's blobGasUsed
blobs += len(tx.BlobHashes())

// Validate the data blobs individually too
if tx.Type() == types.BlobTxType {
blobTxs++
if len(tx.BlobHashes()) == 0 {
return errInvalidBody
}
Expand Down Expand Up @@ -837,6 +841,9 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
}

// do some sanity check for sidecar
if blobTxs != len(sidecars[index]) {
return errInvalidBody
}
for _, sidecar := range sidecars[index] {
if err := sidecar.SanityCheck(header.Number, header.Hash()); err != nil {
return err
Expand Down
27 changes: 27 additions & 0 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)
Expand Down Expand Up @@ -228,7 +229,33 @@ func ServiceGetBlockBodiesQuery(chain *core.BlockChain, query GetBlockBodiesRequ
if body == nil {
continue
}
header := chain.GetHeaderByHash(hash)
if header == nil {
continue
}

sidecars := chain.GetSidecarsByHash(hash)
// Only check for sidecars validity when necessary
highest := chain.ChasingHead()
current := chain.CurrentHeader()
if highest == nil || highest.Number.Cmp(current.Number) < 0 {
highest = current
}
if header.Number.Uint64()+params.MinBlocksForBlobRequests >= highest.Number.Uint64() {
var blobTxs int
for _, tx := range body.Transactions {
if tx.Type() == types.BlobTxType {
blobTxs++
}
}
if blobTxs > 0 {
if len(sidecars) != blobTxs {
log.Warn("Failed to get block sidecars", "blob-txs", blobTxs, "sidecars", len(sidecars), "block", hash)
continue
}
}
}

bodyWithSidecars := &BlockBody{
Transactions: body.Transactions,
Uncles: body.Uncles,
Expand Down

0 comments on commit 9ae3b8a

Please sign in to comment.