diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index 6e405cbe9a..535584aafc 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -61,8 +61,12 @@ var ( // maxDiffLayers is the maximum diff layers allowed in the layer tree. maxDiffLayers = 128 - // historyCacheSize is the maximum size of history cache. - historyCacheSize = 4096 + // historyIndexCacheSize is the maximum count of history index cache. + // Each indexBlockDesc is 14bytes, assume each account has 10 descriptors, + // then the total memory usage is ~54MB. + historyIndexCacheSize = 409600 + // historyBlockCacheSize is the maximum count of history block cache. + historyBlockCacheSize = 4096 ) // layer is the interface implemented by all state layers which includes some @@ -246,7 +250,7 @@ func New(diskdb ethdb.Database, config *Config, isVerkle bool) *Database { config: config, diskdb: diskdb, hasher: merkleNodeHasher, - cacher: newHistoryCacher(historyCacheSize), + cacher: newHistoryCacher(historyIndexCacheSize, historyBlockCacheSize), } // Establish a dedicated database namespace tailored for verkle-specific // data, ensuring the isolation of both verkle and merkle tree data. It's diff --git a/triedb/pathdb/history_reader.go b/triedb/pathdb/history_reader.go index 0d9bac1965..e9f00e91ec 100644 --- a/triedb/pathdb/history_reader.go +++ b/triedb/pathdb/history_reader.go @@ -198,10 +198,10 @@ type historyCacher struct { } // newHistoryCacher creates a new historyCacher instance. -func newHistoryCacher(size int) *historyCacher { +func newHistoryCacher(indexSize, blockSize int) *historyCacher { return &historyCacher{ - index: lru.NewCache[string, []byte](size), - block: lru.NewCache[string, []byte](size), + index: lru.NewCache[string, []byte](indexSize), + block: lru.NewCache[string, []byte](blockSize), } }