Skip to content

Commit

Permalink
Merge pull request #191 from enigbe/feat-run-simulator-with-fixed-seed
Browse files Browse the repository at this point in the history
chore(rng): clean up documentation and RNG type
  • Loading branch information
carlaKC authored Jul 8, 2024
2 parents edb88e6 + 959507a commit 5692374
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ of the random activity that is generated:
capacity in a month.
* `capacity-multiplier=0.5` means that each node sends half their
capacity in a month.
* `--fix-seed`: a `u64` value that allows you to generate random activities deterministically from the provided seed, albeit with some limitations. The simulations are not guaranteed to be perfectly deterministic because tasks complete in slightly different orders on each run of the simulator. With a fixed seed, we can guarantee that the order in which activities are dispatched will be deterministic.
* `--fix-seed`: a `u64` value that allows you to generate random activities
deterministically from the provided seed, albeit with some limitations.
The simulations are not guaranteed to be perfectly deterministic because
tasks complete in slightly different orders on each run of the simulator.
With a fixed seed, we can guarantee that the order in which activities are
dispatched will be deterministic.

### Setup - Defined Activity
If you would like SimLN to generate a specific payments between source
Expand Down
10 changes: 4 additions & 6 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,12 @@ enum SimulationOutput {
///
/// **Note**: `StdMutex`, i.e. (`std::sync::Mutex`), is used here to avoid making the traits
/// `DestinationGenerator` and `PaymentGenerator` async.
type MutRngType = Arc<StdMutex<Box<dyn RngCore + Send>>>;
type MutRngType = Arc<StdMutex<dyn RngCore + Send>>;

/// Newtype for `MutRngType` to encapsulate and hide implementation details for
/// creating new `MutRngType` types. Provides convenient API for the same purpose.
#[derive(Clone)]
struct MutRng(pub MutRngType);
struct MutRng(MutRngType);

impl MutRng {
/// Creates a new MutRng given an optional `u64` argument. If `seed_opt` is `Some`,
Expand All @@ -467,11 +467,9 @@ impl MutRng {
/// non-deterministic source of entropy.
pub fn new(seed_opt: Option<u64>) -> Self {
if let Some(seed) = seed_opt {
Self(Arc::new(StdMutex::new(
Box::new(ChaCha8Rng::seed_from_u64(seed)) as Box<dyn RngCore + Send>,
)))
Self(Arc::new(StdMutex::new(ChaCha8Rng::seed_from_u64(seed))))
} else {
Self(Arc::new(StdMutex::new(Box::new(StdRng::from_entropy()))))
Self(Arc::new(StdMutex::new(StdRng::from_entropy())))
}
}
}
Expand Down

0 comments on commit 5692374

Please sign in to comment.