Skip to content

Commit

Permalink
fix: conflicting state history_size values (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaan7 authored Feb 27, 2025
1 parent 38c744a commit 50c86d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions core/src/client/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use eyre::{eyre, Result};

use crate::consensus::Consensus;
use crate::errors::ClientError;
use crate::execution::constants::MAX_STATE_HISTORY_LENGTH;
use crate::execution::evm::Evm;
use crate::execution::rpc::http_rpc::HttpRpc;
use crate::execution::state::State;
Expand All @@ -20,7 +21,6 @@ use crate::types::BlockTag;
pub struct Node<N: NetworkSpec, C: Consensus<N::BlockResponse>> {
pub consensus: C,
pub execution: Arc<ExecutionClient<N, HttpRpc<N>>>,
pub history_size: usize,
fork_schedule: ForkSchedule,
}

Expand All @@ -33,7 +33,12 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>> Node<N, C> {
let block_recv = consensus.block_recv().unwrap();
let finalized_block_recv = consensus.finalized_block_recv().unwrap();

let state = State::new(block_recv, finalized_block_recv, 256, execution_rpc);
let state = State::new(
block_recv,
finalized_block_recv,
MAX_STATE_HISTORY_LENGTH,
execution_rpc,
);
let execution = Arc::new(
ExecutionClient::new(execution_rpc, state, fork_schedule)
.map_err(ClientError::InternalError)?,
Expand All @@ -42,7 +47,6 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>> Node<N, C> {
Ok(Node {
consensus,
execution,
history_size: 64,
fork_schedule,
})
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/execution/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pub const PARALLEL_QUERY_BATCH_SIZE: usize = 20;
// We currently limit the max number of logs to fetch,
// to avoid blocking the client for too long.
pub const MAX_SUPPORTED_LOGS_NUMBER: usize = 5;

pub const MAX_STATE_HISTORY_LENGTH: usize = 64;
8 changes: 4 additions & 4 deletions core/src/execution/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> State<N, R> {
pub fn new(
mut block_recv: Receiver<N::BlockResponse>,
mut finalized_block_recv: watch::Receiver<Option<N::BlockResponse>>,
history_length: u64,
history_length: usize,
rpc: &str,
) -> Self {
let rpc = R::new(rpc).unwrap();
Expand Down Expand Up @@ -221,12 +221,12 @@ struct Inner<N: NetworkSpec, R: ExecutionRpc<N>> {
hashes: HashMap<B256, u64>,
txs: HashMap<B256, TransactionLocation>,
filters: HashMap<U256, FilterType>,
history_length: u64,
history_length: usize,
rpc: R,
}

impl<N: NetworkSpec, R: ExecutionRpc<N>> Inner<N, R> {
pub fn new(history_length: u64, rpc: R) -> Self {
pub fn new(history_length: usize, rpc: R) -> Self {
Self {
history_length,
blocks: BTreeMap::default(),
Expand Down Expand Up @@ -295,7 +295,7 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> Inner<N, R> {
}

fn prune(&mut self) {
while self.blocks.len() as u64 > self.history_length {
while self.blocks.len() > self.history_length {
if let Some((number, _)) = self.blocks.first_key_value() {
self.remove_block(*number);
}
Expand Down

0 comments on commit 50c86d4

Please sign in to comment.