diff --git a/cmd/geth/main.go b/cmd/geth/main.go index da1623be7c..ad8ab1fc1e 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -159,6 +159,7 @@ var ( utils.BeaconCheckpointFlag, utils.BeaconCheckpointFileFlag, utils.LogSlowBlockFlag, + utils.PrefetchWorkersFlag, }, utils.NetworkFlags, utils.DatabaseFlags) rpcFlags = []cli.Flag{ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 7d8c47e4f7..27e840ee64 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -28,6 +28,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" godebug "runtime/debug" "strconv" "strings" @@ -713,6 +714,13 @@ var ( Category: flags.MiscCategory, } + PrefetchWorkersFlag = &cli.UintFlag{ + Name: "bal.prefetchworkers", + Usage: "The number of concurrent state loading tasks to perform when prefetching BAL state. Default to the number of cpus", + Value: uint(runtime.NumCPU()), + Category: flags.MiscCategory, + } + // RPC settings IPCDisabledFlag = &cli.BoolFlag{ Name: "ipcdisable", @@ -2459,6 +2467,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh TrienodeHistory: ctx.Int64(TrienodeHistoryFlag.Name), NodeFullValueCheckpoint: uint32(ctx.Uint(TrienodeHistoryFullValueCheckpointFlag.Name)), + PrefetchWorkers: int(ctx.Uint(PrefetchWorkersFlag.Name)), // Disable transaction indexing/unindexing. TxLookupLimit: -1, diff --git a/core/blockchain.go b/core/blockchain.go index 4009a5414e..33172aff91 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -211,6 +211,8 @@ type BlockChainConfig struct { Overrides *ChainOverrides // Optional chain config overrides VmConfig vm.Config // Config options for the EVM Interpreter + PrefetchWorkers int // number of concurrent go-routines for BAL state prefetching + // TxLookupLimit specifies the maximum number of blocks from head for which // transaction hashes will be indexed. // @@ -597,7 +599,7 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block * useAsyncReads := bc.cfg.BALExecutionMode != bal.BALExecutionNoBatchIO al := block.AccessList() // TODO: make the return of this method not be a pointer accessListReader := bal.NewAccessListReader(*al) - prefetchReader, err := sdb.ReaderEIP7928(parentRoot, accessListReader.StorageKeys(useAsyncReads), runtime.NumCPU()) + prefetchReader, err := sdb.ReaderEIP7928(parentRoot, accessListReader.StorageKeys(useAsyncReads), bc.cfg.PrefetchWorkers) if err != nil { return nil, err }