-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notify banned solvers #3262
base: blacklist-failing-solvers
Are you sure you want to change the base?
Notify banned solvers #3262
Changes from all commits
321f9bc
f69e174
1504c48
9f0cbc8
7f86000
d233094
105b9a7
08924da
dfec727
e370871
3c591e4
85a3d86
921692f
f3b6415
098113a
43e650f
634aec4
8745e6b
4bee676
17f3f3a
9ee6af7
70d8907
cca70c8
7de4dc1
5c266d8
4523b52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! Types for communicating with drivers as defined in | ||
//! `crates/driver/openapi.yml`. | ||
|
||
pub mod notify; | ||
pub mod reveal; | ||
pub mod settle; | ||
pub mod solve; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use {serde::Serialize, serde_with::serde_as}; | ||
|
||
#[serde_as] | ||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum Request { | ||
Banned { | ||
reason: BanReason, | ||
until_timestamp: u64, | ||
}, | ||
} | ||
|
||
#[serde_as] | ||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum BanReason { | ||
UnsettledConsecutiveAuctions, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod notify_request; | ||
|
||
pub use notify_request::{Error as NotifyError, NotifyRequest}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use {crate::infra::notify, serde::Deserialize, serde_with::serde_as}; | ||
|
||
#[serde_as] | ||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum NotifyRequest { | ||
Banned { | ||
reason: BanReason, | ||
until_timestamp: u64, | ||
}, | ||
} | ||
|
||
#[serde_as] | ||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum BanReason { | ||
/// The driver won multiple consecutive auctions but never settled them. | ||
UnsettledConsecutiveAuctions, | ||
} | ||
|
||
impl From<NotifyRequest> for notify::Kind { | ||
fn from(value: NotifyRequest) -> Self { | ||
match value { | ||
NotifyRequest::Banned { | ||
reason, | ||
until_timestamp, | ||
} => notify::Kind::Banned { | ||
reason: match reason { | ||
BanReason::UnsettledConsecutiveAuctions => { | ||
notify::BanReason::UnsettledConsecutiveAuctions | ||
} | ||
}, | ||
until_timestamp, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error("Unable to notify solver")] | ||
UnableToNotify, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is worth to add some context information like solver address or name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The caller knows for which solver the request was sent. IMO, it is a redundant info here. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
mod dto; | ||
|
||
pub use dto::NotifyError; | ||
|
||
use crate::infra::api::{Error, State}; | ||
|
||
pub(in crate::infra::api) fn notify(router: axum::Router<State>) -> axum::Router<State> { | ||
router.route("/notify", axum::routing::post(route)) | ||
} | ||
|
||
async fn route( | ||
state: axum::extract::State<State>, | ||
req: axum::Json<dto::NotifyRequest>, | ||
) -> Result<hyper::StatusCode, (hyper::StatusCode, axum::Json<Error>)> { | ||
let solver = &state.solver().name().0; | ||
tracing::debug!(?req, ?solver, "received a notification"); | ||
state | ||
.solver() | ||
.notify(None, None, req.0.into()) | ||
.await | ||
.map(|_| hyper::StatusCode::OK) | ||
.map_err(|_| NotifyError::UnableToNotify.into()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Personally I would be ok with omitting completely the error case for
notify
endpoint (be consistent with how the driver propagates it to solvers) as we always considered this endpoint not too important for system to work and we were not interested to act on failure of notification.