add --bal.blockingprefetch: if enabled, will ensure that when executing with a BAL, state loading tasks are completed before tx and state root calculation. can be used with --bal.prefetchworkers

This commit is contained in:
Jared Wasinger 2026-05-06 13:48:19 -04:00
parent 457491107a
commit ac8354d4ca
5 changed files with 20 additions and 4 deletions

View file

@ -160,6 +160,7 @@ var (
utils.BeaconCheckpointFileFlag, utils.BeaconCheckpointFileFlag,
utils.LogSlowBlockFlag, utils.LogSlowBlockFlag,
utils.PrefetchWorkersFlag, utils.PrefetchWorkersFlag,
utils.BlockingPrefetch,
}, utils.NetworkFlags, utils.DatabaseFlags) }, utils.NetworkFlags, utils.DatabaseFlags)
rpcFlags = []cli.Flag{ rpcFlags = []cli.Flag{

View file

@ -721,6 +721,12 @@ var (
Category: flags.MiscCategory, Category: flags.MiscCategory,
} }
BlockingPrefetch = &cli.BoolFlag{
Name: "bal.blockingprefetch",
Usage: "only relevant when executing in parallel with a BAL: if true, the prefetcher will block tx/state-root calculation until all scheduled fetching tasks have completed.",
Category: flags.MiscCategory,
}
// RPC settings // RPC settings
IPCDisabledFlag = &cli.BoolFlag{ IPCDisabledFlag = &cli.BoolFlag{
Name: "ipcdisable", Name: "ipcdisable",
@ -2467,7 +2473,8 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
TrienodeHistory: ctx.Int64(TrienodeHistoryFlag.Name), TrienodeHistory: ctx.Int64(TrienodeHistoryFlag.Name),
NodeFullValueCheckpoint: uint32(ctx.Uint(TrienodeHistoryFullValueCheckpointFlag.Name)), NodeFullValueCheckpoint: uint32(ctx.Uint(TrienodeHistoryFullValueCheckpointFlag.Name)),
PrefetchWorkers: int(ctx.Uint(PrefetchWorkersFlag.Name)), PrefetchWorkers: int(ctx.Uint(PrefetchWorkersFlag.Name)),
BlockingPrefetch: ctx.Bool(BlockingPrefetch.Name),
// Disable transaction indexing/unindexing. // Disable transaction indexing/unindexing.
TxLookupLimit: -1, TxLookupLimit: -1,

View file

@ -211,7 +211,9 @@ type BlockChainConfig struct {
Overrides *ChainOverrides // Optional chain config overrides Overrides *ChainOverrides // Optional chain config overrides
VmConfig vm.Config // Config options for the EVM Interpreter VmConfig vm.Config // Config options for the EVM Interpreter
PrefetchWorkers int // number of concurrent go-routines for BAL state prefetching // BAL-related
PrefetchWorkers int // number of concurrent go-routines for BAL state prefetching
BlockingPrefetch bool // whether the prefetch should block further execution until it finishes
// TxLookupLimit specifies the maximum number of blocks from head for which // TxLookupLimit specifies the maximum number of blocks from head for which
// transaction hashes will be indexed. // transaction hashes will be indexed.
@ -599,7 +601,7 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
useAsyncReads := bc.cfg.BALExecutionMode != bal.BALExecutionNoBatchIO useAsyncReads := bc.cfg.BALExecutionMode != bal.BALExecutionNoBatchIO
al := block.AccessList() // TODO: make the return of this method not be a pointer al := block.AccessList() // TODO: make the return of this method not be a pointer
accessListReader := bal.NewAccessListReader(*al) accessListReader := bal.NewAccessListReader(*al)
prefetchReader, err := sdb.ReaderEIP7928(parentRoot, accessListReader.StorageKeys(useAsyncReads), bc.cfg.PrefetchWorkers) prefetchReader, err := sdb.ReaderEIP7928(parentRoot, accessListReader.StorageKeys(useAsyncReads), bc.cfg.PrefetchWorkers, bc.cfg.BlockingPrefetch)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -240,7 +240,7 @@ func (db *CachingDB) ReadersWithCacheStats(stateRoot common.Hash) (Reader, Reade
} }
// ReaderEIP7928 creates a state reader with the manner of Block-level accessList. // ReaderEIP7928 creates a state reader with the manner of Block-level accessList.
func (db *CachingDB) ReaderEIP7928(stateRoot common.Hash, accessList map[common.Address][]common.Hash, threads int) (Reader, error) { func (db *CachingDB) ReaderEIP7928(stateRoot common.Hash, accessList map[common.Address][]common.Hash, threads int, block bool) (Reader, error) {
base, err := db.StateReader(stateRoot) base, err := db.StateReader(stateRoot)
if err != nil { if err != nil {
return nil, err return nil, err
@ -250,6 +250,11 @@ func (db *CachingDB) ReaderEIP7928(stateRoot common.Hash, accessList map[common.
// Construct the state reader with background prefetching // Construct the state reader with background prefetching
pr := newPrefetchStateReader(r, accessList, threads) pr := newPrefetchStateReader(r, accessList, threads)
if block {
if err := pr.Wait(); err != nil {
panic("wat do")
}
}
return newReaderWithPrefetch(db.codedb.Reader(), pr, pr), nil return newReaderWithPrefetch(db.codedb.Reader(), pr, pr), nil
} }

View file

@ -162,6 +162,7 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter
}, },
StatelessSelfValidation: witness, StatelessSelfValidation: witness,
NoPrefetch: true, NoPrefetch: true,
BlockingPrefetch: true,
PrefetchWorkers: 100, // note: this is totally unrelated to NoPrefetch, just for BAL execution PrefetchWorkers: 100, // note: this is totally unrelated to NoPrefetch, just for BAL execution
} }
if snapshotter { if snapshotter {