Skip to content
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

Open
wants to merge 39 commits into
base: blacklist-failing-solvers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
321f9bc
Use driver directly
squadgazzz Jan 30, 2025
f69e174
Notify external solvers
squadgazzz Jan 30, 2025
1504c48
/notify driver endpoint
squadgazzz Jan 30, 2025
9f0cbc8
OpenApi
squadgazzz Jan 30, 2025
7f86000
Nit
squadgazzz Jan 30, 2025
d233094
Solver's OpenAPI
squadgazzz Jan 30, 2025
105b9a7
Store drivers accepted for the feature
squadgazzz Jan 31, 2025
08924da
Comment
squadgazzz Jan 31, 2025
dfec727
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Jan 31, 2025
e370871
Fix after merge
squadgazzz Jan 31, 2025
3c591e4
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Jan 31, 2025
85a3d86
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Jan 31, 2025
921692f
Notify only accepted solvers
squadgazzz Jan 31, 2025
f3b6415
Minor refactoring
squadgazzz Jan 31, 2025
098113a
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Jan 31, 2025
43e650f
Banned notification
squadgazzz Jan 31, 2025
634aec4
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 3, 2025
8745e6b
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 11, 2025
4bee676
Move notification to the infra mod
squadgazzz Feb 11, 2025
17f3f3a
Ban until timestamp notification
squadgazzz Feb 11, 2025
9ee6af7
Merge remote-tracking branch 'origin/notify-banned-solvers' into noti…
squadgazzz Feb 11, 2025
70d8907
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 11, 2025
cca70c8
Refactoring
squadgazzz Feb 12, 2025
7de4dc1
OpenAPI
squadgazzz Feb 12, 2025
5c266d8
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 12, 2025
4523b52
Formatting
squadgazzz Feb 12, 2025
6bb7ee2
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 14, 2025
b773f66
Api description
squadgazzz Feb 14, 2025
ab5c616
Drop error response
squadgazzz Feb 14, 2025
680e806
Naming
squadgazzz Feb 14, 2025
38ad536
ISO timestamp
squadgazzz Feb 17, 2025
171de85
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 17, 2025
d4b87bd
Fix after merge
squadgazzz Feb 17, 2025
2e3f4ab
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 17, 2025
de8cfa2
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 17, 2025
f5385fb
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 17, 2025
127e2f5
Merge branch 'blacklist-failing-solvers' into notify-banned-solvers
squadgazzz Feb 18, 2025
a4a43e5
Fire notify and forget
squadgazzz Feb 18, 2025
b4c31f3
Redundant serde_as
squadgazzz Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
domain::{eth, Metrics},
infra,
},
chrono::Utc,
ethrpc::block_stream::CurrentBlockWatcher,
std::{
collections::HashMap,
Expand Down Expand Up @@ -72,6 +73,7 @@ impl Validator {
};

let now = Instant::now();
let banned_until = Utc::now() + self_.0.ttl;
let non_settling_solver_names: Vec<&str> = non_settling_solvers
.iter()
.filter_map(|solver| self_.0.drivers_by_address.get(solver))
Expand All @@ -83,6 +85,7 @@ impl Validator {
// CIP making this mandatory has been approved.
if driver.requested_timeout_on_problems {
tracing::debug!(solver = ?driver.name, "disabling solver temporarily");
infra::notify_non_settling_solver(driver.clone(), banned_until);
self_
.0
.banned_solvers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ mod db;
mod onchain;

use {
crate::{
arguments::DbBasedSolverParticipationGuardConfig,
domain::eth,
infra::{self, Ethereum},
},
crate::{arguments::DbBasedSolverParticipationGuardConfig, domain::eth, infra},
std::sync::Arc,
};

Expand All @@ -22,7 +18,7 @@ struct Inner {

impl SolverParticipationGuard {
pub fn new(
eth: Ethereum,
eth: infra::Ethereum,
persistence: infra::Persistence,
competition_updates_receiver: tokio::sync::mpsc::UnboundedReceiver<()>,
db_based_validator_config: DbBasedSolverParticipationGuardConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{domain::eth, infra::Ethereum};
use crate::{domain::eth, infra};

/// Calls Authenticator contract to check if a solver has a sufficient
/// permission.
pub(super) struct Validator {
pub eth: Ethereum,
pub eth: infra::Ethereum,
}

#[async_trait::async_trait]
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub use {
blockchain::Ethereum,
order_validation::banned,
persistence::Persistence,
solvers::Driver,
solvers::{notify_non_settling_solver, Driver},
};
1 change: 1 addition & 0 deletions crates/autopilot/src/infra/solvers/dto/mod.rs
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;
22 changes: 22 additions & 0 deletions crates/autopilot/src/infra/solvers/dto/notify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use {
chrono::{DateTime, Utc},
serde::Serialize,
serde_with::serde_as,
};

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum Request {
Banned {
reason: BanReason,
until: DateTime<Utc>,
},
}

#[serde_as]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum BanReason {
UnsettledConsecutiveAuctions,
}
21 changes: 19 additions & 2 deletions crates/autopilot/src/infra/solvers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use {
self::dto::{reveal, settle, solve},
crate::{arguments::Account, domain::eth, util},
crate::{arguments::Account, domain::eth, infra::solvers::dto::notify, util},
anyhow::{anyhow, Context, Result},
chrono::{DateTime, Utc},
reqwest::{Client, StatusCode},
std::time::Duration,
std::{sync::Arc, time::Duration},
thiserror::Error,
url::Url,
};
Expand Down Expand Up @@ -116,6 +117,10 @@ impl Driver {
Ok(())
}

pub async fn notify(&self, request: &notify::Request) -> Result<()> {
self.request_response("notify", request, None).await
}

async fn request_response<Response>(
&self,
path: &str,
Expand Down Expand Up @@ -172,3 +177,15 @@ pub async fn response_body_with_size_limit(
}
Ok(bytes)
}

/// Notifies the non-settling driver in a fire-and-forget manner.
pub fn notify_non_settling_solver(non_settling_driver: Arc<Driver>, banned_until: DateTime<Utc>) {
tokio::spawn(async move {
let _ = non_settling_driver
.notify(&notify::Request::Banned {
reason: notify::BanReason::UnsettledConsecutiveAuctions,
until: banned_until,
})
.await;
});
}
17 changes: 17 additions & 0 deletions crates/driver/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ paths:
$ref: "#/components/responses/BadRequest"
"500":
$ref: "#/components/responses/InternalServerError"
/notify:
post:
description: |
Receive a notification with a specific reason.
requestBody:
required: true
content:
application/json:
schema:
type: string
enum:
- banned
description: |-
The reason for the notification with optional additional context.
responses:
"200":
description: notification successfully received.
components:
schemas:
Address:
Expand Down
1 change: 1 addition & 0 deletions crates/driver/src/infra/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl Api {
let router = routes::solve(router);
let router = routes::reveal(router);
let router = routes::settle(router);
let router = routes::notify(router);

let bad_token_config = solver.bad_token_detection();
let mut bad_tokens =
Expand Down
2 changes: 2 additions & 0 deletions crates/driver/src/infra/api/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod healthz;
mod info;
mod metrics;
mod notify;
mod quote;
mod reveal;
mod settle;
Expand All @@ -10,6 +11,7 @@ pub(super) use {
healthz::healthz,
info::info,
metrics::metrics,
notify::notify,
quote::{quote, OrderError},
reveal::reveal,
settle::settle,
Expand Down
3 changes: 3 additions & 0 deletions crates/driver/src/infra/api/routes/notify/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod notify_request;

pub use notify_request::NotifyRequest;
39 changes: 39 additions & 0 deletions crates/driver/src/infra/api/routes/notify/dto/notify_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use {
crate::infra::notify,
chrono::{DateTime, Utc},
serde::Deserialize,
serde_with::serde_as,
};

#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum NotifyRequest {
Banned {
reason: BanReason,
until: DateTime<Utc>,
},
}

#[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 } => notify::Kind::Banned {
reason: match reason {
BanReason::UnsettledConsecutiveAuctions => {
notify::BanReason::UnsettledConsecutiveAuctions
}
},
until,
},
}
}
}
17 changes: 17 additions & 0 deletions crates/driver/src/infra/api/routes/notify/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod dto;

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());
Ok(hyper::StatusCode::OK)
}
9 changes: 8 additions & 1 deletion crates/driver/src/infra/notify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ use {

mod notification;

pub use notification::{Kind, Notification, ScoreKind, Settlement, SimulationSucceededAtLeastOnce};
pub use notification::{
BanReason,
Kind,
Notification,
ScoreKind,
Settlement,
SimulationSucceededAtLeastOnce,
};
use {
super::simulator,
crate::domain::{eth, mempools::Error},
Expand Down
12 changes: 12 additions & 0 deletions crates/driver/src/infra/notify/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
competition::{auction, solution},
eth::{self, Ether, TokenAddress},
},
chrono::{DateTime, Utc},
std::collections::BTreeSet,
};

Expand Down Expand Up @@ -45,6 +46,11 @@ pub enum Kind {
DriverError(String),
/// On-chain solution postprocessing timed out.
PostprocessingTimedOut,
/// The solver has been banned for a specific reason.
Banned {
reason: BanReason,
until: DateTime<Utc>,
},
}

#[derive(Debug)]
Expand All @@ -58,6 +64,12 @@ pub enum ScoreKind {
MissingPrice(TokenAddress),
}

#[derive(Debug)]
pub enum BanReason {
/// The driver won multiple consecutive auctions but never settled them.
UnsettledConsecutiveAuctions,
}

#[derive(Debug)]
pub enum Settlement {
/// Winning solver settled successfully transaction onchain.
Expand Down
19 changes: 19 additions & 0 deletions crates/driver/src/infra/solver/dto/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
infra::notify,
util::serialize,
},
chrono::{DateTime, Utc},
serde::Serialize,
serde_with::serde_as,
std::collections::BTreeSet,
Expand Down Expand Up @@ -61,6 +62,14 @@ impl Notification {
notify::Settlement::Expired => Kind::Expired,
},
notify::Kind::PostprocessingTimedOut => Kind::PostprocessingTimedOut,
notify::Kind::Banned { reason, until } => Kind::Banned {
reason: match reason {
notify::BanReason::UnsettledConsecutiveAuctions => {
BanReason::UnsettledConsecutiveAuctions
}
},
until,
},
},
}
}
Expand Down Expand Up @@ -144,6 +153,16 @@ pub enum Kind {
Expired,
Fail,
PostprocessingTimedOut,
Banned {
reason: BanReason,
until: DateTime<Utc>,
},
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase", tag = "reason")]
pub enum BanReason {
UnsettledConsecutiveAuctions,
}

type BlockNo = u64;
Expand Down
1 change: 1 addition & 0 deletions crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ paths:
- cancelled
- fail
- postprocessingTimedOut
- banned
responses:
"200":
description: notification successfully received.
Expand Down
Loading