core/txpool/blobpool: allow toggling cache mode on and off

This commit is contained in:
Felix Lange 2026-06-12 18:01:17 +02:00
parent 1316b2ee79
commit 9527e04f48
2 changed files with 28 additions and 33 deletions

View file

@ -81,11 +81,11 @@ type Cache struct {
needCell bool needCell bool
// channels into loop // channels into loop
quit chan struct{} quit chan struct{}
topkRequest chan struct{} topkRequest chan struct{}
topkTimer mclock.Timer topkTimer mclock.Timer
hasBlobsCh chan []common.Hash // list of tx hashes that should be pinned hasBlobsCh chan []common.Hash // list of tx hashes that should be pinned
enableCellCh chan struct{} // signals the loop to switch to cell mode cellModeCh chan bool // signals the loop to switch cell mode on/offo
step func() // test hook fired after each loop iteration step func() // test hook fired after each loop iteration
@ -103,14 +103,14 @@ func NewCache(p *BlobPool) *Cache {
// It allows injecting a clock and a step hook. // It allows injecting a clock and a step hook.
func newCache(p *BlobPool, clock mclock.Clock, step func()) *Cache { func newCache(p *BlobPool, clock mclock.Clock, step func()) *Cache {
c := &Cache{ c := &Cache{
entries: make(map[common.Hash]*cachedBlob), entries: make(map[common.Hash]*cachedBlob),
blobpool: p, blobpool: p,
hasBlobsCh: make(chan []common.Hash, 1), hasBlobsCh: make(chan []common.Hash, 1),
clock: clock, clock: clock,
step: step, step: step,
quit: make(chan struct{}), quit: make(chan struct{}),
topkRequest: make(chan struct{}, 1), topkRequest: make(chan struct{}, 1),
enableCellCh: make(chan struct{}, 1), cellModeCh: make(chan bool, 1),
} }
c.wg.Add(1) c.wg.Add(1)
@ -311,9 +311,9 @@ func (c *Cache) GetCells(vhashes []common.Hash, mask types.CustodyBitmap) ([][]*
// blobs. This means we can also cache cells that lack enough blobs to // blobs. This means we can also cache cells that lack enough blobs to
// recover. It signals the loop to switch to cell mode and re-select // recover. It signals the loop to switch to cell mode and re-select
// transactions from this wider pool. // transactions from this wider pool.
func (c *Cache) EnableCell() { func (c *Cache) SetCellMode(on bool) {
select { select {
case c.enableCellCh <- struct{}{}: case c.cellModeCh <- on:
case <-c.quit: case <-c.quit:
} }
} }
@ -335,13 +335,11 @@ func (c *Cache) loop() {
c.update(want) c.update(want)
c.triggerTopKAfter(topKTimeout) c.triggerTopKAfter(topKTimeout)
case <-c.enableCellCh: case on := <-c.cellModeCh:
// CL supports cell-based blob retrieval; switch to cell mode and // This runs when the CL signals (non-)support for cell proofs. Enable/disable
// re-select immediately over the now-wider pool. needCell is only // cell mode and re-select immediately to force an update.
// touched here in the loop, so a fresh selection and update observe if c.needCell != on {
// a consistent value. c.needCell = on
if !c.needCell {
c.needCell = true
c.triggerTopK() c.triggerTopK()
} }

View file

@ -22,6 +22,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"slices"
"strconv" "strconv"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -1198,17 +1199,13 @@ func (api *ConsensusAPI) checkFork(timestamp uint64, forks ...forks.Fork) bool {
func (api *ConsensusAPI) ExchangeCapabilities(caps []string) []string { func (api *ConsensusAPI) ExchangeCapabilities(caps []string) []string {
valueT := reflect.TypeOf(api) valueT := reflect.TypeOf(api)
for _, cap := range caps { // If the CL supports getBlobsV4, we call EnableCell() on the
if cap == "engine_getBlobsV4" { // blob cache to skip the blob recovery process. This is a
// If the CL supports getBlobsV4, we call EnableCell() on the // one-directional toggle, which assumes that once the CL
// blob cache to skip the blob recovery process. This is a // supports getBlobsV4, it will not fall back to getBlobsV3
// one-directional toggle, which assumes that once the CL // again.
// supports getBlobsV4, it will not fall back to getBlobsV3 cellmode := slices.Contains(caps, "engine_getBlobsV4")
// again. api.eth.BlobCache().SetCellMode(cellmode)
api.eth.BlobCache().EnableCell()
break
}
}
ourCaps := make([]string, 0, valueT.NumMethod()) ourCaps := make([]string, 0, valueT.NumMethod())
for i := 0; i < valueT.NumMethod(); i++ { for i := 0; i < valueT.NumMethod(); i++ {