Skip to content

Commit fe05ed2

Browse files
modified delete function and added cli argument
1 parent 14fd2b1 commit fe05ed2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

beacon_node/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,15 @@ pub fn cli_app() -> Command {
817817
.action(ArgAction::Set)
818818
.display_order(0)
819819
)
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+
)
820829
/*
821830
* Execution Layer Integration
822831
*/

beacon_node/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ pub fn get_config<E: EthSpec>(
377377
.map_err(|_| "state-cache-size is not a valid integer".to_string())?;
378378
}
379379

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+
380386
if let Some(historic_state_cache_size) =
381387
clap_utils::parse_optional(cli_args, "historic-state-cache-size")?
382388
{

beacon_node/store/src/state_cache.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,19 @@ impl<E: EthSpec> StateCache<E> {
340340
}
341341

342342
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+
);
343348
self.states.pop(state_root);
344349
self.block_map.delete(state_root);
345350
}
346351

347352
pub fn delete_block_states(&mut self, block_root: &Hash256) {
348353
if let Some(slot_map) = self.block_map.delete_block_states(block_root) {
349354
for state_root in slot_map.slots.values() {
350-
self.states.pop(state_root);
355+
self.delete_state(state_root);
351356
}
352357
}
353358
}
@@ -410,6 +415,11 @@ impl<E: EthSpec> StateCache<E> {
410415
.collect::<Vec<_>>();
411416

412417
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+
);
413423
self.delete_state(state_root);
414424
}
415425

0 commit comments

Comments
 (0)