Update backend.go

This commit is contained in:
VolodymyrBg 2025-03-05 19:54:24 +02:00 committed by GitHub
parent f9fd6ceb42
commit cad5df59b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -197,10 +197,25 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
TrieTimeLimit: config.TrieTimeout, TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache, SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages, Preimages: config.Preimages,
StateHistory: config.StateHistory,
StateScheme: scheme, StateScheme: scheme,
} }
) )
// Configure state history based on history mode
if config.HistoryMode == ethconfig.AllHistory {
// In all history mode, retain all state history if specified as 0,
// otherwise use the configured value
cacheConfig.StateHistory = config.StateHistory
} else if config.HistoryMode == ethconfig.PrunedHistory {
// In pruned history mode, ensure state history is limited
if config.StateHistory == 0 {
// If it's set to 0 (unlimited), use a default value for pruned mode
cacheConfig.StateHistory = 2350000 // Same default as TransactionHistory
} else {
cacheConfig.StateHistory = config.StateHistory
}
}
if config.VMTrace != "" { if config.VMTrace != "" {
traceConfig := json.RawMessage("{}") traceConfig := json.RawMessage("{}")
if config.VMTraceJsonConfig != "" { if config.VMTraceJsonConfig != "" {
@ -220,7 +235,24 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.OverrideVerkle != nil { if config.OverrideVerkle != nil {
overrides.OverrideVerkle = config.OverrideVerkle overrides.OverrideVerkle = config.OverrideVerkle
} }
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, &config.TransactionHistory)
// Set transaction history based on history mode
var txHistoryLimit *uint64
if config.HistoryMode == ethconfig.AllHistory {
// In all history mode, use the configured transaction history
txHistoryLimit = &config.TransactionHistory
} else if config.HistoryMode == ethconfig.PrunedHistory {
// In pruned history mode, ensure transaction history is limited
// Make a copy to avoid modifying the original config
limit := config.TransactionHistory
if limit == 0 {
// If it's set to 0 (unlimited), use a reasonable default for pruned mode
limit = 2350000 // Default value in ethconfig.Defaults
}
txHistoryLimit = &limit
}
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, txHistoryLimit)
if err != nil { if err != nil {
return nil, err return nil, err
} }