Skip to content

Conversation

@AdekunleBamz
Copy link

Summary

This PR resolves multiple TODO(rand) comments by replacing direct calls to B256::random() and B512::random() with rng.gen() to consistently use the provided random number generator throughout the networking crates.

Motivation

The existing code had several TODO comments indicating that random value generation should use the provided RNG parameter instead of direct ::random() calls. Using the provided RNG ensures:

  • Better testability with deterministic seeded RNGs
  • Consistent behavior across the codebase
  • Proper encapsulation of randomness sources

Changes

crates/net/ecies/src/algorithm.rs

  • Changed nonce generation in new_client() to use rng.gen() instead of B256::random()
  • Changed nonce generation in new_server() to use rng.gen() instead of B256::random()
  • Removed resolved TODO(rand) comment

crates/net/discv4/src/test_utils.rs

  • Changed B512 ID generation in rng_record() to use rng.gen()
  • Changed B512 ID generation in rng_ipv6_record() to use rng.gen()
  • Changed B512 ID generation in rng_ipv4_record() to use rng.gen()
  • Changed B512 ID generation in rng_message() to use rng.gen()
  • Removed resolved TODO(rand) comments

testing/testing-utils/src/generators.rs

  • Changed B256 generation in random_contract_account_range() to use rng.gen()
  • Changed B256 generation in random_log() to use rng.gen()
  • Removed resolved TODO(rand) comment

Testing

The changes maintain existing behavior while improving code consistency. All modified functions already accept an RNG parameter, so this change simply ensures the provided RNG is used throughout.

Type of Change

  • Refactor (code improvement without functional changes)
  • Bug fix (resolves TODO items)

Replace direct calls to B256::random() and B512::random() with rng.gen()
to use the provided random number generator consistently throughout the
networking crates. This resolves TODO(rand) comments and ensures better
testability and determinism when using seeded RNGs.

Changes:
- crates/net/ecies/src/algorithm.rs: Use rng.gen() for nonce generation
  in new_client() and new_server() methods
- crates/net/discv4/src/test_utils.rs: Use rng.gen() for B512 ID generation
  in rng_record(), rng_ipv6_record(), and rng_ipv4_record() functions
- testing/testing-utils/src/generators.rs: Use rng.gen() for B256 generation
  in random_contract_account_range() and random_log() functions

This improves code consistency and makes testing more reliable by respecting
the RNG parameter provided to these functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant