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

Cancel download and verify tasks when the mempool is deactivated #2764

Merged
merged 14 commits into from
Sep 28, 2021

Conversation

conradoplg
Copy link
Collaborator

@conradoplg conradoplg commented Sep 15, 2021

Motivation

When the mempool is deactivate we should cancel all current transaction download and verify tasks.

Specifications

Designs

Solution

Add a method to cancel the downloads (copied from the block downloader). Call it when the mempool is deactivated.

Additionally, actually deactivate the mempool: when it's disabled, answer any requests with an error. (I can move this to a separate PR, but it seemed simple enough)

Closes #2629

Review

This is in draft because it's waiting for the enabling/disabling handling be improved in #2723 as discussed in #2754 (review) I realized it made more sense to do this directly here.

Anyone working on the mempool can review it.

One detail I'm not sure of is how the mempool should behave when deactivated. I considered making poll_ready return it's not ready, but I think that's not the correct behaviour (the polling seems to be for capacity) and it maybe would lead to blocking callers?

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

@conradoplg conradoplg marked this pull request as draft September 15, 2021 21:05
Base automatically changed from mempool-sync-status to main September 15, 2021 22:13
@mpguerra mpguerra linked an issue Sep 16, 2021 that may be closed by this pull request
@conradoplg conradoplg force-pushed the cancel-tasks-mempool-deactivated branch from 23c1ab3 to f6ef6dc Compare September 16, 2021 17:35
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

I really like the tests here!
And thanks for filling in some missing tests from other PRs.

I think there might be a peer disconnection bug here.
(It might not have shown up during testing, because it would only slow down the sync.)

zebrad/src/components/mempool/error.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

I was doing the refactoring to enable/disable the mempool without relying on boolean and realized that it would automatically solve this issue. For this reason I've committed the refactoring here.

One thing I'm not sure and I'd like feedback on is the enable() and disable() helper functions - if they're a good idea in the first place and also if they're implemented correctly (I'm not sure it's OK to call ready_and() and not call the service aftewards... it works, though)

zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool/error.rs Outdated Show resolved Hide resolved
@conradoplg conradoplg marked this pull request as ready for review September 22, 2021 21:29
@teor2345
Copy link
Contributor

teor2345 commented Sep 23, 2021

One detail I'm not sure of is how the mempool should behave when deactivated. I considered making poll_ready return it's not ready, but I think that's not the correct behaviour (the polling seems to be for capacity) and it maybe would lead to blocking callers?

Yeah there isn't really a state for "still initializing".

And in practice, we don't want to block inbound service requests for 2-6 hours while we sync to the tip.
So we just give the most accurate answer we can: "there's nothing in our mempool yet".

Similarly, while we're initializing the inbound service, we either return an empty response, or we don't respond at all.

One thing I'm not sure and I'd like feedback on is the enable() and disable() helper functions - if they're a good idea in the first place and also if they're implemented correctly (I'm not sure it's OK to call ready_and() and not call the service aftewards... it works, though)

Technically this is ok:

Once poll_ready returns Poll::Ready(Ok(())), a request may be dispatched to the service using call. Until a request is dispatched, repeated calls to poll_ready must return either Poll::Ready(Ok(())) or Poll::Ready(Err(_)).

https://docs.rs/tower-service/0.3.1/tower_service/trait.Service.html#tymethod.poll_ready

But it can cause tower::Buffers to block until some of the spurious readiness slots are dropped:
https://github.com/ZcashFoundation/zebra/blob/main/book/src/dev/rfcs/0011-async-rust-in-zebra.md#buffered-services

So it's better to just submit a cheap read-only request, like oneshot(Request::TransactionIds).

It probably won't matter in this specific situation, because:

  • there aren't any buffers (yet!)
  • the tests are small (but it might slow or fail larger tests)

But it's worth avoiding anyway, so we don't cause failures during future refactors.

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This looks good - we could merge it as it is.

But there's a future bug risk we might want to fix, and a few possible refactors we could do to simplify things.

zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
@teor2345
Copy link
Contributor

One thing I'm not sure and I'd like feedback on is the enable() and disable() helper functions - if they're a good idea in the first place

I just realised I didn't answer this:

Yes, I think these functions are good, because they make the tests simpler.

Copy link
Collaborator Author

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

Addressed comments and synced with main

zebrad/src/components/mempool.rs Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
@conradoplg
Copy link
Collaborator Author

@teor2345 can you please review the last changes?

teor2345
teor2345 previously approved these changes Sep 28, 2021
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks great, but we'll need to resolve conflicts with PR #2765.

Then feel free to merge!

zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
zebrad/src/components/mempool/tests.rs Show resolved Hide resolved
zebrad/src/components/mempool.rs Outdated Show resolved Hide resolved
Co-authored-by: teor <teor@riseup.net>
Copy link
Collaborator Author

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

Solved conflicts and synced with main.

Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Let's merge!

@teor2345 teor2345 merged commit c6878d9 into main Sep 28, 2021
@teor2345 teor2345 deleted the cancel-tasks-mempool-deactivated branch September 28, 2021 23:06
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.

Cancel download and verify tasks when the mempool is deactivated
2 participants