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

feat: Implement BadTokenMonitor #3153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

usagi32
Copy link

@usagi32 usagi32 commented Dec 9, 2024

addresses #3094 and #3092

There will be some mistakes as I did not test this code but this should be suffice for initial implementation.

@usagi32 usagi32 requested a review from a team as a code owner December 9, 2024 20:58
Copy link

github-actions bot commented Dec 9, 2024

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

Copy link
Contributor

@MartinquaXD MartinquaXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already started working on this internally (PR pending) which matches more what we imagined so this PR will probably not get merged but we appreciate your contribution a lot.
In any case I left a review to give some feedback that's hopefully helpful to you.

@@ -72,6 +72,7 @@ pub const TABLES: &[&str] = &[
"auction_participants",
"app_data",
"jit_orders",
"bad_tokens"
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things like this should be passed via arguments to the program.
Instead of introducing another file this could be part of the existing driver config file (each solver could have their own section with supported tokens).

eth: self.eth.clone(),
liquidity: self.liquidity.clone(),
bad_token_monitor: {
let mut monitor = bad_token_monitors.remove(&solver.address()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function already returns a Result so having error handling instead of .unwrap() would be very easy.

timespan = 3


[[tokens.supported]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there multiple entries for tokens.supported? A list should be defined in a single array, I think.
Also it might be nicer to have a mapping token => supported_enum to avoid error cases where the same token is part of both lists.


pub struct ConfigFile {
solver: Option<String>,
tokens: Option<TomlValue>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raw TomlValues should be avoided given that we could use serde to parse the file into proper rust types.

tokens: Option<TomlValue>,
timespan: Option<u32>,
heuristic: Option<TomlValue>,
mode: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode should be parsed into an enum right away

solver: Address,
supported_tokens: Vec<TokenAddress>,
unsupported_tokens: Vec<TokenAddress>,
timespan: u32, // needs to be discussed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should rather be a Duration.

}
}

pub struct ConfigFile {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the names might have gotten mixed up?
ConfigFile does not implement Deserialize but Config does.

Comment on lines +125 to +127
deny_list: HashSet<TokenAddress>,
explicit_deny_list: BTreeSet<TokenAddress>,
explicit_allow_list: BTreeSet<TokenAddress>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason that some lookups are BTree based and some hash based?

Comment on lines +287 to +289
if threshold.threshold <= threshold_state.count + 1 {
self.deny_list.insert(token.to_owned())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear how the heuristic is supposed to work. Overall having doc comments (///) on all the relevant types would be helpful.
I'd imagine the heuristic to keep track of how often a token is involved in a solution that failed to simulate. Here it looks like it would just iterate over all the tokens in the auction without any indication whether they were good or not.

@usagi32
Copy link
Author

usagi32 commented Dec 10, 2024

Thank you for giving this much feedback. Other than the design choice of not persisting in the postgres db, I've had my reasons and justifications for every thing else.

I wanted to contribute to get attention and to show my skills as I am in need of a job. But what seems to me that, in this repository most of the issues are either internally discussed or internally solved. Not much from what I can pick up on.

If you a have job opening, I am open to get some help.

@sunce86
Copy link
Contributor

sunce86 commented Dec 10, 2024

Thank you for taking a shot. We have a good first issue label for issues that are good for newcomers to try out. Although, I must admit we didn't update the label lately.

Let me know if you are willing to take another shot with other tasks as well. I am willing to guide you through execution.

Also, you can find more hiring info here: https://cow.fi/careers

@usagi32
Copy link
Author

usagi32 commented Dec 10, 2024

@sunce86 thank you for replying.

Yes, I am willing to try other tasks. Please guide me through them.

And yes, I knew about the careers page, but for that I don't have the relevant on-paper experience even though I have the necessary skills for it. So, I figured, the only way to prove my skills was through open source contributions.

@tsmahdy
Copy link

tsmahdy commented Dec 11, 2024

@usagi32 Thank you so much for taking the initiative! It's always great to see enthusiasm and proactivity from people interested in joining our team.

Regarding our current job opening, as you mentioned, it does require a certain level of seniority. That said, let's connect on LinkedIn (you can find my profile on my page) and stay in touch for future opportunities. I'd be happy to discuss things further if you're open to exploring possibilities down the line!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants