Skip to content

Remove usage of rand.Rand #2956

@ValarDragon

Description

@ValarDragon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T:code-hygieneGeneral cleanup and restructuring of code to provide clarity, flexibility, and modularity.good first issueContributions Welcome!!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions