-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat: Implement BadTokenMonitor #3153
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
use { | ||
super::database::Postgres, | ||
crate::{ | ||
domain::{self, Mempools}, | ||
infra::{ | ||
self, | ||
config::file::OrderPriorityStrategy, | ||
liquidity, | ||
solver::{Solver, Timeouts}, | ||
tokens, | ||
Ethereum, | ||
self, | ||
bad_token::BadTokenMonitor, | ||
config::file::OrderPriorityStrategy, | ||
liquidity, | ||
solver::{Solver, Timeouts}, | ||
tokens, | ||
Ethereum, | ||
Simulator, | ||
}, | ||
}, | ||
error::Error, | ||
futures::Future, | ||
std::{net::SocketAddr, sync::Arc}, | ||
}, | ||
error::Error, | ||
futures::Future, | ||
std::{net::SocketAddr, sync::Arc}, | ||
tokio::sync::oneshot, | ||
}; | ||
|
||
|
@@ -26,6 +28,7 @@ pub struct Api { | |
pub solvers: Vec<Solver>, | ||
pub liquidity: liquidity::Fetcher, | ||
pub simulator: Simulator, | ||
pub db: Postgres, | ||
pub eth: Ethereum, | ||
pub mempools: Mempools, | ||
pub addr: SocketAddr, | ||
|
@@ -57,6 +60,8 @@ impl Api { | |
app = routes::metrics(app); | ||
app = routes::healthz(app); | ||
|
||
let mut bad_token_monitors = BadTokenMonitor::collect_from_path("./src/infra/bad_token/configs", &solvers); | ||
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. Things like this should be passed via arguments to the program. |
||
|
||
// Multiplex each solver as part of the API. Multiple solvers are multiplexed | ||
// on the same driver so only one liquidity collector collects the liquidity | ||
// for all of them. This is important because liquidity collection is | ||
|
@@ -70,15 +75,21 @@ impl Api { | |
let router = routes::reveal(router); | ||
let router = routes::settle(router); | ||
let router = router.with_state(State(Arc::new(Inner { | ||
db: self.db.clone(), | ||
eth: self.eth.clone(), | ||
solver: solver.clone(), | ||
competition: domain::Competition { | ||
solver, | ||
eth: self.eth.clone(), | ||
liquidity: self.liquidity.clone(), | ||
bad_token_monitor: { | ||
let mut monitor = bad_token_monitors.remove(&solver.address()).unwrap(); | ||
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. This function already returns a |
||
monitor.initialize(&self.db); | ||
monitor | ||
}, | ||
simulator: self.simulator.clone(), | ||
mempools: self.mempools.clone(), | ||
settlements: Default::default(), | ||
solver, | ||
}, | ||
liquidity: self.liquidity.clone(), | ||
tokens: tokens.clone(), | ||
|
@@ -128,6 +139,10 @@ impl State { | |
&self.0.tokens | ||
} | ||
|
||
fn database(&self) -> &Postgres { | ||
&self.0.db | ||
} | ||
|
||
fn pre_processor(&self) -> &domain::competition::AuctionProcessor { | ||
&self.0.pre_processor | ||
} | ||
|
@@ -138,6 +153,7 @@ impl State { | |
} | ||
|
||
struct Inner { | ||
db: Postgres, | ||
eth: Ethereum, | ||
solver: Solver, | ||
competition: domain::Competition, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
solver = "0x1234567890abcdef1234567890abcdef12345678" | ||
timespan = 3 | ||
|
||
|
||
[[tokens.supported]] | ||
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. Why are there multiple entries for |
||
address = "0xabcdefabcdefabcdefabcdefabcdefabcd" | ||
|
||
[[tokens.supported]] | ||
address = "0x1234123412341234123412341234123412341234" | ||
|
||
[[tokens.unsupported]] | ||
address = "0x5678567856785678567856785678567856785678" | ||
|
||
[[tokens.unsupported]] | ||
address = "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" | ||
|
||
[heuristic.ThresholdBased] | ||
threshold = 10 | ||
|
||
mode = "LogOnly" |
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.
I'd like to avoid persisting bad tokens in the DB. At least from the start we should collect the heuristics only based on an in-memory cache.
This trades code complexity for accuracy after restarts. Also so far the driver does not depend on any DB at all which would be an additional piece of infra external teams would have to maintain.