From 41ccb230750eaf58be1ace83ab73298fd6c85f61 Mon Sep 17 00:00:00 2001 From: Trey Del Bonis Date: Mon, 3 Feb 2025 23:42:25 -0500 Subject: [PATCH] consensus-logic: removed now-unused `state_tracker` module --- crates/consensus-logic/src/csm/mod.rs | 1 - .../consensus-logic/src/csm/state_tracker.rs | 101 ------------------ 2 files changed, 102 deletions(-) delete mode 100644 crates/consensus-logic/src/csm/state_tracker.rs diff --git a/crates/consensus-logic/src/csm/mod.rs b/crates/consensus-logic/src/csm/mod.rs index 5bc4f0fa16..0d9c1e47e7 100644 --- a/crates/consensus-logic/src/csm/mod.rs +++ b/crates/consensus-logic/src/csm/mod.rs @@ -10,5 +10,4 @@ pub mod client_transition; pub mod config; pub mod ctl; pub mod message; -pub mod state_tracker; pub mod worker; diff --git a/crates/consensus-logic/src/csm/state_tracker.rs b/crates/consensus-logic/src/csm/state_tracker.rs deleted file mode 100644 index 4942353161..0000000000 --- a/crates/consensus-logic/src/csm/state_tracker.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! Tracker to manage authoritative consensus states as we compute the -//! transition outputs. - -use std::sync::Arc; - -#[cfg(feature = "debug-utils")] -use strata_common::bail_manager::{check_bail_trigger, BAIL_SYNC_EVENT}; -use strata_primitives::params::Params; -use strata_state::{ - client_state::{ClientState, ClientStateMut}, - operation::ClientUpdateOutput, - sync_event::SyncEvent, -}; -use strata_storage::NodeStorage; -use tracing::*; - -use super::client_transition; -use crate::errors::Error; - -pub struct StateTracker { - params: Arc, - storage: Arc, - - cur_state_idx: u64, - cur_state: Arc, -} - -impl StateTracker { - pub fn new( - params: Arc, - storage: Arc, - cur_state_idx: u64, - cur_state: Arc, - ) -> Self { - Self { - params, - storage, - cur_state_idx, - cur_state, - } - } - - pub fn cur_state_idx(&self) -> u64 { - self.cur_state_idx - } - - pub fn cur_state(&self) -> &Arc { - &self.cur_state - } - - /// Fetches a sync event from storage. - fn get_sync_event(&self, idx: u64) -> anyhow::Result { - Ok(self - .storage - .sync_event() - .get_sync_event_blocking(idx)? - .ok_or(Error::MissingSyncEvent(idx))?) - } - - /// Given the next event index, computes the state application if the - /// requisite data is available. Returns the output and the new state. - // TODO maybe remove output return value - pub fn advance_consensus_state( - &mut self, - ev_idx: u64, - ) -> anyhow::Result<(ClientUpdateOutput, Arc)> { - let prev_ev_idx = ev_idx - 1; - if prev_ev_idx != self.cur_state_idx { - return Err(Error::SkippedEventIdx(prev_ev_idx, self.cur_state_idx).into()); - } - - // Load the event from the database. - let ev = self.get_sync_event(ev_idx)?; - - debug!(?ev, "processing sync event"); - - #[cfg(feature = "debug-utils")] - check_bail_trigger(BAIL_SYNC_EVENT); - - // Compute the state transition. - let context = client_transition::StorageEventContext::new(&self.storage); - let mut state_mut = ClientStateMut::new(self.cur_state.as_ref().clone()); - client_transition::process_event(&mut state_mut, &ev, &context, &self.params)?; - - // Clone the state and apply the operations to it. - let outp = state_mut.into_update(); - - // Store the outputs. - let state = self - .storage - .client_state() - .put_update_blocking(ev_idx, outp.clone())?; - - // Update bookkeeping. - self.cur_state = state; - self.cur_state_idx = ev_idx; - debug!(%ev_idx, "computed new consensus state"); - - Ok((outp, self.cur_state.clone())) - } -}