refactor(exex, primitives): move finished exex height to primitives (#7670)

This commit is contained in:
Alexey Shekhirin
2024-04-16 12:45:27 +02:00
committed by GitHub
parent 8105291afa
commit 7f6a2b4cb5
3 changed files with 27 additions and 24 deletions

View File

@ -13,7 +13,7 @@ use crate::ExExEvent;
use futures::StreamExt;
use metrics::Gauge;
use reth_metrics::{metrics::Counter, Metrics};
use reth_primitives::BlockNumber;
use reth_primitives::{BlockNumber, FinishedExExHeight};
use reth_provider::CanonStateNotification;
use reth_tracing::tracing::debug;
use tokio::sync::{
@ -168,7 +168,7 @@ pub struct ExExManager {
is_ready: watch::Sender<bool>,
/// The finished height of all ExEx's.
finished_height: watch::Sender<FinishedHeight>,
finished_height: watch::Sender<FinishedExExHeight>,
/// A handle to the ExEx manager.
handle: ExExManagerHandle,
@ -190,9 +190,9 @@ impl ExExManager {
let (handle_tx, handle_rx) = mpsc::unbounded_channel();
let (is_ready_tx, is_ready_rx) = watch::channel(true);
let (finished_height_tx, finished_height_rx) = watch::channel(if num_exexs == 0 {
FinishedHeight::NoExExs
FinishedExExHeight::NoExExs
} else {
FinishedHeight::NotReady
FinishedExExHeight::NotReady
});
let current_capacity = Arc::new(AtomicUsize::new(max_capacity));
@ -326,7 +326,7 @@ impl Future for ExExManager {
}
});
if let Ok(finished_height) = finished_height {
let _ = self.finished_height.send(FinishedHeight::Height(finished_height));
let _ = self.finished_height.send(FinishedExExHeight::Height(finished_height));
}
Poll::Pending
@ -351,7 +351,7 @@ pub struct ExExManagerHandle {
/// The current capacity of the manager's internal notification buffer.
current_capacity: Arc<AtomicUsize>,
/// The finished height of all ExEx's.
finished_height: watch::Receiver<FinishedHeight>,
finished_height: watch::Receiver<FinishedExExHeight>,
}
impl ExExManagerHandle {
@ -396,7 +396,7 @@ impl ExExManagerHandle {
}
/// The finished height of all ExEx's.
pub fn finished_height(&mut self) -> FinishedHeight {
pub fn finished_height(&mut self) -> FinishedExExHeight {
*self.finished_height.borrow_and_update()
}
@ -433,23 +433,6 @@ impl Clone for ExExManagerHandle {
}
}
/// The finished height of all ExEx's.
#[derive(Debug, Clone, Copy)]
pub enum FinishedHeight {
/// No ExEx's are installed, so there is no finished height.
NoExExs,
/// Not all ExExs emitted a `FinishedHeight` event yet.
NotReady,
/// The finished height of all ExEx's.
///
/// This is the lowest common denominator between all ExEx's.
///
/// This block is used to (amongst other things) determine what blocks are safe to prune.
///
/// The number is inclusive, i.e. all blocks `<= finished_height` are safe to prune.
Height(BlockNumber),
}
#[cfg(test)]
mod tests {
#[tokio::test]