File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -817,6 +817,15 @@ pub fn cli_app() -> Command {
817
817
. action ( ArgAction :: Set )
818
818
. display_order ( 0 )
819
819
)
820
+ . arg (
821
+ Arg :: new ( "state-cache-max-bytes" )
822
+ . long ( "state-cache-max-bytes" )
823
+ . value_name ( "BYTES" )
824
+ . help ( "Specifies the maximum size of the state cache in bytes" )
825
+ . default_value ( "536870912" )
826
+ . action ( ArgAction :: Set )
827
+ . display_order ( 0 )
828
+ )
820
829
/*
821
830
* Execution Layer Integration
822
831
*/
Original file line number Diff line number Diff line change @@ -377,6 +377,12 @@ pub fn get_config<E: EthSpec>(
377
377
. map_err ( |_| "state-cache-size is not a valid integer" . to_string ( ) ) ?;
378
378
}
379
379
380
+ if let Some ( max_bytes) = cli_args. get_one :: < String > ( "state-cache-max-bytes" ) {
381
+ client_config. store . max_state_cache_bytes = max_bytes
382
+ . parse ( )
383
+ . map_err ( |_| "state-cache-max-bytes is not a valid integer" . to_string ( ) ) ?;
384
+ }
385
+
380
386
if let Some ( historic_state_cache_size) =
381
387
clap_utils:: parse_optional ( cli_args, "historic-state-cache-size" ) ?
382
388
{
Original file line number Diff line number Diff line change @@ -340,14 +340,19 @@ impl<E: EthSpec> StateCache<E> {
340
340
}
341
341
342
342
pub fn delete_state ( & mut self , state_root : & Hash256 ) {
343
+ self . cached_bytes = self . cached_bytes . saturating_sub (
344
+ self . states
345
+ . peek ( state_root)
346
+ . map_or ( 0 , |( _, state) | state. memory_size ( ) ) ,
347
+ ) ;
343
348
self . states . pop ( state_root) ;
344
349
self . block_map . delete ( state_root) ;
345
350
}
346
351
347
352
pub fn delete_block_states ( & mut self , block_root : & Hash256 ) {
348
353
if let Some ( slot_map) = self . block_map . delete_block_states ( block_root) {
349
354
for state_root in slot_map. slots . values ( ) {
350
- self . states . pop ( state_root) ;
355
+ self . delete_state ( state_root) ;
351
356
}
352
357
}
353
358
}
@@ -410,6 +415,11 @@ impl<E: EthSpec> StateCache<E> {
410
415
. collect :: < Vec < _ > > ( ) ;
411
416
412
417
for state_root in & state_roots_to_delete {
418
+ self . cached_bytes = self . cached_bytes . saturating_sub (
419
+ self . states
420
+ . peek ( state_root)
421
+ . map_or ( 0 , |( _, state) | state. memory_size ( ) ) ,
422
+ ) ;
413
423
self . delete_state ( state_root) ;
414
424
}
415
425
You can’t perform that action at this time.
0 commit comments