@@ -25,7 +25,7 @@ import (
25
25
"sync"
26
26
"time"
27
27
28
- "github.com/allegro/bigcache "
28
+ "github.com/VictoriaMetrics/fastcache "
29
29
"github.com/ethereum/go-ethereum/common"
30
30
"github.com/ethereum/go-ethereum/ethdb"
31
31
"github.com/ethereum/go-ethereum/log"
@@ -69,7 +69,7 @@ const secureKeyLength = 11 + 32
69
69
type Database struct {
70
70
diskdb ethdb.KeyValueStore // Persistent storage for matured trie nodes
71
71
72
- cleans * bigcache. BigCache // GC friendly memory cache of clean node RLPs
72
+ cleans * fastcache. Cache // GC friendly memory cache of clean node RLPs
73
73
dirties map [common.Hash ]* cachedNode // Data and references relationships of dirty nodes
74
74
oldest common.Hash // Oldest tracked node, flush-list head
75
75
newest common.Hash // Newest tracked node, flush-list tail
@@ -296,16 +296,9 @@ func NewDatabase(diskdb ethdb.KeyValueStore) *Database {
296
296
// before its written out to disk or garbage collected. It also acts as a read cache
297
297
// for nodes loaded from disk.
298
298
func NewDatabaseWithCache (diskdb ethdb.KeyValueStore , cache int ) * Database {
299
- var cleans * bigcache. BigCache
299
+ var cleans * fastcache. Cache
300
300
if cache > 0 {
301
- cleans , _ = bigcache .NewBigCache (bigcache.Config {
302
- Shards : 1024 ,
303
- LifeWindow : time .Hour ,
304
- MaxEntriesInWindow : cache * 1024 ,
305
- MaxEntrySize : 512 ,
306
- HardMaxCacheSize : cache ,
307
- Hasher : trienodeHasher {},
308
- })
301
+ cleans = fastcache .New (cache * 1024 * 1024 )
309
302
}
310
303
return & Database {
311
304
diskdb : diskdb ,
@@ -381,7 +374,7 @@ func (db *Database) insertPreimage(hash common.Hash, preimage []byte) {
381
374
func (db * Database ) node (hash common.Hash ) node {
382
375
// Retrieve the node from the clean cache if available
383
376
if db .cleans != nil {
384
- if enc , err := db .cleans .Get (string ( hash [:])); err == nil && enc != nil {
377
+ if enc := db .cleans .Get (nil , hash [:]); enc != nil {
385
378
memcacheCleanHitMeter .Mark (1 )
386
379
memcacheCleanReadMeter .Mark (int64 (len (enc )))
387
380
return mustDecodeNode (hash [:], enc )
@@ -401,7 +394,7 @@ func (db *Database) node(hash common.Hash) node {
401
394
return nil
402
395
}
403
396
if db .cleans != nil {
404
- db .cleans .Set (string ( hash [:]) , enc )
397
+ db .cleans .Set (hash [:], enc )
405
398
memcacheCleanMissMeter .Mark (1 )
406
399
memcacheCleanWriteMeter .Mark (int64 (len (enc )))
407
400
}
@@ -417,7 +410,7 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) {
417
410
}
418
411
// Retrieve the node from the clean cache if available
419
412
if db .cleans != nil {
420
- if enc , err := db .cleans .Get (string ( hash [:])); err == nil && enc != nil {
413
+ if enc := db .cleans .Get (nil , hash [:]); enc != nil {
421
414
memcacheCleanHitMeter .Mark (1 )
422
415
memcacheCleanReadMeter .Mark (int64 (len (enc )))
423
416
return enc , nil
@@ -435,7 +428,7 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) {
435
428
enc , err := db .diskdb .Get (hash [:])
436
429
if err == nil && enc != nil {
437
430
if db .cleans != nil {
438
- db .cleans .Set (string ( hash [:]) , enc )
431
+ db .cleans .Set (hash [:], enc )
439
432
memcacheCleanMissMeter .Mark (1 )
440
433
memcacheCleanWriteMeter .Mark (int64 (len (enc )))
441
434
}
@@ -832,7 +825,7 @@ func (c *cleaner) Put(key []byte, rlp []byte) error {
832
825
}
833
826
// Move the flushed node into the clean cache to prevent insta-reloads
834
827
if c .db .cleans != nil {
835
- c .db .cleans .Set (string ( hash [:]) , rlp )
828
+ c .db .cleans .Set (hash [:], rlp )
836
829
}
837
830
return nil
838
831
}
0 commit comments