Skip to content

Commit 2215719

Browse files
cskiralySahil-4555
authored andcommitted
core/txpool/blobpool: filter blob txs with sidecar version (ethereum#32577)
As a consequence of moving blob sidecar version migration code around, we ended up building blocks with a mix of v0 and v1 blob transactions (different proof encoding in the sidecar). This PR makes sure we are not building illegal blocks after Osaka. Blob migration is left for another PR. Related issues and PRs: - ethereum#31791 - ethereum#32347 - ethereum#31966 - ethereum#32235 --------- Signed-off-by: Csaba Kiraly <[email protected]>
1 parent f85a8bb commit 2215719

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292
type blobTxMeta struct {
9393
hash common.Hash // Transaction hash to maintain the lookup table
9494
vhashes []common.Hash // Blob versioned hashes to maintain the lookup table
95+
version byte // Blob transaction version to determine proof type
9596

9697
id uint64 // Storage ID in the pool's persistent store
9798
storageSize uint32 // Byte size in the pool's persistent store
@@ -115,10 +116,16 @@ type blobTxMeta struct {
115116

116117
// newBlobTxMeta retrieves the indexed metadata fields from a blob transaction
117118
// and assembles a helper struct to track in memory.
119+
// Requires the transaction to have a sidecar (or that we introduce a special version tag for no-sidecar).
118120
func newBlobTxMeta(id uint64, size uint64, storageSize uint32, tx *types.Transaction) *blobTxMeta {
121+
if tx.BlobTxSidecar() == nil {
122+
// This should never happen, as the pool only admits blob transactions with a sidecar
123+
panic("missing blob tx sidecar")
124+
}
119125
meta := &blobTxMeta{
120126
hash: tx.Hash(),
121127
vhashes: tx.BlobHashes(),
128+
version: tx.BlobTxSidecar().Version,
122129
id: id,
123130
storageSize: storageSize,
124131
size: size,
@@ -1660,7 +1667,7 @@ func (p *BlobPool) drop() {
16601667
func (p *BlobPool) Pending(filter txpool.PendingFilter) map[common.Address][]*txpool.LazyTransaction {
16611668
// If only plain transactions are requested, this pool is unsuitable as it
16621669
// contains none, don't even bother.
1663-
if filter.OnlyPlainTxs {
1670+
if !filter.BlobTxs {
16641671
return nil
16651672
}
16661673
// Track the amount of time waiting to retrieve the list of pending blob txs
@@ -1681,6 +1688,11 @@ func (p *BlobPool) Pending(filter txpool.PendingFilter) map[common.Address][]*tx
16811688
for addr, txs := range p.index {
16821689
lazies := make([]*txpool.LazyTransaction, 0, len(txs))
16831690
for _, tx := range txs {
1691+
// Skip v0 or v1 blob transactions depending on the filter
1692+
if tx.version != filter.BlobVersion {
1693+
break // skip the rest because of nonce ordering
1694+
}
1695+
16841696
// If transaction filtering was requested, discard badly priced ones
16851697
if filter.MinTip != nil && filter.BaseFee != nil {
16861698
if tx.execFeeCap.Lt(filter.BaseFee) {

core/txpool/legacypool/legacypool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func (pool *LegacyPool) ContentFrom(addr common.Address) ([]*types.Transaction,
508508
func (pool *LegacyPool) Pending(filter txpool.PendingFilter) map[common.Address][]*txpool.LazyTransaction {
509509
// If only blob transactions are requested, this pool is unsuitable as it
510510
// contains none, don't even bother.
511-
if filter.OnlyBlobTxs {
511+
if filter.BlobTxs {
512512
return nil
513513
}
514514
pool.mu.Lock()

core/txpool/subpool.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ type PendingFilter struct {
7878
BlobFee *uint256.Int // Minimum 4844 blobfee needed to include a blob transaction
7979
GasLimitCap uint64 // Maximum gas can be used for a single transaction execution (0 means no limit)
8080

81-
OnlyPlainTxs bool // Return only plain EVM transactions (peer-join announces, block space filling)
82-
OnlyBlobTxs bool // Return only blob transactions (block blob-space filling)
81+
// When BlobTxs true, return only blob transactions (block blob-space filling)
82+
// when false, return only non-blob txs (peer-join announces, block space filling)
83+
BlobTxs bool
84+
BlobVersion byte // Blob tx version to include. 0 means pre-Osaka, 1 means Osaka and later
8385
}
8486

8587
// TxMetadata denotes the metadata of a transaction.

eth/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// syncTransactions starts sending all currently pending transactions to the given peer.
2626
func (h *handler) syncTransactions(p *eth.Peer) {
2727
var hashes []common.Hash
28-
for _, batch := range h.txpool.Pending(txpool.PendingFilter{OnlyPlainTxs: true}) {
28+
for _, batch := range h.txpool.Pending(txpool.PendingFilter{BlobTxs: false}) {
2929
for _, tx := range batch {
3030
hashes = append(hashes, tx.Hash)
3131
}

miner/worker.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,15 @@ func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment)
481481
if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) {
482482
filter.GasLimitCap = params.MaxTxGas
483483
}
484-
filter.OnlyPlainTxs, filter.OnlyBlobTxs = true, false
484+
filter.BlobTxs = false
485485
pendingPlainTxs := miner.txpool.Pending(filter)
486486

487-
filter.OnlyPlainTxs, filter.OnlyBlobTxs = false, true
487+
filter.BlobTxs = true
488+
if miner.chainConfig.IsOsaka(env.header.Number, env.header.Time) {
489+
filter.BlobVersion = types.BlobSidecarVersion1
490+
} else {
491+
filter.BlobVersion = types.BlobSidecarVersion0
492+
}
488493
pendingBlobTxs := miner.txpool.Pending(filter)
489494

490495
// Split the pending transactions into locals and remotes.

0 commit comments

Comments
 (0)