-
Notifications
You must be signed in to change notification settings - Fork 37
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
fix: random state reusage #326
Conversation
and adjust usage of presage::Store API which is now asynchronous.
I got another session reset with these changes today. Before trying this build I was running a build based on hrdl-github/presage@8ac1da0, which replaces https://github.com/whisperfish/presage/blob/a8582e5232ce13ae15c84c4634a7226aec943c44/presage/src/manager/registered.rs#L629 and https://github.com/whisperfish/presage/blob/a8582e5232ce13ae15c84c4634a7226aec943c44/presage/src/manager/registered.rs#L1199, among others. |
@hrdl-github I don't see why cloning the rng is a problem. The cloned rng is neither Send nor Sync, so it can be only used on the same thread it was cloned on. Also the edit: Ok, the difference is that in presage |
This explains a lot use rand::rngs::StdRng;
use rand::{RngCore, SeedableRng};
fn main() {
let mut rng = StdRng::from_seed([0; 32]);
let mut rng2 = rng.clone();
println!("{:?}", rng.next_u64());
println!("{:?}", rng2.next_u64());
} Output
|
Thread rng uses (current impl in rand) the os rng. But more important, it uses always the same thread local instance. So, on the same thread cloning this rng is fine, different clones still point to the same instance. However, the StdRng (current impl) is a chacha rng. Cloning it just clones its state. And different clones produce the same sequence of random numbers. |
This includes the fix whisperfish/presage#292 in particular fixing the long-standing issue #234.
Also adjust usage of presage::Store API which is now asynchronous. One possibly negative side-effect is that the UI looks up in the contact names cache in read-only fashion, and only the async part of
gurk
can populate the cache using the store.Also fix clippy warnings.