Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ type BlockChainConfig struct {
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
ArchiveMode bool // Whether to enable the archive mode

// Address-specific cache sizes for biased caching (pathdb only)
// Maps account address to cache size in bytes
AddressCacheSizes map[common.Address]int

// State snapshot related options
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
SnapshotNoBuild bool // Whether the background generation is allowed
Expand Down Expand Up @@ -282,8 +286,9 @@ func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config {
// TODO(rjl493456442): The write buffer represents the memory limit used
// for flushing both trie data and state data to disk. The config name
// should be updated to eliminate the confusion.
WriteBufferSize: cfg.TrieDirtyLimit * 1024 * 1024,
NoAsyncFlush: cfg.TrieNoAsyncFlush,
WriteBufferSize: cfg.TrieDirtyLimit * 1024 * 1024,
NoAsyncFlush: cfg.TrieNoAsyncFlush,
AddressCacheSizes: cfg.AddressCacheSizes,
}
}
return config
Expand Down
25 changes: 13 additions & 12 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,19 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
}
options := &core.BlockChainConfig{
TrieCleanLimit: config.TrieCleanCache,
NoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
ArchiveMode: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
StateHistory: config.StateHistory,
StateScheme: scheme,
TriesInMemory: config.TriesInMemory,
ChainHistoryMode: config.HistoryMode,
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
TrieCleanLimit: config.TrieCleanCache,
NoPrefetch: config.NoPrefetch,
TrieDirtyLimit: config.TrieDirtyCache,
ArchiveMode: config.NoPruning,
TrieTimeLimit: config.TrieTimeout,
SnapshotLimit: config.SnapshotCache,
Preimages: config.Preimages,
StateHistory: config.StateHistory,
StateScheme: scheme,
TriesInMemory: config.TriesInMemory,
ChainHistoryMode: config.HistoryMode,
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
AddressCacheSizes: config.AddressCacheSizes,
VmConfig: vm.Config{
EnablePreimageRecording: config.EnablePreimageRecording,
},
Expand Down
4 changes: 4 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ type Config struct {
// This is the number of blocks for which logs will be cached in the filter system.
FilterLogCacheSize int

// Address-specific cache sizes for biased caching (pathdb only)
// Maps account address to cache size in bytes
AddressCacheSizes map[common.Address]int

// Mining options
Miner miner.Config

Expand Down
61 changes: 61 additions & 0 deletions internal/cli/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ type CacheConfig struct {
// Raise the open file descriptor resource limit (default = system fd limit)
FDLimit int `hcl:"fdlimit,optional" toml:"fdlimit,optional"`

// Address-specific cache sizes for biased caching (format: "address=sizeMB,address=sizeMB")
// Size is specified in MB (megabytes)
// Example: "0x1234...=1024,0x5678...=512" (1024MB and 512MB)
AddressCacheSizesRaw string `hcl:"addresscachesizes,optional" toml:"addresscachesizes,optional"`
AddressCacheSizes map[string]string `hcl:"-,optional" toml:"-"`

// GC settings
// GoMemLimit sets the soft memory limit for the runtime
GoMemLimit string `hcl:"gomemlimit,optional" toml:"gomemlimit,optional"`
Expand Down Expand Up @@ -1280,6 +1286,16 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
n.TrieTimeout = c.Cache.TrieTimeout
n.TriesInMemory = c.Cache.TriesInMemory
n.FilterLogCacheSize = c.Cache.FilterLogCacheSize

// Parse address-specific cache sizes
if c.Cache.AddressCacheSizesRaw != "" {
addressCacheSizes, err := parseAddressCacheSizes(c.Cache.AddressCacheSizesRaw)
if err != nil {
log.Warn("Failed to parse address cache sizes", "error", err)
} else {
n.AddressCacheSizes = addressCacheSizes
}
}
}

// History
Expand Down Expand Up @@ -1392,6 +1408,51 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
return &n, nil
}

// parseAddressCacheSizes parses address cache sizes from a string format
// Expected format: "address1=sizeMB1,address2=sizeMB2,..."
// Sizes are specified in MB (megabytes) and converted to bytes
// Example: "0x1234...=1024,0x5678...=512" means 1024MB and 512MB
func parseAddressCacheSizes(input string) (map[common.Address]int, error) {
result := make(map[common.Address]int)
if input == "" {
return result, nil
}

// Split by comma
pairs := strings.Split(input, ",")
for _, pair := range pairs {
pair = strings.TrimSpace(pair)
if pair == "" {
continue
}

// Split by equals
parts := strings.SplitN(pair, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid format for address cache size pair: %s", pair)
}

// Parse address
addressStr := strings.TrimSpace(parts[0])
if !strings.HasPrefix(addressStr, "0x") {
addressStr = "0x" + addressStr
}
address := common.HexToAddress(addressStr)

// Parse size in MB and convert to bytes
sizeMB, err := strconv.Atoi(strings.TrimSpace(parts[1]))
if err != nil {
return nil, fmt.Errorf("invalid size for address %s: %v (must be integer MB)", addressStr, err)
}

// Convert MB to bytes
sizeBytes := sizeMB * 1024 * 1024
result[address] = sizeBytes
}

return result, nil
}

var (
clientIdentifier = "bor"
gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
Expand Down
7 changes: 7 additions & 0 deletions internal/cli/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
Default: c.cliConfig.Cache.Preimages,
Group: "Cache",
})
f.StringFlag(&flagset.StringFlag{
Name: "cache.addresscachesizes",
Usage: "Address-specific cache sizes for biased caching in MB (format: address=sizeMB,address=sizeMB, e.g. 0x1234...=1024,0x5678...=512)",
Value: &c.cliConfig.Cache.AddressCacheSizesRaw,
Default: c.cliConfig.Cache.AddressCacheSizesRaw,
Group: "Cache",
})
f.Uint64Flag(&flagset.Uint64Flag{
Name: "cache.triesinmemory",
Usage: "Number of block states (tries) to keep in memory",
Expand Down
Loading
Loading