Skip to content

Commit

Permalink
Rework comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Apr 30, 2024
1 parent 70fd46d commit 5a7f087
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
true => SolutionMerging::Allowed,
false => SolutionMerging::Forbidden,
},
s3: config.s3,
s3: config.s3.map(Into::into),
}
}))
.await,
Expand Down
15 changes: 13 additions & 2 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use load::load;
use {
crate::{domain::eth, infra::persistence::S3, util::serialize},
crate::{domain::eth, util::serialize},
reqwest::Url,
serde::{Deserialize, Serialize},
serde_with::serde_as,
Expand Down Expand Up @@ -226,7 +226,7 @@ struct SolverConfig {
#[serde(default)]
merge_solutions: bool,

/// S3 configuration for storing the auction in the form they are sent to
/// S3 configuration for storing the auctions in the form they are sent to
/// the solver engine
#[serde(default)]
s3: Option<S3>,
Expand All @@ -240,6 +240,17 @@ pub enum FeeHandler {
Solver,
}

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct S3 {
/// Name of the AWS S3 bucket in which the auctions will be stored
pub bucket: String,

/// Prepended to the auction id to form the final instance filename on AWS
/// S3 bucket. Something like "staging/mainnet/"
pub prefix: String,
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
Expand Down
35 changes: 20 additions & 15 deletions crates/driver/src/infra/persistence/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
use {
crate::{domain::competition::auction::Id, infra::solver::Config},
serde::Deserialize,
crate::{
domain::competition::auction::Id,
infra::{config::file, solver::Config},
},
std::sync::Arc,
tracing::Instrument,
};

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
#[derive(Clone, Debug, Default)]
pub struct S3 {
/// The s3_instance_upload_* arguments configure how auction instances
/// should be uploaded to AWS S3.
/// They must either all be set or all not set.
/// Name of the AWS S3 bucket in which the auctions will be stored
pub bucket: String,

/// Prepended to the auction id to form the final instance filename on S3.
/// Something like "staging/mainnet/"
/// Prepended to the auction id to form the final instance filename on AWS
/// S3 bucket. Something like "staging/mainnet/"
pub prefix: String,
}

impl From<file::S3> for S3 {
fn from(value: file::S3) -> Self {
Self {
bucket: value.bucket,
prefix: value.prefix,
}
}
}

impl From<S3> for s3::Config {
fn from(value: S3) -> Self {
Self {
Expand Down Expand Up @@ -45,19 +53,16 @@ impl Persistence {

/// Saves the given auction with liquidity with fire and forget mentality
/// (non-blocking operation)
pub fn archive_auction(&self, auction_id: Option<Id>, body: &str) {
pub fn archive_auction(&self, auction_id: Id, body: &str) {
let Some(uploader) = self.s3.clone() else {
return;
};
let Some(id) = auction_id else {
return;
};
let body = body.to_string();
tokio::spawn(
async move {
match uploader.upload(id.to_string(), body).await {
match uploader.upload(auction_id.to_string(), body).await {
Ok(key) => {
tracing::info!(?key, "uploaded auction to s3");
tracing::debug!(?key, "uploaded auction with liquidity to s3");
}
Err(err) => {
tracing::warn!(?err, "failed to upload auction to s3");
Expand Down
8 changes: 6 additions & 2 deletions crates/driver/src/infra/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct Config {
/// TODO: Remove once all solvers are moved to use limit orders for quoting
pub quote_using_limit_orders: bool,
pub merge_solutions: SolutionMerging,
/// S3 configuration for storing the auction in the form they are sent to
/// S3 configuration for storing the auctions in the form they are sent to
/// the solver engine
pub s3: Option<S3>,
}
Expand Down Expand Up @@ -202,7 +202,11 @@ impl Solver {
self.config.fee_handler,
))
.unwrap();
self.persistence.archive_auction(auction.id(), &body);
// Only auctions with IDs are real auctions (/quote requests don't have an ID,
// and it makes no sense to store them)
if let Some(id) = auction.id() {
self.persistence.archive_auction(id, &body);
};
let url = shared::url::join(&self.config.endpoint, "solve");
super::observe::solver_request(&url, &body);
let mut req = self
Expand Down

0 comments on commit 5a7f087

Please sign in to comment.