@@ -302,7 +302,7 @@ pub(crate) struct ExecutionCache {
302302
303303 /// Per-account storage cache: outer cache keyed by Address, inner cache tracks that account’s
304304 /// storage slots.
305- storage_cache : Cache < Address , AccountStorageCache > ,
305+ storage_cache : Cache < Address , Arc < AccountStorageCache > > ,
306306
307307 /// Cache for basic account information (nonce, balance, code hash).
308308 account_cache : Cache < Address , Option < Account > > ,
@@ -340,15 +340,15 @@ impl ExecutionCache {
340340 where
341341 I : IntoIterator < Item = ( StorageKey , Option < StorageValue > ) > ,
342342 {
343- let account_cache = self . storage_cache . get ( & address) . unwrap_or_else ( || {
344- let account_cache = AccountStorageCache :: default ( ) ;
345- self . storage_cache . insert ( address, account_cache. clone ( ) ) ;
346- account_cache
347- } ) ;
343+ let account_cache = self . storage_cache . get ( & address) . unwrap_or_default ( ) ;
348344
349345 for ( key, value) in storage_entries {
350346 account_cache. insert_storage ( key, value) ;
351347 }
348+
349+ // Insert to the cache so that moka picks up on the changed size, even though the actual
350+ // value (the Arc<AccountStorageCache>) is the same
351+ self . storage_cache . insert ( address, account_cache) ;
352352 }
353353
354354 /// Invalidate storage for specific account
@@ -465,7 +465,7 @@ impl ExecutionCacheBuilder {
465465 const TIME_TO_IDLE : Duration = Duration :: from_secs ( 3600 ) ; // 1 hour
466466
467467 let storage_cache = CacheBuilder :: new ( self . storage_cache_entries )
468- . weigher ( |_key : & Address , value : & AccountStorageCache | -> u32 {
468+ . weigher ( |_key : & Address , value : & Arc < AccountStorageCache > | -> u32 {
469469 // values based on results from measure_storage_cache_overhead test
470470 let base_weight = 39_000 ;
471471 let slots_weight = value. len ( ) * 218 ;
0 commit comments