From 68a896eb77e5eb68b5cf68e8cf654ae0cce11838 Mon Sep 17 00:00:00 2001 From: itamar Date: Tue, 24 Sep 2024 18:45:20 -0400 Subject: [PATCH] auction driver boilerplate --- .../src/auction_driver/builder.rs | 20 ++++++++++++ .../src/auction_driver/mod.rs | 17 ++++++++++ .../astria-auctioneer/src/auctioneer/inner.rs | 32 +++++++++---------- crates/astria-auctioneer/src/lib.rs | 1 + 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 crates/astria-auctioneer/src/auction_driver/builder.rs create mode 100644 crates/astria-auctioneer/src/auction_driver/mod.rs diff --git a/crates/astria-auctioneer/src/auction_driver/builder.rs b/crates/astria-auctioneer/src/auction_driver/builder.rs new file mode 100644 index 0000000000..89baebd619 --- /dev/null +++ b/crates/astria-auctioneer/src/auction_driver/builder.rs @@ -0,0 +1,20 @@ +use astria_eyre::eyre; + +use super::AuctionDriver; +use crate::Metrics; + +pub(crate) struct Builder { + pub(crate) metrics: &'static Metrics, +} + +impl Builder { + pub(crate) fn build(self) -> eyre::Result { + let Self { + metrics, + } = self; + + Ok(AuctionDriver { + metrics, + }) + } +} diff --git a/crates/astria-auctioneer/src/auction_driver/mod.rs b/crates/astria-auctioneer/src/auction_driver/mod.rs new file mode 100644 index 0000000000..ecc0b40a03 --- /dev/null +++ b/crates/astria-auctioneer/src/auction_driver/mod.rs @@ -0,0 +1,17 @@ +use astria_eyre::eyre; + +use crate::Metrics; + +mod builder; +pub(crate) use builder::Builder; + +pub(crate) struct AuctionDriver { + #[warn(dead_code)] + metrics: &'static Metrics, +} + +impl AuctionDriver { + pub(crate) async fn run(self) -> eyre::Result<()> { + todo!("implement me") + } +} diff --git a/crates/astria-auctioneer/src/auctioneer/inner.rs b/crates/astria-auctioneer/src/auctioneer/inner.rs index 4d6102fb14..a6f302c2dc 100644 --- a/crates/astria-auctioneer/src/auctioneer/inner.rs +++ b/crates/astria-auctioneer/src/auctioneer/inner.rs @@ -21,6 +21,7 @@ use tracing::{ }; use crate::{ + auction_driver, Config, Metrics, }; @@ -34,23 +35,34 @@ pub(super) struct Auctioneer { } impl Auctioneer { - const _AUCTION_DRIVER: &'static str = "auction_driver"; + const AUCTION_DRIVER: &'static str = "auction_driver"; const _BUNDLE_COLLECTOR: &'static str = "bundle_collector"; const _OPTIMISTIC_EXECUTOR: &'static str = "optimistic_executor"; /// Creates an [`Auctioneer`] service from a [`Config`] and [`Metrics`]. pub(super) fn new( cfg: Config, - _metrics: &'static Metrics, + metrics: &'static Metrics, shutdown_token: CancellationToken, ) -> eyre::Result { let Config { .. } = cfg; - let tasks = JoinMap::new(); + let mut tasks = JoinMap::new(); - // call subtask builders here + // TODO: add tasks here + // - optimistic executor + // - bundle collector + // - auction driver + // - runs the auction + // - runs the sequencer submitter + let auction_driver = auction_driver::Builder { + metrics, + } + .build() + .wrap_err("failed to initialize the auction driver")?; + tasks.spawn(Self::AUCTION_DRIVER, auction_driver.run()); Ok(Self { shutdown_token, @@ -61,8 +73,6 @@ impl Auctioneer { /// Runs the [`Auctioneer`] service until it received an exit signal, or one of the constituent /// tasks either ends unexpectedly or returns an error. pub(super) async fn run(mut self) -> eyre::Result<()> { - self.spawn_tasks(); - let reason = select! { biased; @@ -86,16 +96,6 @@ impl Auctioneer { Ok(()) } - fn spawn_tasks(&self) { - // TODO: add tasks here - // - optimistic executor - // - bundle collector - // - auction runner - // - runs the auction - // - runs the sequencer submitter - todo!("spawn and add to self.tasks"); - } - /// Initiates shutdown of the Auctioneer and waits for all the constituent tasks to shut down. async fn shutdown(mut self) { self.shutdown_token.cancel(); diff --git a/crates/astria-auctioneer/src/lib.rs b/crates/astria-auctioneer/src/lib.rs index 22949326c0..cbc2c3ca61 100644 --- a/crates/astria-auctioneer/src/lib.rs +++ b/crates/astria-auctioneer/src/lib.rs @@ -1,5 +1,6 @@ //! TODO: Add a description +mod auction_driver; mod auctioneer; mod build_info; pub mod config;