paritytech / parity-common

Collection of crates used in Parity projects
https://www.paritytech.io/
Apache License 2.0
282 stars 213 forks source link

fixed-hash: allow opting out `rand` when `std` enabled #805

Closed Farhad-Shabani closed 9 months ago

Farhad-Shabani commented 9 months ago

Context

at ibc-rs, we use primitives_types::U256 for an Amount type, but there's an issue for projects using ibc-rs, when integrating with CosmWasm and compiling with wasm32-unknown-unknown target. We need there, to enable the std feature and avoid pulling in rand or getrandom crates as CosmWasm VM doesn't allow them.

Thus, when we enable primitive_types/std, fixed_hash/std is brought in, and rand is pulled in afterward. This causes compatibility issues with CosmWasm.

Related issue at ibc-rs: https://github.com/cosmos/ibc-rs/issues/991

Proposal

Adding an extra rand feature, so can exclude rand from the fixed_hash crate when:

  primitive-types = { version = "0.12.2", default-features = false, features = "std" }

This allows our users to stick with standard libraries without pulling in the rand while the fixed-hash retains its default behavior.