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

Refactor and document correctness for std::sync::Mutex<AddressBook> #2033

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

teor2345
Copy link
Contributor

Motivation

The shared peer address book uses a threaded mutex. So when we're waiting for the lock in async code, we need to be careful to avoid blocking all the tasks on that thread for too long.

Solution

  • Refactor to make correct usage easier
  • Document correctness

The code in this pull request has:

  • Documentation Comments
  • Integration Tests

Review

@oxarbitrage can review once I've tested it locally.

Related Issues

Implements part of #1995

Follow Up Work

The address book and candidate set code is really complex. It would be easier to avoid hang bugs if they were rewritten as services (#1976).

@teor2345 teor2345 added C-bug Category: This is a bug A-rust Area: Updates to Rust code C-cleanup Category: This is a cleanup P-Medium C-security Category: Security issues I-hang A Zebra component stops responding to requests I-slow Problems with performance or responsiveness labels Apr 19, 2021
@teor2345 teor2345 added this to the 2021 Sprint 7 milestone Apr 19, 2021
@teor2345 teor2345 requested a review from oxarbitrage April 19, 2021 06:19
@teor2345 teor2345 self-assigned this Apr 19, 2021
@mpguerra mpguerra removed this from the 2021 Sprint 7 milestone Apr 19, 2021
@teor2345 teor2345 mentioned this pull request Apr 19, 2021
7 tasks
@teor2345 teor2345 marked this pull request as ready for review April 19, 2021 22:25
@teor2345
Copy link
Contributor Author

Hey @oxarbitrage can you review this PR soon? It's blocking #2035.

Comment on lines +243 to +244
let peers = address_book.lock().unwrap().clone();
let mut peers = peers.sanitized();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fanatid our external address should be added to the cloned peers before they are sanitized().

Comment on lines 195 to +196
// TODO: reduce mutex contention by moving the filtering into
// the address book itself
// the address book itself (#1976)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines +259 to +260
// In this critical section, we hold the address mutex, blocking the
// current thread, and all async tasks scheduled on that thread.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠👍

Comment on lines +387 to +388
// TODO: replace with a watch channel that is updated in `AddressBook::update_metrics()`,
// or turn the address book into a service (#1976)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@dconnolly dconnolly added this to the 2021 Sprint 8 milestone Apr 21, 2021
@dconnolly dconnolly merged commit 0203d14 into ZcashFoundation:main Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-bug Category: This is a bug C-cleanup Category: This is a cleanup C-security Category: Security issues I-hang A Zebra component stops responding to requests I-slow Problems with performance or responsiveness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants