reth_engine_tree/tree/
persistence_state.rsuse alloy_eips::BlockNumHash;
use alloy_primitives::B256;
use std::{collections::VecDeque, time::Instant};
use tokio::sync::oneshot;
use tracing::{debug, trace};
#[derive(Default, Debug)]
pub struct PersistenceState {
pub(crate) last_persisted_block: BlockNumHash,
pub(crate) rx: Option<(oneshot::Receiver<Option<BlockNumHash>>, Instant)>,
pub(crate) remove_above_state: VecDeque<u64>,
}
impl PersistenceState {
pub(crate) const fn in_progress(&self) -> bool {
self.rx.is_some()
}
pub(crate) fn start(&mut self, rx: oneshot::Receiver<Option<BlockNumHash>>) {
self.rx = Some((rx, Instant::now()));
}
pub(crate) fn schedule_removal(&mut self, new_tip_num: u64) {
debug!(target: "engine::tree", ?new_tip_num, prev_remove_state=?self.remove_above_state, last_persisted_block=?self.last_persisted_block, "Scheduling removal");
self.remove_above_state.push_back(new_tip_num);
}
pub(crate) fn finish(
&mut self,
last_persisted_block_hash: B256,
last_persisted_block_number: u64,
) {
trace!(target: "engine::tree", block= %last_persisted_block_number, hash=%last_persisted_block_hash, "updating persistence state");
self.rx = None;
self.last_persisted_block =
BlockNumHash::new(last_persisted_block_number, last_persisted_block_hash);
}
}