-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Currently all randomness happening in tendermint is going through cmn.Rand. This is done under the guise of cmn.Rand being "thread-safe randomness". cmn.Rand is just a global random instance, but with a mutex lock on every single call.
We should instead have each of these distinct threads getting its own randomness instance. This avoids the mutex lock, and more fundamentally is getting its randomness via that thread owning its randomness instance. Having each thread have its own randomness is inherently safer (any issue one thread has won't cascade into other threads), and is much faster due to avoiding contention on that mutex.
We don't need a global randomness instance to seed our per-thread PRG's. This is because as stated in the godoc, the default randomness instance is thread safe.