Skip to content

Commit

Permalink
correct the cache size
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 26, 2024
1 parent 8145d03 commit 66388af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions jsonrpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type JSONRPCBackend struct {
blockHashCache *lru.Cache[common.Hash, uint64]

txLookupCache *lru.Cache[common.Hash, *rpctypes.RPCTransaction]
receiptsCache *lru.Cache[common.Hash, *coretypes.Receipt]
receiptCache *lru.Cache[common.Hash, *coretypes.Receipt]
logsCache *lru.Cache[uint64, []*coretypes.Log]

mut sync.Mutex // mutex for accMuts
Expand All @@ -48,7 +48,6 @@ type JSONRPCBackend struct {
const (
feeHistoryCacheSize = 2048
blockCacheLimit = 256
receiptsCacheLimit = 32
txLookupCacheLimit = 1024
)

Expand Down Expand Up @@ -80,14 +79,16 @@ func NewJSONRPCBackend(
queuedTxs: queuedTxs,
historyCache: lru.NewCache[cacheKey, processedFees](feeHistoryCacheSize),

// per block caches
headerCache: lru.NewCache[uint64, *coretypes.Header](blockCacheLimit),
blockTxsCache: lru.NewCache[uint64, []*rpctypes.RPCTransaction](blockCacheLimit),
blockReceiptsCache: lru.NewCache[uint64, []*coretypes.Receipt](blockCacheLimit),
blockHashCache: lru.NewCache[common.Hash, uint64](blockCacheLimit),
logsCache: lru.NewCache[uint64, []*coretypes.Log](cfg.LogCacheSize),

// per tx caches
txLookupCache: lru.NewCache[common.Hash, *rpctypes.RPCTransaction](txLookupCacheLimit),
receiptsCache: lru.NewCache[common.Hash, *coretypes.Receipt](receiptsCacheLimit),
logsCache: lru.NewCache[uint64, []*coretypes.Log](cfg.LogCacheSize),
receiptCache: lru.NewCache[common.Hash, *coretypes.Receipt](txLookupCacheLimit),

accMuts: make(map[string]*AccMut),

Expand Down
4 changes: 2 additions & 2 deletions jsonrpc/backend/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (b *JSONRPCBackend) getTransaction(hash common.Hash) (*rpctypes.RPCTransact
}

func (b *JSONRPCBackend) getReceipt(hash common.Hash) (*coretypes.Receipt, error) {
if receipt, ok := b.receiptsCache.Get(hash); ok {
if receipt, ok := b.receiptCache.Get(hash); ok {
return receipt, nil
}

Expand All @@ -425,7 +425,7 @@ func (b *JSONRPCBackend) getReceipt(hash common.Hash) (*coretypes.Receipt, error
return nil, NewTxIndexingError()
}

_ = b.receiptsCache.Add(hash, receipt)
_ = b.receiptCache.Add(hash, receipt)
return receipt, nil
}

Expand Down

0 comments on commit 66388af

Please sign in to comment.