cmd, core, eth: disable prefetch by default, fix #1718 (#1719)

This commit is contained in:
Daniel Liu 2025-11-16 13:52:48 +08:00 committed by GitHub
parent 999b775d8e
commit b2664ec363
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 27 deletions

View file

@ -1508,7 +1508,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
cfg.NoPruning = ctx.String(GCModeFlag.Name) == "archive"
cfg.NoPrefetch = !ctx.Bool(CachePrefetchFlag.Name)
cfg.Prefetch = ctx.Bool(CachePrefetchFlag.Name)
// Read the value from the flag no matter if it's set or not.
cfg.Preimages = ctx.Bool(CachePreimagesFlag.Name)
if cfg.NoPruning && !cfg.Preimages {
@ -1778,12 +1778,12 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (chain *core.B
Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}
cache := &core.CacheConfig{
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
TrieCleanNoPrefetch: !ctx.Bool(CachePrefetchFlag.Name),
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
TrieDirtyDisabled: ctx.String(GCModeFlag.Name) == "archive",
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
Preimages: ctx.Bool(CachePreimagesFlag.Name),
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
TrieCleanPrefetch: ctx.Bool(CachePrefetchFlag.Name),
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
TrieDirtyDisabled: ctx.String(GCModeFlag.Name) == "archive",
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
Preimages: ctx.Bool(CachePreimagesFlag.Name),
}
if cache.TrieDirtyDisabled && !cache.Preimages {
cache.Preimages = true

View file

@ -131,12 +131,12 @@ const (
// CacheConfig contains the configuration values for the trie database
// that's resident in a blockchain.
type CacheConfig struct {
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
TrieCleanNoPrefetch bool // Whether to disable heuristic state prefetching for followup blocks
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
TrieDirtyDisabled bool // Whether to disable trie write caching and GC altogether (archive node)
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
Preimages bool // Whether to store preimage of trie key to the disk
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
TrieCleanPrefetch bool // Whether to enable heuristic state prefetching for followup blocks
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
TrieDirtyDisabled bool // Whether to disable trie write caching and GC altogether (archive node)
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
Preimages bool // Whether to store preimage of trie key to the disk
}
type ResultProcessBlock struct {
@ -1784,7 +1784,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
// If we have a followup block, run that against the current state to pre-cache
// transactions and probabilistically some of the account/storage trie nodes.
var followupInterrupt atomic.Bool
if !bc.cacheConfig.TrieCleanNoPrefetch {
if bc.cacheConfig.TrieCleanPrefetch {
if followup, err := it.peek(); followup != nil && err == nil {
throwaway, _ := state.New(parent.Root, bc.stateCache)

View file

@ -194,12 +194,12 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
var (
vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording}
cacheConfig = &core.CacheConfig{
TrieCleanLimit: config.TrieCleanCache,
TrieCleanNoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
Preimages: config.Preimages,
TrieCleanLimit: config.TrieCleanCache,
TrieCleanPrefetch: config.Prefetch,
TrieDirtyLimit: config.TrieDirtyCache,
TrieDirtyDisabled: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
Preimages: config.Preimages,
}
)
if config.VMTrace != "" {

View file

@ -72,8 +72,8 @@ type Config struct {
NetworkId uint64
SyncMode downloader.SyncMode
NoPruning bool // Whether to disable pruning and flush everything to disk
NoPrefetch bool // Whether to disable prefetching and only load state on demand
NoPruning bool // Whether to disable pruning and flush everything to disk
Prefetch bool // Whether to enable prefetching and only load state on demand
// Light client options
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests

View file

@ -23,7 +23,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
NetworkId uint64
SyncMode downloader.SyncMode
NoPruning bool
NoPrefetch bool
Prefetch bool
LightServ int `toml:",omitempty"`
LightPeers int `toml:",omitempty"`
SkipBcVersionCheck bool `toml:"-"`
@ -44,6 +44,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
VMTrace string
VMTraceJsonConfig string
RPCGasCap uint64
RPCEVMTimeout time.Duration
RPCTxFeeCap float64
}
var enc Config
@ -51,7 +52,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.NetworkId = c.NetworkId
enc.SyncMode = c.SyncMode
enc.NoPruning = c.NoPruning
enc.NoPrefetch = c.NoPrefetch
enc.Prefetch = c.Prefetch
enc.LightServ = c.LightServ
enc.LightPeers = c.LightPeers
enc.SkipBcVersionCheck = c.SkipBcVersionCheck
@ -72,6 +73,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.VMTrace = c.VMTrace
enc.VMTraceJsonConfig = c.VMTraceJsonConfig
enc.RPCGasCap = c.RPCGasCap
enc.RPCEVMTimeout = c.RPCEVMTimeout
enc.RPCTxFeeCap = c.RPCTxFeeCap
return &enc, nil
}
@ -83,7 +85,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
NetworkId *uint64
SyncMode *downloader.SyncMode
NoPruning *bool
NoPrefetch *bool
Prefetch *bool
LightServ *int `toml:",omitempty"`
LightPeers *int `toml:",omitempty"`
SkipBcVersionCheck *bool `toml:"-"`
@ -104,6 +106,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
VMTrace *string
VMTraceJsonConfig *string
RPCGasCap *uint64
RPCEVMTimeout *time.Duration
RPCTxFeeCap *float64
}
var dec Config
@ -122,8 +125,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.NoPruning != nil {
c.NoPruning = *dec.NoPruning
}
if dec.NoPrefetch != nil {
c.NoPrefetch = *dec.NoPrefetch
if dec.Prefetch != nil {
c.Prefetch = *dec.Prefetch
}
if dec.LightServ != nil {
c.LightServ = *dec.LightServ
@ -185,6 +188,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.RPCGasCap != nil {
c.RPCGasCap = *dec.RPCGasCap
}
if dec.RPCEVMTimeout != nil {
c.RPCEVMTimeout = *dec.RPCEVMTimeout
}
if dec.RPCTxFeeCap != nil {
c.RPCTxFeeCap = *dec.RPCTxFeeCap
}