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

Allow async implementation for BackupReader and BackupWriter #399

Merged
merged 3 commits into from
Mar 4, 2024

Conversation

maan2003
Copy link
Contributor

using io::Write or io::Read forces a sync implementation.

we were using block_on to use async inside the implementation, but this blocking the executor and sometimes leads to deadlocks.

this is backwards compatible by implementing new traits for any io::Read and io::Write impls.

see fedimint/fedimint#4054 for more context.

Copy link

Please make sure the following happened

  • Appropriate tests created
  • Infrastructure updated accordingly
  • Updated existing documentation
  • New documentation created
  • Version bumped if breaking changes

@dpc
Copy link

dpc commented Jan 19, 2024

this is backwards compatible by implementing new traits for any io::Read and io::Write impls.

Isn't the previous way strictly incorrect? The code running it is async, so it can't be calling blocking IO methods without some form of offloading from the current executor (like tokio::task::block_in_place). The current backward-compat impls preserve the existing incorrect behavior.

@maan2003
Copy link
Contributor Author

should we just remove Read and Write impls. we can't use offloading methods because we don't depend on tokio.

@dpc
Copy link

dpc commented Jan 22, 2024

should we just remove Read and Write impls. we can't use offloading methods because we don't depend on tokio.

IMO there's no reason to try to preserve the old (incorrect) behavior.

@maan2003
Copy link
Contributor Author

we can't remove Read and Write because mock crate impls Read for mock reader.

mock can't impl BackupReader because mock can't depend main crate (circular deps).
Solution to this would be moving mock to same crate, but that will be big change.

@dpc
Copy link

dpc commented Jan 23, 2024

mock can't impl BackupReader because mock can't depend main crate (circular deps).

So a mock can't depend on the thing it's mocking? Weird, but I don't have time to dig into it.

Solution to this would be moving mock to same crate, but that will be big change.

Or move the trait to a separate crate, so both can depend on it. That's how Read was working - it was in a 3rd crate (stdlib).

@joschisan
Copy link
Contributor

we can't remove Read and Write because mock crate impls Read for mock reader.

mock can't impl BackupReader because mock can't depend main crate (circular deps). Solution to this would be moving mock to same crate, but that will be big change.

I think we can move the new traits into the aleph-bft-types crate, that's were the other traits used in the api like Network are too.

consensus/src/backup/loader.rs Outdated Show resolved Hide resolved
consensus/src/backup/loader.rs Outdated Show resolved Hide resolved
consensus/src/backup/saver.rs Outdated Show resolved Hide resolved
@woocash2
Copy link
Contributor

woocash2 commented Mar 1, 2024

Hi, we have looked into your PR and into the issues in your repository, apologies for letting it hang here for a long time. We have introduced traits Read and Write here mostly with an intention of using io::File or a similar kind of a lightweight object with read/write semantics as the implementation. Although we consider it as the preferred way to implement the backup, we understand your need for an asynchronous interface and we're eager to merge the PR in some form. I had my colleague leave some comments so please act upon them, also we'll have to run some checks. Thank you for your contribution.

@dpc
Copy link

dpc commented Mar 3, 2024

We have introduced traits Read and Write here mostly with an intention of using io::File

If it was to be done this way then the core alephbft async code calling this interface should be calling it wrapped in some https://docs.rs/tokio/latest/tokio/task/fn.block_in_place.html , otherwise async executor gets blocked on blocking IO operations, potentially stalling async executor.

@maan2003 maan2003 force-pushed the main branch 2 times, most recently from 27dbaa3 to bfc752b Compare March 4, 2024 10:17
@maan2003
Copy link
Contributor Author

maan2003 commented Mar 4, 2024

  • switched to Async{Read,Write}
  • rebased on master
  • version bump to 0.34

Copy link
Contributor

@timorleph timorleph left a comment

Choose a reason for hiding this comment

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

Nice, thanks! One little comment left.

consensus/src/backup/saver.rs Outdated Show resolved Hide resolved
@timorleph
Copy link
Contributor

Oh, and some failing checks, mostly related to version bumps, one of which should happen in the readme.

@timorleph
Copy link
Contributor

mock and rmc still need version bumps, minor and patch respectively. Although tbh I'm not quite sure why you touched rmc at all?

@maan2003
Copy link
Contributor Author

maan2003 commented Mar 4, 2024

maybe version checks don't understand that removing imports doesn't need bump?

@maan2003
Copy link
Contributor Author

maan2003 commented Mar 4, 2024

oh those were pub use but not exported at top level

@timorleph timorleph merged commit 36638fd into Cardinal-Cryptography:main Mar 4, 2024
9 checks passed
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.

5 participants