Skip to content

Commit

Permalink
auction driver boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Sep 24, 2024
1 parent 563e727 commit b0527c9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
20 changes: 20 additions & 0 deletions crates/astria-auctioneer/src/auction_driver/builder.rs
Original file line number Diff line number Diff line change
@@ -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<AuctionDriver> {
let Self {
metrics,
} = self;

Ok(AuctionDriver {
metrics,
})
}
}
17 changes: 17 additions & 0 deletions crates/astria-auctioneer/src/auction_driver/mod.rs
Original file line number Diff line number Diff line change
@@ -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")
}
}
32 changes: 16 additions & 16 deletions crates/astria-auctioneer/src/auctioneer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use tracing::{
};

use crate::{
auction_driver,
Config,
Metrics,
};
Expand All @@ -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<Self> {
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,
Expand All @@ -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;

Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions crates/astria-auctioneer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! TODO: Add a description
mod auction_driver;
mod auctioneer;
mod build_info;
pub mod config;
Expand Down

0 comments on commit b0527c9

Please sign in to comment.