Skip to content

Commit

Permalink
feat: add a thread_rng wrapper that that can be overriden by reproduc…
Browse files Browse the repository at this point in the history
…ible seeded rng (#5375)

Co-authored-by: Hubert <hubert@chainsafe.io>
  • Loading branch information
hanabi1224 and LesnyRumcajs authored Mar 6, 2025
1 parent 4b88cd4 commit aedb6cd
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 79 deletions.
12 changes: 12 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ use parking_lot::Mutex instead to silently ignore panics."""
path = "multihash_codetable::Code"
reason = """use `crate::utils::multihash::MultihashCode` instead which has `Identity` code back-filled."""

[[disallowed-types]]
path = "rand::rngs::ThreadRng"
reason = """use `crate::utils::forest_rng` instead."""

[[disallowed-types]]
path = "rand::rngs::OsRng"
reason = """use `crate::utils::forest_os_rng` instead."""

[[disallowed-methods]]
path = "rand::thread_rng"
reason = """use `crate::utils::forest_rng` instead."""

[[disallowed-methods]]
path = "tempfile::NamedTempFile::new"
reason = """The temporary files created by this method are not persistable if the temporary directory lives on a different filesystem than the target directory. While it is valid in other contexts (if not persisting files), it was misused many times and so we are banning it. Consider using `tempfile::NamedTempFile::new_in` or `tempfile::NamedTempFile::Builder"""
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

### Added

- [#5375](https://github.com/ChainSafe/forest/issues/5375) Add an RNG wrapper that that can be overriden by a reproducible seeded RNG.

### Changed

### Removed
Expand Down
49 changes: 25 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ prometheus-client = "0.22"
quick-protobuf = "0.8"
quick-protobuf-codec = "0.3"
rand = "0.8"
rand_chacha = "0.3"
rand_distr = "0.4"
raw_sync_2 = "0.1"
rayon = "1"
Expand Down
1 change: 1 addition & 0 deletions docs/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ preload
preloaded
Q4
README
RNG
Roadmap
roadmap
RPC
Expand Down
Loading

0 comments on commit aedb6cd

Please sign in to comment.