From 7f6a2b4cb555847d567378868150510fd0731b28 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 16 Apr 2024 12:45:27 +0200 Subject: [PATCH] refactor(exex, primitives): move finished exex height to primitives (#7670) --- crates/exex/src/manager.rs | 31 +++++++------------------------ crates/primitives/src/exex/mod.rs | 18 ++++++++++++++++++ crates/primitives/src/lib.rs | 2 ++ 3 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 crates/primitives/src/exex/mod.rs diff --git a/crates/exex/src/manager.rs b/crates/exex/src/manager.rs index 8fe6d48f6..32c4d8e26 100644 --- a/crates/exex/src/manager.rs +++ b/crates/exex/src/manager.rs @@ -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, /// The finished height of all ExEx's. - finished_height: watch::Sender, + finished_height: watch::Sender, /// 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, /// The finished height of all ExEx's. - finished_height: watch::Receiver, + finished_height: watch::Receiver, } 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] diff --git a/crates/primitives/src/exex/mod.rs b/crates/primitives/src/exex/mod.rs new file mode 100644 index 000000000..9fc2ace66 --- /dev/null +++ b/crates/primitives/src/exex/mod.rs @@ -0,0 +1,18 @@ +use crate::BlockNumber; + +/// The finished height of all ExEx's. +#[derive(Debug, Clone, Copy)] +pub enum FinishedExExHeight { + /// 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), +} diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index c57bffed5..9c4473890 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -26,6 +26,7 @@ mod compression; pub mod constants; pub mod eip4844; mod error; +mod exex; pub mod fs; pub mod genesis; mod header; @@ -66,6 +67,7 @@ pub use constants::{ KECCAK_EMPTY, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, }; pub use error::{GotExpected, GotExpectedBoxed}; +pub use exex::FinishedExExHeight; pub use genesis::{ChainConfig, Genesis, GenesisAccount}; pub use header::{Header, HeaderValidationError, HeadersDirection, SealedHeader}; pub use integer_list::IntegerList;