Skip to content

Commit

Permalink
domain types
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Oct 23, 2024
1 parent 843fb80 commit 4acb5cd
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 111 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions crates/astria-auctioneer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,30 @@ astria-build-info = { path = "../astria-build-info", features = ["runtime"] }
astria-core = { path = "../astria-core", features = ["serde", "server"] }
astria-eyre = { path = "../astria-eyre" }
config = { package = "astria-config", path = "../astria-config" }
sequencer_client = { package = "astria-sequencer-client", path = "../astria-sequencer-client" }
telemetry = { package = "astria-telemetry", path = "../astria-telemetry", features = [
"display",
"display",
] }

async-trait = { workspace = true }
axum = { workspace = true }
bytes = { workspace = true }
futures = { workspace = true }
humantime = { workspace = true }
itertools = { workspace = true }
pbjson-types = { workspace = true }
pin-project-lite = { workspace = true }
prost = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha2 = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = [
"macros",
"rt-multi-thread",
"sync",
"time",
"signal",
"macros",
"rt-multi-thread",
"sync",
"time",
"signal",
] }
tokio-util = { workspace = true, features = ["rt"] }
tracing = { workspace = true, features = ["attributes"] }
Expand All @@ -47,12 +50,12 @@ tokio-stream = { workspace = true, features = ["net"] }
[dev-dependencies]
astria-core = { path = "../astria-core", features = ["client"] }
config = { package = "astria-config", path = "../astria-config", features = [
"tests",
"tests",
] }
insta = { workspace = true, features = ["json"] }
tempfile = { workspace = true }
test_utils = { package = "astria-test-utils", path = "../astria-test-utils", features = [
"geth",
"geth",
] }
tokio-test = { workspace = true }
wiremock = { workspace = true }
Expand Down
28 changes: 25 additions & 3 deletions crates/astria-auctioneer/src/auction/bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ use astria_core::{
use astria_eyre::eyre::{
self,
};
use bytes::Bytes;

// TODO: this should probably be moved to astria_core::bundle
pub(crate) struct Bundle {}
#[derive(Debug, Clone)]
pub(crate) struct Bundle {
raw: raw::Bundle,
/// The fee that will be charged for this bundle
fee: u64,
/// The byte list of transactions fto be included.
transactions: Vec<Bytes>,
/// The hash of the rollup block that this bundle is based on.
prev_rollup_block_hash: Bytes,
/// The hash of the sequencer block used to derive the rollup block that this bundle is based
/// on.
base_sequencer_block_hash: Bytes,
}

impl Bundle {
fn try_from_raw(raw: raw::Bundle) -> eyre::Result<Self> {
fn try_from_raw(_raw: raw::Bundle) -> eyre::Result<Self> {
unimplemented!()
// Ok(Self {
// raw,
// })
}

fn into_raw(self) -> raw::Bundle {
Expand All @@ -21,12 +37,18 @@ impl Bundle {
pub(crate) fn into_transaction(self) -> SignedTransaction {
unimplemented!()
}

pub(crate) fn bid(&self) -> Bid {
let bundle = self.clone();
Bid::from_bundle(bundle)
}
}

#[derive(Debug, Clone)]
pub(crate) struct Bid {}

impl Bid {
fn from_bundle(bundle: Bundle) -> Self {
fn from_bundle(_bundle: Bundle) -> Self {
unimplemented!()
}

Expand Down
25 changes: 21 additions & 4 deletions crates/astria-auctioneer/src/auction/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) struct Driver {
#[allow(dead_code)]
metrics: &'static Metrics,
shutdown_token: CancellationToken,

/// The time between receiving a block commitment
latency_margin: Duration,
/// Channel for receiving the executed block signal to start processing bundles
Expand All @@ -81,10 +82,12 @@ pub(crate) struct Driver {

impl Driver {
pub(crate) async fn run(mut self) -> eyre::Result<()> {
// TODO: should the timer be inside the auction so that we only have one option?
let mut latency_margin_timer = None;

let mut auction: Option<Auction> = None;

let mut nonce_fetch: Option<tokio::task::JoinHandle<eyre::Result<u64>>> = None;

let auction_result = loop {
select! {
biased;
Expand All @@ -103,7 +106,8 @@ impl Driver {
//
}

// get the auction winner if the timer expires
// get the auction winner when the timer expires
// TODO: should this also be conditioned on auction.is_some()? this feels redundant as we only populate the timer if the auction isnt none
_ = async { latency_margin_timer.as_mut().unwrap() }, if latency_margin_timer.is_some() => {
break Ok(auction.unwrap().winner());
}
Expand All @@ -120,9 +124,14 @@ impl Driver {
if let Err(e) = signal {
break Err(eyre!("commit signal channel closed")).wrap_err(e);
}
// set auction to closing
// start the timer
// set the timer
latency_margin_timer = Some(tokio::time::sleep(self.latency_margin));

// TODO: also want to fetch the pending nonce here (we wait for commit because we want the pending nonce from after the commit)
nonce_fetch = Some(tokio::task::spawn(async {
// TODO: fetch the pending nonce using the sequencer client with tryhard
Ok(0)
}));
}

// TODO: new bundles from the bundle stream if auction exists?
Expand All @@ -141,6 +150,14 @@ impl Driver {
}
};

// await the nonce fetch result
// TODO: flatten this or get rid of the option somehow
let nonce = nonce_fetch
.expect("should have received commit to exit the bid loop")
.await
.wrap_err("task failed")?
.wrap_err("failed to fetch nonce")?;

let submission_result = select! {
biased;

Expand Down
4 changes: 2 additions & 2 deletions crates/astria-auctioneer/src/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub(crate) use driver::Handle;
pub(crate) struct Id([u8; 32]);

impl Id {
fn from_optimistic_block(optimistic_block: block::Optimistic) -> Self {
Self(optimistic_block.sequencer_block_hash())
pub(crate) fn from_sequencer_block_hash(block_hash: [u8; 32]) -> Self {
Self(block_hash)
}
}

Expand Down
Loading

0 comments on commit 4acb5cd

Please sign in to comment.