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

[Merged by Bors] - Fix Rust 1.61 clippy lints #3192

Closed
wants to merge 3 commits into from

Conversation

michaelsproul
Copy link
Member

Issue Addressed

This fixes the low-hanging Clippy lints introduced in Rust 1.61 (due any hour now). It ignores one lint, because fixing it requires a structural refactor of the validator client that needs to be done delicately. I've started on that refactor and will create another PR that can be reviewed in more depth in the coming days. I think we should merge this PR in the meantime to unblock CI.

@michaelsproul michaelsproul added ready-for-review The code is ready for review low-hanging-fruit Easy to resolve, get it before someone else does! labels May 19, 2022
Copy link
Member

@realbigsean realbigsean left a comment

Choose a reason for hiding this comment

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

Looks good! I had a comment on whether we could get around swapping out the lock in the simulator but since it's just the simulator don't think it's a big deal.

In reference to the currently ignored lint: I've read async locks are generally less performant, so I'm wondering if rather than swapping the lock on validator_store.initialized_validators out for an async one, we should instead remove that lock and add one to validator_store.initalized_validators.definitions and validator_store.initialized_validators.validators

Haven't checked it out in depth but I think we could get around holdintg it across an await if we do that

testing/simulator/src/local_network.rs Outdated Show resolved Hide resolved
@michaelsproul
Copy link
Member Author

I'll have to dig into the VC locks some more. I think avoiding the async mutex if we can would be nice, although I'm worried there are other sketchy things we're doing that aren't yet being caught by Clippy (just as this issue wasn't caught until 1.61).

When I started the refactor I noticed a lot of other places where we hold a lock across a block_on, which evaluates a future containing awaits:

Initially I thought these were false negatives for Clippy, but now I think they may actually be fine. As per this issue, Rust is smart enough to mark futures holding locks as !Send, and curiously, unlike spawn, block_on does not require its future to be Send. I think this is because it drives the future to completion on the current thread, and not on a thread from the Tokio async pool. This means there's no risk of a block_on task being paused (when it awaits) and picked up by another thread which doesn't hold the lock. So far so good: that's a static guarantee checked by the type system!

The other way to get a deadlock is described by this comment on that same Rust issue: when the thread holding the lock is re-purposed to run another task/future which tries to obtain the lock. According to std::mutex::Mutex this attempt to obtain the lock from the thread that already holds it will panic (or deadlock?). I think we're safe from this however due to block_on running the task on a dedicated thread that exists outside the Tokio runtime: this thread won't be re-purposed to run any other futures.

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

LGTM!

bors r+

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels May 20, 2022
bors bot pushed a commit that referenced this pull request May 20, 2022
## Issue Addressed

This fixes the low-hanging Clippy lints introduced in Rust 1.61 (due any hour now). It _ignores_ one lint, because fixing it requires a structural refactor of the validator client that needs to be done delicately. I've started on that refactor and will create another PR that can be reviewed in more depth in the coming days. I think we should merge this PR in the meantime to unblock CI.
@bors
Copy link

bors bot commented May 20, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request May 20, 2022
## Issue Addressed

This fixes the low-hanging Clippy lints introduced in Rust 1.61 (due any hour now). It _ignores_ one lint, because fixing it requires a structural refactor of the validator client that needs to be done delicately. I've started on that refactor and will create another PR that can be reviewed in more depth in the coming days. I think we should merge this PR in the meantime to unblock CI.
@bors
Copy link

bors bot commented May 20, 2022

Build failed (retrying...):

@michaelsproul
Copy link
Member Author

bors r-

gotta fix udeps

@bors
Copy link

bors bot commented May 20, 2022

Canceled.

@michaelsproul
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request May 20, 2022
## Issue Addressed

This fixes the low-hanging Clippy lints introduced in Rust 1.61 (due any hour now). It _ignores_ one lint, because fixing it requires a structural refactor of the validator client that needs to be done delicately. I've started on that refactor and will create another PR that can be reviewed in more depth in the coming days. I think we should merge this PR in the meantime to unblock CI.
@bors bors bot changed the title Fix Rust 1.61 clippy lints [Merged by Bors] - Fix Rust 1.61 clippy lints May 20, 2022
@bors bors bot closed this May 20, 2022
@michaelsproul michaelsproul deleted the clippy-1.61-part-1 branch May 20, 2022 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low-hanging-fruit Easy to resolve, get it before someone else does! ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants